提交 76a2ae35 编写于 作者: T terrymanu

for #2084, parse subquery for table reference

上级 5f2609b5
...@@ -40,7 +40,7 @@ public final class SelectItemsExtractor implements OptionalSQLSegmentExtractor { ...@@ -40,7 +40,7 @@ public final class SelectItemsExtractor implements OptionalSQLSegmentExtractor {
@Override @Override
public Optional<SelectItemsSegment> extract(final ParserRuleContext ancestorNode, final Map<ParserRuleContext, Integer> parameterMarkerIndexes) { public Optional<SelectItemsSegment> extract(final ParserRuleContext ancestorNode, final Map<ParserRuleContext, Integer> parameterMarkerIndexes) {
ParserRuleContext selectItemsNode = ExtractorUtils.getFirstChildNode(findMainQueryNode(ancestorNode), RuleName.SELECT_ITEMS); ParserRuleContext selectItemsNode = ExtractorUtils.getFirstChildNode(findMainQueryNode(ancestorNode, false), RuleName.SELECT_ITEMS);
SelectItemsSegment result = new SelectItemsSegment(selectItemsNode.getStart().getStartIndex(), selectItemsNode.getStop().getStopIndex(), extractDistinct(ancestorNode)); SelectItemsSegment result = new SelectItemsSegment(selectItemsNode.getStart().getStartIndex(), selectItemsNode.getStop().getStopIndex(), extractDistinct(ancestorNode));
Optional<ParserRuleContext> unqualifiedShorthandNode = ExtractorUtils.findFirstChildNode(selectItemsNode, RuleName.UNQUALIFIED_SHORTHAND); Optional<ParserRuleContext> unqualifiedShorthandNode = ExtractorUtils.findFirstChildNode(selectItemsNode, RuleName.UNQUALIFIED_SHORTHAND);
if (unqualifiedShorthandNode.isPresent()) { if (unqualifiedShorthandNode.isPresent()) {
...@@ -73,7 +73,7 @@ public final class SelectItemsExtractor implements OptionalSQLSegmentExtractor { ...@@ -73,7 +73,7 @@ public final class SelectItemsExtractor implements OptionalSQLSegmentExtractor {
&& (duplicateSpecificationNode.get().getText().equalsIgnoreCase("DISTINCT") || duplicateSpecificationNode.get().getText().equalsIgnoreCase("DISTINCTROW")); && (duplicateSpecificationNode.get().getText().equalsIgnoreCase("DISTINCT") || duplicateSpecificationNode.get().getText().equalsIgnoreCase("DISTINCTROW"));
} }
private ParserRuleContext findMainQueryNode(final ParserRuleContext ancestorNode) { private ParserRuleContext findMainQueryNode(final ParserRuleContext ancestorNode, final boolean isFromRecursive) {
Optional<ParserRuleContext> tableReferencesNode = ExtractorUtils.findFirstChildNode(ancestorNode, RuleName.TABLE_REFERENCES); Optional<ParserRuleContext> tableReferencesNode = ExtractorUtils.findFirstChildNode(ancestorNode, RuleName.TABLE_REFERENCES);
if (!tableReferencesNode.isPresent()) { if (!tableReferencesNode.isPresent()) {
return ancestorNode; return ancestorNode;
...@@ -81,8 +81,8 @@ public final class SelectItemsExtractor implements OptionalSQLSegmentExtractor { ...@@ -81,8 +81,8 @@ public final class SelectItemsExtractor implements OptionalSQLSegmentExtractor {
ParserRuleContext result = tableReferencesNode.get(); ParserRuleContext result = tableReferencesNode.get();
Optional<ParserRuleContext> subqueryNode = ExtractorUtils.findSingleNodeFromFirstDescendant(tableReferencesNode.get(), RuleName.SUBQUERY); Optional<ParserRuleContext> subqueryNode = ExtractorUtils.findSingleNodeFromFirstDescendant(tableReferencesNode.get(), RuleName.SUBQUERY);
if (subqueryNode.isPresent()) { if (subqueryNode.isPresent()) {
result = findMainQueryNode(subqueryNode.get()); result = findMainQueryNode(subqueryNode.get(), true);
} }
return result.getParent().getParent(); return isFromRecursive ? result : ancestorNode;
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册