-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DDC-2794] Arbitrary Join count walkers solution #1092
Changes from 5 commits
114bd24
a37f99f
1643525
458b953
54ac6a0
d48be34
589d26f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,31 +50,24 @@ public function walkSelectStatement(SelectStatement $AST) | |
throw new \RuntimeException('Cannot count query that uses a HAVING clause. Use the output walkers for pagination'); | ||
} | ||
|
||
$rootComponents = array(); | ||
foreach ($this->_getQueryComponents() as $dqlAlias => $qComp) { | ||
$isParent = array_key_exists('parent', $qComp) | ||
&& $qComp['parent'] === null | ||
&& $qComp['nestingLevel'] == 0 | ||
; | ||
if ($isParent) { | ||
$rootComponents[] = array($dqlAlias => $qComp); | ||
} | ||
} | ||
if (count($rootComponents) > 1) { | ||
$queryComponents = $this->_getQueryComponents(); | ||
// Get the root entity and alias from the AST fromClause | ||
$from = $AST->fromClause->identificationVariableDeclarations; | ||
if (count($from) > 1) { | ||
throw new \RuntimeException("Cannot count query which selects two FROM components, cannot make distinction"); | ||
} | ||
$root = reset($rootComponents); | ||
$parentName = key($root); | ||
$parent = current($root); | ||
$identifierFieldName = $parent['metadata']->getSingleIdentifierFieldName(); | ||
|
||
$rootAlias = $from[0]->rangeVariableDeclaration->aliasIdentificationVariable; | ||
$rootClass = $queryComponents[$rootAlias]['metadata']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. align |
||
$identifierFieldName = $rootClass->getSingleIdentifierFieldName(); | ||
|
||
$pathType = PathExpression::TYPE_STATE_FIELD; | ||
if (isset($parent['metadata']->associationMappings[$identifierFieldName])) { | ||
if (isset($rootClass->associationMappings[$identifierFieldName])) { | ||
$pathType = PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION; | ||
} | ||
|
||
$pathExpression = new PathExpression( | ||
PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $parentName, | ||
PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $rootAlias, | ||
$identifierFieldName | ||
); | ||
$pathExpression->type = $pathType; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,37 +60,34 @@ class LimitSubqueryWalker extends TreeWalkerAdapter | |
*/ | ||
public function walkSelectStatement(SelectStatement $AST) | ||
{ | ||
$parent = null; | ||
$parentName = null; | ||
$queryComponents = $this->_getQueryComponents(); | ||
// Get the root entity and alias from the AST fromClause | ||
$from = $AST->fromClause->identificationVariableDeclarations; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Align |
||
$rootAlias = $from[0]->rangeVariableDeclaration->aliasIdentificationVariable; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The AST doesn't ensure that the array is indexed starting from |
||
$rootClass = $queryComponents[$rootAlias]['metadata']; | ||
$selectExpressions = array(); | ||
|
||
foreach ($this->_getQueryComponents() as $dqlAlias => $qComp) { | ||
foreach ($queryComponents as $dqlAlias => $qComp) { | ||
// Preserve mixed data in query for ordering. | ||
if (isset($qComp['resultVariable'])) { | ||
$selectExpressions[] = new SelectExpression($qComp['resultVariable'], $dqlAlias); | ||
continue; | ||
} | ||
|
||
if ($qComp['parent'] === null && $qComp['nestingLevel'] == 0) { | ||
$parent = $qComp; | ||
$parentName = $dqlAlias; | ||
continue; | ||
} | ||
} | ||
|
||
$identifier = $parent['metadata']->getSingleIdentifierFieldName(); | ||
if (isset($parent['metadata']->associationMappings[$identifier])) { | ||
$identifier = $rootClass->getSingleIdentifierFieldName(); | ||
if (isset($rootClass->associationMappings[$identifier])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. empty newline before this line |
||
throw new \RuntimeException("Paginating an entity with foreign key as identifier only works when using the Output Walkers. Call Paginator#setUseOutputWalkers(true) before iterating the paginator."); | ||
} | ||
|
||
$this->_getQuery()->setHint( | ||
self::IDENTIFIER_TYPE, | ||
Type::getType($parent['metadata']->getTypeOfField($identifier)) | ||
Type::getType($rootClass->getTypeOfField($identifier)) | ||
); | ||
|
||
$pathExpression = new PathExpression( | ||
PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, | ||
$parentName, | ||
$rootAlias, | ||
$identifier | ||
); | ||
$pathExpression->type = PathExpression::TYPE_STATE_FIELD; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,30 +71,23 @@ class WhereInWalker extends TreeWalkerAdapter | |
*/ | ||
public function walkSelectStatement(SelectStatement $AST) | ||
{ | ||
$rootComponents = array(); | ||
foreach ($this->_getQueryComponents() as $dqlAlias => $qComp) { | ||
$isParent = array_key_exists('parent', $qComp) | ||
&& $qComp['parent'] === null | ||
&& $qComp['nestingLevel'] == 0 | ||
; | ||
if ($isParent) { | ||
$rootComponents[] = array($dqlAlias => $qComp); | ||
} | ||
} | ||
if (count($rootComponents) > 1) { | ||
$queryComponents = $this->_getQueryComponents(); | ||
// Get the root entity and alias from the AST fromClause | ||
$from = $AST->fromClause->identificationVariableDeclarations; | ||
if (count($from) > 1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. empty newline before this line |
||
throw new \RuntimeException("Cannot count query which selects two FROM components, cannot make distinction"); | ||
} | ||
$root = reset($rootComponents); | ||
$parentName = key($root); | ||
$parent = current($root); | ||
$identifierFieldName = $parent['metadata']->getSingleIdentifierFieldName(); | ||
|
||
$rootAlias = $from[0]->rangeVariableDeclaration->aliasIdentificationVariable; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Align |
||
$rootClass = $queryComponents[$rootAlias]['metadata']; | ||
$identifierFieldName = $rootClass->getSingleIdentifierFieldName(); | ||
|
||
$pathType = PathExpression::TYPE_STATE_FIELD; | ||
if (isset($parent['metadata']->associationMappings[$identifierFieldName])) { | ||
if (isset($rootClass->associationMappings[$identifierFieldName])) { | ||
$pathType = PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION; | ||
} | ||
|
||
$pathExpression = new PathExpression(PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $parentName, $identifierFieldName); | ||
$pathExpression = new PathExpression(PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $rootAlias, $identifierFieldName); | ||
$pathExpression->type = $pathType; | ||
|
||
$count = $this->_getQuery()->getHint(self::HINT_PAGINATOR_ID_COUNT); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty newline before this line