|
9 | 9 | import static org.apache.calcite.sql.SqlKind.AS; |
10 | 10 | import static org.opensearch.sql.ast.expression.SpanUnit.NONE; |
11 | 11 | import static org.opensearch.sql.ast.expression.SpanUnit.UNKNOWN; |
12 | | -import static org.opensearch.sql.calcite.utils.BuiltinFunctionUtils.VARCHAR_FORCE_NULLABLE; |
13 | | -import static org.opensearch.sql.calcite.utils.UserDefinedFunctionUtils.TransferUserDefinedFunction; |
14 | 12 |
|
15 | 13 | import java.math.BigDecimal; |
16 | 14 | import java.util.ArrayList; |
17 | 15 | import java.util.Collections; |
18 | 16 | import java.util.List; |
19 | | -import java.util.stream.Collectors; |
20 | 17 | import lombok.RequiredArgsConstructor; |
21 | 18 | import org.apache.calcite.rel.RelNode; |
22 | 19 | import org.apache.calcite.rel.type.RelDataType; |
|
25 | 22 | import org.apache.calcite.rex.RexCall; |
26 | 23 | import org.apache.calcite.rex.RexNode; |
27 | 24 | import org.apache.calcite.sql.SqlIntervalQualifier; |
28 | | -import org.apache.calcite.sql.SqlOperator; |
29 | 25 | import org.apache.calcite.sql.fun.SqlStdOperatorTable; |
30 | 26 | import org.apache.calcite.sql.type.SqlTypeName; |
31 | 27 | import org.apache.calcite.util.DateString; |
|
60 | 56 | import org.opensearch.sql.ast.expression.subquery.ScalarSubquery; |
61 | 57 | import org.opensearch.sql.ast.tree.UnresolvedPlan; |
62 | 58 | import org.opensearch.sql.calcite.type.ExprSqlType; |
63 | | -import org.opensearch.sql.calcite.udf.datetimeUDF.PostprocessDateToStringFunction; |
64 | | -import org.opensearch.sql.calcite.utils.BuiltinFunctionUtils; |
65 | 59 | import org.opensearch.sql.calcite.utils.OpenSearchTypeFactory; |
66 | 60 | import org.opensearch.sql.calcite.utils.PlanUtils; |
67 | 61 | import org.opensearch.sql.common.utils.StringUtils; |
68 | 62 | import org.opensearch.sql.data.type.ExprType; |
69 | 63 | import org.opensearch.sql.exception.CalciteUnsupportedException; |
70 | 64 | import org.opensearch.sql.exception.SemanticCheckException; |
71 | 65 | import org.opensearch.sql.expression.function.BuiltinFunctionName; |
| 66 | +import org.opensearch.sql.expression.function.PPLBuiltinOperators; |
72 | 67 | import org.opensearch.sql.expression.function.PPLFuncImpTable; |
73 | 68 |
|
74 | 69 | @RequiredArgsConstructor |
@@ -220,18 +215,8 @@ public RexNode visitCompare(Compare node, CalcitePlanContext context) { |
220 | 215 | private RexNode transferCompareForDateRelated( |
221 | 216 | RexNode candidate, CalcitePlanContext context, boolean whetherCompareByTime) { |
222 | 217 | if (whetherCompareByTime) { |
223 | | - SqlOperator postToStringNode = |
224 | | - TransferUserDefinedFunction( |
225 | | - PostprocessDateToStringFunction.class, |
226 | | - "PostprocessDateToString", |
227 | | - VARCHAR_FORCE_NULLABLE); |
228 | 218 | RexNode transferredStringNode = |
229 | | - context.rexBuilder.makeCall( |
230 | | - postToStringNode, |
231 | | - List.of( |
232 | | - candidate, |
233 | | - context.rexBuilder.makeLiteral( |
234 | | - context.functionProperties.getQueryStartClock().instant().toString()))); |
| 219 | + context.rexBuilder.makeCall(PPLBuiltinOperators.TIMESTAMP, candidate); |
235 | 220 | return transferredStringNode; |
236 | 221 | } else { |
237 | 222 | return candidate; |
@@ -351,26 +336,14 @@ public RexNode visitLet(Let node, CalcitePlanContext context) { |
351 | 336 | @Override |
352 | 337 | public RexNode visitFunction(Function node, CalcitePlanContext context) { |
353 | 338 | List<RexNode> arguments = |
354 | | - node.getFuncArgs().stream().map(arg -> analyze(arg, context)).collect(Collectors.toList()); |
| 339 | + node.getFuncArgs().stream().map(arg -> analyze(arg, context)).toList(); |
355 | 340 | RexNode resolvedNode = |
356 | 341 | PPLFuncImpTable.INSTANCE.resolveSafe( |
357 | 342 | context.rexBuilder, node.getFuncName(), arguments.toArray(new RexNode[0])); |
358 | 343 | if (resolvedNode != null) { |
359 | 344 | return resolvedNode; |
360 | 345 | } |
361 | | - // TODO: Remove below code after migrating all functions to PPLFuncImpTable, |
362 | | - // https://github.com/opensearch-project/sql/issues/3524 |
363 | | - SqlOperator operator = BuiltinFunctionUtils.translate(node.getFuncName()); |
364 | | - List<RexNode> translatedArguments = |
365 | | - BuiltinFunctionUtils.translateArgument( |
366 | | - node.getFuncName(), |
367 | | - arguments, |
368 | | - context, |
369 | | - context.functionProperties.getQueryStartClock().instant().toString()); |
370 | | - RelDataType returnType = |
371 | | - BuiltinFunctionUtils.deriveReturnType( |
372 | | - node.getFuncName(), context.rexBuilder, operator, translatedArguments); |
373 | | - return context.rexBuilder.makeCall(returnType, operator, translatedArguments); |
| 346 | + throw new IllegalArgumentException("Unsupported operator: " + node.getFuncName()); |
374 | 347 | } |
375 | 348 |
|
376 | 349 | @Override |
|
0 commit comments