Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

lomoree
Copy link
Contributor

@lomoree lomoree commented Dec 3, 2016

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

@lomoree lomoree force-pushed the sequencearithmetic branch 2 times, most recently from c77c493 to 98edcf5 Compare December 3, 2016 03:34
@@ -1343,6 +1343,28 @@ public void initTable() throws Exception {
{7L, "0000000005", "T5", "0000000005", "S5"},
{8L, "0000000006", "T6", "0000000006", "S6"}})
.close();

Copy link
Contributor

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?

Copy link
Contributor Author

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);
           }            
       };

Copy link
Contributor

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){
Copy link
Contributor

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?

Copy link
Contributor Author

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) {

Copy link
Contributor

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}

@lomoree
Copy link
Contributor Author

lomoree commented Dec 12, 2016

After discussing options, we kept original design and merged as is. Closing PR.

@lomoree lomoree closed this Dec 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants