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) {
319 if (extSigs == null) {
322 HashSet<String> demangledNames =
new HashSet<String>();
324 final String demangledName =
dropSuffix(extSig.getKey());
325 final String demangledNameArity = extSig.getValue().isTableUdf()
326 ? String.format(
"%s-%s-%s",
328 extSig.getValue().getArgs(),
329 extSig.getValue().getCursorFieldTypes())
330 : String.format(
"%s-%d", demangledName, extSig.getValue().getArgs().size());
331 if (demangledNames.contains(demangledNameArity)) {
334 demangledNames.add(demangledNameArity);
335 if (extSig.getValue().isRowUdf()) {
344 int suffix_idx = str.indexOf(
"__");
345 if (suffix_idx == -1) {
348 assert suffix_idx > 0;
349 return str.substring(0, suffix_idx);
359 extends SqlArrayValueConstructor {
362 RelDataTypeFactory typeFactory, List<RelDataType> argTypes) {
363 if (argTypes.isEmpty()) {
364 return typeFactory.createSqlType(SqlTypeName.NULL);
366 return super.getComponentType(typeFactory, argTypes);
371 if (callBinding.operands().isEmpty()) {
374 return super.checkOperandTypes(callBinding, throwOnFailure);
384 SqlKind.OTHER_FUNCTION,
387 OperandTypes.NUMERIC,
388 SqlFunctionCategory.USER_DEFINED_FUNCTION);
393 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
394 return typeFactory.builder().add(
"I", SqlTypeName.INTEGER).build();
404 SqlKind.OTHER_FUNCTION,
407 OperandTypes.VARIADIC,
408 SqlFunctionCategory.USER_DEFINED_FUNCTION);
413 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
414 return typeFactory.builder().add(
"NAME", SqlTypeName.VARCHAR, 1024).build();
425 SqlKind.OTHER_FUNCTION,
428 OperandTypes.STRING_STRING,
429 SqlFunctionCategory.SYSTEM);
434 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
435 return typeFactory.createSqlType(SqlTypeName.BIGINT);
443 SqlKind.OTHER_FUNCTION,
447 SqlFunctionCategory.SYSTEM);
452 assert opBinding.getOperandCount() == 1;
453 RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
454 assert elem_type != null;
460 public static class Any extends SqlFunction {
463 SqlKind.OTHER_FUNCTION,
467 SqlFunctionCategory.SYSTEM);
472 assert opBinding.getOperandCount() == 1;
473 RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
474 assert elem_type != null;
480 public static class All extends SqlFunction {
483 SqlKind.OTHER_FUNCTION,
487 SqlFunctionCategory.SYSTEM);
492 assert opBinding.getOperandCount() == 1;
493 RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
494 assert elem_type != null;
500 public static class Now extends SqlFunction {
503 SqlKind.OTHER_FUNCTION,
506 OperandTypes.NILADIC,
507 SqlFunctionCategory.SYSTEM);
512 assert opBinding.getOperandCount() == 0;
513 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
514 return typeFactory.createSqlType(SqlTypeName.TIMESTAMP);
522 SqlKind.OTHER_FUNCTION,
526 SqlFunctionCategory.SYSTEM);
531 assert opBinding.getOperandCount() == 1;
532 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
533 return typeFactory.createSqlType(
534 SqlTypeName.TIMESTAMP, opBinding.getOperandType(0).getPrecision());
542 SqlKind.OTHER_FUNCTION,
545 OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
546 SqlFunctionCategory.SYSTEM);
551 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
552 return typeFactory.createTypeWithNullability(
553 typeFactory.createSqlType(SqlTypeName.BIGINT),
554 opBinding.getOperandType(1).isNullable());
561 SqlKind.OTHER_FUNCTION,
564 OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
565 SqlFunctionCategory.TIMEDATE);
570 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
571 return typeFactory.createTypeWithNullability(
572 typeFactory.createSqlType(SqlTypeName.BIGINT),
573 opBinding.getOperandType(1).isNullable());
577 public static class Dateadd extends SqlFunction {
580 SqlKind.OTHER_FUNCTION,
583 OperandTypes.family(SqlTypeFamily.STRING,
584 SqlTypeFamily.INTEGER,
585 SqlTypeFamily.DATETIME),
586 SqlFunctionCategory.TIMEDATE);
591 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
592 return typeFactory.createTypeWithNullability(
593 typeFactory.createSqlType(
594 SqlTypeName.TIMESTAMP, opBinding.getOperandType(2).getPrecision()),
595 opBinding.getOperandType(2).isNullable());
602 SqlKind.OTHER_FUNCTION,
605 OperandTypes.family(SqlTypeFamily.STRING,
606 SqlTypeFamily.DATETIME,
607 SqlTypeFamily.DATETIME),
608 SqlFunctionCategory.TIMEDATE);
613 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
614 return typeFactory.createTypeWithNullability(
615 typeFactory.createSqlType(SqlTypeName.BIGINT),
616 opBinding.getOperandType(1).isNullable()
617 || opBinding.getOperandType(2).isNullable());
624 super(
"PG_DATE_TRUNC",
625 SqlKind.OTHER_FUNCTION,
628 OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
629 SqlFunctionCategory.SYSTEM);
634 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
635 return typeFactory.createTypeWithNullability(
636 typeFactory.createSqlType(
637 SqlTypeName.TIMESTAMP, opBinding.getOperandType(1).getPrecision()),
638 opBinding.getOperandType(1).isNullable());
642 public static class Length extends SqlFunction {
645 SqlKind.OTHER_FUNCTION,
649 SqlFunctionCategory.SYSTEM);
654 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
655 return typeFactory.createSqlType(SqlTypeName.INTEGER);
662 SqlKind.OTHER_FUNCTION,
666 SqlFunctionCategory.SYSTEM);
671 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
672 return typeFactory.createSqlType(SqlTypeName.INTEGER);
678 super(
"KEY_FOR_STRING",
679 SqlKind.OTHER_FUNCTION,
683 SqlFunctionCategory.SYSTEM);
688 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
689 return typeFactory.createTypeWithNullability(
690 typeFactory.createSqlType(SqlTypeName.INTEGER),
691 opBinding.getOperandType(0).isNullable());
697 super(
"SAMPLE_RATIO",
698 SqlKind.OTHER_FUNCTION,
702 SqlFunctionCategory.SYSTEM);
707 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
708 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
711 private static java.util.List<SqlTypeFamily>
signature() {
712 java.util.ArrayList<SqlTypeFamily> families =
713 new java.util.ArrayList<SqlTypeFamily>();
714 families.add(SqlTypeFamily.NUMERIC);
721 super(
"WIDTH_BUCKET",
722 SqlKind.OTHER_FUNCTION,
726 SqlFunctionCategory.SYSTEM);
731 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
732 return typeFactory.createTypeWithNullability(
733 typeFactory.createSqlType(SqlTypeName.INTEGER),
true);
736 private static java.util.List<SqlTypeFamily>
signature() {
737 java.util.ArrayList<SqlTypeFamily> families =
738 new java.util.ArrayList<SqlTypeFamily>();
739 families.add(SqlTypeFamily.NUMERIC);
740 families.add(SqlTypeFamily.NUMERIC);
741 families.add(SqlTypeFamily.NUMERIC);
742 families.add(SqlTypeFamily.INTEGER);
750 SqlKind.OTHER_FUNCTION,
754 SqlFunctionCategory.SYSTEM);
759 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
760 return typeFactory.createTypeWithNullability(
761 typeFactory.createSqlType(SqlTypeName.DOUBLE),
true);
766 return SqlOperandCountRanges.from(2);
775 final SqlValidator validator = callBinding.getValidator();
777 final int num_operands = callBinding.getOperandCount();
778 if (num_operands < 2) {
779 throw new IllegalArgumentException(
780 "At least 2 arguments are required, the model name and one or more predictors.");
782 for (
int operand_idx = 0; operand_idx < num_operands; operand_idx++) {
783 final SqlNode operand = callBinding.operand(operand_idx);
784 final SqlTypeName operand_type =
785 validator.getValidatedNodeType(operand).getSqlTypeName();
786 final SqlTypeFamily operand_type_family = operand_type.getFamily();
787 if (operand_idx == 0) {
788 if (!operand.isA(EnumSet.of(SqlKind.LITERAL))
789 || operand_type_family != SqlTypeFamily.CHARACTER) {
790 throw new IllegalArgumentException(
791 "First argument must be TEXT literal denoting the model name.");
794 if (operand.isA(EnumSet.of(SqlKind.LITERAL))) {
795 throw new IllegalArgumentException(
796 "Literals are not supported as predictors.");
798 if (!(operand_type_family == SqlTypeFamily.NUMERIC
799 || operand_type_family == SqlTypeFamily.CHARACTER)) {
800 throw new IllegalArgumentException(
801 "Only TEXT and NUMERIC predictors are supported.");
812 SqlKind.OTHER_FUNCTION,
816 SqlFunctionCategory.SYSTEM);
821 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
822 return typeFactory.createTypeWithNullability(
823 typeFactory.createSqlType(SqlTypeName.DOUBLE),
true);
828 return SqlOperandCountRanges.from(3);
838 final SqlValidator validator = callBinding.getValidator();
840 final int num_operands = callBinding.getOperandCount();
841 if (num_operands < 3) {
842 throw new IllegalArgumentException(
843 "At least 3 arguments are required, the model name, one or more features, and the nth principal component to project to.");
845 for (
int operand_idx = 0; operand_idx < num_operands; operand_idx++) {
846 final SqlNode operand = callBinding.operand(operand_idx);
847 final SqlTypeName operand_type =
848 validator.getValidatedNodeType(operand).getSqlTypeName();
849 final SqlTypeFamily operand_type_family = operand_type.getFamily();
850 if (operand_idx == 0) {
851 if (!operand.isA(EnumSet.of(SqlKind.LITERAL))
852 || operand_type_family != SqlTypeFamily.CHARACTER) {
853 throw new IllegalArgumentException(
854 "First argument must be TEXT literal denoting the model name.");
856 }
else if (operand_idx < num_operands - 1) {
857 if (operand.isA(EnumSet.of(SqlKind.LITERAL))) {
858 throw new IllegalArgumentException(
"Literals are not supported as features.");
860 if (!(operand_type_family == SqlTypeFamily.NUMERIC
861 || operand_type_family == SqlTypeFamily.CHARACTER)) {
862 throw new IllegalArgumentException(
863 "Only TEXT and NUMERIC features are supported.");
865 }
else if (!operand.isA(EnumSet.of(SqlKind.LITERAL))
866 || !(operand_type_family == SqlTypeFamily.NUMERIC)
867 || !(operand_type.equals(SqlTypeName.INTEGER))) {
868 throw new IllegalArgumentException(
869 "Last argument to PCA_PROJECT expects integer literal dimension index.");
878 super(
"LEAD_IN_FRAME", SqlKind.LEAD);
884 super(
"LAG_IN_FRAME", SqlKind.LAG);
890 super(
"NTH_VALUE_IN_FRAME");
896 super(
"FIRST_VALUE_IN_FRAME", SqlKind.FIRST_VALUE);
902 super(
"LAST_VALUE_IN_FRAME", SqlKind.LAST_VALUE);
908 super(
"ARRAY_LENGTH",
909 SqlKind.OTHER_FUNCTION,
913 SqlFunctionCategory.SYSTEM);
918 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
919 return typeFactory.createSqlType(SqlTypeName.INTEGER);
924 SqlValidator validator,
925 SqlValidatorScope scope,
926 SqlValidatorScope operandScope) {
927 for (
int i = 0; i < call.operandCount(); ++i) {
928 SqlNode operand = call.operand(i);
929 if (operand instanceof SqlCall) {
930 SqlCall operand_call = (SqlCall) operand;
931 SqlOperator call_oper = operand_call.getOperator();
932 if (call_oper instanceof SqlFunction) {
933 SqlFunction call_func = (SqlFunction) call_oper;
934 if (call_func.getFunctionType()
935 == SqlFunctionCategory.USER_DEFINED_FUNCTION) {
940 throw validator.newValidationError(
941 call, _ERRORS.illegalArrayLengthCall(call.toString()));
946 super.validateCall(call, validator, scope, operandScope);
950 @BaseMessage(
"Illegal argument to 'ARRAY_LENGTH': ''{0}''")
955 Resources.create(ArrayLengthErrors.class);
958 public static class PgILike extends SqlFunction {
961 SqlKind.OTHER_FUNCTION,
965 SqlFunctionCategory.SYSTEM);
969 java.util.ArrayList<SqlTypeFamily> families =
970 new java.util.ArrayList<SqlTypeFamily>();
978 implements java.util.function.Predicate<Integer>, Predicate<Integer> {
980 public boolean test(Integer t) {
992 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
993 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1000 SqlKind.OTHER_FUNCTION,
1004 SqlFunctionCategory.SYSTEM);
1008 java.util.ArrayList<SqlTypeFamily> families =
1009 new java.util.ArrayList<SqlTypeFamily>();
1017 implements java.util.function.Predicate<Integer>, Predicate<Integer> {
1030 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1031 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1039 ReturnTypes.ARG0.andThen(SqlTypeTransforms.TO_NULLABLE)
1040 .andThen(SqlTypeTransforms.TO_VARYING),
1043 OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.STRING),
1044 new SameOperandTypeChecker(2) {
1046 protected List<Integer> getOperandList(
int operandCount) {
1047 return ImmutableList.of(0, 1);
1050 SqlFunctionCategory.STRING);
1054 public SqlCall
createCall(@Nullable SqlLiteral functionQualifier,
1056 @Nullable SqlNode... operands) {
1057 assert functionQualifier == null;
1058 switch (operands.length) {
1060 operands =
new SqlNode[] {operands[0], SqlLiteral.createCharString(
" ", pos)};
1063 if (operands[1] == null) {
1064 operands[1] = SqlLiteral.createCharString(
" ", pos);
1066 operands =
new SqlNode[] {operands[0], operands[1]};
1069 throw new IllegalArgumentException(
1070 "Invalid operand count " + Arrays.toString(operands));
1072 return super.createCall(functionQualifier, pos, operands);
1078 return (operands.size() == 1);
1084 super(
"LTRIM", SqlKind.LTRIM);
1089 super(
"RTRIM", SqlKind.RTRIM);
1095 SqlKind.OTHER_FUNCTION,
1096 ReturnTypes.ARG0.andThen(SqlTypeTransforms.TO_NULLABLE)
1097 .andThen(SqlTypeTransforms.TO_VARYING),
1099 OperandTypes.and(OperandTypes.family(SqlTypeFamily.STRING,
1100 SqlTypeFamily.INTEGER,
1101 SqlTypeFamily.STRING),
1102 new SameOperandTypeChecker(3) {
1104 protected List<Integer> getOperandList(
int operandCount) {
1105 return ImmutableList.of(0, 2);
1108 SqlFunctionCategory.STRING);
1112 public SqlCall
createCall(@Nullable SqlLiteral functionQualifier,
1114 @Nullable SqlNode... operands) {
1115 assert functionQualifier == null;
1116 switch (operands.length) {
1118 operands =
new SqlNode[] {
1119 operands[0], operands[1], SqlLiteral.createCharString(
" ", pos)};
1122 if (operands[2] == null) {
1123 operands[2] = SqlLiteral.createCharString(
" ", pos);
1125 operands =
new SqlNode[] {operands[0], operands[1], operands[2]};
1128 throw new IllegalArgumentException(
1129 "Invalid operand count " + Arrays.toString(operands));
1131 return super.createCall(functionQualifier, pos, operands);
1136 if (!super.checkOperandTypes(callBinding, throwOnFailure)) {
1141 return SqlTypeUtil.isCharTypeComparable(callBinding,
1142 ImmutableList.of(callBinding.operand(0), callBinding.operand(2)),
1152 return (operands.size() == 2);
1170 SqlKind.OTHER_FUNCTION,
1173 OperandTypes.family(getSignatureFamilies()),
1178 java.util.ArrayList<SqlTypeFamily> families =
1179 new java.util.ArrayList<SqlTypeFamily>();
1182 families.add(SqlTypeFamily.INTEGER);
1188 return opBinding.getOperandType(0);
1195 SqlKind.OTHER_FUNCTION,
1198 OperandTypes.family(getSignatureFamilies()),
1203 java.util.ArrayList<SqlTypeFamily> families =
1204 new java.util.ArrayList<SqlTypeFamily>();
1213 return opBinding.getOperandType(0);
1217 public SqlCall
createCall(@Nullable SqlLiteral functionQualifier,
1219 @Nullable SqlNode... operands) {
1220 assert functionQualifier == null;
1221 switch (operands.length) {
1223 operands =
new SqlNode[] {
1224 operands[0], operands[1], SqlLiteral.createCharString(
"", pos)};
1229 throw new IllegalArgumentException(
1230 "Invalid operand count " + Arrays.toString(operands));
1232 return super.createCall(functionQualifier, pos, operands);
1238 return (operands.size() == 2);
1244 SqlKind.OTHER_FUNCTION,
1247 OperandTypes.family(getSignatureFamilies()),
1252 java.util.ArrayList<SqlTypeFamily> families =
1253 new java.util.ArrayList<SqlTypeFamily>();
1260 return opBinding.getOperandType(0);
1263 public static class Repeat extends SqlFunction {
1266 SqlKind.OTHER_FUNCTION,
1269 OperandTypes.family(getSignatureFamilies()),
1274 java.util.ArrayList<SqlTypeFamily> families =
1275 new java.util.ArrayList<SqlTypeFamily>();
1277 families.add(SqlTypeFamily.INTEGER);
1283 return opBinding.getOperandType(0);
1289 super(
"REGEXP_REPLACE",
1290 SqlKind.OTHER_FUNCTION,
1293 OperandTypes.family(getSignatureFamilies()),
1298 java.util.ArrayList<SqlTypeFamily> families =
1299 new java.util.ArrayList<SqlTypeFamily>();
1303 families.add(SqlTypeFamily.INTEGER);
1304 families.add(SqlTypeFamily.INTEGER);
1310 public SqlCall
createCall(@Nullable SqlLiteral functionQualifier,
1312 @Nullable SqlNode... operands) {
1313 assert functionQualifier == null;
1314 final int num_operands = operands.length;
1315 if (num_operands < 2 || num_operands > 6) {
1316 throw new IllegalArgumentException(
1317 "Invalid operand count " + Arrays.toString(operands));
1319 SqlNode[] new_operands =
new SqlNode[6];
1321 new_operands[0] = operands[0];
1323 new_operands[1] = operands[1];
1325 if (num_operands < 3 || operands[2] == null) {
1326 new_operands[2] = SqlLiteral.createCharString(
"", pos);
1328 new_operands[2] = operands[2];
1331 if (num_operands < 4 || operands[3] == null) {
1332 new_operands[3] = SqlLiteral.createExactNumeric(
"1", pos);
1334 new_operands[3] = operands[3];
1337 if (num_operands < 5 || operands[4] == null) {
1338 new_operands[4] = SqlLiteral.createExactNumeric(
"0", pos);
1340 new_operands[4] = operands[4];
1343 if (num_operands < 6 || operands[5] == null) {
1344 new_operands[5] = SqlLiteral.createCharString(
"c", pos);
1346 new_operands[5] = operands[5];
1348 return super.createCall(functionQualifier, pos, new_operands);
1353 return opBinding.getOperandType(0);
1359 super(
"REGEXP_SUBSTR",
1360 SqlKind.OTHER_FUNCTION,
1363 OperandTypes.family(getSignatureFamilies()),
1369 SqlKind.OTHER_FUNCTION,
1372 OperandTypes.family(getSignatureFamilies()),
1373 SqlFunctionCategory.SYSTEM);
1377 java.util.ArrayList<SqlTypeFamily> families =
1378 new java.util.ArrayList<SqlTypeFamily>();
1381 families.add(SqlTypeFamily.INTEGER);
1382 families.add(SqlTypeFamily.INTEGER);
1384 families.add(SqlTypeFamily.INTEGER);
1389 public SqlCall
createCall(@Nullable SqlLiteral functionQualifier,
1391 @Nullable SqlNode... operands) {
1392 assert functionQualifier == null;
1393 final int num_operands = operands.length;
1394 if (num_operands < 2 || num_operands > 6) {
1395 throw new IllegalArgumentException(
1396 "Invalid operand count " + Arrays.toString(operands));
1398 SqlNode[] new_operands =
new SqlNode[6];
1401 new_operands[0] = operands[0];
1403 new_operands[1] = operands[1];
1405 if (num_operands < 3 || operands[2] == null) {
1406 new_operands[2] = SqlLiteral.createExactNumeric(
"1", pos);
1408 new_operands[2] = operands[2];
1411 if (num_operands < 4 || operands[3] == null) {
1412 new_operands[3] = SqlLiteral.createExactNumeric(
"1", pos);
1414 new_operands[3] = operands[3];
1417 if (num_operands < 5 || operands[4] == null) {
1418 new_operands[4] = SqlLiteral.createCharString(
"c", pos);
1420 new_operands[4] = operands[4];
1423 if (num_operands < 6 || operands[5] == null) {
1424 new_operands[5] = SqlLiteral.createExactNumeric(
"1", pos);
1426 new_operands[5] = operands[5];
1428 return super.createCall(functionQualifier, pos, new_operands);
1433 return opBinding.getOperandType(0);
1439 super(
"REGEXP_MATCH");
1444 super(
"BASE64_ENCODE",
1445 SqlKind.OTHER_FUNCTION,
1448 OperandTypes.family(getSignatureFamilies()),
1453 java.util.ArrayList<SqlTypeFamily> families =
1454 new java.util.ArrayList<SqlTypeFamily>();
1461 return opBinding.getOperandType(0);
1467 super(
"BASE64_DECODE",
1468 SqlKind.OTHER_FUNCTION,
1471 OperandTypes.family(getSignatureFamilies()),
1476 java.util.ArrayList<SqlTypeFamily> families =
1477 new java.util.ArrayList<SqlTypeFamily>();
1484 return opBinding.getOperandType(0);
1493 SqlKind.OTHER_FUNCTION,
1495 InferTypes.FIRST_KNOWN,
1497 SqlFunctionCategory.SYSTEM);
1503 assert opBinding.getOperandCount() == 2;
1504 RelDataType ret = opBinding.getOperandType(1);
1505 RelDataType firstType = opBinding.getOperandType(0);
1506 ret = opBinding.getTypeFactory().createTypeWithNullability(
1507 ret, firstType.isNullable());
1508 if (opBinding instanceof SqlCallBinding) {
1509 SqlCallBinding callBinding = (SqlCallBinding) opBinding;
1510 SqlNode operand0 = callBinding.operand(0);
1514 if (((operand0 instanceof SqlLiteral)
1515 && (((SqlLiteral) operand0).getValue() == null))
1516 || (operand0 instanceof SqlDynamicParam)) {
1519 validator.setValidatedNodeType(operand0, ret);
1526 assert operandsCount == 2;
1527 return "{0}({1} AS {2})";
1531 return SqlOperandCountRanges.of(2);
1540 final SqlNode left = callBinding.operand(0);
1541 final SqlNode right = callBinding.operand(1);
1542 if (SqlUtil.isNullLiteral(left,
false) || left instanceof SqlDynamicParam) {
1545 RelDataType validatedNodeType =
1546 callBinding.getValidator().getValidatedNodeType(left);
1547 RelDataType returnType =
1548 callBinding.getValidator().deriveType(callBinding.getScope(), right);
1549 if (!SqlTypeUtil.canCastFrom(returnType, validatedNodeType,
true)) {
1550 if (throwOnFailure) {
1551 throw callBinding.newError(RESOURCE.cannotCastValue(
1552 validatedNodeType.toString(), returnType.toString()));
1556 if (SqlTypeUtil.areCharacterSetsMismatched(validatedNodeType, returnType)) {
1557 if (throwOnFailure) {
1560 throw callBinding.newError(RESOURCE.cannotCastValue(
1561 validatedNodeType.getFullTypeString(), returnType.getFullTypeString()));
1569 return SqlSyntax.FUNCTION;
1572 public void unparse(SqlWriter writer, SqlCall call,
int leftPrec,
int rightPrec) {
1573 assert call.operandCount() == 2;
1574 final SqlWriter.Frame frame = writer.startFunCall(getName());
1575 call.operand(0).unparse(writer, 0, 0);
1577 if (call.operand(1) instanceof SqlIntervalQualifier) {
1578 writer.sep(
"INTERVAL");
1580 call.operand(1).unparse(writer, 0, 0);
1581 writer.endFunCall(frame);
1585 public static class Likely extends SqlFunction {
1588 SqlKind.OTHER_FUNCTION,
1591 OperandTypes.BOOLEAN,
1592 SqlFunctionCategory.SYSTEM);
1597 return opBinding.getOperandType(0);
1604 SqlKind.OTHER_FUNCTION,
1607 OperandTypes.BOOLEAN,
1608 SqlFunctionCategory.SYSTEM);
1613 return opBinding.getOperandType(0);
1617 public static class Sign extends SqlFunction {
1620 SqlKind.OTHER_FUNCTION,
1623 OperandTypes.NUMERIC,
1624 SqlFunctionCategory.NUMERIC);
1629 return opBinding.getOperandType(0);
1636 SqlKind.OTHER_FUNCTION,
1639 OperandTypes.family(signature()),
1640 SqlFunctionCategory.NUMERIC);
1645 assert opBinding.getOperandCount() == 2;
1646 return opBinding.getOperandType(0);
1650 java.util.List<SqlTypeFamily> truncate_sig =
1651 new java.util.ArrayList<SqlTypeFamily>();
1652 truncate_sig.add(SqlTypeFamily.NUMERIC);
1653 truncate_sig.add(SqlTypeFamily.INTEGER);
1654 return truncate_sig;
1661 SqlKind.OTHER_FUNCTION,
1664 OperandTypes.family(signature()),
1665 SqlFunctionCategory.SYSTEM);
1670 assert opBinding.getOperandCount() == 1;
1671 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1672 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1676 java.util.List<SqlTypeFamily> st_isempty_sig =
1677 new java.util.ArrayList<SqlTypeFamily>();
1678 st_isempty_sig.add(SqlTypeFamily.ANY);
1679 return st_isempty_sig;
1686 SqlKind.OTHER_FUNCTION,
1689 OperandTypes.family(signature()),
1690 SqlFunctionCategory.SYSTEM);
1695 assert opBinding.getOperandCount() == 1;
1696 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1697 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1701 java.util.List<SqlTypeFamily> st_isvalid_sig =
1702 new java.util.ArrayList<SqlTypeFamily>();
1703 st_isvalid_sig.add(SqlTypeFamily.ANY);
1704 return st_isvalid_sig;
1710 super(
"ST_Contains",
1711 SqlKind.OTHER_FUNCTION,
1714 OperandTypes.family(signature()),
1715 SqlFunctionCategory.SYSTEM);
1720 assert opBinding.getOperandCount() == 2;
1721 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1722 return typeFactory.createTypeWithNullability(
1723 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1724 opBinding.getOperandType(0).isNullable()
1725 || opBinding.getOperandType(1).isNullable());
1729 java.util.List<SqlTypeFamily> st_contains_sig =
1730 new java.util.ArrayList<SqlTypeFamily>();
1731 st_contains_sig.add(SqlTypeFamily.ANY);
1732 st_contains_sig.add(SqlTypeFamily.ANY);
1733 return st_contains_sig;
1740 SqlKind.OTHER_FUNCTION,
1743 OperandTypes.family(signature()),
1744 SqlFunctionCategory.SYSTEM);
1749 assert opBinding.getOperandCount() == 2;
1750 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1751 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1755 java.util.List<SqlTypeFamily> st_equals_sig =
1756 new java.util.ArrayList<SqlTypeFamily>();
1757 st_equals_sig.add(SqlTypeFamily.ANY);
1758 st_equals_sig.add(SqlTypeFamily.ANY);
1759 return st_equals_sig;
1765 super(
"ST_Intersects",
1766 SqlKind.OTHER_FUNCTION,
1769 OperandTypes.family(signature()),
1770 SqlFunctionCategory.SYSTEM);
1775 assert opBinding.getOperandCount() == 2;
1776 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1777 return typeFactory.createTypeWithNullability(
1778 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1779 opBinding.getOperandType(0).isNullable()
1780 || opBinding.getOperandType(1).isNullable());
1784 java.util.List<SqlTypeFamily> st_intersects_sig =
1785 new java.util.ArrayList<SqlTypeFamily>();
1786 st_intersects_sig.add(SqlTypeFamily.ANY);
1787 st_intersects_sig.add(SqlTypeFamily.ANY);
1788 return st_intersects_sig;
1794 super(
"ST_IntersectsBox",
1795 SqlKind.OTHER_FUNCTION,
1798 OperandTypes.family(signature()),
1799 SqlFunctionCategory.SYSTEM);
1804 assert opBinding.getOperandCount() == 2;
1805 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1806 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1810 java.util.List<SqlTypeFamily> st_intersect_box_sig =
1811 new java.util.ArrayList<SqlTypeFamily>();
1812 st_intersect_box_sig.add(SqlTypeFamily.ANY);
1813 st_intersect_box_sig.add(SqlTypeFamily.ANY);
1814 return st_intersect_box_sig;
1820 super(
"ST_Approx_Overlaps",
1821 SqlKind.OTHER_FUNCTION,
1824 OperandTypes.family(signature()),
1825 SqlFunctionCategory.SYSTEM);
1830 assert opBinding.getOperandCount() == 2;
1831 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1832 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1836 java.util.List<SqlTypeFamily> st_intersect_box_sig =
1837 new java.util.ArrayList<SqlTypeFamily>();
1838 st_intersect_box_sig.add(SqlTypeFamily.ANY);
1839 st_intersect_box_sig.add(SqlTypeFamily.ANY);
1840 return st_intersect_box_sig;
1846 super(
"ST_Disjoint",
1847 SqlKind.OTHER_FUNCTION,
1850 OperandTypes.family(signature()),
1851 SqlFunctionCategory.SYSTEM);
1856 assert opBinding.getOperandCount() == 2;
1857 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1858 return typeFactory.createTypeWithNullability(
1859 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1860 opBinding.getOperandType(0).isNullable()
1861 || opBinding.getOperandType(1).isNullable());
1865 java.util.List<SqlTypeFamily> st_disjoint_sig =
1866 new java.util.ArrayList<SqlTypeFamily>();
1867 st_disjoint_sig.add(SqlTypeFamily.ANY);
1868 st_disjoint_sig.add(SqlTypeFamily.ANY);
1869 return st_disjoint_sig;
1876 SqlKind.OTHER_FUNCTION,
1879 OperandTypes.family(signature()),
1880 SqlFunctionCategory.SYSTEM);
1885 assert opBinding.getOperandCount() == 2;
1886 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1887 return typeFactory.createTypeWithNullability(
1888 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1889 opBinding.getOperandType(0).isNullable()
1890 || opBinding.getOperandType(1).isNullable());
1894 java.util.List<SqlTypeFamily> st_within_sig =
1895 new java.util.ArrayList<SqlTypeFamily>();
1896 st_within_sig.add(SqlTypeFamily.ANY);
1897 st_within_sig.add(SqlTypeFamily.ANY);
1898 return st_within_sig;
1905 SqlKind.OTHER_FUNCTION,
1908 OperandTypes.family(signature()),
1909 SqlFunctionCategory.SYSTEM);
1914 assert opBinding.getOperandCount() == 3;
1915 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1916 return typeFactory.createTypeWithNullability(
1917 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1918 opBinding.getOperandType(0).isNullable()
1919 || opBinding.getOperandType(1).isNullable()
1920 || opBinding.getOperandType(2).isNullable());
1924 java.util.List<SqlTypeFamily> st_dwithin_sig =
1925 new java.util.ArrayList<SqlTypeFamily>();
1926 st_dwithin_sig.add(SqlTypeFamily.ANY);
1927 st_dwithin_sig.add(SqlTypeFamily.ANY);
1928 st_dwithin_sig.add(SqlTypeFamily.NUMERIC);
1929 return st_dwithin_sig;
1935 super(
"ST_DFullyWithin",
1936 SqlKind.OTHER_FUNCTION,
1939 OperandTypes.family(signature()),
1940 SqlFunctionCategory.SYSTEM);
1945 assert opBinding.getOperandCount() == 3;
1946 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1947 return typeFactory.createTypeWithNullability(
1948 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1949 opBinding.getOperandType(0).isNullable()
1950 || opBinding.getOperandType(1).isNullable()
1951 || opBinding.getOperandType(2).isNullable());
1955 java.util.List<SqlTypeFamily> st_dwithin_sig =
1956 new java.util.ArrayList<SqlTypeFamily>();
1957 st_dwithin_sig.add(SqlTypeFamily.ANY);
1958 st_dwithin_sig.add(SqlTypeFamily.ANY);
1959 st_dwithin_sig.add(SqlTypeFamily.NUMERIC);
1960 return st_dwithin_sig;
1966 super(
"ST_Distance",
1967 SqlKind.OTHER_FUNCTION,
1970 OperandTypes.family(signature()),
1971 SqlFunctionCategory.SYSTEM);
1976 assert opBinding.getOperandCount() == 2;
1977 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1978 return typeFactory.createTypeWithNullability(
1979 typeFactory.createSqlType(SqlTypeName.DOUBLE),
1980 opBinding.getOperandType(0).isNullable()
1981 || opBinding.getOperandType(1).isNullable());
1985 java.util.List<SqlTypeFamily> st_distance_sig =
1986 new java.util.ArrayList<SqlTypeFamily>();
1987 st_distance_sig.add(SqlTypeFamily.ANY);
1988 st_distance_sig.add(SqlTypeFamily.ANY);
1989 return st_distance_sig;
1995 super(
"ST_MaxDistance",
1996 SqlKind.OTHER_FUNCTION,
1999 OperandTypes.family(signature()),
2000 SqlFunctionCategory.SYSTEM);
2005 assert opBinding.getOperandCount() == 2;
2006 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2007 return typeFactory.createTypeWithNullability(
2008 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2009 opBinding.getOperandType(0).isNullable()
2010 || opBinding.getOperandType(1).isNullable());
2014 java.util.List<SqlTypeFamily> st_maxdistance_sig =
2015 new java.util.ArrayList<SqlTypeFamily>();
2016 st_maxdistance_sig.add(SqlTypeFamily.ANY);
2017 st_maxdistance_sig.add(SqlTypeFamily.ANY);
2018 return st_maxdistance_sig;
2024 super(
"ST_GeogFromText",
2025 SqlKind.OTHER_FUNCTION,
2028 OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
2029 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
2030 SqlFunctionCategory.SYSTEM);
2035 assert opBinding.getOperandCount() == 1;
2036 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2037 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2043 super(
"ST_GeomFromText",
2044 SqlKind.OTHER_FUNCTION,
2047 OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
2048 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
2049 SqlFunctionCategory.SYSTEM);
2054 assert opBinding.getOperandCount() == 1;
2055 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2056 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2062 super(
"ST_Transform",
2063 SqlKind.OTHER_FUNCTION,
2066 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
2067 SqlFunctionCategory.SYSTEM);
2072 assert opBinding.getOperandCount() == 1;
2073 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2074 return typeFactory.createTypeWithNullability(
2075 typeFactory.createSqlType(SqlTypeName.INTEGER),
2076 opBinding.getOperandType(0).isNullable());
2080 static class ST_X extends SqlFunction {
2083 SqlKind.OTHER_FUNCTION,
2086 OperandTypes.family(SqlTypeFamily.ANY),
2087 SqlFunctionCategory.SYSTEM);
2092 assert opBinding.getOperandCount() == 1;
2093 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2094 return typeFactory.createTypeWithNullability(
2095 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2096 opBinding.getOperandType(0).isNullable());
2100 static class ST_Y extends SqlFunction {
2103 SqlKind.OTHER_FUNCTION,
2106 OperandTypes.family(SqlTypeFamily.ANY),
2107 SqlFunctionCategory.SYSTEM);
2112 assert opBinding.getOperandCount() == 1;
2113 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2114 return typeFactory.createTypeWithNullability(
2115 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2116 opBinding.getOperandType(0).isNullable());
2123 SqlKind.OTHER_FUNCTION,
2126 OperandTypes.family(SqlTypeFamily.ANY),
2127 SqlFunctionCategory.SYSTEM);
2132 assert opBinding.getOperandCount() == 1;
2133 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2134 return typeFactory.createTypeWithNullability(
2135 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2136 opBinding.getOperandType(0).isNullable());
2143 SqlKind.OTHER_FUNCTION,
2146 OperandTypes.family(SqlTypeFamily.ANY),
2147 SqlFunctionCategory.SYSTEM);
2152 assert opBinding.getOperandCount() == 1;
2153 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2154 return typeFactory.createTypeWithNullability(
2155 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2156 opBinding.getOperandType(0).isNullable());
2163 SqlKind.OTHER_FUNCTION,
2166 OperandTypes.family(SqlTypeFamily.ANY),
2167 SqlFunctionCategory.SYSTEM);
2172 assert opBinding.getOperandCount() == 1;
2173 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2174 return typeFactory.createTypeWithNullability(
2175 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2176 opBinding.getOperandType(0).isNullable());
2183 SqlKind.OTHER_FUNCTION,
2186 OperandTypes.family(SqlTypeFamily.ANY),
2187 SqlFunctionCategory.SYSTEM);
2192 assert opBinding.getOperandCount() == 1;
2193 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2194 return typeFactory.createTypeWithNullability(
2195 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2196 opBinding.getOperandType(0).isNullable());
2203 SqlKind.OTHER_FUNCTION,
2206 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
2207 SqlFunctionCategory.SYSTEM);
2212 assert opBinding.getOperandCount() == 1;
2213 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2214 return typeFactory.createTypeWithNullability(
2215 typeFactory.createSqlType(SqlTypeName.INTEGER),
2216 opBinding.getOperandType(0).isNullable());
2222 super(
"ST_EndPoint",
2223 SqlKind.OTHER_FUNCTION,
2226 OperandTypes.family(SqlTypeFamily.ANY),
2227 SqlFunctionCategory.SYSTEM);
2232 assert opBinding.getOperandCount() == 1;
2233 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2234 return typeFactory.createTypeWithNullability(
2235 typeFactory.createSqlType(SqlTypeName.INTEGER),
2236 opBinding.getOperandType(0).isNullable());
2242 super(
"ST_StartPoint",
2243 SqlKind.OTHER_FUNCTION,
2246 OperandTypes.family(SqlTypeFamily.ANY),
2247 SqlFunctionCategory.SYSTEM);
2252 assert opBinding.getOperandCount() == 1;
2253 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2254 return typeFactory.createTypeWithNullability(
2255 typeFactory.createSqlType(SqlTypeName.INTEGER),
2256 opBinding.getOperandType(0).isNullable());
2263 SqlKind.OTHER_FUNCTION,
2266 OperandTypes.family(SqlTypeFamily.ANY),
2267 SqlFunctionCategory.SYSTEM);
2272 assert opBinding.getOperandCount() == 1;
2273 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2274 return typeFactory.createTypeWithNullability(
2275 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2276 opBinding.getOperandType(0).isNullable());
2282 super(
"ST_Perimeter",
2283 SqlKind.OTHER_FUNCTION,
2286 OperandTypes.family(SqlTypeFamily.ANY),
2287 SqlFunctionCategory.SYSTEM);
2292 assert opBinding.getOperandCount() == 1;
2293 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2294 return typeFactory.createTypeWithNullability(
2295 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2296 opBinding.getOperandType(0).isNullable());
2303 SqlKind.OTHER_FUNCTION,
2306 OperandTypes.family(SqlTypeFamily.ANY),
2307 SqlFunctionCategory.SYSTEM);
2312 assert opBinding.getOperandCount() == 1;
2313 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2314 return typeFactory.createTypeWithNullability(
2315 typeFactory.createSqlType(SqlTypeName.DOUBLE),
2316 opBinding.getOperandType(0).isNullable());
2323 SqlKind.OTHER_FUNCTION,
2326 OperandTypes.family(SqlTypeFamily.ANY),
2327 SqlFunctionCategory.SYSTEM);
2332 assert opBinding.getOperandCount() == 1;
2333 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2334 return typeFactory.createTypeWithNullability(
2335 typeFactory.createSqlType(SqlTypeName.INTEGER),
2336 opBinding.getOperandType(0).isNullable());
2343 SqlKind.OTHER_FUNCTION,
2346 OperandTypes.family(SqlTypeFamily.ANY),
2347 SqlFunctionCategory.SYSTEM);
2352 assert opBinding.getOperandCount() == 1;
2353 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2354 return typeFactory.createTypeWithNullability(
2355 typeFactory.createSqlType(SqlTypeName.INTEGER),
2356 opBinding.getOperandType(0).isNullable());
2362 super(
"ST_NumGeometries",
2363 SqlKind.OTHER_FUNCTION,
2366 OperandTypes.family(SqlTypeFamily.ANY),
2367 SqlFunctionCategory.SYSTEM);
2372 assert opBinding.getOperandCount() == 1;
2373 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2374 return typeFactory.createTypeWithNullability(
2375 typeFactory.createSqlType(SqlTypeName.INTEGER),
2376 opBinding.getOperandType(0).isNullable());
2383 SqlKind.OTHER_FUNCTION,
2386 OperandTypes.family(SqlTypeFamily.ANY),
2387 SqlFunctionCategory.SYSTEM);
2392 assert opBinding.getOperandCount() == 1;
2393 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2394 return typeFactory.createTypeWithNullability(
2395 typeFactory.createSqlType(SqlTypeName.INTEGER),
2396 opBinding.getOperandType(0).isNullable());
2403 SqlKind.OTHER_FUNCTION,
2406 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
2407 SqlFunctionCategory.SYSTEM);
2412 assert opBinding.getOperandCount() == 1;
2413 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2414 return typeFactory.createTypeWithNullability(
2415 typeFactory.createSqlType(SqlTypeName.INTEGER),
2416 opBinding.getOperandType(0).isNullable());
2423 SqlKind.OTHER_FUNCTION,
2426 OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
2427 SqlFunctionCategory.SYSTEM);
2432 assert opBinding.getOperandCount() == 2;
2433 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2434 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2440 super(
"ST_Centroid",
2441 SqlKind.OTHER_FUNCTION,
2444 OperandTypes.family(signature()),
2445 SqlFunctionCategory.SYSTEM);
2450 assert opBinding.getOperandCount() == 1;
2451 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2452 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2456 java.util.List<SqlTypeFamily> st_centroid_sig =
2457 new java.util.ArrayList<SqlTypeFamily>();
2458 st_centroid_sig.add(SqlTypeFamily.ANY);
2459 return st_centroid_sig;
2466 SqlKind.OTHER_FUNCTION,
2469 OperandTypes.family(signature()),
2470 SqlFunctionCategory.SYSTEM);
2475 assert opBinding.getOperandCount() == 2;
2476 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2477 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2481 java.util.List<SqlTypeFamily> st_buffer_sig =
2482 new java.util.ArrayList<SqlTypeFamily>();
2483 st_buffer_sig.add(SqlTypeFamily.ANY);
2484 st_buffer_sig.add(SqlTypeFamily.NUMERIC);
2485 return st_buffer_sig;
2491 super(
"ST_ConcaveHull",
2492 SqlKind.OTHER_FUNCTION,
2495 OperandTypes.family(signature()),
2496 SqlFunctionCategory.SYSTEM);
2501 assert opBinding.getOperandCount() == 2;
2502 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2503 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2507 java.util.List<SqlTypeFamily> st_concavehull_sig =
2508 new java.util.ArrayList<SqlTypeFamily>();
2509 st_concavehull_sig.add(SqlTypeFamily.ANY);
2510 st_concavehull_sig.add(SqlTypeFamily.NUMERIC);
2511 return st_concavehull_sig;
2517 super(
"ST_ConvexHull",
2518 SqlKind.OTHER_FUNCTION,
2521 OperandTypes.family(signature()),
2522 SqlFunctionCategory.SYSTEM);
2527 assert opBinding.getOperandCount() == 1;
2528 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2529 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2533 java.util.List<SqlTypeFamily> st_convexhull_sig =
2534 new java.util.ArrayList<SqlTypeFamily>();
2535 st_convexhull_sig.add(SqlTypeFamily.ANY);
2536 return st_convexhull_sig;
2542 super(
"ST_Intersection",
2543 SqlKind.OTHER_FUNCTION,
2546 OperandTypes.family(signature()),
2547 SqlFunctionCategory.SYSTEM);
2552 assert opBinding.getOperandCount() == 2;
2553 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2554 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2558 java.util.List<SqlTypeFamily> st_intersection_sig =
2559 new java.util.ArrayList<SqlTypeFamily>();
2560 st_intersection_sig.add(SqlTypeFamily.ANY);
2561 st_intersection_sig.add(SqlTypeFamily.ANY);
2562 return st_intersection_sig;
2569 SqlKind.OTHER_FUNCTION,
2572 OperandTypes.family(signature()),
2573 SqlFunctionCategory.SYSTEM);
2578 assert opBinding.getOperandCount() == 2;
2579 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2580 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2584 java.util.List<SqlTypeFamily> st_union_sig =
2585 new java.util.ArrayList<SqlTypeFamily>();
2586 st_union_sig.add(SqlTypeFamily.ANY);
2587 st_union_sig.add(SqlTypeFamily.ANY);
2588 return st_union_sig;
2594 super(
"ST_Difference",
2595 SqlKind.OTHER_FUNCTION,
2598 OperandTypes.family(signature()),
2599 SqlFunctionCategory.SYSTEM);
2604 assert opBinding.getOperandCount() == 2;
2605 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2606 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2610 java.util.List<SqlTypeFamily> st_difference_sig =
2611 new java.util.ArrayList<SqlTypeFamily>();
2612 st_difference_sig.add(SqlTypeFamily.ANY);
2613 st_difference_sig.add(SqlTypeFamily.ANY);
2614 return st_difference_sig;
2620 super(
"CastToGeography",
2621 SqlKind.OTHER_FUNCTION,
2624 OperandTypes.family(SqlTypeFamily.ANY),
2625 SqlFunctionCategory.SYSTEM);
2630 assert opBinding.getOperandCount() == 1;
2631 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2632 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2638 super(
"ENCODE_TEXT",
2639 SqlKind.OTHER_FUNCTION,
2642 OperandTypes.family(SqlTypeFamily.STRING),
2643 SqlFunctionCategory.SYSTEM);
2648 assert opBinding.getOperandCount() == 1;
2649 return opBinding.getOperandType(0);
2656 super(
"OFFSET_IN_FRAGMENT",
2657 SqlKind.OTHER_FUNCTION,
2660 OperandTypes.NILADIC,
2661 SqlFunctionCategory.SYSTEM);
2666 assert opBinding.getOperandCount() == 0;
2667 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2668 return typeFactory.createSqlType(SqlTypeName.BIGINT);
2674 super(
"APPROX_COUNT_DISTINCT",
2676 SqlKind.OTHER_FUNCTION,
2679 OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
2680 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
2681 SqlFunctionCategory.SYSTEM,
2684 Optionality.FORBIDDEN);
2689 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2690 return typeFactory.createSqlType(SqlTypeName.BIGINT);
2696 super(
"APPROX_MEDIAN",
2697 SqlKind.OTHER_FUNCTION,
2700 OperandTypes.family(SqlTypeFamily.NUMERIC),
2701 SqlFunctionCategory.SYSTEM);
2706 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2707 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2713 super(
"APPROX_PERCENTILE",
2714 SqlKind.OTHER_FUNCTION,
2717 OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
2718 SqlFunctionCategory.SYSTEM);
2723 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2724 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2730 super(
"APPROX_QUANTILE",
2731 SqlKind.OTHER_FUNCTION,
2734 OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
2735 SqlFunctionCategory.SYSTEM);
2740 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2741 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2749 SqlKind.OTHER_FUNCTION,
2752 OperandTypes.or(OperandTypes.family(SqlTypeFamily.NUMERIC),
2753 OperandTypes.family(SqlTypeFamily.GEO)),
2754 SqlFunctionCategory.SYSTEM);
2759 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2760 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2764 static class Mode extends SqlAggFunction {
2767 SqlKind.OTHER_FUNCTION,
2771 SqlFunctionCategory.SYSTEM);
2776 return opBinding.getOperandType(0);
2780 public static class Sample extends SqlAggFunction {
2784 SqlKind.OTHER_FUNCTION,
2788 SqlFunctionCategory.SYSTEM,
2791 Optionality.FORBIDDEN);
2796 return opBinding.getOperandType(0);
2803 super(
"LAST_SAMPLE",
2805 SqlKind.OTHER_FUNCTION,
2809 SqlFunctionCategory.SYSTEM,
2812 Optionality.FORBIDDEN);
2817 return opBinding.getOperandType(0);
2825 SqlKind.OTHER_FUNCTION,
2829 SqlFunctionCategory.SYSTEM,
2832 Optionality.FORBIDDEN);
2837 return opBinding.getOperandType(0);
2841 static class SumIf extends SqlAggFunction {
2844 SqlKind.OTHER_FUNCTION,
2847 OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.BOOLEAN),
2848 SqlFunctionCategory.SYSTEM);
2853 return opBinding.getOperandType(0);
2859 super(
"CONDITIONAL_CHANGE_EVENT",
2861 SqlKind.OTHER_FUNCTION,
2864 OperandTypes.family(SqlTypeFamily.ANY),
2865 SqlFunctionCategory.SYSTEM,
2868 Optionality.FORBIDDEN);
2883 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2884 return typeFactory.createSqlType(SqlTypeName.BIGINT);
2891 SqlKind.OTHER_FUNCTION,
2895 SqlFunctionCategory.USER_DEFINED_FUNCTION);
2897 arg_names = sig.getArgNames();
2907 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2909 SqlTypeName valueType =
2911 RelDataType subType = typeFactory.createSqlType(valueType, -1);
2912 RelDataType arr = typeFactory.createArrayType(subType, -1);
2916 SqlTypeName ret = sig.getSqlRet();
2917 return typeFactory.createTypeWithNullability(
2918 typeFactory.createSqlType(ret),
true);
2929 SqlKind.OTHER_FUNCTION,
2933 SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION);
2934 arg_types = sig.getArgs();
2935 outs = sig.getOuts();
2936 out_names = sig.getOutNames();
2937 arg_names = sig.getArgNames();
2941 pretty_arg_names = sig.getPrettyArgNames();
2942 options = sig.getOptions();
2943 cursor_field_types = sig.getCursorFieldTypes();
2944 default_values = sig.getDefaultValues();
2954 return pretty_arg_names;
2968 final Boolean has_names = this.pretty_arg_names != null
2969 && this.pretty_arg_names.size() == this.arg_types.size();
2970 final List<FunctionParameter> parameters =
new java.util.ArrayList<>();
2971 for (
int i = 0; i < this.arg_types.size(); i++) {
2972 final int arg_idx = i;
2973 parameters.add(
new FunctionParameter() {
2974 public int getOrdinal() {
2978 public String getName() {
2980 return pretty_arg_names.get(arg_idx);
2982 return "arg" + arg_idx;
2985 public RelDataType getType(RelDataTypeFactory typeFactory) {
2986 SqlTypeFamily
type = toSqlTypeName(arg_types.get(arg_idx)).getFamily();
2987 return type.getDefaultConcreteType(typeFactory);
2990 public boolean isOptional() {
3000 return opBinding -> {
3001 RelDataTypeFactory fact = opBinding.getTypeFactory();
3002 FieldInfoBuilder ret = fact.builder();
3003 for (
int out_idx = 0; out_idx < outs.size(); ++out_idx) {
3005 if (toSqlTypeName(outs.get(out_idx)) == SqlTypeName.ARRAY) {
3008 extSubType = getValueType(extSubType);
3010 RelDataType subtype = fact.createSqlType(toSqlTypeName(extSubType));
3011 type = fact.createArrayType(subtype, -1);
3013 type = fact.createSqlType(toSqlTypeName(outs.get(out_idx)));
3015 ret = ret.add(out_names.get(out_idx), type);
3016 ret = ret.nullable(
true);
3024 System.out.println(msg);
3029 final Boolean debugMode =
false;
3030 Set<RelColumnMapping> s =
new HashSet<RelColumnMapping>();
3031 debugPrint(
"getNameAsId() -> " + getNameAsId() +
", arg_names=" + arg_names
3032 +
", out_names=" + out_names,
3034 if (
Integer.valueOf(options.getOrDefault(
"filter_table_function_transpose",
"0"))
3036 debugPrint(
"getNameAsId() -> " + getNameAsId(), debugMode);
3038 for (
int arg_idx = 0; arg_idx < arg_names.size(); ++arg_idx) {
3039 String arg_name = arg_names.get(arg_idx);
3041 int start = arg_name.indexOf(
"[");
3044 int end = arg_name.lastIndexOf(
"]");
3045 fields = arg_name.substring(start + 1, end)
3046 .replaceAll(
"\\s+",
"")
3049 fields =
new String[] {arg_name};
3051 debugPrint(
"fields=" + Arrays.toString(fields), debugMode);
3052 for (
int field_idx = 0; field_idx < fields.length; ++field_idx) {
3053 int out_idx = out_names.indexOf(fields[field_idx]);
3055 s.add(
new RelColumnMapping(out_idx, rel_idx, field_idx,
false));
3056 debugPrint(
"out_idx, arg_idx/rel_idx, field_idx=" + out_idx +
", " + arg_idx
3057 +
"/" + rel_idx +
", " + field_idx,
3076 StringBuilder ret =
new StringBuilder();
3078 ret.append(this.getName());
3081 for (
int i = 0; i < this.arg_types.size(); i++) {
3087 String paramName = arg_names.get(i);
3088 ret.append(paramName).
append(
" => ");
3090 final String t = type.toString().toUpperCase(Locale.ROOT);
3091 ret.append(
"<").
append(t);
3093 List<ExtensionFunction.ExtArgumentType> field_types =
3094 cursor_field_types.get(paramName);
3096 for (
int j = 0; j < field_types.size(); j++) {
3101 ret.append(toSqlTypeName(field_type));
3102 if (isColumnListType(field_type)) {
3105 ret.append(toSqlTypeName(subtype));
3107 }
else if (isColumnArrayType(field_type) || isArrayType(field_type)) {
3110 ret.append(toSqlTypeName(subtype));
3120 return ret.toString();
3126 return this.arg_names;
3132 return this.getExtendedSignature().hashCode();
3144 if (getClass() != obj.getClass()) {
3153 if (!this.getName().equals(other.getName())) {
3156 if (arg_types.size() != other.arg_types.size()) {
3160 for (
int i = 0; i < arg_types.size(); i++) {
3161 if (arg_types.get(i) != other.arg_types.get(i)) {
3165 String paramName = this.arg_names.get(i);
3166 String otherParamName = other.getExtendedParamNames().
get(i);
3167 if (!paramName.equals(otherParamName)) {
3171 List<ExtArgumentType> field_types = this.getCursorFieldTypes().
get(paramName);
3172 List<ExtArgumentType> other_field_types =
3173 other.getCursorFieldTypes().
get(paramName);
3174 if (field_types.size() != other_field_types.size()) {
3177 for (
int j = 0; j < field_types.size(); j++) {
3178 if (field_types.get(j) != other_field_types.get(j)) {
3189 return getExtendedSignature();
3193 return cursor_field_types;
3201 return default_values;
3205 return (default_values.size() > 0);
3212 String paramName = getParamNames().get(i);
3213 return getDefaultValues().get(paramName) != null;
3217 return getDefaultValues().size();
3234 for (Ord<SqlNode> operand : Ord.zip(permutedCall.getOperandList())) {
3235 if (operand.e.getClass() == SqlBasicCall.class) {
3236 SqlBasicCall operandAsCall = (SqlBasicCall) operand.e;
3237 if (operandAsCall.getOperator().getName() ==
"DEFAULT") {
3239 String paramName = tf.getExtendedParamNames().
get(operand.i);
3240 Comparable<?> defaultVal = tf.getDefaultValues().
get(paramName);
3241 SqlLiteral newOperand = createLiteralForDefaultValue(
3242 defaultVal, operand.e.getParserPosition());
3243 permutedCall.setOperand(operand.i, newOperand);
3247 return permutedCall;
3251 if (value instanceof
Integer || value instanceof Long || value instanceof
Float
3252 || value instanceof
Double) {
3253 return SqlLiteral.createExactNumeric(value.toString(), pos);
3254 }
else if (value instanceof Boolean) {
3255 Boolean asBool = (Boolean) value;
3256 return SqlLiteral.createBoolean(asBool.booleanValue(), pos);
3257 }
else if (value instanceof String) {
3258 return SqlLiteral.createCharString(value.toString(), pos);
3271 return getOperandTypeChecker().checkOperandTypes(callBinding, throwOnFailure);
3275 private final List<ExtArgumentType>
outs;
3290 super(
"HeavyDB_Geo_PolyBoundsPtr",
3291 SqlKind.OTHER_FUNCTION,
3294 OperandTypes.family(SqlTypeFamily.ANY),
3295 SqlFunctionCategory.SYSTEM);
3300 assert opBinding.getOperandCount() == 1;
3301 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3302 return typeFactory.createSqlType(SqlTypeName.BIGINT);
3308 super(
"convert_meters_to_pixel_width",
3309 SqlKind.OTHER_FUNCTION,
3312 OperandTypes.family(SqlTypeFamily.NUMERIC,
3314 SqlTypeFamily.NUMERIC,
3315 SqlTypeFamily.NUMERIC,
3316 SqlTypeFamily.NUMERIC,
3317 SqlTypeFamily.NUMERIC),
3318 SqlFunctionCategory.SYSTEM);
3323 assert opBinding.getOperandCount() == 6;
3324 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3325 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
3331 super(
"convert_meters_to_pixel_height",
3332 SqlKind.OTHER_FUNCTION,
3335 OperandTypes.family(SqlTypeFamily.NUMERIC,
3337 SqlTypeFamily.NUMERIC,
3338 SqlTypeFamily.NUMERIC,
3339 SqlTypeFamily.NUMERIC,
3340 SqlTypeFamily.NUMERIC),
3341 SqlFunctionCategory.SYSTEM);
3346 assert opBinding.getOperandCount() == 6;
3347 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3348 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
3354 super(
"is_point_in_view",
3355 SqlKind.OTHER_FUNCTION,
3358 OperandTypes.family(SqlTypeFamily.ANY,
3359 SqlTypeFamily.NUMERIC,
3360 SqlTypeFamily.NUMERIC,
3361 SqlTypeFamily.NUMERIC,
3362 SqlTypeFamily.NUMERIC),
3363 SqlFunctionCategory.SYSTEM);
3368 assert opBinding.getOperandCount() == 5;
3369 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3370 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
3376 super(
"is_point_size_in_view",
3377 SqlKind.OTHER_FUNCTION,
3380 OperandTypes.family(SqlTypeFamily.ANY,
3381 SqlTypeFamily.NUMERIC,
3382 SqlTypeFamily.NUMERIC,
3383 SqlTypeFamily.NUMERIC,
3384 SqlTypeFamily.NUMERIC,
3385 SqlTypeFamily.NUMERIC),
3386 SqlFunctionCategory.SYSTEM);
3391 assert opBinding.getOperandCount() == 6;
3392 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3393 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
3399 super(
"usTIMESTAMP",
3400 SqlKind.OTHER_FUNCTION,
3403 OperandTypes.STRING,
3404 SqlFunctionCategory.SYSTEM);
3409 assert opBinding.getOperandCount() == 1;
3410 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3411 return typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 6);
3417 super(
"nsTIMESTAMP",
3418 SqlKind.OTHER_FUNCTION,
3421 OperandTypes.STRING,
3422 SqlFunctionCategory.SYSTEM);
3427 assert opBinding.getOperandCount() == 1;
3428 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
3429 return typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 9);
3435 super(
"FORWARD_FILL",
3440 OperandTypes.family(SqlTypeFamily.ANY),
3441 SqlFunctionCategory.SYSTEM,
3444 Optionality.FORBIDDEN);
3455 super(
"BACKWARD_FILL",
3460 OperandTypes.family(SqlTypeFamily.ANY),
3461 SqlFunctionCategory.SYSTEM,
3464 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()
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)
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)
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)
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)