chunweilei commented on a change in pull request #1647: [CALCITE-3588] Support
more operators in Join condition when convert …
URL: https://github.com/apache/calcite/pull/1647#discussion_r357142672
##########
File path:
core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
##########
@@ -193,102 +193,12 @@ public Result setOpToSql(SqlSetOperator operator,
RelNode rel) {
* @param node Join condition
* @param leftContext Left context
* @param rightContext Right context
- * @param leftFieldCount Number of fields on left result
* @return SqlNode that represents the condition
*/
- public static SqlNode convertConditionToSqlNode(RexNode node,
- Context leftContext,
- Context rightContext,
- int leftFieldCount,
- SqlDialect dialect) {
- if (node.isAlwaysTrue()) {
- return SqlLiteral.createBoolean(true, POS);
- }
- if (node.isAlwaysFalse()) {
- return SqlLiteral.createBoolean(false, POS);
- }
- if (node instanceof RexInputRef) {
- Context joinContext = leftContext.implementor().joinContext(leftContext,
rightContext);
- return joinContext.toSql(null, node);
- }
- if (!(node instanceof RexCall)) {
- throw new AssertionError(node);
- }
- final List<RexNode> operands;
- final SqlOperator op;
- final Context joinContext;
- switch (node.getKind()) {
- case AND:
- case OR:
- operands = ((RexCall) node).getOperands();
- op = ((RexCall) node).getOperator();
- SqlNode sqlCondition = null;
- for (RexNode operand : operands) {
- SqlNode x = convertConditionToSqlNode(operand, leftContext,
- rightContext, leftFieldCount, dialect);
- if (sqlCondition == null) {
- sqlCondition = x;
- } else {
- sqlCondition = op.createCall(POS, sqlCondition, x);
- }
- }
- return sqlCondition;
-
- case EQUALS:
- case IS_NOT_DISTINCT_FROM:
- case NOT_EQUALS:
- case GREATER_THAN:
- case GREATER_THAN_OR_EQUAL:
- case LESS_THAN:
- case LESS_THAN_OR_EQUAL:
- case LIKE:
- node = stripCastFromString(node, dialect);
- operands = ((RexCall) node).getOperands();
- op = ((RexCall) node).getOperator();
- if (operands.size() == 2
- && operands.get(0) instanceof RexInputRef
- && operands.get(1) instanceof RexInputRef) {
- final RexInputRef op0 = (RexInputRef) operands.get(0);
- final RexInputRef op1 = (RexInputRef) operands.get(1);
-
- if (op0.getIndex() < leftFieldCount
- && op1.getIndex() >= leftFieldCount) {
- // Arguments were of form 'op0 = op1'
- return op.createCall(POS,
- leftContext.field(op0.getIndex()),
- rightContext.field(op1.getIndex() - leftFieldCount));
- }
- if (op1.getIndex() < leftFieldCount
- && op0.getIndex() >= leftFieldCount) {
- // Arguments were of form 'op1 = op0'
- return reverseOperatorDirection(op).createCall(POS,
- leftContext.field(op1.getIndex()),
- rightContext.field(op0.getIndex() - leftFieldCount));
- }
- }
- joinContext =
- leftContext.implementor().joinContext(leftContext, rightContext);
- return joinContext.toSql(null, node);
- case IS_NULL:
- case IS_NOT_NULL:
- operands = ((RexCall) node).getOperands();
- if (operands.size() == 1
- && operands.get(0) instanceof RexInputRef) {
- op = ((RexCall) node).getOperator();
- final RexInputRef op0 = (RexInputRef) operands.get(0);
- if (op0.getIndex() < leftFieldCount) {
- return op.createCall(POS, leftContext.field(op0.getIndex()));
- } else {
- return op.createCall(POS,
- rightContext.field(op0.getIndex() - leftFieldCount));
- }
- }
- joinContext =
- leftContext.implementor().joinContext(leftContext, rightContext);
- return joinContext.toSql(null, node);
- default:
- throw new AssertionError(node);
- }
Review comment:
`throw new AssertionError(node)` might show that some operators are not
supported. Am I right? What I mean by 'negative cases' is add such a test case.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services