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;
32 import org.apache.calcite.linq4j.Ord;
33 import org.apache.calcite.rel.metadata.RelColumnMapping;
34 import org.apache.calcite.rel.type.RelDataType;
35 import org.apache.calcite.rel.type.RelDataTypeFactory;
36 import org.apache.calcite.rel.type.RelDataTypeFactory.FieldInfoBuilder;
37 import org.apache.calcite.rel.type.RelDataTypeFamily;
38 import org.apache.calcite.runtime.Resources;
39 import org.apache.calcite.runtime.Resources.BaseMessage;
40 import org.apache.calcite.runtime.Resources.ExInst;
41 import org.apache.calcite.schema.FunctionParameter;
42 import org.apache.calcite.sql.SqlAggFunction;
43 import org.apache.calcite.sql.SqlBasicCall;
44 import org.apache.calcite.sql.SqlCall;
45 import org.apache.calcite.sql.SqlCallBinding;
46 import org.apache.calcite.sql.SqlDynamicParam;
47 import org.apache.calcite.sql.SqlFunction;
48 import org.apache.calcite.sql.SqlFunctionCategory;
49 import org.apache.calcite.sql.SqlIdentifier;
50 import org.apache.calcite.sql.SqlIntervalQualifier;
51 import org.apache.calcite.sql.SqlKind;
52 import org.apache.calcite.sql.SqlLiteral;
53 import org.apache.calcite.sql.SqlNode;
54 import org.apache.calcite.sql.SqlOperandCountRange;
56 import org.apache.calcite.sql.SqlOperatorBinding;
57 import org.apache.calcite.sql.SqlOperatorTable;
58 import org.apache.calcite.sql.SqlSyntax;
59 import org.apache.calcite.sql.SqlTableFunction;
60 import org.apache.calcite.sql.SqlUtil;
61 import org.apache.calcite.sql.SqlWriter;
62 import org.apache.calcite.sql.fun.SqlArrayValueConstructor;
63 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
64 import org.apache.calcite.sql.parser.SqlParserPos;
65 import org.apache.calcite.sql.type.InferTypes;
66 import org.apache.calcite.sql.type.OperandTypes;
67 import org.apache.calcite.sql.type.ReturnTypes;
68 import org.apache.calcite.sql.type.SameOperandTypeChecker;
69 import org.apache.calcite.sql.type.SqlOperandCountRanges;
70 import org.apache.calcite.sql.type.SqlReturnTypeInference;
71 import org.apache.calcite.sql.type.SqlTypeFamily;
72 import org.apache.calcite.sql.type.SqlTypeName;
73 import org.apache.calcite.sql.type.SqlTypeTransforms;
74 import org.apache.calcite.sql.type.SqlTypeUtil;
75 import org.apache.calcite.sql.util.ChainedSqlOperatorTable;
76 import org.apache.calcite.sql.util.ListSqlOperatorTable;
77 import org.apache.calcite.sql.util.ReflectiveSqlOperatorTable;
78 import org.apache.calcite.sql.validate.SqlNameMatcher;
79 import org.apache.calcite.sql.validate.SqlValidator;
80 import org.apache.calcite.sql.validate.SqlValidatorException;
82 import org.apache.calcite.sql.validate.SqlValidatorScope;
83 import org.apache.calcite.util.Optionality;
84 import org.checkerframework.checker.nullness.qual.Nullable;
85 import org.slf4j.Logger;
86 import org.slf4j.LoggerFactory;
88 import java.lang.reflect.Field;
89 import java.util.Arrays;
90 import java.util.EnumSet;
91 import java.util.HashSet;
92 import java.util.Iterator;
93 import java.util.List;
94 import java.util.Locale;
97 import java.util.stream.Collectors;
102 SqlFunctionCategory category,
104 List<SqlOperator> operatorList,
105 SqlNameMatcher nameMatcher) {
106 for (
SqlOperator operator : this.getOperatorList()) {
107 if (
operator.getSyntax() != syntax) {
110 if (!opName.isSimple()
111 || !nameMatcher.matches(operator.getName(), opName.getSimple())) {
114 SqlFunctionCategory functionCategory;
115 if (
operator instanceof SqlFunction) {
116 functionCategory = ((SqlFunction)
operator).getFunctionType();
118 functionCategory = SqlFunctionCategory.SYSTEM;
120 if (category != functionCategory
121 && category != SqlFunctionCategory.USER_DEFINED_FUNCTION) {
124 operatorList.add(
operator);
138 Field
f = ReflectiveSqlOperatorTable.class.getDeclaredField(
139 "caseSensitiveOperators");
140 f.setAccessible(
true);
141 Multimap operators = (Multimap) f.get(SqlStdOperatorTable.instance());
142 for (Iterator i = operators.entries().iterator(); i.hasNext();) {
143 Map.Entry entry = (Map.Entry) i.next();
144 if (entry.getValue() == SqlStdOperatorTable.APPROX_COUNT_DISTINCT
145 || entry.getValue() == SqlStdOperatorTable.AVG
146 || entry.getValue() == SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR) {
153 Field f = ReflectiveSqlOperatorTable.class.getDeclaredField(
154 "caseInsensitiveOperators");
155 f.setAccessible(
true);
156 Multimap operators = (Multimap) f.get(SqlStdOperatorTable.instance());
157 for (Iterator i = operators.entries().iterator(); i.hasNext();) {
158 Map.Entry entry = (Map.Entry) i.next();
159 if (entry.getValue() == SqlStdOperatorTable.APPROX_COUNT_DISTINCT
160 || entry.getValue() == SqlStdOperatorTable.AVG
161 || entry.getValue() == SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR) {
169 }
catch (Exception e) {
170 throw new RuntimeException(e);
178 LoggerFactory.getLogger(HeavyDBSqlOperatorTable.class);
190 listOpTab = (ListSqlOperatorTable) tableList.get(1);
202 public void addUDF(
final Map<String, ExtensionFunction> extSigs) {
326 if (extSigs == null) {
329 HashSet<String> demangledNames =
new HashSet<String>();
331 final String demangledName =
dropSuffix(extSig.getKey());
332 final String demangledNameArity = extSig.getValue().isTableUdf()
333 ? String.format(
"%s-%s-%s",
335 extSig.getValue().getArgs(),
336 extSig.getValue().getCursorFieldTypes())
337 : String.format(
"%s-%d", demangledName, extSig.getValue().getArgs().size());
338 if (demangledNames.contains(demangledNameArity)) {
341 demangledNames.add(demangledNameArity);
342 if (extSig.getValue().isRowUdf()) {
351 int suffix_idx = str.indexOf(
"__");
352 if (suffix_idx == -1) {
355 assert suffix_idx > 0;
356 return str.substring(0, suffix_idx);
366 extends SqlArrayValueConstructor {
369 RelDataTypeFactory typeFactory, List<RelDataType> argTypes) {
370 if (argTypes.isEmpty()) {
371 return typeFactory.createSqlType(SqlTypeName.NULL);
373 return super.getComponentType(typeFactory, argTypes);
378 if (callBinding.operands().isEmpty()) {
381 return super.checkOperandTypes(callBinding, throwOnFailure);
391 SqlKind.OTHER_FUNCTION,
394 OperandTypes.NUMERIC,
395 SqlFunctionCategory.USER_DEFINED_FUNCTION);
400 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
401 return typeFactory.builder().add(
"I", SqlTypeName.INTEGER).build();
411 SqlKind.OTHER_FUNCTION,
414 OperandTypes.VARIADIC,
415 SqlFunctionCategory.USER_DEFINED_FUNCTION);
420 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
421 return typeFactory.builder().add(
"NAME", SqlTypeName.VARCHAR, 1024).build();
432 SqlKind.OTHER_FUNCTION,
435 OperandTypes.STRING_STRING,
436 SqlFunctionCategory.SYSTEM);
441 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
442 return typeFactory.createSqlType(SqlTypeName.BIGINT);
450 SqlKind.OTHER_FUNCTION,
454 SqlFunctionCategory.SYSTEM);
459 assert opBinding.getOperandCount() == 1;
460 RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
461 assert elem_type != null;
467 public static class Any extends SqlFunction {
470 SqlKind.OTHER_FUNCTION,
474 SqlFunctionCategory.SYSTEM);
479 assert opBinding.getOperandCount() == 1;
480 RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
481 assert elem_type != null;
487 public static class All extends SqlFunction {
490 SqlKind.OTHER_FUNCTION,
494 SqlFunctionCategory.SYSTEM);
499 assert opBinding.getOperandCount() == 1;
500 RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
501 assert elem_type != null;
507 public static class Now extends SqlFunction {
510 SqlKind.OTHER_FUNCTION,
513 OperandTypes.NILADIC,
514 SqlFunctionCategory.SYSTEM);
519 assert opBinding.getOperandCount() == 0;
520 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
521 return typeFactory.createSqlType(SqlTypeName.TIMESTAMP);
529 SqlKind.OTHER_FUNCTION,
533 SqlFunctionCategory.SYSTEM);
538 assert opBinding.getOperandCount() == 1;
539 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
540 return typeFactory.createSqlType(
541 SqlTypeName.TIMESTAMP, opBinding.getOperandType(0).getPrecision());
549 SqlKind.OTHER_FUNCTION,
552 OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
553 SqlFunctionCategory.SYSTEM);
558 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
559 return typeFactory.createTypeWithNullability(
560 typeFactory.createSqlType(SqlTypeName.BIGINT),
561 opBinding.getOperandType(1).isNullable());
568 SqlKind.OTHER_FUNCTION,
571 OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
572 SqlFunctionCategory.TIMEDATE);
577 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
578 return typeFactory.createTypeWithNullability(
579 typeFactory.createSqlType(SqlTypeName.BIGINT),
580 opBinding.getOperandType(1).isNullable());
584 public static class Dateadd extends SqlFunction {
587 SqlKind.OTHER_FUNCTION,
590 OperandTypes.family(SqlTypeFamily.STRING,
591 SqlTypeFamily.INTEGER,
592 SqlTypeFamily.DATETIME),
593 SqlFunctionCategory.TIMEDATE);
598 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
599 return typeFactory.createTypeWithNullability(
600 typeFactory.createSqlType(
601 SqlTypeName.TIMESTAMP, opBinding.getOperandType(2).getPrecision()),
602 opBinding.getOperandType(2).isNullable());
609 SqlKind.OTHER_FUNCTION,
612 OperandTypes.family(SqlTypeFamily.STRING,
613 SqlTypeFamily.DATETIME,
614 SqlTypeFamily.DATETIME),
615 SqlFunctionCategory.TIMEDATE);
620 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
621 return typeFactory.createTypeWithNullability(
622 typeFactory.createSqlType(SqlTypeName.BIGINT),
623 opBinding.getOperandType(1).isNullable()
624 || opBinding.getOperandType(2).isNullable());
631 super(
"PG_DATE_TRUNC",
632 SqlKind.OTHER_FUNCTION,
635 OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
636 SqlFunctionCategory.SYSTEM);
641 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
642 return typeFactory.createTypeWithNullability(
643 typeFactory.createSqlType(
644 SqlTypeName.TIMESTAMP, opBinding.getOperandType(1).getPrecision()),
645 opBinding.getOperandType(1).isNullable());
649 public static class Length extends SqlFunction {
652 SqlKind.OTHER_FUNCTION,
656 SqlFunctionCategory.SYSTEM);
661 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
662 return typeFactory.createSqlType(SqlTypeName.INTEGER);
669 SqlKind.OTHER_FUNCTION,
673 SqlFunctionCategory.SYSTEM);
678 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
679 return typeFactory.createSqlType(SqlTypeName.INTEGER);
685 super(
"KEY_FOR_STRING",
686 SqlKind.OTHER_FUNCTION,
690 SqlFunctionCategory.SYSTEM);
695 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
696 return typeFactory.createTypeWithNullability(
697 typeFactory.createSqlType(SqlTypeName.INTEGER),
698 opBinding.getOperandType(0).isNullable());
704 super(
"SAMPLE_RATIO",
705 SqlKind.OTHER_FUNCTION,
709 SqlFunctionCategory.SYSTEM);
714 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
715 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
718 private static java.util.List<SqlTypeFamily>
signature() {
719 java.util.ArrayList<SqlTypeFamily> families =
720 new java.util.ArrayList<SqlTypeFamily>();
721 families.add(SqlTypeFamily.NUMERIC);
728 super(
"WIDTH_BUCKET",
729 SqlKind.OTHER_FUNCTION,
733 SqlFunctionCategory.SYSTEM);
738 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
739 return typeFactory.createTypeWithNullability(
740 typeFactory.createSqlType(SqlTypeName.INTEGER),
true);
743 private static java.util.List<SqlTypeFamily>
signature() {
744 java.util.ArrayList<SqlTypeFamily> families =
745 new java.util.ArrayList<SqlTypeFamily>();
746 families.add(SqlTypeFamily.NUMERIC);
747 families.add(SqlTypeFamily.NUMERIC);
748 families.add(SqlTypeFamily.NUMERIC);
749 families.add(SqlTypeFamily.INTEGER);
757 SqlKind.OTHER_FUNCTION,
761 SqlFunctionCategory.SYSTEM);
766 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
767 return typeFactory.createTypeWithNullability(
768 typeFactory.createSqlType(SqlTypeName.DOUBLE),
true);
773 return SqlOperandCountRanges.from(2);
782 final SqlValidator validator = callBinding.getValidator();
784 final int num_operands = callBinding.getOperandCount();
785 if (num_operands < 2) {
786 throw new IllegalArgumentException(
787 "At least 2 arguments are required, the model name and one or more predictors.");
789 for (
int operand_idx = 0; operand_idx < num_operands; operand_idx++) {
790 final SqlNode operand = callBinding.operand(operand_idx);
791 final SqlTypeName operand_type =
792 validator.getValidatedNodeType(operand).getSqlTypeName();
793 final SqlTypeFamily operand_type_family = operand_type.getFamily();
794 if (operand_idx == 0) {
795 if (!operand.isA(EnumSet.of(SqlKind.LITERAL))
796 || operand_type_family != SqlTypeFamily.CHARACTER) {
797 throw new IllegalArgumentException(
798 "First argument must be TEXT literal denoting the model name.");
801 if (operand.isA(EnumSet.of(SqlKind.LITERAL))) {
802 throw new IllegalArgumentException(
803 "Literals are not supported as predictors.");
805 if (!(operand_type_family == SqlTypeFamily.NUMERIC
806 || operand_type_family == SqlTypeFamily.CHARACTER)) {
807 throw new IllegalArgumentException(
808 "Only TEXT and NUMERIC predictors are supported.");
819 SqlKind.OTHER_FUNCTION,
823 SqlFunctionCategory.SYSTEM);
828 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
829 return typeFactory.createTypeWithNullability(
830 typeFactory.createSqlType(SqlTypeName.DOUBLE),
true);
835 return SqlOperandCountRanges.from(3);
845 final SqlValidator validator = callBinding.getValidator();
847 final int num_operands = callBinding.getOperandCount();
848 if (num_operands < 3) {
849 throw new IllegalArgumentException(
850 "At least 3 arguments are required, the model name, one or more features, and the nth principal component to project to.");
852 for (
int operand_idx = 0; operand_idx < num_operands; operand_idx++) {
853 final SqlNode operand = callBinding.operand(operand_idx);
854 final SqlTypeName operand_type =
855 validator.getValidatedNodeType(operand).getSqlTypeName();
856 final SqlTypeFamily operand_type_family = operand_type.getFamily();
857 if (operand_idx == 0) {
858 if (!operand.isA(EnumSet.of(SqlKind.LITERAL))
859 || operand_type_family != SqlTypeFamily.CHARACTER) {
860 throw new IllegalArgumentException(
861 "First argument must be TEXT literal denoting the model name.");
863 }
else if (operand_idx < num_operands - 1) {
864 if (operand.isA(EnumSet.of(SqlKind.LITERAL))) {
865 throw new IllegalArgumentException(
"Literals are not supported as features.");
867 if (!(operand_type_family == SqlTypeFamily.NUMERIC
868 || operand_type_family == SqlTypeFamily.CHARACTER)) {
869 throw new IllegalArgumentException(
870 "Only TEXT and NUMERIC features are supported.");
872 }
else if (!operand.isA(EnumSet.of(SqlKind.LITERAL))
873 || !(operand_type_family == SqlTypeFamily.NUMERIC)
874 || !(operand_type.equals(SqlTypeName.INTEGER))) {
875 throw new IllegalArgumentException(
876 "Last argument to PCA_PROJECT expects integer literal dimension index.");
885 super(
"LEAD_IN_FRAME", SqlKind.LEAD);
891 super(
"LAG_IN_FRAME", SqlKind.LAG);
897 super(
"NTH_VALUE_IN_FRAME");
903 super(
"FIRST_VALUE_IN_FRAME", SqlKind.FIRST_VALUE);
909 super(
"LAST_VALUE_IN_FRAME", SqlKind.LAST_VALUE);
915 super(
"ARRAY_LENGTH",
916 SqlKind.OTHER_FUNCTION,
920 SqlFunctionCategory.SYSTEM);
925 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
926 return typeFactory.createSqlType(SqlTypeName.INTEGER);
931 SqlValidator validator,
932 SqlValidatorScope scope,
933 SqlValidatorScope operandScope) {
934 for (
int i = 0; i < call.operandCount(); ++i) {
935 SqlNode operand = call.operand(i);
936 if (operand instanceof SqlCall) {
937 SqlCall operand_call = (SqlCall) operand;
938 SqlOperator call_oper = operand_call.getOperator();
939 if (call_oper instanceof SqlFunction) {
940 SqlFunction call_func = (SqlFunction) call_oper;
941 if (call_func.getFunctionType()
942 == SqlFunctionCategory.USER_DEFINED_FUNCTION) {
947 throw validator.newValidationError(
948 call, _ERRORS.illegalArrayLengthCall(call.toString()));
953 super.validateCall(call, validator, scope, operandScope);
957 @BaseMessage(
"Illegal argument to 'ARRAY_LENGTH': ''{0}''")
962 Resources.create(ArrayLengthErrors.class);
965 public static class PgILike extends SqlFunction {
968 SqlKind.OTHER_FUNCTION,
972 SqlFunctionCategory.SYSTEM);
976 java.util.ArrayList<SqlTypeFamily> families =
977 new java.util.ArrayList<SqlTypeFamily>();
985 implements java.util.function.Predicate<Integer>, Predicate<Integer> {
987 public boolean test(Integer t) {
999 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1000 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1006 super(
"REGEXP_LIKE",
1007 SqlKind.OTHER_FUNCTION,
1011 SqlFunctionCategory.SYSTEM);
1015 java.util.ArrayList<SqlTypeFamily> families =
1016 new java.util.ArrayList<SqlTypeFamily>();
1024 implements java.util.function.Predicate<Integer>, Predicate<Integer> {
1037 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1038 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1046 ReturnTypes.ARG0.andThen(SqlTypeTransforms.TO_NULLABLE)
1047 .andThen(SqlTypeTransforms.TO_VARYING),
1050 OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.STRING),
1051 new SameOperandTypeChecker(2) {
1053 protected List<Integer> getOperandList(
int operandCount) {
1054 return ImmutableList.of(0, 1);
1057 SqlFunctionCategory.STRING);
1061 public SqlCall
createCall(@Nullable SqlLiteral functionQualifier,
1063 @Nullable SqlNode... operands) {
1064 assert functionQualifier == null;
1065 switch (operands.length) {
1067 operands =
new SqlNode[] {operands[0], SqlLiteral.createCharString(
" ", pos)};
1070 if (operands[1] == null) {
1071 operands[1] = SqlLiteral.createCharString(
" ", pos);
1073 operands =
new SqlNode[] {operands[0], operands[1]};
1076 throw new IllegalArgumentException(
1077 "Invalid operand count " + Arrays.toString(operands));
1079 return super.createCall(functionQualifier, pos, operands);
1085 return (operands.size() == 1);
1091 super(
"LTRIM", SqlKind.LTRIM);
1096 super(
"RTRIM", SqlKind.RTRIM);
1102 SqlKind.OTHER_FUNCTION,
1103 ReturnTypes.ARG0.andThen(SqlTypeTransforms.TO_NULLABLE)
1104 .andThen(SqlTypeTransforms.TO_VARYING),
1106 OperandTypes.and(OperandTypes.family(SqlTypeFamily.STRING,
1107 SqlTypeFamily.INTEGER,
1108 SqlTypeFamily.STRING),
1109 new SameOperandTypeChecker(3) {
1111 protected List<Integer> getOperandList(
int operandCount) {
1112 return ImmutableList.of(0, 2);
1115 SqlFunctionCategory.STRING);
1119 public SqlCall
createCall(@Nullable SqlLiteral functionQualifier,
1121 @Nullable SqlNode... operands) {
1122 assert functionQualifier == null;
1123 switch (operands.length) {
1125 operands =
new SqlNode[] {
1126 operands[0], operands[1], SqlLiteral.createCharString(
" ", pos)};
1129 if (operands[2] == null) {
1130 operands[2] = SqlLiteral.createCharString(
" ", pos);
1132 operands =
new SqlNode[] {operands[0], operands[1], operands[2]};
1135 throw new IllegalArgumentException(
1136 "Invalid operand count " + Arrays.toString(operands));
1138 return super.createCall(functionQualifier, pos, operands);
1143 if (!super.checkOperandTypes(callBinding, throwOnFailure)) {
1148 return SqlTypeUtil.isCharTypeComparable(callBinding,
1149 ImmutableList.of(callBinding.operand(0), callBinding.operand(2)),
1159 return (operands.size() == 2);
1177 SqlKind.OTHER_FUNCTION,
1180 OperandTypes.family(getSignatureFamilies()),
1185 java.util.ArrayList<SqlTypeFamily> families =
1186 new java.util.ArrayList<SqlTypeFamily>();
1189 families.add(SqlTypeFamily.INTEGER);
1195 return opBinding.getOperandType(0);
1202 SqlKind.OTHER_FUNCTION,
1205 OperandTypes.family(getSignatureFamilies()),
1210 java.util.ArrayList<SqlTypeFamily> families =
1211 new java.util.ArrayList<SqlTypeFamily>();
1220 return opBinding.getOperandType(0);
1224 public SqlCall
createCall(@Nullable SqlLiteral functionQualifier,
1226 @Nullable SqlNode... operands) {
1227 assert functionQualifier == null;
1228 switch (operands.length) {
1230 operands =
new SqlNode[] {
1231 operands[0], operands[1], SqlLiteral.createCharString(
"", pos)};
1236 throw new IllegalArgumentException(
1237 "Invalid operand count " + Arrays.toString(operands));
1239 return super.createCall(functionQualifier, pos, operands);
1245 return (operands.size() == 2);
1251 SqlKind.OTHER_FUNCTION,
1254 OperandTypes.family(getSignatureFamilies()),
1259 java.util.ArrayList<SqlTypeFamily> families =
1260 new java.util.ArrayList<SqlTypeFamily>();
1267 return opBinding.getOperandType(0);
1270 public static class Repeat extends SqlFunction {
1273 SqlKind.OTHER_FUNCTION,
1276 OperandTypes.family(getSignatureFamilies()),
1281 java.util.ArrayList<SqlTypeFamily> families =
1282 new java.util.ArrayList<SqlTypeFamily>();
1284 families.add(SqlTypeFamily.INTEGER);
1290 return opBinding.getOperandType(0);
1296 super(
"REGEXP_REPLACE",
1297 SqlKind.OTHER_FUNCTION,
1300 OperandTypes.family(getSignatureFamilies()),
1305 java.util.ArrayList<SqlTypeFamily> families =
1306 new java.util.ArrayList<SqlTypeFamily>();
1310 families.add(SqlTypeFamily.INTEGER);
1311 families.add(SqlTypeFamily.INTEGER);
1317 public SqlCall
createCall(@Nullable SqlLiteral functionQualifier,
1319 @Nullable SqlNode... operands) {
1320 assert functionQualifier == null;
1321 final int num_operands = operands.length;
1322 if (num_operands < 2 || num_operands > 6) {
1323 throw new IllegalArgumentException(
1324 "Invalid operand count " + Arrays.toString(operands));
1326 SqlNode[] new_operands =
new SqlNode[6];
1328 new_operands[0] = operands[0];
1330 new_operands[1] = operands[1];
1332 if (num_operands < 3 || operands[2] == null) {
1333 new_operands[2] = SqlLiteral.createCharString(
"", pos);
1335 new_operands[2] = operands[2];
1338 if (num_operands < 4 || operands[3] == null) {
1339 new_operands[3] = SqlLiteral.createExactNumeric(
"1", pos);
1341 new_operands[3] = operands[3];
1344 if (num_operands < 5 || operands[4] == null) {
1345 new_operands[4] = SqlLiteral.createExactNumeric(
"0", pos);
1347 new_operands[4] = operands[4];
1350 if (num_operands < 6 || operands[5] == null) {
1351 new_operands[5] = SqlLiteral.createCharString(
"c", pos);
1353 new_operands[5] = operands[5];
1355 return super.createCall(functionQualifier, pos, new_operands);
1360 return opBinding.getOperandType(0);
1366 super(
"REGEXP_SUBSTR",
1367 SqlKind.OTHER_FUNCTION,
1370 OperandTypes.family(getSignatureFamilies()),
1376 SqlKind.OTHER_FUNCTION,
1379 OperandTypes.family(getSignatureFamilies()),
1380 SqlFunctionCategory.SYSTEM);
1384 java.util.ArrayList<SqlTypeFamily> families =
1385 new java.util.ArrayList<SqlTypeFamily>();
1388 families.add(SqlTypeFamily.INTEGER);
1389 families.add(SqlTypeFamily.INTEGER);
1391 families.add(SqlTypeFamily.INTEGER);
1396 public SqlCall
createCall(@Nullable SqlLiteral functionQualifier,
1398 @Nullable SqlNode... operands) {
1399 assert functionQualifier == null;
1400 final int num_operands = operands.length;
1401 if (num_operands < 2 || num_operands > 6) {
1402 throw new IllegalArgumentException(
1403 "Invalid operand count " + Arrays.toString(operands));
1405 SqlNode[] new_operands =
new SqlNode[6];
1408 new_operands[0] = operands[0];
1410 new_operands[1] = operands[1];
1412 if (num_operands < 3 || operands[2] == null) {
1413 new_operands[2] = SqlLiteral.createExactNumeric(
"1", pos);
1415 new_operands[2] = operands[2];
1418 if (num_operands < 4 || operands[3] == null) {
1419 new_operands[3] = SqlLiteral.createExactNumeric(
"1", pos);
1421 new_operands[3] = operands[3];
1424 if (num_operands < 5 || operands[4] == null) {
1425 new_operands[4] = SqlLiteral.createCharString(
"c", pos);
1427 new_operands[4] = operands[4];
1430 if (num_operands < 6 || operands[5] == null) {
1431 new_operands[5] = SqlLiteral.createExactNumeric(
"1", pos);
1433 new_operands[5] = operands[5];
1435 return super.createCall(functionQualifier, pos, new_operands);
1440 return opBinding.getOperandType(0);
1446 super(
"REGEXP_MATCH");
1452 super(
"REGEXP_COUNT",
1453 SqlKind.OTHER_FUNCTION,
1456 OperandTypes.family(getSignatureFamilies()),
1461 java.util.ArrayList<SqlTypeFamily> families =
1462 new java.util.ArrayList<SqlTypeFamily>();
1465 families.add(SqlTypeFamily.INTEGER);
1471 public SqlCall
createCall(@Nullable SqlLiteral functionQualifier,
1473 @Nullable SqlNode... operands) {
1474 assert functionQualifier == null;
1475 final int num_operands = operands.length;
1476 if (num_operands < 2 || num_operands > 4) {
1477 throw new IllegalArgumentException(
1478 "Invalid operand count " + Arrays.toString(operands));
1480 SqlNode[] new_operands =
new SqlNode[4];
1482 new_operands[0] = operands[0];
1484 new_operands[1] = operands[1];
1486 if (num_operands < 3 || operands[2] == null) {
1487 new_operands[2] = SqlLiteral.createExactNumeric(
"1", pos);
1489 new_operands[2] = operands[2];
1492 if (num_operands < 4 || operands[3] == null) {
1493 new_operands[3] = SqlLiteral.createCharString(
"c", pos);
1495 new_operands[3] = operands[3];
1497 return super.createCall(functionQualifier, pos, new_operands);
1502 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1503 RelDataType dataType = typeFactory.createSqlType(SqlTypeName.BIGINT);
1504 return typeFactory.createTypeWithNullability(dataType,
true);
1510 super(
"BASE64_ENCODE",
1511 SqlKind.OTHER_FUNCTION,
1514 OperandTypes.family(getSignatureFamilies()),
1519 java.util.ArrayList<SqlTypeFamily> families =
1520 new java.util.ArrayList<SqlTypeFamily>();
1527 return opBinding.getOperandType(0);
1533 super(
"BASE64_DECODE",
1534 SqlKind.OTHER_FUNCTION,
1537 OperandTypes.family(getSignatureFamilies()),
1542 java.util.ArrayList<SqlTypeFamily> families =
1543 new java.util.ArrayList<SqlTypeFamily>();
1550 return opBinding.getOperandType(0);
1557 SqlKind.OTHER_FUNCTION,
1560 OperandTypes.family(getSignatureFamilies()),
1565 java.util.ArrayList<SqlTypeFamily> families =
1566 new java.util.ArrayList<SqlTypeFamily>();
1573 return opBinding.getOperandType(0);
1580 SqlKind.OTHER_FUNCTION,
1583 OperandTypes.family(getSignatureFamilies()),
1588 java.util.ArrayList<SqlTypeFamily> families =
1589 new java.util.ArrayList<SqlTypeFamily>();
1596 return opBinding.getOperandType(0);
1602 super(
"JAROWINKLER_SIMILARITY",
1603 SqlKind.OTHER_FUNCTION,
1606 OperandTypes.family(getSignatureFamilies()),
1611 java.util.ArrayList<SqlTypeFamily> families =
1612 new java.util.ArrayList<SqlTypeFamily>();
1620 assert opBinding.getOperandCount() == 2;
1621 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1622 RelDataType dataType = typeFactory.createSqlType(SqlTypeName.BIGINT);
1623 return typeFactory.createTypeWithNullability(dataType,
true);
1629 super(
"LEVENSHTEIN_DISTANCE",
1630 SqlKind.OTHER_FUNCTION,
1633 OperandTypes.family(getSignatureFamilies()),
1638 java.util.ArrayList<SqlTypeFamily> families =
1639 new java.util.ArrayList<SqlTypeFamily>();
1647 assert opBinding.getOperandCount() == 2;
1648 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1649 RelDataType dataType = typeFactory.createSqlType(SqlTypeName.BIGINT);
1650 return typeFactory.createTypeWithNullability(dataType,
true);
1659 SqlKind.OTHER_FUNCTION,
1661 InferTypes.FIRST_KNOWN,
1663 SqlFunctionCategory.SYSTEM);
1669 assert opBinding.getOperandCount() == 2;
1670 RelDataType ret = opBinding.getOperandType(1);
1671 RelDataType firstType = opBinding.getOperandType(0);
1672 ret = opBinding.getTypeFactory().createTypeWithNullability(
1673 ret, firstType.isNullable());
1674 if (opBinding instanceof SqlCallBinding) {
1675 SqlCallBinding callBinding = (SqlCallBinding) opBinding;
1676 SqlNode operand0 = callBinding.operand(0);
1680 if (((operand0 instanceof SqlLiteral)
1681 && (((SqlLiteral) operand0).getValue() == null))
1682 || (operand0 instanceof SqlDynamicParam)) {
1685 validator.setValidatedNodeType(operand0, ret);
1692 assert operandsCount == 2;
1693 return "{0}({1} AS {2})";
1697 return SqlOperandCountRanges.of(2);
1706 final SqlNode left = callBinding.operand(0);
1707 final SqlNode right = callBinding.operand(1);
1708 if (SqlUtil.isNullLiteral(left,
false) || left instanceof SqlDynamicParam) {
1711 RelDataType validatedNodeType =
1712 callBinding.getValidator().getValidatedNodeType(left);
1713 RelDataType returnType =
1714 callBinding.getValidator().deriveType(callBinding.getScope(), right);
1715 if (!SqlTypeUtil.canCastFrom(returnType, validatedNodeType,
true)) {
1716 if (throwOnFailure) {
1717 throw callBinding.newError(RESOURCE.cannotCastValue(
1718 validatedNodeType.toString(), returnType.toString()));
1722 if (SqlTypeUtil.areCharacterSetsMismatched(validatedNodeType, returnType)) {
1723 if (throwOnFailure) {
1726 throw callBinding.newError(RESOURCE.cannotCastValue(
1727 validatedNodeType.getFullTypeString(), returnType.getFullTypeString()));
1735 return SqlSyntax.FUNCTION;
1738 public void unparse(SqlWriter writer, SqlCall call,
int leftPrec,
int rightPrec) {
1739 assert call.operandCount() == 2;
1740 final SqlWriter.Frame frame = writer.startFunCall(getName());
1741 call.operand(0).unparse(writer, 0, 0);
1743 if (call.operand(1) instanceof SqlIntervalQualifier) {
1744 writer.sep(
"INTERVAL");
1746 call.operand(1).unparse(writer, 0, 0);
1747 writer.endFunCall(frame);
1751 public static class Hash extends SqlFunction {
1754 SqlKind.OTHER_FUNCTION,
1757 OperandTypes.family(getSignatureFamilies()),
1758 SqlFunctionCategory.SYSTEM);
1762 java.util.ArrayList<SqlTypeFamily> families =
1763 new java.util.ArrayList<SqlTypeFamily>();
1772 assert opBinding.getOperandCount() == 1;
1773 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1774 return typeFactory.createTypeWithNullability(
1775 typeFactory.createSqlType(SqlTypeName.BIGINT),
1776 opBinding.getOperandType(0).isNullable());
1780 public static class Likely extends SqlFunction {
1783 SqlKind.OTHER_FUNCTION,
1786 OperandTypes.BOOLEAN,
1787 SqlFunctionCategory.SYSTEM);
1792 return opBinding.getOperandType(0);
1799 SqlKind.OTHER_FUNCTION,
1802 OperandTypes.BOOLEAN,
1803 SqlFunctionCategory.SYSTEM);
1808 return opBinding.getOperandType(0);
1812 public static class Sign extends SqlFunction {
1815 SqlKind.OTHER_FUNCTION,
1818 OperandTypes.NUMERIC,
1819 SqlFunctionCategory.NUMERIC);
1824 return opBinding.getOperandType(0);
1831 SqlKind.OTHER_FUNCTION,
1834 OperandTypes.family(signature()),
1835 SqlFunctionCategory.NUMERIC);
1840 assert opBinding.getOperandCount() == 2;
1841 return opBinding.getOperandType(0);
1845 java.util.List<SqlTypeFamily> truncate_sig =
1846 new java.util.ArrayList<SqlTypeFamily>();
1847 truncate_sig.add(SqlTypeFamily.NUMERIC);
1848 truncate_sig.add(SqlTypeFamily.INTEGER);
1849 return truncate_sig;
1856 SqlKind.OTHER_FUNCTION,
1859 OperandTypes.family(signature()),
1860 SqlFunctionCategory.SYSTEM);
1865 assert opBinding.getOperandCount() == 1;
1866 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1867 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1871 java.util.List<SqlTypeFamily> st_isempty_sig =
1872 new java.util.ArrayList<SqlTypeFamily>();
1873 st_isempty_sig.add(SqlTypeFamily.ANY);
1874 return st_isempty_sig;
1881 SqlKind.OTHER_FUNCTION,
1884 OperandTypes.family(signature()),
1885 SqlFunctionCategory.SYSTEM);
1890 assert opBinding.getOperandCount() == 1;
1891 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1892 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1896 java.util.List<SqlTypeFamily> st_isvalid_sig =
1897 new java.util.ArrayList<SqlTypeFamily>();
1898 st_isvalid_sig.add(SqlTypeFamily.ANY);
1899 return st_isvalid_sig;
1905 super(
"ST_Contains",
1906 SqlKind.OTHER_FUNCTION,
1909 OperandTypes.family(signature()),
1910 SqlFunctionCategory.SYSTEM);
1915 assert opBinding.getOperandCount() == 2;
1916 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1917 return typeFactory.createTypeWithNullability(
1918 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1919 opBinding.getOperandType(0).isNullable()
1920 || opBinding.getOperandType(1).isNullable());
1924 java.util.List<SqlTypeFamily> st_contains_sig =
1925 new java.util.ArrayList<SqlTypeFamily>();
1926 st_contains_sig.add(SqlTypeFamily.ANY);
1927 st_contains_sig.add(SqlTypeFamily.ANY);
1928 return st_contains_sig;
1935 SqlKind.OTHER_FUNCTION,
1938 OperandTypes.family(signature()),
1939 SqlFunctionCategory.SYSTEM);
1944 assert opBinding.getOperandCount() == 2;
1945 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1946 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1950 java.util.List<SqlTypeFamily> st_equals_sig =
1951 new java.util.ArrayList<SqlTypeFamily>();
1952 st_equals_sig.add(SqlTypeFamily.ANY);
1953 st_equals_sig.add(SqlTypeFamily.ANY);
1954 return st_equals_sig;
1960 super(
"ST_Intersects",
1961 SqlKind.OTHER_FUNCTION,
1964 OperandTypes.family(signature()),
1965 SqlFunctionCategory.SYSTEM);
1970 assert opBinding.getOperandCount() == 2;
1971 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1972 return typeFactory.createTypeWithNullability(
1973 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1974 opBinding.getOperandType(0).isNullable()
1975 || opBinding.getOperandType(1).isNullable());
1979 java.util.List<SqlTypeFamily> st_intersects_sig =
1980 new java.util.ArrayList<SqlTypeFamily>();
1981 st_intersects_sig.add(SqlTypeFamily.ANY);
1982 st_intersects_sig.add(SqlTypeFamily.ANY);
1983 return st_intersects_sig;
1989 super(
"ST_IntersectsBox",
1990 SqlKind.OTHER_FUNCTION,
1993 OperandTypes.family(signature()),
1994 SqlFunctionCategory.SYSTEM);
1999 assert opBinding.getOperandCount() == 2;
2000 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2001 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
2005 java.util.List<SqlTypeFamily> st_intersect_box_sig =
2006 new java.util.ArrayList<SqlTypeFamily>();
2007 st_intersect_box_sig.add(SqlTypeFamily.ANY);
2008 st_intersect_box_sig.add(SqlTypeFamily.ANY);
2009 return st_intersect_box_sig;
2015 super(
"ST_Approx_Overlaps",
2016 SqlKind.OTHER_FUNCTION,
2019 OperandTypes.family(signature()),
2020 SqlFunctionCategory.SYSTEM);
2025 assert opBinding.getOperandCount() == 2;
2026 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2027 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
2031 java.util.List<SqlTypeFamily> st_intersect_box_sig =
2032 new java.util.ArrayList<SqlTypeFamily>();
2033 st_intersect_box_sig.add(SqlTypeFamily.ANY);
2034 st_intersect_box_sig.add(SqlTypeFamily.ANY);
2035 return st_intersect_box_sig;
2041 super(
"ST_Disjoint",
2042 SqlKind.OTHER_FUNCTION,
2045 OperandTypes.family(signature()),
2046 SqlFunctionCategory.SYSTEM);
2051 assert opBinding.getOperandCount() == 2;
2052 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2053 return typeFactory.createTypeWithNullability(
2054 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
2055 opBinding.getOperandType(0).isNullable()
2056 || opBinding.getOperandType(1).isNullable());
2060 java.util.List<SqlTypeFamily> st_disjoint_sig =
2061 new java.util.ArrayList<SqlTypeFamily>();
2062 st_disjoint_sig.add(SqlTypeFamily.ANY);
2063 st_disjoint_sig.add(SqlTypeFamily.ANY);
2064 return st_disjoint_sig;
2071 SqlKind.OTHER_FUNCTION,
2074 OperandTypes.family(signature()),
2075 SqlFunctionCategory.SYSTEM);
2080 assert opBinding.getOperandCount() == 2;
2081 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2082 return typeFactory.createTypeWithNullability(
2083 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
2084 opBinding.getOperandType(0).isNullable()
2085 || opBinding.getOperandType(1).isNullable());
2089 java.util.List<SqlTypeFamily> st_within_sig =
2090 new java.util.ArrayList<SqlTypeFamily>();
2091 st_within_sig.add(SqlTypeFamily.ANY);
2092 st_within_sig.add(SqlTypeFamily.ANY);
2093 return st_within_sig;
2100 SqlKind.OTHER_FUNCTION,
2103 OperandTypes.family(signature()),
2104 SqlFunctionCategory.SYSTEM);
2109 assert opBinding.getOperandCount() == 3;
2110 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2111 return typeFactory.createTypeWithNullability(
2112 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
2113 opBinding.getOperandType(0).isNullable()
2114 || opBinding.getOperandType(1).isNullable()
2115 || opBinding.getOperandType(2).isNullable());
2119 java.util.List<SqlTypeFamily> st_dwithin_sig =
2120 new java.util.ArrayList<SqlTypeFamily>();
2121 st_dwithin_sig.add(SqlTypeFamily.ANY);
2122 st_dwithin_sig.add(SqlTypeFamily.ANY);
2123 st_dwithin_sig.add(SqlTypeFamily.NUMERIC);
2124 return st_dwithin_sig;
2130 super(
"ST_DFullyWithin",
2131 SqlKind.OTHER_FUNCTION,
2134 OperandTypes.family(signature()),
2135 SqlFunctionCategory.SYSTEM);
2140 assert opBinding.getOperandCount() == 3;
2141 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2142 return typeFactory.createTypeWithNullability(
2143 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
2144 opBinding.getOperandType(0).isNullable()
2145 || opBinding.getOperandType(1).isNullable()
2146 || opBinding.getOperandType(2).isNullable());
2150 java.util.List<SqlTypeFamily> st_dwithin_sig =
2151 new java.util.ArrayList<SqlTypeFamily>();
2152 st_dwithin_sig.add(SqlTypeFamily.ANY);
2153 st_dwithin_sig.add(SqlTypeFamily.ANY);
2154 st_dwithin_sig.add(SqlTypeFamily.NUMERIC);
2155 return st_dwithin_sig;
2161 super(
"ST_Distance",
2162 SqlKind.OTHER_FUNCTION,
2165 OperandTypes.family(signature()),
2166 SqlFunctionCategory.SYSTEM);
2171 assert opBinding.getOperandCount() == 2;
2172 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2173 return typeFactory.createTypeWithNullability(
2174 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2175 opBinding.getOperandType(0).isNullable()
2176 || opBinding.getOperandType(1).isNullable());
2180 java.util.List<SqlTypeFamily> st_distance_sig =
2181 new java.util.ArrayList<SqlTypeFamily>();
2182 st_distance_sig.add(SqlTypeFamily.ANY);
2183 st_distance_sig.add(SqlTypeFamily.ANY);
2184 return st_distance_sig;
2190 super(
"ST_MaxDistance",
2191 SqlKind.OTHER_FUNCTION,
2194 OperandTypes.family(signature()),
2195 SqlFunctionCategory.SYSTEM);
2200 assert opBinding.getOperandCount() == 2;
2201 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2202 return typeFactory.createTypeWithNullability(
2203 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2204 opBinding.getOperandType(0).isNullable()
2205 || opBinding.getOperandType(1).isNullable());
2209 java.util.List<SqlTypeFamily> st_maxdistance_sig =
2210 new java.util.ArrayList<SqlTypeFamily>();
2211 st_maxdistance_sig.add(SqlTypeFamily.ANY);
2212 st_maxdistance_sig.add(SqlTypeFamily.ANY);
2213 return st_maxdistance_sig;
2219 super(
"ST_GeogFromText",
2220 SqlKind.OTHER_FUNCTION,
2223 OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
2224 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
2225 SqlFunctionCategory.SYSTEM);
2230 assert opBinding.getOperandCount() == 1;
2231 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2232 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2238 super(
"ST_GeomFromText",
2239 SqlKind.OTHER_FUNCTION,
2242 OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
2243 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
2244 SqlFunctionCategory.SYSTEM);
2249 assert opBinding.getOperandCount() == 1;
2250 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2251 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2257 super(
"ST_Transform",
2258 SqlKind.OTHER_FUNCTION,
2261 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
2262 SqlFunctionCategory.SYSTEM);
2267 assert opBinding.getOperandCount() == 1;
2268 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2269 return typeFactory.createTypeWithNullability(
2270 typeFactory.createSqlType(SqlTypeName.INTEGER),
2271 opBinding.getOperandType(0).isNullable());
2275 static class ST_X extends SqlFunction {
2278 SqlKind.OTHER_FUNCTION,
2281 OperandTypes.family(SqlTypeFamily.ANY),
2282 SqlFunctionCategory.SYSTEM);
2287 assert opBinding.getOperandCount() == 1;
2288 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2289 return typeFactory.createTypeWithNullability(
2290 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2291 opBinding.getOperandType(0).isNullable());
2295 static class ST_Y extends SqlFunction {
2298 SqlKind.OTHER_FUNCTION,
2301 OperandTypes.family(SqlTypeFamily.ANY),
2302 SqlFunctionCategory.SYSTEM);
2307 assert opBinding.getOperandCount() == 1;
2308 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2309 return typeFactory.createTypeWithNullability(
2310 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2311 opBinding.getOperandType(0).isNullable());
2318 SqlKind.OTHER_FUNCTION,
2321 OperandTypes.family(SqlTypeFamily.ANY),
2322 SqlFunctionCategory.SYSTEM);
2327 assert opBinding.getOperandCount() == 1;
2328 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2329 return typeFactory.createTypeWithNullability(
2330 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2331 opBinding.getOperandType(0).isNullable());
2338 SqlKind.OTHER_FUNCTION,
2341 OperandTypes.family(SqlTypeFamily.ANY),
2342 SqlFunctionCategory.SYSTEM);
2347 assert opBinding.getOperandCount() == 1;
2348 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2349 return typeFactory.createTypeWithNullability(
2350 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2351 opBinding.getOperandType(0).isNullable());
2358 SqlKind.OTHER_FUNCTION,
2361 OperandTypes.family(SqlTypeFamily.ANY),
2362 SqlFunctionCategory.SYSTEM);
2367 assert opBinding.getOperandCount() == 1;
2368 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2369 return typeFactory.createTypeWithNullability(
2370 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2371 opBinding.getOperandType(0).isNullable());
2378 SqlKind.OTHER_FUNCTION,
2381 OperandTypes.family(SqlTypeFamily.ANY),
2382 SqlFunctionCategory.SYSTEM);
2387 assert opBinding.getOperandCount() == 1;
2388 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2389 return typeFactory.createTypeWithNullability(
2390 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2391 opBinding.getOperandType(0).isNullable());
2398 SqlKind.OTHER_FUNCTION,
2401 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
2402 SqlFunctionCategory.SYSTEM);
2407 assert opBinding.getOperandCount() == 1;
2408 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2409 return typeFactory.createTypeWithNullability(
2410 typeFactory.createSqlType(SqlTypeName.INTEGER),
2411 opBinding.getOperandType(0).isNullable());
2417 super(
"ST_EndPoint",
2418 SqlKind.OTHER_FUNCTION,
2421 OperandTypes.family(SqlTypeFamily.ANY),
2422 SqlFunctionCategory.SYSTEM);
2427 assert opBinding.getOperandCount() == 1;
2428 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2429 return typeFactory.createTypeWithNullability(
2430 typeFactory.createSqlType(SqlTypeName.INTEGER),
2431 opBinding.getOperandType(0).isNullable());
2437 super(
"ST_StartPoint",
2438 SqlKind.OTHER_FUNCTION,
2441 OperandTypes.family(SqlTypeFamily.ANY),
2442 SqlFunctionCategory.SYSTEM);
2447 assert opBinding.getOperandCount() == 1;
2448 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2449 return typeFactory.createTypeWithNullability(
2450 typeFactory.createSqlType(SqlTypeName.INTEGER),
2451 opBinding.getOperandType(0).isNullable());
2458 SqlKind.OTHER_FUNCTION,
2461 OperandTypes.family(SqlTypeFamily.ANY),
2462 SqlFunctionCategory.SYSTEM);
2467 assert opBinding.getOperandCount() == 1;
2468 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2469 return typeFactory.createTypeWithNullability(
2470 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2471 opBinding.getOperandType(0).isNullable());
2477 super(
"ST_Perimeter",
2478 SqlKind.OTHER_FUNCTION,
2481 OperandTypes.family(SqlTypeFamily.ANY),
2482 SqlFunctionCategory.SYSTEM);
2487 assert opBinding.getOperandCount() == 1;
2488 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2489 return typeFactory.createTypeWithNullability(
2490 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2491 opBinding.getOperandType(0).isNullable());
2498 SqlKind.OTHER_FUNCTION,
2501 OperandTypes.family(SqlTypeFamily.ANY),
2502 SqlFunctionCategory.SYSTEM);
2507 assert opBinding.getOperandCount() == 1;
2508 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2509 return typeFactory.createTypeWithNullability(
2510 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2511 opBinding.getOperandType(0).isNullable());
2518 SqlKind.OTHER_FUNCTION,
2521 OperandTypes.family(SqlTypeFamily.ANY),
2522 SqlFunctionCategory.SYSTEM);
2527 assert opBinding.getOperandCount() == 1;
2528 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2529 return typeFactory.createTypeWithNullability(
2530 typeFactory.createSqlType(SqlTypeName.INTEGER),
2531 opBinding.getOperandType(0).isNullable());
2538 SqlKind.OTHER_FUNCTION,
2541 OperandTypes.family(SqlTypeFamily.ANY),
2542 SqlFunctionCategory.SYSTEM);
2547 assert opBinding.getOperandCount() == 1;
2548 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2549 return typeFactory.createTypeWithNullability(
2550 typeFactory.createSqlType(SqlTypeName.INTEGER),
2551 opBinding.getOperandType(0).isNullable());
2557 super(
"ST_NumGeometries",
2558 SqlKind.OTHER_FUNCTION,
2561 OperandTypes.family(SqlTypeFamily.ANY),
2562 SqlFunctionCategory.SYSTEM);
2567 assert opBinding.getOperandCount() == 1;
2568 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2569 return typeFactory.createTypeWithNullability(
2570 typeFactory.createSqlType(SqlTypeName.INTEGER),
2571 opBinding.getOperandType(0).isNullable());
2578 SqlKind.OTHER_FUNCTION,
2581 OperandTypes.family(SqlTypeFamily.ANY),
2582 SqlFunctionCategory.SYSTEM);
2587 assert opBinding.getOperandCount() == 1;
2588 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2589 return typeFactory.createTypeWithNullability(
2590 typeFactory.createSqlType(SqlTypeName.INTEGER),
2591 opBinding.getOperandType(0).isNullable());
2598 SqlKind.OTHER_FUNCTION,
2601 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
2602 SqlFunctionCategory.SYSTEM);
2607 assert opBinding.getOperandCount() == 1;
2608 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2609 return typeFactory.createTypeWithNullability(
2610 typeFactory.createSqlType(SqlTypeName.INTEGER),
2611 opBinding.getOperandType(0).isNullable());
2618 SqlKind.OTHER_FUNCTION,
2621 OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
2622 SqlFunctionCategory.SYSTEM);
2627 assert opBinding.getOperandCount() == 2;
2628 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2629 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2635 super(
"ST_Centroid",
2636 SqlKind.OTHER_FUNCTION,
2639 OperandTypes.family(signature()),
2640 SqlFunctionCategory.SYSTEM);
2645 assert opBinding.getOperandCount() == 1;
2646 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2647 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2651 java.util.List<SqlTypeFamily> st_centroid_sig =
2652 new java.util.ArrayList<SqlTypeFamily>();
2653 st_centroid_sig.add(SqlTypeFamily.ANY);
2654 return st_centroid_sig;
2661 SqlKind.OTHER_FUNCTION,
2664 OperandTypes.family(signature()),
2665 SqlFunctionCategory.SYSTEM);
2670 assert opBinding.getOperandCount() == 2;
2671 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2672 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2676 java.util.List<SqlTypeFamily> st_buffer_sig =
2677 new java.util.ArrayList<SqlTypeFamily>();
2678 st_buffer_sig.add(SqlTypeFamily.ANY);
2679 st_buffer_sig.add(SqlTypeFamily.NUMERIC);
2680 return st_buffer_sig;
2686 super(
"ST_ConcaveHull",
2687 SqlKind.OTHER_FUNCTION,
2690 OperandTypes.family(signature()),
2691 SqlFunctionCategory.SYSTEM);
2696 assert opBinding.getOperandCount() == 2;
2697 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2698 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2702 java.util.List<SqlTypeFamily> st_concavehull_sig =
2703 new java.util.ArrayList<SqlTypeFamily>();
2704 st_concavehull_sig.add(SqlTypeFamily.ANY);
2705 st_concavehull_sig.add(SqlTypeFamily.NUMERIC);
2706 return st_concavehull_sig;
2712 super(
"ST_ConvexHull",
2713 SqlKind.OTHER_FUNCTION,
2716 OperandTypes.family(signature()),
2717 SqlFunctionCategory.SYSTEM);
2722 assert opBinding.getOperandCount() == 1;
2723 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2724 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2728 java.util.List<SqlTypeFamily> st_convexhull_sig =
2729 new java.util.ArrayList<SqlTypeFamily>();
2730 st_convexhull_sig.add(SqlTypeFamily.ANY);
2731 return st_convexhull_sig;
2737 super(
"ST_Intersection",
2738 SqlKind.OTHER_FUNCTION,
2741 OperandTypes.family(signature()),
2742 SqlFunctionCategory.SYSTEM);
2747 assert opBinding.getOperandCount() == 2;
2748 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2749 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2753 java.util.List<SqlTypeFamily> st_intersection_sig =
2754 new java.util.ArrayList<SqlTypeFamily>();
2755 st_intersection_sig.add(SqlTypeFamily.ANY);
2756 st_intersection_sig.add(SqlTypeFamily.ANY);
2757 return st_intersection_sig;
2764 SqlKind.OTHER_FUNCTION,
2767 OperandTypes.family(signature()),
2768 SqlFunctionCategory.SYSTEM);
2773 assert opBinding.getOperandCount() == 2;
2774 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2775 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2779 java.util.List<SqlTypeFamily> st_union_sig =
2780 new java.util.ArrayList<SqlTypeFamily>();
2781 st_union_sig.add(SqlTypeFamily.ANY);
2782 st_union_sig.add(SqlTypeFamily.ANY);
2783 return st_union_sig;
2789 super(
"ST_Difference",
2790 SqlKind.OTHER_FUNCTION,
2793 OperandTypes.family(signature()),
2794 SqlFunctionCategory.SYSTEM);
2799 assert opBinding.getOperandCount() == 2;
2800 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2801 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2805 java.util.List<SqlTypeFamily> st_difference_sig =
2806 new java.util.ArrayList<SqlTypeFamily>();
2807 st_difference_sig.add(SqlTypeFamily.ANY);
2808 st_difference_sig.add(SqlTypeFamily.ANY);
2809 return st_difference_sig;
2815 super(
"CastToGeography",
2816 SqlKind.OTHER_FUNCTION,
2819 OperandTypes.family(SqlTypeFamily.ANY),
2820 SqlFunctionCategory.SYSTEM);
2825 assert opBinding.getOperandCount() == 1;
2826 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2827 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2833 super(
"ENCODE_TEXT",
2834 SqlKind.OTHER_FUNCTION,
2837 OperandTypes.family(SqlTypeFamily.STRING),
2838 SqlFunctionCategory.SYSTEM);
2843 assert opBinding.getOperandCount() == 1;
2844 return opBinding.getOperandType(0);
2851 super(
"OFFSET_IN_FRAGMENT",
2852 SqlKind.OTHER_FUNCTION,
2855 OperandTypes.NILADIC,
2856 SqlFunctionCategory.SYSTEM);
2861 assert opBinding.getOperandCount() == 0;
2862 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2863 return typeFactory.createSqlType(SqlTypeName.BIGINT);
2869 super(
"APPROX_COUNT_DISTINCT",
2871 SqlKind.OTHER_FUNCTION,
2874 OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
2875 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
2876 SqlFunctionCategory.SYSTEM,
2879 Optionality.FORBIDDEN);
2884 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2885 return typeFactory.createSqlType(SqlTypeName.BIGINT);
2891 super(
"APPROX_MEDIAN",
2892 SqlKind.OTHER_FUNCTION,
2895 OperandTypes.family(SqlTypeFamily.NUMERIC),
2896 SqlFunctionCategory.SYSTEM);
2901 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2902 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2908 super(
"APPROX_PERCENTILE",
2909 SqlKind.OTHER_FUNCTION,
2912 OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
2913 SqlFunctionCategory.SYSTEM);
2918 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2919 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2925 super(
"APPROX_QUANTILE",
2926 SqlKind.OTHER_FUNCTION,
2929 OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
2930 SqlFunctionCategory.SYSTEM);
2935 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2936 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2944 SqlKind.OTHER_FUNCTION,
2947 OperandTypes.or(OperandTypes.family(SqlTypeFamily.NUMERIC),
2948 OperandTypes.family(SqlTypeFamily.GEO)),
2949 SqlFunctionCategory.SYSTEM);
2954 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2955 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2959 static class Mode extends SqlAggFunction {
2962 SqlKind.OTHER_FUNCTION,
2966 SqlFunctionCategory.SYSTEM);
2971 return opBinding.getOperandType(0);
2975 public static class Sample extends SqlAggFunction {
2979 SqlKind.OTHER_FUNCTION,
2983 SqlFunctionCategory.SYSTEM,
2986 Optionality.FORBIDDEN);
2991 return opBinding.getOperandType(0);
2998 super(
"LAST_SAMPLE",
3000 SqlKind.OTHER_FUNCTION,
3004 SqlFunctionCategory.SYSTEM,
3007 Optionality.FORBIDDEN);
3012 return opBinding.getOperandType(0);
3020 SqlKind.OTHER_FUNCTION,
3024 SqlFunctionCategory.SYSTEM,
3027 Optionality.FORBIDDEN);
3032 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3033 return typeFactory.createTypeWithNullability(
3034 typeFactory.createSqlType(SqlTypeName.BIGINT),
false);
3038 static class SumIf extends SqlAggFunction {
3041 SqlKind.OTHER_FUNCTION,
3044 OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.BOOLEAN),
3045 SqlFunctionCategory.SYSTEM);
3050 return opBinding.getOperandType(0);
3056 super(
"CONDITIONAL_CHANGE_EVENT",
3058 SqlKind.OTHER_FUNCTION,
3061 OperandTypes.family(SqlTypeFamily.ANY),
3062 SqlFunctionCategory.SYSTEM,
3065 Optionality.FORBIDDEN);
3080 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3081 return typeFactory.createSqlType(SqlTypeName.BIGINT);
3088 SqlKind.OTHER_FUNCTION,
3092 SqlFunctionCategory.USER_DEFINED_FUNCTION);
3094 arg_names = sig.getArgNames();
3104 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3106 SqlTypeName valueType =
3108 RelDataType subType = typeFactory.createSqlType(valueType, -1);
3109 RelDataType arr = typeFactory.createArrayType(subType, -1);
3113 SqlTypeName ret = sig.getSqlRet();
3114 return typeFactory.createTypeWithNullability(
3115 typeFactory.createSqlType(ret),
true);
3126 SqlKind.OTHER_FUNCTION,
3130 SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION);
3131 arg_types = sig.getArgs();
3132 outs = sig.getOuts();
3133 out_names = sig.getOutNames();
3134 arg_names = sig.getArgNames();
3138 pretty_arg_names = sig.getPrettyArgNames();
3139 options = sig.getOptions();
3140 cursor_field_types = sig.getCursorFieldTypes();
3141 default_values = sig.getDefaultValues();
3151 return pretty_arg_names;
3165 final Boolean has_names = this.pretty_arg_names != null
3166 && this.pretty_arg_names.size() == this.arg_types.size();
3167 final List<FunctionParameter> parameters =
new java.util.ArrayList<>();
3168 for (
int i = 0; i < this.arg_types.size(); i++) {
3169 final int arg_idx = i;
3170 parameters.add(
new FunctionParameter() {
3171 public int getOrdinal() {
3175 public String getName() {
3177 return pretty_arg_names.get(arg_idx);
3179 return "arg" + arg_idx;
3182 public RelDataType getType(RelDataTypeFactory typeFactory) {
3183 SqlTypeFamily
type = toSqlTypeName(arg_types.get(arg_idx)).getFamily();
3184 return type.getDefaultConcreteType(typeFactory);
3187 public boolean isOptional() {
3197 return opBinding -> {
3198 RelDataTypeFactory fact = opBinding.getTypeFactory();
3199 FieldInfoBuilder ret = fact.builder();
3200 for (
int out_idx = 0; out_idx < outs.size(); ++out_idx) {
3202 if (toSqlTypeName(outs.get(out_idx)) == SqlTypeName.ARRAY) {
3205 extSubType = getValueType(extSubType);
3207 RelDataType subtype = fact.createSqlType(toSqlTypeName(extSubType));
3208 type = fact.createArrayType(subtype, -1);
3210 type = fact.createSqlType(toSqlTypeName(outs.get(out_idx)));
3212 ret = ret.add(out_names.get(out_idx), type);
3213 ret = ret.nullable(
true);
3221 System.out.println(msg);
3226 final Boolean debugMode =
false;
3227 Set<RelColumnMapping> s =
new HashSet<RelColumnMapping>();
3228 debugPrint(
"getNameAsId() -> " + getNameAsId() +
", arg_names=" + arg_names
3229 +
", out_names=" + out_names,
3231 if (
Integer.valueOf(options.getOrDefault(
"filter_table_function_transpose",
"0"))
3233 debugPrint(
"getNameAsId() -> " + getNameAsId(), debugMode);
3235 for (
int arg_idx = 0; arg_idx < arg_names.size(); ++arg_idx) {
3236 String arg_name = arg_names.get(arg_idx);
3238 int start = arg_name.indexOf(
"[");
3241 int end = arg_name.lastIndexOf(
"]");
3242 fields = arg_name.substring(start + 1, end)
3243 .replaceAll(
"\\s+",
"")
3246 fields =
new String[] {arg_name};
3248 debugPrint(
"fields=" + Arrays.toString(fields), debugMode);
3249 for (
int field_idx = 0; field_idx < fields.length; ++field_idx) {
3250 int out_idx = out_names.indexOf(fields[field_idx]);
3252 s.add(
new RelColumnMapping(out_idx, rel_idx, field_idx,
false));
3253 debugPrint(
"out_idx, arg_idx/rel_idx, field_idx=" + out_idx +
", " + arg_idx
3254 +
"/" + rel_idx +
", " + field_idx,
3273 StringBuilder ret =
new StringBuilder();
3275 ret.append(this.getName());
3278 for (
int i = 0; i < this.arg_types.size(); i++) {
3284 String paramName = arg_names.get(i);
3285 ret.append(paramName).
append(
" => ");
3287 final String t = type.toString().toUpperCase(Locale.ROOT);
3288 ret.append(
"<").
append(t);
3290 List<ExtensionFunction.ExtArgumentType> field_types =
3291 cursor_field_types.get(paramName);
3293 for (
int j = 0; j < field_types.size(); j++) {
3298 ret.append(toSqlTypeName(field_type));
3299 if (isColumnListType(field_type)) {
3302 ret.append(toSqlTypeName(subtype));
3304 }
else if (isColumnArrayType(field_type) || isArrayType(field_type)) {
3307 ret.append(toSqlTypeName(subtype));
3317 return ret.toString();
3323 return this.arg_names;
3329 return this.getExtendedSignature().hashCode();
3341 if (getClass() != obj.getClass()) {
3350 if (!this.getName().equals(other.getName())) {
3353 if (arg_types.size() != other.arg_types.size()) {
3357 for (
int i = 0; i < arg_types.size(); i++) {
3358 if (arg_types.get(i) != other.arg_types.get(i)) {
3362 String paramName = this.arg_names.get(i);
3363 String otherParamName = other.getExtendedParamNames().
get(i);
3364 if (!paramName.equals(otherParamName)) {
3368 List<ExtArgumentType> field_types = this.getCursorFieldTypes().
get(paramName);
3369 List<ExtArgumentType> other_field_types =
3370 other.getCursorFieldTypes().
get(paramName);
3371 if (field_types.size() != other_field_types.size()) {
3374 for (
int j = 0; j < field_types.size(); j++) {
3375 if (field_types.get(j) != other_field_types.get(j)) {
3386 return getExtendedSignature();
3390 return cursor_field_types;
3398 return default_values;
3402 return (default_values.size() > 0);
3409 String paramName = getParamNames().get(i);
3410 return getDefaultValues().get(paramName) != null;
3414 return getDefaultValues().size();
3431 for (Ord<SqlNode> operand : Ord.zip(permutedCall.getOperandList())) {
3432 if (operand.e.getClass() == SqlBasicCall.class) {
3433 SqlBasicCall operandAsCall = (SqlBasicCall) operand.e;
3434 if (operandAsCall.getOperator().getName() ==
"DEFAULT") {
3436 String paramName = tf.getExtendedParamNames().
get(operand.i);
3437 Comparable<?> defaultVal = tf.getDefaultValues().
get(paramName);
3438 SqlLiteral newOperand = createLiteralForDefaultValue(
3439 defaultVal, operand.e.getParserPosition());
3440 permutedCall.setOperand(operand.i, newOperand);
3444 return permutedCall;
3448 if (value instanceof
Integer || value instanceof Long || value instanceof
Float
3449 || value instanceof
Double) {
3450 return SqlLiteral.createExactNumeric(value.toString(), pos);
3451 }
else if (value instanceof Boolean) {
3452 Boolean asBool = (Boolean) value;
3453 return SqlLiteral.createBoolean(asBool.booleanValue(), pos);
3454 }
else if (value instanceof String) {
3455 return SqlLiteral.createCharString(value.toString(), pos);
3468 return getOperandTypeChecker().checkOperandTypes(callBinding, throwOnFailure);
3472 private final List<ExtArgumentType>
outs;
3487 super(
"HeavyDB_Geo_PolyBoundsPtr",
3488 SqlKind.OTHER_FUNCTION,
3491 OperandTypes.family(SqlTypeFamily.ANY),
3492 SqlFunctionCategory.SYSTEM);
3497 assert opBinding.getOperandCount() == 1;
3498 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3499 return typeFactory.createSqlType(SqlTypeName.BIGINT);
3505 super(
"convert_meters_to_pixel_width",
3506 SqlKind.OTHER_FUNCTION,
3509 OperandTypes.family(SqlTypeFamily.NUMERIC,
3511 SqlTypeFamily.NUMERIC,
3512 SqlTypeFamily.NUMERIC,
3513 SqlTypeFamily.NUMERIC,
3514 SqlTypeFamily.NUMERIC),
3515 SqlFunctionCategory.SYSTEM);
3520 assert opBinding.getOperandCount() == 6;
3521 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3522 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
3528 super(
"convert_meters_to_pixel_height",
3529 SqlKind.OTHER_FUNCTION,
3532 OperandTypes.family(SqlTypeFamily.NUMERIC,
3534 SqlTypeFamily.NUMERIC,
3535 SqlTypeFamily.NUMERIC,
3536 SqlTypeFamily.NUMERIC,
3537 SqlTypeFamily.NUMERIC),
3538 SqlFunctionCategory.SYSTEM);
3543 assert opBinding.getOperandCount() == 6;
3544 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3545 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
3551 super(
"is_point_in_view",
3552 SqlKind.OTHER_FUNCTION,
3555 OperandTypes.family(SqlTypeFamily.ANY,
3556 SqlTypeFamily.NUMERIC,
3557 SqlTypeFamily.NUMERIC,
3558 SqlTypeFamily.NUMERIC,
3559 SqlTypeFamily.NUMERIC),
3560 SqlFunctionCategory.SYSTEM);
3565 assert opBinding.getOperandCount() == 5;
3566 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3567 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
3573 super(
"is_point_size_in_view",
3574 SqlKind.OTHER_FUNCTION,
3577 OperandTypes.family(SqlTypeFamily.ANY,
3578 SqlTypeFamily.NUMERIC,
3579 SqlTypeFamily.NUMERIC,
3580 SqlTypeFamily.NUMERIC,
3581 SqlTypeFamily.NUMERIC,
3582 SqlTypeFamily.NUMERIC),
3583 SqlFunctionCategory.SYSTEM);
3588 assert opBinding.getOperandCount() == 6;
3589 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3590 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
3596 super(
"usTIMESTAMP",
3597 SqlKind.OTHER_FUNCTION,
3600 OperandTypes.STRING,
3601 SqlFunctionCategory.SYSTEM);
3606 assert opBinding.getOperandCount() == 1;
3607 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3608 return typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 6);
3614 super(
"nsTIMESTAMP",
3615 SqlKind.OTHER_FUNCTION,
3618 OperandTypes.STRING,
3619 SqlFunctionCategory.SYSTEM);
3624 assert opBinding.getOperandCount() == 1;
3625 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3626 return typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 9);
3632 super(
"FORWARD_FILL",
3637 OperandTypes.family(SqlTypeFamily.ANY),
3638 SqlFunctionCategory.SYSTEM,
3641 Optionality.FORBIDDEN);
3652 super(
"BACKWARD_FILL",
3657 OperandTypes.family(SqlTypeFamily.ANY),
3658 SqlFunctionCategory.SYSTEM,
3661 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)
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)
static java.util.List< SqlTypeFamily > getSignatureFamilies()
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
static java.util.List< SqlTypeFamily > getSignatureFamilies()
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()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
void debugPrint(String msg, Boolean debugMode)
final List< ExtArgumentType > arg_types
static java.util.List< SqlTypeFamily > getSignatureFamilies()
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)
static java.util.List< SqlTypeFamily > getSignatureFamilies()
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
SqlCall createCall(@Nullable SqlLiteral functionQualifier, SqlParserPos pos,@Nullable SqlNode...operands)
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)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
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)
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)