-
Notifications
You must be signed in to change notification settings - Fork 180
Support join with dynamic fields #4746
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
base: feature/permissive
Are you sure you want to change the base?
Changes from all commits
f7f8f86
379a6f9
50830fc
703757c
072bd82
ce40b23
3cc00f7
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 |
|---|---|---|
|
|
@@ -12,16 +12,19 @@ | |
| import org.apache.calcite.avatica.util.TimeUnit; | ||
| import org.apache.calcite.rel.type.RelDataType; | ||
| import org.apache.calcite.rex.RexBuilder; | ||
| import org.apache.calcite.rex.RexCall; | ||
| import org.apache.calcite.rex.RexLiteral; | ||
| import org.apache.calcite.rex.RexNode; | ||
| import org.apache.calcite.sql.SqlIntervalQualifier; | ||
| import org.apache.calcite.sql.SqlKind; | ||
| import org.apache.calcite.sql.fun.SqlStdOperatorTable; | ||
| import org.apache.calcite.sql.parser.SqlParserPos; | ||
| import org.apache.calcite.sql.type.SqlTypeName; | ||
| import org.apache.calcite.sql.type.SqlTypeUtil; | ||
| import org.opensearch.sql.ast.expression.SpanUnit; | ||
| import org.opensearch.sql.calcite.type.AbstractExprRelDataType; | ||
| import org.opensearch.sql.calcite.utils.OpenSearchTypeFactory; | ||
| import org.opensearch.sql.calcite.utils.RexConverter; | ||
| import org.opensearch.sql.data.type.ExprCoreType; | ||
| import org.opensearch.sql.exception.ExpressionEvaluationException; | ||
| import org.opensearch.sql.exception.SemanticCheckException; | ||
|
|
@@ -41,6 +44,20 @@ public RexNode equals(RexNode n1, RexNode n2) { | |
| return this.makeCall(SqlStdOperatorTable.EQUALS, n1, n2); | ||
| } | ||
|
|
||
| /** Make equals call with adding cast in case the node type is ANY. */ | ||
| public RexNode equalsWithCastAsNeeded(RexNode n1, RexNode n2) { | ||
| if (isAnyType(n1) && isAnyType(n2)) { | ||
| n1 = castToString(n1); | ||
| n2 = castToString(n2); | ||
| } else if (isAnyType(n1)) { | ||
| n1 = castToTargetType(n1, n2); | ||
| } else if (isAnyType(n2)) { | ||
| n2 = castToTargetType(n2, n1); | ||
| } | ||
|
|
||
| return equals(n1, n2); | ||
| } | ||
|
|
||
| public RexNode and(RexNode left, RexNode right) { | ||
| final RelDataType booleanType = this.getTypeFactory().createSqlType(SqlTypeName.BOOLEAN); | ||
| return this.makeCall(booleanType, SqlStdOperatorTable.AND, List.of(left, right)); | ||
|
|
@@ -164,10 +181,39 @@ else if ((SqlTypeUtil.isApproximateNumeric(sourceType) || SqlTypeUtil.isDecimal( | |
| return super.makeCast(pos, type, exp, matchNullability, safe, format); | ||
| } | ||
|
|
||
| public boolean isAnyType(RexNode node) { | ||
| return node.getType().getSqlTypeName().equals(SqlTypeName.ANY); | ||
| } | ||
|
|
||
| /** Cast node to string */ | ||
| public RexNode castToString(RexNode node) { | ||
| RelDataType stringType = getTypeFactory().createSqlType(SqlTypeName.VARCHAR); | ||
| RelDataType nullableStringType = getTypeFactory().createTypeWithNullability(stringType, true); | ||
| return makeCast(nullableStringType, node, true, true); | ||
| } | ||
|
|
||
| /** cast node to the same type as target */ | ||
| public RexNode castToTargetType(RexNode node, RexNode target) { | ||
| return makeCast(target.getType(), node, true, true); | ||
| } | ||
|
|
||
| /** | ||
| * Utility to cast ANY to specific types to avoid compare issue in Calcite: | ||
| * https://issues.apache.org/jira/browse/CALCITE-7206 | ||
| */ | ||
| RexNode castAnyToAlignTypes(RexNode rexNode, CalcitePlanContext context) { | ||
| return rexNode.accept( | ||
| new RexConverter() { | ||
| @Override | ||
| public RexNode visitCall(RexCall call) { | ||
| if (call.getKind() == SqlKind.EQUALS) { | ||
| RexNode n0 = call.operands.get(0); | ||
| RexNode n1 = call.operands.get(1); | ||
| return super.visitCall((RexCall) equalsWithCastAsNeeded(n0, n1)); | ||
| } else { | ||
| return super.visitCall(call); | ||
| } | ||
| } | ||
|
Comment on lines
+208
to
+216
Collaborator
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. question (non-blocking): Can you explain this more? What's special about
Collaborator
Author
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. Ah, forgot to add comment. I'll add comment. |
||
| }); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
Not entirely the fault of this PR, but CalciteRelNodeVisitor is already a very large file, and I dislike that we're adding more complexity with this logic.
I'd like if we could move the bulk of this visit logic to a dedicated class and leverage that to simplify the method. I did similar refactoring for SPath via
rewriteAsEval.I also think the class would be a better place to encapsulate the left/right distinction, to make it easier to vet that we've applied any relevant logic to both halves.
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 totally agree with that.
Although, I don't want to do that in this series of PRs as it would make it difficult to merge back to main branch.