OmniSciDB  04ee39c94c
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.SqlFunction;
27 import org.apache.calcite.sql.SqlFunctionCategory;
28 import org.apache.calcite.sql.SqlIdentifier;
29 import org.apache.calcite.sql.SqlKind;
30 import org.apache.calcite.sql.SqlOperator;
31 import org.apache.calcite.sql.SqlOperatorBinding;
32 import org.apache.calcite.sql.SqlOperatorTable;
33 import org.apache.calcite.sql.SqlSyntax;
34 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
35 import org.apache.calcite.sql.type.OperandTypes;
36 import org.apache.calcite.sql.type.SqlTypeFamily;
37 import org.apache.calcite.sql.type.SqlTypeName;
38 import org.apache.calcite.sql.util.ChainedSqlOperatorTable;
39 import org.apache.calcite.sql.util.ListSqlOperatorTable;
40 import org.apache.calcite.sql.util.ReflectiveSqlOperatorTable;
41 import org.apache.calcite.sql.validate.SqlNameMatcher;
42 
43 import java.lang.reflect.Field;
44 import java.util.HashSet;
45 import java.util.Iterator;
46 import java.util.List;
47 import java.util.Map;
48 
49 class CaseInsensitiveListSqlOperatorTable extends ListSqlOperatorTable {
50  @Override
51  public void lookupOperatorOverloads(SqlIdentifier opName,
52  SqlFunctionCategory category,
53  SqlSyntax syntax,
54  List<SqlOperator> operatorList,
55  SqlNameMatcher nameMatcher) {
56  for (SqlOperator operator : this.getOperatorList()) {
57  if (operator.getSyntax() != syntax) {
58  continue;
59  }
60  if (!opName.isSimple()
61  || !nameMatcher.matches(operator.getName(), opName.getSimple())) {
62  continue;
63  }
64  SqlFunctionCategory functionCategory;
65  if (operator instanceof SqlFunction) {
66  functionCategory = ((SqlFunction) operator).getFunctionType();
67  } else {
68  functionCategory = SqlFunctionCategory.SYSTEM;
69  }
70  if (category != functionCategory
71  && category != SqlFunctionCategory.USER_DEFINED_FUNCTION) {
72  continue;
73  }
74  operatorList.add(operator);
75  }
76  }
77 }
78 
83 public class MapDSqlOperatorTable extends ChainedSqlOperatorTable {
84  static {
85  try {
86  // some nasty bit to remove the std APPROX_COUNT_DISTINCT function definition
87  {
88  Field f = ReflectiveSqlOperatorTable.class.getDeclaredField(
89  "caseSensitiveOperators");
90  f.setAccessible(true);
91  Multimap operators = (Multimap) f.get(SqlStdOperatorTable.instance());
92  for (Iterator i = operators.entries().iterator(); i.hasNext();) {
93  Map.Entry entry = (Map.Entry) i.next();
94  if (entry.getValue() == SqlStdOperatorTable.APPROX_COUNT_DISTINCT
95  || entry.getValue() == SqlStdOperatorTable.AVG) {
96  i.remove();
97  }
98  }
99  }
100 
101  {
102  Field f = ReflectiveSqlOperatorTable.class.getDeclaredField(
103  "caseInsensitiveOperators");
104  f.setAccessible(true);
105  Multimap operators = (Multimap) f.get(SqlStdOperatorTable.instance());
106  for (Iterator i = operators.entries().iterator(); i.hasNext();) {
107  Map.Entry entry = (Map.Entry) i.next();
108  if (entry.getValue() == SqlStdOperatorTable.APPROX_COUNT_DISTINCT
109  || entry.getValue() == SqlStdOperatorTable.AVG) {
110  i.remove();
111  }
112  }
113  }
114 
115  } catch (Exception e) {
116  throw new RuntimeException(e);
117  }
118 
119  // register our approx count distinct against std table
120  // SqlStdOperatorTable.instance().register(new ApproxCountDistinct());
121  }
122 
127  // ~ Instance fields --------------------------------------------------------
128  private final ListSqlOperatorTable listOpTab;
129 
130  // ~ Constructors -----------------------------------------------------------
131  public MapDSqlOperatorTable(SqlOperatorTable parentTable) {
132  super(ImmutableList.of(parentTable, new CaseInsensitiveListSqlOperatorTable()));
133  listOpTab = (ListSqlOperatorTable) tableList.get(1);
134  }
135 
136  // ~ Methods ----------------------------------------------------------------
142  public void addOperator(SqlOperator op) {
143  listOpTab.add(op);
144  }
145 
146  public static void addUDF(
147  MapDSqlOperatorTable opTab, final Map<String, ExtensionFunction> extSigs) {
148  // Don't use anonymous inner classes. They can't be instantiated
149  // using reflection when we are deserializing from JSON.
150  // opTab.addOperator(new RampFunction());
151  // opTab.addOperator(new DedupFunction());
152  opTab.addOperator(new MyUDFFunction());
153  opTab.addOperator(new PgUnnest());
154  opTab.addOperator(new Any());
155  opTab.addOperator(new All());
156  opTab.addOperator(new Now());
157  opTab.addOperator(new Datetime());
158  opTab.addOperator(new PgExtract());
159  opTab.addOperator(new Dateadd());
160  opTab.addOperator(new Datediff());
161  opTab.addOperator(new Datepart());
162  opTab.addOperator(new PgDateTrunc());
163  opTab.addOperator(new Length());
164  opTab.addOperator(new CharLength());
165  opTab.addOperator(new KeyForString());
166  opTab.addOperator(new ArrayLength());
167  opTab.addOperator(new PgILike());
168  opTab.addOperator(new RegexpLike());
169  opTab.addOperator(new Likely());
170  opTab.addOperator(new Unlikely());
171  opTab.addOperator(new Sign());
172  opTab.addOperator(new Truncate());
173  opTab.addOperator(new ST_Contains());
174  opTab.addOperator(new ST_Intersects());
175  opTab.addOperator(new ST_Disjoint());
176  opTab.addOperator(new ST_Within());
177  opTab.addOperator(new ST_DWithin());
178  opTab.addOperator(new ST_DFullyWithin());
179  opTab.addOperator(new ST_Distance());
180  opTab.addOperator(new ST_MaxDistance());
181  opTab.addOperator(new ST_GeogFromText());
182  opTab.addOperator(new ST_GeomFromText());
183  opTab.addOperator(new ST_Transform());
184  opTab.addOperator(new ST_X());
185  opTab.addOperator(new ST_Y());
186  opTab.addOperator(new ST_XMin());
187  opTab.addOperator(new ST_XMax());
188  opTab.addOperator(new ST_YMin());
189  opTab.addOperator(new ST_YMax());
190  opTab.addOperator(new ST_PointN());
191  opTab.addOperator(new ST_StartPoint());
192  opTab.addOperator(new ST_EndPoint());
193  opTab.addOperator(new ST_Length());
194  opTab.addOperator(new ST_Perimeter());
195  opTab.addOperator(new ST_Area());
196  opTab.addOperator(new ST_NPoints());
197  opTab.addOperator(new ST_NRings());
198  opTab.addOperator(new ST_SRID());
199  opTab.addOperator(new ST_SetSRID());
200  opTab.addOperator(new ST_Point());
201  opTab.addOperator(new CastToGeography());
202  opTab.addOperator(new OffsetInFragment());
203  opTab.addOperator(new ApproxCountDistinct());
204  opTab.addOperator(new MapDAvg());
205  opTab.addOperator(new Sample());
206  opTab.addOperator(new LastSample());
207  // MapD_Geo* are deprecated in place of the OmniSci_Geo_ varietals
208  opTab.addOperator(new MapD_GeoPolyBoundsPtr());
214  opTab.addOperator(new is_point_in_view());
215  opTab.addOperator(new is_point_size_in_view());
216  opTab.addOperator(new usTimestamp());
217  opTab.addOperator(new nsTimestamp());
218  if (extSigs == null) {
219  return;
220  }
221  HashSet<String> demangledNames = new HashSet<String>();
222  for (Map.Entry<String, ExtensionFunction> extSig : extSigs.entrySet()) {
223  final String demangledName = dropSuffix(extSig.getKey());
224  if (demangledNames.contains(demangledName)) {
225  continue;
226  }
227  demangledNames.add(demangledName);
228  opTab.addOperator(new ExtFunction(extSig.getKey(), extSig.getValue()));
229  }
230  }
231 
232  private static String dropSuffix(final String str) {
233  int suffix_idx = str.indexOf("__");
234  if (suffix_idx == -1) {
235  return str;
236  }
237  assert suffix_idx > 0;
238  return str.substring(0, suffix_idx - 1);
239  }
240 
244  public static class RampFunction extends SqlFunction {
245  public RampFunction() {
246  super("RAMP",
247  SqlKind.OTHER_FUNCTION,
248  null,
249  null,
250  OperandTypes.NUMERIC,
251  SqlFunctionCategory.USER_DEFINED_FUNCTION);
252  }
253 
254  @Override
255  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
256  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
257  return typeFactory.builder().add("I", SqlTypeName.INTEGER).build();
258  }
259  }
260 
264  public static class DedupFunction extends SqlFunction {
265  public DedupFunction() {
266  super("DEDUP",
267  SqlKind.OTHER_FUNCTION,
268  null,
269  null,
270  OperandTypes.VARIADIC,
271  SqlFunctionCategory.USER_DEFINED_FUNCTION);
272  }
273 
274  @Override
275  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
276  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
277  return typeFactory.builder().add("NAME", SqlTypeName.VARCHAR, 1024).build();
278  }
279  }
280 
285  public static class MyUDFFunction extends SqlFunction {
286  public MyUDFFunction() {
287  super("MyUDF",
288  SqlKind.OTHER_FUNCTION,
289  null,
290  null,
291  OperandTypes.STRING_STRING,
292  SqlFunctionCategory.SYSTEM);
293  }
294 
295  @Override
296  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
297  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
298  return typeFactory.createSqlType(SqlTypeName.BIGINT);
299  }
300  }
301 
302  /* Postgres-style UNNEST */
303  public static class PgUnnest extends SqlFunction {
304  public PgUnnest() {
305  super("PG_UNNEST",
306  SqlKind.OTHER_FUNCTION,
307  null,
308  null,
309  OperandTypes.ARRAY,
310  SqlFunctionCategory.SYSTEM);
311  }
312 
313  @Override
314  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
315  assert opBinding.getOperandCount() == 1;
316  RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
317  assert elem_type != null;
318  return elem_type;
319  }
320  }
321 
322  /* ANY qualifier */
323  public static class Any extends SqlFunction {
324  public Any() {
325  super("PG_ANY",
326  SqlKind.OTHER_FUNCTION,
327  null,
328  null,
329  OperandTypes.ARRAY,
330  SqlFunctionCategory.SYSTEM);
331  }
332 
333  @Override
334  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
335  assert opBinding.getOperandCount() == 1;
336  RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
337  assert elem_type != null;
338  return elem_type;
339  }
340  }
341 
342  /* ALL qualifier */
343  public static class All extends SqlFunction {
344  public All() {
345  super("PG_ALL",
346  SqlKind.OTHER_FUNCTION,
347  null,
348  null,
349  OperandTypes.ARRAY,
350  SqlFunctionCategory.SYSTEM);
351  }
352 
353  @Override
354  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
355  assert opBinding.getOperandCount() == 1;
356  RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
357  assert elem_type != null;
358  return elem_type;
359  }
360  }
361 
362  /* NOW() */
363  public static class Now extends SqlFunction {
364  public Now() {
365  super("NOW",
366  SqlKind.OTHER_FUNCTION,
367  null,
368  null,
369  OperandTypes.NILADIC,
370  SqlFunctionCategory.SYSTEM);
371  }
372 
373  @Override
374  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
375  assert opBinding.getOperandCount() == 0;
376  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
377  return typeFactory.createSqlType(SqlTypeName.TIMESTAMP);
378  }
379  }
380 
381  /* DATETIME */
382  public static class Datetime extends SqlFunction {
383  public Datetime() {
384  super("DATETIME",
385  SqlKind.OTHER_FUNCTION,
386  null,
387  null,
388  OperandTypes.STRING,
389  SqlFunctionCategory.SYSTEM);
390  }
391 
392  @Override
393  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
394  assert opBinding.getOperandCount() == 1;
395  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
396  return typeFactory.createSqlType(
397  SqlTypeName.TIMESTAMP, opBinding.getOperandType(0).getPrecision());
398  }
399  }
400 
401  /* Postgres-style EXTRACT */
402  public static class PgExtract extends SqlFunction {
403  public PgExtract() {
404  super("PG_EXTRACT",
405  SqlKind.OTHER_FUNCTION,
406  null,
407  null,
408  OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
409  SqlFunctionCategory.SYSTEM);
410  }
411 
412  @Override
413  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
414  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
415  return typeFactory.createTypeWithNullability(
416  typeFactory.createSqlType(SqlTypeName.BIGINT),
417  opBinding.getOperandType(1).isNullable());
418  }
419  }
420 
421  public static class Datepart extends SqlFunction {
422  public Datepart() {
423  super("DATEPART",
424  SqlKind.OTHER_FUNCTION,
425  null,
426  null,
427  OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
428  SqlFunctionCategory.TIMEDATE);
429  }
430 
431  @Override
432  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
433  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
434  return typeFactory.createTypeWithNullability(
435  typeFactory.createSqlType(SqlTypeName.BIGINT),
436  opBinding.getOperandType(1).isNullable());
437  }
438  }
439 
440  public static class Dateadd extends SqlFunction {
441  public Dateadd() {
442  super("DATEADD",
443  SqlKind.OTHER_FUNCTION,
444  null,
445  null,
446  OperandTypes.family(SqlTypeFamily.STRING,
447  SqlTypeFamily.INTEGER,
448  SqlTypeFamily.DATETIME),
449  SqlFunctionCategory.TIMEDATE);
450  }
451 
452  @Override
453  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
454  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
455  return typeFactory.createTypeWithNullability(
456  typeFactory.createSqlType(
457  SqlTypeName.TIMESTAMP, opBinding.getOperandType(2).getPrecision()),
458  opBinding.getOperandType(2).isNullable());
459  }
460  }
461 
462  public static class Datediff extends SqlFunction {
463  public Datediff() {
464  super("DATEDIFF",
465  SqlKind.OTHER_FUNCTION,
466  null,
467  null,
468  OperandTypes.family(SqlTypeFamily.STRING,
469  SqlTypeFamily.DATETIME,
470  SqlTypeFamily.DATETIME),
471  SqlFunctionCategory.TIMEDATE);
472  }
473 
474  @Override
475  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
476  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
477  return typeFactory.createTypeWithNullability(
478  typeFactory.createSqlType(SqlTypeName.BIGINT),
479  opBinding.getOperandType(1).isNullable()
480  || opBinding.getOperandType(2).isNullable());
481  }
482  }
483 
484  /* Postgres-style DATE_TRUNC */
485  public static class PgDateTrunc extends SqlFunction {
486  public PgDateTrunc() {
487  super("PG_DATE_TRUNC",
488  SqlKind.OTHER_FUNCTION,
489  null,
490  null,
491  OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
492  SqlFunctionCategory.SYSTEM);
493  }
494 
495  @Override
496  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
497  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
498  return typeFactory.createTypeWithNullability(
499  typeFactory.createSqlType(
500  SqlTypeName.TIMESTAMP, opBinding.getOperandType(1).getPrecision()),
501  opBinding.getOperandType(1).isNullable());
502  }
503  }
504 
505  public static class Length extends SqlFunction {
506  public Length() {
507  super("LENGTH",
508  SqlKind.OTHER_FUNCTION,
509  null,
510  null,
511  OperandTypes.STRING,
512  SqlFunctionCategory.SYSTEM);
513  }
514 
515  @Override
516  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
517  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
518  return typeFactory.createSqlType(SqlTypeName.INTEGER);
519  }
520  }
521 
522  public static class CharLength extends SqlFunction {
523  public CharLength() {
524  super("CHAR_LENGTH",
525  SqlKind.OTHER_FUNCTION,
526  null,
527  null,
528  OperandTypes.STRING,
529  SqlFunctionCategory.SYSTEM);
530  }
531 
532  @Override
533  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
534  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
535  return typeFactory.createSqlType(SqlTypeName.INTEGER);
536  }
537  }
538 
539  public static class KeyForString extends SqlFunction {
540  public KeyForString() {
541  super("KEY_FOR_STRING",
542  SqlKind.OTHER_FUNCTION,
543  null,
544  null,
545  OperandTypes.STRING,
546  SqlFunctionCategory.SYSTEM);
547  }
548 
549  @Override
550  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
551  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
552  return typeFactory.createTypeWithNullability(
553  typeFactory.createSqlType(SqlTypeName.INTEGER),
554  opBinding.getOperandType(0).isNullable());
555  }
556  }
557 
558  public static class ArrayLength extends SqlFunction {
559  public ArrayLength() {
560  super("ARRAY_LENGTH",
561  SqlKind.OTHER_FUNCTION,
562  null,
563  null,
564  OperandTypes.ARRAY,
565  SqlFunctionCategory.SYSTEM);
566  }
567 
568  @Override
569  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
570  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
571  return typeFactory.createSqlType(SqlTypeName.INTEGER);
572  }
573  }
574 
575  public static class PgILike extends SqlFunction {
576  public PgILike() {
577  super("PG_ILIKE",
578  SqlKind.OTHER_FUNCTION,
579  null,
580  null,
581  OperandTypes.family(getSignatureFamilies(), new EscapeOptional()),
582  SqlFunctionCategory.SYSTEM);
583  }
584 
585  private static java.util.List<SqlTypeFamily> getSignatureFamilies() {
586  java.util.ArrayList<SqlTypeFamily> families =
587  new java.util.ArrayList<SqlTypeFamily>();
588  families.add(SqlTypeFamily.STRING);
589  families.add(SqlTypeFamily.STRING);
590  families.add(SqlTypeFamily.STRING);
591  return families;
592  }
593 
594  private static class EscapeOptional
595  implements java.util.function.Predicate<Integer>, Predicate<Integer> {
596  @Override
597  public boolean test(Integer t) {
598  return apply(t);
599  }
600 
601  @Override
602  public boolean apply(Integer t) {
603  return t == 2;
604  }
605  }
606 
607  @Override
608  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
609  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
610  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
611  }
612  }
613 
614  public static class RegexpLike extends SqlFunction {
615  public RegexpLike() {
616  super("REGEXP_LIKE",
617  SqlKind.OTHER_FUNCTION,
618  null,
619  null,
620  OperandTypes.family(getSignatureFamilies(), new EscapeOptional()),
621  SqlFunctionCategory.SYSTEM);
622  }
623 
624  private static java.util.List<SqlTypeFamily> getSignatureFamilies() {
625  java.util.ArrayList<SqlTypeFamily> families =
626  new java.util.ArrayList<SqlTypeFamily>();
627  families.add(SqlTypeFamily.STRING);
628  families.add(SqlTypeFamily.STRING);
629  families.add(SqlTypeFamily.STRING);
630  return families;
631  }
632 
633  private static class EscapeOptional
634  implements java.util.function.Predicate<Integer>, Predicate<Integer> {
635  @Override
636  public boolean test(Integer t) {
637  return apply(t);
638  }
639 
640  public boolean apply(Integer t) {
641  return t == 2;
642  }
643  }
644 
645  @Override
646  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
647  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
648  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
649  }
650  }
651 
652  public static class Likely extends SqlFunction {
653  public Likely() {
654  super("LIKELY",
655  SqlKind.OTHER_FUNCTION,
656  null,
657  null,
658  OperandTypes.BOOLEAN,
659  SqlFunctionCategory.SYSTEM);
660  }
661 
662  @Override
663  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
664  return opBinding.getOperandType(0);
665  }
666  }
667 
668  public static class Unlikely extends SqlFunction {
669  public Unlikely() {
670  super("UNLIKELY",
671  SqlKind.OTHER_FUNCTION,
672  null,
673  null,
674  OperandTypes.BOOLEAN,
675  SqlFunctionCategory.SYSTEM);
676  }
677 
678  @Override
679  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
680  return opBinding.getOperandType(0);
681  }
682  }
683 
684  public static class Sign extends SqlFunction {
685  public Sign() {
686  super("SIGN",
687  SqlKind.OTHER_FUNCTION,
688  null,
689  null,
690  OperandTypes.NUMERIC,
691  SqlFunctionCategory.NUMERIC);
692  }
693 
694  @Override
695  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
696  return opBinding.getOperandType(0);
697  }
698  }
699 
700  static class Truncate extends SqlFunction {
702  super("TRUNCATE",
703  SqlKind.OTHER_FUNCTION,
704  null,
705  null,
706  OperandTypes.family(signature()),
707  SqlFunctionCategory.NUMERIC);
708  }
709 
710  @Override
711  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
712  assert opBinding.getOperandCount() == 2;
713  return opBinding.getOperandType(0);
714  }
715 
716  private static java.util.List<SqlTypeFamily> signature() {
717  java.util.List<SqlTypeFamily> truncate_sig =
718  new java.util.ArrayList<SqlTypeFamily>();
719  truncate_sig.add(SqlTypeFamily.NUMERIC);
720  truncate_sig.add(SqlTypeFamily.INTEGER);
721  return truncate_sig;
722  }
723  }
724 
725  static class ST_Contains extends SqlFunction {
727  super("ST_Contains",
728  SqlKind.OTHER_FUNCTION,
729  null,
730  null,
731  OperandTypes.family(signature()),
732  SqlFunctionCategory.SYSTEM);
733  }
734 
735  @Override
736  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
737  assert opBinding.getOperandCount() == 2;
738  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
739  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
740  }
741 
742  private static java.util.List<SqlTypeFamily> signature() {
743  java.util.List<SqlTypeFamily> st_contains_sig =
744  new java.util.ArrayList<SqlTypeFamily>();
745  st_contains_sig.add(SqlTypeFamily.ANY);
746  st_contains_sig.add(SqlTypeFamily.ANY);
747  return st_contains_sig;
748  }
749  }
750 
751  static class ST_Intersects extends SqlFunction {
753  super("ST_Intersects",
754  SqlKind.OTHER_FUNCTION,
755  null,
756  null,
757  OperandTypes.family(signature()),
758  SqlFunctionCategory.SYSTEM);
759  }
760 
761  @Override
762  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
763  assert opBinding.getOperandCount() == 2;
764  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
765  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
766  }
767 
768  private static java.util.List<SqlTypeFamily> signature() {
769  java.util.List<SqlTypeFamily> st_intersects_sig =
770  new java.util.ArrayList<SqlTypeFamily>();
771  st_intersects_sig.add(SqlTypeFamily.ANY);
772  st_intersects_sig.add(SqlTypeFamily.ANY);
773  return st_intersects_sig;
774  }
775  }
776 
777  static class ST_Disjoint extends SqlFunction {
779  super("ST_Disjoint",
780  SqlKind.OTHER_FUNCTION,
781  null,
782  null,
783  OperandTypes.family(signature()),
784  SqlFunctionCategory.SYSTEM);
785  }
786 
787  @Override
788  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
789  assert opBinding.getOperandCount() == 2;
790  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
791  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
792  }
793 
794  private static java.util.List<SqlTypeFamily> signature() {
795  java.util.List<SqlTypeFamily> st_disjoint_sig =
796  new java.util.ArrayList<SqlTypeFamily>();
797  st_disjoint_sig.add(SqlTypeFamily.ANY);
798  st_disjoint_sig.add(SqlTypeFamily.ANY);
799  return st_disjoint_sig;
800  }
801  }
802 
803  static class ST_Within extends SqlFunction {
805  super("ST_Within",
806  SqlKind.OTHER_FUNCTION,
807  null,
808  null,
809  OperandTypes.family(signature()),
810  SqlFunctionCategory.SYSTEM);
811  }
812 
813  @Override
814  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
815  assert opBinding.getOperandCount() == 2;
816  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
817  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
818  }
819 
820  private static java.util.List<SqlTypeFamily> signature() {
821  java.util.List<SqlTypeFamily> st_within_sig =
822  new java.util.ArrayList<SqlTypeFamily>();
823  st_within_sig.add(SqlTypeFamily.ANY);
824  st_within_sig.add(SqlTypeFamily.ANY);
825  return st_within_sig;
826  }
827  }
828 
829  static class ST_DWithin extends SqlFunction {
831  super("ST_DWithin",
832  SqlKind.OTHER_FUNCTION,
833  null,
834  null,
835  OperandTypes.family(signature()),
836  SqlFunctionCategory.SYSTEM);
837  }
838 
839  @Override
840  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
841  assert opBinding.getOperandCount() == 3;
842  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
843  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
844  }
845 
846  private static java.util.List<SqlTypeFamily> signature() {
847  java.util.List<SqlTypeFamily> st_dwithin_sig =
848  new java.util.ArrayList<SqlTypeFamily>();
849  st_dwithin_sig.add(SqlTypeFamily.ANY);
850  st_dwithin_sig.add(SqlTypeFamily.ANY);
851  st_dwithin_sig.add(SqlTypeFamily.NUMERIC);
852  return st_dwithin_sig;
853  }
854  }
855 
856  static class ST_DFullyWithin extends SqlFunction {
858  super("ST_DFullyWithin",
859  SqlKind.OTHER_FUNCTION,
860  null,
861  null,
862  OperandTypes.family(signature()),
863  SqlFunctionCategory.SYSTEM);
864  }
865 
866  @Override
867  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
868  assert opBinding.getOperandCount() == 3;
869  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
870  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
871  }
872 
873  private static java.util.List<SqlTypeFamily> signature() {
874  java.util.List<SqlTypeFamily> st_dwithin_sig =
875  new java.util.ArrayList<SqlTypeFamily>();
876  st_dwithin_sig.add(SqlTypeFamily.ANY);
877  st_dwithin_sig.add(SqlTypeFamily.ANY);
878  st_dwithin_sig.add(SqlTypeFamily.NUMERIC);
879  return st_dwithin_sig;
880  }
881  }
882 
883  static class ST_Distance extends SqlFunction {
885  super("ST_Distance",
886  SqlKind.OTHER_FUNCTION,
887  null,
888  null,
889  OperandTypes.family(signature()),
890  SqlFunctionCategory.SYSTEM);
891  }
892 
893  @Override
894  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
895  assert opBinding.getOperandCount() == 2;
896  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
897  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
898  }
899 
900  private static java.util.List<SqlTypeFamily> signature() {
901  java.util.List<SqlTypeFamily> st_distance_sig =
902  new java.util.ArrayList<SqlTypeFamily>();
903  st_distance_sig.add(SqlTypeFamily.ANY);
904  st_distance_sig.add(SqlTypeFamily.ANY);
905  return st_distance_sig;
906  }
907  }
908 
909  static class ST_MaxDistance extends SqlFunction {
911  super("ST_MaxDistance",
912  SqlKind.OTHER_FUNCTION,
913  null,
914  null,
915  OperandTypes.family(signature()),
916  SqlFunctionCategory.SYSTEM);
917  }
918 
919  @Override
920  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
921  assert opBinding.getOperandCount() == 2;
922  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
923  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
924  }
925 
926  private static java.util.List<SqlTypeFamily> signature() {
927  java.util.List<SqlTypeFamily> st_maxdistance_sig =
928  new java.util.ArrayList<SqlTypeFamily>();
929  st_maxdistance_sig.add(SqlTypeFamily.ANY);
930  st_maxdistance_sig.add(SqlTypeFamily.ANY);
931  return st_maxdistance_sig;
932  }
933  }
934 
935  static class ST_GeogFromText extends SqlFunction {
937  super("ST_GeogFromText",
938  SqlKind.OTHER_FUNCTION,
939  null,
940  null,
941  OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
942  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
943  SqlFunctionCategory.SYSTEM);
944  }
945 
946  @Override
947  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
948  assert opBinding.getOperandCount() == 1;
949  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
950  return typeFactory.createSqlType(SqlTypeName.INTEGER);
951  }
952  }
953 
954  static class ST_GeomFromText extends SqlFunction {
956  super("ST_GeomFromText",
957  SqlKind.OTHER_FUNCTION,
958  null,
959  null,
960  OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
961  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
962  SqlFunctionCategory.SYSTEM);
963  }
964 
965  @Override
966  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
967  assert opBinding.getOperandCount() == 1;
968  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
969  return typeFactory.createSqlType(SqlTypeName.INTEGER);
970  }
971  }
972 
973  static class ST_Transform extends SqlFunction {
975  super("ST_Transform",
976  SqlKind.OTHER_FUNCTION,
977  null,
978  null,
979  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
980  SqlFunctionCategory.SYSTEM);
981  }
982 
983  @Override
984  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
985  assert opBinding.getOperandCount() == 1;
986  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
987  return typeFactory.createSqlType(SqlTypeName.INTEGER);
988  }
989  }
990 
991  static class ST_X extends SqlFunction {
992  ST_X() {
993  super("ST_X",
994  SqlKind.OTHER_FUNCTION,
995  null,
996  null,
997  OperandTypes.family(SqlTypeFamily.ANY),
998  SqlFunctionCategory.SYSTEM);
999  }
1000 
1001  @Override
1002  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1003  assert opBinding.getOperandCount() == 1;
1004  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1005  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
1006  }
1007  }
1008 
1009  static class ST_Y extends SqlFunction {
1010  ST_Y() {
1011  super("ST_Y",
1012  SqlKind.OTHER_FUNCTION,
1013  null,
1014  null,
1015  OperandTypes.family(SqlTypeFamily.ANY),
1016  SqlFunctionCategory.SYSTEM);
1017  }
1018 
1019  @Override
1020  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1021  assert opBinding.getOperandCount() == 1;
1022  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1023  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
1024  }
1025  }
1026 
1027  static class ST_XMin extends SqlFunction {
1029  super("ST_XMin",
1030  SqlKind.OTHER_FUNCTION,
1031  null,
1032  null,
1033  OperandTypes.family(SqlTypeFamily.ANY),
1034  SqlFunctionCategory.SYSTEM);
1035  }
1036 
1037  @Override
1038  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1039  assert opBinding.getOperandCount() == 1;
1040  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1041  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
1042  }
1043  }
1044 
1045  static class ST_XMax extends SqlFunction {
1047  super("ST_XMax",
1048  SqlKind.OTHER_FUNCTION,
1049  null,
1050  null,
1051  OperandTypes.family(SqlTypeFamily.ANY),
1052  SqlFunctionCategory.SYSTEM);
1053  }
1054 
1055  @Override
1056  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1057  assert opBinding.getOperandCount() == 1;
1058  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1059  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
1060  }
1061  }
1062 
1063  static class ST_YMin extends SqlFunction {
1065  super("ST_YMin",
1066  SqlKind.OTHER_FUNCTION,
1067  null,
1068  null,
1069  OperandTypes.family(SqlTypeFamily.ANY),
1070  SqlFunctionCategory.SYSTEM);
1071  }
1072 
1073  @Override
1074  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1075  assert opBinding.getOperandCount() == 1;
1076  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1077  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
1078  }
1079  }
1080 
1081  static class ST_YMax extends SqlFunction {
1083  super("ST_YMax",
1084  SqlKind.OTHER_FUNCTION,
1085  null,
1086  null,
1087  OperandTypes.family(SqlTypeFamily.ANY),
1088  SqlFunctionCategory.SYSTEM);
1089  }
1090 
1091  @Override
1092  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1093  assert opBinding.getOperandCount() == 1;
1094  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1095  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
1096  }
1097  }
1098 
1099  static class ST_PointN extends SqlFunction {
1101  super("ST_PointN",
1102  SqlKind.OTHER_FUNCTION,
1103  null,
1104  null,
1105  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
1106  SqlFunctionCategory.SYSTEM);
1107  }
1108 
1109  @Override
1110  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1111  assert opBinding.getOperandCount() == 1;
1112  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1113  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1114  }
1115  }
1116 
1117  static class ST_EndPoint extends SqlFunction {
1119  super("ST_EndPoint",
1120  SqlKind.OTHER_FUNCTION,
1121  null,
1122  null,
1123  OperandTypes.family(SqlTypeFamily.ANY),
1124  SqlFunctionCategory.SYSTEM);
1125  }
1126 
1127  @Override
1128  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1129  assert opBinding.getOperandCount() == 1;
1130  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1131  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1132  }
1133  }
1134 
1135  static class ST_StartPoint extends SqlFunction {
1137  super("ST_StartPoint",
1138  SqlKind.OTHER_FUNCTION,
1139  null,
1140  null,
1141  OperandTypes.family(SqlTypeFamily.ANY),
1142  SqlFunctionCategory.SYSTEM);
1143  }
1144 
1145  @Override
1146  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1147  assert opBinding.getOperandCount() == 1;
1148  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1149  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1150  }
1151  }
1152 
1153  static class ST_Length extends SqlFunction {
1155  super("ST_Length",
1156  SqlKind.OTHER_FUNCTION,
1157  null,
1158  null,
1159  OperandTypes.family(SqlTypeFamily.ANY),
1160  SqlFunctionCategory.SYSTEM);
1161  }
1162 
1163  @Override
1164  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1165  assert opBinding.getOperandCount() == 1;
1166  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1167  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
1168  }
1169  }
1170 
1171  static class ST_Perimeter extends SqlFunction {
1173  super("ST_Perimeter",
1174  SqlKind.OTHER_FUNCTION,
1175  null,
1176  null,
1177  OperandTypes.family(SqlTypeFamily.ANY),
1178  SqlFunctionCategory.SYSTEM);
1179  }
1180 
1181  @Override
1182  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1183  assert opBinding.getOperandCount() == 1;
1184  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1185  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
1186  }
1187  }
1188 
1189  static class ST_Area extends SqlFunction {
1191  super("ST_Area",
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.createSqlType(SqlTypeName.DOUBLE);
1204  }
1205  }
1206 
1207  static class ST_NPoints extends SqlFunction {
1209  super("ST_NPoints",
1210  SqlKind.OTHER_FUNCTION,
1211  null,
1212  null,
1213  OperandTypes.family(SqlTypeFamily.ANY),
1214  SqlFunctionCategory.SYSTEM);
1215  }
1216 
1217  @Override
1218  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1219  assert opBinding.getOperandCount() == 1;
1220  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1221  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1222  }
1223  }
1224 
1225  static class ST_NRings extends SqlFunction {
1227  super("ST_NRings",
1228  SqlKind.OTHER_FUNCTION,
1229  null,
1230  null,
1231  OperandTypes.family(SqlTypeFamily.ANY),
1232  SqlFunctionCategory.SYSTEM);
1233  }
1234 
1235  @Override
1236  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1237  assert opBinding.getOperandCount() == 1;
1238  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1239  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1240  }
1241  }
1242 
1243  static class ST_SRID extends SqlFunction {
1245  super("ST_SRID",
1246  SqlKind.OTHER_FUNCTION,
1247  null,
1248  null,
1249  OperandTypes.family(SqlTypeFamily.ANY),
1250  SqlFunctionCategory.SYSTEM);
1251  }
1252 
1253  @Override
1254  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1255  assert opBinding.getOperandCount() == 1;
1256  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1257  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1258  }
1259  }
1260 
1261  static class ST_SetSRID extends SqlFunction {
1263  super("ST_SetSRID",
1264  SqlKind.OTHER_FUNCTION,
1265  null,
1266  null,
1267  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
1268  SqlFunctionCategory.SYSTEM);
1269  }
1270 
1271  @Override
1272  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1273  assert opBinding.getOperandCount() == 1;
1274  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1275  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1276  }
1277  }
1278 
1279  static class ST_Point extends SqlFunction {
1281  super("ST_Point",
1282  SqlKind.OTHER_FUNCTION,
1283  null,
1284  null,
1285  OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
1286  SqlFunctionCategory.SYSTEM);
1287  }
1288 
1289  @Override
1290  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1291  assert opBinding.getOperandCount() == 2;
1292  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1293  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1294  }
1295  }
1296 
1297  static class CastToGeography extends SqlFunction {
1299  super("CastToGeography",
1300  SqlKind.OTHER_FUNCTION,
1301  null,
1302  null,
1303  OperandTypes.family(SqlTypeFamily.ANY),
1304  SqlFunctionCategory.SYSTEM);
1305  }
1306 
1307  @Override
1308  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1309  assert opBinding.getOperandCount() == 1;
1310  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1311  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1312  }
1313  }
1314 
1315  /* OFFSET_IN_FRAGMENT() */
1316  public static class OffsetInFragment extends SqlFunction {
1317  public OffsetInFragment() {
1318  super("OFFSET_IN_FRAGMENT",
1319  SqlKind.OTHER_FUNCTION,
1320  null,
1321  null,
1322  OperandTypes.NILADIC,
1323  SqlFunctionCategory.SYSTEM);
1324  }
1325 
1326  @Override
1327  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1328  assert opBinding.getOperandCount() == 0;
1329  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1330  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1331  }
1332  }
1333 
1334  static class ApproxCountDistinct extends SqlAggFunction {
1336  super("APPROX_COUNT_DISTINCT",
1337  null,
1338  SqlKind.OTHER_FUNCTION,
1339  null,
1340  null,
1341  OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
1342  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
1343  SqlFunctionCategory.SYSTEM);
1344  }
1345 
1346  @Override
1347  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1348  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1349  return typeFactory.createSqlType(SqlTypeName.BIGINT);
1350  }
1351  }
1352 
1353  static class MapDAvg extends SqlAggFunction {
1355  super("AVG",
1356  null,
1357  SqlKind.OTHER_FUNCTION,
1358  null,
1359  null,
1360  OperandTypes.family(SqlTypeFamily.NUMERIC),
1361  SqlFunctionCategory.SYSTEM);
1362  }
1363 
1364  @Override
1365  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1366  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1367  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
1368  }
1369  }
1370 
1371  public static class Sample extends SqlAggFunction {
1372  public Sample() {
1373  super("SAMPLE",
1374  SqlKind.OTHER_FUNCTION,
1375  null,
1376  null,
1377  OperandTypes.ANY,
1378  SqlFunctionCategory.SYSTEM);
1379  }
1380 
1381  @Override
1382  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1383  return opBinding.getOperandType(0);
1384  }
1385  }
1386 
1387  // for backwards compatibility
1388  public static class LastSample extends SqlAggFunction {
1389  public LastSample() {
1390  super("LAST_SAMPLE",
1391  SqlKind.OTHER_FUNCTION,
1392  null,
1393  null,
1394  OperandTypes.ANY,
1395  SqlFunctionCategory.SYSTEM);
1396  }
1397 
1398  @Override
1399  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1400  return opBinding.getOperandType(0);
1401  }
1402  }
1403 
1404  static class ExtFunction extends SqlFunction {
1405  ExtFunction(final String name, final ExtensionFunction sig) {
1406  super(name,
1407  SqlKind.OTHER_FUNCTION,
1408  null,
1409  null,
1410  OperandTypes.family(toSqlSignature(sig)),
1411  SqlFunctionCategory.SYSTEM);
1412  ret = toSqlTypeName(sig.getRet());
1413  }
1414 
1415  private static java.util.List<SqlTypeFamily> toSqlSignature(
1416  final ExtensionFunction sig) {
1417  java.util.List<SqlTypeFamily> sql_sig = new java.util.ArrayList<SqlTypeFamily>();
1418  for (int arg_idx = 0; arg_idx < sig.getArgs().size(); ++arg_idx) {
1419  final ExtensionFunction.ExtArgumentType arg_type = sig.getArgs().get(arg_idx);
1420  sql_sig.add(toSqlTypeName(arg_type).getFamily());
1421  if (isPointerType(arg_type)) {
1422  ++arg_idx;
1423  }
1424  }
1425  return sql_sig;
1426  }
1427 
1428  private static boolean isPointerType(final ExtensionFunction.ExtArgumentType type) {
1435  }
1436 
1437  @Override
1438  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1439  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1440  return typeFactory.createTypeWithNullability(typeFactory.createSqlType(ret), true);
1441  }
1442 
1443  private static SqlTypeName toSqlTypeName(
1445  switch (type) {
1446  case Bool:
1447  return SqlTypeName.BOOLEAN;
1448  case Int8:
1449  return SqlTypeName.TINYINT;
1450  case Int16:
1451  return SqlTypeName.SMALLINT;
1452  case Int32:
1453  return SqlTypeName.INTEGER;
1454  case Int64:
1455  return SqlTypeName.BIGINT;
1456  case Float:
1457  return SqlTypeName.FLOAT;
1458  case Double:
1459  return SqlTypeName.DOUBLE;
1460  case PInt8:
1461  case PInt16:
1462  case PInt32:
1463  case PInt64:
1464  case PFloat:
1465  case PDouble:
1466  return SqlTypeName.ARRAY;
1467  }
1468  assert false;
1469  return null;
1470  }
1471 
1472  private final SqlTypeName ret;
1473  }
1474 
1475  //
1476  // Internal accessors for in-situ poly render queries
1477  //
1478  // The MapD_* varietals are deprecated. The OmniSci_Geo_* ones should be used instead
1479  //
1480 
1481  static class MapD_GeoPolyBoundsPtr extends SqlFunction {
1483  super("MapD_GeoPolyBoundsPtr",
1484  SqlKind.OTHER_FUNCTION,
1485  null,
1486  null,
1487  OperandTypes.family(SqlTypeFamily.ANY),
1488  SqlFunctionCategory.SYSTEM);
1489  }
1490 
1491  @Override
1492  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1493  assert opBinding.getOperandCount() == 1;
1494  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1495  return typeFactory.createSqlType(SqlTypeName.BIGINT);
1496  }
1497  }
1498 
1499  static class MapD_GeoPolyRenderGroup extends SqlFunction {
1501  super("MapD_GeoPolyRenderGroup",
1502  SqlKind.OTHER_FUNCTION,
1503  null,
1504  null,
1505  OperandTypes.family(SqlTypeFamily.ANY),
1506  SqlFunctionCategory.SYSTEM);
1507  }
1508 
1509  @Override
1510  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1511  assert opBinding.getOperandCount() == 1;
1512  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1513  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1514  }
1515  }
1516 
1517  static class OmniSci_Geo_PolyBoundsPtr extends SqlFunction {
1519  super("OmniSci_Geo_PolyBoundsPtr",
1520  SqlKind.OTHER_FUNCTION,
1521  null,
1522  null,
1523  OperandTypes.family(SqlTypeFamily.ANY),
1524  SqlFunctionCategory.SYSTEM);
1525  }
1526 
1527  @Override
1528  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1529  assert opBinding.getOperandCount() == 1;
1530  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1531  return typeFactory.createSqlType(SqlTypeName.BIGINT);
1532  }
1533  }
1534 
1535  static class OmniSci_Geo_PolyRenderGroup extends SqlFunction {
1537  super("OmniSci_Geo_PolyRenderGroup",
1538  SqlKind.OTHER_FUNCTION,
1539  null,
1540  null,
1541  OperandTypes.family(SqlTypeFamily.ANY),
1542  SqlFunctionCategory.SYSTEM);
1543  }
1544 
1545  @Override
1546  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1547  assert opBinding.getOperandCount() == 1;
1548  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1549  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1550  }
1551  }
1552 
1553  static class convert_meters_to_pixel_width extends SqlFunction {
1555  super("convert_meters_to_pixel_width",
1556  SqlKind.OTHER_FUNCTION,
1557  null,
1558  null,
1559  OperandTypes.family(SqlTypeFamily.NUMERIC,
1560  SqlTypeFamily.ANY,
1561  SqlTypeFamily.NUMERIC,
1562  SqlTypeFamily.NUMERIC,
1563  SqlTypeFamily.NUMERIC,
1564  SqlTypeFamily.NUMERIC),
1565  SqlFunctionCategory.SYSTEM);
1566  }
1567 
1568  @Override
1569  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1570  assert opBinding.getOperandCount() == 6;
1571  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1572  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
1573  }
1574  }
1575 
1576  static class convert_meters_to_pixel_height extends SqlFunction {
1578  super("convert_meters_to_pixel_height",
1579  SqlKind.OTHER_FUNCTION,
1580  null,
1581  null,
1582  OperandTypes.family(SqlTypeFamily.NUMERIC,
1583  SqlTypeFamily.ANY,
1584  SqlTypeFamily.NUMERIC,
1585  SqlTypeFamily.NUMERIC,
1586  SqlTypeFamily.NUMERIC,
1587  SqlTypeFamily.NUMERIC),
1588  SqlFunctionCategory.SYSTEM);
1589  }
1590 
1591  @Override
1592  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1593  assert opBinding.getOperandCount() == 6;
1594  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1595  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
1596  }
1597  }
1598 
1599  static class is_point_in_view extends SqlFunction {
1601  super("is_point_in_view",
1602  SqlKind.OTHER_FUNCTION,
1603  null,
1604  null,
1605  OperandTypes.family(SqlTypeFamily.ANY,
1606  SqlTypeFamily.NUMERIC,
1607  SqlTypeFamily.NUMERIC,
1608  SqlTypeFamily.NUMERIC,
1609  SqlTypeFamily.NUMERIC),
1610  SqlFunctionCategory.SYSTEM);
1611  }
1612 
1613  @Override
1614  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1615  assert opBinding.getOperandCount() == 5;
1616  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1617  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1618  }
1619  }
1620 
1621  static class is_point_size_in_view extends SqlFunction {
1623  super("is_point_size_in_view",
1624  SqlKind.OTHER_FUNCTION,
1625  null,
1626  null,
1627  OperandTypes.family(SqlTypeFamily.ANY,
1628  SqlTypeFamily.NUMERIC,
1629  SqlTypeFamily.NUMERIC,
1630  SqlTypeFamily.NUMERIC,
1631  SqlTypeFamily.NUMERIC,
1632  SqlTypeFamily.NUMERIC),
1633  SqlFunctionCategory.SYSTEM);
1634  }
1635 
1636  @Override
1637  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1638  assert opBinding.getOperandCount() == 6;
1639  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1640  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1641  }
1642  }
1643 
1644  public static class usTimestamp extends SqlFunction {
1645  public usTimestamp() {
1646  super("usTIMESTAMP",
1647  SqlKind.OTHER_FUNCTION,
1648  null,
1649  null,
1650  OperandTypes.STRING,
1651  SqlFunctionCategory.SYSTEM);
1652  }
1653 
1654  @Override
1655  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1656  assert opBinding.getOperandCount() == 1;
1657  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1658  return typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 6);
1659  }
1660  }
1661 
1662  public static class nsTimestamp extends SqlFunction {
1663  public nsTimestamp() {
1664  super("nsTIMESTAMP",
1665  SqlKind.OTHER_FUNCTION,
1666  null,
1667  null,
1668  OperandTypes.STRING,
1669  SqlFunctionCategory.SYSTEM);
1670  }
1671 
1672  @Override
1673  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1674  assert opBinding.getOperandCount() == 1;
1675  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1676  return typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 9);
1677  }
1678  }
1679 }
1680 
1681 // End MapDSqlOperatorTable.java
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)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static boolean isPointerType(final ExtensionFunction.ExtArgumentType type)
ExtFunction(final String name, final ExtensionFunction sig)
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 > signature()
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)
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)
static SqlTypeName toSqlTypeName(final ExtensionFunction.ExtArgumentType type)
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)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > toSqlSignature(final ExtensionFunction sig)
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)
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)
void lookupOperatorOverloads(SqlIdentifier opName, SqlFunctionCategory category, SqlSyntax syntax, List< SqlOperator > operatorList, SqlNameMatcher nameMatcher)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)