-
Notifications
You must be signed in to change notification settings - Fork 993
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
PHOENIX-3477 Support sequence arithmetic in Calcite-Phoenix #224
Conversation
c77c493
to
98edcf5
Compare
98edcf5
to
662b443
Compare
@@ -1343,6 +1343,28 @@ public void initTable() throws Exception { | |||
{7L, "0000000005", "T5", "0000000005", "S5"}, | |||
{8L, "0000000006", "T6", "0000000006", "S6"}}) | |||
.close(); | |||
|
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.
I remember you said you ran into a problem using PhoenixServerProject, but it's PhoenixClientProject here again. Does it oscillate between the two? Could you please try {{start(false, 1f)}} instead?
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.
While that was my initial thinking, upon looking deeper I discovered a different source for the issue
The reason a ServerProject was being created was because of visitCall(). It wasn't recursively checking for sequences. Therefore, when an operator like SqlKind.PLUS was present and the sequence was present, the sequence would be pushed down to a child operand and not be seen by visitCall()
PhoenixConverterRules is designed so that a ServerProject does not get created if a sequence is present
private static Predicate<LogicalProject> NO_SEQUENCE = new Predicate<LogicalProject>() {
@Override
public boolean apply(LogicalProject input) {
return !CalciteUtils.hasSequenceValueCall(input);
}
};
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.
Thank you for the info, @lomoree! Very helpful! I was wondering if there had been any check of that kind during conversion. Anyway, would you mind removing that NO_SEQUENCE predicate and trying the changes I suggested below?
@@ -1115,6 +1099,11 @@ public Void visitCall(RexCall call) { | |||
|| call.getKind() == SqlKind.NEXT_VALUE)) { | |||
sequenceValueCall = call; | |||
} | |||
if (sequenceValueCall == null){ |
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.
Think we are good to remove this class, right?
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.
Per above I don't believe so
implementor.setSequenceManager(seqManager); | ||
TupleProjector tupleProjector = project(implementor); | ||
if (seqManager != null) { | ||
|
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.
This entire wrapping logic should live in PhoenixToEnumerableConverter instead. Wrapping it with an iterator not a query plan would be better, something like:
{code}
return new DelegateQueryPlan((QueryPlan) plan) {
@Override
public ResultIterator iterator() throws SQLException {
ResultIterator iterator = iterator(DefaultParallelScanGrouper.getInstance());
if (phoenixImplementor.getSequenceManager().getSequenceCount() > 0) {
iterator = new SequenceResultIterator(iterator, phoenixImplementor.getSequenceManager());
}
return iterator;
}
@Override
public ExplainPlan getExplainPlan() throws SQLException {
{code}
After discussing options, we kept original design and merged as is. Closing PR. |
PhoenixConverterRules is meant to route any logical project with a sequence through PhoenixClientProject. Before, sequences were not properly being found. This patch simplifies the logic and adds that support.
-- Check for nested sequences
-- Use the Sequence Manager now available in StatementContext
-- Add relevant test cases to CalciteIT