OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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.metadata.RelColumnMapping;
24 import org.apache.calcite.rel.type.RelDataType;
25 import org.apache.calcite.rel.type.RelDataTypeFactory;
26 import org.apache.calcite.rel.type.RelDataTypeFactory.FieldInfoBuilder;
27 import org.apache.calcite.schema.TranslatableTable;
28 import org.apache.calcite.sql.SqlAggFunction;
29 import org.apache.calcite.sql.SqlCallBinding;
30 import org.apache.calcite.sql.SqlFunction;
31 import org.apache.calcite.sql.SqlFunctionCategory;
32 import org.apache.calcite.sql.SqlIdentifier;
33 import org.apache.calcite.sql.SqlKind;
34 import org.apache.calcite.sql.SqlOperator;
35 import org.apache.calcite.sql.SqlOperatorBinding;
36 import org.apache.calcite.sql.SqlOperatorTable;
37 import org.apache.calcite.sql.SqlSyntax;
38 import org.apache.calcite.sql.SqlTableFunction;
39 import org.apache.calcite.sql.fun.SqlArrayValueConstructor;
40 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
41 import org.apache.calcite.sql.type.OperandTypes;
42 import org.apache.calcite.sql.type.ReturnTypes;
43 import org.apache.calcite.sql.type.SqlReturnTypeInference;
44 import org.apache.calcite.sql.type.SqlTypeFamily;
45 import org.apache.calcite.sql.type.SqlTypeName;
46 import org.apache.calcite.sql.util.ChainedSqlOperatorTable;
47 import org.apache.calcite.sql.util.ListSqlOperatorTable;
48 import org.apache.calcite.sql.util.ReflectiveSqlOperatorTable;
49 import org.apache.calcite.sql.validate.SqlNameMatcher;
50 import org.apache.calcite.util.Optionality;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
53 
54 import java.lang.reflect.Field;
55 import java.util.HashSet;
56 import java.util.Iterator;
57 import java.util.List;
58 import java.util.Map;
59 import java.util.Set;
60 
61 class CaseInsensitiveListSqlOperatorTable extends ListSqlOperatorTable {
62  @Override
63  public void lookupOperatorOverloads(SqlIdentifier opName,
64  SqlFunctionCategory category,
65  SqlSyntax syntax,
66  List<SqlOperator> operatorList,
67  SqlNameMatcher nameMatcher) {
68  for (SqlOperator operator : this.getOperatorList()) {
69  if (operator.getSyntax() != syntax) {
70  continue;
71  }
72  if (!opName.isSimple()
73  || !nameMatcher.matches(operator.getName(), opName.getSimple())) {
74  continue;
75  }
76  SqlFunctionCategory functionCategory;
77  if (operator instanceof SqlFunction) {
78  functionCategory = ((SqlFunction) operator).getFunctionType();
79  } else {
80  functionCategory = SqlFunctionCategory.SYSTEM;
81  }
82  if (category != functionCategory
83  && category != SqlFunctionCategory.USER_DEFINED_FUNCTION) {
84  continue;
85  }
86  operatorList.add(operator);
87  }
88  }
89 }
90 
95 public class MapDSqlOperatorTable extends ChainedSqlOperatorTable {
98 
99  static {
100  try {
101  // some nasty bit to remove the std APPROX_COUNT_DISTINCT function definition
102  {
103  Field f = ReflectiveSqlOperatorTable.class.getDeclaredField(
104  "caseSensitiveOperators");
105  f.setAccessible(true);
106  Multimap operators = (Multimap) f.get(SqlStdOperatorTable.instance());
107  for (Iterator i = operators.entries().iterator(); i.hasNext();) {
108  Map.Entry entry = (Map.Entry) i.next();
109  if (entry.getValue() == SqlStdOperatorTable.APPROX_COUNT_DISTINCT
110  || entry.getValue() == SqlStdOperatorTable.AVG
111  || entry.getValue() == SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR) {
112  i.remove();
113  }
114  }
115  }
116 
117  {
118  Field f = ReflectiveSqlOperatorTable.class.getDeclaredField(
119  "caseInsensitiveOperators");
120  f.setAccessible(true);
121  Multimap operators = (Multimap) f.get(SqlStdOperatorTable.instance());
122  for (Iterator i = operators.entries().iterator(); i.hasNext();) {
123  Map.Entry entry = (Map.Entry) i.next();
124  if (entry.getValue() == SqlStdOperatorTable.APPROX_COUNT_DISTINCT
125  || entry.getValue() == SqlStdOperatorTable.AVG
126  || entry.getValue() == SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR) {
127  i.remove();
128  }
129  }
130  }
131 
132  SqlStdOperatorTable.instance().register(ARRAY_VALUE_CONSTRUCTOR);
133 
134  } catch (Exception e) {
135  throw new RuntimeException(e);
136  }
137 
138  // register our approx count distinct against std table
139  // SqlStdOperatorTable.instance().register(new ApproxCountDistinct());
140  }
141 
142  final static Logger MAPDLOGGER = LoggerFactory.getLogger(MapDSqlOperatorTable.class);
143 
148  // ~ Instance fields --------------------------------------------------------
149  private final ListSqlOperatorTable listOpTab;
150 
151  // ~ Constructors -----------------------------------------------------------
152  public MapDSqlOperatorTable(SqlOperatorTable parentTable) {
153  super(ImmutableList.of(parentTable, new CaseInsensitiveListSqlOperatorTable()));
154  listOpTab = (ListSqlOperatorTable) tableList.get(1);
155  }
156 
157  // ~ Methods ----------------------------------------------------------------
163  public void addOperator(SqlOperator op) {
164  listOpTab.add(op);
165  }
166 
167  public static void addUDF(
168  MapDSqlOperatorTable opTab, final Map<String, ExtensionFunction> extSigs) {
169  // Don't use anonymous inner classes. They can't be instantiated
170  // using reflection when we are deserializing from JSON.
171  // opTab.addOperator(new RampFunction());
172  // opTab.addOperator(new DedupFunction());
173  opTab.addOperator(new MyUDFFunction());
174  opTab.addOperator(new PgUnnest());
175  opTab.addOperator(new Any());
176  opTab.addOperator(new All());
177  opTab.addOperator(new Now());
178  opTab.addOperator(new Datetime());
179  opTab.addOperator(new PgExtract());
180  opTab.addOperator(new Dateadd());
181  opTab.addOperator(new Datediff());
182  opTab.addOperator(new Datepart());
183  opTab.addOperator(new PgDateTrunc());
184  opTab.addOperator(new Length());
185  opTab.addOperator(new CharLength());
186  opTab.addOperator(new KeyForString());
187  opTab.addOperator(new SampleRatio());
188  opTab.addOperator(new WidthBucket());
189  opTab.addOperator(new ArrayLength());
190  opTab.addOperator(new PgILike());
191  opTab.addOperator(new RegexpLike());
192  opTab.addOperator(new Likely());
193  opTab.addOperator(new Unlikely());
194  opTab.addOperator(new Sign());
195  opTab.addOperator(new Truncate());
196  opTab.addOperator(new ST_IsEmpty());
197  opTab.addOperator(new ST_IsValid());
198  opTab.addOperator(new ST_Contains());
199  opTab.addOperator(new ST_Equals());
200  opTab.addOperator(new ST_Intersects());
201  opTab.addOperator(new ST_Overlaps());
202  opTab.addOperator(new ST_Approx_Overlaps());
203  opTab.addOperator(new ST_Disjoint());
204  opTab.addOperator(new ST_Within());
205  opTab.addOperator(new ST_DWithin());
206  opTab.addOperator(new ST_DFullyWithin());
207  opTab.addOperator(new ST_Distance());
208  opTab.addOperator(new ST_MaxDistance());
209  opTab.addOperator(new ST_GeogFromText());
210  opTab.addOperator(new ST_GeomFromText());
211  opTab.addOperator(new ST_Transform());
212  opTab.addOperator(new ST_X());
213  opTab.addOperator(new ST_Y());
214  opTab.addOperator(new ST_XMin());
215  opTab.addOperator(new ST_XMax());
216  opTab.addOperator(new ST_YMin());
217  opTab.addOperator(new ST_YMax());
218  opTab.addOperator(new ST_PointN());
219  opTab.addOperator(new ST_StartPoint());
220  opTab.addOperator(new ST_EndPoint());
221  opTab.addOperator(new ST_Length());
222  opTab.addOperator(new ST_Perimeter());
223  opTab.addOperator(new ST_Area());
224  opTab.addOperator(new ST_NPoints());
225  opTab.addOperator(new ST_NRings());
226  opTab.addOperator(new ST_SRID());
227  opTab.addOperator(new ST_SetSRID());
228  opTab.addOperator(new ST_Point());
229  opTab.addOperator(new ST_Centroid());
230  opTab.addOperator(new ST_Buffer());
231  opTab.addOperator(new ST_Intersection());
232  opTab.addOperator(new ST_Union());
233  opTab.addOperator(new ST_Difference());
234  opTab.addOperator(new CastToGeography());
235  opTab.addOperator(new OffsetInFragment());
236  opTab.addOperator(new ApproxCountDistinct());
237  opTab.addOperator(new ApproxMedian());
238  opTab.addOperator(new ApproxPercentile());
239  opTab.addOperator(new ApproxQuantile());
240  opTab.addOperator(new MapDAvg());
241  opTab.addOperator(new Sample());
242  opTab.addOperator(new LastSample());
243  // MapD_Geo* are deprecated in place of the OmniSci_Geo_ varietals
244  opTab.addOperator(new MapD_GeoPolyBoundsPtr());
245  opTab.addOperator(new MapD_GeoPolyRenderGroup());
246  opTab.addOperator(new OmniSci_Geo_PolyBoundsPtr());
247  opTab.addOperator(new OmniSci_Geo_PolyRenderGroup());
248  opTab.addOperator(new convert_meters_to_pixel_width());
249  opTab.addOperator(new convert_meters_to_pixel_height());
250  opTab.addOperator(new is_point_in_view());
251  opTab.addOperator(new is_point_size_in_view());
252  opTab.addOperator(new usTimestamp());
253  opTab.addOperator(new nsTimestamp());
254  if (extSigs == null) {
255  return;
256  }
257  HashSet<String> demangledNames = new HashSet<String>();
258  for (Map.Entry<String, ExtensionFunction> extSig : extSigs.entrySet()) {
259  final String demangledName = dropSuffix(extSig.getKey());
260  final String demangledNameArity =
261  String.format("%s-%d", demangledName, extSig.getValue().getArgs().size());
262  if (demangledNames.contains(demangledNameArity)) {
263  continue;
264  }
265  demangledNames.add(demangledNameArity);
266  if (extSig.getValue().isRowUdf()) {
267  opTab.addOperator(new ExtFunction(demangledName, extSig.getValue()));
268  } else {
269  opTab.addOperator(new ExtTableFunction(demangledName, extSig.getValue()));
270  }
271  }
272  }
273 
274  private static String dropSuffix(final String str) {
275  int suffix_idx = str.indexOf("__");
276  if (suffix_idx == -1) {
277  return str;
278  }
279  assert suffix_idx > 0;
280  return str.substring(0, suffix_idx);
281  }
282 
284  extends SqlArrayValueConstructor {
285  @Override
286  protected RelDataType getComponentType(
287  RelDataTypeFactory typeFactory, List<RelDataType> argTypes) {
288  if (argTypes.isEmpty()) {
289  return typeFactory.createSqlType(SqlTypeName.NULL);
290  }
291  return super.getComponentType(typeFactory, argTypes);
292  }
293 
294  @Override
295  public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
296  if (callBinding.operands().isEmpty()) {
297  return true;
298  }
299  return super.checkOperandTypes(callBinding, throwOnFailure);
300  }
301  }
302 
306  public static class RampFunction extends SqlFunction {
307  public RampFunction() {
308  super("RAMP",
309  SqlKind.OTHER_FUNCTION,
310  null,
311  null,
312  OperandTypes.NUMERIC,
313  SqlFunctionCategory.USER_DEFINED_FUNCTION);
314  }
315 
316  @Override
317  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
318  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
319  return typeFactory.builder().add("I", SqlTypeName.INTEGER).build();
320  }
321  }
322 
326  public static class DedupFunction extends SqlFunction {
327  public DedupFunction() {
328  super("DEDUP",
329  SqlKind.OTHER_FUNCTION,
330  null,
331  null,
332  OperandTypes.VARIADIC,
333  SqlFunctionCategory.USER_DEFINED_FUNCTION);
334  }
335 
336  @Override
337  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
338  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
339  return typeFactory.builder().add("NAME", SqlTypeName.VARCHAR, 1024).build();
340  }
341  }
342 
347  public static class MyUDFFunction extends SqlFunction {
348  public MyUDFFunction() {
349  super("MyUDF",
350  SqlKind.OTHER_FUNCTION,
351  null,
352  null,
353  OperandTypes.STRING_STRING,
354  SqlFunctionCategory.SYSTEM);
355  }
356 
357  @Override
358  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
359  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
360  return typeFactory.createSqlType(SqlTypeName.BIGINT);
361  }
362  }
363 
364  /* Postgres-style UNNEST */
365  public static class PgUnnest extends SqlFunction {
366  public PgUnnest() {
367  super("PG_UNNEST",
368  SqlKind.OTHER_FUNCTION,
369  null,
370  null,
371  OperandTypes.ARRAY,
372  SqlFunctionCategory.SYSTEM);
373  }
374 
375  @Override
376  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
377  assert opBinding.getOperandCount() == 1;
378  RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
379  assert elem_type != null;
380  return elem_type;
381  }
382  }
383 
384  /* ANY qualifier */
385  public static class Any extends SqlFunction {
386  public Any() {
387  super("PG_ANY",
388  SqlKind.OTHER_FUNCTION,
389  null,
390  null,
391  OperandTypes.ARRAY,
392  SqlFunctionCategory.SYSTEM);
393  }
394 
395  @Override
396  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
397  assert opBinding.getOperandCount() == 1;
398  RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
399  assert elem_type != null;
400  return elem_type;
401  }
402  }
403 
404  /* ALL qualifier */
405  public static class All extends SqlFunction {
406  public All() {
407  super("PG_ALL",
408  SqlKind.OTHER_FUNCTION,
409  null,
410  null,
411  OperandTypes.ARRAY,
412  SqlFunctionCategory.SYSTEM);
413  }
414 
415  @Override
416  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
417  assert opBinding.getOperandCount() == 1;
418  RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
419  assert elem_type != null;
420  return elem_type;
421  }
422  }
423 
424  /* NOW() */
425  public static class Now extends SqlFunction {
426  public Now() {
427  super("NOW",
428  SqlKind.OTHER_FUNCTION,
429  null,
430  null,
431  OperandTypes.NILADIC,
432  SqlFunctionCategory.SYSTEM);
433  }
434 
435  @Override
436  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
437  assert opBinding.getOperandCount() == 0;
438  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
439  return typeFactory.createSqlType(SqlTypeName.TIMESTAMP);
440  }
441  }
442 
443  /* DATETIME */
444  public static class Datetime extends SqlFunction {
445  public Datetime() {
446  super("DATETIME",
447  SqlKind.OTHER_FUNCTION,
448  null,
449  null,
450  OperandTypes.STRING,
451  SqlFunctionCategory.SYSTEM);
452  }
453 
454  @Override
455  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
456  assert opBinding.getOperandCount() == 1;
457  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
458  return typeFactory.createSqlType(
459  SqlTypeName.TIMESTAMP, opBinding.getOperandType(0).getPrecision());
460  }
461  }
462 
463  /* Postgres-style EXTRACT */
464  public static class PgExtract extends SqlFunction {
465  public PgExtract() {
466  super("PG_EXTRACT",
467  SqlKind.OTHER_FUNCTION,
468  null,
469  null,
470  OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
471  SqlFunctionCategory.SYSTEM);
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  }
481  }
482 
483  public static class Datepart extends SqlFunction {
484  public Datepart() {
485  super("DATEPART",
486  SqlKind.OTHER_FUNCTION,
487  null,
488  null,
489  OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
490  SqlFunctionCategory.TIMEDATE);
491  }
492 
493  @Override
494  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
495  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
496  return typeFactory.createTypeWithNullability(
497  typeFactory.createSqlType(SqlTypeName.BIGINT),
498  opBinding.getOperandType(1).isNullable());
499  }
500  }
501 
502  public static class Dateadd extends SqlFunction {
503  public Dateadd() {
504  super("DATEADD",
505  SqlKind.OTHER_FUNCTION,
506  null,
507  null,
508  OperandTypes.family(SqlTypeFamily.STRING,
509  SqlTypeFamily.INTEGER,
510  SqlTypeFamily.DATETIME),
511  SqlFunctionCategory.TIMEDATE);
512  }
513 
514  @Override
515  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
516  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
517  return typeFactory.createTypeWithNullability(
518  typeFactory.createSqlType(
519  SqlTypeName.TIMESTAMP, opBinding.getOperandType(2).getPrecision()),
520  opBinding.getOperandType(2).isNullable());
521  }
522  }
523 
524  public static class Datediff extends SqlFunction {
525  public Datediff() {
526  super("DATEDIFF",
527  SqlKind.OTHER_FUNCTION,
528  null,
529  null,
530  OperandTypes.family(SqlTypeFamily.STRING,
531  SqlTypeFamily.DATETIME,
532  SqlTypeFamily.DATETIME),
533  SqlFunctionCategory.TIMEDATE);
534  }
535 
536  @Override
537  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
538  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
539  return typeFactory.createTypeWithNullability(
540  typeFactory.createSqlType(SqlTypeName.BIGINT),
541  opBinding.getOperandType(1).isNullable()
542  || opBinding.getOperandType(2).isNullable());
543  }
544  }
545 
546  /* Postgres-style DATE_TRUNC */
547  public static class PgDateTrunc extends SqlFunction {
548  public PgDateTrunc() {
549  super("PG_DATE_TRUNC",
550  SqlKind.OTHER_FUNCTION,
551  null,
552  null,
553  OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
554  SqlFunctionCategory.SYSTEM);
555  }
556 
557  @Override
558  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
559  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
560  return typeFactory.createTypeWithNullability(
561  typeFactory.createSqlType(
562  SqlTypeName.TIMESTAMP, opBinding.getOperandType(1).getPrecision()),
563  opBinding.getOperandType(1).isNullable());
564  }
565  }
566 
567  public static class Length extends SqlFunction {
568  public Length() {
569  super("LENGTH",
570  SqlKind.OTHER_FUNCTION,
571  null,
572  null,
573  OperandTypes.STRING,
574  SqlFunctionCategory.SYSTEM);
575  }
576 
577  @Override
578  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
579  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
580  return typeFactory.createSqlType(SqlTypeName.INTEGER);
581  }
582  }
583 
584  public static class CharLength extends SqlFunction {
585  public CharLength() {
586  super("CHAR_LENGTH",
587  SqlKind.OTHER_FUNCTION,
588  null,
589  null,
590  OperandTypes.STRING,
591  SqlFunctionCategory.SYSTEM);
592  }
593 
594  @Override
595  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
596  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
597  return typeFactory.createSqlType(SqlTypeName.INTEGER);
598  }
599  }
600 
601  public static class KeyForString extends SqlFunction {
602  public KeyForString() {
603  super("KEY_FOR_STRING",
604  SqlKind.OTHER_FUNCTION,
605  null,
606  null,
607  OperandTypes.STRING,
608  SqlFunctionCategory.SYSTEM);
609  }
610 
611  @Override
612  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
613  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
614  return typeFactory.createTypeWithNullability(
615  typeFactory.createSqlType(SqlTypeName.INTEGER),
616  opBinding.getOperandType(0).isNullable());
617  }
618  }
619 
620  public static class SampleRatio extends SqlFunction {
621  public SampleRatio() {
622  super("SAMPLE_RATIO",
623  SqlKind.OTHER_FUNCTION,
624  null,
625  null,
626  OperandTypes.family(signature()),
627  SqlFunctionCategory.SYSTEM);
628  }
629 
630  @Override
631  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
632  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
633  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
634  }
635 
636  private static java.util.List<SqlTypeFamily> signature() {
637  java.util.ArrayList<SqlTypeFamily> families =
638  new java.util.ArrayList<SqlTypeFamily>();
639  families.add(SqlTypeFamily.NUMERIC);
640  return families;
641  }
642  }
643 
644  public static class WidthBucket extends SqlFunction {
645  public WidthBucket() {
646  super("WIDTH_BUCKET",
647  SqlKind.OTHER_FUNCTION,
648  null,
649  null,
650  OperandTypes.family(signature()),
651  SqlFunctionCategory.SYSTEM);
652  }
653 
654  @Override
655  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
656  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
657  return typeFactory.createTypeWithNullability(
658  typeFactory.createSqlType(SqlTypeName.INTEGER), /*nullable=*/true);
659  }
660 
661  private static java.util.List<SqlTypeFamily> signature() {
662  java.util.ArrayList<SqlTypeFamily> families =
663  new java.util.ArrayList<SqlTypeFamily>();
664  families.add(SqlTypeFamily.NUMERIC);
665  families.add(SqlTypeFamily.NUMERIC);
666  families.add(SqlTypeFamily.NUMERIC);
667  families.add(SqlTypeFamily.INTEGER);
668  return families;
669  }
670  }
671 
672  public static class ArrayLength extends SqlFunction {
673  public ArrayLength() {
674  super("ARRAY_LENGTH",
675  SqlKind.OTHER_FUNCTION,
676  null,
677  null,
678  OperandTypes.ARRAY,
679  SqlFunctionCategory.SYSTEM);
680  }
681 
682  @Override
683  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
684  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
685  return typeFactory.createSqlType(SqlTypeName.INTEGER);
686  }
687  }
688 
689  public static class PgILike extends SqlFunction {
690  public PgILike() {
691  super("PG_ILIKE",
692  SqlKind.OTHER_FUNCTION,
693  null,
694  null,
695  OperandTypes.family(getSignatureFamilies(), new EscapeOptional()),
696  SqlFunctionCategory.SYSTEM);
697  }
698 
699  private static java.util.List<SqlTypeFamily> getSignatureFamilies() {
700  java.util.ArrayList<SqlTypeFamily> families =
701  new java.util.ArrayList<SqlTypeFamily>();
702  families.add(SqlTypeFamily.STRING);
703  families.add(SqlTypeFamily.STRING);
704  families.add(SqlTypeFamily.STRING);
705  return families;
706  }
707 
708  private static class EscapeOptional
709  implements java.util.function.Predicate<Integer>, Predicate<Integer> {
710  @Override
711  public boolean test(Integer t) {
712  return apply(t);
713  }
714 
715  @Override
716  public boolean apply(Integer t) {
717  return t == 2;
718  }
719  }
720 
721  @Override
722  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
723  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
724  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
725  }
726  }
727 
728  public static class RegexpLike extends SqlFunction {
729  public RegexpLike() {
730  super("REGEXP_LIKE",
731  SqlKind.OTHER_FUNCTION,
732  null,
733  null,
734  OperandTypes.family(getSignatureFamilies(), new EscapeOptional()),
735  SqlFunctionCategory.SYSTEM);
736  }
737 
738  private static java.util.List<SqlTypeFamily> getSignatureFamilies() {
739  java.util.ArrayList<SqlTypeFamily> families =
740  new java.util.ArrayList<SqlTypeFamily>();
741  families.add(SqlTypeFamily.STRING);
742  families.add(SqlTypeFamily.STRING);
743  families.add(SqlTypeFamily.STRING);
744  return families;
745  }
746 
747  private static class EscapeOptional
748  implements java.util.function.Predicate<Integer>, Predicate<Integer> {
749  @Override
750  public boolean test(Integer t) {
751  return apply(t);
752  }
753 
754  public boolean apply(Integer t) {
755  return t == 2;
756  }
757  }
758 
759  @Override
760  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
761  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
762  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
763  }
764  }
765 
766  public static class Likely extends SqlFunction {
767  public Likely() {
768  super("LIKELY",
769  SqlKind.OTHER_FUNCTION,
770  null,
771  null,
772  OperandTypes.BOOLEAN,
773  SqlFunctionCategory.SYSTEM);
774  }
775 
776  @Override
777  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
778  return opBinding.getOperandType(0);
779  }
780  }
781 
782  public static class Unlikely extends SqlFunction {
783  public Unlikely() {
784  super("UNLIKELY",
785  SqlKind.OTHER_FUNCTION,
786  null,
787  null,
788  OperandTypes.BOOLEAN,
789  SqlFunctionCategory.SYSTEM);
790  }
791 
792  @Override
793  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
794  return opBinding.getOperandType(0);
795  }
796  }
797 
798  public static class Sign extends SqlFunction {
799  public Sign() {
800  super("SIGN",
801  SqlKind.OTHER_FUNCTION,
802  null,
803  null,
804  OperandTypes.NUMERIC,
805  SqlFunctionCategory.NUMERIC);
806  }
807 
808  @Override
809  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
810  return opBinding.getOperandType(0);
811  }
812  }
813 
814  static class Truncate extends SqlFunction {
816  super("TRUNCATE",
817  SqlKind.OTHER_FUNCTION,
818  null,
819  null,
820  OperandTypes.family(signature()),
822  }
823 
824  @Override
825  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
826  assert opBinding.getOperandCount() == 2;
827  return opBinding.getOperandType(0);
828  }
829 
830  private static java.util.List<SqlTypeFamily> signature() {
831  java.util.List<SqlTypeFamily> truncate_sig =
832  new java.util.ArrayList<SqlTypeFamily>();
833  truncate_sig.add(SqlTypeFamily.NUMERIC);
834  truncate_sig.add(SqlTypeFamily.INTEGER);
835  return truncate_sig;
836  }
837  }
838 
839  static class ST_IsEmpty extends SqlFunction {
841  super("ST_IsEmpty",
842  SqlKind.OTHER_FUNCTION,
843  null,
844  null,
845  OperandTypes.family(signature()),
846  SqlFunctionCategory.SYSTEM);
847  }
848 
849  @Override
850  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
851  assert opBinding.getOperandCount() == 1;
852  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
853  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
854  }
855 
856  private static java.util.List<SqlTypeFamily> signature() {
857  java.util.List<SqlTypeFamily> st_isempty_sig =
858  new java.util.ArrayList<SqlTypeFamily>();
859  st_isempty_sig.add(SqlTypeFamily.ANY);
860  return st_isempty_sig;
861  }
862  }
863 
864  static class ST_IsValid extends SqlFunction {
866  super("ST_IsValid",
867  SqlKind.OTHER_FUNCTION,
868  null,
869  null,
870  OperandTypes.family(signature()),
871  SqlFunctionCategory.SYSTEM);
872  }
873 
874  @Override
875  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
876  assert opBinding.getOperandCount() == 1;
877  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
878  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
879  }
880 
881  private static java.util.List<SqlTypeFamily> signature() {
882  java.util.List<SqlTypeFamily> st_isvalid_sig =
883  new java.util.ArrayList<SqlTypeFamily>();
884  st_isvalid_sig.add(SqlTypeFamily.ANY);
885  return st_isvalid_sig;
886  }
887  }
888 
889  static class ST_Contains extends SqlFunction {
891  super("ST_Contains",
892  SqlKind.OTHER_FUNCTION,
893  null,
894  null,
895  OperandTypes.family(signature()),
896  SqlFunctionCategory.SYSTEM);
897  }
898 
899  @Override
900  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
901  assert opBinding.getOperandCount() == 2;
902  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
903  return typeFactory.createTypeWithNullability(
904  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
905  opBinding.getOperandType(0).isNullable()
906  || opBinding.getOperandType(1).isNullable());
907  }
908 
909  private static java.util.List<SqlTypeFamily> signature() {
910  java.util.List<SqlTypeFamily> st_contains_sig =
911  new java.util.ArrayList<SqlTypeFamily>();
912  st_contains_sig.add(SqlTypeFamily.ANY);
913  st_contains_sig.add(SqlTypeFamily.ANY);
914  return st_contains_sig;
915  }
916  }
917 
918  static class ST_Equals extends SqlFunction {
920  super("ST_Equals",
921  SqlKind.OTHER_FUNCTION,
922  null,
923  null,
924  OperandTypes.family(signature()),
925  SqlFunctionCategory.SYSTEM);
926  }
927 
928  @Override
929  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
930  assert opBinding.getOperandCount() == 2;
931  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
932  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
933  }
934 
935  private static java.util.List<SqlTypeFamily> signature() {
936  java.util.List<SqlTypeFamily> st_equals_sig =
937  new java.util.ArrayList<SqlTypeFamily>();
938  st_equals_sig.add(SqlTypeFamily.ANY);
939  st_equals_sig.add(SqlTypeFamily.ANY);
940  return st_equals_sig;
941  }
942  }
943 
944  static class ST_Intersects extends SqlFunction {
946  super("ST_Intersects",
947  SqlKind.OTHER_FUNCTION,
948  null,
949  null,
950  OperandTypes.family(signature()),
951  SqlFunctionCategory.SYSTEM);
952  }
953 
954  @Override
955  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
956  assert opBinding.getOperandCount() == 2;
957  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
958  return typeFactory.createTypeWithNullability(
959  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
960  opBinding.getOperandType(0).isNullable()
961  || opBinding.getOperandType(1).isNullable());
962  }
963 
964  private static java.util.List<SqlTypeFamily> signature() {
965  java.util.List<SqlTypeFamily> st_intersects_sig =
966  new java.util.ArrayList<SqlTypeFamily>();
967  st_intersects_sig.add(SqlTypeFamily.ANY);
968  st_intersects_sig.add(SqlTypeFamily.ANY);
969  return st_intersects_sig;
970  }
971  }
972 
973  static class ST_Overlaps extends SqlFunction {
975  super("ST_Overlaps",
976  SqlKind.OTHER_FUNCTION,
977  null,
978  null,
979  OperandTypes.family(signature()),
980  SqlFunctionCategory.SYSTEM);
981  }
982 
983  @Override
984  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
985  assert opBinding.getOperandCount() == 2;
986  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
987  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
988  }
989 
990  private static java.util.List<SqlTypeFamily> signature() {
991  java.util.List<SqlTypeFamily> st_overlaps_sig =
992  new java.util.ArrayList<SqlTypeFamily>();
993  st_overlaps_sig.add(SqlTypeFamily.ANY);
994  st_overlaps_sig.add(SqlTypeFamily.ANY);
995  return st_overlaps_sig;
996  }
997  }
998 
999  static class ST_Approx_Overlaps extends SqlFunction {
1001  super("ST_Approx_Overlaps",
1002  SqlKind.OTHER_FUNCTION,
1003  null,
1004  null,
1005  OperandTypes.family(signature()),
1006  SqlFunctionCategory.SYSTEM);
1007  }
1008 
1009  @Override
1010  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1011  assert opBinding.getOperandCount() == 2;
1012  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1013  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1014  }
1015 
1016  private static java.util.List<SqlTypeFamily> signature() {
1017  java.util.List<SqlTypeFamily> st_overlaps_sig =
1018  new java.util.ArrayList<SqlTypeFamily>();
1019  st_overlaps_sig.add(SqlTypeFamily.ANY);
1020  st_overlaps_sig.add(SqlTypeFamily.ANY);
1021  return st_overlaps_sig;
1022  }
1023  }
1024 
1025  static class ST_Disjoint extends SqlFunction {
1027  super("ST_Disjoint",
1028  SqlKind.OTHER_FUNCTION,
1029  null,
1030  null,
1031  OperandTypes.family(signature()),
1032  SqlFunctionCategory.SYSTEM);
1033  }
1034 
1035  @Override
1036  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1037  assert opBinding.getOperandCount() == 2;
1038  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1039  return typeFactory.createTypeWithNullability(
1040  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1041  opBinding.getOperandType(0).isNullable()
1042  || opBinding.getOperandType(1).isNullable());
1043  }
1044 
1045  private static java.util.List<SqlTypeFamily> signature() {
1046  java.util.List<SqlTypeFamily> st_disjoint_sig =
1047  new java.util.ArrayList<SqlTypeFamily>();
1048  st_disjoint_sig.add(SqlTypeFamily.ANY);
1049  st_disjoint_sig.add(SqlTypeFamily.ANY);
1050  return st_disjoint_sig;
1051  }
1052  }
1053 
1054  static class ST_Within extends SqlFunction {
1056  super("ST_Within",
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() == 2;
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  }
1073 
1074  private static java.util.List<SqlTypeFamily> signature() {
1075  java.util.List<SqlTypeFamily> st_within_sig =
1076  new java.util.ArrayList<SqlTypeFamily>();
1077  st_within_sig.add(SqlTypeFamily.ANY);
1078  st_within_sig.add(SqlTypeFamily.ANY);
1079  return st_within_sig;
1080  }
1081  }
1082 
1083  static class ST_DWithin extends SqlFunction {
1085  super("ST_DWithin",
1086  SqlKind.OTHER_FUNCTION,
1087  null,
1088  null,
1089  OperandTypes.family(signature()),
1090  SqlFunctionCategory.SYSTEM);
1091  }
1092 
1093  @Override
1094  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1095  assert opBinding.getOperandCount() == 3;
1096  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1097  return typeFactory.createTypeWithNullability(
1098  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1099  opBinding.getOperandType(0).isNullable()
1100  || opBinding.getOperandType(1).isNullable()
1101  || opBinding.getOperandType(2).isNullable());
1102  }
1103 
1104  private static java.util.List<SqlTypeFamily> signature() {
1105  java.util.List<SqlTypeFamily> st_dwithin_sig =
1106  new java.util.ArrayList<SqlTypeFamily>();
1107  st_dwithin_sig.add(SqlTypeFamily.ANY);
1108  st_dwithin_sig.add(SqlTypeFamily.ANY);
1109  st_dwithin_sig.add(SqlTypeFamily.NUMERIC);
1110  return st_dwithin_sig;
1111  }
1112  }
1113 
1114  static class ST_DFullyWithin extends SqlFunction {
1116  super("ST_DFullyWithin",
1117  SqlKind.OTHER_FUNCTION,
1118  null,
1119  null,
1120  OperandTypes.family(signature()),
1121  SqlFunctionCategory.SYSTEM);
1122  }
1123 
1124  @Override
1125  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1126  assert opBinding.getOperandCount() == 3;
1127  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1128  return typeFactory.createTypeWithNullability(
1129  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1130  opBinding.getOperandType(0).isNullable()
1131  || opBinding.getOperandType(1).isNullable()
1132  || opBinding.getOperandType(2).isNullable());
1133  }
1134 
1135  private static java.util.List<SqlTypeFamily> signature() {
1136  java.util.List<SqlTypeFamily> st_dwithin_sig =
1137  new java.util.ArrayList<SqlTypeFamily>();
1138  st_dwithin_sig.add(SqlTypeFamily.ANY);
1139  st_dwithin_sig.add(SqlTypeFamily.ANY);
1140  st_dwithin_sig.add(SqlTypeFamily.NUMERIC);
1141  return st_dwithin_sig;
1142  }
1143  }
1144 
1145  static class ST_Distance extends SqlFunction {
1147  super("ST_Distance",
1148  SqlKind.OTHER_FUNCTION,
1149  null,
1150  null,
1151  OperandTypes.family(signature()),
1152  SqlFunctionCategory.SYSTEM);
1153  }
1154 
1155  @Override
1156  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1157  assert opBinding.getOperandCount() == 2;
1158  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1159  return typeFactory.createTypeWithNullability(
1160  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1161  opBinding.getOperandType(0).isNullable()
1162  || opBinding.getOperandType(1).isNullable());
1163  }
1164 
1165  private static java.util.List<SqlTypeFamily> signature() {
1166  java.util.List<SqlTypeFamily> st_distance_sig =
1167  new java.util.ArrayList<SqlTypeFamily>();
1168  st_distance_sig.add(SqlTypeFamily.ANY);
1169  st_distance_sig.add(SqlTypeFamily.ANY);
1170  return st_distance_sig;
1171  }
1172  }
1173 
1174  static class ST_MaxDistance extends SqlFunction {
1176  super("ST_MaxDistance",
1177  SqlKind.OTHER_FUNCTION,
1178  null,
1179  null,
1180  OperandTypes.family(signature()),
1181  SqlFunctionCategory.SYSTEM);
1182  }
1183 
1184  @Override
1185  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1186  assert opBinding.getOperandCount() == 2;
1187  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1188  return typeFactory.createTypeWithNullability(
1189  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1190  opBinding.getOperandType(0).isNullable()
1191  || opBinding.getOperandType(1).isNullable());
1192  }
1193 
1194  private static java.util.List<SqlTypeFamily> signature() {
1195  java.util.List<SqlTypeFamily> st_maxdistance_sig =
1196  new java.util.ArrayList<SqlTypeFamily>();
1197  st_maxdistance_sig.add(SqlTypeFamily.ANY);
1198  st_maxdistance_sig.add(SqlTypeFamily.ANY);
1199  return st_maxdistance_sig;
1200  }
1201  }
1202 
1203  static class ST_GeogFromText extends SqlFunction {
1205  super("ST_GeogFromText",
1206  SqlKind.OTHER_FUNCTION,
1207  null,
1208  null,
1209  OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
1210  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
1211  SqlFunctionCategory.SYSTEM);
1212  }
1213 
1214  @Override
1215  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1216  assert opBinding.getOperandCount() == 1;
1217  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1218  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1219  }
1220  }
1221 
1222  static class ST_GeomFromText extends SqlFunction {
1224  super("ST_GeomFromText",
1225  SqlKind.OTHER_FUNCTION,
1226  null,
1227  null,
1228  OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
1229  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
1230  SqlFunctionCategory.SYSTEM);
1231  }
1232 
1233  @Override
1234  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1235  assert opBinding.getOperandCount() == 1;
1236  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1237  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1238  }
1239  }
1240 
1241  static class ST_Transform extends SqlFunction {
1243  super("ST_Transform",
1244  SqlKind.OTHER_FUNCTION,
1245  null,
1246  null,
1247  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
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.INTEGER),
1257  opBinding.getOperandType(0).isNullable());
1258  }
1259  }
1260 
1261  static class ST_X extends SqlFunction {
1262  ST_X() {
1263  super("ST_X",
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_Y extends SqlFunction {
1282  ST_Y() {
1283  super("ST_Y",
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_XMin extends SqlFunction {
1303  super("ST_XMin",
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_XMax extends SqlFunction {
1323  super("ST_XMax",
1324  SqlKind.OTHER_FUNCTION,
1325  null,
1326  null,
1327  OperandTypes.family(SqlTypeFamily.ANY),
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.DOUBLE),
1337  opBinding.getOperandType(0).isNullable());
1338  }
1339  }
1340 
1341  static class ST_YMin extends SqlFunction {
1343  super("ST_YMin",
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.DOUBLE),
1357  opBinding.getOperandType(0).isNullable());
1358  }
1359  }
1360 
1361  static class ST_YMax extends SqlFunction {
1363  super("ST_YMax",
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.DOUBLE),
1377  opBinding.getOperandType(0).isNullable());
1378  }
1379  }
1380 
1381  static class ST_PointN extends SqlFunction {
1383  super("ST_PointN",
1384  SqlKind.OTHER_FUNCTION,
1385  null,
1386  null,
1387  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
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.INTEGER),
1397  opBinding.getOperandType(0).isNullable());
1398  }
1399  }
1400 
1401  static class ST_EndPoint extends SqlFunction {
1403  super("ST_EndPoint",
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.INTEGER),
1417  opBinding.getOperandType(0).isNullable());
1418  }
1419  }
1420 
1421  static class ST_StartPoint extends SqlFunction {
1423  super("ST_StartPoint",
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.INTEGER),
1437  opBinding.getOperandType(0).isNullable());
1438  }
1439  }
1440 
1441  static class ST_Length extends SqlFunction {
1443  super("ST_Length",
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.DOUBLE),
1457  opBinding.getOperandType(0).isNullable());
1458  }
1459  }
1460 
1461  static class ST_Perimeter extends SqlFunction {
1463  super("ST_Perimeter",
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.DOUBLE),
1477  opBinding.getOperandType(0).isNullable());
1478  }
1479  }
1480 
1481  static class ST_Area extends SqlFunction {
1483  super("ST_Area",
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.DOUBLE),
1497  opBinding.getOperandType(0).isNullable());
1498  }
1499  }
1500 
1501  static class ST_NPoints extends SqlFunction {
1503  super("ST_NPoints",
1504  SqlKind.OTHER_FUNCTION,
1505  null,
1506  null,
1507  OperandTypes.family(SqlTypeFamily.ANY),
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_NRings extends SqlFunction {
1523  super("ST_NRings",
1524  SqlKind.OTHER_FUNCTION,
1525  null,
1526  null,
1527  OperandTypes.family(SqlTypeFamily.ANY),
1528  SqlFunctionCategory.SYSTEM);
1529  }
1530 
1531  @Override
1532  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1533  assert opBinding.getOperandCount() == 1;
1534  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1535  return typeFactory.createTypeWithNullability(
1536  typeFactory.createSqlType(SqlTypeName.INTEGER),
1537  opBinding.getOperandType(0).isNullable());
1538  }
1539  }
1540 
1541  static class ST_SRID extends SqlFunction {
1543  super("ST_SRID",
1544  SqlKind.OTHER_FUNCTION,
1545  null,
1546  null,
1547  OperandTypes.family(SqlTypeFamily.ANY),
1548  SqlFunctionCategory.SYSTEM);
1549  }
1550 
1551  @Override
1552  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1553  assert opBinding.getOperandCount() == 1;
1554  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1555  return typeFactory.createTypeWithNullability(
1556  typeFactory.createSqlType(SqlTypeName.INTEGER),
1557  opBinding.getOperandType(0).isNullable());
1558  }
1559  }
1560 
1561  static class ST_SetSRID extends SqlFunction {
1563  super("ST_SetSRID",
1564  SqlKind.OTHER_FUNCTION,
1565  null,
1566  null,
1567  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
1568  SqlFunctionCategory.SYSTEM);
1569  }
1570 
1571  @Override
1572  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1573  assert opBinding.getOperandCount() == 1;
1574  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1575  return typeFactory.createTypeWithNullability(
1576  typeFactory.createSqlType(SqlTypeName.INTEGER),
1577  opBinding.getOperandType(0).isNullable());
1578  }
1579  }
1580 
1581  static class ST_Point extends SqlFunction {
1583  super("ST_Point",
1584  SqlKind.OTHER_FUNCTION,
1585  null,
1586  null,
1587  OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
1588  SqlFunctionCategory.SYSTEM);
1589  }
1590 
1591  @Override
1592  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1593  assert opBinding.getOperandCount() == 2;
1594  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1595  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1596  }
1597  }
1598 
1599  static class ST_Centroid extends SqlFunction {
1601  super("ST_Centroid",
1602  SqlKind.OTHER_FUNCTION,
1603  null,
1604  null,
1605  OperandTypes.family(signature()),
1606  SqlFunctionCategory.SYSTEM);
1607  }
1608 
1609  @Override
1610  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1611  assert opBinding.getOperandCount() == 1;
1612  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1613  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1614  }
1615 
1616  private static java.util.List<SqlTypeFamily> signature() {
1617  java.util.List<SqlTypeFamily> st_centroid_sig =
1618  new java.util.ArrayList<SqlTypeFamily>();
1619  st_centroid_sig.add(SqlTypeFamily.ANY);
1620  return st_centroid_sig;
1621  }
1622  }
1623 
1624  static class ST_Buffer extends SqlFunction {
1626  super("ST_Buffer",
1627  SqlKind.OTHER_FUNCTION,
1628  null,
1629  null,
1630  OperandTypes.family(signature()),
1631  SqlFunctionCategory.SYSTEM);
1632  }
1633 
1634  @Override
1635  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1636  assert opBinding.getOperandCount() == 2;
1637  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1638  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1639  }
1640 
1641  private static java.util.List<SqlTypeFamily> signature() {
1642  java.util.List<SqlTypeFamily> st_buffer_sig =
1643  new java.util.ArrayList<SqlTypeFamily>();
1644  st_buffer_sig.add(SqlTypeFamily.ANY);
1645  st_buffer_sig.add(SqlTypeFamily.NUMERIC);
1646  return st_buffer_sig;
1647  }
1648  }
1649 
1650  static class ST_Intersection extends SqlFunction {
1652  super("ST_Intersection",
1653  SqlKind.OTHER_FUNCTION,
1654  null,
1655  null,
1656  OperandTypes.family(signature()),
1657  SqlFunctionCategory.SYSTEM);
1658  }
1659 
1660  @Override
1661  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1662  assert opBinding.getOperandCount() == 2;
1663  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1664  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1665  }
1666 
1667  private static java.util.List<SqlTypeFamily> signature() {
1668  java.util.List<SqlTypeFamily> st_intersection_sig =
1669  new java.util.ArrayList<SqlTypeFamily>();
1670  st_intersection_sig.add(SqlTypeFamily.ANY);
1671  st_intersection_sig.add(SqlTypeFamily.ANY);
1672  return st_intersection_sig;
1673  }
1674  }
1675 
1676  static class ST_Union extends SqlFunction {
1678  super("ST_Union",
1679  SqlKind.OTHER_FUNCTION,
1680  null,
1681  null,
1682  OperandTypes.family(signature()),
1683  SqlFunctionCategory.SYSTEM);
1684  }
1685 
1686  @Override
1687  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1688  assert opBinding.getOperandCount() == 2;
1689  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1690  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1691  }
1692 
1693  private static java.util.List<SqlTypeFamily> signature() {
1694  java.util.List<SqlTypeFamily> st_union_sig =
1695  new java.util.ArrayList<SqlTypeFamily>();
1696  st_union_sig.add(SqlTypeFamily.ANY);
1697  st_union_sig.add(SqlTypeFamily.ANY);
1698  return st_union_sig;
1699  }
1700  }
1701 
1702  static class ST_Difference extends SqlFunction {
1704  super("ST_Difference",
1705  SqlKind.OTHER_FUNCTION,
1706  null,
1707  null,
1708  OperandTypes.family(signature()),
1709  SqlFunctionCategory.SYSTEM);
1710  }
1711 
1712  @Override
1713  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1714  assert opBinding.getOperandCount() == 2;
1715  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1716  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1717  }
1718 
1719  private static java.util.List<SqlTypeFamily> signature() {
1720  java.util.List<SqlTypeFamily> st_difference_sig =
1721  new java.util.ArrayList<SqlTypeFamily>();
1722  st_difference_sig.add(SqlTypeFamily.ANY);
1723  st_difference_sig.add(SqlTypeFamily.ANY);
1724  return st_difference_sig;
1725  }
1726  }
1727 
1728  static class CastToGeography extends SqlFunction {
1730  super("CastToGeography",
1731  SqlKind.OTHER_FUNCTION,
1732  null,
1733  null,
1734  OperandTypes.family(SqlTypeFamily.ANY),
1735  SqlFunctionCategory.SYSTEM);
1736  }
1737 
1738  @Override
1739  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1740  assert opBinding.getOperandCount() == 1;
1741  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1742  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1743  }
1744  }
1745 
1746  /* OFFSET_IN_FRAGMENT() */
1747  public static class OffsetInFragment extends SqlFunction {
1748  public OffsetInFragment() {
1749  super("OFFSET_IN_FRAGMENT",
1750  SqlKind.OTHER_FUNCTION,
1751  null,
1752  null,
1753  OperandTypes.NILADIC,
1754  SqlFunctionCategory.SYSTEM);
1755  }
1756 
1757  @Override
1758  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1759  assert opBinding.getOperandCount() == 0;
1760  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1761  return typeFactory.createSqlType(SqlTypeName.BIGINT);
1762  }
1763  }
1764 
1765  static class ApproxCountDistinct extends SqlAggFunction {
1767  super("APPROX_COUNT_DISTINCT",
1768  null,
1769  SqlKind.OTHER_FUNCTION,
1770  null,
1771  null,
1772  OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
1773  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
1774  SqlFunctionCategory.SYSTEM,
1775  false,
1776  false,
1777  Optionality.FORBIDDEN);
1778  }
1779 
1780  @Override
1781  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1782  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1783  return typeFactory.createSqlType(SqlTypeName.BIGINT);
1784  }
1785  }
1786 
1787  static class ApproxMedian extends SqlAggFunction {
1789  super("APPROX_MEDIAN",
1790  null,
1791  SqlKind.OTHER_FUNCTION,
1792  null,
1793  null,
1794  OperandTypes.family(SqlTypeFamily.NUMERIC),
1795  SqlFunctionCategory.SYSTEM,
1796  false,
1797  false,
1798  Optionality.FORBIDDEN);
1799  }
1800 
1801  @Override
1802  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1803  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1804  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
1805  }
1806  }
1807 
1808  static class ApproxPercentile extends SqlAggFunction {
1810  super("APPROX_PERCENTILE",
1811  null,
1812  SqlKind.OTHER_FUNCTION,
1813  null,
1814  null,
1815  OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
1816  SqlFunctionCategory.SYSTEM,
1817  false,
1818  false,
1819  Optionality.FORBIDDEN);
1820  }
1821 
1822  @Override
1823  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1824  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1825  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
1826  }
1827  }
1828 
1829  static class ApproxQuantile extends SqlAggFunction {
1831  super("APPROX_QUANTILE",
1832  null,
1833  SqlKind.OTHER_FUNCTION,
1834  null,
1835  null,
1836  OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
1837  SqlFunctionCategory.SYSTEM,
1838  false,
1839  false,
1840  Optionality.FORBIDDEN);
1841  }
1842 
1843  @Override
1844  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1845  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1846  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
1847  }
1848  }
1849 
1850  static class MapDAvg extends SqlAggFunction {
1852  super("AVG",
1853  null,
1854  SqlKind.OTHER_FUNCTION,
1855  null,
1856  null,
1857  OperandTypes.family(SqlTypeFamily.NUMERIC),
1858  SqlFunctionCategory.SYSTEM);
1859  }
1860 
1861  @Override
1862  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1863  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1864  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
1865  }
1866  }
1867 
1868  public static class Sample extends SqlAggFunction {
1869  public Sample() {
1870  super("SAMPLE",
1871  null,
1872  SqlKind.OTHER_FUNCTION,
1873  null,
1874  null,
1875  OperandTypes.ANY,
1876  SqlFunctionCategory.SYSTEM,
1877  false,
1878  false,
1879  Optionality.FORBIDDEN);
1880  }
1881 
1882  @Override
1883  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1884  return opBinding.getOperandType(0);
1885  }
1886  }
1887 
1888  // for backwards compatibility
1889  public static class LastSample extends SqlAggFunction {
1890  public LastSample() {
1891  super("LAST_SAMPLE",
1892  null,
1893  SqlKind.OTHER_FUNCTION,
1894  null,
1895  null,
1896  OperandTypes.ANY,
1897  SqlFunctionCategory.SYSTEM,
1898  false,
1899  false,
1900  Optionality.FORBIDDEN);
1901  }
1902 
1903  @Override
1904  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1905  return opBinding.getOperandType(0);
1906  }
1907  }
1908 
1909  static class ExtFunction extends SqlFunction {
1910  ExtFunction(final String name, final ExtensionFunction sig) {
1911  super(name,
1912  SqlKind.OTHER_FUNCTION,
1913  null,
1914  null,
1915  OperandTypes.family(sig.toSqlSignature()),
1916  SqlFunctionCategory.SYSTEM);
1917  ret = sig.getSqlRet();
1918  }
1919 
1920  @Override
1921  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1922  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1923  return typeFactory.createTypeWithNullability(typeFactory.createSqlType(ret), true);
1924  }
1925 
1926  private final SqlTypeName ret;
1927  }
1928 
1929  public static class ExtTableFunction extends SqlFunction implements SqlTableFunction {
1930  ExtTableFunction(final String name, final ExtensionFunction sig) {
1931  super(name,
1932  SqlKind.OTHER_FUNCTION,
1933  ReturnTypes.CURSOR,
1934  null,
1935  OperandTypes.family(sig.toSqlSignature()),
1936  SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION);
1937  outs = sig.getSqlOuts();
1938  out_names = sig.getOutNames();
1939  arg_names = sig.getArgNames();
1940  options = sig.getOptions();
1941  }
1942 
1943  @Override
1944  public SqlReturnTypeInference getRowTypeInference() {
1945  return opBinding -> {
1946  FieldInfoBuilder ret = opBinding.getTypeFactory().builder();
1947  for (int out_idx = 0; out_idx < outs.size(); ++out_idx) {
1948  ret = ret.add(out_names.get(out_idx), outs.get(out_idx));
1949  }
1950  return ret.build();
1951  };
1952  }
1953  public Set<RelColumnMapping> getColumnMappings() {
1954  Set<RelColumnMapping> s = new HashSet<RelColumnMapping>();
1955  if (Integer.valueOf(options.getOrDefault("filter_table_function_transpose", "0"))
1956  == 1) {
1957  for (int arg_idx = 0; arg_idx < arg_names.size(); ++arg_idx) {
1958  String arg_name = arg_names.get(arg_idx);
1959  String[] fields;
1960  int start = arg_name.indexOf("[");
1961  if (start != -1) {
1962  int end = arg_name.lastIndexOf("]");
1963  fields = arg_name.substring(start, end).replaceAll("\\s+", "").split(",", 0);
1964  } else {
1965  fields = new String[] {arg_name};
1966  }
1967  for (int field_idx = 0; field_idx < fields.length; ++field_idx) {
1968  int out_idx = out_names.indexOf(fields[field_idx]);
1969  if (out_idx >= 0) {
1970  s.add(new RelColumnMapping(out_idx, arg_idx, field_idx, false));
1971  }
1972  }
1973  }
1974  }
1975  return s;
1976  }
1977 
1978  private final List<SqlTypeName> outs;
1979  private final List<String> arg_names;
1980  private final List<String> out_names;
1981  private final Map<String, String> options;
1982  }
1983 
1984  //
1985  // Internal accessors for in-situ poly render queries
1986  //
1987  // The MapD_* varietals are deprecated. The OmniSci_Geo_* ones should be used
1988  // instead
1989  //
1990 
1991  static class MapD_GeoPolyBoundsPtr extends SqlFunction {
1993  super("MapD_GeoPolyBoundsPtr",
1994  SqlKind.OTHER_FUNCTION,
1995  null,
1996  null,
1997  OperandTypes.family(SqlTypeFamily.ANY),
1998  SqlFunctionCategory.SYSTEM);
1999  }
2000 
2001  @Override
2002  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2003  assert opBinding.getOperandCount() == 1;
2004  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2005  return typeFactory.createSqlType(SqlTypeName.BIGINT);
2006  }
2007  }
2008 
2009  static class MapD_GeoPolyRenderGroup extends SqlFunction {
2011  super("MapD_GeoPolyRenderGroup",
2012  SqlKind.OTHER_FUNCTION,
2013  null,
2014  null,
2015  OperandTypes.family(SqlTypeFamily.ANY),
2016  SqlFunctionCategory.SYSTEM);
2017  }
2018 
2019  @Override
2020  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2021  assert opBinding.getOperandCount() == 1;
2022  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2023  return typeFactory.createSqlType(SqlTypeName.INTEGER);
2024  }
2025  }
2026 
2027  static class OmniSci_Geo_PolyBoundsPtr extends SqlFunction {
2029  super("OmniSci_Geo_PolyBoundsPtr",
2030  SqlKind.OTHER_FUNCTION,
2031  null,
2032  null,
2033  OperandTypes.family(SqlTypeFamily.ANY),
2034  SqlFunctionCategory.SYSTEM);
2035  }
2036 
2037  @Override
2038  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2039  assert opBinding.getOperandCount() == 1;
2040  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2041  return typeFactory.createSqlType(SqlTypeName.BIGINT);
2042  }
2043  }
2044 
2045  static class OmniSci_Geo_PolyRenderGroup extends SqlFunction {
2047  super("OmniSci_Geo_PolyRenderGroup",
2048  SqlKind.OTHER_FUNCTION,
2049  null,
2050  null,
2051  OperandTypes.family(SqlTypeFamily.ANY),
2052  SqlFunctionCategory.SYSTEM);
2053  }
2054 
2055  @Override
2056  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2057  assert opBinding.getOperandCount() == 1;
2058  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2059  return typeFactory.createSqlType(SqlTypeName.INTEGER);
2060  }
2061  }
2062 
2063  static class convert_meters_to_pixel_width extends SqlFunction {
2065  super("convert_meters_to_pixel_width",
2066  SqlKind.OTHER_FUNCTION,
2067  null,
2068  null,
2069  OperandTypes.family(SqlTypeFamily.NUMERIC,
2070  SqlTypeFamily.ANY,
2071  SqlTypeFamily.NUMERIC,
2072  SqlTypeFamily.NUMERIC,
2073  SqlTypeFamily.NUMERIC,
2074  SqlTypeFamily.NUMERIC),
2075  SqlFunctionCategory.SYSTEM);
2076  }
2077 
2078  @Override
2079  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2080  assert opBinding.getOperandCount() == 6;
2081  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2082  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2083  }
2084  }
2085 
2086  static class convert_meters_to_pixel_height extends SqlFunction {
2088  super("convert_meters_to_pixel_height",
2089  SqlKind.OTHER_FUNCTION,
2090  null,
2091  null,
2092  OperandTypes.family(SqlTypeFamily.NUMERIC,
2093  SqlTypeFamily.ANY,
2094  SqlTypeFamily.NUMERIC,
2095  SqlTypeFamily.NUMERIC,
2096  SqlTypeFamily.NUMERIC,
2097  SqlTypeFamily.NUMERIC),
2098  SqlFunctionCategory.SYSTEM);
2099  }
2100 
2101  @Override
2102  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2103  assert opBinding.getOperandCount() == 6;
2104  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2105  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2106  }
2107  }
2108 
2109  static class is_point_in_view extends SqlFunction {
2111  super("is_point_in_view",
2112  SqlKind.OTHER_FUNCTION,
2113  null,
2114  null,
2115  OperandTypes.family(SqlTypeFamily.ANY,
2116  SqlTypeFamily.NUMERIC,
2117  SqlTypeFamily.NUMERIC,
2118  SqlTypeFamily.NUMERIC,
2119  SqlTypeFamily.NUMERIC),
2120  SqlFunctionCategory.SYSTEM);
2121  }
2122 
2123  @Override
2124  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2125  assert opBinding.getOperandCount() == 5;
2126  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2127  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
2128  }
2129  }
2130 
2131  static class is_point_size_in_view extends SqlFunction {
2133  super("is_point_size_in_view",
2134  SqlKind.OTHER_FUNCTION,
2135  null,
2136  null,
2137  OperandTypes.family(SqlTypeFamily.ANY,
2138  SqlTypeFamily.NUMERIC,
2139  SqlTypeFamily.NUMERIC,
2140  SqlTypeFamily.NUMERIC,
2141  SqlTypeFamily.NUMERIC,
2142  SqlTypeFamily.NUMERIC),
2143  SqlFunctionCategory.SYSTEM);
2144  }
2145 
2146  @Override
2147  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2148  assert opBinding.getOperandCount() == 6;
2149  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2150  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
2151  }
2152  }
2153 
2154  public static class usTimestamp extends SqlFunction {
2155  public usTimestamp() {
2156  super("usTIMESTAMP",
2157  SqlKind.OTHER_FUNCTION,
2158  null,
2159  null,
2160  OperandTypes.STRING,
2161  SqlFunctionCategory.SYSTEM);
2162  }
2163 
2164  @Override
2165  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2166  assert opBinding.getOperandCount() == 1;
2167  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2168  return typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 6);
2169  }
2170  }
2171 
2172  public static class nsTimestamp extends SqlFunction {
2173  public nsTimestamp() {
2174  super("nsTIMESTAMP",
2175  SqlKind.OTHER_FUNCTION,
2176  null,
2177  null,
2178  OperandTypes.STRING,
2179  SqlFunctionCategory.SYSTEM);
2180  }
2181 
2182  @Override
2183  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2184  assert opBinding.getOperandCount() == 1;
2185  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2186  return typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 9);
2187  }
2188  }
2189 }
2190 
2191 // 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 java.util.List< SqlTypeFamily > signature()
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)
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)