-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[CALCITE-6825] Add support for ALL, SOME, ANY in RelToSqlConverter #4224
base: main
Are you sure you want to change the base?
Conversation
|
@@ -118,4 +119,42 @@ public class SqlQuantifyOperator extends SqlInOperator { | |||
} | |||
return null; | |||
} | |||
|
|||
@Override public SqlOperator not() { |
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.
how is this change related to the issue?
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.
When <All
convertTo NOT(>= SOME)
, it is used for toSql.
e.g.
The test on RelToSqlConverterTest#testAll
this commit
SQL: SELECT 1, "gross_weight" < ALL(SELECT "gross_weight" FROM "foodmart"."product") AS "t" FROM "foodmart"."product"
Converted rel:
rel#10:LogicalProject.NONE.[](input=JdbcTableScan#7,exprs=[1, NOT(>= SOME($6, {
LogicalProject(gross_weight=[$6])
JdbcTableScan(table=[[foodmart, product]])
}))])
ToSql:
call SqlImplementor.Context#toSql(RexProgram,RexNode):
case NOT:
RexNode operand = ((RexCall) rex).operands.get(0);
final SqlNode node = toSql(program, operand);
final SqlOperator inverseOperator = getInverseOperator(operand); //line 802
getInverseOperator
use the function not
.
If not done, it will throw unexpected SOME.
java.lang.AssertionError: unexpected SOME
at org.apache.calcite.sql.fun.SqlInOperator.of(SqlInOperator.java:98)
at org.apache.calcite.sql.fun.SqlInOperator.not(SqlInOperator.java:84)
at org.apache.calcite.rel.rel2sql.SqlImplementor$Context.getInverseOperator(SqlImplementor.java:914)
at org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:802)
at org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:460)
@@ -9307,6 +9307,24 @@ private void checkLiteral2(String expression, String expected) { | |||
} | |||
|
|||
|
|||
@Test void testSome() { | |||
final String sql = "SELECT 1, \"gross_weight\" < SOME(SELECT \"gross_weight\" " |
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.
Test cases should include ANY. Can we directly rewrite SqlQuantifyOpenator?
ALL
,SOME
,ANY
on subQuery likeIN
.not
inSqlQuantifyOperator
to NOT SOME/ALL.JIRA: https://issues.apache.org/jira/browse/CALCITE-5100