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