|
5 | 5 |
|
6 | 6 | package org.opensearch.sql.calcite; |
7 | 7 |
|
| 8 | +import static org.opensearch.sql.calcite.utils.OpenSearchTypeFactory.ExprUDT.EXPR_DATE; |
| 9 | +import static org.opensearch.sql.calcite.utils.OpenSearchTypeFactory.ExprUDT.EXPR_TIME; |
| 10 | +import static org.opensearch.sql.calcite.utils.OpenSearchTypeFactory.ExprUDT.EXPR_TIMESTAMP; |
| 11 | + |
8 | 12 | import com.google.common.collect.ImmutableList; |
9 | 13 | import java.util.Arrays; |
10 | 14 | import java.util.List; |
| 15 | +import java.util.Set; |
11 | 16 | import org.apache.calcite.avatica.util.TimeUnit; |
12 | 17 | import org.apache.calcite.rel.type.RelDataType; |
13 | 18 | import org.apache.calcite.rex.RexBuilder; |
|
19 | 24 | import org.apache.calcite.sql.type.SqlTypeName; |
20 | 25 | import org.apache.calcite.sql.type.SqlTypeUtil; |
21 | 26 | import org.opensearch.sql.ast.expression.SpanUnit; |
| 27 | +import org.opensearch.sql.calcite.type.ExprSqlType; |
| 28 | +import org.opensearch.sql.expression.function.PPLBuiltinOperators; |
22 | 29 |
|
23 | 30 | public class ExtendedRexBuilder extends RexBuilder { |
24 | 31 |
|
@@ -117,6 +124,16 @@ public RexNode makeCast( |
117 | 124 | // SqlStdOperatorTable.NOT_EQUALS, |
118 | 125 | // ImmutableList.of(exp, makeZeroLiteral(exp.getType()))); |
119 | 126 | } |
| 127 | + } else if (type instanceof ExprSqlType exprSqlType |
| 128 | + && Set.of(EXPR_DATE, EXPR_TIME, EXPR_TIMESTAMP).contains(exprSqlType.getUdt())) { |
| 129 | + switch (exprSqlType.getUdt()) { |
| 130 | + case EXPR_DATE: |
| 131 | + return makeCall(type, PPLBuiltinOperators.DATE, List.of(exp)); |
| 132 | + case EXPR_TIME: |
| 133 | + return makeCall(type, PPLBuiltinOperators.TIME, List.of(exp)); |
| 134 | + case EXPR_TIMESTAMP: |
| 135 | + return makeCall(type, PPLBuiltinOperators.TIMESTAMP, List.of(exp)); |
| 136 | + } |
120 | 137 | } |
121 | 138 | return super.makeCast(pos, type, exp, matchNullability, safe, format); |
122 | 139 | } |
|
0 commit comments