17 package com.mapd.calcite.parser;
19 import com.google.common.base.Predicate;
20 import com.google.common.collect.ImmutableList;
21 import com.google.common.collect.Multimap;
24 import org.apache.calcite.rel.metadata.RelColumnMapping;
25 import org.apache.calcite.rel.type.RelDataType;
26 import org.apache.calcite.rel.type.RelDataTypeFactory;
27 import org.apache.calcite.rel.type.RelDataTypeFactory.FieldInfoBuilder;
28 import org.apache.calcite.schema.FunctionParameter;
29 import org.apache.calcite.schema.TranslatableTable;
30 import org.apache.calcite.sql.SqlAggFunction;
31 import org.apache.calcite.sql.SqlCall;
32 import org.apache.calcite.sql.SqlCallBinding;
33 import org.apache.calcite.sql.SqlFunction;
34 import org.apache.calcite.sql.SqlFunctionCategory;
35 import org.apache.calcite.sql.SqlIdentifier;
36 import org.apache.calcite.sql.SqlKind;
37 import org.apache.calcite.sql.SqlLiteral;
38 import org.apache.calcite.sql.SqlNode;
39 import org.apache.calcite.sql.SqlOperator;
40 import org.apache.calcite.sql.SqlOperatorBinding;
41 import org.apache.calcite.sql.SqlOperatorTable;
42 import org.apache.calcite.sql.SqlSyntax;
43 import org.apache.calcite.sql.SqlTableFunction;
44 import org.apache.calcite.sql.fun.SqlArrayValueConstructor;
45 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
46 import org.apache.calcite.sql.parser.SqlParserPos;
47 import org.apache.calcite.sql.type.OperandTypes;
48 import org.apache.calcite.sql.type.ReturnTypes;
49 import org.apache.calcite.sql.type.SameOperandTypeChecker;
50 import org.apache.calcite.sql.type.SqlReturnTypeInference;
51 import org.apache.calcite.sql.type.SqlTypeFamily;
52 import org.apache.calcite.sql.type.SqlTypeName;
53 import org.apache.calcite.sql.type.SqlTypeTransforms;
54 import org.apache.calcite.sql.type.SqlTypeUtil;
55 import org.apache.calcite.sql.util.ChainedSqlOperatorTable;
56 import org.apache.calcite.sql.util.ListSqlOperatorTable;
57 import org.apache.calcite.sql.util.ReflectiveSqlOperatorTable;
58 import org.apache.calcite.sql.validate.SqlNameMatcher;
59 import org.apache.calcite.util.Optionality;
60 import org.checkerframework.checker.nullness.qual.Nullable;
61 import org.slf4j.Logger;
62 import org.slf4j.LoggerFactory;
64 import java.lang.reflect.Field;
65 import java.util.Arrays;
66 import java.util.HashSet;
67 import java.util.Iterator;
68 import java.util.List;
75 SqlFunctionCategory category,
77 List<SqlOperator> operatorList,
78 SqlNameMatcher nameMatcher) {
79 for (SqlOperator
operator : this.getOperatorList()) {
80 if (
operator.getSyntax() != syntax) {
83 if (!opName.isSimple()
84 || !nameMatcher.matches(operator.getName(), opName.getSimple())) {
87 SqlFunctionCategory functionCategory;
88 if (
operator instanceof SqlFunction) {
89 functionCategory = ((SqlFunction)
operator).getFunctionType();
91 functionCategory = SqlFunctionCategory.SYSTEM;
93 if (category != functionCategory
94 && category != SqlFunctionCategory.USER_DEFINED_FUNCTION) {
97 operatorList.add(
operator);
110 Field
f = ReflectiveSqlOperatorTable.class.getDeclaredField(
111 "caseSensitiveOperators");
112 f.setAccessible(
true);
113 Multimap operators = (Multimap) f.get(SqlStdOperatorTable.instance());
114 for (Iterator i = operators.entries().iterator(); i.hasNext();) {
115 Map.Entry entry = (Map.Entry) i.next();
116 if (entry.getValue() == SqlStdOperatorTable.APPROX_COUNT_DISTINCT
117 || entry.getValue() == SqlStdOperatorTable.AVG
118 || entry.getValue() == SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR) {
125 Field f = ReflectiveSqlOperatorTable.class.getDeclaredField(
126 "caseInsensitiveOperators");
127 f.setAccessible(
true);
128 Multimap operators = (Multimap) f.get(SqlStdOperatorTable.instance());
129 for (Iterator i = operators.entries().iterator(); i.hasNext();) {
130 Map.Entry entry = (Map.Entry) i.next();
131 if (entry.getValue() == SqlStdOperatorTable.APPROX_COUNT_DISTINCT
132 || entry.getValue() == SqlStdOperatorTable.AVG
133 || entry.getValue() == SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR) {
141 }
catch (Exception e) {
142 throw new RuntimeException(e);
150 LoggerFactory.getLogger(HeavyDBSqlOperatorTable.class);
162 listOpTab = (ListSqlOperatorTable) tableList.get(1);
182 opTab.addOperator(
new Any());
183 opTab.addOperator(
new All());
184 opTab.addOperator(
new Now());
187 opTab.addOperator(
new Dateadd());
191 opTab.addOperator(
new Length());
197 opTab.addOperator(
new PgILike());
198 opTab.addOperator(
new LTrim());
199 opTab.addOperator(
new RTrim());
200 opTab.addOperator(
new LPad());
201 opTab.addOperator(
new RPad());
202 opTab.addOperator(
new Replace());
203 opTab.addOperator(
new Reverse());
204 opTab.addOperator(
new Repeat());
210 opTab.addOperator(
new Likely());
212 opTab.addOperator(
new Sign());
230 opTab.addOperator(
new ST_X());
231 opTab.addOperator(
new ST_Y());
232 opTab.addOperator(
new ST_XMin());
233 opTab.addOperator(
new ST_XMax());
234 opTab.addOperator(
new ST_YMin());
235 opTab.addOperator(
new ST_YMax());
241 opTab.addOperator(
new ST_Area());
244 opTab.addOperator(
new ST_SRID());
259 opTab.addOperator(
new MapDAvg());
260 opTab.addOperator(
new Sample());
270 if (extSigs == null) {
273 HashSet<String> demangledNames =
new HashSet<String>();
275 final String demangledName =
dropSuffix(extSig.getKey());
276 final String demangledNameArity =
277 String.format(
"%s-%d", demangledName, extSig.getValue().getArgs().size());
278 if (demangledNames.contains(demangledNameArity)) {
281 demangledNames.add(demangledNameArity);
282 if (extSig.getValue().isRowUdf()) {
283 opTab.addOperator(
new ExtFunction(demangledName, extSig.getValue()));
291 int suffix_idx = str.indexOf(
"__");
292 if (suffix_idx == -1) {
295 assert suffix_idx > 0;
296 return str.substring(0, suffix_idx);
306 extends SqlArrayValueConstructor {
309 RelDataTypeFactory typeFactory, List<RelDataType> argTypes) {
310 if (argTypes.isEmpty()) {
311 return typeFactory.createSqlType(SqlTypeName.NULL);
313 return super.getComponentType(typeFactory, argTypes);
318 if (callBinding.operands().isEmpty()) {
321 return super.checkOperandTypes(callBinding, throwOnFailure);
331 SqlKind.OTHER_FUNCTION,
334 OperandTypes.NUMERIC,
335 SqlFunctionCategory.USER_DEFINED_FUNCTION);
340 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
341 return typeFactory.builder().add(
"I", SqlTypeName.INTEGER).build();
351 SqlKind.OTHER_FUNCTION,
354 OperandTypes.VARIADIC,
355 SqlFunctionCategory.USER_DEFINED_FUNCTION);
360 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
361 return typeFactory.builder().add(
"NAME", SqlTypeName.VARCHAR, 1024).build();
372 SqlKind.OTHER_FUNCTION,
375 OperandTypes.STRING_STRING,
376 SqlFunctionCategory.SYSTEM);
381 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
382 return typeFactory.createSqlType(SqlTypeName.BIGINT);
390 SqlKind.OTHER_FUNCTION,
394 SqlFunctionCategory.SYSTEM);
399 assert opBinding.getOperandCount() == 1;
400 RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
401 assert elem_type != null;
407 public static class Any extends SqlFunction {
410 SqlKind.OTHER_FUNCTION,
414 SqlFunctionCategory.SYSTEM);
419 assert opBinding.getOperandCount() == 1;
420 RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
421 assert elem_type != null;
427 public static class All extends SqlFunction {
430 SqlKind.OTHER_FUNCTION,
434 SqlFunctionCategory.SYSTEM);
439 assert opBinding.getOperandCount() == 1;
440 RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
441 assert elem_type != null;
447 public static class Now extends SqlFunction {
450 SqlKind.OTHER_FUNCTION,
453 OperandTypes.NILADIC,
454 SqlFunctionCategory.SYSTEM);
459 assert opBinding.getOperandCount() == 0;
460 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
461 return typeFactory.createSqlType(SqlTypeName.TIMESTAMP);
469 SqlKind.OTHER_FUNCTION,
473 SqlFunctionCategory.SYSTEM);
478 assert opBinding.getOperandCount() == 1;
479 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
480 return typeFactory.createSqlType(
481 SqlTypeName.TIMESTAMP, opBinding.getOperandType(0).getPrecision());
489 SqlKind.OTHER_FUNCTION,
492 OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
493 SqlFunctionCategory.SYSTEM);
498 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
499 return typeFactory.createTypeWithNullability(
500 typeFactory.createSqlType(SqlTypeName.BIGINT),
501 opBinding.getOperandType(1).isNullable());
508 SqlKind.OTHER_FUNCTION,
511 OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
512 SqlFunctionCategory.TIMEDATE);
517 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
518 return typeFactory.createTypeWithNullability(
519 typeFactory.createSqlType(SqlTypeName.BIGINT),
520 opBinding.getOperandType(1).isNullable());
524 public static class Dateadd extends SqlFunction {
527 SqlKind.OTHER_FUNCTION,
530 OperandTypes.family(SqlTypeFamily.STRING,
531 SqlTypeFamily.INTEGER,
532 SqlTypeFamily.DATETIME),
533 SqlFunctionCategory.TIMEDATE);
538 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
539 return typeFactory.createTypeWithNullability(
540 typeFactory.createSqlType(
541 SqlTypeName.TIMESTAMP, opBinding.getOperandType(2).getPrecision()),
542 opBinding.getOperandType(2).isNullable());
549 SqlKind.OTHER_FUNCTION,
552 OperandTypes.family(SqlTypeFamily.STRING,
553 SqlTypeFamily.DATETIME,
554 SqlTypeFamily.DATETIME),
555 SqlFunctionCategory.TIMEDATE);
560 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
561 return typeFactory.createTypeWithNullability(
562 typeFactory.createSqlType(SqlTypeName.BIGINT),
563 opBinding.getOperandType(1).isNullable()
564 || opBinding.getOperandType(2).isNullable());
571 super(
"PG_DATE_TRUNC",
572 SqlKind.OTHER_FUNCTION,
575 OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
576 SqlFunctionCategory.SYSTEM);
581 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
582 return typeFactory.createTypeWithNullability(
583 typeFactory.createSqlType(
584 SqlTypeName.TIMESTAMP, opBinding.getOperandType(1).getPrecision()),
585 opBinding.getOperandType(1).isNullable());
589 public static class Length extends SqlFunction {
592 SqlKind.OTHER_FUNCTION,
596 SqlFunctionCategory.SYSTEM);
601 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
602 return typeFactory.createSqlType(SqlTypeName.INTEGER);
609 SqlKind.OTHER_FUNCTION,
613 SqlFunctionCategory.SYSTEM);
618 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
619 return typeFactory.createSqlType(SqlTypeName.INTEGER);
625 super(
"KEY_FOR_STRING",
626 SqlKind.OTHER_FUNCTION,
630 SqlFunctionCategory.SYSTEM);
635 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
636 return typeFactory.createTypeWithNullability(
637 typeFactory.createSqlType(SqlTypeName.INTEGER),
638 opBinding.getOperandType(0).isNullable());
644 super(
"SAMPLE_RATIO",
645 SqlKind.OTHER_FUNCTION,
649 SqlFunctionCategory.SYSTEM);
654 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
655 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
658 private static java.util.List<SqlTypeFamily>
signature() {
659 java.util.ArrayList<SqlTypeFamily> families =
660 new java.util.ArrayList<SqlTypeFamily>();
661 families.add(SqlTypeFamily.NUMERIC);
668 super(
"WIDTH_BUCKET",
669 SqlKind.OTHER_FUNCTION,
673 SqlFunctionCategory.SYSTEM);
678 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
679 return typeFactory.createTypeWithNullability(
680 typeFactory.createSqlType(SqlTypeName.INTEGER),
true);
683 private static java.util.List<SqlTypeFamily>
signature() {
684 java.util.ArrayList<SqlTypeFamily> families =
685 new java.util.ArrayList<SqlTypeFamily>();
686 families.add(SqlTypeFamily.NUMERIC);
687 families.add(SqlTypeFamily.NUMERIC);
688 families.add(SqlTypeFamily.NUMERIC);
689 families.add(SqlTypeFamily.INTEGER);
696 super(
"ARRAY_LENGTH",
697 SqlKind.OTHER_FUNCTION,
701 SqlFunctionCategory.SYSTEM);
706 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
707 return typeFactory.createSqlType(SqlTypeName.INTEGER);
711 public static class PgILike extends SqlFunction {
714 SqlKind.OTHER_FUNCTION,
718 SqlFunctionCategory.SYSTEM);
722 java.util.ArrayList<SqlTypeFamily> families =
723 new java.util.ArrayList<SqlTypeFamily>();
731 implements java.util.function.Predicate<Integer>, Predicate<Integer> {
733 public boolean test(Integer t) {
745 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
746 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
753 SqlKind.OTHER_FUNCTION,
757 SqlFunctionCategory.SYSTEM);
761 java.util.ArrayList<SqlTypeFamily> families =
762 new java.util.ArrayList<SqlTypeFamily>();
770 implements java.util.function.Predicate<Integer>, Predicate<Integer> {
772 public boolean test(Integer t) {
783 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
784 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
792 ReturnTypes.ARG0.andThen(SqlTypeTransforms.TO_NULLABLE)
793 .andThen(SqlTypeTransforms.TO_VARYING),
796 OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.STRING),
797 new SameOperandTypeChecker(2) {
799 protected List<Integer> getOperandList(
int operandCount) {
800 return ImmutableList.of(0, 1);
803 SqlFunctionCategory.STRING);
807 public SqlCall
createCall(@Nullable SqlLiteral functionQualifier,
809 @Nullable SqlNode... operands) {
810 assert functionQualifier == null;
811 switch (operands.length) {
813 operands =
new SqlNode[] {SqlLiteral.createCharString(
" ", pos), operands[0]};
816 if (operands[1] == null) {
817 operands[1] = SqlLiteral.createCharString(
" ", pos);
819 operands =
new SqlNode[] {operands[1], operands[0]};
822 throw new IllegalArgumentException(
823 "Invalid operand count " + Arrays.toString(operands));
825 return super.createCall(functionQualifier, pos, operands);
831 super(
"LTRIM", SqlKind.LTRIM);
836 super(
"RTRIM", SqlKind.RTRIM);
842 SqlKind.OTHER_FUNCTION,
843 ReturnTypes.ARG0.andThen(SqlTypeTransforms.TO_NULLABLE)
844 .andThen(SqlTypeTransforms.TO_VARYING),
846 OperandTypes.and(OperandTypes.family(SqlTypeFamily.STRING,
847 SqlTypeFamily.INTEGER,
848 SqlTypeFamily.STRING),
849 new SameOperandTypeChecker(3) {
851 protected List<Integer> getOperandList(
int operandCount) {
852 return ImmutableList.of(0, 2);
855 SqlFunctionCategory.STRING);
859 public SqlCall
createCall(@Nullable SqlLiteral functionQualifier,
861 @Nullable SqlNode... operands) {
862 assert functionQualifier == null;
863 switch (operands.length) {
865 operands =
new SqlNode[] {
866 operands[0], operands[1], SqlLiteral.createCharString(
" ", pos)};
869 if (operands[2] == null) {
870 operands[2] = SqlLiteral.createCharString(
" ", pos);
872 operands =
new SqlNode[] {operands[0], operands[1], operands[2]};
875 throw new IllegalArgumentException(
876 "Invalid operand count " + Arrays.toString(operands));
878 return super.createCall(functionQualifier, pos, operands);
883 if (!super.checkOperandTypes(callBinding, throwOnFailure)) {
888 return SqlTypeUtil.isCharTypeComparable(callBinding,
889 ImmutableList.of(callBinding.operand(0), callBinding.operand(2)),
911 SqlKind.OTHER_FUNCTION,
914 OperandTypes.family(getSignatureFamilies()),
919 java.util.ArrayList<SqlTypeFamily> families =
920 new java.util.ArrayList<SqlTypeFamily>();
923 families.add(SqlTypeFamily.INTEGER);
929 return opBinding.getOperandType(0);
933 public static class Replace extends SqlFunction {
936 SqlKind.OTHER_FUNCTION,
939 OperandTypes.family(getSignatureFamilies()),
944 java.util.ArrayList<SqlTypeFamily> families =
945 new java.util.ArrayList<SqlTypeFamily>();
954 return opBinding.getOperandType(0);
958 public SqlCall
createCall(@Nullable SqlLiteral functionQualifier,
960 @Nullable SqlNode... operands) {
961 assert functionQualifier == null;
962 switch (operands.length) {
964 operands =
new SqlNode[] {
965 operands[0], operands[1], SqlLiteral.createCharString(
"", pos)};
970 throw new IllegalArgumentException(
971 "Invalid operand count " + Arrays.toString(operands));
973 return super.createCall(functionQualifier, pos, operands);
976 public static class Reverse extends SqlFunction {
979 SqlKind.OTHER_FUNCTION,
982 OperandTypes.family(getSignatureFamilies()),
987 java.util.ArrayList<SqlTypeFamily> families =
988 new java.util.ArrayList<SqlTypeFamily>();
995 return opBinding.getOperandType(0);
998 public static class Repeat extends SqlFunction {
1001 SqlKind.OTHER_FUNCTION,
1004 OperandTypes.family(getSignatureFamilies()),
1009 java.util.ArrayList<SqlTypeFamily> families =
1010 new java.util.ArrayList<SqlTypeFamily>();
1012 families.add(SqlTypeFamily.INTEGER);
1018 return opBinding.getOperandType(0);
1024 super(
"REGEXP_REPLACE",
1025 SqlKind.OTHER_FUNCTION,
1028 OperandTypes.family(getSignatureFamilies()),
1033 java.util.ArrayList<SqlTypeFamily> families =
1034 new java.util.ArrayList<SqlTypeFamily>();
1038 families.add(SqlTypeFamily.INTEGER);
1039 families.add(SqlTypeFamily.INTEGER);
1045 public SqlCall
createCall(@Nullable SqlLiteral functionQualifier,
1047 @Nullable SqlNode... operands) {
1048 assert functionQualifier == null;
1049 final int num_operands = operands.length;
1050 if (num_operands < 2 || num_operands > 6) {
1051 throw new IllegalArgumentException(
1052 "Invalid operand count " + Arrays.toString(operands));
1054 SqlNode[] new_operands =
new SqlNode[6];
1056 new_operands[0] = operands[0];
1058 new_operands[1] = operands[1];
1060 if (num_operands < 3 || operands[2] == null) {
1061 new_operands[2] = SqlLiteral.createCharString(
"", pos);
1063 new_operands[2] = operands[2];
1066 if (num_operands < 4 || operands[3] == null) {
1067 new_operands[3] = SqlLiteral.createExactNumeric(
"1", pos);
1069 new_operands[3] = operands[3];
1072 if (num_operands < 5 || operands[4] == null) {
1073 new_operands[4] = SqlLiteral.createExactNumeric(
"0", pos);
1075 new_operands[4] = operands[4];
1078 if (num_operands < 6 || operands[5] == null) {
1079 new_operands[5] = SqlLiteral.createCharString(
"c", pos);
1081 new_operands[5] = operands[5];
1083 return super.createCall(functionQualifier, pos, new_operands);
1088 return opBinding.getOperandType(0);
1094 super(
"REGEXP_SUBSTR",
1095 SqlKind.OTHER_FUNCTION,
1098 OperandTypes.family(getSignatureFamilies()),
1104 SqlKind.OTHER_FUNCTION,
1107 OperandTypes.family(getSignatureFamilies()),
1108 SqlFunctionCategory.SYSTEM);
1112 java.util.ArrayList<SqlTypeFamily> families =
1113 new java.util.ArrayList<SqlTypeFamily>();
1116 families.add(SqlTypeFamily.INTEGER);
1117 families.add(SqlTypeFamily.INTEGER);
1119 families.add(SqlTypeFamily.INTEGER);
1124 public SqlCall
createCall(@Nullable SqlLiteral functionQualifier,
1126 @Nullable SqlNode... operands) {
1127 assert functionQualifier == null;
1128 final int num_operands = operands.length;
1129 if (num_operands < 2 || num_operands > 6) {
1130 throw new IllegalArgumentException(
1131 "Invalid operand count " + Arrays.toString(operands));
1133 SqlNode[] new_operands =
new SqlNode[6];
1136 new_operands[0] = operands[0];
1138 new_operands[1] = operands[1];
1140 if (num_operands < 3 || operands[2] == null) {
1141 new_operands[2] = SqlLiteral.createExactNumeric(
"1", pos);
1143 new_operands[2] = operands[2];
1146 if (num_operands < 4 || operands[3] == null) {
1147 new_operands[3] = SqlLiteral.createExactNumeric(
"1", pos);
1149 new_operands[3] = operands[3];
1152 if (num_operands < 5 || operands[4] == null) {
1153 new_operands[4] = SqlLiteral.createCharString(
"c", pos);
1155 new_operands[4] = operands[4];
1158 if (num_operands < 6 || operands[5] == null) {
1159 new_operands[5] = SqlLiteral.createExactNumeric(
"1", pos);
1161 new_operands[5] = operands[5];
1163 return super.createCall(functionQualifier, pos, new_operands);
1168 return opBinding.getOperandType(0);
1174 super(
"REGEXP_MATCH");
1178 public static class Likely extends SqlFunction {
1181 SqlKind.OTHER_FUNCTION,
1184 OperandTypes.BOOLEAN,
1185 SqlFunctionCategory.SYSTEM);
1190 return opBinding.getOperandType(0);
1197 SqlKind.OTHER_FUNCTION,
1200 OperandTypes.BOOLEAN,
1201 SqlFunctionCategory.SYSTEM);
1206 return opBinding.getOperandType(0);
1210 public static class Sign extends SqlFunction {
1213 SqlKind.OTHER_FUNCTION,
1216 OperandTypes.NUMERIC,
1217 SqlFunctionCategory.NUMERIC);
1222 return opBinding.getOperandType(0);
1229 SqlKind.OTHER_FUNCTION,
1232 OperandTypes.family(signature()),
1233 SqlFunctionCategory.NUMERIC);
1238 assert opBinding.getOperandCount() == 2;
1239 return opBinding.getOperandType(0);
1243 java.util.List<SqlTypeFamily> truncate_sig =
1244 new java.util.ArrayList<SqlTypeFamily>();
1245 truncate_sig.add(SqlTypeFamily.NUMERIC);
1246 truncate_sig.add(SqlTypeFamily.INTEGER);
1247 return truncate_sig;
1254 SqlKind.OTHER_FUNCTION,
1257 OperandTypes.family(signature()),
1258 SqlFunctionCategory.SYSTEM);
1263 assert opBinding.getOperandCount() == 1;
1264 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1265 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1269 java.util.List<SqlTypeFamily> st_isempty_sig =
1270 new java.util.ArrayList<SqlTypeFamily>();
1271 st_isempty_sig.add(SqlTypeFamily.ANY);
1272 return st_isempty_sig;
1279 SqlKind.OTHER_FUNCTION,
1282 OperandTypes.family(signature()),
1283 SqlFunctionCategory.SYSTEM);
1288 assert opBinding.getOperandCount() == 1;
1289 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1290 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1294 java.util.List<SqlTypeFamily> st_isvalid_sig =
1295 new java.util.ArrayList<SqlTypeFamily>();
1296 st_isvalid_sig.add(SqlTypeFamily.ANY);
1297 return st_isvalid_sig;
1303 super(
"ST_Contains",
1304 SqlKind.OTHER_FUNCTION,
1307 OperandTypes.family(signature()),
1308 SqlFunctionCategory.SYSTEM);
1313 assert opBinding.getOperandCount() == 2;
1314 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1315 return typeFactory.createTypeWithNullability(
1316 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1317 opBinding.getOperandType(0).isNullable()
1318 || opBinding.getOperandType(1).isNullable());
1322 java.util.List<SqlTypeFamily> st_contains_sig =
1323 new java.util.ArrayList<SqlTypeFamily>();
1324 st_contains_sig.add(SqlTypeFamily.ANY);
1325 st_contains_sig.add(SqlTypeFamily.ANY);
1326 return st_contains_sig;
1333 SqlKind.OTHER_FUNCTION,
1336 OperandTypes.family(signature()),
1337 SqlFunctionCategory.SYSTEM);
1342 assert opBinding.getOperandCount() == 2;
1343 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1344 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1348 java.util.List<SqlTypeFamily> st_equals_sig =
1349 new java.util.ArrayList<SqlTypeFamily>();
1350 st_equals_sig.add(SqlTypeFamily.ANY);
1351 st_equals_sig.add(SqlTypeFamily.ANY);
1352 return st_equals_sig;
1358 super(
"ST_Intersects",
1359 SqlKind.OTHER_FUNCTION,
1362 OperandTypes.family(signature()),
1363 SqlFunctionCategory.SYSTEM);
1368 assert opBinding.getOperandCount() == 2;
1369 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1370 return typeFactory.createTypeWithNullability(
1371 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1372 opBinding.getOperandType(0).isNullable()
1373 || opBinding.getOperandType(1).isNullable());
1377 java.util.List<SqlTypeFamily> st_intersects_sig =
1378 new java.util.ArrayList<SqlTypeFamily>();
1379 st_intersects_sig.add(SqlTypeFamily.ANY);
1380 st_intersects_sig.add(SqlTypeFamily.ANY);
1381 return st_intersects_sig;
1387 super(
"ST_Overlaps",
1388 SqlKind.OTHER_FUNCTION,
1391 OperandTypes.family(signature()),
1392 SqlFunctionCategory.SYSTEM);
1397 assert opBinding.getOperandCount() == 2;
1398 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1399 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1403 java.util.List<SqlTypeFamily> st_overlaps_sig =
1404 new java.util.ArrayList<SqlTypeFamily>();
1405 st_overlaps_sig.add(SqlTypeFamily.ANY);
1406 st_overlaps_sig.add(SqlTypeFamily.ANY);
1407 return st_overlaps_sig;
1413 super(
"ST_Approx_Overlaps",
1414 SqlKind.OTHER_FUNCTION,
1417 OperandTypes.family(signature()),
1418 SqlFunctionCategory.SYSTEM);
1423 assert opBinding.getOperandCount() == 2;
1424 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1425 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1429 java.util.List<SqlTypeFamily> st_overlaps_sig =
1430 new java.util.ArrayList<SqlTypeFamily>();
1431 st_overlaps_sig.add(SqlTypeFamily.ANY);
1432 st_overlaps_sig.add(SqlTypeFamily.ANY);
1433 return st_overlaps_sig;
1439 super(
"ST_Disjoint",
1440 SqlKind.OTHER_FUNCTION,
1443 OperandTypes.family(signature()),
1444 SqlFunctionCategory.SYSTEM);
1449 assert opBinding.getOperandCount() == 2;
1450 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1451 return typeFactory.createTypeWithNullability(
1452 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1453 opBinding.getOperandType(0).isNullable()
1454 || opBinding.getOperandType(1).isNullable());
1458 java.util.List<SqlTypeFamily> st_disjoint_sig =
1459 new java.util.ArrayList<SqlTypeFamily>();
1460 st_disjoint_sig.add(SqlTypeFamily.ANY);
1461 st_disjoint_sig.add(SqlTypeFamily.ANY);
1462 return st_disjoint_sig;
1469 SqlKind.OTHER_FUNCTION,
1472 OperandTypes.family(signature()),
1473 SqlFunctionCategory.SYSTEM);
1478 assert opBinding.getOperandCount() == 2;
1479 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1480 return typeFactory.createTypeWithNullability(
1481 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1482 opBinding.getOperandType(0).isNullable()
1483 || opBinding.getOperandType(1).isNullable());
1487 java.util.List<SqlTypeFamily> st_within_sig =
1488 new java.util.ArrayList<SqlTypeFamily>();
1489 st_within_sig.add(SqlTypeFamily.ANY);
1490 st_within_sig.add(SqlTypeFamily.ANY);
1491 return st_within_sig;
1498 SqlKind.OTHER_FUNCTION,
1501 OperandTypes.family(signature()),
1502 SqlFunctionCategory.SYSTEM);
1507 assert opBinding.getOperandCount() == 3;
1508 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1509 return typeFactory.createTypeWithNullability(
1510 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1511 opBinding.getOperandType(0).isNullable()
1512 || opBinding.getOperandType(1).isNullable()
1513 || opBinding.getOperandType(2).isNullable());
1517 java.util.List<SqlTypeFamily> st_dwithin_sig =
1518 new java.util.ArrayList<SqlTypeFamily>();
1519 st_dwithin_sig.add(SqlTypeFamily.ANY);
1520 st_dwithin_sig.add(SqlTypeFamily.ANY);
1521 st_dwithin_sig.add(SqlTypeFamily.NUMERIC);
1522 return st_dwithin_sig;
1528 super(
"ST_DFullyWithin",
1529 SqlKind.OTHER_FUNCTION,
1532 OperandTypes.family(signature()),
1533 SqlFunctionCategory.SYSTEM);
1538 assert opBinding.getOperandCount() == 3;
1539 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1540 return typeFactory.createTypeWithNullability(
1541 typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1542 opBinding.getOperandType(0).isNullable()
1543 || opBinding.getOperandType(1).isNullable()
1544 || opBinding.getOperandType(2).isNullable());
1548 java.util.List<SqlTypeFamily> st_dwithin_sig =
1549 new java.util.ArrayList<SqlTypeFamily>();
1550 st_dwithin_sig.add(SqlTypeFamily.ANY);
1551 st_dwithin_sig.add(SqlTypeFamily.ANY);
1552 st_dwithin_sig.add(SqlTypeFamily.NUMERIC);
1553 return st_dwithin_sig;
1559 super(
"ST_Distance",
1560 SqlKind.OTHER_FUNCTION,
1563 OperandTypes.family(signature()),
1564 SqlFunctionCategory.SYSTEM);
1569 assert opBinding.getOperandCount() == 2;
1570 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1571 return typeFactory.createTypeWithNullability(
1572 typeFactory.createSqlType(SqlTypeName.DOUBLE),
1573 opBinding.getOperandType(0).isNullable()
1574 || opBinding.getOperandType(1).isNullable());
1578 java.util.List<SqlTypeFamily> st_distance_sig =
1579 new java.util.ArrayList<SqlTypeFamily>();
1580 st_distance_sig.add(SqlTypeFamily.ANY);
1581 st_distance_sig.add(SqlTypeFamily.ANY);
1582 return st_distance_sig;
1588 super(
"ST_MaxDistance",
1589 SqlKind.OTHER_FUNCTION,
1592 OperandTypes.family(signature()),
1593 SqlFunctionCategory.SYSTEM);
1598 assert opBinding.getOperandCount() == 2;
1599 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1600 return typeFactory.createTypeWithNullability(
1601 typeFactory.createSqlType(SqlTypeName.DOUBLE),
1602 opBinding.getOperandType(0).isNullable()
1603 || opBinding.getOperandType(1).isNullable());
1607 java.util.List<SqlTypeFamily> st_maxdistance_sig =
1608 new java.util.ArrayList<SqlTypeFamily>();
1609 st_maxdistance_sig.add(SqlTypeFamily.ANY);
1610 st_maxdistance_sig.add(SqlTypeFamily.ANY);
1611 return st_maxdistance_sig;
1617 super(
"ST_GeogFromText",
1618 SqlKind.OTHER_FUNCTION,
1621 OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
1622 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
1623 SqlFunctionCategory.SYSTEM);
1628 assert opBinding.getOperandCount() == 1;
1629 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1630 return typeFactory.createSqlType(SqlTypeName.INTEGER);
1636 super(
"ST_GeomFromText",
1637 SqlKind.OTHER_FUNCTION,
1640 OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
1641 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
1642 SqlFunctionCategory.SYSTEM);
1647 assert opBinding.getOperandCount() == 1;
1648 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1649 return typeFactory.createSqlType(SqlTypeName.INTEGER);
1655 super(
"ST_Transform",
1656 SqlKind.OTHER_FUNCTION,
1659 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
1660 SqlFunctionCategory.SYSTEM);
1665 assert opBinding.getOperandCount() == 1;
1666 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1667 return typeFactory.createTypeWithNullability(
1668 typeFactory.createSqlType(SqlTypeName.INTEGER),
1669 opBinding.getOperandType(0).isNullable());
1673 static class ST_X extends SqlFunction {
1676 SqlKind.OTHER_FUNCTION,
1679 OperandTypes.family(SqlTypeFamily.ANY),
1680 SqlFunctionCategory.SYSTEM);
1685 assert opBinding.getOperandCount() == 1;
1686 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1687 return typeFactory.createTypeWithNullability(
1688 typeFactory.createSqlType(SqlTypeName.DOUBLE),
1689 opBinding.getOperandType(0).isNullable());
1693 static class ST_Y extends SqlFunction {
1696 SqlKind.OTHER_FUNCTION,
1699 OperandTypes.family(SqlTypeFamily.ANY),
1700 SqlFunctionCategory.SYSTEM);
1705 assert opBinding.getOperandCount() == 1;
1706 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1707 return typeFactory.createTypeWithNullability(
1708 typeFactory.createSqlType(SqlTypeName.DOUBLE),
1709 opBinding.getOperandType(0).isNullable());
1716 SqlKind.OTHER_FUNCTION,
1719 OperandTypes.family(SqlTypeFamily.ANY),
1720 SqlFunctionCategory.SYSTEM);
1725 assert opBinding.getOperandCount() == 1;
1726 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1727 return typeFactory.createTypeWithNullability(
1728 typeFactory.createSqlType(SqlTypeName.DOUBLE),
1729 opBinding.getOperandType(0).isNullable());
1736 SqlKind.OTHER_FUNCTION,
1739 OperandTypes.family(SqlTypeFamily.ANY),
1740 SqlFunctionCategory.SYSTEM);
1745 assert opBinding.getOperandCount() == 1;
1746 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1747 return typeFactory.createTypeWithNullability(
1748 typeFactory.createSqlType(SqlTypeName.DOUBLE),
1749 opBinding.getOperandType(0).isNullable());
1756 SqlKind.OTHER_FUNCTION,
1759 OperandTypes.family(SqlTypeFamily.ANY),
1760 SqlFunctionCategory.SYSTEM);
1765 assert opBinding.getOperandCount() == 1;
1766 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1767 return typeFactory.createTypeWithNullability(
1768 typeFactory.createSqlType(SqlTypeName.DOUBLE),
1769 opBinding.getOperandType(0).isNullable());
1776 SqlKind.OTHER_FUNCTION,
1779 OperandTypes.family(SqlTypeFamily.ANY),
1780 SqlFunctionCategory.SYSTEM);
1785 assert opBinding.getOperandCount() == 1;
1786 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1787 return typeFactory.createTypeWithNullability(
1788 typeFactory.createSqlType(SqlTypeName.DOUBLE),
1789 opBinding.getOperandType(0).isNullable());
1796 SqlKind.OTHER_FUNCTION,
1799 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
1800 SqlFunctionCategory.SYSTEM);
1805 assert opBinding.getOperandCount() == 1;
1806 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1807 return typeFactory.createTypeWithNullability(
1808 typeFactory.createSqlType(SqlTypeName.INTEGER),
1809 opBinding.getOperandType(0).isNullable());
1815 super(
"ST_EndPoint",
1816 SqlKind.OTHER_FUNCTION,
1819 OperandTypes.family(SqlTypeFamily.ANY),
1820 SqlFunctionCategory.SYSTEM);
1825 assert opBinding.getOperandCount() == 1;
1826 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1827 return typeFactory.createTypeWithNullability(
1828 typeFactory.createSqlType(SqlTypeName.INTEGER),
1829 opBinding.getOperandType(0).isNullable());
1835 super(
"ST_StartPoint",
1836 SqlKind.OTHER_FUNCTION,
1839 OperandTypes.family(SqlTypeFamily.ANY),
1840 SqlFunctionCategory.SYSTEM);
1845 assert opBinding.getOperandCount() == 1;
1846 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1847 return typeFactory.createTypeWithNullability(
1848 typeFactory.createSqlType(SqlTypeName.INTEGER),
1849 opBinding.getOperandType(0).isNullable());
1856 SqlKind.OTHER_FUNCTION,
1859 OperandTypes.family(SqlTypeFamily.ANY),
1860 SqlFunctionCategory.SYSTEM);
1865 assert opBinding.getOperandCount() == 1;
1866 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1867 return typeFactory.createTypeWithNullability(
1868 typeFactory.createSqlType(SqlTypeName.DOUBLE),
1869 opBinding.getOperandType(0).isNullable());
1875 super(
"ST_Perimeter",
1876 SqlKind.OTHER_FUNCTION,
1879 OperandTypes.family(SqlTypeFamily.ANY),
1880 SqlFunctionCategory.SYSTEM);
1885 assert opBinding.getOperandCount() == 1;
1886 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1887 return typeFactory.createTypeWithNullability(
1888 typeFactory.createSqlType(SqlTypeName.DOUBLE),
1889 opBinding.getOperandType(0).isNullable());
1896 SqlKind.OTHER_FUNCTION,
1899 OperandTypes.family(SqlTypeFamily.ANY),
1900 SqlFunctionCategory.SYSTEM);
1905 assert opBinding.getOperandCount() == 1;
1906 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1907 return typeFactory.createTypeWithNullability(
1908 typeFactory.createSqlType(SqlTypeName.DOUBLE),
1909 opBinding.getOperandType(0).isNullable());
1916 SqlKind.OTHER_FUNCTION,
1919 OperandTypes.family(SqlTypeFamily.ANY),
1920 SqlFunctionCategory.SYSTEM);
1925 assert opBinding.getOperandCount() == 1;
1926 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1927 return typeFactory.createTypeWithNullability(
1928 typeFactory.createSqlType(SqlTypeName.INTEGER),
1929 opBinding.getOperandType(0).isNullable());
1936 SqlKind.OTHER_FUNCTION,
1939 OperandTypes.family(SqlTypeFamily.ANY),
1940 SqlFunctionCategory.SYSTEM);
1945 assert opBinding.getOperandCount() == 1;
1946 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1947 return typeFactory.createTypeWithNullability(
1948 typeFactory.createSqlType(SqlTypeName.INTEGER),
1949 opBinding.getOperandType(0).isNullable());
1956 SqlKind.OTHER_FUNCTION,
1959 OperandTypes.family(SqlTypeFamily.ANY),
1960 SqlFunctionCategory.SYSTEM);
1965 assert opBinding.getOperandCount() == 1;
1966 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1967 return typeFactory.createTypeWithNullability(
1968 typeFactory.createSqlType(SqlTypeName.INTEGER),
1969 opBinding.getOperandType(0).isNullable());
1976 SqlKind.OTHER_FUNCTION,
1979 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
1980 SqlFunctionCategory.SYSTEM);
1985 assert opBinding.getOperandCount() == 1;
1986 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1987 return typeFactory.createTypeWithNullability(
1988 typeFactory.createSqlType(SqlTypeName.INTEGER),
1989 opBinding.getOperandType(0).isNullable());
1996 SqlKind.OTHER_FUNCTION,
1999 OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
2000 SqlFunctionCategory.SYSTEM);
2005 assert opBinding.getOperandCount() == 2;
2006 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2007 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2013 super(
"ST_Centroid",
2014 SqlKind.OTHER_FUNCTION,
2017 OperandTypes.family(signature()),
2018 SqlFunctionCategory.SYSTEM);
2023 assert opBinding.getOperandCount() == 1;
2024 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2025 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2029 java.util.List<SqlTypeFamily> st_centroid_sig =
2030 new java.util.ArrayList<SqlTypeFamily>();
2031 st_centroid_sig.add(SqlTypeFamily.ANY);
2032 return st_centroid_sig;
2039 SqlKind.OTHER_FUNCTION,
2042 OperandTypes.family(signature()),
2043 SqlFunctionCategory.SYSTEM);
2048 assert opBinding.getOperandCount() == 2;
2049 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2050 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2054 java.util.List<SqlTypeFamily> st_buffer_sig =
2055 new java.util.ArrayList<SqlTypeFamily>();
2056 st_buffer_sig.add(SqlTypeFamily.ANY);
2057 st_buffer_sig.add(SqlTypeFamily.NUMERIC);
2058 return st_buffer_sig;
2064 super(
"ST_Intersection",
2065 SqlKind.OTHER_FUNCTION,
2068 OperandTypes.family(signature()),
2069 SqlFunctionCategory.SYSTEM);
2074 assert opBinding.getOperandCount() == 2;
2075 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2076 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2080 java.util.List<SqlTypeFamily> st_intersection_sig =
2081 new java.util.ArrayList<SqlTypeFamily>();
2082 st_intersection_sig.add(SqlTypeFamily.ANY);
2083 st_intersection_sig.add(SqlTypeFamily.ANY);
2084 return st_intersection_sig;
2091 SqlKind.OTHER_FUNCTION,
2094 OperandTypes.family(signature()),
2095 SqlFunctionCategory.SYSTEM);
2100 assert opBinding.getOperandCount() == 2;
2101 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2102 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2106 java.util.List<SqlTypeFamily> st_union_sig =
2107 new java.util.ArrayList<SqlTypeFamily>();
2108 st_union_sig.add(SqlTypeFamily.ANY);
2109 st_union_sig.add(SqlTypeFamily.ANY);
2110 return st_union_sig;
2116 super(
"ST_Difference",
2117 SqlKind.OTHER_FUNCTION,
2120 OperandTypes.family(signature()),
2121 SqlFunctionCategory.SYSTEM);
2126 assert opBinding.getOperandCount() == 2;
2127 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2128 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2132 java.util.List<SqlTypeFamily> st_difference_sig =
2133 new java.util.ArrayList<SqlTypeFamily>();
2134 st_difference_sig.add(SqlTypeFamily.ANY);
2135 st_difference_sig.add(SqlTypeFamily.ANY);
2136 return st_difference_sig;
2142 super(
"CastToGeography",
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.createSqlType(SqlTypeName.INTEGER);
2160 super(
"ENCODE_TEXT",
2161 SqlKind.OTHER_FUNCTION,
2164 OperandTypes.family(SqlTypeFamily.STRING),
2165 SqlFunctionCategory.SYSTEM);
2170 assert opBinding.getOperandCount() == 1;
2171 return opBinding.getOperandType(0);
2178 super(
"OFFSET_IN_FRAGMENT",
2179 SqlKind.OTHER_FUNCTION,
2182 OperandTypes.NILADIC,
2183 SqlFunctionCategory.SYSTEM);
2188 assert opBinding.getOperandCount() == 0;
2189 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2190 return typeFactory.createSqlType(SqlTypeName.BIGINT);
2196 super(
"APPROX_COUNT_DISTINCT",
2198 SqlKind.OTHER_FUNCTION,
2201 OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
2202 OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
2203 SqlFunctionCategory.SYSTEM,
2206 Optionality.FORBIDDEN);
2211 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2212 return typeFactory.createSqlType(SqlTypeName.BIGINT);
2218 super(
"APPROX_MEDIAN",
2220 SqlKind.OTHER_FUNCTION,
2223 OperandTypes.family(SqlTypeFamily.NUMERIC),
2224 SqlFunctionCategory.SYSTEM,
2227 Optionality.FORBIDDEN);
2232 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2233 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2239 super(
"APPROX_PERCENTILE",
2241 SqlKind.OTHER_FUNCTION,
2244 OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
2245 SqlFunctionCategory.SYSTEM,
2248 Optionality.FORBIDDEN);
2253 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2254 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2260 super(
"APPROX_QUANTILE",
2262 SqlKind.OTHER_FUNCTION,
2265 OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
2266 SqlFunctionCategory.SYSTEM,
2269 Optionality.FORBIDDEN);
2274 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2275 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2283 SqlKind.OTHER_FUNCTION,
2286 OperandTypes.family(SqlTypeFamily.NUMERIC),
2287 SqlFunctionCategory.SYSTEM);
2292 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2293 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2297 public static class Sample extends SqlAggFunction {
2301 SqlKind.OTHER_FUNCTION,
2305 SqlFunctionCategory.SYSTEM,
2308 Optionality.FORBIDDEN);
2313 return opBinding.getOperandType(0);
2320 super(
"LAST_SAMPLE",
2322 SqlKind.OTHER_FUNCTION,
2326 SqlFunctionCategory.SYSTEM,
2329 Optionality.FORBIDDEN);
2334 return opBinding.getOperandType(0);
2341 SqlKind.OTHER_FUNCTION,
2345 SqlFunctionCategory.SYSTEM);
2346 ret = sig.getSqlRet();
2347 arg_names = sig.getArgNames();
2357 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2358 return typeFactory.createTypeWithNullability(typeFactory.createSqlType(ret),
true);
2361 private final SqlTypeName
ret;
2368 SqlKind.OTHER_FUNCTION,
2372 SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION);
2373 arg_types = sig.toSqlSignature();
2374 outs = sig.getSqlOuts();
2375 out_names = sig.getOutNames();
2376 arg_names = sig.getArgNames();
2380 pretty_arg_names = sig.getPrettyArgNames();
2381 options = sig.getOptions();
2391 return pretty_arg_names;
2405 final Boolean has_names = this.pretty_arg_names != null
2406 && this.pretty_arg_names.size() == this.arg_types.size();
2407 final List<FunctionParameter> parameters =
new java.util.ArrayList<>();
2408 for (
int i = 0; i < this.arg_types.size(); i++) {
2409 final int arg_idx = i;
2410 parameters.add(
new FunctionParameter() {
2411 public int getOrdinal() {
2415 public String getName() {
2417 return pretty_arg_names.get(arg_idx);
2419 return "arg" + arg_idx;
2422 public RelDataType getType(RelDataTypeFactory typeFactory) {
2423 return arg_types.get(arg_idx).getDefaultConcreteType(typeFactory);
2426 public boolean isOptional() {
2436 return opBinding -> {
2437 FieldInfoBuilder ret = opBinding.getTypeFactory().builder();
2438 for (
int out_idx = 0; out_idx < outs.size(); ++out_idx) {
2439 ret = ret.add(out_names.get(out_idx), outs.get(out_idx));
2440 ret = ret.nullable(
true);
2448 System.out.println(msg);
2453 final Boolean debugMode =
false;
2454 Set<RelColumnMapping> s =
new HashSet<RelColumnMapping>();
2455 debugPrint(
"getNameAsId() -> " + getNameAsId() +
", arg_names=" + arg_names
2456 +
", out_names=" + out_names,
2458 if (
Integer.valueOf(options.getOrDefault(
"filter_table_function_transpose",
"0"))
2460 debugPrint(
"getNameAsId() -> " + getNameAsId(), debugMode);
2462 for (
int arg_idx = 0; arg_idx < arg_names.size(); ++arg_idx) {
2463 String arg_name = arg_names.get(arg_idx);
2465 int start = arg_name.indexOf(
"[");
2468 int end = arg_name.lastIndexOf(
"]");
2469 fields = arg_name.substring(start + 1, end)
2470 .replaceAll(
"\\s+",
"")
2473 fields =
new String[] {arg_name};
2475 debugPrint(
"fields=" + Arrays.toString(fields), debugMode);
2476 for (
int field_idx = 0; field_idx < fields.length; ++field_idx) {
2477 int out_idx = out_names.indexOf(fields[field_idx]);
2479 s.add(
new RelColumnMapping(out_idx, rel_idx, field_idx,
false));
2480 debugPrint(
"out_idx, arg_idx/rel_idx, field_idx=" + out_idx +
", " + arg_idx
2481 +
"/" + rel_idx +
", " + field_idx,
2491 private final List<SqlTypeName>
outs;
2504 super(
"HeavyDB_Geo_PolyBoundsPtr",
2505 SqlKind.OTHER_FUNCTION,
2508 OperandTypes.family(SqlTypeFamily.ANY),
2509 SqlFunctionCategory.SYSTEM);
2514 assert opBinding.getOperandCount() == 1;
2515 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2516 return typeFactory.createSqlType(SqlTypeName.BIGINT);
2522 super(
"HeavyDB_Geo_PolyRenderGroup",
2523 SqlKind.OTHER_FUNCTION,
2526 OperandTypes.family(SqlTypeFamily.ANY),
2527 SqlFunctionCategory.SYSTEM);
2532 assert opBinding.getOperandCount() == 1;
2533 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2534 return typeFactory.createSqlType(SqlTypeName.INTEGER);
2540 super(
"convert_meters_to_pixel_width",
2541 SqlKind.OTHER_FUNCTION,
2544 OperandTypes.family(SqlTypeFamily.NUMERIC,
2546 SqlTypeFamily.NUMERIC,
2547 SqlTypeFamily.NUMERIC,
2548 SqlTypeFamily.NUMERIC,
2549 SqlTypeFamily.NUMERIC),
2550 SqlFunctionCategory.SYSTEM);
2555 assert opBinding.getOperandCount() == 6;
2556 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2557 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2563 super(
"convert_meters_to_pixel_height",
2564 SqlKind.OTHER_FUNCTION,
2567 OperandTypes.family(SqlTypeFamily.NUMERIC,
2569 SqlTypeFamily.NUMERIC,
2570 SqlTypeFamily.NUMERIC,
2571 SqlTypeFamily.NUMERIC,
2572 SqlTypeFamily.NUMERIC),
2573 SqlFunctionCategory.SYSTEM);
2578 assert opBinding.getOperandCount() == 6;
2579 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2580 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2586 super(
"is_point_in_view",
2587 SqlKind.OTHER_FUNCTION,
2590 OperandTypes.family(SqlTypeFamily.ANY,
2591 SqlTypeFamily.NUMERIC,
2592 SqlTypeFamily.NUMERIC,
2593 SqlTypeFamily.NUMERIC,
2594 SqlTypeFamily.NUMERIC),
2595 SqlFunctionCategory.SYSTEM);
2600 assert opBinding.getOperandCount() == 5;
2601 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2602 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
2608 super(
"is_point_size_in_view",
2609 SqlKind.OTHER_FUNCTION,
2612 OperandTypes.family(SqlTypeFamily.ANY,
2613 SqlTypeFamily.NUMERIC,
2614 SqlTypeFamily.NUMERIC,
2615 SqlTypeFamily.NUMERIC,
2616 SqlTypeFamily.NUMERIC,
2617 SqlTypeFamily.NUMERIC),
2618 SqlFunctionCategory.SYSTEM);
2623 assert opBinding.getOperandCount() == 6;
2624 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2625 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
2631 super(
"usTIMESTAMP",
2632 SqlKind.OTHER_FUNCTION,
2635 OperandTypes.STRING,
2636 SqlFunctionCategory.SYSTEM);
2641 assert opBinding.getOperandCount() == 1;
2642 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2643 return typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 6);
2649 super(
"nsTIMESTAMP",
2650 SqlKind.OTHER_FUNCTION,
2653 OperandTypes.STRING,
2654 SqlFunctionCategory.SYSTEM);
2659 assert opBinding.getOperandCount() == 1;
2660 final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2661 return typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 9);
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)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > signature()
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()
EXTENSION_NOINLINE double ST_XMax(int8_t *coords, int64_t size, int32_t ic, int32_t isr, int32_t osr)
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)
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)
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)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RegexpSubstr(final String alias)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
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)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
convert_meters_to_pixel_height()
boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
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 getComponentType(RelDataTypeFactory typeFactory, List< RelDataType > argTypes)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > getSignatureFamilies()
void debugPrint(String msg, Boolean debugMode)
EXTENSION_NOINLINE double ST_YMin(int8_t *coords, int64_t size, int32_t ic, int32_t isr, int32_t osr)
static java.util.List< SqlTypeFamily > signature()
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)
HeavyDB_Geo_PolyRenderGroup()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
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)
EXTENSION_INLINE int32_t HeavyDB_Geo_PolyRenderGroup(int32_t render_group)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
HeavyDBSqlOperatorTable(SqlOperatorTable parentTable)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
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)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > signature()
static java.util.List< SqlTypeFamily > getSignatureFamilies()
convert_meters_to_pixel_width()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
final List< String > out_names
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()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
final List< String > arg_names
final List< SqlTypeFamily > arg_types
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()
final List< String > arg_names
RelDataType inferReturnType(SqlOperatorBinding opBinding)
List< String > getParamNames()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
Set< RelColumnMapping > getColumnMappings()
static void addUDF(HeavyDBSqlOperatorTable opTab, final Map< String, ExtensionFunction > extSigs)
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()
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)
final List< String > pretty_arg_names
static java.util.List< SqlTypeFamily > signature()
final List< SqlTypeName > outs
RelDataType inferReturnType(SqlOperatorBinding opBinding)
SqlCall createCall(@Nullable SqlLiteral functionQualifier, SqlParserPos pos,@Nullable SqlNode...operands)
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)
static final SqlArrayValueConstructorAllowingEmpty ARRAY_VALUE_CONSTRUCTOR
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > getSignatureFamilies()
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)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > signature()
LeftRightPad(final String name)