OmniSciDB  340b00dbf6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 {
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, copy column to output column
166  opTab.addOperator(new RowAdder()); // UDTF prototype, add two columns to output column
167  opTab.addOperator(
168  new RowAddSub()); // UDTF prototype, add two columns to output column
169  opTab.addOperator(new GetMaxWithRowOffset()); // UDTF prototype, constant sized with 1
170  // output row, get max of column along
171  // with row offset as two columns
172  opTab.addOperator(new MyUDFFunction());
173  opTab.addOperator(new PgUnnest());
174  opTab.addOperator(new Any());
175  opTab.addOperator(new All());
176  opTab.addOperator(new Now());
177  opTab.addOperator(new Datetime());
178  opTab.addOperator(new PgExtract());
179  opTab.addOperator(new Dateadd());
180  opTab.addOperator(new Datediff());
181  opTab.addOperator(new Datepart());
182  opTab.addOperator(new PgDateTrunc());
183  opTab.addOperator(new Length());
184  opTab.addOperator(new CharLength());
185  opTab.addOperator(new KeyForString());
186  opTab.addOperator(new SampleRatio());
187  opTab.addOperator(new ArrayLength());
188  opTab.addOperator(new PgILike());
189  opTab.addOperator(new RegexpLike());
190  opTab.addOperator(new Likely());
191  opTab.addOperator(new Unlikely());
192  opTab.addOperator(new Sign());
193  opTab.addOperator(new Truncate());
194  opTab.addOperator(new ST_IsEmpty());
195  opTab.addOperator(new ST_IsValid());
196  opTab.addOperator(new ST_Contains());
197  opTab.addOperator(new ST_Intersects());
198  opTab.addOperator(new ST_Overlaps());
199  opTab.addOperator(new ST_Disjoint());
200  opTab.addOperator(new ST_Within());
201  opTab.addOperator(new ST_DWithin());
202  opTab.addOperator(new ST_DFullyWithin());
203  opTab.addOperator(new ST_Distance());
204  opTab.addOperator(new ST_MaxDistance());
205  opTab.addOperator(new ST_GeogFromText());
206  opTab.addOperator(new ST_GeomFromText());
207  opTab.addOperator(new ST_Transform());
208  opTab.addOperator(new ST_X());
209  opTab.addOperator(new ST_Y());
210  opTab.addOperator(new ST_XMin());
211  opTab.addOperator(new ST_XMax());
212  opTab.addOperator(new ST_YMin());
213  opTab.addOperator(new ST_YMax());
214  opTab.addOperator(new ST_PointN());
215  opTab.addOperator(new ST_StartPoint());
216  opTab.addOperator(new ST_EndPoint());
217  opTab.addOperator(new ST_Length());
218  opTab.addOperator(new ST_Perimeter());
219  opTab.addOperator(new ST_Area());
220  opTab.addOperator(new ST_NPoints());
221  opTab.addOperator(new ST_NRings());
222  opTab.addOperator(new ST_SRID());
223  opTab.addOperator(new ST_SetSRID());
224  opTab.addOperator(new ST_Point());
225  opTab.addOperator(new ST_Centroid());
226  opTab.addOperator(new ST_Buffer());
227  opTab.addOperator(new ST_Intersection());
228  opTab.addOperator(new ST_Union());
229  opTab.addOperator(new ST_Difference());
230  opTab.addOperator(new CastToGeography());
231  opTab.addOperator(new OffsetInFragment());
232  opTab.addOperator(new ApproxCountDistinct());
233  opTab.addOperator(new MapDAvg());
234  opTab.addOperator(new Sample());
235  opTab.addOperator(new LastSample());
236  // MapD_Geo* are deprecated in place of the OmniSci_Geo_ varietals
237  opTab.addOperator(new MapD_GeoPolyBoundsPtr());
238  opTab.addOperator(new MapD_GeoPolyRenderGroup());
239  opTab.addOperator(new OmniSci_Geo_PolyBoundsPtr());
240  opTab.addOperator(new OmniSci_Geo_PolyRenderGroup());
241  opTab.addOperator(new convert_meters_to_pixel_width());
242  opTab.addOperator(new convert_meters_to_pixel_height());
243  opTab.addOperator(new is_point_in_view());
244  opTab.addOperator(new is_point_size_in_view());
245  opTab.addOperator(new usTimestamp());
246  opTab.addOperator(new nsTimestamp());
247  if (extSigs == null) {
248  return;
249  }
250  HashSet<String> demangledNames = new HashSet<String>();
251  for (Map.Entry<String, ExtensionFunction> extSig : extSigs.entrySet()) {
252  final String demangledName = dropSuffix(extSig.getKey());
253  final String demangledNameArity =
254  String.format("%s-%d", demangledName, extSig.getValue().getArgs().size());
255  if (demangledNames.contains(demangledNameArity)) {
256  continue;
257  }
258  demangledNames.add(demangledNameArity);
259  opTab.addOperator(new ExtFunction(demangledName, extSig.getValue()));
260  }
261  }
262 
263  private static String dropSuffix(final String str) {
264  int suffix_idx = str.indexOf("__");
265  if (suffix_idx == -1) {
266  return str;
267  }
268  assert suffix_idx > 0;
269  return str.substring(0, suffix_idx);
270  }
271 
273  extends SqlArrayValueConstructor {
274  @Override
275  protected RelDataType getComponentType(
276  RelDataTypeFactory typeFactory, List<RelDataType> argTypes) {
277  if (argTypes.isEmpty()) {
278  return typeFactory.createSqlType(SqlTypeName.NULL);
279  }
280  return super.getComponentType(typeFactory, argTypes);
281  }
282 
283  @Override
284  public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
285  if (callBinding.operands().isEmpty()) {
286  return true;
287  }
288  return super.checkOperandTypes(callBinding, throwOnFailure);
289  }
290  }
291 
295  public static class RampFunction extends SqlFunction {
296  public RampFunction() {
297  super("RAMP",
298  SqlKind.OTHER_FUNCTION,
299  null,
300  null,
301  OperandTypes.NUMERIC,
302  SqlFunctionCategory.USER_DEFINED_FUNCTION);
303  }
304 
305  @Override
306  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
307  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
308  return typeFactory.builder().add("I", SqlTypeName.INTEGER).build();
309  }
310  }
311 
315  public static class DedupFunction extends SqlFunction {
316  public DedupFunction() {
317  super("DEDUP",
318  SqlKind.OTHER_FUNCTION,
319  null,
320  null,
321  OperandTypes.VARIADIC,
322  SqlFunctionCategory.USER_DEFINED_FUNCTION);
323  }
324 
325  @Override
326  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
327  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
328  return typeFactory.builder().add("NAME", SqlTypeName.VARCHAR, 1024).build();
329  }
330  }
331 
336  public static class MyUDFFunction extends SqlFunction {
337  public MyUDFFunction() {
338  super("MyUDF",
339  SqlKind.OTHER_FUNCTION,
340  null,
341  null,
342  OperandTypes.STRING_STRING,
343  SqlFunctionCategory.SYSTEM);
344  }
345 
346  @Override
347  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
348  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
349  return typeFactory.createSqlType(SqlTypeName.BIGINT);
350  }
351  }
352 
356  public static class RowCopier extends SqlFunction {
357  public RowCopier() {
358  super("ROW_COPIER",
359  SqlKind.OTHER_FUNCTION,
360  null,
361  null,
362  OperandTypes.family(signature()),
363  SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION);
364  }
365 
366  @Override
367  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
368  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
369  java.util.List<RelDataType> typeList = new java.util.ArrayList<RelDataType>();
370  java.util.List<java.lang.String> fieldNameList =
371  new java.util.ArrayList<java.lang.String>();
372  fieldNameList.add("out0");
373  typeList.add(typeFactory.createSqlType(SqlTypeName.DOUBLE));
374  return typeFactory.createStructType(typeList, fieldNameList);
375  }
376 
377  private static java.util.List<SqlTypeFamily> signature() {
378  java.util.List<SqlTypeFamily> sig_family = new java.util.ArrayList<SqlTypeFamily>();
379  sig_family.add(SqlTypeFamily.CURSOR);
380  sig_family.add(SqlTypeFamily.ANY);
381  return sig_family;
382  }
383  }
384 
385  public static class RowAdder extends SqlFunction {
386  public RowAdder() {
387  super("ROW_ADDER",
388  SqlKind.OTHER_FUNCTION,
389  null,
390  null,
391  OperandTypes.family(signature()),
392  SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION);
393  }
394 
395  @Override
396  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
397  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
398  java.util.List<RelDataType> typeList = new java.util.ArrayList<RelDataType>();
399  java.util.List<java.lang.String> fieldNameList =
400  new java.util.ArrayList<java.lang.String>();
401  fieldNameList.add("out_add");
402  typeList.add(typeFactory.createSqlType(SqlTypeName.DOUBLE));
403  return typeFactory.createStructType(typeList, fieldNameList);
404  }
405 
406  private static java.util.List<SqlTypeFamily> signature() {
407  java.util.List<SqlTypeFamily> sig_family = new java.util.ArrayList<SqlTypeFamily>();
408  sig_family.add(SqlTypeFamily.INTEGER);
409  sig_family.add(SqlTypeFamily.CURSOR);
410  return sig_family;
411  }
412  }
413 
414  public static class RowAddSub extends SqlFunction {
415  public RowAddSub() {
416  super("ROW_ADDSUB",
417  SqlKind.OTHER_FUNCTION,
418  null,
419  null,
420  OperandTypes.family(signature()),
421  SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION);
422  }
423 
424  @Override
425  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
426  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
427  java.util.List<RelDataType> typeList = new java.util.ArrayList<RelDataType>();
428  java.util.List<java.lang.String> fieldNameList =
429  new java.util.ArrayList<java.lang.String>();
430  fieldNameList.add("out_add");
431  fieldNameList.add("out_sub");
432  typeList.add(typeFactory.createSqlType(SqlTypeName.DOUBLE));
433  typeList.add(typeFactory.createSqlType(SqlTypeName.DOUBLE));
434  return typeFactory.createStructType(typeList, fieldNameList);
435  }
436 
437  private static java.util.List<SqlTypeFamily> signature() {
438  java.util.List<SqlTypeFamily> sig_family = new java.util.ArrayList<SqlTypeFamily>();
439  sig_family.add(SqlTypeFamily.INTEGER);
440  sig_family.add(SqlTypeFamily.CURSOR);
441  return sig_family;
442  }
443  }
444 
445  public static class GetMaxWithRowOffset extends SqlFunction {
447  super("GET_MAX_WITH_ROW_OFFSET",
448  SqlKind.OTHER_FUNCTION,
449  null,
450  null,
451  OperandTypes.family(signature()),
452  SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION);
453  }
454 
455  @Override
456  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
457  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
458  java.util.List<RelDataType> typeList = new java.util.ArrayList<RelDataType>();
459  java.util.List<java.lang.String> fieldNameList =
460  new java.util.ArrayList<java.lang.String>();
461  fieldNameList.add("out0");
462  fieldNameList.add("out1");
463  typeList.add(typeFactory.createSqlType(SqlTypeName.INTEGER));
464  typeList.add(typeFactory.createSqlType(SqlTypeName.INTEGER));
465  return typeFactory.createStructType(typeList, fieldNameList);
466  }
467 
468  private static java.util.List<SqlTypeFamily> signature() {
469  java.util.List<SqlTypeFamily> sig_family = new java.util.ArrayList<SqlTypeFamily>();
470  sig_family.add(SqlTypeFamily.CURSOR);
471  return sig_family;
472  }
473  }
474 
475  /* Postgres-style UNNEST */
476  public static class PgUnnest extends SqlFunction {
477  public PgUnnest() {
478  super("PG_UNNEST",
479  SqlKind.OTHER_FUNCTION,
480  null,
481  null,
482  OperandTypes.ARRAY,
483  SqlFunctionCategory.SYSTEM);
484  }
485 
486  @Override
487  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
488  assert opBinding.getOperandCount() == 1;
489  RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
490  assert elem_type != null;
491  return elem_type;
492  }
493  }
494 
495  /* ANY qualifier */
496  public static class Any extends SqlFunction {
497  public Any() {
498  super("PG_ANY",
499  SqlKind.OTHER_FUNCTION,
500  null,
501  null,
502  OperandTypes.ARRAY,
503  SqlFunctionCategory.SYSTEM);
504  }
505 
506  @Override
507  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
508  assert opBinding.getOperandCount() == 1;
509  RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
510  assert elem_type != null;
511  return elem_type;
512  }
513  }
514 
515  /* ALL qualifier */
516  public static class All extends SqlFunction {
517  public All() {
518  super("PG_ALL",
519  SqlKind.OTHER_FUNCTION,
520  null,
521  null,
522  OperandTypes.ARRAY,
523  SqlFunctionCategory.SYSTEM);
524  }
525 
526  @Override
527  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
528  assert opBinding.getOperandCount() == 1;
529  RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
530  assert elem_type != null;
531  return elem_type;
532  }
533  }
534 
535  /* NOW() */
536  public static class Now extends SqlFunction {
537  public Now() {
538  super("NOW",
539  SqlKind.OTHER_FUNCTION,
540  null,
541  null,
542  OperandTypes.NILADIC,
543  SqlFunctionCategory.SYSTEM);
544  }
545 
546  @Override
547  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
548  assert opBinding.getOperandCount() == 0;
549  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
550  return typeFactory.createSqlType(SqlTypeName.TIMESTAMP);
551  }
552  }
553 
554  /* DATETIME */
555  public static class Datetime extends SqlFunction {
556  public Datetime() {
557  super("DATETIME",
558  SqlKind.OTHER_FUNCTION,
559  null,
560  null,
561  OperandTypes.STRING,
562  SqlFunctionCategory.SYSTEM);
563  }
564 
565  @Override
566  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
567  assert opBinding.getOperandCount() == 1;
568  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
569  return typeFactory.createSqlType(
570  SqlTypeName.TIMESTAMP, opBinding.getOperandType(0).getPrecision());
571  }
572  }
573 
574  /* Postgres-style EXTRACT */
575  public static class PgExtract extends SqlFunction {
576  public PgExtract() {
577  super("PG_EXTRACT",
578  SqlKind.OTHER_FUNCTION,
579  null,
580  null,
581  OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
582  SqlFunctionCategory.SYSTEM);
583  }
584 
585  @Override
586  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
587  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
588  return typeFactory.createTypeWithNullability(
589  typeFactory.createSqlType(SqlTypeName.BIGINT),
590  opBinding.getOperandType(1).isNullable());
591  }
592  }
593 
594  public static class Datepart extends SqlFunction {
595  public Datepart() {
596  super("DATEPART",
597  SqlKind.OTHER_FUNCTION,
598  null,
599  null,
600  OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
601  SqlFunctionCategory.TIMEDATE);
602  }
603 
604  @Override
605  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
606  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
607  return typeFactory.createTypeWithNullability(
608  typeFactory.createSqlType(SqlTypeName.BIGINT),
609  opBinding.getOperandType(1).isNullable());
610  }
611  }
612 
613  public static class Dateadd extends SqlFunction {
614  public Dateadd() {
615  super("DATEADD",
616  SqlKind.OTHER_FUNCTION,
617  null,
618  null,
619  OperandTypes.family(SqlTypeFamily.STRING,
620  SqlTypeFamily.INTEGER,
621  SqlTypeFamily.DATETIME),
622  SqlFunctionCategory.TIMEDATE);
623  }
624 
625  @Override
626  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
627  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
628  return typeFactory.createTypeWithNullability(
629  typeFactory.createSqlType(
630  SqlTypeName.TIMESTAMP, opBinding.getOperandType(2).getPrecision()),
631  opBinding.getOperandType(2).isNullable());
632  }
633  }
634 
635  public static class Datediff extends SqlFunction {
636  public Datediff() {
637  super("DATEDIFF",
638  SqlKind.OTHER_FUNCTION,
639  null,
640  null,
641  OperandTypes.family(SqlTypeFamily.STRING,
642  SqlTypeFamily.DATETIME,
643  SqlTypeFamily.DATETIME),
644  SqlFunctionCategory.TIMEDATE);
645  }
646 
647  @Override
648  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
649  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
650  return typeFactory.createTypeWithNullability(
651  typeFactory.createSqlType(SqlTypeName.BIGINT),
652  opBinding.getOperandType(1).isNullable()
653  || opBinding.getOperandType(2).isNullable());
654  }
655  }
656 
657  /* Postgres-style DATE_TRUNC */
658  public static class PgDateTrunc extends SqlFunction {
659  public PgDateTrunc() {
660  super("PG_DATE_TRUNC",
661  SqlKind.OTHER_FUNCTION,
662  null,
663  null,
664  OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
665  SqlFunctionCategory.SYSTEM);
666  }
667 
668  @Override
669  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
670  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
671  return typeFactory.createTypeWithNullability(
672  typeFactory.createSqlType(
673  SqlTypeName.TIMESTAMP, opBinding.getOperandType(1).getPrecision()),
674  opBinding.getOperandType(1).isNullable());
675  }
676  }
677 
678  public static class Length extends SqlFunction {
679  public Length() {
680  super("LENGTH",
681  SqlKind.OTHER_FUNCTION,
682  null,
683  null,
684  OperandTypes.STRING,
685  SqlFunctionCategory.SYSTEM);
686  }
687 
688  @Override
689  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
690  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
691  return typeFactory.createSqlType(SqlTypeName.INTEGER);
692  }
693  }
694 
695  public static class CharLength extends SqlFunction {
696  public CharLength() {
697  super("CHAR_LENGTH",
698  SqlKind.OTHER_FUNCTION,
699  null,
700  null,
701  OperandTypes.STRING,
702  SqlFunctionCategory.SYSTEM);
703  }
704 
705  @Override
706  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
707  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
708  return typeFactory.createSqlType(SqlTypeName.INTEGER);
709  }
710  }
711 
712  public static class KeyForString extends SqlFunction {
713  public KeyForString() {
714  super("KEY_FOR_STRING",
715  SqlKind.OTHER_FUNCTION,
716  null,
717  null,
718  OperandTypes.STRING,
719  SqlFunctionCategory.SYSTEM);
720  }
721 
722  @Override
723  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
724  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
725  return typeFactory.createTypeWithNullability(
726  typeFactory.createSqlType(SqlTypeName.INTEGER),
727  opBinding.getOperandType(0).isNullable());
728  }
729  }
730 
731  public static class SampleRatio extends SqlFunction {
732  public SampleRatio() {
733  super("SAMPLE_RATIO",
734  SqlKind.OTHER_FUNCTION,
735  null,
736  null,
737  OperandTypes.family(signature()),
738  SqlFunctionCategory.SYSTEM);
739  }
740 
741  @Override
742  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
743  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
744  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
745  }
746 
747  private static java.util.List<SqlTypeFamily> signature() {
748  java.util.ArrayList<SqlTypeFamily> families =
749  new java.util.ArrayList<SqlTypeFamily>();
750  families.add(SqlTypeFamily.NUMERIC);
751  return families;
752  }
753  }
754 
755  public static class ArrayLength extends SqlFunction {
756  public ArrayLength() {
757  super("ARRAY_LENGTH",
758  SqlKind.OTHER_FUNCTION,
759  null,
760  null,
761  OperandTypes.ARRAY,
762  SqlFunctionCategory.SYSTEM);
763  }
764 
765  @Override
766  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
767  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
768  return typeFactory.createSqlType(SqlTypeName.INTEGER);
769  }
770  }
771 
772  public static class PgILike extends SqlFunction {
773  public PgILike() {
774  super("PG_ILIKE",
775  SqlKind.OTHER_FUNCTION,
776  null,
777  null,
778  OperandTypes.family(getSignatureFamilies(), new EscapeOptional()),
779  SqlFunctionCategory.SYSTEM);
780  }
781 
782  private static java.util.List<SqlTypeFamily> getSignatureFamilies() {
783  java.util.ArrayList<SqlTypeFamily> families =
784  new java.util.ArrayList<SqlTypeFamily>();
785  families.add(SqlTypeFamily.STRING);
786  families.add(SqlTypeFamily.STRING);
787  families.add(SqlTypeFamily.STRING);
788  return families;
789  }
790 
791  private static class EscapeOptional
792  implements java.util.function.Predicate<Integer>, Predicate<Integer> {
793  @Override
794  public boolean test(Integer t) {
795  return apply(t);
796  }
797 
798  @Override
799  public boolean apply(Integer t) {
800  return t == 2;
801  }
802  }
803 
804  @Override
805  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
806  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
807  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
808  }
809  }
810 
811  public static class RegexpLike extends SqlFunction {
812  public RegexpLike() {
813  super("REGEXP_LIKE",
814  SqlKind.OTHER_FUNCTION,
815  null,
816  null,
817  OperandTypes.family(getSignatureFamilies(), new EscapeOptional()),
818  SqlFunctionCategory.SYSTEM);
819  }
820 
821  private static java.util.List<SqlTypeFamily> getSignatureFamilies() {
822  java.util.ArrayList<SqlTypeFamily> families =
823  new java.util.ArrayList<SqlTypeFamily>();
824  families.add(SqlTypeFamily.STRING);
825  families.add(SqlTypeFamily.STRING);
826  families.add(SqlTypeFamily.STRING);
827  return families;
828  }
829 
830  private static class EscapeOptional
831  implements java.util.function.Predicate<Integer>, Predicate<Integer> {
832  @Override
833  public boolean test(Integer t) {
834  return apply(t);
835  }
836 
837  public boolean apply(Integer t) {
838  return t == 2;
839  }
840  }
841 
842  @Override
843  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
844  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
845  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
846  }
847  }
848 
849  public static class Likely extends SqlFunction {
850  public Likely() {
851  super("LIKELY",
852  SqlKind.OTHER_FUNCTION,
853  null,
854  null,
855  OperandTypes.BOOLEAN,
856  SqlFunctionCategory.SYSTEM);
857  }
858 
859  @Override
860  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
861  return opBinding.getOperandType(0);
862  }
863  }
864 
865  public static class Unlikely extends SqlFunction {
866  public Unlikely() {
867  super("UNLIKELY",
868  SqlKind.OTHER_FUNCTION,
869  null,
870  null,
871  OperandTypes.BOOLEAN,
872  SqlFunctionCategory.SYSTEM);
873  }
874 
875  @Override
876  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
877  return opBinding.getOperandType(0);
878  }
879  }
880 
881  public static class Sign extends SqlFunction {
882  public Sign() {
883  super("SIGN",
884  SqlKind.OTHER_FUNCTION,
885  null,
886  null,
887  OperandTypes.NUMERIC,
888  SqlFunctionCategory.NUMERIC);
889  }
890 
891  @Override
892  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
893  return opBinding.getOperandType(0);
894  }
895  }
896 
897  static class Truncate extends SqlFunction {
899  super("TRUNCATE",
900  SqlKind.OTHER_FUNCTION,
901  null,
902  null,
903  OperandTypes.family(signature()),
904  SqlFunctionCategory.NUMERIC);
905  }
906 
907  @Override
908  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
909  assert opBinding.getOperandCount() == 2;
910  return opBinding.getOperandType(0);
911  }
912 
913  private static java.util.List<SqlTypeFamily> signature() {
914  java.util.List<SqlTypeFamily> truncate_sig =
915  new java.util.ArrayList<SqlTypeFamily>();
916  truncate_sig.add(SqlTypeFamily.NUMERIC);
917  truncate_sig.add(SqlTypeFamily.INTEGER);
918  return truncate_sig;
919  }
920  }
921 
922  static class ST_IsEmpty extends SqlFunction {
924  super("ST_IsEmpty",
925  SqlKind.OTHER_FUNCTION,
926  null,
927  null,
928  OperandTypes.family(signature()),
929  SqlFunctionCategory.SYSTEM);
930  }
931 
932  @Override
933  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
934  assert opBinding.getOperandCount() == 1;
935  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
936  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
937  }
938 
939  private static java.util.List<SqlTypeFamily> signature() {
940  java.util.List<SqlTypeFamily> st_isempty_sig =
941  new java.util.ArrayList<SqlTypeFamily>();
942  st_isempty_sig.add(SqlTypeFamily.ANY);
943  return st_isempty_sig;
944  }
945  }
946 
947  static class ST_IsValid extends SqlFunction {
949  super("ST_IsValid",
950  SqlKind.OTHER_FUNCTION,
951  null,
952  null,
953  OperandTypes.family(signature()),
954  SqlFunctionCategory.SYSTEM);
955  }
956 
957  @Override
958  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
959  assert opBinding.getOperandCount() == 1;
960  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
961  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
962  }
963 
964  private static java.util.List<SqlTypeFamily> signature() {
965  java.util.List<SqlTypeFamily> st_isvalid_sig =
966  new java.util.ArrayList<SqlTypeFamily>();
967  st_isvalid_sig.add(SqlTypeFamily.ANY);
968  return st_isvalid_sig;
969  }
970  }
971 
972  static class ST_Contains extends SqlFunction {
974  super("ST_Contains",
975  SqlKind.OTHER_FUNCTION,
976  null,
977  null,
978  OperandTypes.family(signature()),
979  SqlFunctionCategory.SYSTEM);
980  }
981 
982  @Override
983  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
984  assert opBinding.getOperandCount() == 2;
985  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
986  return typeFactory.createTypeWithNullability(
987  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
988  opBinding.getOperandType(0).isNullable()
989  || opBinding.getOperandType(1).isNullable());
990  }
991 
992  private static java.util.List<SqlTypeFamily> signature() {
993  java.util.List<SqlTypeFamily> st_contains_sig =
994  new java.util.ArrayList<SqlTypeFamily>();
995  st_contains_sig.add(SqlTypeFamily.ANY);
996  st_contains_sig.add(SqlTypeFamily.ANY);
997  return st_contains_sig;
998  }
999  }
1000 
1001  static class ST_Intersects extends SqlFunction {
1003  super("ST_Intersects",
1004  SqlKind.OTHER_FUNCTION,
1005  null,
1006  null,
1007  OperandTypes.family(signature()),
1008  SqlFunctionCategory.SYSTEM);
1009  }
1010 
1011  @Override
1012  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1013  assert opBinding.getOperandCount() == 2;
1014  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1015  return typeFactory.createTypeWithNullability(
1016  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1017  opBinding.getOperandType(0).isNullable()
1018  || opBinding.getOperandType(1).isNullable());
1019  }
1020 
1021  private static java.util.List<SqlTypeFamily> signature() {
1022  java.util.List<SqlTypeFamily> st_intersects_sig =
1023  new java.util.ArrayList<SqlTypeFamily>();
1024  st_intersects_sig.add(SqlTypeFamily.ANY);
1025  st_intersects_sig.add(SqlTypeFamily.ANY);
1026  return st_intersects_sig;
1027  }
1028  }
1029 
1030  static class ST_Overlaps extends SqlFunction {
1032  super("ST_Overlaps",
1033  SqlKind.OTHER_FUNCTION,
1034  null,
1035  null,
1036  OperandTypes.family(signature()),
1037  SqlFunctionCategory.SYSTEM);
1038  }
1039 
1040  @Override
1041  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1042  assert opBinding.getOperandCount() == 2;
1043  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1044  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1045  }
1046 
1047  private static java.util.List<SqlTypeFamily> signature() {
1048  java.util.List<SqlTypeFamily> st_overlaps_sig =
1049  new java.util.ArrayList<SqlTypeFamily>();
1050  st_overlaps_sig.add(SqlTypeFamily.ANY);
1051  st_overlaps_sig.add(SqlTypeFamily.ANY);
1052  return st_overlaps_sig;
1053  }
1054  }
1055 
1056  static class ST_Disjoint extends SqlFunction {
1058  super("ST_Disjoint",
1059  SqlKind.OTHER_FUNCTION,
1060  null,
1061  null,
1062  OperandTypes.family(signature()),
1063  SqlFunctionCategory.SYSTEM);
1064  }
1065 
1066  @Override
1067  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1068  assert opBinding.getOperandCount() == 2;
1069  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1070  return typeFactory.createTypeWithNullability(
1071  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1072  opBinding.getOperandType(0).isNullable()
1073  || opBinding.getOperandType(1).isNullable());
1074  }
1075 
1076  private static java.util.List<SqlTypeFamily> signature() {
1077  java.util.List<SqlTypeFamily> st_disjoint_sig =
1078  new java.util.ArrayList<SqlTypeFamily>();
1079  st_disjoint_sig.add(SqlTypeFamily.ANY);
1080  st_disjoint_sig.add(SqlTypeFamily.ANY);
1081  return st_disjoint_sig;
1082  }
1083  }
1084 
1085  static class ST_Within extends SqlFunction {
1087  super("ST_Within",
1088  SqlKind.OTHER_FUNCTION,
1089  null,
1090  null,
1091  OperandTypes.family(signature()),
1092  SqlFunctionCategory.SYSTEM);
1093  }
1094 
1095  @Override
1096  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1097  assert opBinding.getOperandCount() == 2;
1098  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1099  return typeFactory.createTypeWithNullability(
1100  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1101  opBinding.getOperandType(0).isNullable()
1102  || opBinding.getOperandType(1).isNullable());
1103  }
1104 
1105  private static java.util.List<SqlTypeFamily> signature() {
1106  java.util.List<SqlTypeFamily> st_within_sig =
1107  new java.util.ArrayList<SqlTypeFamily>();
1108  st_within_sig.add(SqlTypeFamily.ANY);
1109  st_within_sig.add(SqlTypeFamily.ANY);
1110  return st_within_sig;
1111  }
1112  }
1113 
1114  static class ST_DWithin extends SqlFunction {
1116  super("ST_DWithin",
1117  SqlKind.OTHER_FUNCTION,
1118  null,
1119  null,
1120  OperandTypes.family(signature()),
1121  SqlFunctionCategory.SYSTEM);
1122  }
1123 
1124  @Override
1125  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1126  assert opBinding.getOperandCount() == 3;
1127  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1128  return typeFactory.createTypeWithNullability(
1129  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1130  opBinding.getOperandType(0).isNullable()
1131  || opBinding.getOperandType(1).isNullable()
1132  || opBinding.getOperandType(2).isNullable());
1133  }
1134 
1135  private static java.util.List<SqlTypeFamily> signature() {
1136  java.util.List<SqlTypeFamily> st_dwithin_sig =
1137  new java.util.ArrayList<SqlTypeFamily>();
1138  st_dwithin_sig.add(SqlTypeFamily.ANY);
1139  st_dwithin_sig.add(SqlTypeFamily.ANY);
1140  st_dwithin_sig.add(SqlTypeFamily.NUMERIC);
1141  return st_dwithin_sig;
1142  }
1143  }
1144 
1145  static class ST_DFullyWithin extends SqlFunction {
1147  super("ST_DFullyWithin",
1148  SqlKind.OTHER_FUNCTION,
1149  null,
1150  null,
1151  OperandTypes.family(signature()),
1152  SqlFunctionCategory.SYSTEM);
1153  }
1154 
1155  @Override
1156  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1157  assert opBinding.getOperandCount() == 3;
1158  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1159  return typeFactory.createTypeWithNullability(
1160  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1161  opBinding.getOperandType(0).isNullable()
1162  || opBinding.getOperandType(1).isNullable()
1163  || opBinding.getOperandType(2).isNullable());
1164  }
1165 
1166  private static java.util.List<SqlTypeFamily> signature() {
1167  java.util.List<SqlTypeFamily> st_dwithin_sig =
1168  new java.util.ArrayList<SqlTypeFamily>();
1169  st_dwithin_sig.add(SqlTypeFamily.ANY);
1170  st_dwithin_sig.add(SqlTypeFamily.ANY);
1171  st_dwithin_sig.add(SqlTypeFamily.NUMERIC);
1172  return st_dwithin_sig;
1173  }
1174  }
1175 
1176  static class ST_Distance extends SqlFunction {
1178  super("ST_Distance",
1179  SqlKind.OTHER_FUNCTION,
1180  null,
1181  null,
1182  OperandTypes.family(signature()),
1183  SqlFunctionCategory.SYSTEM);
1184  }
1185 
1186  @Override
1187  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1188  assert opBinding.getOperandCount() == 2;
1189  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1190  return typeFactory.createTypeWithNullability(
1191  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1192  opBinding.getOperandType(0).isNullable()
1193  || opBinding.getOperandType(1).isNullable());
1194  }
1195 
1196  private static java.util.List<SqlTypeFamily> signature() {
1197  java.util.List<SqlTypeFamily> st_distance_sig =
1198  new java.util.ArrayList<SqlTypeFamily>();
1199  st_distance_sig.add(SqlTypeFamily.ANY);
1200  st_distance_sig.add(SqlTypeFamily.ANY);
1201  return st_distance_sig;
1202  }
1203  }
1204 
1205  static class ST_MaxDistance extends SqlFunction {
1207  super("ST_MaxDistance",
1208  SqlKind.OTHER_FUNCTION,
1209  null,
1210  null,
1211  OperandTypes.family(signature()),
1212  SqlFunctionCategory.SYSTEM);
1213  }
1214 
1215  @Override
1216  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1217  assert opBinding.getOperandCount() == 2;
1218  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1219  return typeFactory.createTypeWithNullability(
1220  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1221  opBinding.getOperandType(0).isNullable()
1222  || opBinding.getOperandType(1).isNullable());
1223  }
1224 
1225  private static java.util.List<SqlTypeFamily> signature() {
1226  java.util.List<SqlTypeFamily> st_maxdistance_sig =
1227  new java.util.ArrayList<SqlTypeFamily>();
1228  st_maxdistance_sig.add(SqlTypeFamily.ANY);
1229  st_maxdistance_sig.add(SqlTypeFamily.ANY);
1230  return st_maxdistance_sig;
1231  }
1232  }
1233 
1234  static class ST_GeogFromText extends SqlFunction {
1236  super("ST_GeogFromText",
1237  SqlKind.OTHER_FUNCTION,
1238  null,
1239  null,
1240  OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
1241  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
1242  SqlFunctionCategory.SYSTEM);
1243  }
1244 
1245  @Override
1246  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1247  assert opBinding.getOperandCount() == 1;
1248  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1249  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1250  }
1251  }
1252 
1253  static class ST_GeomFromText extends SqlFunction {
1255  super("ST_GeomFromText",
1256  SqlKind.OTHER_FUNCTION,
1257  null,
1258  null,
1259  OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
1260  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
1261  SqlFunctionCategory.SYSTEM);
1262  }
1263 
1264  @Override
1265  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1266  assert opBinding.getOperandCount() == 1;
1267  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1268  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1269  }
1270  }
1271 
1272  static class ST_Transform extends SqlFunction {
1274  super("ST_Transform",
1275  SqlKind.OTHER_FUNCTION,
1276  null,
1277  null,
1278  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
1279  SqlFunctionCategory.SYSTEM);
1280  }
1281 
1282  @Override
1283  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1284  assert opBinding.getOperandCount() == 1;
1285  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1286  return typeFactory.createTypeWithNullability(
1287  typeFactory.createSqlType(SqlTypeName.INTEGER),
1288  opBinding.getOperandType(0).isNullable());
1289  }
1290  }
1291 
1292  static class ST_X extends SqlFunction {
1293  ST_X() {
1294  super("ST_X",
1295  SqlKind.OTHER_FUNCTION,
1296  null,
1297  null,
1298  OperandTypes.family(SqlTypeFamily.ANY),
1299  SqlFunctionCategory.SYSTEM);
1300  }
1301 
1302  @Override
1303  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1304  assert opBinding.getOperandCount() == 1;
1305  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1306  return typeFactory.createTypeWithNullability(
1307  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1308  opBinding.getOperandType(0).isNullable());
1309  }
1310  }
1311 
1312  static class ST_Y extends SqlFunction {
1313  ST_Y() {
1314  super("ST_Y",
1315  SqlKind.OTHER_FUNCTION,
1316  null,
1317  null,
1318  OperandTypes.family(SqlTypeFamily.ANY),
1319  SqlFunctionCategory.SYSTEM);
1320  }
1321 
1322  @Override
1323  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1324  assert opBinding.getOperandCount() == 1;
1325  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1326  return typeFactory.createTypeWithNullability(
1327  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1328  opBinding.getOperandType(0).isNullable());
1329  }
1330  }
1331 
1332  static class ST_XMin extends SqlFunction {
1334  super("ST_XMin",
1335  SqlKind.OTHER_FUNCTION,
1336  null,
1337  null,
1338  OperandTypes.family(SqlTypeFamily.ANY),
1339  SqlFunctionCategory.SYSTEM);
1340  }
1341 
1342  @Override
1343  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1344  assert opBinding.getOperandCount() == 1;
1345  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1346  return typeFactory.createTypeWithNullability(
1347  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1348  opBinding.getOperandType(0).isNullable());
1349  }
1350  }
1351 
1352  static class ST_XMax extends SqlFunction {
1354  super("ST_XMax",
1355  SqlKind.OTHER_FUNCTION,
1356  null,
1357  null,
1358  OperandTypes.family(SqlTypeFamily.ANY),
1359  SqlFunctionCategory.SYSTEM);
1360  }
1361 
1362  @Override
1363  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1364  assert opBinding.getOperandCount() == 1;
1365  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1366  return typeFactory.createTypeWithNullability(
1367  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1368  opBinding.getOperandType(0).isNullable());
1369  }
1370  }
1371 
1372  static class ST_YMin extends SqlFunction {
1374  super("ST_YMin",
1375  SqlKind.OTHER_FUNCTION,
1376  null,
1377  null,
1378  OperandTypes.family(SqlTypeFamily.ANY),
1379  SqlFunctionCategory.SYSTEM);
1380  }
1381 
1382  @Override
1383  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1384  assert opBinding.getOperandCount() == 1;
1385  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1386  return typeFactory.createTypeWithNullability(
1387  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1388  opBinding.getOperandType(0).isNullable());
1389  }
1390  }
1391 
1392  static class ST_YMax extends SqlFunction {
1394  super("ST_YMax",
1395  SqlKind.OTHER_FUNCTION,
1396  null,
1397  null,
1398  OperandTypes.family(SqlTypeFamily.ANY),
1399  SqlFunctionCategory.SYSTEM);
1400  }
1401 
1402  @Override
1403  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1404  assert opBinding.getOperandCount() == 1;
1405  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1406  return typeFactory.createTypeWithNullability(
1407  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1408  opBinding.getOperandType(0).isNullable());
1409  }
1410  }
1411 
1412  static class ST_PointN extends SqlFunction {
1414  super("ST_PointN",
1415  SqlKind.OTHER_FUNCTION,
1416  null,
1417  null,
1418  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
1419  SqlFunctionCategory.SYSTEM);
1420  }
1421 
1422  @Override
1423  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1424  assert opBinding.getOperandCount() == 1;
1425  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1426  return typeFactory.createTypeWithNullability(
1427  typeFactory.createSqlType(SqlTypeName.INTEGER),
1428  opBinding.getOperandType(0).isNullable());
1429  }
1430  }
1431 
1432  static class ST_EndPoint extends SqlFunction {
1434  super("ST_EndPoint",
1435  SqlKind.OTHER_FUNCTION,
1436  null,
1437  null,
1438  OperandTypes.family(SqlTypeFamily.ANY),
1439  SqlFunctionCategory.SYSTEM);
1440  }
1441 
1442  @Override
1443  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1444  assert opBinding.getOperandCount() == 1;
1445  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1446  return typeFactory.createTypeWithNullability(
1447  typeFactory.createSqlType(SqlTypeName.INTEGER),
1448  opBinding.getOperandType(0).isNullable());
1449  }
1450  }
1451 
1452  static class ST_StartPoint extends SqlFunction {
1454  super("ST_StartPoint",
1455  SqlKind.OTHER_FUNCTION,
1456  null,
1457  null,
1458  OperandTypes.family(SqlTypeFamily.ANY),
1459  SqlFunctionCategory.SYSTEM);
1460  }
1461 
1462  @Override
1463  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1464  assert opBinding.getOperandCount() == 1;
1465  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1466  return typeFactory.createTypeWithNullability(
1467  typeFactory.createSqlType(SqlTypeName.INTEGER),
1468  opBinding.getOperandType(0).isNullable());
1469  }
1470  }
1471 
1472  static class ST_Length extends SqlFunction {
1474  super("ST_Length",
1475  SqlKind.OTHER_FUNCTION,
1476  null,
1477  null,
1478  OperandTypes.family(SqlTypeFamily.ANY),
1479  SqlFunctionCategory.SYSTEM);
1480  }
1481 
1482  @Override
1483  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1484  assert opBinding.getOperandCount() == 1;
1485  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1486  return typeFactory.createTypeWithNullability(
1487  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1488  opBinding.getOperandType(0).isNullable());
1489  }
1490  }
1491 
1492  static class ST_Perimeter extends SqlFunction {
1494  super("ST_Perimeter",
1495  SqlKind.OTHER_FUNCTION,
1496  null,
1497  null,
1498  OperandTypes.family(SqlTypeFamily.ANY),
1499  SqlFunctionCategory.SYSTEM);
1500  }
1501 
1502  @Override
1503  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1504  assert opBinding.getOperandCount() == 1;
1505  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1506  return typeFactory.createTypeWithNullability(
1507  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1508  opBinding.getOperandType(0).isNullable());
1509  }
1510  }
1511 
1512  static class ST_Area extends SqlFunction {
1514  super("ST_Area",
1515  SqlKind.OTHER_FUNCTION,
1516  null,
1517  null,
1518  OperandTypes.family(SqlTypeFamily.ANY),
1519  SqlFunctionCategory.SYSTEM);
1520  }
1521 
1522  @Override
1523  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1524  assert opBinding.getOperandCount() == 1;
1525  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1526  return typeFactory.createTypeWithNullability(
1527  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1528  opBinding.getOperandType(0).isNullable());
1529  }
1530  }
1531 
1532  static class ST_NPoints extends SqlFunction {
1534  super("ST_NPoints",
1535  SqlKind.OTHER_FUNCTION,
1536  null,
1537  null,
1538  OperandTypes.family(SqlTypeFamily.ANY),
1539  SqlFunctionCategory.SYSTEM);
1540  }
1541 
1542  @Override
1543  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1544  assert opBinding.getOperandCount() == 1;
1545  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1546  return typeFactory.createTypeWithNullability(
1547  typeFactory.createSqlType(SqlTypeName.INTEGER),
1548  opBinding.getOperandType(0).isNullable());
1549  }
1550  }
1551 
1552  static class ST_NRings extends SqlFunction {
1554  super("ST_NRings",
1555  SqlKind.OTHER_FUNCTION,
1556  null,
1557  null,
1558  OperandTypes.family(SqlTypeFamily.ANY),
1559  SqlFunctionCategory.SYSTEM);
1560  }
1561 
1562  @Override
1563  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1564  assert opBinding.getOperandCount() == 1;
1565  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1566  return typeFactory.createTypeWithNullability(
1567  typeFactory.createSqlType(SqlTypeName.INTEGER),
1568  opBinding.getOperandType(0).isNullable());
1569  }
1570  }
1571 
1572  static class ST_SRID extends SqlFunction {
1574  super("ST_SRID",
1575  SqlKind.OTHER_FUNCTION,
1576  null,
1577  null,
1578  OperandTypes.family(SqlTypeFamily.ANY),
1579  SqlFunctionCategory.SYSTEM);
1580  }
1581 
1582  @Override
1583  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1584  assert opBinding.getOperandCount() == 1;
1585  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1586  return typeFactory.createTypeWithNullability(
1587  typeFactory.createSqlType(SqlTypeName.INTEGER),
1588  opBinding.getOperandType(0).isNullable());
1589  }
1590  }
1591 
1592  static class ST_SetSRID extends SqlFunction {
1594  super("ST_SetSRID",
1595  SqlKind.OTHER_FUNCTION,
1596  null,
1597  null,
1598  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
1599  SqlFunctionCategory.SYSTEM);
1600  }
1601 
1602  @Override
1603  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1604  assert opBinding.getOperandCount() == 1;
1605  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1606  return typeFactory.createTypeWithNullability(
1607  typeFactory.createSqlType(SqlTypeName.INTEGER),
1608  opBinding.getOperandType(0).isNullable());
1609  }
1610  }
1611 
1612  static class ST_Point extends SqlFunction {
1614  super("ST_Point",
1615  SqlKind.OTHER_FUNCTION,
1616  null,
1617  null,
1618  OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
1619  SqlFunctionCategory.SYSTEM);
1620  }
1621 
1622  @Override
1623  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1624  assert opBinding.getOperandCount() == 2;
1625  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1626  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1627  }
1628  }
1629 
1630  static class ST_Centroid extends SqlFunction {
1632  super("ST_Centroid",
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() == 1;
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_centroid_sig =
1649  new java.util.ArrayList<SqlTypeFamily>();
1650  st_centroid_sig.add(SqlTypeFamily.ANY);
1651  return st_centroid_sig;
1652  }
1653  }
1654 
1655  static class ST_Buffer extends SqlFunction {
1657  super("ST_Buffer",
1658  SqlKind.OTHER_FUNCTION,
1659  null,
1660  null,
1661  OperandTypes.family(signature()),
1662  SqlFunctionCategory.SYSTEM);
1663  }
1664 
1665  @Override
1666  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1667  assert opBinding.getOperandCount() == 2;
1668  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1669  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1670  }
1671 
1672  private static java.util.List<SqlTypeFamily> signature() {
1673  java.util.List<SqlTypeFamily> st_buffer_sig =
1674  new java.util.ArrayList<SqlTypeFamily>();
1675  st_buffer_sig.add(SqlTypeFamily.ANY);
1676  st_buffer_sig.add(SqlTypeFamily.NUMERIC);
1677  return st_buffer_sig;
1678  }
1679  }
1680 
1681  static class ST_Intersection extends SqlFunction {
1683  super("ST_Intersection",
1684  SqlKind.OTHER_FUNCTION,
1685  null,
1686  null,
1687  OperandTypes.family(signature()),
1688  SqlFunctionCategory.SYSTEM);
1689  }
1690 
1691  @Override
1692  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1693  assert opBinding.getOperandCount() == 2;
1694  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1695  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1696  }
1697 
1698  private static java.util.List<SqlTypeFamily> signature() {
1699  java.util.List<SqlTypeFamily> st_intersection_sig =
1700  new java.util.ArrayList<SqlTypeFamily>();
1701  st_intersection_sig.add(SqlTypeFamily.ANY);
1702  st_intersection_sig.add(SqlTypeFamily.ANY);
1703  return st_intersection_sig;
1704  }
1705  }
1706 
1707  static class ST_Union extends SqlFunction {
1709  super("ST_Union",
1710  SqlKind.OTHER_FUNCTION,
1711  null,
1712  null,
1713  OperandTypes.family(signature()),
1714  SqlFunctionCategory.SYSTEM);
1715  }
1716 
1717  @Override
1718  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1719  assert opBinding.getOperandCount() == 2;
1720  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1721  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1722  }
1723 
1724  private static java.util.List<SqlTypeFamily> signature() {
1725  java.util.List<SqlTypeFamily> st_union_sig =
1726  new java.util.ArrayList<SqlTypeFamily>();
1727  st_union_sig.add(SqlTypeFamily.ANY);
1728  st_union_sig.add(SqlTypeFamily.ANY);
1729  return st_union_sig;
1730  }
1731  }
1732 
1733  static class ST_Difference extends SqlFunction {
1735  super("ST_Difference",
1736  SqlKind.OTHER_FUNCTION,
1737  null,
1738  null,
1739  OperandTypes.family(signature()),
1740  SqlFunctionCategory.SYSTEM);
1741  }
1742 
1743  @Override
1744  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1745  assert opBinding.getOperandCount() == 2;
1746  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1747  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1748  }
1749 
1750  private static java.util.List<SqlTypeFamily> signature() {
1751  java.util.List<SqlTypeFamily> st_difference_sig =
1752  new java.util.ArrayList<SqlTypeFamily>();
1753  st_difference_sig.add(SqlTypeFamily.ANY);
1754  st_difference_sig.add(SqlTypeFamily.ANY);
1755  return st_difference_sig;
1756  }
1757  }
1758 
1759  static class CastToGeography extends SqlFunction {
1761  super("CastToGeography",
1762  SqlKind.OTHER_FUNCTION,
1763  null,
1764  null,
1765  OperandTypes.family(SqlTypeFamily.ANY),
1766  SqlFunctionCategory.SYSTEM);
1767  }
1768 
1769  @Override
1770  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1771  assert opBinding.getOperandCount() == 1;
1772  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1773  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1774  }
1775  }
1776 
1777  /* OFFSET_IN_FRAGMENT() */
1778  public static class OffsetInFragment extends SqlFunction {
1779  public OffsetInFragment() {
1780  super("OFFSET_IN_FRAGMENT",
1781  SqlKind.OTHER_FUNCTION,
1782  null,
1783  null,
1784  OperandTypes.NILADIC,
1785  SqlFunctionCategory.SYSTEM);
1786  }
1787 
1788  @Override
1789  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1790  assert opBinding.getOperandCount() == 0;
1791  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1792  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1793  }
1794  }
1795 
1796  static class ApproxCountDistinct extends SqlAggFunction {
1798  super("APPROX_COUNT_DISTINCT",
1799  null,
1800  SqlKind.OTHER_FUNCTION,
1801  null,
1802  null,
1803  OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
1804  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
1805  SqlFunctionCategory.SYSTEM);
1806  }
1807 
1808  @Override
1809  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1810  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1811  return typeFactory.createSqlType(SqlTypeName.BIGINT);
1812  }
1813  }
1814 
1815  static class MapDAvg extends SqlAggFunction {
1817  super("AVG",
1818  null,
1819  SqlKind.OTHER_FUNCTION,
1820  null,
1821  null,
1822  OperandTypes.family(SqlTypeFamily.NUMERIC),
1823  SqlFunctionCategory.SYSTEM);
1824  }
1825 
1826  @Override
1827  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1828  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1829  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
1830  }
1831  }
1832 
1833  public static class Sample extends SqlAggFunction {
1834  public Sample() {
1835  super("SAMPLE",
1836  SqlKind.OTHER_FUNCTION,
1837  null,
1838  null,
1839  OperandTypes.ANY,
1840  SqlFunctionCategory.SYSTEM);
1841  }
1842 
1843  @Override
1844  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1845  return opBinding.getOperandType(0);
1846  }
1847  }
1848 
1849  // for backwards compatibility
1850  public static class LastSample extends SqlAggFunction {
1851  public LastSample() {
1852  super("LAST_SAMPLE",
1853  SqlKind.OTHER_FUNCTION,
1854  null,
1855  null,
1856  OperandTypes.ANY,
1857  SqlFunctionCategory.SYSTEM);
1858  }
1859 
1860  @Override
1861  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1862  return opBinding.getOperandType(0);
1863  }
1864  }
1865 
1866  static class ExtFunction extends SqlFunction {
1867  ExtFunction(final String name, final ExtensionFunction sig) {
1868  super(name,
1869  SqlKind.OTHER_FUNCTION,
1870  null,
1871  null,
1872  OperandTypes.family(sig.toSqlSignature()),
1873  sig.isRowUdf() ? SqlFunctionCategory.SYSTEM
1874  : SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION);
1875  isRowUdf = sig.isRowUdf();
1876  if (isRowUdf) {
1877  ret = sig.getSqlRet();
1878  outs = null;
1879  } else {
1880  ret = null;
1881  outs = sig.getSqlOuts();
1882  }
1883  }
1884 
1885  @Override
1886  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1887  if (isRowUdf) {
1888  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1889  return typeFactory.createTypeWithNullability(
1890  typeFactory.createSqlType(ret), true);
1891  } else {
1892  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1893  java.util.List<RelDataType> typeList = new java.util.ArrayList<RelDataType>();
1894  java.util.List<java.lang.String> fieldNameList =
1895  new java.util.ArrayList<java.lang.String>();
1896 
1897  for (int out_idx = 0; out_idx < outs.size(); ++out_idx) {
1898  // TODO: use the argument names of output columns as field names
1899  fieldNameList.add("out" + out_idx);
1900  typeList.add(typeFactory.createSqlType(outs.get(out_idx)));
1901  }
1902  return typeFactory.createStructType(typeList, fieldNameList);
1903  }
1904  }
1905 
1906  private final boolean isRowUdf;
1907  private final SqlTypeName ret; // used only by UDFs
1908  private final List<SqlTypeName> outs; // used only by UDTFs
1909  }
1910 
1911  //
1912  // Internal accessors for in-situ poly render queries
1913  //
1914  // The MapD_* varietals are deprecated. The OmniSci_Geo_* ones should be used
1915  // instead
1916  //
1917 
1918  static class MapD_GeoPolyBoundsPtr extends SqlFunction {
1920  super("MapD_GeoPolyBoundsPtr",
1921  SqlKind.OTHER_FUNCTION,
1922  null,
1923  null,
1924  OperandTypes.family(SqlTypeFamily.ANY),
1925  SqlFunctionCategory.SYSTEM);
1926  }
1927 
1928  @Override
1929  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1930  assert opBinding.getOperandCount() == 1;
1931  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1932  return typeFactory.createSqlType(SqlTypeName.BIGINT);
1933  }
1934  }
1935 
1936  static class MapD_GeoPolyRenderGroup extends SqlFunction {
1938  super("MapD_GeoPolyRenderGroup",
1939  SqlKind.OTHER_FUNCTION,
1940  null,
1941  null,
1942  OperandTypes.family(SqlTypeFamily.ANY),
1943  SqlFunctionCategory.SYSTEM);
1944  }
1945 
1946  @Override
1947  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1948  assert opBinding.getOperandCount() == 1;
1949  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1950  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1951  }
1952  }
1953 
1954  static class OmniSci_Geo_PolyBoundsPtr extends SqlFunction {
1956  super("OmniSci_Geo_PolyBoundsPtr",
1957  SqlKind.OTHER_FUNCTION,
1958  null,
1959  null,
1960  OperandTypes.family(SqlTypeFamily.ANY),
1961  SqlFunctionCategory.SYSTEM);
1962  }
1963 
1964  @Override
1965  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1966  assert opBinding.getOperandCount() == 1;
1967  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1968  return typeFactory.createSqlType(SqlTypeName.BIGINT);
1969  }
1970  }
1971 
1972  static class OmniSci_Geo_PolyRenderGroup extends SqlFunction {
1974  super("OmniSci_Geo_PolyRenderGroup",
1975  SqlKind.OTHER_FUNCTION,
1976  null,
1977  null,
1978  OperandTypes.family(SqlTypeFamily.ANY),
1979  SqlFunctionCategory.SYSTEM);
1980  }
1981 
1982  @Override
1983  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1984  assert opBinding.getOperandCount() == 1;
1985  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1986  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1987  }
1988  }
1989 
1990  static class convert_meters_to_pixel_width extends SqlFunction {
1992  super("convert_meters_to_pixel_width",
1993  SqlKind.OTHER_FUNCTION,
1994  null,
1995  null,
1996  OperandTypes.family(SqlTypeFamily.NUMERIC,
1997  SqlTypeFamily.ANY,
1998  SqlTypeFamily.NUMERIC,
1999  SqlTypeFamily.NUMERIC,
2000  SqlTypeFamily.NUMERIC,
2001  SqlTypeFamily.NUMERIC),
2002  SqlFunctionCategory.SYSTEM);
2003  }
2004 
2005  @Override
2006  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2007  assert opBinding.getOperandCount() == 6;
2008  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2009  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2010  }
2011  }
2012 
2013  static class convert_meters_to_pixel_height extends SqlFunction {
2015  super("convert_meters_to_pixel_height",
2016  SqlKind.OTHER_FUNCTION,
2017  null,
2018  null,
2019  OperandTypes.family(SqlTypeFamily.NUMERIC,
2020  SqlTypeFamily.ANY,
2021  SqlTypeFamily.NUMERIC,
2022  SqlTypeFamily.NUMERIC,
2023  SqlTypeFamily.NUMERIC,
2024  SqlTypeFamily.NUMERIC),
2025  SqlFunctionCategory.SYSTEM);
2026  }
2027 
2028  @Override
2029  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2030  assert opBinding.getOperandCount() == 6;
2031  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2032  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2033  }
2034  }
2035 
2036  static class is_point_in_view extends SqlFunction {
2038  super("is_point_in_view",
2039  SqlKind.OTHER_FUNCTION,
2040  null,
2041  null,
2042  OperandTypes.family(SqlTypeFamily.ANY,
2043  SqlTypeFamily.NUMERIC,
2044  SqlTypeFamily.NUMERIC,
2045  SqlTypeFamily.NUMERIC,
2046  SqlTypeFamily.NUMERIC),
2047  SqlFunctionCategory.SYSTEM);
2048  }
2049 
2050  @Override
2051  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2052  assert opBinding.getOperandCount() == 5;
2053  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2054  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
2055  }
2056  }
2057 
2058  static class is_point_size_in_view extends SqlFunction {
2060  super("is_point_size_in_view",
2061  SqlKind.OTHER_FUNCTION,
2062  null,
2063  null,
2064  OperandTypes.family(SqlTypeFamily.ANY,
2065  SqlTypeFamily.NUMERIC,
2066  SqlTypeFamily.NUMERIC,
2067  SqlTypeFamily.NUMERIC,
2068  SqlTypeFamily.NUMERIC,
2069  SqlTypeFamily.NUMERIC),
2070  SqlFunctionCategory.SYSTEM);
2071  }
2072 
2073  @Override
2074  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2075  assert opBinding.getOperandCount() == 6;
2076  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2077  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
2078  }
2079  }
2080 
2081  public static class usTimestamp extends SqlFunction {
2082  public usTimestamp() {
2083  super("usTIMESTAMP",
2084  SqlKind.OTHER_FUNCTION,
2085  null,
2086  null,
2087  OperandTypes.STRING,
2088  SqlFunctionCategory.SYSTEM);
2089  }
2090 
2091  @Override
2092  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2093  assert opBinding.getOperandCount() == 1;
2094  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2095  return typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 6);
2096  }
2097  }
2098 
2099  public static class nsTimestamp extends SqlFunction {
2100  public nsTimestamp() {
2101  super("nsTIMESTAMP",
2102  SqlKind.OTHER_FUNCTION,
2103  null,
2104  null,
2105  OperandTypes.STRING,
2106  SqlFunctionCategory.SYSTEM);
2107  }
2108 
2109  @Override
2110  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2111  assert opBinding.getOperandCount() == 1;
2112  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2113  return typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 9);
2114  }
2115  }
2116 }
2117 
2118 // 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)
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)
static final SqlArrayValueConstructorAllowingEmpty ARRAY_VALUE_CONSTRUCTOR
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)
tuple STRING
Definition: dtypes.py:31
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)
static java.util.List< SqlTypeFamily > signature()
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)
string name
Definition: setup.py:35
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > signature()
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)
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)