17 package com.mapd.calcite.parser;
21 import static org.apache.calcite.util.Static.RESOURCE;
23 import com.google.common.base.Predicate;
24 import com.google.common.collect.ImmutableList;
25 import com.google.common.collect.Multimap;
31 import org.apache.calcite.linq4j.Ord;
32 import org.apache.calcite.rel.metadata.RelColumnMapping;
33 import org.apache.calcite.rel.type.RelDataType;
34 import org.apache.calcite.rel.type.RelDataTypeFactory;
35 import org.apache.calcite.rel.type.RelDataTypeFactory.FieldInfoBuilder;
36 import org.apache.calcite.rel.type.RelDataTypeFamily;
37 import org.apache.calcite.runtime.Resources;
38 import org.apache.calcite.runtime.Resources.BaseMessage;
39 import org.apache.calcite.runtime.Resources.ExInst;
40 import org.apache.calcite.schema.FunctionParameter;
41 import org.apache.calcite.sql.SqlAggFunction;
42 import org.apache.calcite.sql.SqlBasicCall;
43 import org.apache.calcite.sql.SqlCall;
44 import org.apache.calcite.sql.SqlCallBinding;
45 import org.apache.calcite.sql.SqlDynamicParam;
46 import org.apache.calcite.sql.SqlFunction;
47 import org.apache.calcite.sql.SqlFunctionCategory;
48 import org.apache.calcite.sql.SqlIdentifier;
49 import org.apache.calcite.sql.SqlIntervalQualifier;
50 import org.apache.calcite.sql.SqlKind;
51 import org.apache.calcite.sql.SqlLiteral;
52 import org.apache.calcite.sql.SqlNode;
53 import org.apache.calcite.sql.SqlOperandCountRange;
55 import org.apache.calcite.sql.SqlOperatorBinding;
56 import org.apache.calcite.sql.SqlOperatorTable;
57 import org.apache.calcite.sql.SqlSyntax;
58 import org.apache.calcite.sql.SqlTableFunction;
59 import org.apache.calcite.sql.SqlUtil;
60 import org.apache.calcite.sql.SqlWriter;
61 import org.apache.calcite.sql.fun.SqlArrayValueConstructor;
62 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
63 import org.apache.calcite.sql.parser.SqlParserPos;
64 import org.apache.calcite.sql.type.InferTypes;
65 import org.apache.calcite.sql.type.OperandTypes;
66 import org.apache.calcite.sql.type.ReturnTypes;
67 import org.apache.calcite.sql.type.SameOperandTypeChecker;
68 import org.apache.calcite.sql.type.SqlOperandCountRanges;
69 import org.apache.calcite.sql.type.SqlReturnTypeInference;
70 import org.apache.calcite.sql.type.SqlTypeFamily;
71 import org.apache.calcite.sql.type.SqlTypeName;
72 import org.apache.calcite.sql.type.SqlTypeTransforms;
73 import org.apache.calcite.sql.type.SqlTypeUtil;
74 import org.apache.calcite.sql.util.ChainedSqlOperatorTable;
75 import org.apache.calcite.sql.util.ListSqlOperatorTable;
76 import org.apache.calcite.sql.util.ReflectiveSqlOperatorTable;
77 import org.apache.calcite.sql.validate.SqlNameMatcher;
78 import org.apache.calcite.sql.validate.SqlValidator;
79 import org.apache.calcite.sql.validate.SqlValidatorException;
81 import org.apache.calcite.sql.validate.SqlValidatorScope;
82 import org.apache.calcite.util.Optionality;
83 import org.checkerframework.checker.nullness.qual.Nullable;
84 import org.slf4j.Logger;
85 import org.slf4j.LoggerFactory;
87 import java.lang.reflect.Field;
88 import java.util.Arrays;
89 import java.util.EnumSet;
90 import java.util.HashSet;
91 import java.util.Iterator;
92 import java.util.List;
93 import java.util.Locale;
96 import java.util.stream.Collectors;
101 SqlFunctionCategory category,
103 List<SqlOperator> operatorList,
104 SqlNameMatcher nameMatcher) {
105 for (
SqlOperator operator : this.getOperatorList()) {
106 if (
operator.getSyntax() != syntax) {
109 if (!opName.isSimple()
110 || !nameMatcher.matches(operator.getName(), opName.getSimple())) {
113 SqlFunctionCategory functionCategory;
114 if (
operator instanceof SqlFunction) {
115 functionCategory = ((SqlFunction)
operator).getFunctionType();
117 functionCategory = SqlFunctionCategory.SYSTEM;
119 if (category != functionCategory
120 && category != SqlFunctionCategory.USER_DEFINED_FUNCTION) {
123 operatorList.add(
operator);
137 Field
f = ReflectiveSqlOperatorTable.class.getDeclaredField(
138 "caseSensitiveOperators");
139 f.setAccessible(
true);
140 Multimap operators = (Multimap) f.get(SqlStdOperatorTable.instance());
141 for (Iterator i = operators.entries().iterator(); i.hasNext();) {
142 Map.Entry entry = (Map.Entry) i.next();
143 if (entry.getValue() == SqlStdOperatorTable.APPROX_COUNT_DISTINCT
144 || entry.getValue() == SqlStdOperatorTable.AVG
145 || entry.getValue() == SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR) {
152 Field f = ReflectiveSqlOperatorTable.class.getDeclaredField(
153 "caseInsensitiveOperators");
154 f.setAccessible(
true);
155 Multimap operators = (Multimap) f.get(SqlStdOperatorTable.instance());
156 for (Iterator i = operators.entries().iterator(); i.hasNext();) {
157 Map.Entry entry = (Map.Entry) i.next();
158 if (entry.getValue() == SqlStdOperatorTable.APPROX_COUNT_DISTINCT
159 || entry.getValue() == SqlStdOperatorTable.AVG
160 || entry.getValue() == SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR) {
168 }
catch (Exception e) {
169 throw new RuntimeException(e);
177 LoggerFactory.getLogger(HeavyDBSqlOperatorTable.class);
189 listOpTab = (ListSqlOperatorTable) tableList.get(1);
201 public void addUDF(
final Map<String, ExtensionFunction> extSigs) {
321 if (extSigs == null) {
324 HashSet<String> demangledNames =
new HashSet<String>();
326 final String demangledName =
dropSuffix(extSig.getKey());
327 final String demangledNameArity = extSig.getValue().isTableUdf()
328 ? String.format(
"%s-%s-%s",
330 extSig.getValue().getArgs(),
331 extSig.getValue().getCursorFieldTypes())
332 : String.format(
"%s-%d", demangledName, extSig.getValue().getArgs().size());
333 if (demangledNames.contains(demangledNameArity)) {
336 demangledNames.add(demangledNameArity);
337 if (extSig.getValue().isRowUdf()) {
346 int suffix_idx = str.indexOf(
"__");
347 if (suffix_idx == -1) {
350 assert suffix_idx > 0;
351 return str.substring(0, suffix_idx);
361 extends SqlArrayValueConstructor {
364 RelDataTypeFactory typeFactory, List<RelDataType> argTypes) {
365 if (argTypes.isEmpty()) {
366 return typeFactory.createSqlType(SqlTypeName.NULL);
368 return super.getComponentType(typeFactory, argTypes);
373 if (callBinding.operands().isEmpty()) {
376 return super.checkOperandTypes(callBinding, throwOnFailure);
386 SqlKind.OTHER_FUNCTION,
389 OperandTypes.NUMERIC,
390 SqlFunctionCategory.USER_DEFINED_FUNCTION);
395 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
396 return typeFactory.builder().add(
"I", SqlTypeName.INTEGER).build();
406 SqlKind.OTHER_FUNCTION,
409 OperandTypes.VARIADIC,
410 SqlFunctionCategory.USER_DEFINED_FUNCTION);
415 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
416 return typeFactory.builder().add(
"NAME", SqlTypeName.VARCHAR, 1024).build();
427 SqlKind.OTHER_FUNCTION,
430 OperandTypes.STRING_STRING,
431 SqlFunctionCategory.SYSTEM);
436 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
437 return typeFactory.createSqlType(SqlTypeName.BIGINT);
445 SqlKind.OTHER_FUNCTION,
449 SqlFunctionCategory.SYSTEM);
454 assert opBinding.getOperandCount() == 1;
455 RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
456 assert elem_type != null;
462 public static class Any extends SqlFunction {
465 SqlKind.OTHER_FUNCTION,
469 SqlFunctionCategory.SYSTEM);
474 assert opBinding.getOperandCount() == 1;
475 RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
476 assert elem_type != null;
482 public static class All extends SqlFunction {
485 SqlKind.OTHER_FUNCTION,
489 SqlFunctionCategory.SYSTEM);
494 assert opBinding.getOperandCount() == 1;
495 RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
496 assert elem_type != null;
502 public static class Now extends SqlFunction {
505 SqlKind.OTHER_FUNCTION,
508 OperandTypes.NILADIC,
509 SqlFunctionCategory.SYSTEM);
514 assert opBinding.getOperandCount() == 0;
515 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
516 return typeFactory.createSqlType(SqlTypeName.TIMESTAMP);
524 SqlKind.OTHER_FUNCTION,
528 SqlFunctionCategory.SYSTEM);
533 assert opBinding.getOperandCount() == 1;
534 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
535 return typeFactory.createSqlType(
536 SqlTypeName.TIMESTAMP, opBinding.getOperandType(0).getPrecision());
544 SqlKind.OTHER_FUNCTION,
547 OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
548 SqlFunctionCategory.SYSTEM);
553 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
554 return typeFactory.createTypeWithNullability(
555 typeFactory.createSqlType(SqlTypeName.BIGINT),
556 opBinding.getOperandType(1).isNullable());
563 SqlKind.OTHER_FUNCTION,
566 OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
567 SqlFunctionCategory.TIMEDATE);
572 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
573 return typeFactory.createTypeWithNullability(
574 typeFactory.createSqlType(SqlTypeName.BIGINT),
575 opBinding.getOperandType(1).isNullable());
579 public static class Dateadd extends SqlFunction {
582 SqlKind.OTHER_FUNCTION,
585 OperandTypes.family(SqlTypeFamily.STRING,
586 SqlTypeFamily.INTEGER,
587 SqlTypeFamily.DATETIME),
588 SqlFunctionCategory.TIMEDATE);
593 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
594 return typeFactory.createTypeWithNullability(
595 typeFactory.createSqlType(
596 SqlTypeName.TIMESTAMP, opBinding.getOperandType(2).getPrecision()),
597 opBinding.getOperandType(2).isNullable());
604 SqlKind.OTHER_FUNCTION,
607 OperandTypes.family(SqlTypeFamily.STRING,
608 SqlTypeFamily.DATETIME,
609 SqlTypeFamily.DATETIME),
610 SqlFunctionCategory.TIMEDATE);
615 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
616 return typeFactory.createTypeWithNullability(
617 typeFactory.createSqlType(SqlTypeName.BIGINT),
618 opBinding.getOperandType(1).isNullable()
619 || opBinding.getOperandType(2).isNullable());
626 super(
"PG_DATE_TRUNC",
627 SqlKind.OTHER_FUNCTION,
630 OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
631 SqlFunctionCategory.SYSTEM);
636 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
637 return typeFactory.createTypeWithNullability(
638 typeFactory.createSqlType(
639 SqlTypeName.TIMESTAMP, opBinding.getOperandType(1).getPrecision()),
640 opBinding.getOperandType(1).isNullable());
644 public static class Length extends SqlFunction {
647 SqlKind.OTHER_FUNCTION,
651 SqlFunctionCategory.SYSTEM);
656 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
657 return typeFactory.createSqlType(SqlTypeName.INTEGER);
664 SqlKind.OTHER_FUNCTION,
668 SqlFunctionCategory.SYSTEM);
673 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
674 return typeFactory.createSqlType(SqlTypeName.INTEGER);
680 super(
"KEY_FOR_STRING",
681 SqlKind.OTHER_FUNCTION,
685 SqlFunctionCategory.SYSTEM);
690 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
691 return typeFactory.createTypeWithNullability(
692 typeFactory.createSqlType(SqlTypeName.INTEGER),
693 opBinding.getOperandType(0).isNullable());
699 super(
"SAMPLE_RATIO",
700 SqlKind.OTHER_FUNCTION,
704 SqlFunctionCategory.SYSTEM);
709 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
710 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
713 private static java.util.List<SqlTypeFamily>
signature() {
714 java.util.ArrayList<SqlTypeFamily> families =
715 new java.util.ArrayList<SqlTypeFamily>();
716 families.add(SqlTypeFamily.NUMERIC);
723 super(
"WIDTH_BUCKET",
724 SqlKind.OTHER_FUNCTION,
728 SqlFunctionCategory.SYSTEM);
733 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
734 return typeFactory.createTypeWithNullability(
735 typeFactory.createSqlType(SqlTypeName.INTEGER),
true);
738 private static java.util.List<SqlTypeFamily>
signature() {
739 java.util.ArrayList<SqlTypeFamily> families =
740 new java.util.ArrayList<SqlTypeFamily>();
741 families.add(SqlTypeFamily.NUMERIC);
742 families.add(SqlTypeFamily.NUMERIC);
743 families.add(SqlTypeFamily.NUMERIC);
744 families.add(SqlTypeFamily.INTEGER);
752 SqlKind.OTHER_FUNCTION,
756 SqlFunctionCategory.SYSTEM);
761 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
762 return typeFactory.createTypeWithNullability(
763 typeFactory.createSqlType(SqlTypeName.DOUBLE),
true);
768 return SqlOperandCountRanges.from(2);
777 final SqlValidator validator = callBinding.getValidator();
779 final int num_operands = callBinding.getOperandCount();
780 if (num_operands < 2) {
781 throw new IllegalArgumentException(
782 "At least 2 arguments are required, the model name and one or more predictors.");
784 for (
int operand_idx = 0; operand_idx < num_operands; operand_idx++) {
785 final SqlNode operand = callBinding.operand(operand_idx);
786 final SqlTypeName operand_type =
787 validator.getValidatedNodeType(operand).getSqlTypeName();
788 final SqlTypeFamily operand_type_family = operand_type.getFamily();
789 if (operand_idx == 0) {
790 if (!operand.isA(EnumSet.of(SqlKind.LITERAL))
791 || operand_type_family != SqlTypeFamily.CHARACTER) {
792 throw new IllegalArgumentException(
793 "First argument must be TEXT literal denoting the model name.");
796 if (operand.isA(EnumSet.of(SqlKind.LITERAL))) {
797 throw new IllegalArgumentException(
798 "Literals are not supported as predictors.");
800 if (!(operand_type_family == SqlTypeFamily.NUMERIC
801 || operand_type_family == SqlTypeFamily.CHARACTER)) {
802 throw new IllegalArgumentException(
803 "Only TEXT and NUMERIC predictors are supported.");
814 SqlKind.OTHER_FUNCTION,
818 SqlFunctionCategory.SYSTEM);
823 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
824 return typeFactory.createTypeWithNullability(
825 typeFactory.createSqlType(SqlTypeName.DOUBLE),
true);
830 return SqlOperandCountRanges.from(3);
840 final SqlValidator validator = callBinding.getValidator();
842 final int num_operands = callBinding.getOperandCount();
843 if (num_operands < 3) {
844 throw new IllegalArgumentException(
845 "At least 3 arguments are required, the model name, one or more features, and the nth principal component to project to.");
847 for (
int operand_idx = 0; operand_idx < num_operands; operand_idx++) {
848 final SqlNode operand = callBinding.operand(operand_idx);
849 final SqlTypeName operand_type =
850 validator.getValidatedNodeType(operand).getSqlTypeName();
851 final SqlTypeFamily operand_type_family = operand_type.getFamily();
852 if (operand_idx == 0) {
853 if (!operand.isA(EnumSet.of(SqlKind.LITERAL))
854 || operand_type_family != SqlTypeFamily.CHARACTER) {
855 throw new IllegalArgumentException(
856 "First argument must be TEXT literal denoting the model name.");
858 }
else if (operand_idx < num_operands - 1) {
859 if (operand.isA(EnumSet.of(SqlKind.LITERAL))) {
860 throw new IllegalArgumentException(
"Literals are not supported as features.");
862 if (!(operand_type_family == SqlTypeFamily.NUMERIC
863 || operand_type_family == SqlTypeFamily.CHARACTER)) {
864 throw new IllegalArgumentException(
865 "Only TEXT and NUMERIC features are supported.");
867 }
else if (!operand.isA(EnumSet.of(SqlKind.LITERAL))
868 || !(operand_type_family == SqlTypeFamily.NUMERIC)
869 || !(operand_type.equals(SqlTypeName.INTEGER))) {
870 throw new IllegalArgumentException(
871 "Last argument to PCA_PROJECT expects integer literal dimension index.");
880 super(
"LEAD_IN_FRAME", SqlKind.LEAD);
886 super(
"LAG_IN_FRAME", SqlKind.LAG);
892 super(
"NTH_VALUE_IN_FRAME");
898 super(
"FIRST_VALUE_IN_FRAME", SqlKind.FIRST_VALUE);
904 super(
"LAST_VALUE_IN_FRAME", SqlKind.LAST_VALUE);
910 super(
"ARRAY_LENGTH",
911 SqlKind.OTHER_FUNCTION,
915 SqlFunctionCategory.SYSTEM);
920 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
921 return typeFactory.createSqlType(SqlTypeName.INTEGER);
926 SqlValidator validator,
927 SqlValidatorScope scope,
928 SqlValidatorScope operandScope) {
929 for (
int i = 0; i < call.operandCount(); ++i) {
930 SqlNode operand = call.operand(i);
931 if (operand instanceof SqlCall) {
932 SqlCall operand_call = (SqlCall) operand;
933 SqlOperator call_oper = operand_call.getOperator();
934 if (call_oper instanceof SqlFunction) {
935 SqlFunction call_func = (SqlFunction) call_oper;
936 if (call_func.getFunctionType()
937 == SqlFunctionCategory.USER_DEFINED_FUNCTION) {
942 throw validator.newValidationError(
943 call, _ERRORS.illegalArrayLengthCall(call.toString()));
948 super.validateCall(call, validator, scope, operandScope);
952 @BaseMessage(
"Illegal argument to 'ARRAY_LENGTH': ''{0}''")
957 Resources.create(ArrayLengthErrors.class);
960 public static class PgILike extends SqlFunction {
963 SqlKind.OTHER_FUNCTION,
967 SqlFunctionCategory.SYSTEM);
971 java.util.ArrayList<SqlTypeFamily> families =
972 new java.util.ArrayList<SqlTypeFamily>();
980 implements java.util.function.Predicate<Integer>, Predicate<Integer> {
982 public boolean test(Integer t) {
994 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
995 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1001 super(
"REGEXP_LIKE",
1002 SqlKind.OTHER_FUNCTION,
1006 SqlFunctionCategory.SYSTEM);
1010 java.util.ArrayList<SqlTypeFamily> families =
1011 new java.util.ArrayList<SqlTypeFamily>();
1019 implements java.util.function.Predicate<Integer>, Predicate<Integer> {
1032 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1033 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1041 ReturnTypes.ARG0.andThen(SqlTypeTransforms.TO_NULLABLE)
1042 .andThen(SqlTypeTransforms.TO_VARYING),
1045 OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.STRING),
1046 new SameOperandTypeChecker(2) {
1048 protected List<Integer> getOperandList(
int operandCount) {
1049 return ImmutableList.of(0, 1);
1052 SqlFunctionCategory.STRING);
1056 public SqlCall
createCall(@Nullable SqlLiteral functionQualifier,
1058 @Nullable SqlNode... operands) {
1059 assert functionQualifier == null;
1060 switch (operands.length) {
1062 operands =
new SqlNode[] {operands[0], SqlLiteral.createCharString(
" ", pos)};
1065 if (operands[1] == null) {
1066 operands[1] = SqlLiteral.createCharString(
" ", pos);
1068 operands =
new SqlNode[] {operands[0], operands[1]};
1071 throw new IllegalArgumentException(
1072 "Invalid operand count " + Arrays.toString(operands));
1074 return super.createCall(functionQualifier, pos, operands);
1080 return (operands.size() == 1);
1086 super(
"LTRIM", SqlKind.LTRIM);
1091 super(
"RTRIM", SqlKind.RTRIM);
1097 SqlKind.OTHER_FUNCTION,
1098 ReturnTypes.ARG0.andThen(SqlTypeTransforms.TO_NULLABLE)
1099 .andThen(SqlTypeTransforms.TO_VARYING),
1101 OperandTypes.and(OperandTypes.family(SqlTypeFamily.STRING,
1102 SqlTypeFamily.INTEGER,
1103 SqlTypeFamily.STRING),
1104 new SameOperandTypeChecker(3) {
1106 protected List<Integer> getOperandList(
int operandCount) {
1107 return ImmutableList.of(0, 2);
1110 SqlFunctionCategory.STRING);
1114 public SqlCall
createCall(@Nullable SqlLiteral functionQualifier,
1116 @Nullable SqlNode... operands) {
1117 assert functionQualifier == null;
1118 switch (operands.length) {
1120 operands =
new SqlNode[] {
1121 operands[0], operands[1], SqlLiteral.createCharString(
" ", pos)};
1124 if (operands[2] == null) {
1125 operands[2] = SqlLiteral.createCharString(
" ", pos);
1127 operands =
new SqlNode[] {operands[0], operands[1], operands[2]};
1130 throw new IllegalArgumentException(
1131 "Invalid operand count " + Arrays.toString(operands));
1133 return super.createCall(functionQualifier, pos, operands);
1138 if (!super.checkOperandTypes(callBinding, throwOnFailure)) {
1143 return SqlTypeUtil.isCharTypeComparable(callBinding,
1144 ImmutableList.of(callBinding.operand(0), callBinding.operand(2)),
1154 return (operands.size() == 2);
1172 SqlKind.OTHER_FUNCTION,
1175 OperandTypes.family(getSignatureFamilies()),
1180 java.util.ArrayList<SqlTypeFamily> families =
1181 new java.util.ArrayList<SqlTypeFamily>();
1184 families.add(SqlTypeFamily.INTEGER);
1190 return opBinding.getOperandType(0);
1197 SqlKind.OTHER_FUNCTION,
1200 OperandTypes.family(getSignatureFamilies()),
1205 java.util.ArrayList<SqlTypeFamily> families =
1206 new java.util.ArrayList<SqlTypeFamily>();
1215 return opBinding.getOperandType(0);
1219 public SqlCall
createCall(@Nullable SqlLiteral functionQualifier,
1221 @Nullable SqlNode... operands) {
1222 assert functionQualifier == null;
1223 switch (operands.length) {
1225 operands =
new SqlNode[] {
1226 operands[0], operands[1], SqlLiteral.createCharString(
"", pos)};
1231 throw new IllegalArgumentException(
1232 "Invalid operand count " + Arrays.toString(operands));
1234 return super.createCall(functionQualifier, pos, operands);
1240 return (operands.size() == 2);
1246 SqlKind.OTHER_FUNCTION,
1249 OperandTypes.family(getSignatureFamilies()),
1254 java.util.ArrayList<SqlTypeFamily> families =
1255 new java.util.ArrayList<SqlTypeFamily>();
1262 return opBinding.getOperandType(0);
1265 public static class Repeat extends SqlFunction {
1268 SqlKind.OTHER_FUNCTION,
1271 OperandTypes.family(getSignatureFamilies()),
1276 java.util.ArrayList<SqlTypeFamily> families =
1277 new java.util.ArrayList<SqlTypeFamily>();
1279 families.add(SqlTypeFamily.INTEGER);
1285 return opBinding.getOperandType(0);
1291 super(
"REGEXP_REPLACE",
1292 SqlKind.OTHER_FUNCTION,
1295 OperandTypes.family(getSignatureFamilies()),
1300 java.util.ArrayList<SqlTypeFamily> families =
1301 new java.util.ArrayList<SqlTypeFamily>();
1305 families.add(SqlTypeFamily.INTEGER);
1306 families.add(SqlTypeFamily.INTEGER);
1312 public SqlCall
createCall(@Nullable SqlLiteral functionQualifier,
1314 @Nullable SqlNode... operands) {
1315 assert functionQualifier == null;
1316 final int num_operands = operands.length;
1317 if (num_operands < 2 || num_operands > 6) {
1318 throw new IllegalArgumentException(
1319 "Invalid operand count " + Arrays.toString(operands));
1321 SqlNode[] new_operands =
new SqlNode[6];
1323 new_operands[0] = operands[0];
1325 new_operands[1] = operands[1];
1327 if (num_operands < 3 || operands[2] == null) {
1328 new_operands[2] = SqlLiteral.createCharString(
"", pos);
1330 new_operands[2] = operands[2];
1333 if (num_operands < 4 || operands[3] == null) {
1334 new_operands[3] = SqlLiteral.createExactNumeric(
"1", pos);
1336 new_operands[3] = operands[3];
1339 if (num_operands < 5 || operands[4] == null) {
1340 new_operands[4] = SqlLiteral.createExactNumeric(
"0", pos);
1342 new_operands[4] = operands[4];
1345 if (num_operands < 6 || operands[5] == null) {
1346 new_operands[5] = SqlLiteral.createCharString(
"c", pos);
1348 new_operands[5] = operands[5];
1350 return super.createCall(functionQualifier, pos, new_operands);
1355 return opBinding.getOperandType(0);
1361 super(
"REGEXP_SUBSTR",
1362 SqlKind.OTHER_FUNCTION,
1365 OperandTypes.family(getSignatureFamilies()),
1371 SqlKind.OTHER_FUNCTION,
1374 OperandTypes.family(getSignatureFamilies()),
1375 SqlFunctionCategory.SYSTEM);
1379 java.util.ArrayList<SqlTypeFamily> families =
1380 new java.util.ArrayList<SqlTypeFamily>();
1383 families.add(SqlTypeFamily.INTEGER);
1384 families.add(SqlTypeFamily.INTEGER);
1386 families.add(SqlTypeFamily.INTEGER);
1391 public SqlCall
createCall(@Nullable SqlLiteral functionQualifier,
1393 @Nullable SqlNode... operands) {
1394 assert functionQualifier == null;
1395 final int num_operands = operands.length;
1396 if (num_operands < 2 || num_operands > 6) {
1397 throw new IllegalArgumentException(
1398 "Invalid operand count " + Arrays.toString(operands));
1400 SqlNode[] new_operands =
new SqlNode[6];
1403 new_operands[0] = operands[0];
1405 new_operands[1] = operands[1];
1407 if (num_operands < 3 || operands[2] == null) {
1408 new_operands[2] = SqlLiteral.createExactNumeric(
"1", pos);
1410 new_operands[2] = operands[2];
1413 if (num_operands < 4 || operands[3] == null) {
1414 new_operands[3] = SqlLiteral.createExactNumeric(
"1", pos);
1416 new_operands[3] = operands[3];
1419 if (num_operands < 5 || operands[4] == null) {
1420 new_operands[4] = SqlLiteral.createCharString(
"c", pos);
1422 new_operands[4] = operands[4];
1425 if (num_operands < 6 || operands[5] == null) {
1426 new_operands[5] = SqlLiteral.createExactNumeric(
"1", pos);
1428 new_operands[5] = operands[5];
1430 return super.createCall(functionQualifier, pos, new_operands);
1435 return opBinding.getOperandType(0);
1441 super(
"REGEXP_MATCH");
1446 super(
"BASE64_ENCODE",
1447 SqlKind.OTHER_FUNCTION,
1450 OperandTypes.family(getSignatureFamilies()),
1455 java.util.ArrayList<SqlTypeFamily> families =
1456 new java.util.ArrayList<SqlTypeFamily>();
1463 return opBinding.getOperandType(0);
1469 super(
"BASE64_DECODE",
1470 SqlKind.OTHER_FUNCTION,
1473 OperandTypes.family(getSignatureFamilies()),
1478 java.util.ArrayList<SqlTypeFamily> families =
1479 new java.util.ArrayList<SqlTypeFamily>();
1486 return opBinding.getOperandType(0);
1492 super(
"JAROWINKLER_SIMILARITY",
1493 SqlKind.OTHER_FUNCTION,
1496 OperandTypes.family(getSignatureFamilies()),
1501 java.util.ArrayList<SqlTypeFamily> families =
1502 new java.util.ArrayList<SqlTypeFamily>();
1510 assert opBinding.getOperandCount() == 2;
1511 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1512 return typeFactory.createSqlType(SqlTypeName.BIGINT);
1518 super(
"LEVENSHTEIN_DISTANCE",
1519 SqlKind.OTHER_FUNCTION,
1522 OperandTypes.family(getSignatureFamilies()),
1527 java.util.ArrayList<SqlTypeFamily> families =
1528 new java.util.ArrayList<SqlTypeFamily>();
1536 assert opBinding.getOperandCount() == 2;
1537 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1538 return typeFactory.createSqlType(SqlTypeName.BIGINT);
1547 SqlKind.OTHER_FUNCTION,
1549 InferTypes.FIRST_KNOWN,
1551 SqlFunctionCategory.SYSTEM);
1557 assert opBinding.getOperandCount() == 2;
1558 RelDataType ret = opBinding.getOperandType(1);
1559 RelDataType firstType = opBinding.getOperandType(0);
1560 ret = opBinding.getTypeFactory().createTypeWithNullability(
1561 ret, firstType.isNullable());
1562 if (opBinding instanceof SqlCallBinding) {
1563 SqlCallBinding callBinding = (SqlCallBinding) opBinding;
1564 SqlNode operand0 = callBinding.operand(0);
1568 if (((operand0 instanceof SqlLiteral)
1569 && (((SqlLiteral) operand0).getValue() == null))
1570 || (operand0 instanceof SqlDynamicParam)) {
1573 validator.setValidatedNodeType(operand0, ret);
1580 assert operandsCount == 2;
1581 return "{0}({1} AS {2})";
1585 return SqlOperandCountRanges.of(2);
1594 final SqlNode left = callBinding.operand(0);
1595 final SqlNode right = callBinding.operand(1);
1596 if (SqlUtil.isNullLiteral(left,
false) || left instanceof SqlDynamicParam) {
1599 RelDataType validatedNodeType =
1600 callBinding.getValidator().getValidatedNodeType(left);
1601 RelDataType returnType =
1602 callBinding.getValidator().deriveType(callBinding.getScope(), right);
1603 if (!SqlTypeUtil.canCastFrom(returnType, validatedNodeType,
true)) {
1604 if (throwOnFailure) {
1605 throw callBinding.newError(RESOURCE.cannotCastValue(
1606 validatedNodeType.toString(), returnType.toString()));
1610 if (SqlTypeUtil.areCharacterSetsMismatched(validatedNodeType, returnType)) {
1611 if (throwOnFailure) {
1614 throw callBinding.newError(RESOURCE.cannotCastValue(
1615 validatedNodeType.getFullTypeString(), returnType.getFullTypeString()));
1623 return SqlSyntax.FUNCTION;
1626 public void unparse(SqlWriter writer, SqlCall call,
int leftPrec,
int rightPrec) {
1627 assert call.operandCount() == 2;
1628 final SqlWriter.Frame frame = writer.startFunCall(getName());
1629 call.operand(0).unparse(writer, 0, 0);
1631 if (call.operand(1) instanceof SqlIntervalQualifier) {
1632 writer.sep(
"INTERVAL");
1634 call.operand(1).unparse(writer, 0, 0);
1635 writer.endFunCall(frame);
1639 public static class Likely extends SqlFunction {
1642 SqlKind.OTHER_FUNCTION,
1645 OperandTypes.BOOLEAN,
1646 SqlFunctionCategory.SYSTEM);
1651 return opBinding.getOperandType(0);
1658 SqlKind.OTHER_FUNCTION,
1661 OperandTypes.BOOLEAN,
1662 SqlFunctionCategory.SYSTEM);
1667 return opBinding.getOperandType(0);
1671 public static class Sign extends SqlFunction {
1674 SqlKind.OTHER_FUNCTION,
1677 OperandTypes.NUMERIC,
1678 SqlFunctionCategory.NUMERIC);
1683 return opBinding.getOperandType(0);
1690 SqlKind.OTHER_FUNCTION,
1693 OperandTypes.family(signature()),
1694 SqlFunctionCategory.NUMERIC);
1699 assert opBinding.getOperandCount() == 2;
1700 return opBinding.getOperandType(0);
1704 java.util.List<SqlTypeFamily> truncate_sig =
1705 new java.util.ArrayList<SqlTypeFamily>();
1706 truncate_sig.add(SqlTypeFamily.NUMERIC);
1707 truncate_sig.add(SqlTypeFamily.INTEGER);
1708 return truncate_sig;
1715 SqlKind.OTHER_FUNCTION,
1718 OperandTypes.family(signature()),
1719 SqlFunctionCategory.SYSTEM);
1724 assert opBinding.getOperandCount() == 1;
1725 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1726 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1730 java.util.List<SqlTypeFamily> st_isempty_sig =
1731 new java.util.ArrayList<SqlTypeFamily>();
1732 st_isempty_sig.add(SqlTypeFamily.ANY);
1733 return st_isempty_sig;
1740 SqlKind.OTHER_FUNCTION,
1743 OperandTypes.family(signature()),
1744 SqlFunctionCategory.SYSTEM);
1749 assert opBinding.getOperandCount() == 1;
1750 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1751 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1755 java.util.List<SqlTypeFamily> st_isvalid_sig =
1756 new java.util.ArrayList<SqlTypeFamily>();
1757 st_isvalid_sig.add(SqlTypeFamily.ANY);
1758 return st_isvalid_sig;
1764 super(
"ST_Contains",
1765 SqlKind.OTHER_FUNCTION,
1768 OperandTypes.family(signature()),
1769 SqlFunctionCategory.SYSTEM);
1774 assert opBinding.getOperandCount() == 2;
1775 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1776 return typeFactory.createTypeWithNullability(
1777 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1778 opBinding.getOperandType(0).isNullable()
1779 || opBinding.getOperandType(1).isNullable());
1783 java.util.List<SqlTypeFamily> st_contains_sig =
1784 new java.util.ArrayList<SqlTypeFamily>();
1785 st_contains_sig.add(SqlTypeFamily.ANY);
1786 st_contains_sig.add(SqlTypeFamily.ANY);
1787 return st_contains_sig;
1794 SqlKind.OTHER_FUNCTION,
1797 OperandTypes.family(signature()),
1798 SqlFunctionCategory.SYSTEM);
1803 assert opBinding.getOperandCount() == 2;
1804 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1805 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1809 java.util.List<SqlTypeFamily> st_equals_sig =
1810 new java.util.ArrayList<SqlTypeFamily>();
1811 st_equals_sig.add(SqlTypeFamily.ANY);
1812 st_equals_sig.add(SqlTypeFamily.ANY);
1813 return st_equals_sig;
1819 super(
"ST_Intersects",
1820 SqlKind.OTHER_FUNCTION,
1823 OperandTypes.family(signature()),
1824 SqlFunctionCategory.SYSTEM);
1829 assert opBinding.getOperandCount() == 2;
1830 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1831 return typeFactory.createTypeWithNullability(
1832 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1833 opBinding.getOperandType(0).isNullable()
1834 || opBinding.getOperandType(1).isNullable());
1838 java.util.List<SqlTypeFamily> st_intersects_sig =
1839 new java.util.ArrayList<SqlTypeFamily>();
1840 st_intersects_sig.add(SqlTypeFamily.ANY);
1841 st_intersects_sig.add(SqlTypeFamily.ANY);
1842 return st_intersects_sig;
1848 super(
"ST_IntersectsBox",
1849 SqlKind.OTHER_FUNCTION,
1852 OperandTypes.family(signature()),
1853 SqlFunctionCategory.SYSTEM);
1858 assert opBinding.getOperandCount() == 2;
1859 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1860 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1864 java.util.List<SqlTypeFamily> st_intersect_box_sig =
1865 new java.util.ArrayList<SqlTypeFamily>();
1866 st_intersect_box_sig.add(SqlTypeFamily.ANY);
1867 st_intersect_box_sig.add(SqlTypeFamily.ANY);
1868 return st_intersect_box_sig;
1874 super(
"ST_Approx_Overlaps",
1875 SqlKind.OTHER_FUNCTION,
1878 OperandTypes.family(signature()),
1879 SqlFunctionCategory.SYSTEM);
1884 assert opBinding.getOperandCount() == 2;
1885 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1886 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1890 java.util.List<SqlTypeFamily> st_intersect_box_sig =
1891 new java.util.ArrayList<SqlTypeFamily>();
1892 st_intersect_box_sig.add(SqlTypeFamily.ANY);
1893 st_intersect_box_sig.add(SqlTypeFamily.ANY);
1894 return st_intersect_box_sig;
1900 super(
"ST_Disjoint",
1901 SqlKind.OTHER_FUNCTION,
1904 OperandTypes.family(signature()),
1905 SqlFunctionCategory.SYSTEM);
1910 assert opBinding.getOperandCount() == 2;
1911 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1912 return typeFactory.createTypeWithNullability(
1913 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1914 opBinding.getOperandType(0).isNullable()
1915 || opBinding.getOperandType(1).isNullable());
1919 java.util.List<SqlTypeFamily> st_disjoint_sig =
1920 new java.util.ArrayList<SqlTypeFamily>();
1921 st_disjoint_sig.add(SqlTypeFamily.ANY);
1922 st_disjoint_sig.add(SqlTypeFamily.ANY);
1923 return st_disjoint_sig;
1930 SqlKind.OTHER_FUNCTION,
1933 OperandTypes.family(signature()),
1934 SqlFunctionCategory.SYSTEM);
1939 assert opBinding.getOperandCount() == 2;
1940 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1941 return typeFactory.createTypeWithNullability(
1942 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1943 opBinding.getOperandType(0).isNullable()
1944 || opBinding.getOperandType(1).isNullable());
1948 java.util.List<SqlTypeFamily> st_within_sig =
1949 new java.util.ArrayList<SqlTypeFamily>();
1950 st_within_sig.add(SqlTypeFamily.ANY);
1951 st_within_sig.add(SqlTypeFamily.ANY);
1952 return st_within_sig;
1959 SqlKind.OTHER_FUNCTION,
1962 OperandTypes.family(signature()),
1963 SqlFunctionCategory.SYSTEM);
1968 assert opBinding.getOperandCount() == 3;
1969 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1970 return typeFactory.createTypeWithNullability(
1971 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1972 opBinding.getOperandType(0).isNullable()
1973 || opBinding.getOperandType(1).isNullable()
1974 || opBinding.getOperandType(2).isNullable());
1978 java.util.List<SqlTypeFamily> st_dwithin_sig =
1979 new java.util.ArrayList<SqlTypeFamily>();
1980 st_dwithin_sig.add(SqlTypeFamily.ANY);
1981 st_dwithin_sig.add(SqlTypeFamily.ANY);
1982 st_dwithin_sig.add(SqlTypeFamily.NUMERIC);
1983 return st_dwithin_sig;
1989 super(
"ST_DFullyWithin",
1990 SqlKind.OTHER_FUNCTION,
1993 OperandTypes.family(signature()),
1994 SqlFunctionCategory.SYSTEM);
1999 assert opBinding.getOperandCount() == 3;
2000 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2001 return typeFactory.createTypeWithNullability(
2002 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
2003 opBinding.getOperandType(0).isNullable()
2004 || opBinding.getOperandType(1).isNullable()
2005 || opBinding.getOperandType(2).isNullable());
2009 java.util.List<SqlTypeFamily> st_dwithin_sig =
2010 new java.util.ArrayList<SqlTypeFamily>();
2011 st_dwithin_sig.add(SqlTypeFamily.ANY);
2012 st_dwithin_sig.add(SqlTypeFamily.ANY);
2013 st_dwithin_sig.add(SqlTypeFamily.NUMERIC);
2014 return st_dwithin_sig;
2020 super(
"ST_Distance",
2021 SqlKind.OTHER_FUNCTION,
2024 OperandTypes.family(signature()),
2025 SqlFunctionCategory.SYSTEM);
2030 assert opBinding.getOperandCount() == 2;
2031 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2032 return typeFactory.createTypeWithNullability(
2033 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2034 opBinding.getOperandType(0).isNullable()
2035 || opBinding.getOperandType(1).isNullable());
2039 java.util.List<SqlTypeFamily> st_distance_sig =
2040 new java.util.ArrayList<SqlTypeFamily>();
2041 st_distance_sig.add(SqlTypeFamily.ANY);
2042 st_distance_sig.add(SqlTypeFamily.ANY);
2043 return st_distance_sig;
2049 super(
"ST_MaxDistance",
2050 SqlKind.OTHER_FUNCTION,
2053 OperandTypes.family(signature()),
2054 SqlFunctionCategory.SYSTEM);
2059 assert opBinding.getOperandCount() == 2;
2060 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2061 return typeFactory.createTypeWithNullability(
2062 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2063 opBinding.getOperandType(0).isNullable()
2064 || opBinding.getOperandType(1).isNullable());
2068 java.util.List<SqlTypeFamily> st_maxdistance_sig =
2069 new java.util.ArrayList<SqlTypeFamily>();
2070 st_maxdistance_sig.add(SqlTypeFamily.ANY);
2071 st_maxdistance_sig.add(SqlTypeFamily.ANY);
2072 return st_maxdistance_sig;
2078 super(
"ST_GeogFromText",
2079 SqlKind.OTHER_FUNCTION,
2082 OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
2083 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
2084 SqlFunctionCategory.SYSTEM);
2089 assert opBinding.getOperandCount() == 1;
2090 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2091 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2097 super(
"ST_GeomFromText",
2098 SqlKind.OTHER_FUNCTION,
2101 OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
2102 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
2103 SqlFunctionCategory.SYSTEM);
2108 assert opBinding.getOperandCount() == 1;
2109 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2110 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2116 super(
"ST_Transform",
2117 SqlKind.OTHER_FUNCTION,
2120 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
2121 SqlFunctionCategory.SYSTEM);
2126 assert opBinding.getOperandCount() == 1;
2127 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2128 return typeFactory.createTypeWithNullability(
2129 typeFactory.createSqlType(SqlTypeName.INTEGER),
2130 opBinding.getOperandType(0).isNullable());
2134 static class ST_X extends SqlFunction {
2137 SqlKind.OTHER_FUNCTION,
2140 OperandTypes.family(SqlTypeFamily.ANY),
2141 SqlFunctionCategory.SYSTEM);
2146 assert opBinding.getOperandCount() == 1;
2147 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2148 return typeFactory.createTypeWithNullability(
2149 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2150 opBinding.getOperandType(0).isNullable());
2154 static class ST_Y extends SqlFunction {
2157 SqlKind.OTHER_FUNCTION,
2160 OperandTypes.family(SqlTypeFamily.ANY),
2161 SqlFunctionCategory.SYSTEM);
2166 assert opBinding.getOperandCount() == 1;
2167 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2168 return typeFactory.createTypeWithNullability(
2169 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2170 opBinding.getOperandType(0).isNullable());
2177 SqlKind.OTHER_FUNCTION,
2180 OperandTypes.family(SqlTypeFamily.ANY),
2181 SqlFunctionCategory.SYSTEM);
2186 assert opBinding.getOperandCount() == 1;
2187 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2188 return typeFactory.createTypeWithNullability(
2189 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2190 opBinding.getOperandType(0).isNullable());
2197 SqlKind.OTHER_FUNCTION,
2200 OperandTypes.family(SqlTypeFamily.ANY),
2201 SqlFunctionCategory.SYSTEM);
2206 assert opBinding.getOperandCount() == 1;
2207 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2208 return typeFactory.createTypeWithNullability(
2209 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2210 opBinding.getOperandType(0).isNullable());
2217 SqlKind.OTHER_FUNCTION,
2220 OperandTypes.family(SqlTypeFamily.ANY),
2221 SqlFunctionCategory.SYSTEM);
2226 assert opBinding.getOperandCount() == 1;
2227 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2228 return typeFactory.createTypeWithNullability(
2229 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2230 opBinding.getOperandType(0).isNullable());
2237 SqlKind.OTHER_FUNCTION,
2240 OperandTypes.family(SqlTypeFamily.ANY),
2241 SqlFunctionCategory.SYSTEM);
2246 assert opBinding.getOperandCount() == 1;
2247 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2248 return typeFactory.createTypeWithNullability(
2249 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2250 opBinding.getOperandType(0).isNullable());
2257 SqlKind.OTHER_FUNCTION,
2260 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
2261 SqlFunctionCategory.SYSTEM);
2266 assert opBinding.getOperandCount() == 1;
2267 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2268 return typeFactory.createTypeWithNullability(
2269 typeFactory.createSqlType(SqlTypeName.INTEGER),
2270 opBinding.getOperandType(0).isNullable());
2276 super(
"ST_EndPoint",
2277 SqlKind.OTHER_FUNCTION,
2280 OperandTypes.family(SqlTypeFamily.ANY),
2281 SqlFunctionCategory.SYSTEM);
2286 assert opBinding.getOperandCount() == 1;
2287 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2288 return typeFactory.createTypeWithNullability(
2289 typeFactory.createSqlType(SqlTypeName.INTEGER),
2290 opBinding.getOperandType(0).isNullable());
2296 super(
"ST_StartPoint",
2297 SqlKind.OTHER_FUNCTION,
2300 OperandTypes.family(SqlTypeFamily.ANY),
2301 SqlFunctionCategory.SYSTEM);
2306 assert opBinding.getOperandCount() == 1;
2307 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2308 return typeFactory.createTypeWithNullability(
2309 typeFactory.createSqlType(SqlTypeName.INTEGER),
2310 opBinding.getOperandType(0).isNullable());
2317 SqlKind.OTHER_FUNCTION,
2320 OperandTypes.family(SqlTypeFamily.ANY),
2321 SqlFunctionCategory.SYSTEM);
2326 assert opBinding.getOperandCount() == 1;
2327 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2328 return typeFactory.createTypeWithNullability(
2329 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2330 opBinding.getOperandType(0).isNullable());
2336 super(
"ST_Perimeter",
2337 SqlKind.OTHER_FUNCTION,
2340 OperandTypes.family(SqlTypeFamily.ANY),
2341 SqlFunctionCategory.SYSTEM);
2346 assert opBinding.getOperandCount() == 1;
2347 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2348 return typeFactory.createTypeWithNullability(
2349 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2350 opBinding.getOperandType(0).isNullable());
2357 SqlKind.OTHER_FUNCTION,
2360 OperandTypes.family(SqlTypeFamily.ANY),
2361 SqlFunctionCategory.SYSTEM);
2366 assert opBinding.getOperandCount() == 1;
2367 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2368 return typeFactory.createTypeWithNullability(
2369 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2370 opBinding.getOperandType(0).isNullable());
2377 SqlKind.OTHER_FUNCTION,
2380 OperandTypes.family(SqlTypeFamily.ANY),
2381 SqlFunctionCategory.SYSTEM);
2386 assert opBinding.getOperandCount() == 1;
2387 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2388 return typeFactory.createTypeWithNullability(
2389 typeFactory.createSqlType(SqlTypeName.INTEGER),
2390 opBinding.getOperandType(0).isNullable());
2397 SqlKind.OTHER_FUNCTION,
2400 OperandTypes.family(SqlTypeFamily.ANY),
2401 SqlFunctionCategory.SYSTEM);
2406 assert opBinding.getOperandCount() == 1;
2407 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2408 return typeFactory.createTypeWithNullability(
2409 typeFactory.createSqlType(SqlTypeName.INTEGER),
2410 opBinding.getOperandType(0).isNullable());
2416 super(
"ST_NumGeometries",
2417 SqlKind.OTHER_FUNCTION,
2420 OperandTypes.family(SqlTypeFamily.ANY),
2421 SqlFunctionCategory.SYSTEM);
2426 assert opBinding.getOperandCount() == 1;
2427 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2428 return typeFactory.createTypeWithNullability(
2429 typeFactory.createSqlType(SqlTypeName.INTEGER),
2430 opBinding.getOperandType(0).isNullable());
2437 SqlKind.OTHER_FUNCTION,
2440 OperandTypes.family(SqlTypeFamily.ANY),
2441 SqlFunctionCategory.SYSTEM);
2446 assert opBinding.getOperandCount() == 1;
2447 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2448 return typeFactory.createTypeWithNullability(
2449 typeFactory.createSqlType(SqlTypeName.INTEGER),
2450 opBinding.getOperandType(0).isNullable());
2457 SqlKind.OTHER_FUNCTION,
2460 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
2461 SqlFunctionCategory.SYSTEM);
2466 assert opBinding.getOperandCount() == 1;
2467 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2468 return typeFactory.createTypeWithNullability(
2469 typeFactory.createSqlType(SqlTypeName.INTEGER),
2470 opBinding.getOperandType(0).isNullable());
2477 SqlKind.OTHER_FUNCTION,
2480 OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
2481 SqlFunctionCategory.SYSTEM);
2486 assert opBinding.getOperandCount() == 2;
2487 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2488 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2494 super(
"ST_Centroid",
2495 SqlKind.OTHER_FUNCTION,
2498 OperandTypes.family(signature()),
2499 SqlFunctionCategory.SYSTEM);
2504 assert opBinding.getOperandCount() == 1;
2505 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2506 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2510 java.util.List<SqlTypeFamily> st_centroid_sig =
2511 new java.util.ArrayList<SqlTypeFamily>();
2512 st_centroid_sig.add(SqlTypeFamily.ANY);
2513 return st_centroid_sig;
2520 SqlKind.OTHER_FUNCTION,
2523 OperandTypes.family(signature()),
2524 SqlFunctionCategory.SYSTEM);
2529 assert opBinding.getOperandCount() == 2;
2530 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2531 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2535 java.util.List<SqlTypeFamily> st_buffer_sig =
2536 new java.util.ArrayList<SqlTypeFamily>();
2537 st_buffer_sig.add(SqlTypeFamily.ANY);
2538 st_buffer_sig.add(SqlTypeFamily.NUMERIC);
2539 return st_buffer_sig;
2545 super(
"ST_ConcaveHull",
2546 SqlKind.OTHER_FUNCTION,
2549 OperandTypes.family(signature()),
2550 SqlFunctionCategory.SYSTEM);
2555 assert opBinding.getOperandCount() == 2;
2556 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2557 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2561 java.util.List<SqlTypeFamily> st_concavehull_sig =
2562 new java.util.ArrayList<SqlTypeFamily>();
2563 st_concavehull_sig.add(SqlTypeFamily.ANY);
2564 st_concavehull_sig.add(SqlTypeFamily.NUMERIC);
2565 return st_concavehull_sig;
2571 super(
"ST_ConvexHull",
2572 SqlKind.OTHER_FUNCTION,
2575 OperandTypes.family(signature()),
2576 SqlFunctionCategory.SYSTEM);
2581 assert opBinding.getOperandCount() == 1;
2582 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2583 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2587 java.util.List<SqlTypeFamily> st_convexhull_sig =
2588 new java.util.ArrayList<SqlTypeFamily>();
2589 st_convexhull_sig.add(SqlTypeFamily.ANY);
2590 return st_convexhull_sig;
2596 super(
"ST_Intersection",
2597 SqlKind.OTHER_FUNCTION,
2600 OperandTypes.family(signature()),
2601 SqlFunctionCategory.SYSTEM);
2606 assert opBinding.getOperandCount() == 2;
2607 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2608 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2612 java.util.List<SqlTypeFamily> st_intersection_sig =
2613 new java.util.ArrayList<SqlTypeFamily>();
2614 st_intersection_sig.add(SqlTypeFamily.ANY);
2615 st_intersection_sig.add(SqlTypeFamily.ANY);
2616 return st_intersection_sig;
2623 SqlKind.OTHER_FUNCTION,
2626 OperandTypes.family(signature()),
2627 SqlFunctionCategory.SYSTEM);
2632 assert opBinding.getOperandCount() == 2;
2633 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2634 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2638 java.util.List<SqlTypeFamily> st_union_sig =
2639 new java.util.ArrayList<SqlTypeFamily>();
2640 st_union_sig.add(SqlTypeFamily.ANY);
2641 st_union_sig.add(SqlTypeFamily.ANY);
2642 return st_union_sig;
2648 super(
"ST_Difference",
2649 SqlKind.OTHER_FUNCTION,
2652 OperandTypes.family(signature()),
2653 SqlFunctionCategory.SYSTEM);
2658 assert opBinding.getOperandCount() == 2;
2659 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2660 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2664 java.util.List<SqlTypeFamily> st_difference_sig =
2665 new java.util.ArrayList<SqlTypeFamily>();
2666 st_difference_sig.add(SqlTypeFamily.ANY);
2667 st_difference_sig.add(SqlTypeFamily.ANY);
2668 return st_difference_sig;
2674 super(
"CastToGeography",
2675 SqlKind.OTHER_FUNCTION,
2678 OperandTypes.family(SqlTypeFamily.ANY),
2679 SqlFunctionCategory.SYSTEM);
2684 assert opBinding.getOperandCount() == 1;
2685 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2686 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2692 super(
"ENCODE_TEXT",
2693 SqlKind.OTHER_FUNCTION,
2696 OperandTypes.family(SqlTypeFamily.STRING),
2697 SqlFunctionCategory.SYSTEM);
2702 assert opBinding.getOperandCount() == 1;
2703 return opBinding.getOperandType(0);
2710 super(
"OFFSET_IN_FRAGMENT",
2711 SqlKind.OTHER_FUNCTION,
2714 OperandTypes.NILADIC,
2715 SqlFunctionCategory.SYSTEM);
2720 assert opBinding.getOperandCount() == 0;
2721 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2722 return typeFactory.createSqlType(SqlTypeName.BIGINT);
2728 super(
"APPROX_COUNT_DISTINCT",
2730 SqlKind.OTHER_FUNCTION,
2733 OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
2734 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
2735 SqlFunctionCategory.SYSTEM,
2738 Optionality.FORBIDDEN);
2743 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2744 return typeFactory.createSqlType(SqlTypeName.BIGINT);
2750 super(
"APPROX_MEDIAN",
2751 SqlKind.OTHER_FUNCTION,
2754 OperandTypes.family(SqlTypeFamily.NUMERIC),
2755 SqlFunctionCategory.SYSTEM);
2760 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2761 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2767 super(
"APPROX_PERCENTILE",
2768 SqlKind.OTHER_FUNCTION,
2771 OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
2772 SqlFunctionCategory.SYSTEM);
2777 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2778 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2784 super(
"APPROX_QUANTILE",
2785 SqlKind.OTHER_FUNCTION,
2788 OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
2789 SqlFunctionCategory.SYSTEM);
2794 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2795 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2803 SqlKind.OTHER_FUNCTION,
2806 OperandTypes.or(OperandTypes.family(SqlTypeFamily.NUMERIC),
2807 OperandTypes.family(SqlTypeFamily.GEO)),
2808 SqlFunctionCategory.SYSTEM);
2813 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2814 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2818 static class Mode extends SqlAggFunction {
2821 SqlKind.OTHER_FUNCTION,
2825 SqlFunctionCategory.SYSTEM);
2830 return opBinding.getOperandType(0);
2834 public static class Sample extends SqlAggFunction {
2838 SqlKind.OTHER_FUNCTION,
2842 SqlFunctionCategory.SYSTEM,
2845 Optionality.FORBIDDEN);
2850 return opBinding.getOperandType(0);
2857 super(
"LAST_SAMPLE",
2859 SqlKind.OTHER_FUNCTION,
2863 SqlFunctionCategory.SYSTEM,
2866 Optionality.FORBIDDEN);
2871 return opBinding.getOperandType(0);
2879 SqlKind.OTHER_FUNCTION,
2883 SqlFunctionCategory.SYSTEM,
2886 Optionality.FORBIDDEN);
2891 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2892 return typeFactory.createTypeWithNullability(
2893 typeFactory.createSqlType(SqlTypeName.BIGINT),
false);
2897 static class SumIf extends SqlAggFunction {
2900 SqlKind.OTHER_FUNCTION,
2903 OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.BOOLEAN),
2904 SqlFunctionCategory.SYSTEM);
2909 return opBinding.getOperandType(0);
2915 super(
"CONDITIONAL_CHANGE_EVENT",
2917 SqlKind.OTHER_FUNCTION,
2920 OperandTypes.family(SqlTypeFamily.ANY),
2921 SqlFunctionCategory.SYSTEM,
2924 Optionality.FORBIDDEN);
2939 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2940 return typeFactory.createSqlType(SqlTypeName.BIGINT);
2947 SqlKind.OTHER_FUNCTION,
2951 SqlFunctionCategory.USER_DEFINED_FUNCTION);
2953 arg_names = sig.getArgNames();
2963 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2965 SqlTypeName valueType =
2967 RelDataType subType = typeFactory.createSqlType(valueType, -1);
2968 RelDataType arr = typeFactory.createArrayType(subType, -1);
2972 SqlTypeName ret = sig.getSqlRet();
2973 return typeFactory.createTypeWithNullability(
2974 typeFactory.createSqlType(ret),
true);
2985 SqlKind.OTHER_FUNCTION,
2989 SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION);
2990 arg_types = sig.getArgs();
2991 outs = sig.getOuts();
2992 out_names = sig.getOutNames();
2993 arg_names = sig.getArgNames();
2997 pretty_arg_names = sig.getPrettyArgNames();
2998 options = sig.getOptions();
2999 cursor_field_types = sig.getCursorFieldTypes();
3000 default_values = sig.getDefaultValues();
3010 return pretty_arg_names;
3024 final Boolean has_names = this.pretty_arg_names != null
3025 && this.pretty_arg_names.size() == this.arg_types.size();
3026 final List<FunctionParameter> parameters =
new java.util.ArrayList<>();
3027 for (
int i = 0; i < this.arg_types.size(); i++) {
3028 final int arg_idx = i;
3029 parameters.add(
new FunctionParameter() {
3030 public int getOrdinal() {
3034 public String getName() {
3036 return pretty_arg_names.get(arg_idx);
3038 return "arg" + arg_idx;
3041 public RelDataType getType(RelDataTypeFactory typeFactory) {
3042 SqlTypeFamily
type = toSqlTypeName(arg_types.get(arg_idx)).getFamily();
3043 return type.getDefaultConcreteType(typeFactory);
3046 public boolean isOptional() {
3056 return opBinding -> {
3057 RelDataTypeFactory fact = opBinding.getTypeFactory();
3058 FieldInfoBuilder ret = fact.builder();
3059 for (
int out_idx = 0; out_idx < outs.size(); ++out_idx) {
3061 if (toSqlTypeName(outs.get(out_idx)) == SqlTypeName.ARRAY) {
3064 extSubType = getValueType(extSubType);
3066 RelDataType subtype = fact.createSqlType(toSqlTypeName(extSubType));
3067 type = fact.createArrayType(subtype, -1);
3069 type = fact.createSqlType(toSqlTypeName(outs.get(out_idx)));
3071 ret = ret.add(out_names.get(out_idx), type);
3072 ret = ret.nullable(
true);
3080 System.out.println(msg);
3085 final Boolean debugMode =
false;
3086 Set<RelColumnMapping> s =
new HashSet<RelColumnMapping>();
3087 debugPrint(
"getNameAsId() -> " + getNameAsId() +
", arg_names=" + arg_names
3088 +
", out_names=" + out_names,
3090 if (
Integer.valueOf(options.getOrDefault(
"filter_table_function_transpose",
"0"))
3092 debugPrint(
"getNameAsId() -> " + getNameAsId(), debugMode);
3094 for (
int arg_idx = 0; arg_idx < arg_names.size(); ++arg_idx) {
3095 String arg_name = arg_names.get(arg_idx);
3097 int start = arg_name.indexOf(
"[");
3100 int end = arg_name.lastIndexOf(
"]");
3101 fields = arg_name.substring(start + 1, end)
3102 .replaceAll(
"\\s+",
"")
3105 fields =
new String[] {arg_name};
3107 debugPrint(
"fields=" + Arrays.toString(fields), debugMode);
3108 for (
int field_idx = 0; field_idx < fields.length; ++field_idx) {
3109 int out_idx = out_names.indexOf(fields[field_idx]);
3111 s.add(
new RelColumnMapping(out_idx, rel_idx, field_idx,
false));
3112 debugPrint(
"out_idx, arg_idx/rel_idx, field_idx=" + out_idx +
", " + arg_idx
3113 +
"/" + rel_idx +
", " + field_idx,
3132 StringBuilder ret =
new StringBuilder();
3134 ret.append(this.getName());
3137 for (
int i = 0; i < this.arg_types.size(); i++) {
3143 String paramName = arg_names.get(i);
3144 ret.append(paramName).
append(
" => ");
3146 final String t = type.toString().toUpperCase(Locale.ROOT);
3147 ret.append(
"<").
append(t);
3149 List<ExtensionFunction.ExtArgumentType> field_types =
3150 cursor_field_types.get(paramName);
3152 for (
int j = 0; j < field_types.size(); j++) {
3157 ret.append(toSqlTypeName(field_type));
3158 if (isColumnListType(field_type)) {
3161 ret.append(toSqlTypeName(subtype));
3163 }
else if (isColumnArrayType(field_type) || isArrayType(field_type)) {
3166 ret.append(toSqlTypeName(subtype));
3176 return ret.toString();
3182 return this.arg_names;
3188 return this.getExtendedSignature().hashCode();
3200 if (getClass() != obj.getClass()) {
3209 if (!this.getName().equals(other.getName())) {
3212 if (arg_types.size() != other.arg_types.size()) {
3216 for (
int i = 0; i < arg_types.size(); i++) {
3217 if (arg_types.get(i) != other.arg_types.get(i)) {
3221 String paramName = this.arg_names.get(i);
3222 String otherParamName = other.getExtendedParamNames().
get(i);
3223 if (!paramName.equals(otherParamName)) {
3227 List<ExtArgumentType> field_types = this.getCursorFieldTypes().
get(paramName);
3228 List<ExtArgumentType> other_field_types =
3229 other.getCursorFieldTypes().
get(paramName);
3230 if (field_types.size() != other_field_types.size()) {
3233 for (
int j = 0; j < field_types.size(); j++) {
3234 if (field_types.get(j) != other_field_types.get(j)) {
3245 return getExtendedSignature();
3249 return cursor_field_types;
3257 return default_values;
3261 return (default_values.size() > 0);
3268 String paramName = getParamNames().get(i);
3269 return getDefaultValues().get(paramName) != null;
3273 return getDefaultValues().size();
3290 for (Ord<SqlNode> operand : Ord.zip(permutedCall.getOperandList())) {
3291 if (operand.e.getClass() == SqlBasicCall.class) {
3292 SqlBasicCall operandAsCall = (SqlBasicCall) operand.e;
3293 if (operandAsCall.getOperator().getName() ==
"DEFAULT") {
3295 String paramName = tf.getExtendedParamNames().
get(operand.i);
3296 Comparable<?> defaultVal = tf.getDefaultValues().
get(paramName);
3297 SqlLiteral newOperand = createLiteralForDefaultValue(
3298 defaultVal, operand.e.getParserPosition());
3299 permutedCall.setOperand(operand.i, newOperand);
3303 return permutedCall;
3307 if (value instanceof
Integer || value instanceof Long || value instanceof
Float
3308 || value instanceof
Double) {
3309 return SqlLiteral.createExactNumeric(value.toString(), pos);
3310 }
else if (value instanceof Boolean) {
3311 Boolean asBool = (Boolean) value;
3312 return SqlLiteral.createBoolean(asBool.booleanValue(), pos);
3313 }
else if (value instanceof String) {
3314 return SqlLiteral.createCharString(value.toString(), pos);
3327 return getOperandTypeChecker().checkOperandTypes(callBinding, throwOnFailure);
3331 private final List<ExtArgumentType>
outs;
3346 super(
"HeavyDB_Geo_PolyBoundsPtr",
3347 SqlKind.OTHER_FUNCTION,
3350 OperandTypes.family(SqlTypeFamily.ANY),
3351 SqlFunctionCategory.SYSTEM);
3356 assert opBinding.getOperandCount() == 1;
3357 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3358 return typeFactory.createSqlType(SqlTypeName.BIGINT);
3364 super(
"convert_meters_to_pixel_width",
3365 SqlKind.OTHER_FUNCTION,
3368 OperandTypes.family(SqlTypeFamily.NUMERIC,
3370 SqlTypeFamily.NUMERIC,
3371 SqlTypeFamily.NUMERIC,
3372 SqlTypeFamily.NUMERIC,
3373 SqlTypeFamily.NUMERIC),
3374 SqlFunctionCategory.SYSTEM);
3379 assert opBinding.getOperandCount() == 6;
3380 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3381 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
3387 super(
"convert_meters_to_pixel_height",
3388 SqlKind.OTHER_FUNCTION,
3391 OperandTypes.family(SqlTypeFamily.NUMERIC,
3393 SqlTypeFamily.NUMERIC,
3394 SqlTypeFamily.NUMERIC,
3395 SqlTypeFamily.NUMERIC,
3396 SqlTypeFamily.NUMERIC),
3397 SqlFunctionCategory.SYSTEM);
3402 assert opBinding.getOperandCount() == 6;
3403 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3404 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
3410 super(
"is_point_in_view",
3411 SqlKind.OTHER_FUNCTION,
3414 OperandTypes.family(SqlTypeFamily.ANY,
3415 SqlTypeFamily.NUMERIC,
3416 SqlTypeFamily.NUMERIC,
3417 SqlTypeFamily.NUMERIC,
3418 SqlTypeFamily.NUMERIC),
3419 SqlFunctionCategory.SYSTEM);
3424 assert opBinding.getOperandCount() == 5;
3425 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3426 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
3432 super(
"is_point_size_in_view",
3433 SqlKind.OTHER_FUNCTION,
3436 OperandTypes.family(SqlTypeFamily.ANY,
3437 SqlTypeFamily.NUMERIC,
3438 SqlTypeFamily.NUMERIC,
3439 SqlTypeFamily.NUMERIC,
3440 SqlTypeFamily.NUMERIC,
3441 SqlTypeFamily.NUMERIC),
3442 SqlFunctionCategory.SYSTEM);
3447 assert opBinding.getOperandCount() == 6;
3448 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3449 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
3455 super(
"usTIMESTAMP",
3456 SqlKind.OTHER_FUNCTION,
3459 OperandTypes.STRING,
3460 SqlFunctionCategory.SYSTEM);
3465 assert opBinding.getOperandCount() == 1;
3466 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3467 return typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 6);
3473 super(
"nsTIMESTAMP",
3474 SqlKind.OTHER_FUNCTION,
3477 OperandTypes.STRING,
3478 SqlFunctionCategory.SYSTEM);
3483 assert opBinding.getOperandCount() == 1;
3484 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3485 return typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 9);
3491 super(
"FORWARD_FILL",
3496 OperandTypes.family(SqlTypeFamily.ANY),
3497 SqlFunctionCategory.SYSTEM,
3500 Optionality.FORBIDDEN);
3511 super(
"BACKWARD_FILL",
3516 OperandTypes.family(SqlTypeFamily.ANY),
3517 SqlFunctionCategory.SYSTEM,
3520 Optionality.FORBIDDEN);
static java.util.List< SqlTypeFamily > signature()
EXTENSION_NOINLINE double convert_meters_to_pixel_width(const double meters, int8_t *p, const int64_t psize, const int32_t ic, const int32_t isr, const int32_t osr, const double min_lon, const double max_lon, const int32_t img_width, const double min_width)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
EXTENSION_INLINE int64_t HeavyDB_Geo_PolyBoundsPtr(double *bounds, int64_t size)
final java.util.List< SqlTypeFamily > toSqlSignature()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static final SqlFunction TRY_CAST
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > signature()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
size_t append(FILE *f, const size_t size, const int8_t *buf)
Appends the specified number of bytes to the end of the file f from buf.
boolean isArgumentOptional(int i)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
ExtTableFunction(final String name, final ExtensionFunction sig)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
List< FunctionParameter > getParameters()
SqlReturnTypeInference getRowTypeInference()
boolean requiresCreate(List< SqlNode > operands)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
EXTENSION_NOINLINE double ST_XMax(int8_t *coords, int64_t size, int32_t ic, int32_t isr, int32_t osr)
boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
String getSignatureTemplate(final int operandsCount)
static final ArrayLengthErrors _ERRORS
static java.util.List< SqlTypeFamily > getSignatureFamilies()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
ExInst< SqlValidatorException > illegalArrayLengthCall(String query)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
EXTENSION_NOINLINE bool is_point_size_in_view(int8_t *p, const int64_t psize, const int32_t ic, const double meters, const double min_lon, const double max_lon, const double min_lat, const double max_lat)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > signature()
static java.util.List< SqlTypeFamily > signature()
EXTENSION_NOINLINE double ST_YMax(int8_t *coords, int64_t size, int32_t ic, int32_t isr, int32_t osr)
LeftRightTrim(final String name, final SqlKind kind)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
List< ExtArgumentType > getArgTypes()
static java.util.List< SqlTypeFamily > signature()
SqlCall createCall(@Nullable SqlLiteral functionQualifier, SqlParserPos pos,@Nullable SqlNode...operands)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
EXTENSION_NOINLINE double ST_XMin(int8_t *coords, int64_t size, int32_t ic, int32_t isr, int32_t osr)
static java.util.List< SqlTypeFamily > signature()
static String dropSuffix(final String str)
static java.util.List< SqlTypeFamily > signature()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
boolean allowsNullTreatment()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RegexpSubstr(final String alias)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
String getExtendedSignature()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
final Map< String, String > options
List< String > getParamNames()
static java.util.List< SqlTypeFamily > signature()
static java.util.List< SqlTypeFamily > getSignatureFamilies()
EXTENSION_NOINLINE double convert_meters_to_pixel_height(const double meters, int8_t *p, const int64_t psize, const int32_t ic, const int32_t isr, const int32_t osr, const double min_lat, const double max_lat, const int32_t img_height, const double min_height)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
boolean equals(final Object obj)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
convert_meters_to_pixel_height()
boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
final List< ExtArgumentType > outs
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static final Logger HEAVYDBLOGGER
RelDataType inferReturnType(SqlOperatorBinding opBinding)
final ListSqlOperatorTable listOpTab
static java.util.List< SqlTypeFamily > getSignatureFamilies()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > getSignatureFamilies()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType getComponentType(RelDataTypeFactory typeFactory, List< RelDataType > argTypes)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > getSignatureFamilies()
void debugPrint(String msg, Boolean debugMode)
final List< ExtArgumentType > arg_types
EXTENSION_NOINLINE double ST_YMin(int8_t *coords, int64_t size, int32_t ic, int32_t isr, int32_t osr)
int getNumOptionalArguments()
static java.util.List< SqlTypeFamily > signature()
final ExtensionFunction sig
boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > signature()
SqlCall createCall(@Nullable SqlLiteral functionQualifier, SqlParserPos pos,@Nullable SqlNode...operands)
static java.util.List< SqlTypeFamily > getSignatureFamilies()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
boolean supportsDefaultArguments()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > signature()
static boolean isColumnArrayType(final ExtArgumentType type)
static java.util.List< SqlTypeFamily > signature()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
void addUDF(final Map< String, ExtensionFunction > extSigs)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
HeavyDBSqlOperatorTable(SqlOperatorTable parentTable)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > getSignatureFamilies()
void validateCall(SqlCall call, SqlValidator validator, SqlValidatorScope scope, SqlValidatorScope operandScope)
EXTENSION_NOINLINE bool is_point_in_view(int8_t *p, const int64_t psize, const int32_t ic, const double min_lon, const double max_lon, const double min_lat, const double max_lat)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
ExtFunction(final String name, final ExtensionFunction sig)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
Map< String, Comparable<?> > getDefaultValues()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
SqlLiteral createLiteralForDefaultValue(Comparable<?> value, SqlParserPos pos)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
SqlOperandCountRange getOperandCountRange()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > getSignatureFamilies()
convert_meters_to_pixel_width()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
SqlOperandCountRange getOperandCountRange()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
final List< String > out_names
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > signature()
void addOperator(SqlOperator op)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
HeavyDB_Geo_PolyBoundsPtr()
static java.util.List< SqlTypeFamily > getSignatureFamilies()
static java.util.List< SqlTypeFamily > signature()
final Map< String, List< ExtArgumentType > > cursor_field_types
RelDataType inferReturnType(SqlOperatorBinding opBinding)
final List< String > arg_names
SqlOperandCountRange getOperandCountRange()
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)
static java.util.List< SqlTypeFamily > signature()
static java.util.List< SqlTypeFamily > signature()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > signature()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > signature()
static java.util.List< SqlTypeFamily > signature()
void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
final List< String > arg_names
RelDataType inferReturnType(SqlOperatorBinding opBinding)
List< String > getParamNames()
static boolean isArrayType(final ExtArgumentType type)
boolean requiresCreate(List< SqlNode > operands)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
Set< RelColumnMapping > getColumnMappings()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > signature()
SqlCall createCall(@Nullable SqlLiteral functionQualifier, SqlParserPos pos,@Nullable SqlNode...operands)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > getSignatureFamilies()
SqlCall createCall(@Nullable SqlLiteral functionQualifier, SqlParserPos pos,@Nullable SqlNode...operands)
EXTENSION_NOINLINE double Truncate(const double x, const int32_t y)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
final List< String > pretty_arg_names
SqlCall rewriteCallWithDefaultArguments(SqlCall permutedCall)
final Map< String, Comparable<?> > default_values
boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure)
static java.util.List< SqlTypeFamily > signature()
Map< String, List< ExtArgumentType > > getCursorFieldTypes()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
SqlCall createCall(@Nullable SqlLiteral functionQualifier, SqlParserPos pos,@Nullable SqlNode...operands)
boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > signature()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure)
static final SqlArrayValueConstructorAllowingEmpty ARRAY_VALUE_CONSTRUCTOR
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > getSignatureFamilies()
boolean requiresCreate(List< SqlNode > operands)
static ExtArgumentType getValueType(final ExtArgumentType type)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
List< String > getExtendedParamNames()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > getSignatureFamilies()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
void lookupOperatorOverloads(SqlIdentifier opName, SqlFunctionCategory category, SqlSyntax syntax, List< SqlOperator > operatorList, SqlNameMatcher nameMatcher)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > signature()
LeftRightPad(final String name)