|
214 | 214 |
|
215 | 215 | import com.google.common.collect.ImmutableList; |
216 | 216 | import com.google.common.collect.ImmutableMap; |
217 | | -import java.math.BigDecimal; |
218 | 217 | import java.util.ArrayList; |
219 | 218 | import java.util.Arrays; |
220 | 219 | import java.util.HashMap; |
@@ -332,6 +331,18 @@ default PPLTypeChecker getTypeChecker() { |
332 | 331 | final AggBuilder aggBuilder = new AggBuilder(); |
333 | 332 | aggBuilder.populate(); |
334 | 333 | INSTANCE = new PPLFuncImpTable(builder, aggBuilder); |
| 334 | + |
| 335 | + // Some operators are registered via register instead of registerOperator |
| 336 | + // We add them explicitly so that they can be found during validation |
| 337 | + var pplOps = PplOpTable.getInstance(); |
| 338 | + pplOps.add(JSON_ARRAY, SqlStdOperatorTable.JSON_ARRAY); |
| 339 | + pplOps.add(JSON_OBJECT, SqlStdOperatorTable.JSON_OBJECT); |
| 340 | + pplOps.add(INTERNAL_ITEM, SqlStdOperatorTable.ITEM); |
| 341 | + // pplOps.add(TYPEOF, ... ); |
| 342 | + pplOps.add(IF, SqlStdOperatorTable.CASE); |
| 343 | + pplOps.add(NULLIF, SqlStdOperatorTable.CASE); |
| 344 | + pplOps.add(IS_EMPTY, SqlStdOperatorTable.IS_EMPTY); |
| 345 | + pplOps.add(IS_BLANK, SqlStdOperatorTable.IS_EMPTY); |
335 | 346 | } |
336 | 347 |
|
337 | 348 | /** |
@@ -535,7 +546,9 @@ private static void registerToCatalogWithReplace( |
535 | 546 | TRIM, |
536 | 547 | SqlStdOperatorTable.TRIM, |
537 | 548 | STRCMP, |
538 | | - SqlLibraryOperators.STRCMP); |
| 549 | + SqlLibraryOperators.STRCMP, |
| 550 | + XOR, |
| 551 | + SqlStdOperatorTable.NOT_EQUALS); |
539 | 552 | PplOpTable.getInstance().add(functionName, replacement.getOrDefault(functionName, operator)); |
540 | 553 | } |
541 | 554 |
|
@@ -720,6 +733,9 @@ void populate() { |
720 | 733 | registerOperator(CRC32, PPLBuiltinOperators.CRC32); |
721 | 734 | registerOperator(DIVIDE, PPLBuiltinOperators.DIVIDE); |
722 | 735 | registerOperator(DIVIDEFUNCTION, PPLBuiltinOperators.DIVIDE); |
| 736 | + // SqlStdOperatorTable.SQRT is declared but not implemented. The call to SQRT in Calcite is |
| 737 | + // converted to POWER(x, 0.5). |
| 738 | + registerOperator(SQRT, PPLBuiltinOperators.SQRT); |
723 | 739 | registerOperator(SHA2, PPLBuiltinOperators.SHA2); |
724 | 740 | registerOperator(CIDRMATCH, PPLBuiltinOperators.CIDRMATCH); |
725 | 741 | registerOperator(INTERNAL_GROK, PPLBuiltinOperators.GROK); |
@@ -860,23 +876,12 @@ void populate() { |
860 | 876 | OperandTypes.family(SqlTypeFamily.ARRAY, SqlTypeFamily.INTEGER) |
861 | 877 | .or(OperandTypes.family(SqlTypeFamily.MAP, SqlTypeFamily.ANY)), |
862 | 878 | false)); |
863 | | - // SqlStdOperatorTable.SQRT is declared but not implemented. The call to SQRT in Calcite is |
864 | | - // converted to POWER(x, 0.5). |
865 | | - register( |
866 | | - SQRT, |
867 | | - createFunctionImpWithTypeChecker( |
868 | | - (builder, arg) -> |
869 | | - builder.makeCall( |
870 | | - SqlStdOperatorTable.POWER, |
871 | | - arg, |
872 | | - builder.makeApproxLiteral(BigDecimal.valueOf(0.5))), |
873 | | - PPLTypeChecker.family(SqlTypeFamily.NUMERIC))); |
874 | 879 | register( |
875 | 880 | TYPEOF, |
876 | 881 | (FunctionImp1) |
877 | 882 | (builder, arg) -> |
878 | 883 | builder.makeLiteral(getLegacyTypeName(arg.getType(), QueryType.PPL))); |
879 | | - register(XOR, new XOR_FUNC()); |
| 884 | + registerOperator(XOR, PPLBuiltinOperators.XOR); |
880 | 885 | // SqlStdOperatorTable.CASE.getOperandTypeChecker is null. We manually create a type checker |
881 | 886 | // for it. The second and third operands are required to be of the same type. If not, |
882 | 887 | // it will throw an IllegalArgumentException with information Can't find leastRestrictive type |
|
0 commit comments