OmniSciDB  8a228a1076
MapDSqlOperatorTable.java
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.mapd.calcite.parser;
17 
18 import com.google.common.base.Predicate;
19 import com.google.common.collect.ImmutableList;
20 import com.google.common.collect.Multimap;
22 
23 import org.apache.calcite.rel.type.RelDataType;
24 import org.apache.calcite.rel.type.RelDataTypeFactory;
25 import org.apache.calcite.sql.SqlAggFunction;
26 import org.apache.calcite.sql.SqlCallBinding;
27 import org.apache.calcite.sql.SqlFunction;
28 import org.apache.calcite.sql.SqlFunctionCategory;
29 import org.apache.calcite.sql.SqlIdentifier;
30 import org.apache.calcite.sql.SqlKind;
31 import org.apache.calcite.sql.SqlOperator;
32 import org.apache.calcite.sql.SqlOperatorBinding;
33 import org.apache.calcite.sql.SqlOperatorTable;
34 import org.apache.calcite.sql.SqlSyntax;
35 import org.apache.calcite.sql.fun.SqlArrayValueConstructor;
36 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
37 import org.apache.calcite.sql.type.OperandTypes;
38 import org.apache.calcite.sql.type.SqlTypeFamily;
39 import org.apache.calcite.sql.type.SqlTypeName;
40 import org.apache.calcite.sql.util.ChainedSqlOperatorTable;
41 import org.apache.calcite.sql.util.ListSqlOperatorTable;
42 import org.apache.calcite.sql.util.ReflectiveSqlOperatorTable;
43 import org.apache.calcite.sql.validate.SqlNameMatcher;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46 
47 import java.lang.reflect.Field;
48 import java.util.HashSet;
49 import java.util.Iterator;
50 import java.util.List;
51 import java.util.Map;
52 
53 class CaseInsensitiveListSqlOperatorTable extends ListSqlOperatorTable {
54  @Override
55  public void lookupOperatorOverloads(SqlIdentifier opName,
56  SqlFunctionCategory category,
57  SqlSyntax syntax,
58  List<SqlOperator> operatorList,
59  SqlNameMatcher nameMatcher) {
60  for (SqlOperator operator : this.getOperatorList()) {
61  if (operator.getSyntax() != syntax) {
62  continue;
63  }
64  if (!opName.isSimple()
65  || !nameMatcher.matches(operator.getName(), opName.getSimple())) {
66  continue;
67  }
68  SqlFunctionCategory functionCategory;
69  if (operator instanceof SqlFunction) {
70  functionCategory = ((SqlFunction) operator).getFunctionType();
71  } else {
72  functionCategory = SqlFunctionCategory.SYSTEM;
73  }
74  if (category != functionCategory
75  && category != SqlFunctionCategory.USER_DEFINED_FUNCTION) {
76  continue;
77  }
78  operatorList.add(operator);
79  }
80  }
81 }
82 
87 public class MapDSqlOperatorTable extends ChainedSqlOperatorTable {
88  public static final SqlArrayValueConstructorAllowingEmpty ARRAY_VALUE_CONSTRUCTOR =
90 
91  static {
92  try {
93  // some nasty bit to remove the std APPROX_COUNT_DISTINCT function definition
94  {
95  Field f = ReflectiveSqlOperatorTable.class.getDeclaredField(
96  "caseSensitiveOperators");
97  f.setAccessible(true);
98  Multimap operators = (Multimap) f.get(SqlStdOperatorTable.instance());
99  for (Iterator i = operators.entries().iterator(); i.hasNext();) {
100  Map.Entry entry = (Map.Entry) i.next();
101  if (entry.getValue() == SqlStdOperatorTable.APPROX_COUNT_DISTINCT
102  || entry.getValue() == SqlStdOperatorTable.AVG
103  || entry.getValue() == SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR) {
104  i.remove();
105  }
106  }
107  }
108 
109  {
110  Field f = ReflectiveSqlOperatorTable.class.getDeclaredField(
111  "caseInsensitiveOperators");
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) {
119  i.remove();
120  }
121  }
122  }
123 
124  SqlStdOperatorTable.instance().register(ARRAY_VALUE_CONSTRUCTOR);
125 
126  } catch (Exception e) {
127  throw new RuntimeException(e);
128  }
129 
130  // register our approx count distinct against std table
131  // SqlStdOperatorTable.instance().register(new ApproxCountDistinct());
132  }
133 
134  final static Logger MAPDLOGGER = LoggerFactory.getLogger(MapDSqlOperatorTable.class);
135 
140  // ~ Instance fields --------------------------------------------------------
141  private final ListSqlOperatorTable listOpTab;
142 
143  // ~ Constructors -----------------------------------------------------------
144  public MapDSqlOperatorTable(SqlOperatorTable parentTable) {
145  super(ImmutableList.of(parentTable, new CaseInsensitiveListSqlOperatorTable()));
146  listOpTab = (ListSqlOperatorTable) tableList.get(1);
147  }
148 
149  // ~ Methods ----------------------------------------------------------------
155  public void addOperator(SqlOperator op) {
156  listOpTab.add(op);
157  }
158 
159  public static void addUDF(
160  MapDSqlOperatorTable opTab, final Map<String, ExtensionFunction> extSigs) {
161  // Don't use anonymous inner classes. They can't be instantiated
162  // using reflection when we are deserializing from JSON.
163  // opTab.addOperator(new RampFunction());
164  // opTab.addOperator(new DedupFunction());
165  opTab.addOperator(new RowCopier()); // UDTF prototype
166  opTab.addOperator(new MyUDFFunction());
167  opTab.addOperator(new PgUnnest());
168  opTab.addOperator(new Any());
169  opTab.addOperator(new All());
170  opTab.addOperator(new Now());
171  opTab.addOperator(new Datetime());
172  opTab.addOperator(new PgExtract());
173  opTab.addOperator(new Dateadd());
174  opTab.addOperator(new Datediff());
175  opTab.addOperator(new Datepart());
176  opTab.addOperator(new PgDateTrunc());
177  opTab.addOperator(new Length());
178  opTab.addOperator(new CharLength());
179  opTab.addOperator(new KeyForString());
180  opTab.addOperator(new SampleRatio());
181  opTab.addOperator(new ArrayLength());
182  opTab.addOperator(new PgILike());
183  opTab.addOperator(new RegexpLike());
184  opTab.addOperator(new Likely());
185  opTab.addOperator(new Unlikely());
186  opTab.addOperator(new Sign());
187  opTab.addOperator(new Truncate());
188  opTab.addOperator(new ST_IsEmpty());
189  opTab.addOperator(new ST_IsValid());
190  opTab.addOperator(new ST_Contains());
191  opTab.addOperator(new ST_Intersects());
192  opTab.addOperator(new ST_Overlaps());
193  opTab.addOperator(new ST_Disjoint());
194  opTab.addOperator(new ST_Within());
195  opTab.addOperator(new ST_DWithin());
196  opTab.addOperator(new ST_DFullyWithin());
197  opTab.addOperator(new ST_Distance());
198  opTab.addOperator(new ST_MaxDistance());
199  opTab.addOperator(new ST_GeogFromText());
200  opTab.addOperator(new ST_GeomFromText());
201  opTab.addOperator(new ST_Transform());
202  opTab.addOperator(new ST_X());
203  opTab.addOperator(new ST_Y());
204  opTab.addOperator(new ST_XMin());
205  opTab.addOperator(new ST_XMax());
206  opTab.addOperator(new ST_YMin());
207  opTab.addOperator(new ST_YMax());
208  opTab.addOperator(new ST_PointN());
209  opTab.addOperator(new ST_StartPoint());
210  opTab.addOperator(new ST_EndPoint());
211  opTab.addOperator(new ST_Length());
212  opTab.addOperator(new ST_Perimeter());
213  opTab.addOperator(new ST_Area());
214  opTab.addOperator(new ST_NPoints());
215  opTab.addOperator(new ST_NRings());
216  opTab.addOperator(new ST_SRID());
217  opTab.addOperator(new ST_SetSRID());
218  opTab.addOperator(new ST_Point());
219  opTab.addOperator(new ST_Centroid());
220  opTab.addOperator(new ST_Buffer());
221  opTab.addOperator(new ST_Intersection());
222  opTab.addOperator(new ST_Union());
223  opTab.addOperator(new ST_Difference());
224  opTab.addOperator(new CastToGeography());
225  opTab.addOperator(new OffsetInFragment());
226  opTab.addOperator(new ApproxCountDistinct());
227  opTab.addOperator(new MapDAvg());
228  opTab.addOperator(new Sample());
229  opTab.addOperator(new LastSample());
230  // MapD_Geo* are deprecated in place of the OmniSci_Geo_ varietals
231  opTab.addOperator(new MapD_GeoPolyBoundsPtr());
237  opTab.addOperator(new is_point_in_view());
238  opTab.addOperator(new is_point_size_in_view());
239  opTab.addOperator(new usTimestamp());
240  opTab.addOperator(new nsTimestamp());
241  if (extSigs == null) {
242  return;
243  }
244  HashSet<String> demangledNames = new HashSet<String>();
245  for (Map.Entry<String, ExtensionFunction> extSig : extSigs.entrySet()) {
246  final String demangledName = dropSuffix(extSig.getKey());
247  if (demangledNames.contains(demangledName)) {
248  continue;
249  }
250  demangledNames.add(demangledName);
251  opTab.addOperator(new ExtFunction(demangledName, extSig.getValue()));
252  }
253  }
254 
255  private static String dropSuffix(final String str) {
256  int suffix_idx = str.indexOf("__");
257  if (suffix_idx == -1) {
258  return str;
259  }
260  assert suffix_idx > 0;
261  return str.substring(0, suffix_idx);
262  }
263 
265  extends SqlArrayValueConstructor {
266  @Override
267  protected RelDataType getComponentType(
268  RelDataTypeFactory typeFactory, List<RelDataType> argTypes) {
269  if (argTypes.isEmpty()) {
270  return typeFactory.createSqlType(SqlTypeName.NULL);
271  }
272  return super.getComponentType(typeFactory, argTypes);
273  }
274 
275  @Override
276  public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
277  if (callBinding.operands().isEmpty()) {
278  return true;
279  }
280  return super.checkOperandTypes(callBinding, throwOnFailure);
281  }
282  }
283 
287  public static class RampFunction extends SqlFunction {
288  public RampFunction() {
289  super("RAMP",
290  SqlKind.OTHER_FUNCTION,
291  null,
292  null,
293  OperandTypes.NUMERIC,
294  SqlFunctionCategory.USER_DEFINED_FUNCTION);
295  }
296 
297  @Override
298  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
299  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
300  return typeFactory.builder().add("I", SqlTypeName.INTEGER).build();
301  }
302  }
303 
307  public static class DedupFunction extends SqlFunction {
308  public DedupFunction() {
309  super("DEDUP",
310  SqlKind.OTHER_FUNCTION,
311  null,
312  null,
313  OperandTypes.VARIADIC,
314  SqlFunctionCategory.USER_DEFINED_FUNCTION);
315  }
316 
317  @Override
318  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
319  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
320  return typeFactory.builder().add("NAME", SqlTypeName.VARCHAR, 1024).build();
321  }
322  }
323 
328  public static class MyUDFFunction extends SqlFunction {
329  public MyUDFFunction() {
330  super("MyUDF",
331  SqlKind.OTHER_FUNCTION,
332  null,
333  null,
334  OperandTypes.STRING_STRING,
335  SqlFunctionCategory.SYSTEM);
336  }
337 
338  @Override
339  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
340  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
341  return typeFactory.createSqlType(SqlTypeName.BIGINT);
342  }
343  }
344 
348  public static class RowCopier extends SqlFunction {
349  public RowCopier() {
350  super("ROW_COPIER",
351  SqlKind.OTHER_FUNCTION,
352  null,
353  null,
354  OperandTypes.family(signature()),
355  SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION);
356  }
357 
358  @Override
359  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
360  assert opBinding.getOperandCount() == 2;
361  return opBinding.getCursorOperand(0);
362  }
363 
364  private static java.util.List<SqlTypeFamily> signature() {
365  java.util.List<SqlTypeFamily> sig_family = new java.util.ArrayList<SqlTypeFamily>();
366  sig_family.add(SqlTypeFamily.CURSOR);
367  sig_family.add(SqlTypeFamily.ANY);
368  return sig_family;
369  }
370  }
371 
372  /* Postgres-style UNNEST */
373  public static class PgUnnest extends SqlFunction {
374  public PgUnnest() {
375  super("PG_UNNEST",
376  SqlKind.OTHER_FUNCTION,
377  null,
378  null,
379  OperandTypes.ARRAY,
380  SqlFunctionCategory.SYSTEM);
381  }
382 
383  @Override
384  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
385  assert opBinding.getOperandCount() == 1;
386  RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
387  assert elem_type != null;
388  return elem_type;
389  }
390  }
391 
392  /* ANY qualifier */
393  public static class Any extends SqlFunction {
394  public Any() {
395  super("PG_ANY",
396  SqlKind.OTHER_FUNCTION,
397  null,
398  null,
399  OperandTypes.ARRAY,
400  SqlFunctionCategory.SYSTEM);
401  }
402 
403  @Override
404  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
405  assert opBinding.getOperandCount() == 1;
406  RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
407  assert elem_type != null;
408  return elem_type;
409  }
410  }
411 
412  /* ALL qualifier */
413  public static class All extends SqlFunction {
414  public All() {
415  super("PG_ALL",
416  SqlKind.OTHER_FUNCTION,
417  null,
418  null,
419  OperandTypes.ARRAY,
420  SqlFunctionCategory.SYSTEM);
421  }
422 
423  @Override
424  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
425  assert opBinding.getOperandCount() == 1;
426  RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
427  assert elem_type != null;
428  return elem_type;
429  }
430  }
431 
432  /* NOW() */
433  public static class Now extends SqlFunction {
434  public Now() {
435  super("NOW",
436  SqlKind.OTHER_FUNCTION,
437  null,
438  null,
439  OperandTypes.NILADIC,
440  SqlFunctionCategory.SYSTEM);
441  }
442 
443  @Override
444  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
445  assert opBinding.getOperandCount() == 0;
446  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
447  return typeFactory.createSqlType(SqlTypeName.TIMESTAMP);
448  }
449  }
450 
451  /* DATETIME */
452  public static class Datetime extends SqlFunction {
453  public Datetime() {
454  super("DATETIME",
455  SqlKind.OTHER_FUNCTION,
456  null,
457  null,
458  OperandTypes.STRING,
459  SqlFunctionCategory.SYSTEM);
460  }
461 
462  @Override
463  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
464  assert opBinding.getOperandCount() == 1;
465  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
466  return typeFactory.createSqlType(
467  SqlTypeName.TIMESTAMP, opBinding.getOperandType(0).getPrecision());
468  }
469  }
470 
471  /* Postgres-style EXTRACT */
472  public static class PgExtract extends SqlFunction {
473  public PgExtract() {
474  super("PG_EXTRACT",
475  SqlKind.OTHER_FUNCTION,
476  null,
477  null,
478  OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
479  SqlFunctionCategory.SYSTEM);
480  }
481 
482  @Override
483  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
484  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
485  return typeFactory.createTypeWithNullability(
486  typeFactory.createSqlType(SqlTypeName.BIGINT),
487  opBinding.getOperandType(1).isNullable());
488  }
489  }
490 
491  public static class Datepart extends SqlFunction {
492  public Datepart() {
493  super("DATEPART",
494  SqlKind.OTHER_FUNCTION,
495  null,
496  null,
497  OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
498  SqlFunctionCategory.TIMEDATE);
499  }
500 
501  @Override
502  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
503  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
504  return typeFactory.createTypeWithNullability(
505  typeFactory.createSqlType(SqlTypeName.BIGINT),
506  opBinding.getOperandType(1).isNullable());
507  }
508  }
509 
510  public static class Dateadd extends SqlFunction {
511  public Dateadd() {
512  super("DATEADD",
513  SqlKind.OTHER_FUNCTION,
514  null,
515  null,
516  OperandTypes.family(SqlTypeFamily.STRING,
517  SqlTypeFamily.INTEGER,
518  SqlTypeFamily.DATETIME),
519  SqlFunctionCategory.TIMEDATE);
520  }
521 
522  @Override
523  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
524  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
525  return typeFactory.createTypeWithNullability(
526  typeFactory.createSqlType(
527  SqlTypeName.TIMESTAMP, opBinding.getOperandType(2).getPrecision()),
528  opBinding.getOperandType(2).isNullable());
529  }
530  }
531 
532  public static class Datediff extends SqlFunction {
533  public Datediff() {
534  super("DATEDIFF",
535  SqlKind.OTHER_FUNCTION,
536  null,
537  null,
538  OperandTypes.family(SqlTypeFamily.STRING,
539  SqlTypeFamily.DATETIME,
540  SqlTypeFamily.DATETIME),
541  SqlFunctionCategory.TIMEDATE);
542  }
543 
544  @Override
545  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
546  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
547  return typeFactory.createTypeWithNullability(
548  typeFactory.createSqlType(SqlTypeName.BIGINT),
549  opBinding.getOperandType(1).isNullable()
550  || opBinding.getOperandType(2).isNullable());
551  }
552  }
553 
554  /* Postgres-style DATE_TRUNC */
555  public static class PgDateTrunc extends SqlFunction {
556  public PgDateTrunc() {
557  super("PG_DATE_TRUNC",
558  SqlKind.OTHER_FUNCTION,
559  null,
560  null,
561  OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
562  SqlFunctionCategory.SYSTEM);
563  }
564 
565  @Override
566  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
567  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
568  return typeFactory.createTypeWithNullability(
569  typeFactory.createSqlType(
570  SqlTypeName.TIMESTAMP, opBinding.getOperandType(1).getPrecision()),
571  opBinding.getOperandType(1).isNullable());
572  }
573  }
574 
575  public static class Length extends SqlFunction {
576  public Length() {
577  super("LENGTH",
578  SqlKind.OTHER_FUNCTION,
579  null,
580  null,
581  OperandTypes.STRING,
582  SqlFunctionCategory.SYSTEM);
583  }
584 
585  @Override
586  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
587  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
588  return typeFactory.createSqlType(SqlTypeName.INTEGER);
589  }
590  }
591 
592  public static class CharLength extends SqlFunction {
593  public CharLength() {
594  super("CHAR_LENGTH",
595  SqlKind.OTHER_FUNCTION,
596  null,
597  null,
598  OperandTypes.STRING,
599  SqlFunctionCategory.SYSTEM);
600  }
601 
602  @Override
603  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
604  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
605  return typeFactory.createSqlType(SqlTypeName.INTEGER);
606  }
607  }
608 
609  public static class KeyForString extends SqlFunction {
610  public KeyForString() {
611  super("KEY_FOR_STRING",
612  SqlKind.OTHER_FUNCTION,
613  null,
614  null,
615  OperandTypes.STRING,
616  SqlFunctionCategory.SYSTEM);
617  }
618 
619  @Override
620  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
621  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
622  return typeFactory.createTypeWithNullability(
623  typeFactory.createSqlType(SqlTypeName.INTEGER),
624  opBinding.getOperandType(0).isNullable());
625  }
626  }
627 
628  public static class SampleRatio extends SqlFunction {
629  public SampleRatio() {
630  super("SAMPLE_RATIO",
631  SqlKind.OTHER_FUNCTION,
632  null,
633  null,
634  OperandTypes.family(signature()),
635  SqlFunctionCategory.SYSTEM);
636  }
637 
638  @Override
639  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
640  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
641  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
642  }
643 
644  private static java.util.List<SqlTypeFamily> signature() {
645  java.util.ArrayList<SqlTypeFamily> families =
646  new java.util.ArrayList<SqlTypeFamily>();
647  families.add(SqlTypeFamily.NUMERIC);
648  return families;
649  }
650  }
651 
652  public static class ArrayLength extends SqlFunction {
653  public ArrayLength() {
654  super("ARRAY_LENGTH",
655  SqlKind.OTHER_FUNCTION,
656  null,
657  null,
658  OperandTypes.ARRAY,
659  SqlFunctionCategory.SYSTEM);
660  }
661 
662  @Override
663  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
664  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
665  return typeFactory.createSqlType(SqlTypeName.INTEGER);
666  }
667  }
668 
669  public static class PgILike extends SqlFunction {
670  public PgILike() {
671  super("PG_ILIKE",
672  SqlKind.OTHER_FUNCTION,
673  null,
674  null,
675  OperandTypes.family(getSignatureFamilies(), new EscapeOptional()),
676  SqlFunctionCategory.SYSTEM);
677  }
678 
679  private static java.util.List<SqlTypeFamily> getSignatureFamilies() {
680  java.util.ArrayList<SqlTypeFamily> families =
681  new java.util.ArrayList<SqlTypeFamily>();
682  families.add(SqlTypeFamily.STRING);
683  families.add(SqlTypeFamily.STRING);
684  families.add(SqlTypeFamily.STRING);
685  return families;
686  }
687 
688  private static class EscapeOptional
689  implements java.util.function.Predicate<Integer>, Predicate<Integer> {
690  @Override
691  public boolean test(Integer t) {
692  return apply(t);
693  }
694 
695  @Override
696  public boolean apply(Integer t) {
697  return t == 2;
698  }
699  }
700 
701  @Override
702  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
703  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
704  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
705  }
706  }
707 
708  public static class RegexpLike extends SqlFunction {
709  public RegexpLike() {
710  super("REGEXP_LIKE",
711  SqlKind.OTHER_FUNCTION,
712  null,
713  null,
714  OperandTypes.family(getSignatureFamilies(), new EscapeOptional()),
715  SqlFunctionCategory.SYSTEM);
716  }
717 
718  private static java.util.List<SqlTypeFamily> getSignatureFamilies() {
719  java.util.ArrayList<SqlTypeFamily> families =
720  new java.util.ArrayList<SqlTypeFamily>();
721  families.add(SqlTypeFamily.STRING);
722  families.add(SqlTypeFamily.STRING);
723  families.add(SqlTypeFamily.STRING);
724  return families;
725  }
726 
727  private static class EscapeOptional
728  implements java.util.function.Predicate<Integer>, Predicate<Integer> {
729  @Override
730  public boolean test(Integer t) {
731  return apply(t);
732  }
733 
734  public boolean apply(Integer t) {
735  return t == 2;
736  }
737  }
738 
739  @Override
740  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
741  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
742  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
743  }
744  }
745 
746  public static class Likely extends SqlFunction {
747  public Likely() {
748  super("LIKELY",
749  SqlKind.OTHER_FUNCTION,
750  null,
751  null,
752  OperandTypes.BOOLEAN,
753  SqlFunctionCategory.SYSTEM);
754  }
755 
756  @Override
757  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
758  return opBinding.getOperandType(0);
759  }
760  }
761 
762  public static class Unlikely extends SqlFunction {
763  public Unlikely() {
764  super("UNLIKELY",
765  SqlKind.OTHER_FUNCTION,
766  null,
767  null,
768  OperandTypes.BOOLEAN,
769  SqlFunctionCategory.SYSTEM);
770  }
771 
772  @Override
773  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
774  return opBinding.getOperandType(0);
775  }
776  }
777 
778  public static class Sign extends SqlFunction {
779  public Sign() {
780  super("SIGN",
781  SqlKind.OTHER_FUNCTION,
782  null,
783  null,
784  OperandTypes.NUMERIC,
785  SqlFunctionCategory.NUMERIC);
786  }
787 
788  @Override
789  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
790  return opBinding.getOperandType(0);
791  }
792  }
793 
794  static class Truncate extends SqlFunction {
796  super("TRUNCATE",
797  SqlKind.OTHER_FUNCTION,
798  null,
799  null,
800  OperandTypes.family(signature()),
801  SqlFunctionCategory.NUMERIC);
802  }
803 
804  @Override
805  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
806  assert opBinding.getOperandCount() == 2;
807  return opBinding.getOperandType(0);
808  }
809 
810  private static java.util.List<SqlTypeFamily> signature() {
811  java.util.List<SqlTypeFamily> truncate_sig =
812  new java.util.ArrayList<SqlTypeFamily>();
813  truncate_sig.add(SqlTypeFamily.NUMERIC);
814  truncate_sig.add(SqlTypeFamily.INTEGER);
815  return truncate_sig;
816  }
817  }
818 
819  static class ST_IsEmpty extends SqlFunction {
821  super("ST_IsEmpty",
822  SqlKind.OTHER_FUNCTION,
823  null,
824  null,
825  OperandTypes.family(signature()),
826  SqlFunctionCategory.SYSTEM);
827  }
828 
829  @Override
830  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
831  assert opBinding.getOperandCount() == 1;
832  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
833  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
834  }
835 
836  private static java.util.List<SqlTypeFamily> signature() {
837  java.util.List<SqlTypeFamily> st_isempty_sig =
838  new java.util.ArrayList<SqlTypeFamily>();
839  st_isempty_sig.add(SqlTypeFamily.ANY);
840  return st_isempty_sig;
841  }
842  }
843 
844  static class ST_IsValid extends SqlFunction {
846  super("ST_IsValid",
847  SqlKind.OTHER_FUNCTION,
848  null,
849  null,
850  OperandTypes.family(signature()),
851  SqlFunctionCategory.SYSTEM);
852  }
853 
854  @Override
855  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
856  assert opBinding.getOperandCount() == 1;
857  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
858  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
859  }
860 
861  private static java.util.List<SqlTypeFamily> signature() {
862  java.util.List<SqlTypeFamily> st_isvalid_sig =
863  new java.util.ArrayList<SqlTypeFamily>();
864  st_isvalid_sig.add(SqlTypeFamily.ANY);
865  return st_isvalid_sig;
866  }
867  }
868 
869  static class ST_Contains extends SqlFunction {
871  super("ST_Contains",
872  SqlKind.OTHER_FUNCTION,
873  null,
874  null,
875  OperandTypes.family(signature()),
876  SqlFunctionCategory.SYSTEM);
877  }
878 
879  @Override
880  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
881  assert opBinding.getOperandCount() == 2;
882  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
883  return typeFactory.createTypeWithNullability(
884  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
885  opBinding.getOperandType(0).isNullable()
886  || opBinding.getOperandType(1).isNullable());
887  }
888 
889  private static java.util.List<SqlTypeFamily> signature() {
890  java.util.List<SqlTypeFamily> st_contains_sig =
891  new java.util.ArrayList<SqlTypeFamily>();
892  st_contains_sig.add(SqlTypeFamily.ANY);
893  st_contains_sig.add(SqlTypeFamily.ANY);
894  return st_contains_sig;
895  }
896  }
897 
898  static class ST_Intersects extends SqlFunction {
900  super("ST_Intersects",
901  SqlKind.OTHER_FUNCTION,
902  null,
903  null,
904  OperandTypes.family(signature()),
905  SqlFunctionCategory.SYSTEM);
906  }
907 
908  @Override
909  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
910  assert opBinding.getOperandCount() == 2;
911  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
912  return typeFactory.createTypeWithNullability(
913  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
914  opBinding.getOperandType(0).isNullable()
915  || opBinding.getOperandType(1).isNullable());
916  }
917 
918  private static java.util.List<SqlTypeFamily> signature() {
919  java.util.List<SqlTypeFamily> st_intersects_sig =
920  new java.util.ArrayList<SqlTypeFamily>();
921  st_intersects_sig.add(SqlTypeFamily.ANY);
922  st_intersects_sig.add(SqlTypeFamily.ANY);
923  return st_intersects_sig;
924  }
925  }
926 
927  static class ST_Overlaps extends SqlFunction {
929  super("ST_Overlaps",
930  SqlKind.OTHER_FUNCTION,
931  null,
932  null,
933  OperandTypes.family(signature()),
934  SqlFunctionCategory.SYSTEM);
935  }
936 
937  @Override
938  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
939  assert opBinding.getOperandCount() == 2;
940  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
941  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
942  }
943 
944  private static java.util.List<SqlTypeFamily> signature() {
945  java.util.List<SqlTypeFamily> st_overlaps_sig =
946  new java.util.ArrayList<SqlTypeFamily>();
947  st_overlaps_sig.add(SqlTypeFamily.ANY);
948  st_overlaps_sig.add(SqlTypeFamily.ANY);
949  return st_overlaps_sig;
950  }
951  }
952 
953  static class ST_Disjoint extends SqlFunction {
955  super("ST_Disjoint",
956  SqlKind.OTHER_FUNCTION,
957  null,
958  null,
959  OperandTypes.family(signature()),
960  SqlFunctionCategory.SYSTEM);
961  }
962 
963  @Override
964  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
965  assert opBinding.getOperandCount() == 2;
966  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
967  return typeFactory.createTypeWithNullability(
968  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
969  opBinding.getOperandType(0).isNullable()
970  || opBinding.getOperandType(1).isNullable());
971  }
972 
973  private static java.util.List<SqlTypeFamily> signature() {
974  java.util.List<SqlTypeFamily> st_disjoint_sig =
975  new java.util.ArrayList<SqlTypeFamily>();
976  st_disjoint_sig.add(SqlTypeFamily.ANY);
977  st_disjoint_sig.add(SqlTypeFamily.ANY);
978  return st_disjoint_sig;
979  }
980  }
981 
982  static class ST_Within extends SqlFunction {
984  super("ST_Within",
985  SqlKind.OTHER_FUNCTION,
986  null,
987  null,
988  OperandTypes.family(signature()),
989  SqlFunctionCategory.SYSTEM);
990  }
991 
992  @Override
993  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
994  assert opBinding.getOperandCount() == 2;
995  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
996  return typeFactory.createTypeWithNullability(
997  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
998  opBinding.getOperandType(0).isNullable()
999  || opBinding.getOperandType(1).isNullable());
1000  }
1001 
1002  private static java.util.List<SqlTypeFamily> signature() {
1003  java.util.List<SqlTypeFamily> st_within_sig =
1004  new java.util.ArrayList<SqlTypeFamily>();
1005  st_within_sig.add(SqlTypeFamily.ANY);
1006  st_within_sig.add(SqlTypeFamily.ANY);
1007  return st_within_sig;
1008  }
1009  }
1010 
1011  static class ST_DWithin extends SqlFunction {
1013  super("ST_DWithin",
1014  SqlKind.OTHER_FUNCTION,
1015  null,
1016  null,
1017  OperandTypes.family(signature()),
1018  SqlFunctionCategory.SYSTEM);
1019  }
1020 
1021  @Override
1022  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1023  assert opBinding.getOperandCount() == 3;
1024  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1025  return typeFactory.createTypeWithNullability(
1026  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1027  opBinding.getOperandType(0).isNullable()
1028  || opBinding.getOperandType(1).isNullable()
1029  || opBinding.getOperandType(2).isNullable());
1030  }
1031 
1032  private static java.util.List<SqlTypeFamily> signature() {
1033  java.util.List<SqlTypeFamily> st_dwithin_sig =
1034  new java.util.ArrayList<SqlTypeFamily>();
1035  st_dwithin_sig.add(SqlTypeFamily.ANY);
1036  st_dwithin_sig.add(SqlTypeFamily.ANY);
1037  st_dwithin_sig.add(SqlTypeFamily.NUMERIC);
1038  return st_dwithin_sig;
1039  }
1040  }
1041 
1042  static class ST_DFullyWithin extends SqlFunction {
1044  super("ST_DFullyWithin",
1045  SqlKind.OTHER_FUNCTION,
1046  null,
1047  null,
1048  OperandTypes.family(signature()),
1049  SqlFunctionCategory.SYSTEM);
1050  }
1051 
1052  @Override
1053  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1054  assert opBinding.getOperandCount() == 3;
1055  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1056  return typeFactory.createTypeWithNullability(
1057  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1058  opBinding.getOperandType(0).isNullable()
1059  || opBinding.getOperandType(1).isNullable()
1060  || opBinding.getOperandType(2).isNullable());
1061  }
1062 
1063  private static java.util.List<SqlTypeFamily> signature() {
1064  java.util.List<SqlTypeFamily> st_dwithin_sig =
1065  new java.util.ArrayList<SqlTypeFamily>();
1066  st_dwithin_sig.add(SqlTypeFamily.ANY);
1067  st_dwithin_sig.add(SqlTypeFamily.ANY);
1068  st_dwithin_sig.add(SqlTypeFamily.NUMERIC);
1069  return st_dwithin_sig;
1070  }
1071  }
1072 
1073  static class ST_Distance extends SqlFunction {
1075  super("ST_Distance",
1076  SqlKind.OTHER_FUNCTION,
1077  null,
1078  null,
1079  OperandTypes.family(signature()),
1080  SqlFunctionCategory.SYSTEM);
1081  }
1082 
1083  @Override
1084  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1085  assert opBinding.getOperandCount() == 2;
1086  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1087  return typeFactory.createTypeWithNullability(
1088  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1089  opBinding.getOperandType(0).isNullable()
1090  || opBinding.getOperandType(1).isNullable());
1091  }
1092 
1093  private static java.util.List<SqlTypeFamily> signature() {
1094  java.util.List<SqlTypeFamily> st_distance_sig =
1095  new java.util.ArrayList<SqlTypeFamily>();
1096  st_distance_sig.add(SqlTypeFamily.ANY);
1097  st_distance_sig.add(SqlTypeFamily.ANY);
1098  return st_distance_sig;
1099  }
1100  }
1101 
1102  static class ST_MaxDistance extends SqlFunction {
1104  super("ST_MaxDistance",
1105  SqlKind.OTHER_FUNCTION,
1106  null,
1107  null,
1108  OperandTypes.family(signature()),
1109  SqlFunctionCategory.SYSTEM);
1110  }
1111 
1112  @Override
1113  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1114  assert opBinding.getOperandCount() == 2;
1115  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1116  return typeFactory.createTypeWithNullability(
1117  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1118  opBinding.getOperandType(0).isNullable()
1119  || opBinding.getOperandType(1).isNullable());
1120  }
1121 
1122  private static java.util.List<SqlTypeFamily> signature() {
1123  java.util.List<SqlTypeFamily> st_maxdistance_sig =
1124  new java.util.ArrayList<SqlTypeFamily>();
1125  st_maxdistance_sig.add(SqlTypeFamily.ANY);
1126  st_maxdistance_sig.add(SqlTypeFamily.ANY);
1127  return st_maxdistance_sig;
1128  }
1129  }
1130 
1131  static class ST_GeogFromText extends SqlFunction {
1133  super("ST_GeogFromText",
1134  SqlKind.OTHER_FUNCTION,
1135  null,
1136  null,
1137  OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
1138  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
1139  SqlFunctionCategory.SYSTEM);
1140  }
1141 
1142  @Override
1143  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1144  assert opBinding.getOperandCount() == 1;
1145  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1146  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1147  }
1148  }
1149 
1150  static class ST_GeomFromText extends SqlFunction {
1152  super("ST_GeomFromText",
1153  SqlKind.OTHER_FUNCTION,
1154  null,
1155  null,
1156  OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
1157  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
1158  SqlFunctionCategory.SYSTEM);
1159  }
1160 
1161  @Override
1162  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1163  assert opBinding.getOperandCount() == 1;
1164  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1165  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1166  }
1167  }
1168 
1169  static class ST_Transform extends SqlFunction {
1171  super("ST_Transform",
1172  SqlKind.OTHER_FUNCTION,
1173  null,
1174  null,
1175  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
1176  SqlFunctionCategory.SYSTEM);
1177  }
1178 
1179  @Override
1180  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1181  assert opBinding.getOperandCount() == 1;
1182  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1183  return typeFactory.createTypeWithNullability(
1184  typeFactory.createSqlType(SqlTypeName.INTEGER),
1185  opBinding.getOperandType(0).isNullable());
1186  }
1187  }
1188 
1189  static class ST_X extends SqlFunction {
1190  ST_X() {
1191  super("ST_X",
1192  SqlKind.OTHER_FUNCTION,
1193  null,
1194  null,
1195  OperandTypes.family(SqlTypeFamily.ANY),
1196  SqlFunctionCategory.SYSTEM);
1197  }
1198 
1199  @Override
1200  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1201  assert opBinding.getOperandCount() == 1;
1202  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1203  return typeFactory.createTypeWithNullability(
1204  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1205  opBinding.getOperandType(0).isNullable());
1206  }
1207  }
1208 
1209  static class ST_Y extends SqlFunction {
1210  ST_Y() {
1211  super("ST_Y",
1212  SqlKind.OTHER_FUNCTION,
1213  null,
1214  null,
1215  OperandTypes.family(SqlTypeFamily.ANY),
1216  SqlFunctionCategory.SYSTEM);
1217  }
1218 
1219  @Override
1220  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1221  assert opBinding.getOperandCount() == 1;
1222  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1223  return typeFactory.createTypeWithNullability(
1224  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1225  opBinding.getOperandType(0).isNullable());
1226  }
1227  }
1228 
1229  static class ST_XMin extends SqlFunction {
1231  super("ST_XMin",
1232  SqlKind.OTHER_FUNCTION,
1233  null,
1234  null,
1235  OperandTypes.family(SqlTypeFamily.ANY),
1236  SqlFunctionCategory.SYSTEM);
1237  }
1238 
1239  @Override
1240  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1241  assert opBinding.getOperandCount() == 1;
1242  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1243  return typeFactory.createTypeWithNullability(
1244  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1245  opBinding.getOperandType(0).isNullable());
1246  }
1247  }
1248 
1249  static class ST_XMax extends SqlFunction {
1251  super("ST_XMax",
1252  SqlKind.OTHER_FUNCTION,
1253  null,
1254  null,
1255  OperandTypes.family(SqlTypeFamily.ANY),
1256  SqlFunctionCategory.SYSTEM);
1257  }
1258 
1259  @Override
1260  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1261  assert opBinding.getOperandCount() == 1;
1262  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1263  return typeFactory.createTypeWithNullability(
1264  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1265  opBinding.getOperandType(0).isNullable());
1266  }
1267  }
1268 
1269  static class ST_YMin extends SqlFunction {
1271  super("ST_YMin",
1272  SqlKind.OTHER_FUNCTION,
1273  null,
1274  null,
1275  OperandTypes.family(SqlTypeFamily.ANY),
1276  SqlFunctionCategory.SYSTEM);
1277  }
1278 
1279  @Override
1280  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1281  assert opBinding.getOperandCount() == 1;
1282  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1283  return typeFactory.createTypeWithNullability(
1284  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1285  opBinding.getOperandType(0).isNullable());
1286  }
1287  }
1288 
1289  static class ST_YMax extends SqlFunction {
1291  super("ST_YMax",
1292  SqlKind.OTHER_FUNCTION,
1293  null,
1294  null,
1295  OperandTypes.family(SqlTypeFamily.ANY),
1296  SqlFunctionCategory.SYSTEM);
1297  }
1298 
1299  @Override
1300  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1301  assert opBinding.getOperandCount() == 1;
1302  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1303  return typeFactory.createTypeWithNullability(
1304  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1305  opBinding.getOperandType(0).isNullable());
1306  }
1307  }
1308 
1309  static class ST_PointN extends SqlFunction {
1311  super("ST_PointN",
1312  SqlKind.OTHER_FUNCTION,
1313  null,
1314  null,
1315  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
1316  SqlFunctionCategory.SYSTEM);
1317  }
1318 
1319  @Override
1320  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1321  assert opBinding.getOperandCount() == 1;
1322  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1323  return typeFactory.createTypeWithNullability(
1324  typeFactory.createSqlType(SqlTypeName.INTEGER),
1325  opBinding.getOperandType(0).isNullable());
1326  }
1327  }
1328 
1329  static class ST_EndPoint extends SqlFunction {
1331  super("ST_EndPoint",
1332  SqlKind.OTHER_FUNCTION,
1333  null,
1334  null,
1335  OperandTypes.family(SqlTypeFamily.ANY),
1336  SqlFunctionCategory.SYSTEM);
1337  }
1338 
1339  @Override
1340  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1341  assert opBinding.getOperandCount() == 1;
1342  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1343  return typeFactory.createTypeWithNullability(
1344  typeFactory.createSqlType(SqlTypeName.INTEGER),
1345  opBinding.getOperandType(0).isNullable());
1346  }
1347  }
1348 
1349  static class ST_StartPoint extends SqlFunction {
1351  super("ST_StartPoint",
1352  SqlKind.OTHER_FUNCTION,
1353  null,
1354  null,
1355  OperandTypes.family(SqlTypeFamily.ANY),
1356  SqlFunctionCategory.SYSTEM);
1357  }
1358 
1359  @Override
1360  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1361  assert opBinding.getOperandCount() == 1;
1362  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1363  return typeFactory.createTypeWithNullability(
1364  typeFactory.createSqlType(SqlTypeName.INTEGER),
1365  opBinding.getOperandType(0).isNullable());
1366  }
1367  }
1368 
1369  static class ST_Length extends SqlFunction {
1371  super("ST_Length",
1372  SqlKind.OTHER_FUNCTION,
1373  null,
1374  null,
1375  OperandTypes.family(SqlTypeFamily.ANY),
1376  SqlFunctionCategory.SYSTEM);
1377  }
1378 
1379  @Override
1380  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1381  assert opBinding.getOperandCount() == 1;
1382  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1383  return typeFactory.createTypeWithNullability(
1384  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1385  opBinding.getOperandType(0).isNullable());
1386  }
1387  }
1388 
1389  static class ST_Perimeter extends SqlFunction {
1391  super("ST_Perimeter",
1392  SqlKind.OTHER_FUNCTION,
1393  null,
1394  null,
1395  OperandTypes.family(SqlTypeFamily.ANY),
1396  SqlFunctionCategory.SYSTEM);
1397  }
1398 
1399  @Override
1400  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1401  assert opBinding.getOperandCount() == 1;
1402  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1403  return typeFactory.createTypeWithNullability(
1404  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1405  opBinding.getOperandType(0).isNullable());
1406  }
1407  }
1408 
1409  static class ST_Area extends SqlFunction {
1411  super("ST_Area",
1412  SqlKind.OTHER_FUNCTION,
1413  null,
1414  null,
1415  OperandTypes.family(SqlTypeFamily.ANY),
1416  SqlFunctionCategory.SYSTEM);
1417  }
1418 
1419  @Override
1420  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1421  assert opBinding.getOperandCount() == 1;
1422  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1423  return typeFactory.createTypeWithNullability(
1424  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1425  opBinding.getOperandType(0).isNullable());
1426  }
1427  }
1428 
1429  static class ST_NPoints extends SqlFunction {
1431  super("ST_NPoints",
1432  SqlKind.OTHER_FUNCTION,
1433  null,
1434  null,
1435  OperandTypes.family(SqlTypeFamily.ANY),
1436  SqlFunctionCategory.SYSTEM);
1437  }
1438 
1439  @Override
1440  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1441  assert opBinding.getOperandCount() == 1;
1442  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1443  return typeFactory.createTypeWithNullability(
1444  typeFactory.createSqlType(SqlTypeName.INTEGER),
1445  opBinding.getOperandType(0).isNullable());
1446  }
1447  }
1448 
1449  static class ST_NRings extends SqlFunction {
1451  super("ST_NRings",
1452  SqlKind.OTHER_FUNCTION,
1453  null,
1454  null,
1455  OperandTypes.family(SqlTypeFamily.ANY),
1456  SqlFunctionCategory.SYSTEM);
1457  }
1458 
1459  @Override
1460  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1461  assert opBinding.getOperandCount() == 1;
1462  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1463  return typeFactory.createTypeWithNullability(
1464  typeFactory.createSqlType(SqlTypeName.INTEGER),
1465  opBinding.getOperandType(0).isNullable());
1466  }
1467  }
1468 
1469  static class ST_SRID extends SqlFunction {
1471  super("ST_SRID",
1472  SqlKind.OTHER_FUNCTION,
1473  null,
1474  null,
1475  OperandTypes.family(SqlTypeFamily.ANY),
1476  SqlFunctionCategory.SYSTEM);
1477  }
1478 
1479  @Override
1480  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1481  assert opBinding.getOperandCount() == 1;
1482  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1483  return typeFactory.createTypeWithNullability(
1484  typeFactory.createSqlType(SqlTypeName.INTEGER),
1485  opBinding.getOperandType(0).isNullable());
1486  }
1487  }
1488 
1489  static class ST_SetSRID extends SqlFunction {
1491  super("ST_SetSRID",
1492  SqlKind.OTHER_FUNCTION,
1493  null,
1494  null,
1495  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
1496  SqlFunctionCategory.SYSTEM);
1497  }
1498 
1499  @Override
1500  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1501  assert opBinding.getOperandCount() == 1;
1502  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1503  return typeFactory.createTypeWithNullability(
1504  typeFactory.createSqlType(SqlTypeName.INTEGER),
1505  opBinding.getOperandType(0).isNullable());
1506  }
1507  }
1508 
1509  static class ST_Point extends SqlFunction {
1511  super("ST_Point",
1512  SqlKind.OTHER_FUNCTION,
1513  null,
1514  null,
1515  OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
1516  SqlFunctionCategory.SYSTEM);
1517  }
1518 
1519  @Override
1520  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1521  assert opBinding.getOperandCount() == 2;
1522  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1523  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1524  }
1525  }
1526 
1527  static class ST_Centroid extends SqlFunction {
1529  super("ST_Centroid",
1530  SqlKind.OTHER_FUNCTION,
1531  null,
1532  null,
1533  OperandTypes.family(signature()),
1534  SqlFunctionCategory.SYSTEM);
1535  }
1536 
1537  @Override
1538  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1539  assert opBinding.getOperandCount() == 1;
1540  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1541  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1542  }
1543 
1544  private static java.util.List<SqlTypeFamily> signature() {
1545  java.util.List<SqlTypeFamily> st_centroid_sig =
1546  new java.util.ArrayList<SqlTypeFamily>();
1547  st_centroid_sig.add(SqlTypeFamily.ANY);
1548  return st_centroid_sig;
1549  }
1550  }
1551 
1552  static class ST_Buffer extends SqlFunction {
1554  super("ST_Buffer",
1555  SqlKind.OTHER_FUNCTION,
1556  null,
1557  null,
1558  OperandTypes.family(signature()),
1559  SqlFunctionCategory.SYSTEM);
1560  }
1561 
1562  @Override
1563  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1564  assert opBinding.getOperandCount() == 2;
1565  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1566  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1567  }
1568 
1569  private static java.util.List<SqlTypeFamily> signature() {
1570  java.util.List<SqlTypeFamily> st_buffer_sig =
1571  new java.util.ArrayList<SqlTypeFamily>();
1572  st_buffer_sig.add(SqlTypeFamily.ANY);
1573  st_buffer_sig.add(SqlTypeFamily.NUMERIC);
1574  return st_buffer_sig;
1575  }
1576  }
1577 
1578  static class ST_Intersection extends SqlFunction {
1580  super("ST_Intersection",
1581  SqlKind.OTHER_FUNCTION,
1582  null,
1583  null,
1584  OperandTypes.family(signature()),
1585  SqlFunctionCategory.SYSTEM);
1586  }
1587 
1588  @Override
1589  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1590  assert opBinding.getOperandCount() == 2;
1591  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1592  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1593  }
1594 
1595  private static java.util.List<SqlTypeFamily> signature() {
1596  java.util.List<SqlTypeFamily> st_intersection_sig =
1597  new java.util.ArrayList<SqlTypeFamily>();
1598  st_intersection_sig.add(SqlTypeFamily.ANY);
1599  st_intersection_sig.add(SqlTypeFamily.ANY);
1600  return st_intersection_sig;
1601  }
1602  }
1603 
1604  static class ST_Union extends SqlFunction {
1606  super("ST_Union",
1607  SqlKind.OTHER_FUNCTION,
1608  null,
1609  null,
1610  OperandTypes.family(signature()),
1611  SqlFunctionCategory.SYSTEM);
1612  }
1613 
1614  @Override
1615  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1616  assert opBinding.getOperandCount() == 2;
1617  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1618  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1619  }
1620 
1621  private static java.util.List<SqlTypeFamily> signature() {
1622  java.util.List<SqlTypeFamily> st_union_sig =
1623  new java.util.ArrayList<SqlTypeFamily>();
1624  st_union_sig.add(SqlTypeFamily.ANY);
1625  st_union_sig.add(SqlTypeFamily.ANY);
1626  return st_union_sig;
1627  }
1628  }
1629 
1630  static class ST_Difference extends SqlFunction {
1632  super("ST_Difference",
1633  SqlKind.OTHER_FUNCTION,
1634  null,
1635  null,
1636  OperandTypes.family(signature()),
1637  SqlFunctionCategory.SYSTEM);
1638  }
1639 
1640  @Override
1641  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1642  assert opBinding.getOperandCount() == 2;
1643  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1644  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1645  }
1646 
1647  private static java.util.List<SqlTypeFamily> signature() {
1648  java.util.List<SqlTypeFamily> st_difference_sig =
1649  new java.util.ArrayList<SqlTypeFamily>();
1650  st_difference_sig.add(SqlTypeFamily.ANY);
1651  st_difference_sig.add(SqlTypeFamily.ANY);
1652  return st_difference_sig;
1653  }
1654  }
1655 
1656  static class CastToGeography extends SqlFunction {
1658  super("CastToGeography",
1659  SqlKind.OTHER_FUNCTION,
1660  null,
1661  null,
1662  OperandTypes.family(SqlTypeFamily.ANY),
1663  SqlFunctionCategory.SYSTEM);
1664  }
1665 
1666  @Override
1667  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1668  assert opBinding.getOperandCount() == 1;
1669  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1670  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1671  }
1672  }
1673 
1674  /* OFFSET_IN_FRAGMENT() */
1675  public static class OffsetInFragment extends SqlFunction {
1676  public OffsetInFragment() {
1677  super("OFFSET_IN_FRAGMENT",
1678  SqlKind.OTHER_FUNCTION,
1679  null,
1680  null,
1681  OperandTypes.NILADIC,
1682  SqlFunctionCategory.SYSTEM);
1683  }
1684 
1685  @Override
1686  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1687  assert opBinding.getOperandCount() == 0;
1688  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1689  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1690  }
1691  }
1692 
1693  static class ApproxCountDistinct extends SqlAggFunction {
1695  super("APPROX_COUNT_DISTINCT",
1696  null,
1697  SqlKind.OTHER_FUNCTION,
1698  null,
1699  null,
1700  OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
1701  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
1702  SqlFunctionCategory.SYSTEM);
1703  }
1704 
1705  @Override
1706  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1707  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1708  return typeFactory.createSqlType(SqlTypeName.BIGINT);
1709  }
1710  }
1711 
1712  static class MapDAvg extends SqlAggFunction {
1714  super("AVG",
1715  null,
1716  SqlKind.OTHER_FUNCTION,
1717  null,
1718  null,
1719  OperandTypes.family(SqlTypeFamily.NUMERIC),
1720  SqlFunctionCategory.SYSTEM);
1721  }
1722 
1723  @Override
1724  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1725  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1726  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
1727  }
1728  }
1729 
1730  public static class Sample extends SqlAggFunction {
1731  public Sample() {
1732  super("SAMPLE",
1733  SqlKind.OTHER_FUNCTION,
1734  null,
1735  null,
1736  OperandTypes.ANY,
1737  SqlFunctionCategory.SYSTEM);
1738  }
1739 
1740  @Override
1741  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1742  return opBinding.getOperandType(0);
1743  }
1744  }
1745 
1746  // for backwards compatibility
1747  public static class LastSample extends SqlAggFunction {
1748  public LastSample() {
1749  super("LAST_SAMPLE",
1750  SqlKind.OTHER_FUNCTION,
1751  null,
1752  null,
1753  OperandTypes.ANY,
1754  SqlFunctionCategory.SYSTEM);
1755  }
1756 
1757  @Override
1758  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1759  return opBinding.getOperandType(0);
1760  }
1761  }
1762 
1763  static class ExtFunction extends SqlFunction {
1764  ExtFunction(final String name, final ExtensionFunction sig) {
1765  super(name,
1766  SqlKind.OTHER_FUNCTION,
1767  null,
1768  null,
1769  OperandTypes.family(sig.toSqlSignature()),
1770  sig.isRowUdf() ? SqlFunctionCategory.SYSTEM
1771  : SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION);
1772  isRowUdf = sig.isRowUdf();
1773  if (isRowUdf) {
1774  ret = sig.getSqlRet();
1775  outs = null;
1776  } else {
1777  ret = null;
1778  outs = sig.getSqlOuts();
1779  }
1780  }
1781 
1782  @Override
1783  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1784  if (isRowUdf) {
1785  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1786  return typeFactory.createTypeWithNullability(
1787  typeFactory.createSqlType(ret), true);
1788  } else {
1789  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1790  java.util.List<RelDataType> typeList = new java.util.ArrayList<RelDataType>();
1791  java.util.List<java.lang.String> fieldNameList =
1792  new java.util.ArrayList<java.lang.String>();
1793 
1794  for (int out_idx = 0; out_idx < outs.size(); ++out_idx) {
1795  // TODO: use the argument names of output columns as field names
1796  fieldNameList.add("out" + out_idx);
1797  typeList.add(typeFactory.createSqlType(outs.get(out_idx)));
1798  }
1799  return typeFactory.createStructType(typeList, fieldNameList);
1800  }
1801  }
1802 
1803  private final boolean isRowUdf;
1804  private final SqlTypeName ret; // used only by UDFs
1805  private final List<SqlTypeName> outs; // used only by UDTFs
1806  }
1807 
1808  //
1809  // Internal accessors for in-situ poly render queries
1810  //
1811  // The MapD_* varietals are deprecated. The OmniSci_Geo_* ones should be used
1812  // instead
1813  //
1814 
1815  static class MapD_GeoPolyBoundsPtr extends SqlFunction {
1817  super("MapD_GeoPolyBoundsPtr",
1818  SqlKind.OTHER_FUNCTION,
1819  null,
1820  null,
1821  OperandTypes.family(SqlTypeFamily.ANY),
1822  SqlFunctionCategory.SYSTEM);
1823  }
1824 
1825  @Override
1826  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1827  assert opBinding.getOperandCount() == 1;
1828  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1829  return typeFactory.createSqlType(SqlTypeName.BIGINT);
1830  }
1831  }
1832 
1833  static class MapD_GeoPolyRenderGroup extends SqlFunction {
1835  super("MapD_GeoPolyRenderGroup",
1836  SqlKind.OTHER_FUNCTION,
1837  null,
1838  null,
1839  OperandTypes.family(SqlTypeFamily.ANY),
1840  SqlFunctionCategory.SYSTEM);
1841  }
1842 
1843  @Override
1844  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1845  assert opBinding.getOperandCount() == 1;
1846  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1847  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1848  }
1849  }
1850 
1851  static class OmniSci_Geo_PolyBoundsPtr extends SqlFunction {
1853  super("OmniSci_Geo_PolyBoundsPtr",
1854  SqlKind.OTHER_FUNCTION,
1855  null,
1856  null,
1857  OperandTypes.family(SqlTypeFamily.ANY),
1858  SqlFunctionCategory.SYSTEM);
1859  }
1860 
1861  @Override
1862  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1863  assert opBinding.getOperandCount() == 1;
1864  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1865  return typeFactory.createSqlType(SqlTypeName.BIGINT);
1866  }
1867  }
1868 
1869  static class OmniSci_Geo_PolyRenderGroup extends SqlFunction {
1871  super("OmniSci_Geo_PolyRenderGroup",
1872  SqlKind.OTHER_FUNCTION,
1873  null,
1874  null,
1875  OperandTypes.family(SqlTypeFamily.ANY),
1876  SqlFunctionCategory.SYSTEM);
1877  }
1878 
1879  @Override
1880  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1881  assert opBinding.getOperandCount() == 1;
1882  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1883  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1884  }
1885  }
1886 
1887  static class convert_meters_to_pixel_width extends SqlFunction {
1889  super("convert_meters_to_pixel_width",
1890  SqlKind.OTHER_FUNCTION,
1891  null,
1892  null,
1893  OperandTypes.family(SqlTypeFamily.NUMERIC,
1894  SqlTypeFamily.ANY,
1895  SqlTypeFamily.NUMERIC,
1896  SqlTypeFamily.NUMERIC,
1897  SqlTypeFamily.NUMERIC,
1898  SqlTypeFamily.NUMERIC),
1899  SqlFunctionCategory.SYSTEM);
1900  }
1901 
1902  @Override
1903  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1904  assert opBinding.getOperandCount() == 6;
1905  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1906  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
1907  }
1908  }
1909 
1910  static class convert_meters_to_pixel_height extends SqlFunction {
1912  super("convert_meters_to_pixel_height",
1913  SqlKind.OTHER_FUNCTION,
1914  null,
1915  null,
1916  OperandTypes.family(SqlTypeFamily.NUMERIC,
1917  SqlTypeFamily.ANY,
1918  SqlTypeFamily.NUMERIC,
1919  SqlTypeFamily.NUMERIC,
1920  SqlTypeFamily.NUMERIC,
1921  SqlTypeFamily.NUMERIC),
1922  SqlFunctionCategory.SYSTEM);
1923  }
1924 
1925  @Override
1926  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1927  assert opBinding.getOperandCount() == 6;
1928  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1929  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
1930  }
1931  }
1932 
1933  static class is_point_in_view extends SqlFunction {
1935  super("is_point_in_view",
1936  SqlKind.OTHER_FUNCTION,
1937  null,
1938  null,
1939  OperandTypes.family(SqlTypeFamily.ANY,
1940  SqlTypeFamily.NUMERIC,
1941  SqlTypeFamily.NUMERIC,
1942  SqlTypeFamily.NUMERIC,
1943  SqlTypeFamily.NUMERIC),
1944  SqlFunctionCategory.SYSTEM);
1945  }
1946 
1947  @Override
1948  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1949  assert opBinding.getOperandCount() == 5;
1950  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1951  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1952  }
1953  }
1954 
1955  static class is_point_size_in_view extends SqlFunction {
1957  super("is_point_size_in_view",
1958  SqlKind.OTHER_FUNCTION,
1959  null,
1960  null,
1961  OperandTypes.family(SqlTypeFamily.ANY,
1962  SqlTypeFamily.NUMERIC,
1963  SqlTypeFamily.NUMERIC,
1964  SqlTypeFamily.NUMERIC,
1965  SqlTypeFamily.NUMERIC,
1966  SqlTypeFamily.NUMERIC),
1967  SqlFunctionCategory.SYSTEM);
1968  }
1969 
1970  @Override
1971  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1972  assert opBinding.getOperandCount() == 6;
1973  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1974  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1975  }
1976  }
1977 
1978  public static class usTimestamp extends SqlFunction {
1979  public usTimestamp() {
1980  super("usTIMESTAMP",
1981  SqlKind.OTHER_FUNCTION,
1982  null,
1983  null,
1984  OperandTypes.STRING,
1985  SqlFunctionCategory.SYSTEM);
1986  }
1987 
1988  @Override
1989  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1990  assert opBinding.getOperandCount() == 1;
1991  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1992  return typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 6);
1993  }
1994  }
1995 
1996  public static class nsTimestamp extends SqlFunction {
1997  public nsTimestamp() {
1998  super("nsTIMESTAMP",
1999  SqlKind.OTHER_FUNCTION,
2000  null,
2001  null,
2002  OperandTypes.STRING,
2003  SqlFunctionCategory.SYSTEM);
2004  }
2005 
2006  @Override
2007  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2008  assert opBinding.getOperandCount() == 1;
2009  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2010  return typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 9);
2011  }
2012  }
2013 }
2014 
2015 // End MapDSqlOperatorTable.java
static java.util.List< SqlTypeFamily > signature()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
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)
final java.util.List< SqlTypeFamily > toSqlSignature()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
ExtFunction(final String name, final ExtensionFunction sig)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > signature()
EXTENSION_INLINE int32_t OmniSci_Geo_PolyRenderGroup(int32_t render_group)
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)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > getSignatureFamilies()
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)
EXTENSION_NOINLINE double ST_YMax(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)
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 > getSignatureFamilies()
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 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)
EXTENSION_INLINE int32_t MapD_GeoPolyRenderGroup(int32_t render_group)
EXTENSION_INLINE int64_t OmniSci_Geo_PolyBoundsPtr(double *bounds, int64_t size)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
EXTENSION_NOINLINE double ST_YMin(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)
EXTENSION_INLINE int64_t MapD_GeoPolyBoundsPtr(double *bounds, int64_t size)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
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)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure)
RelDataType getComponentType(RelDataTypeFactory typeFactory, List< RelDataType > argTypes)
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)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
EXTENSION_INLINE int32_t ST_NRings(int32_t *poly_ring_sizes, int64_t poly_num_rings)
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 double Truncate(const double x, const int32_t y)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static void addUDF(MapDSqlOperatorTable opTab, final Map< String, ExtensionFunction > extSigs)
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)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
EXTENSION_INLINE int32_t ST_NPoints(int8_t *coords, int64_t coords_sz, int32_t ic)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
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)