OmniSciDB  4201147b46
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HeavyDBSqlOperatorTable.java
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, 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 
17 package com.mapd.calcite.parser;
18 
19 import com.google.common.base.Predicate;
20 import com.google.common.collect.ImmutableList;
21 import com.google.common.collect.Multimap;
23 
24 import org.apache.calcite.rel.metadata.RelColumnMapping;
25 import org.apache.calcite.rel.type.RelDataType;
26 import org.apache.calcite.rel.type.RelDataTypeFactory;
27 import org.apache.calcite.rel.type.RelDataTypeFactory.FieldInfoBuilder;
28 import org.apache.calcite.schema.FunctionParameter;
29 import org.apache.calcite.schema.TranslatableTable;
30 import org.apache.calcite.sql.SqlAggFunction;
31 import org.apache.calcite.sql.SqlCall;
32 import org.apache.calcite.sql.SqlCallBinding;
33 import org.apache.calcite.sql.SqlFunction;
34 import org.apache.calcite.sql.SqlFunctionCategory;
35 import org.apache.calcite.sql.SqlIdentifier;
36 import org.apache.calcite.sql.SqlKind;
37 import org.apache.calcite.sql.SqlLiteral;
38 import org.apache.calcite.sql.SqlNode;
39 import org.apache.calcite.sql.SqlOperator;
40 import org.apache.calcite.sql.SqlOperatorBinding;
41 import org.apache.calcite.sql.SqlOperatorTable;
42 import org.apache.calcite.sql.SqlSyntax;
43 import org.apache.calcite.sql.SqlTableFunction;
44 import org.apache.calcite.sql.fun.SqlArrayValueConstructor;
45 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
46 import org.apache.calcite.sql.parser.SqlParserPos;
47 import org.apache.calcite.sql.type.OperandTypes;
48 import org.apache.calcite.sql.type.ReturnTypes;
49 import org.apache.calcite.sql.type.SameOperandTypeChecker;
50 import org.apache.calcite.sql.type.SqlReturnTypeInference;
51 import org.apache.calcite.sql.type.SqlTypeFamily;
52 import org.apache.calcite.sql.type.SqlTypeName;
53 import org.apache.calcite.sql.type.SqlTypeTransforms;
54 import org.apache.calcite.sql.type.SqlTypeUtil;
55 import org.apache.calcite.sql.util.ChainedSqlOperatorTable;
56 import org.apache.calcite.sql.util.ListSqlOperatorTable;
57 import org.apache.calcite.sql.util.ReflectiveSqlOperatorTable;
58 import org.apache.calcite.sql.validate.SqlNameMatcher;
59 import org.apache.calcite.util.Optionality;
60 import org.checkerframework.checker.nullness.qual.Nullable;
61 import org.slf4j.Logger;
62 import org.slf4j.LoggerFactory;
63 
64 import java.lang.reflect.Field;
65 import java.util.Arrays;
66 import java.util.HashSet;
67 import java.util.Iterator;
68 import java.util.List;
69 import java.util.Map;
70 import java.util.Set;
71 
72 class CaseInsensitiveListSqlOperatorTable extends ListSqlOperatorTable {
73  @Override
74  public void lookupOperatorOverloads(SqlIdentifier opName,
75  SqlFunctionCategory category,
76  SqlSyntax syntax,
77  List<SqlOperator> operatorList,
78  SqlNameMatcher nameMatcher) {
79  for (SqlOperator operator : this.getOperatorList()) {
80  if (operator.getSyntax() != syntax) {
81  continue;
82  }
83  if (!opName.isSimple()
84  || !nameMatcher.matches(operator.getName(), opName.getSimple())) {
85  continue;
86  }
87  SqlFunctionCategory functionCategory;
88  if (operator instanceof SqlFunction) {
89  functionCategory = ((SqlFunction) operator).getFunctionType();
90  } else {
91  functionCategory = SqlFunctionCategory.SYSTEM;
92  }
93  if (category != functionCategory
94  && category != SqlFunctionCategory.USER_DEFINED_FUNCTION) {
95  continue;
96  }
97  operatorList.add(operator);
98  }
99  }
100 }
101 
102 public class HeavyDBSqlOperatorTable extends ChainedSqlOperatorTable {
105 
106  static {
107  try {
108  // some nasty bit to remove the std APPROX_COUNT_DISTINCT function definition
109  {
110  Field f = ReflectiveSqlOperatorTable.class.getDeclaredField(
111  "caseSensitiveOperators");
112  f.setAccessible(true);
113  Multimap operators = (Multimap) f.get(SqlStdOperatorTable.instance());
114  for (Iterator i = operators.entries().iterator(); i.hasNext();) {
115  Map.Entry entry = (Map.Entry) i.next();
116  if (entry.getValue() == SqlStdOperatorTable.APPROX_COUNT_DISTINCT
117  || entry.getValue() == SqlStdOperatorTable.AVG
118  || entry.getValue() == SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR) {
119  i.remove();
120  }
121  }
122  }
123 
124  {
125  Field f = ReflectiveSqlOperatorTable.class.getDeclaredField(
126  "caseInsensitiveOperators");
127  f.setAccessible(true);
128  Multimap operators = (Multimap) f.get(SqlStdOperatorTable.instance());
129  for (Iterator i = operators.entries().iterator(); i.hasNext();) {
130  Map.Entry entry = (Map.Entry) i.next();
131  if (entry.getValue() == SqlStdOperatorTable.APPROX_COUNT_DISTINCT
132  || entry.getValue() == SqlStdOperatorTable.AVG
133  || entry.getValue() == SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR) {
134  i.remove();
135  }
136  }
137  }
138 
139  SqlStdOperatorTable.instance().register(ARRAY_VALUE_CONSTRUCTOR);
140 
141  } catch (Exception e) {
142  throw new RuntimeException(e);
143  }
144 
145  // register our approx count distinct against std table
146  // SqlStdOperatorTable.instance().register(new ApproxCountDistinct());
147  }
148 
149  final static Logger HEAVYDBLOGGER =
150  LoggerFactory.getLogger(HeavyDBSqlOperatorTable.class);
151 
156  // ~ Instance fields --------------------------------------------------------
157  private final ListSqlOperatorTable listOpTab;
158 
159  // ~ Constructors -----------------------------------------------------------
160  public HeavyDBSqlOperatorTable(SqlOperatorTable parentTable) {
161  super(ImmutableList.of(parentTable, new CaseInsensitiveListSqlOperatorTable()));
162  listOpTab = (ListSqlOperatorTable) tableList.get(1);
163  }
164 
170  public void addOperator(SqlOperator op) {
171  listOpTab.add(op);
172  }
173 
174  public static void addUDF(
175  HeavyDBSqlOperatorTable opTab, final Map<String, ExtensionFunction> extSigs) {
176  // Don't use anonymous inner classes. They can't be instantiated
177  // using reflection when we are deserializing from JSON.
178  // opTab.addOperator(new RampFunction());
179  // opTab.addOperator(new DedupFunction());
180  opTab.addOperator(new MyUDFFunction());
181  opTab.addOperator(new PgUnnest());
182  opTab.addOperator(new Any());
183  opTab.addOperator(new All());
184  opTab.addOperator(new Now());
185  opTab.addOperator(new Datetime());
186  opTab.addOperator(new PgExtract());
187  opTab.addOperator(new Dateadd());
188  opTab.addOperator(new Datediff());
189  opTab.addOperator(new Datepart());
190  opTab.addOperator(new PgDateTrunc());
191  opTab.addOperator(new Length());
192  opTab.addOperator(new CharLength());
193  opTab.addOperator(new KeyForString());
194  opTab.addOperator(new SampleRatio());
195  opTab.addOperator(new WidthBucket());
196  opTab.addOperator(new ArrayLength());
197  opTab.addOperator(new PgILike());
198  opTab.addOperator(new LTrim());
199  opTab.addOperator(new RTrim());
200  opTab.addOperator(new LPad());
201  opTab.addOperator(new RPad());
202  opTab.addOperator(new Replace());
203  opTab.addOperator(new Reverse());
204  opTab.addOperator(new Repeat());
205  opTab.addOperator(new SplitPart());
206  opTab.addOperator(new RegexpLike());
207  opTab.addOperator(new RegexpReplace());
208  opTab.addOperator(new RegexpSubstr());
209  opTab.addOperator(new RegexpMatch());
210  opTab.addOperator(new Likely());
211  opTab.addOperator(new Unlikely());
212  opTab.addOperator(new Sign());
213  opTab.addOperator(new Truncate());
214  opTab.addOperator(new ST_IsEmpty());
215  opTab.addOperator(new ST_IsValid());
216  opTab.addOperator(new ST_Contains());
217  opTab.addOperator(new ST_Equals());
218  opTab.addOperator(new ST_Intersects());
219  opTab.addOperator(new ST_Overlaps());
220  opTab.addOperator(new ST_Approx_Overlaps());
221  opTab.addOperator(new ST_Disjoint());
222  opTab.addOperator(new ST_Within());
223  opTab.addOperator(new ST_DWithin());
224  opTab.addOperator(new ST_DFullyWithin());
225  opTab.addOperator(new ST_Distance());
226  opTab.addOperator(new ST_MaxDistance());
227  opTab.addOperator(new ST_GeogFromText());
228  opTab.addOperator(new ST_GeomFromText());
229  opTab.addOperator(new ST_Transform());
230  opTab.addOperator(new ST_X());
231  opTab.addOperator(new ST_Y());
232  opTab.addOperator(new ST_XMin());
233  opTab.addOperator(new ST_XMax());
234  opTab.addOperator(new ST_YMin());
235  opTab.addOperator(new ST_YMax());
236  opTab.addOperator(new ST_PointN());
237  opTab.addOperator(new ST_StartPoint());
238  opTab.addOperator(new ST_EndPoint());
239  opTab.addOperator(new ST_Length());
240  opTab.addOperator(new ST_Perimeter());
241  opTab.addOperator(new ST_Area());
242  opTab.addOperator(new ST_NPoints());
243  opTab.addOperator(new ST_NRings());
244  opTab.addOperator(new ST_SRID());
245  opTab.addOperator(new ST_SetSRID());
246  opTab.addOperator(new ST_Point());
247  opTab.addOperator(new ST_Centroid());
248  opTab.addOperator(new ST_Buffer());
249  opTab.addOperator(new ST_Intersection());
250  opTab.addOperator(new ST_Union());
251  opTab.addOperator(new ST_Difference());
252  opTab.addOperator(new CastToGeography());
253  opTab.addOperator(new EncodeText());
254  opTab.addOperator(new OffsetInFragment());
255  opTab.addOperator(new ApproxCountDistinct());
256  opTab.addOperator(new ApproxMedian());
257  opTab.addOperator(new ApproxPercentile());
258  opTab.addOperator(new ApproxQuantile());
259  opTab.addOperator(new MapDAvg());
260  opTab.addOperator(new Sample());
261  opTab.addOperator(new LastSample());
262  opTab.addOperator(new HeavyDB_Geo_PolyBoundsPtr());
263  opTab.addOperator(new HeavyDB_Geo_PolyRenderGroup());
264  opTab.addOperator(new convert_meters_to_pixel_width());
265  opTab.addOperator(new convert_meters_to_pixel_height());
266  opTab.addOperator(new is_point_in_view());
267  opTab.addOperator(new is_point_size_in_view());
268  opTab.addOperator(new usTimestamp());
269  opTab.addOperator(new nsTimestamp());
270  if (extSigs == null) {
271  return;
272  }
273  HashSet<String> demangledNames = new HashSet<String>();
274  for (Map.Entry<String, ExtensionFunction> extSig : extSigs.entrySet()) {
275  final String demangledName = dropSuffix(extSig.getKey());
276  final String demangledNameArity =
277  String.format("%s-%d", demangledName, extSig.getValue().getArgs().size());
278  if (demangledNames.contains(demangledNameArity)) {
279  continue;
280  }
281  demangledNames.add(demangledNameArity);
282  if (extSig.getValue().isRowUdf()) {
283  opTab.addOperator(new ExtFunction(demangledName, extSig.getValue()));
284  } else {
285  opTab.addOperator(new ExtTableFunction(demangledName, extSig.getValue()));
286  }
287  }
288  }
289 
290  private static String dropSuffix(final String str) {
291  int suffix_idx = str.indexOf("__");
292  if (suffix_idx == -1) {
293  return str;
294  }
295  assert suffix_idx > 0;
296  return str.substring(0, suffix_idx);
297  }
298 
299  //@Deprecated // to be removed before 2.0
300  // public static final SqlFunction LTRIM = SqlLibraryOperators.LTRIM;
301 
302  //@Deprecated // to be removed before 2.0
303  // public static final SqlFunction RTRIM = SqlLibraryOperators.RTRIM;
304 
306  extends SqlArrayValueConstructor {
307  @Override
308  protected RelDataType getComponentType(
309  RelDataTypeFactory typeFactory, List<RelDataType> argTypes) {
310  if (argTypes.isEmpty()) {
311  return typeFactory.createSqlType(SqlTypeName.NULL);
312  }
313  return super.getComponentType(typeFactory, argTypes);
314  }
315 
316  @Override
317  public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
318  if (callBinding.operands().isEmpty()) {
319  return true;
320  }
321  return super.checkOperandTypes(callBinding, throwOnFailure);
322  }
323  }
324 
328  public static class RampFunction extends SqlFunction {
329  public RampFunction() {
330  super("RAMP",
331  SqlKind.OTHER_FUNCTION,
332  null,
333  null,
334  OperandTypes.NUMERIC,
335  SqlFunctionCategory.USER_DEFINED_FUNCTION);
336  }
337 
338  @Override
339  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
340  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
341  return typeFactory.builder().add("I", SqlTypeName.INTEGER).build();
342  }
343  }
344 
348  public static class DedupFunction extends SqlFunction {
349  public DedupFunction() {
350  super("DEDUP",
351  SqlKind.OTHER_FUNCTION,
352  null,
353  null,
354  OperandTypes.VARIADIC,
355  SqlFunctionCategory.USER_DEFINED_FUNCTION);
356  }
357 
358  @Override
359  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
360  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
361  return typeFactory.builder().add("NAME", SqlTypeName.VARCHAR, 1024).build();
362  }
363  }
364 
369  public static class MyUDFFunction extends SqlFunction {
370  public MyUDFFunction() {
371  super("MyUDF",
372  SqlKind.OTHER_FUNCTION,
373  null,
374  null,
375  OperandTypes.STRING_STRING,
376  SqlFunctionCategory.SYSTEM);
377  }
378 
379  @Override
380  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
381  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
382  return typeFactory.createSqlType(SqlTypeName.BIGINT);
383  }
384  }
385 
386  /* Postgres-style UNNEST */
387  public static class PgUnnest extends SqlFunction {
388  public PgUnnest() {
389  super("PG_UNNEST",
390  SqlKind.OTHER_FUNCTION,
391  null,
392  null,
393  OperandTypes.ARRAY,
394  SqlFunctionCategory.SYSTEM);
395  }
396 
397  @Override
398  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
399  assert opBinding.getOperandCount() == 1;
400  RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
401  assert elem_type != null;
402  return elem_type;
403  }
404  }
405 
406  /* ANY qualifier */
407  public static class Any extends SqlFunction {
408  public Any() {
409  super("PG_ANY",
410  SqlKind.OTHER_FUNCTION,
411  null,
412  null,
413  OperandTypes.ARRAY,
414  SqlFunctionCategory.SYSTEM);
415  }
416 
417  @Override
418  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
419  assert opBinding.getOperandCount() == 1;
420  RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
421  assert elem_type != null;
422  return elem_type;
423  }
424  }
425 
426  /* ALL qualifier */
427  public static class All extends SqlFunction {
428  public All() {
429  super("PG_ALL",
430  SqlKind.OTHER_FUNCTION,
431  null,
432  null,
433  OperandTypes.ARRAY,
434  SqlFunctionCategory.SYSTEM);
435  }
436 
437  @Override
438  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
439  assert opBinding.getOperandCount() == 1;
440  RelDataType elem_type = opBinding.getOperandType(0).getComponentType();
441  assert elem_type != null;
442  return elem_type;
443  }
444  }
445 
446  /* NOW() */
447  public static class Now extends SqlFunction {
448  public Now() {
449  super("NOW",
450  SqlKind.OTHER_FUNCTION,
451  null,
452  null,
453  OperandTypes.NILADIC,
454  SqlFunctionCategory.SYSTEM);
455  }
456 
457  @Override
458  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
459  assert opBinding.getOperandCount() == 0;
460  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
461  return typeFactory.createSqlType(SqlTypeName.TIMESTAMP);
462  }
463  }
464 
465  /* DATETIME */
466  public static class Datetime extends SqlFunction {
467  public Datetime() {
468  super("DATETIME",
469  SqlKind.OTHER_FUNCTION,
470  null,
471  null,
472  OperandTypes.STRING,
473  SqlFunctionCategory.SYSTEM);
474  }
475 
476  @Override
477  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
478  assert opBinding.getOperandCount() == 1;
479  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
480  return typeFactory.createSqlType(
481  SqlTypeName.TIMESTAMP, opBinding.getOperandType(0).getPrecision());
482  }
483  }
484 
485  /* Postgres-style EXTRACT */
486  public static class PgExtract extends SqlFunction {
487  public PgExtract() {
488  super("PG_EXTRACT",
489  SqlKind.OTHER_FUNCTION,
490  null,
491  null,
492  OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
493  SqlFunctionCategory.SYSTEM);
494  }
495 
496  @Override
497  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
498  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
499  return typeFactory.createTypeWithNullability(
500  typeFactory.createSqlType(SqlTypeName.BIGINT),
501  opBinding.getOperandType(1).isNullable());
502  }
503  }
504 
505  public static class Datepart extends SqlFunction {
506  public Datepart() {
507  super("DATEPART",
508  SqlKind.OTHER_FUNCTION,
509  null,
510  null,
511  OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
512  SqlFunctionCategory.TIMEDATE);
513  }
514 
515  @Override
516  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
517  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
518  return typeFactory.createTypeWithNullability(
519  typeFactory.createSqlType(SqlTypeName.BIGINT),
520  opBinding.getOperandType(1).isNullable());
521  }
522  }
523 
524  public static class Dateadd extends SqlFunction {
525  public Dateadd() {
526  super("DATEADD",
527  SqlKind.OTHER_FUNCTION,
528  null,
529  null,
530  OperandTypes.family(SqlTypeFamily.STRING,
531  SqlTypeFamily.INTEGER,
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(
541  SqlTypeName.TIMESTAMP, opBinding.getOperandType(2).getPrecision()),
542  opBinding.getOperandType(2).isNullable());
543  }
544  }
545 
546  public static class Datediff extends SqlFunction {
547  public Datediff() {
548  super("DATEDIFF",
549  SqlKind.OTHER_FUNCTION,
550  null,
551  null,
552  OperandTypes.family(SqlTypeFamily.STRING,
553  SqlTypeFamily.DATETIME,
554  SqlTypeFamily.DATETIME),
555  SqlFunctionCategory.TIMEDATE);
556  }
557 
558  @Override
559  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
560  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
561  return typeFactory.createTypeWithNullability(
562  typeFactory.createSqlType(SqlTypeName.BIGINT),
563  opBinding.getOperandType(1).isNullable()
564  || opBinding.getOperandType(2).isNullable());
565  }
566  }
567 
568  /* Postgres-style DATE_TRUNC */
569  public static class PgDateTrunc extends SqlFunction {
570  public PgDateTrunc() {
571  super("PG_DATE_TRUNC",
572  SqlKind.OTHER_FUNCTION,
573  null,
574  null,
575  OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.DATETIME),
576  SqlFunctionCategory.SYSTEM);
577  }
578 
579  @Override
580  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
581  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
582  return typeFactory.createTypeWithNullability(
583  typeFactory.createSqlType(
584  SqlTypeName.TIMESTAMP, opBinding.getOperandType(1).getPrecision()),
585  opBinding.getOperandType(1).isNullable());
586  }
587  }
588 
589  public static class Length extends SqlFunction {
590  public Length() {
591  super("LENGTH",
592  SqlKind.OTHER_FUNCTION,
593  null,
594  null,
595  OperandTypes.STRING,
596  SqlFunctionCategory.SYSTEM);
597  }
598 
599  @Override
600  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
601  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
602  return typeFactory.createSqlType(SqlTypeName.INTEGER);
603  }
604  }
605 
606  public static class CharLength extends SqlFunction {
607  public CharLength() {
608  super("CHAR_LENGTH",
609  SqlKind.OTHER_FUNCTION,
610  null,
611  null,
612  OperandTypes.STRING,
613  SqlFunctionCategory.SYSTEM);
614  }
615 
616  @Override
617  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
618  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
619  return typeFactory.createSqlType(SqlTypeName.INTEGER);
620  }
621  }
622 
623  public static class KeyForString extends SqlFunction {
624  public KeyForString() {
625  super("KEY_FOR_STRING",
626  SqlKind.OTHER_FUNCTION,
627  null,
628  null,
629  OperandTypes.STRING,
630  SqlFunctionCategory.SYSTEM);
631  }
632 
633  @Override
634  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
635  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
636  return typeFactory.createTypeWithNullability(
637  typeFactory.createSqlType(SqlTypeName.INTEGER),
638  opBinding.getOperandType(0).isNullable());
639  }
640  }
641 
642  public static class SampleRatio extends SqlFunction {
643  public SampleRatio() {
644  super("SAMPLE_RATIO",
645  SqlKind.OTHER_FUNCTION,
646  null,
647  null,
648  OperandTypes.family(signature()),
649  SqlFunctionCategory.SYSTEM);
650  }
651 
652  @Override
653  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
654  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
655  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
656  }
657 
658  private static java.util.List<SqlTypeFamily> signature() {
659  java.util.ArrayList<SqlTypeFamily> families =
660  new java.util.ArrayList<SqlTypeFamily>();
661  families.add(SqlTypeFamily.NUMERIC);
662  return families;
663  }
664  }
665 
666  public static class WidthBucket extends SqlFunction {
667  public WidthBucket() {
668  super("WIDTH_BUCKET",
669  SqlKind.OTHER_FUNCTION,
670  null,
671  null,
672  OperandTypes.family(signature()),
673  SqlFunctionCategory.SYSTEM);
674  }
675 
676  @Override
677  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
678  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
679  return typeFactory.createTypeWithNullability(
680  typeFactory.createSqlType(SqlTypeName.INTEGER), /*nullable=*/true);
681  }
682 
683  private static java.util.List<SqlTypeFamily> signature() {
684  java.util.ArrayList<SqlTypeFamily> families =
685  new java.util.ArrayList<SqlTypeFamily>();
686  families.add(SqlTypeFamily.NUMERIC);
687  families.add(SqlTypeFamily.NUMERIC);
688  families.add(SqlTypeFamily.NUMERIC);
689  families.add(SqlTypeFamily.INTEGER);
690  return families;
691  }
692  }
693 
694  public static class ArrayLength extends SqlFunction {
695  public ArrayLength() {
696  super("ARRAY_LENGTH",
697  SqlKind.OTHER_FUNCTION,
698  null,
699  null,
700  OperandTypes.ARRAY,
701  SqlFunctionCategory.SYSTEM);
702  }
703 
704  @Override
705  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
706  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
707  return typeFactory.createSqlType(SqlTypeName.INTEGER);
708  }
709  }
710 
711  public static class PgILike extends SqlFunction {
712  public PgILike() {
713  super("PG_ILIKE",
714  SqlKind.OTHER_FUNCTION,
715  null,
716  null,
717  OperandTypes.family(getSignatureFamilies(), new EscapeOptional()),
718  SqlFunctionCategory.SYSTEM);
719  }
720 
721  private static java.util.List<SqlTypeFamily> getSignatureFamilies() {
722  java.util.ArrayList<SqlTypeFamily> families =
723  new java.util.ArrayList<SqlTypeFamily>();
724  families.add(SqlTypeFamily.STRING);
725  families.add(SqlTypeFamily.STRING);
726  families.add(SqlTypeFamily.STRING);
727  return families;
728  }
729 
730  private static class EscapeOptional
731  implements java.util.function.Predicate<Integer>, Predicate<Integer> {
732  @Override
733  public boolean test(Integer t) {
734  return apply(t);
735  }
736 
737  @Override
738  public boolean apply(Integer t) {
739  return t == 2;
740  }
741  }
742 
743  @Override
744  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
745  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
746  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
747  }
748  }
749 
750  public static class RegexpLike extends SqlFunction {
751  public RegexpLike() {
752  super("REGEXP_LIKE",
753  SqlKind.OTHER_FUNCTION,
754  null,
755  null,
756  OperandTypes.family(getSignatureFamilies(), new EscapeOptional()),
757  SqlFunctionCategory.SYSTEM);
758  }
759 
760  private static java.util.List<SqlTypeFamily> getSignatureFamilies() {
761  java.util.ArrayList<SqlTypeFamily> families =
762  new java.util.ArrayList<SqlTypeFamily>();
763  families.add(SqlTypeFamily.STRING);
764  families.add(SqlTypeFamily.STRING);
765  families.add(SqlTypeFamily.STRING);
766  return families;
767  }
768 
769  private static class EscapeOptional
770  implements java.util.function.Predicate<Integer>, Predicate<Integer> {
771  @Override
772  public boolean test(Integer t) {
773  return apply(t);
774  }
775 
776  public boolean apply(Integer t) {
777  return t == 2;
778  }
779  }
780 
781  @Override
782  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
783  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
784  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
785  }
786  }
787 
788  public static class LeftRightTrim extends SqlFunction {
789  public LeftRightTrim(final String name, final SqlKind kind) {
790  super(name,
791  kind,
792  ReturnTypes.ARG0.andThen(SqlTypeTransforms.TO_NULLABLE)
793  .andThen(SqlTypeTransforms.TO_VARYING),
794  null,
795  OperandTypes.and(
796  OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.STRING),
797  new SameOperandTypeChecker(2) {
798  @Override
799  protected List<Integer> getOperandList(int operandCount) {
800  return ImmutableList.of(0, 1);
801  }
802  }),
803  SqlFunctionCategory.STRING);
804  }
805 
806  @Override
807  public SqlCall createCall(@Nullable SqlLiteral functionQualifier,
808  SqlParserPos pos,
809  @Nullable SqlNode... operands) {
810  assert functionQualifier == null;
811  switch (operands.length) {
812  case 1:
813  operands = new SqlNode[] {SqlLiteral.createCharString(" ", pos), operands[0]};
814  break;
815  case 2:
816  if (operands[1] == null) {
817  operands[1] = SqlLiteral.createCharString(" ", pos);
818  }
819  operands = new SqlNode[] {operands[1], operands[0]};
820  break;
821  default:
822  throw new IllegalArgumentException(
823  "Invalid operand count " + Arrays.toString(operands));
824  }
825  return super.createCall(functionQualifier, pos, operands);
826  }
827  }
828 
829  public static class LTrim extends LeftRightTrim {
830  public LTrim() {
831  super("LTRIM", SqlKind.LTRIM);
832  }
833  }
834  public static class RTrim extends LeftRightTrim {
835  public RTrim() {
836  super("RTRIM", SqlKind.RTRIM);
837  }
838  }
839  public static class LeftRightPad extends SqlFunction {
840  public LeftRightPad(final String name) {
841  super(name,
842  SqlKind.OTHER_FUNCTION,
843  ReturnTypes.ARG0.andThen(SqlTypeTransforms.TO_NULLABLE)
844  .andThen(SqlTypeTransforms.TO_VARYING),
845  null,
846  OperandTypes.and(OperandTypes.family(SqlTypeFamily.STRING,
847  SqlTypeFamily.INTEGER,
848  SqlTypeFamily.STRING),
849  new SameOperandTypeChecker(3) {
850  @Override
851  protected List<Integer> getOperandList(int operandCount) {
852  return ImmutableList.of(0, 2);
853  }
854  }),
855  SqlFunctionCategory.STRING);
856  }
857 
858  @Override
859  public SqlCall createCall(@Nullable SqlLiteral functionQualifier,
860  SqlParserPos pos,
861  @Nullable SqlNode... operands) {
862  assert functionQualifier == null;
863  switch (operands.length) {
864  case 2:
865  operands = new SqlNode[] {
866  operands[0], operands[1], SqlLiteral.createCharString(" ", pos)};
867  break;
868  case 3:
869  if (operands[2] == null) {
870  operands[2] = SqlLiteral.createCharString(" ", pos);
871  }
872  operands = new SqlNode[] {operands[0], operands[1], operands[2]};
873  break;
874  default:
875  throw new IllegalArgumentException(
876  "Invalid operand count " + Arrays.toString(operands));
877  }
878  return super.createCall(functionQualifier, pos, operands);
879  }
880 
881  @Override
882  public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
883  if (!super.checkOperandTypes(callBinding, throwOnFailure)) {
884  return false;
885  }
886  switch (kind) {
887  case TRIM:
888  return SqlTypeUtil.isCharTypeComparable(callBinding,
889  ImmutableList.of(callBinding.operand(0), callBinding.operand(2)),
890  throwOnFailure);
891  default:
892  return true;
893  }
894  }
895  }
896 
897  public static class LPad extends LeftRightPad {
898  public LPad() {
899  super("LPAD");
900  }
901  }
902  public static class RPad extends LeftRightPad {
903  public RPad() {
904  super("RPAD");
905  }
906  }
907 
908  public static class SplitPart extends SqlFunction {
909  public SplitPart() {
910  super("SPLIT_PART",
911  SqlKind.OTHER_FUNCTION,
912  null,
913  null,
914  OperandTypes.family(getSignatureFamilies()),
916  }
917 
918  private static java.util.List<SqlTypeFamily> getSignatureFamilies() {
919  java.util.ArrayList<SqlTypeFamily> families =
920  new java.util.ArrayList<SqlTypeFamily>();
921  families.add(SqlTypeFamily.STRING);
922  families.add(SqlTypeFamily.STRING);
923  families.add(SqlTypeFamily.INTEGER);
924  return families;
925  }
926 
927  @Override
928  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
929  return opBinding.getOperandType(0);
930  }
931  }
932 
933  public static class Replace extends SqlFunction {
934  public Replace() {
935  super("REPLACE",
936  SqlKind.OTHER_FUNCTION,
937  null,
938  null,
939  OperandTypes.family(getSignatureFamilies()),
941  }
942 
943  private static java.util.List<SqlTypeFamily> getSignatureFamilies() {
944  java.util.ArrayList<SqlTypeFamily> families =
945  new java.util.ArrayList<SqlTypeFamily>();
946  families.add(SqlTypeFamily.STRING);
947  families.add(SqlTypeFamily.STRING);
948  families.add(SqlTypeFamily.STRING);
949  return families;
950  }
951 
952  @Override
953  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
954  return opBinding.getOperandType(0);
955  }
956 
957  @Override
958  public SqlCall createCall(@Nullable SqlLiteral functionQualifier,
959  SqlParserPos pos,
960  @Nullable SqlNode... operands) {
961  assert functionQualifier == null;
962  switch (operands.length) {
963  case 2:
964  operands = new SqlNode[] {
965  operands[0], operands[1], SqlLiteral.createCharString("", pos)};
966  break;
967  case 3:
968  break;
969  default:
970  throw new IllegalArgumentException(
971  "Invalid operand count " + Arrays.toString(operands));
972  }
973  return super.createCall(functionQualifier, pos, operands);
974  }
975  }
976  public static class Reverse extends SqlFunction {
977  public Reverse() {
978  super("REVERSE",
979  SqlKind.OTHER_FUNCTION,
980  null,
981  null,
982  OperandTypes.family(getSignatureFamilies()),
984  }
985 
986  private static java.util.List<SqlTypeFamily> getSignatureFamilies() {
987  java.util.ArrayList<SqlTypeFamily> families =
988  new java.util.ArrayList<SqlTypeFamily>();
989  families.add(SqlTypeFamily.STRING);
990  return families;
991  }
992 
993  @Override
994  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
995  return opBinding.getOperandType(0);
996  }
997  }
998  public static class Repeat extends SqlFunction {
999  public Repeat() {
1000  super("REPEAT",
1001  SqlKind.OTHER_FUNCTION,
1002  null,
1003  null,
1004  OperandTypes.family(getSignatureFamilies()),
1006  }
1007 
1008  private static java.util.List<SqlTypeFamily> getSignatureFamilies() {
1009  java.util.ArrayList<SqlTypeFamily> families =
1010  new java.util.ArrayList<SqlTypeFamily>();
1011  families.add(SqlTypeFamily.STRING);
1012  families.add(SqlTypeFamily.INTEGER);
1013  return families;
1014  }
1015 
1016  @Override
1017  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1018  return opBinding.getOperandType(0);
1019  }
1020  }
1021 
1022  public static class RegexpReplace extends SqlFunction {
1023  public RegexpReplace() {
1024  super("REGEXP_REPLACE",
1025  SqlKind.OTHER_FUNCTION,
1026  null,
1027  null,
1028  OperandTypes.family(getSignatureFamilies()),
1030  }
1031 
1032  private static java.util.List<SqlTypeFamily> getSignatureFamilies() {
1033  java.util.ArrayList<SqlTypeFamily> families =
1034  new java.util.ArrayList<SqlTypeFamily>();
1035  families.add(SqlTypeFamily.STRING);
1036  families.add(SqlTypeFamily.STRING);
1037  families.add(SqlTypeFamily.STRING);
1038  families.add(SqlTypeFamily.INTEGER);
1039  families.add(SqlTypeFamily.INTEGER);
1040  families.add(SqlTypeFamily.STRING);
1041  return families;
1042  }
1043 
1044  @Override
1045  public SqlCall createCall(@Nullable SqlLiteral functionQualifier,
1046  SqlParserPos pos,
1047  @Nullable SqlNode... operands) {
1048  assert functionQualifier == null;
1049  final int num_operands = operands.length;
1050  if (num_operands < 2 || num_operands > 6) {
1051  throw new IllegalArgumentException(
1052  "Invalid operand count " + Arrays.toString(operands));
1053  }
1054  SqlNode[] new_operands = new SqlNode[6];
1055  // operand string
1056  new_operands[0] = operands[0];
1057  // pattern
1058  new_operands[1] = operands[1];
1059  // replacement
1060  if (num_operands < 3 || operands[2] == null) {
1061  new_operands[2] = SqlLiteral.createCharString("", pos);
1062  } else {
1063  new_operands[2] = operands[2];
1064  }
1065  // position
1066  if (num_operands < 4 || operands[3] == null) {
1067  new_operands[3] = SqlLiteral.createExactNumeric("1", pos);
1068  } else {
1069  new_operands[3] = operands[3];
1070  }
1071  // occurrence
1072  if (num_operands < 5 || operands[4] == null) {
1073  new_operands[4] = SqlLiteral.createExactNumeric("0", pos);
1074  } else {
1075  new_operands[4] = operands[4];
1076  }
1077  // parameters
1078  if (num_operands < 6 || operands[5] == null) {
1079  new_operands[5] = SqlLiteral.createCharString("c", pos);
1080  } else {
1081  new_operands[5] = operands[5];
1082  }
1083  return super.createCall(functionQualifier, pos, new_operands);
1084  }
1085 
1086  @Override
1087  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1088  return opBinding.getOperandType(0);
1089  }
1090  }
1091 
1092  public static class RegexpSubstr extends SqlFunction {
1093  public RegexpSubstr() {
1094  super("REGEXP_SUBSTR",
1095  SqlKind.OTHER_FUNCTION,
1096  null,
1097  null,
1098  OperandTypes.family(getSignatureFamilies()),
1100  }
1101 
1102  public RegexpSubstr(final String alias) {
1103  super(alias,
1104  SqlKind.OTHER_FUNCTION,
1105  null,
1106  null,
1107  OperandTypes.family(getSignatureFamilies()),
1108  SqlFunctionCategory.SYSTEM);
1109  }
1110 
1111  private static java.util.List<SqlTypeFamily> getSignatureFamilies() {
1112  java.util.ArrayList<SqlTypeFamily> families =
1113  new java.util.ArrayList<SqlTypeFamily>();
1114  families.add(SqlTypeFamily.STRING);
1115  families.add(SqlTypeFamily.STRING);
1116  families.add(SqlTypeFamily.INTEGER);
1117  families.add(SqlTypeFamily.INTEGER);
1118  families.add(SqlTypeFamily.STRING);
1119  families.add(SqlTypeFamily.INTEGER);
1120  return families;
1121  }
1122 
1123  @Override
1124  public SqlCall createCall(@Nullable SqlLiteral functionQualifier,
1125  SqlParserPos pos,
1126  @Nullable SqlNode... operands) {
1127  assert functionQualifier == null;
1128  final int num_operands = operands.length;
1129  if (num_operands < 2 || num_operands > 6) {
1130  throw new IllegalArgumentException(
1131  "Invalid operand count " + Arrays.toString(operands));
1132  }
1133  SqlNode[] new_operands = new SqlNode[6];
1134 
1135  // operand string (required)
1136  new_operands[0] = operands[0];
1137  // pattern (required)
1138  new_operands[1] = operands[1];
1139  // start position
1140  if (num_operands < 3 || operands[2] == null) {
1141  new_operands[2] = SqlLiteral.createExactNumeric("1", pos);
1142  } else {
1143  new_operands[2] = operands[2];
1144  }
1145  // match occurrence
1146  if (num_operands < 4 || operands[3] == null) {
1147  new_operands[3] = SqlLiteral.createExactNumeric("1", pos);
1148  } else {
1149  new_operands[3] = operands[3];
1150  }
1151  // regex params (default 'c' = case sensitive)
1152  if (num_operands < 5 || operands[4] == null) {
1153  new_operands[4] = SqlLiteral.createCharString("c", pos);
1154  } else {
1155  new_operands[4] = operands[4];
1156  }
1157  // Sub-match occurrence, valid with regex param 'e'
1158  if (num_operands < 6 || operands[5] == null) {
1159  new_operands[5] = SqlLiteral.createExactNumeric("1", pos);
1160  } else {
1161  new_operands[5] = operands[5];
1162  }
1163  return super.createCall(functionQualifier, pos, new_operands);
1164  }
1165 
1166  @Override
1167  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1168  return opBinding.getOperandType(0);
1169  }
1170  }
1171 
1172  public static class RegexpMatch extends RegexpSubstr {
1173  public RegexpMatch() {
1174  super("REGEXP_MATCH");
1175  }
1176  }
1177 
1178  public static class Likely extends SqlFunction {
1179  public Likely() {
1180  super("LIKELY",
1181  SqlKind.OTHER_FUNCTION,
1182  null,
1183  null,
1184  OperandTypes.BOOLEAN,
1185  SqlFunctionCategory.SYSTEM);
1186  }
1187 
1188  @Override
1189  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1190  return opBinding.getOperandType(0);
1191  }
1192  }
1193 
1194  public static class Unlikely extends SqlFunction {
1195  public Unlikely() {
1196  super("UNLIKELY",
1197  SqlKind.OTHER_FUNCTION,
1198  null,
1199  null,
1200  OperandTypes.BOOLEAN,
1201  SqlFunctionCategory.SYSTEM);
1202  }
1203 
1204  @Override
1205  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1206  return opBinding.getOperandType(0);
1207  }
1208  }
1209 
1210  public static class Sign extends SqlFunction {
1211  public Sign() {
1212  super("SIGN",
1213  SqlKind.OTHER_FUNCTION,
1214  null,
1215  null,
1216  OperandTypes.NUMERIC,
1217  SqlFunctionCategory.NUMERIC);
1218  }
1219 
1220  @Override
1221  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1222  return opBinding.getOperandType(0);
1223  }
1224  }
1225 
1226  static class Truncate extends SqlFunction {
1228  super("TRUNCATE",
1229  SqlKind.OTHER_FUNCTION,
1230  null,
1231  null,
1232  OperandTypes.family(signature()),
1233  SqlFunctionCategory.NUMERIC);
1234  }
1235 
1236  @Override
1237  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1238  assert opBinding.getOperandCount() == 2;
1239  return opBinding.getOperandType(0);
1240  }
1241 
1242  private static java.util.List<SqlTypeFamily> signature() {
1243  java.util.List<SqlTypeFamily> truncate_sig =
1244  new java.util.ArrayList<SqlTypeFamily>();
1245  truncate_sig.add(SqlTypeFamily.NUMERIC);
1246  truncate_sig.add(SqlTypeFamily.INTEGER);
1247  return truncate_sig;
1248  }
1249  }
1250 
1251  static class ST_IsEmpty extends SqlFunction {
1253  super("ST_IsEmpty",
1254  SqlKind.OTHER_FUNCTION,
1255  null,
1256  null,
1257  OperandTypes.family(signature()),
1258  SqlFunctionCategory.SYSTEM);
1259  }
1260 
1261  @Override
1262  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1263  assert opBinding.getOperandCount() == 1;
1264  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1265  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1266  }
1267 
1268  private static java.util.List<SqlTypeFamily> signature() {
1269  java.util.List<SqlTypeFamily> st_isempty_sig =
1270  new java.util.ArrayList<SqlTypeFamily>();
1271  st_isempty_sig.add(SqlTypeFamily.ANY);
1272  return st_isempty_sig;
1273  }
1274  }
1275 
1276  static class ST_IsValid extends SqlFunction {
1278  super("ST_IsValid",
1279  SqlKind.OTHER_FUNCTION,
1280  null,
1281  null,
1282  OperandTypes.family(signature()),
1283  SqlFunctionCategory.SYSTEM);
1284  }
1285 
1286  @Override
1287  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1288  assert opBinding.getOperandCount() == 1;
1289  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1290  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1291  }
1292 
1293  private static java.util.List<SqlTypeFamily> signature() {
1294  java.util.List<SqlTypeFamily> st_isvalid_sig =
1295  new java.util.ArrayList<SqlTypeFamily>();
1296  st_isvalid_sig.add(SqlTypeFamily.ANY);
1297  return st_isvalid_sig;
1298  }
1299  }
1300 
1301  static class ST_Contains extends SqlFunction {
1303  super("ST_Contains",
1304  SqlKind.OTHER_FUNCTION,
1305  null,
1306  null,
1307  OperandTypes.family(signature()),
1308  SqlFunctionCategory.SYSTEM);
1309  }
1310 
1311  @Override
1312  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1313  assert opBinding.getOperandCount() == 2;
1314  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1315  return typeFactory.createTypeWithNullability(
1316  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1317  opBinding.getOperandType(0).isNullable()
1318  || opBinding.getOperandType(1).isNullable());
1319  }
1320 
1321  private static java.util.List<SqlTypeFamily> signature() {
1322  java.util.List<SqlTypeFamily> st_contains_sig =
1323  new java.util.ArrayList<SqlTypeFamily>();
1324  st_contains_sig.add(SqlTypeFamily.ANY);
1325  st_contains_sig.add(SqlTypeFamily.ANY);
1326  return st_contains_sig;
1327  }
1328  }
1329 
1330  static class ST_Equals extends SqlFunction {
1332  super("ST_Equals",
1333  SqlKind.OTHER_FUNCTION,
1334  null,
1335  null,
1336  OperandTypes.family(signature()),
1337  SqlFunctionCategory.SYSTEM);
1338  }
1339 
1340  @Override
1341  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1342  assert opBinding.getOperandCount() == 2;
1343  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1344  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1345  }
1346 
1347  private static java.util.List<SqlTypeFamily> signature() {
1348  java.util.List<SqlTypeFamily> st_equals_sig =
1349  new java.util.ArrayList<SqlTypeFamily>();
1350  st_equals_sig.add(SqlTypeFamily.ANY);
1351  st_equals_sig.add(SqlTypeFamily.ANY);
1352  return st_equals_sig;
1353  }
1354  }
1355 
1356  static class ST_Intersects extends SqlFunction {
1358  super("ST_Intersects",
1359  SqlKind.OTHER_FUNCTION,
1360  null,
1361  null,
1362  OperandTypes.family(signature()),
1363  SqlFunctionCategory.SYSTEM);
1364  }
1365 
1366  @Override
1367  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1368  assert opBinding.getOperandCount() == 2;
1369  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1370  return typeFactory.createTypeWithNullability(
1371  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1372  opBinding.getOperandType(0).isNullable()
1373  || opBinding.getOperandType(1).isNullable());
1374  }
1375 
1376  private static java.util.List<SqlTypeFamily> signature() {
1377  java.util.List<SqlTypeFamily> st_intersects_sig =
1378  new java.util.ArrayList<SqlTypeFamily>();
1379  st_intersects_sig.add(SqlTypeFamily.ANY);
1380  st_intersects_sig.add(SqlTypeFamily.ANY);
1381  return st_intersects_sig;
1382  }
1383  }
1384 
1385  static class ST_Overlaps extends SqlFunction {
1387  super("ST_Overlaps",
1388  SqlKind.OTHER_FUNCTION,
1389  null,
1390  null,
1391  OperandTypes.family(signature()),
1392  SqlFunctionCategory.SYSTEM);
1393  }
1394 
1395  @Override
1396  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1397  assert opBinding.getOperandCount() == 2;
1398  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1399  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1400  }
1401 
1402  private static java.util.List<SqlTypeFamily> signature() {
1403  java.util.List<SqlTypeFamily> st_overlaps_sig =
1404  new java.util.ArrayList<SqlTypeFamily>();
1405  st_overlaps_sig.add(SqlTypeFamily.ANY);
1406  st_overlaps_sig.add(SqlTypeFamily.ANY);
1407  return st_overlaps_sig;
1408  }
1409  }
1410 
1411  static class ST_Approx_Overlaps extends SqlFunction {
1413  super("ST_Approx_Overlaps",
1414  SqlKind.OTHER_FUNCTION,
1415  null,
1416  null,
1417  OperandTypes.family(signature()),
1418  SqlFunctionCategory.SYSTEM);
1419  }
1420 
1421  @Override
1422  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1423  assert opBinding.getOperandCount() == 2;
1424  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1425  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
1426  }
1427 
1428  private static java.util.List<SqlTypeFamily> signature() {
1429  java.util.List<SqlTypeFamily> st_overlaps_sig =
1430  new java.util.ArrayList<SqlTypeFamily>();
1431  st_overlaps_sig.add(SqlTypeFamily.ANY);
1432  st_overlaps_sig.add(SqlTypeFamily.ANY);
1433  return st_overlaps_sig;
1434  }
1435  }
1436 
1437  static class ST_Disjoint extends SqlFunction {
1439  super("ST_Disjoint",
1440  SqlKind.OTHER_FUNCTION,
1441  null,
1442  null,
1443  OperandTypes.family(signature()),
1444  SqlFunctionCategory.SYSTEM);
1445  }
1446 
1447  @Override
1448  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1449  assert opBinding.getOperandCount() == 2;
1450  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1451  return typeFactory.createTypeWithNullability(
1452  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1453  opBinding.getOperandType(0).isNullable()
1454  || opBinding.getOperandType(1).isNullable());
1455  }
1456 
1457  private static java.util.List<SqlTypeFamily> signature() {
1458  java.util.List<SqlTypeFamily> st_disjoint_sig =
1459  new java.util.ArrayList<SqlTypeFamily>();
1460  st_disjoint_sig.add(SqlTypeFamily.ANY);
1461  st_disjoint_sig.add(SqlTypeFamily.ANY);
1462  return st_disjoint_sig;
1463  }
1464  }
1465 
1466  static class ST_Within extends SqlFunction {
1468  super("ST_Within",
1469  SqlKind.OTHER_FUNCTION,
1470  null,
1471  null,
1472  OperandTypes.family(signature()),
1473  SqlFunctionCategory.SYSTEM);
1474  }
1475 
1476  @Override
1477  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1478  assert opBinding.getOperandCount() == 2;
1479  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1480  return typeFactory.createTypeWithNullability(
1481  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1482  opBinding.getOperandType(0).isNullable()
1483  || opBinding.getOperandType(1).isNullable());
1484  }
1485 
1486  private static java.util.List<SqlTypeFamily> signature() {
1487  java.util.List<SqlTypeFamily> st_within_sig =
1488  new java.util.ArrayList<SqlTypeFamily>();
1489  st_within_sig.add(SqlTypeFamily.ANY);
1490  st_within_sig.add(SqlTypeFamily.ANY);
1491  return st_within_sig;
1492  }
1493  }
1494 
1495  static class ST_DWithin extends SqlFunction {
1497  super("ST_DWithin",
1498  SqlKind.OTHER_FUNCTION,
1499  null,
1500  null,
1501  OperandTypes.family(signature()),
1502  SqlFunctionCategory.SYSTEM);
1503  }
1504 
1505  @Override
1506  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1507  assert opBinding.getOperandCount() == 3;
1508  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1509  return typeFactory.createTypeWithNullability(
1510  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1511  opBinding.getOperandType(0).isNullable()
1512  || opBinding.getOperandType(1).isNullable()
1513  || opBinding.getOperandType(2).isNullable());
1514  }
1515 
1516  private static java.util.List<SqlTypeFamily> signature() {
1517  java.util.List<SqlTypeFamily> st_dwithin_sig =
1518  new java.util.ArrayList<SqlTypeFamily>();
1519  st_dwithin_sig.add(SqlTypeFamily.ANY);
1520  st_dwithin_sig.add(SqlTypeFamily.ANY);
1521  st_dwithin_sig.add(SqlTypeFamily.NUMERIC);
1522  return st_dwithin_sig;
1523  }
1524  }
1525 
1526  static class ST_DFullyWithin extends SqlFunction {
1528  super("ST_DFullyWithin",
1529  SqlKind.OTHER_FUNCTION,
1530  null,
1531  null,
1532  OperandTypes.family(signature()),
1533  SqlFunctionCategory.SYSTEM);
1534  }
1535 
1536  @Override
1537  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1538  assert opBinding.getOperandCount() == 3;
1539  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1540  return typeFactory.createTypeWithNullability(
1541  typeFactory.createSqlType(SqlTypeName.BOOLEAN),
1542  opBinding.getOperandType(0).isNullable()
1543  || opBinding.getOperandType(1).isNullable()
1544  || opBinding.getOperandType(2).isNullable());
1545  }
1546 
1547  private static java.util.List<SqlTypeFamily> signature() {
1548  java.util.List<SqlTypeFamily> st_dwithin_sig =
1549  new java.util.ArrayList<SqlTypeFamily>();
1550  st_dwithin_sig.add(SqlTypeFamily.ANY);
1551  st_dwithin_sig.add(SqlTypeFamily.ANY);
1552  st_dwithin_sig.add(SqlTypeFamily.NUMERIC);
1553  return st_dwithin_sig;
1554  }
1555  }
1556 
1557  static class ST_Distance extends SqlFunction {
1559  super("ST_Distance",
1560  SqlKind.OTHER_FUNCTION,
1561  null,
1562  null,
1563  OperandTypes.family(signature()),
1564  SqlFunctionCategory.SYSTEM);
1565  }
1566 
1567  @Override
1568  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1569  assert opBinding.getOperandCount() == 2;
1570  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1571  return typeFactory.createTypeWithNullability(
1572  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1573  opBinding.getOperandType(0).isNullable()
1574  || opBinding.getOperandType(1).isNullable());
1575  }
1576 
1577  private static java.util.List<SqlTypeFamily> signature() {
1578  java.util.List<SqlTypeFamily> st_distance_sig =
1579  new java.util.ArrayList<SqlTypeFamily>();
1580  st_distance_sig.add(SqlTypeFamily.ANY);
1581  st_distance_sig.add(SqlTypeFamily.ANY);
1582  return st_distance_sig;
1583  }
1584  }
1585 
1586  static class ST_MaxDistance extends SqlFunction {
1588  super("ST_MaxDistance",
1589  SqlKind.OTHER_FUNCTION,
1590  null,
1591  null,
1592  OperandTypes.family(signature()),
1593  SqlFunctionCategory.SYSTEM);
1594  }
1595 
1596  @Override
1597  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1598  assert opBinding.getOperandCount() == 2;
1599  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1600  return typeFactory.createTypeWithNullability(
1601  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1602  opBinding.getOperandType(0).isNullable()
1603  || opBinding.getOperandType(1).isNullable());
1604  }
1605 
1606  private static java.util.List<SqlTypeFamily> signature() {
1607  java.util.List<SqlTypeFamily> st_maxdistance_sig =
1608  new java.util.ArrayList<SqlTypeFamily>();
1609  st_maxdistance_sig.add(SqlTypeFamily.ANY);
1610  st_maxdistance_sig.add(SqlTypeFamily.ANY);
1611  return st_maxdistance_sig;
1612  }
1613  }
1614 
1615  static class ST_GeogFromText extends SqlFunction {
1617  super("ST_GeogFromText",
1618  SqlKind.OTHER_FUNCTION,
1619  null,
1620  null,
1621  OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
1622  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
1623  SqlFunctionCategory.SYSTEM);
1624  }
1625 
1626  @Override
1627  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1628  assert opBinding.getOperandCount() == 1;
1629  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1630  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1631  }
1632  }
1633 
1634  static class ST_GeomFromText extends SqlFunction {
1636  super("ST_GeomFromText",
1637  SqlKind.OTHER_FUNCTION,
1638  null,
1639  null,
1640  OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
1641  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
1642  SqlFunctionCategory.SYSTEM);
1643  }
1644 
1645  @Override
1646  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1647  assert opBinding.getOperandCount() == 1;
1648  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1649  return typeFactory.createSqlType(SqlTypeName.INTEGER);
1650  }
1651  }
1652 
1653  static class ST_Transform extends SqlFunction {
1655  super("ST_Transform",
1656  SqlKind.OTHER_FUNCTION,
1657  null,
1658  null,
1659  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
1660  SqlFunctionCategory.SYSTEM);
1661  }
1662 
1663  @Override
1664  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1665  assert opBinding.getOperandCount() == 1;
1666  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1667  return typeFactory.createTypeWithNullability(
1668  typeFactory.createSqlType(SqlTypeName.INTEGER),
1669  opBinding.getOperandType(0).isNullable());
1670  }
1671  }
1672 
1673  static class ST_X extends SqlFunction {
1674  ST_X() {
1675  super("ST_X",
1676  SqlKind.OTHER_FUNCTION,
1677  null,
1678  null,
1679  OperandTypes.family(SqlTypeFamily.ANY),
1680  SqlFunctionCategory.SYSTEM);
1681  }
1682 
1683  @Override
1684  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1685  assert opBinding.getOperandCount() == 1;
1686  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1687  return typeFactory.createTypeWithNullability(
1688  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1689  opBinding.getOperandType(0).isNullable());
1690  }
1691  }
1692 
1693  static class ST_Y extends SqlFunction {
1694  ST_Y() {
1695  super("ST_Y",
1696  SqlKind.OTHER_FUNCTION,
1697  null,
1698  null,
1699  OperandTypes.family(SqlTypeFamily.ANY),
1700  SqlFunctionCategory.SYSTEM);
1701  }
1702 
1703  @Override
1704  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1705  assert opBinding.getOperandCount() == 1;
1706  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1707  return typeFactory.createTypeWithNullability(
1708  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1709  opBinding.getOperandType(0).isNullable());
1710  }
1711  }
1712 
1713  static class ST_XMin extends SqlFunction {
1715  super("ST_XMin",
1716  SqlKind.OTHER_FUNCTION,
1717  null,
1718  null,
1719  OperandTypes.family(SqlTypeFamily.ANY),
1720  SqlFunctionCategory.SYSTEM);
1721  }
1722 
1723  @Override
1724  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1725  assert opBinding.getOperandCount() == 1;
1726  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1727  return typeFactory.createTypeWithNullability(
1728  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1729  opBinding.getOperandType(0).isNullable());
1730  }
1731  }
1732 
1733  static class ST_XMax extends SqlFunction {
1735  super("ST_XMax",
1736  SqlKind.OTHER_FUNCTION,
1737  null,
1738  null,
1739  OperandTypes.family(SqlTypeFamily.ANY),
1740  SqlFunctionCategory.SYSTEM);
1741  }
1742 
1743  @Override
1744  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1745  assert opBinding.getOperandCount() == 1;
1746  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1747  return typeFactory.createTypeWithNullability(
1748  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1749  opBinding.getOperandType(0).isNullable());
1750  }
1751  }
1752 
1753  static class ST_YMin extends SqlFunction {
1755  super("ST_YMin",
1756  SqlKind.OTHER_FUNCTION,
1757  null,
1758  null,
1759  OperandTypes.family(SqlTypeFamily.ANY),
1760  SqlFunctionCategory.SYSTEM);
1761  }
1762 
1763  @Override
1764  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1765  assert opBinding.getOperandCount() == 1;
1766  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1767  return typeFactory.createTypeWithNullability(
1768  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1769  opBinding.getOperandType(0).isNullable());
1770  }
1771  }
1772 
1773  static class ST_YMax extends SqlFunction {
1775  super("ST_YMax",
1776  SqlKind.OTHER_FUNCTION,
1777  null,
1778  null,
1779  OperandTypes.family(SqlTypeFamily.ANY),
1780  SqlFunctionCategory.SYSTEM);
1781  }
1782 
1783  @Override
1784  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1785  assert opBinding.getOperandCount() == 1;
1786  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1787  return typeFactory.createTypeWithNullability(
1788  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1789  opBinding.getOperandType(0).isNullable());
1790  }
1791  }
1792 
1793  static class ST_PointN extends SqlFunction {
1795  super("ST_PointN",
1796  SqlKind.OTHER_FUNCTION,
1797  null,
1798  null,
1799  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
1800  SqlFunctionCategory.SYSTEM);
1801  }
1802 
1803  @Override
1804  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1805  assert opBinding.getOperandCount() == 1;
1806  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1807  return typeFactory.createTypeWithNullability(
1808  typeFactory.createSqlType(SqlTypeName.INTEGER),
1809  opBinding.getOperandType(0).isNullable());
1810  }
1811  }
1812 
1813  static class ST_EndPoint extends SqlFunction {
1815  super("ST_EndPoint",
1816  SqlKind.OTHER_FUNCTION,
1817  null,
1818  null,
1819  OperandTypes.family(SqlTypeFamily.ANY),
1820  SqlFunctionCategory.SYSTEM);
1821  }
1822 
1823  @Override
1824  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1825  assert opBinding.getOperandCount() == 1;
1826  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1827  return typeFactory.createTypeWithNullability(
1828  typeFactory.createSqlType(SqlTypeName.INTEGER),
1829  opBinding.getOperandType(0).isNullable());
1830  }
1831  }
1832 
1833  static class ST_StartPoint extends SqlFunction {
1835  super("ST_StartPoint",
1836  SqlKind.OTHER_FUNCTION,
1837  null,
1838  null,
1839  OperandTypes.family(SqlTypeFamily.ANY),
1840  SqlFunctionCategory.SYSTEM);
1841  }
1842 
1843  @Override
1844  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1845  assert opBinding.getOperandCount() == 1;
1846  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1847  return typeFactory.createTypeWithNullability(
1848  typeFactory.createSqlType(SqlTypeName.INTEGER),
1849  opBinding.getOperandType(0).isNullable());
1850  }
1851  }
1852 
1853  static class ST_Length extends SqlFunction {
1855  super("ST_Length",
1856  SqlKind.OTHER_FUNCTION,
1857  null,
1858  null,
1859  OperandTypes.family(SqlTypeFamily.ANY),
1860  SqlFunctionCategory.SYSTEM);
1861  }
1862 
1863  @Override
1864  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1865  assert opBinding.getOperandCount() == 1;
1866  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1867  return typeFactory.createTypeWithNullability(
1868  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1869  opBinding.getOperandType(0).isNullable());
1870  }
1871  }
1872 
1873  static class ST_Perimeter extends SqlFunction {
1875  super("ST_Perimeter",
1876  SqlKind.OTHER_FUNCTION,
1877  null,
1878  null,
1879  OperandTypes.family(SqlTypeFamily.ANY),
1880  SqlFunctionCategory.SYSTEM);
1881  }
1882 
1883  @Override
1884  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1885  assert opBinding.getOperandCount() == 1;
1886  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1887  return typeFactory.createTypeWithNullability(
1888  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1889  opBinding.getOperandType(0).isNullable());
1890  }
1891  }
1892 
1893  static class ST_Area extends SqlFunction {
1895  super("ST_Area",
1896  SqlKind.OTHER_FUNCTION,
1897  null,
1898  null,
1899  OperandTypes.family(SqlTypeFamily.ANY),
1900  SqlFunctionCategory.SYSTEM);
1901  }
1902 
1903  @Override
1904  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1905  assert opBinding.getOperandCount() == 1;
1906  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1907  return typeFactory.createTypeWithNullability(
1908  typeFactory.createSqlType(SqlTypeName.DOUBLE),
1909  opBinding.getOperandType(0).isNullable());
1910  }
1911  }
1912 
1913  static class ST_NPoints extends SqlFunction {
1915  super("ST_NPoints",
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.createTypeWithNullability(
1928  typeFactory.createSqlType(SqlTypeName.INTEGER),
1929  opBinding.getOperandType(0).isNullable());
1930  }
1931  }
1932 
1933  static class ST_NRings extends SqlFunction {
1935  super("ST_NRings",
1936  SqlKind.OTHER_FUNCTION,
1937  null,
1938  null,
1939  OperandTypes.family(SqlTypeFamily.ANY),
1940  SqlFunctionCategory.SYSTEM);
1941  }
1942 
1943  @Override
1944  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1945  assert opBinding.getOperandCount() == 1;
1946  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1947  return typeFactory.createTypeWithNullability(
1948  typeFactory.createSqlType(SqlTypeName.INTEGER),
1949  opBinding.getOperandType(0).isNullable());
1950  }
1951  }
1952 
1953  static class ST_SRID extends SqlFunction {
1955  super("ST_SRID",
1956  SqlKind.OTHER_FUNCTION,
1957  null,
1958  null,
1959  OperandTypes.family(SqlTypeFamily.ANY),
1960  SqlFunctionCategory.SYSTEM);
1961  }
1962 
1963  @Override
1964  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1965  assert opBinding.getOperandCount() == 1;
1966  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1967  return typeFactory.createTypeWithNullability(
1968  typeFactory.createSqlType(SqlTypeName.INTEGER),
1969  opBinding.getOperandType(0).isNullable());
1970  }
1971  }
1972 
1973  static class ST_SetSRID extends SqlFunction {
1975  super("ST_SetSRID",
1976  SqlKind.OTHER_FUNCTION,
1977  null,
1978  null,
1979  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER),
1980  SqlFunctionCategory.SYSTEM);
1981  }
1982 
1983  @Override
1984  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
1985  assert opBinding.getOperandCount() == 1;
1986  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
1987  return typeFactory.createTypeWithNullability(
1988  typeFactory.createSqlType(SqlTypeName.INTEGER),
1989  opBinding.getOperandType(0).isNullable());
1990  }
1991  }
1992 
1993  static class ST_Point extends SqlFunction {
1995  super("ST_Point",
1996  SqlKind.OTHER_FUNCTION,
1997  null,
1998  null,
1999  OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
2000  SqlFunctionCategory.SYSTEM);
2001  }
2002 
2003  @Override
2004  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2005  assert opBinding.getOperandCount() == 2;
2006  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2007  return typeFactory.createSqlType(SqlTypeName.INTEGER);
2008  }
2009  }
2010 
2011  static class ST_Centroid extends SqlFunction {
2013  super("ST_Centroid",
2014  SqlKind.OTHER_FUNCTION,
2015  null,
2016  null,
2017  OperandTypes.family(signature()),
2018  SqlFunctionCategory.SYSTEM);
2019  }
2020 
2021  @Override
2022  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2023  assert opBinding.getOperandCount() == 1;
2024  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2025  return typeFactory.createSqlType(SqlTypeName.INTEGER);
2026  }
2027 
2028  private static java.util.List<SqlTypeFamily> signature() {
2029  java.util.List<SqlTypeFamily> st_centroid_sig =
2030  new java.util.ArrayList<SqlTypeFamily>();
2031  st_centroid_sig.add(SqlTypeFamily.ANY);
2032  return st_centroid_sig;
2033  }
2034  }
2035 
2036  static class ST_Buffer extends SqlFunction {
2038  super("ST_Buffer",
2039  SqlKind.OTHER_FUNCTION,
2040  null,
2041  null,
2042  OperandTypes.family(signature()),
2043  SqlFunctionCategory.SYSTEM);
2044  }
2045 
2046  @Override
2047  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2048  assert opBinding.getOperandCount() == 2;
2049  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2050  return typeFactory.createSqlType(SqlTypeName.INTEGER);
2051  }
2052 
2053  private static java.util.List<SqlTypeFamily> signature() {
2054  java.util.List<SqlTypeFamily> st_buffer_sig =
2055  new java.util.ArrayList<SqlTypeFamily>();
2056  st_buffer_sig.add(SqlTypeFamily.ANY);
2057  st_buffer_sig.add(SqlTypeFamily.NUMERIC);
2058  return st_buffer_sig;
2059  }
2060  }
2061 
2062  static class ST_Intersection extends SqlFunction {
2064  super("ST_Intersection",
2065  SqlKind.OTHER_FUNCTION,
2066  null,
2067  null,
2068  OperandTypes.family(signature()),
2069  SqlFunctionCategory.SYSTEM);
2070  }
2071 
2072  @Override
2073  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2074  assert opBinding.getOperandCount() == 2;
2075  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2076  return typeFactory.createSqlType(SqlTypeName.INTEGER);
2077  }
2078 
2079  private static java.util.List<SqlTypeFamily> signature() {
2080  java.util.List<SqlTypeFamily> st_intersection_sig =
2081  new java.util.ArrayList<SqlTypeFamily>();
2082  st_intersection_sig.add(SqlTypeFamily.ANY);
2083  st_intersection_sig.add(SqlTypeFamily.ANY);
2084  return st_intersection_sig;
2085  }
2086  }
2087 
2088  static class ST_Union extends SqlFunction {
2090  super("ST_Union",
2091  SqlKind.OTHER_FUNCTION,
2092  null,
2093  null,
2094  OperandTypes.family(signature()),
2095  SqlFunctionCategory.SYSTEM);
2096  }
2097 
2098  @Override
2099  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2100  assert opBinding.getOperandCount() == 2;
2101  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2102  return typeFactory.createSqlType(SqlTypeName.INTEGER);
2103  }
2104 
2105  private static java.util.List<SqlTypeFamily> signature() {
2106  java.util.List<SqlTypeFamily> st_union_sig =
2107  new java.util.ArrayList<SqlTypeFamily>();
2108  st_union_sig.add(SqlTypeFamily.ANY);
2109  st_union_sig.add(SqlTypeFamily.ANY);
2110  return st_union_sig;
2111  }
2112  }
2113 
2114  static class ST_Difference extends SqlFunction {
2116  super("ST_Difference",
2117  SqlKind.OTHER_FUNCTION,
2118  null,
2119  null,
2120  OperandTypes.family(signature()),
2121  SqlFunctionCategory.SYSTEM);
2122  }
2123 
2124  @Override
2125  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2126  assert opBinding.getOperandCount() == 2;
2127  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2128  return typeFactory.createSqlType(SqlTypeName.INTEGER);
2129  }
2130 
2131  private static java.util.List<SqlTypeFamily> signature() {
2132  java.util.List<SqlTypeFamily> st_difference_sig =
2133  new java.util.ArrayList<SqlTypeFamily>();
2134  st_difference_sig.add(SqlTypeFamily.ANY);
2135  st_difference_sig.add(SqlTypeFamily.ANY);
2136  return st_difference_sig;
2137  }
2138  }
2139 
2140  static class CastToGeography extends SqlFunction {
2142  super("CastToGeography",
2143  SqlKind.OTHER_FUNCTION,
2144  null,
2145  null,
2146  OperandTypes.family(SqlTypeFamily.ANY),
2147  SqlFunctionCategory.SYSTEM);
2148  }
2149 
2150  @Override
2151  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2152  assert opBinding.getOperandCount() == 1;
2153  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2154  return typeFactory.createSqlType(SqlTypeName.INTEGER);
2155  }
2156  }
2157 
2158  static class EncodeText extends SqlFunction {
2160  super("ENCODE_TEXT",
2161  SqlKind.OTHER_FUNCTION,
2162  null,
2163  null,
2164  OperandTypes.family(SqlTypeFamily.STRING),
2165  SqlFunctionCategory.SYSTEM);
2166  }
2167 
2168  @Override
2169  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2170  assert opBinding.getOperandCount() == 1;
2171  return opBinding.getOperandType(0);
2172  }
2173  }
2174 
2175  /* OFFSET_IN_FRAGMENT() */
2176  public static class OffsetInFragment extends SqlFunction {
2177  public OffsetInFragment() {
2178  super("OFFSET_IN_FRAGMENT",
2179  SqlKind.OTHER_FUNCTION,
2180  null,
2181  null,
2182  OperandTypes.NILADIC,
2183  SqlFunctionCategory.SYSTEM);
2184  }
2185 
2186  @Override
2187  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2188  assert opBinding.getOperandCount() == 0;
2189  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2190  return typeFactory.createSqlType(SqlTypeName.BIGINT);
2191  }
2192  }
2193 
2194  static class ApproxCountDistinct extends SqlAggFunction {
2196  super("APPROX_COUNT_DISTINCT",
2197  null,
2198  SqlKind.OTHER_FUNCTION,
2199  null,
2200  null,
2201  OperandTypes.or(OperandTypes.family(SqlTypeFamily.ANY),
2202  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)),
2203  SqlFunctionCategory.SYSTEM,
2204  false,
2205  false,
2206  Optionality.FORBIDDEN);
2207  }
2208 
2209  @Override
2210  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2211  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2212  return typeFactory.createSqlType(SqlTypeName.BIGINT);
2213  }
2214  }
2215 
2216  static class ApproxMedian extends SqlAggFunction {
2218  super("APPROX_MEDIAN",
2219  null,
2220  SqlKind.OTHER_FUNCTION,
2221  null,
2222  null,
2223  OperandTypes.family(SqlTypeFamily.NUMERIC),
2224  SqlFunctionCategory.SYSTEM,
2225  false,
2226  false,
2227  Optionality.FORBIDDEN);
2228  }
2229 
2230  @Override
2231  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2232  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2233  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2234  }
2235  }
2236 
2237  static class ApproxPercentile extends SqlAggFunction {
2239  super("APPROX_PERCENTILE",
2240  null,
2241  SqlKind.OTHER_FUNCTION,
2242  null,
2243  null,
2244  OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
2245  SqlFunctionCategory.SYSTEM,
2246  false,
2247  false,
2248  Optionality.FORBIDDEN);
2249  }
2250 
2251  @Override
2252  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2253  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2254  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2255  }
2256  }
2257 
2258  static class ApproxQuantile extends SqlAggFunction {
2260  super("APPROX_QUANTILE",
2261  null,
2262  SqlKind.OTHER_FUNCTION,
2263  null,
2264  null,
2265  OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
2266  SqlFunctionCategory.SYSTEM,
2267  false,
2268  false,
2269  Optionality.FORBIDDEN);
2270  }
2271 
2272  @Override
2273  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2274  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2275  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2276  }
2277  }
2278 
2279  static class MapDAvg extends SqlAggFunction {
2281  super("AVG",
2282  null,
2283  SqlKind.OTHER_FUNCTION,
2284  null,
2285  null,
2286  OperandTypes.family(SqlTypeFamily.NUMERIC),
2287  SqlFunctionCategory.SYSTEM);
2288  }
2289 
2290  @Override
2291  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2292  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2293  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2294  }
2295  }
2296 
2297  public static class Sample extends SqlAggFunction {
2298  public Sample() {
2299  super("SAMPLE",
2300  null,
2301  SqlKind.OTHER_FUNCTION,
2302  null,
2303  null,
2304  OperandTypes.ANY,
2305  SqlFunctionCategory.SYSTEM,
2306  false,
2307  false,
2308  Optionality.FORBIDDEN);
2309  }
2310 
2311  @Override
2312  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2313  return opBinding.getOperandType(0);
2314  }
2315  }
2316 
2317  // for backwards compatibility
2318  public static class LastSample extends SqlAggFunction {
2319  public LastSample() {
2320  super("LAST_SAMPLE",
2321  null,
2322  SqlKind.OTHER_FUNCTION,
2323  null,
2324  null,
2325  OperandTypes.ANY,
2326  SqlFunctionCategory.SYSTEM,
2327  false,
2328  false,
2329  Optionality.FORBIDDEN);
2330  }
2331 
2332  @Override
2333  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2334  return opBinding.getOperandType(0);
2335  }
2336  }
2337 
2338  static class ExtFunction extends SqlFunction {
2339  ExtFunction(final String name, final ExtensionFunction sig) {
2340  super(name,
2341  SqlKind.OTHER_FUNCTION,
2342  null,
2343  null,
2344  OperandTypes.family(sig.toSqlSignature()),
2345  SqlFunctionCategory.SYSTEM);
2346  ret = sig.getSqlRet();
2347  arg_names = sig.getArgNames();
2348  }
2349 
2350  @Override
2351  public List<String> getParamNames() {
2352  return arg_names;
2353  }
2354 
2355  @Override
2356  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2357  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2358  return typeFactory.createTypeWithNullability(typeFactory.createSqlType(ret), true);
2359  }
2360 
2361  private final SqlTypeName ret;
2362  private final List<String> arg_names;
2363  }
2364 
2365  public static class ExtTableFunction extends SqlFunction implements SqlTableFunction {
2366  ExtTableFunction(final String name, final ExtensionFunction sig) {
2367  super(name,
2368  SqlKind.OTHER_FUNCTION,
2369  ReturnTypes.CURSOR,
2370  null,
2371  OperandTypes.family(sig.toSqlSignature()),
2372  SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION);
2373  arg_types = sig.toSqlSignature();
2374  outs = sig.getSqlOuts();
2375  out_names = sig.getOutNames();
2376  arg_names = sig.getArgNames();
2377  // pretty_arg_names will be same as arg_names, except with
2378  // arg names for cursors stripped of array elements, i.e
2379  // my_cursor_input[x, y, z] => my_cursor_input
2380  pretty_arg_names = sig.getPrettyArgNames();
2381  options = sig.getOptions();
2382  }
2383 
2384  // The following method allows for parameter annotation
2385  // i.e. my_param => 3.
2386  // Note this method is deprecated, and it appears that
2387  // getParameters() is the correct method to use, but
2388  // need to troubleshoot why it's not being called
2389  @Override
2390  public List<String> getParamNames() {
2391  return pretty_arg_names;
2392  }
2393 
2394  // Per the above, this appears to be the non-deprecated way
2395  // to allow for parameter annotation, and it also allows
2396  // for specifying optionality.
2397  // However it currently is not being picked up/called,
2398  // so need to troubleshot. Leaving in for now as scaffolding
2399  // for the correct approach forward.
2400 
2401  // Note that OperandTypeInference seems another route
2402  // to implementing optionality.
2403 
2404  public List<FunctionParameter> getParameters() {
2405  final Boolean has_names = this.pretty_arg_names != null
2406  && this.pretty_arg_names.size() == this.arg_types.size();
2407  final List<FunctionParameter> parameters = new java.util.ArrayList<>();
2408  for (int i = 0; i < this.arg_types.size(); i++) {
2409  final int arg_idx = i;
2410  parameters.add(new FunctionParameter() {
2411  public int getOrdinal() {
2412  return arg_idx;
2413  }
2414 
2415  public String getName() {
2416  if (has_names) {
2417  return pretty_arg_names.get(arg_idx);
2418  }
2419  return "arg" + arg_idx;
2420  }
2421 
2422  public RelDataType getType(RelDataTypeFactory typeFactory) {
2423  return arg_types.get(arg_idx).getDefaultConcreteType(typeFactory);
2424  }
2425 
2426  public boolean isOptional() {
2427  return false;
2428  }
2429  });
2430  }
2431  return parameters;
2432  }
2433 
2434  @Override
2435  public SqlReturnTypeInference getRowTypeInference() {
2436  return opBinding -> {
2437  FieldInfoBuilder ret = opBinding.getTypeFactory().builder();
2438  for (int out_idx = 0; out_idx < outs.size(); ++out_idx) {
2439  ret = ret.add(out_names.get(out_idx), outs.get(out_idx));
2440  ret = ret.nullable(true);
2441  }
2442  return ret.build();
2443  };
2444  }
2445 
2446  private void debugPrint(String msg, Boolean debugMode) {
2447  if (debugMode) {
2448  System.out.println(msg);
2449  }
2450  }
2451 
2452  public Set<RelColumnMapping> getColumnMappings() {
2453  final Boolean debugMode = false;
2454  Set<RelColumnMapping> s = new HashSet<RelColumnMapping>();
2455  debugPrint("getNameAsId() -> " + getNameAsId() + ", arg_names=" + arg_names
2456  + ", out_names=" + out_names,
2457  debugMode);
2458  if (Integer.valueOf(options.getOrDefault("filter_table_function_transpose", "0"))
2459  == 1) {
2460  debugPrint("getNameAsId() -> " + getNameAsId(), debugMode);
2461  int rel_idx = -1;
2462  for (int arg_idx = 0; arg_idx < arg_names.size(); ++arg_idx) {
2463  String arg_name = arg_names.get(arg_idx);
2464  String[] fields;
2465  int start = arg_name.indexOf("[");
2466  if (start != -1) {
2467  rel_idx += 1;
2468  int end = arg_name.lastIndexOf("]");
2469  fields = arg_name.substring(start + 1, end)
2470  .replaceAll("\\s+", "")
2471  .split(",", 0);
2472  } else {
2473  fields = new String[] {arg_name};
2474  }
2475  debugPrint("fields=" + Arrays.toString(fields), debugMode);
2476  for (int field_idx = 0; field_idx < fields.length; ++field_idx) {
2477  int out_idx = out_names.indexOf(fields[field_idx]);
2478  if (out_idx >= 0) {
2479  s.add(new RelColumnMapping(out_idx, rel_idx, field_idx, false));
2480  debugPrint("out_idx, arg_idx/rel_idx, field_idx=" + out_idx + ", " + arg_idx
2481  + "/" + rel_idx + ", " + field_idx,
2482  debugMode);
2483  }
2484  }
2485  }
2486  }
2487  return s;
2488  }
2489 
2490  private final List<SqlTypeFamily> arg_types;
2491  private final List<SqlTypeName> outs;
2492  private final List<String> arg_names;
2493  private final List<String> pretty_arg_names;
2494  private final List<String> out_names;
2495  private final Map<String, String> options;
2496  }
2497 
2498  //
2499  // Internal accessors for in-situ poly render queries
2500  //
2501 
2502  static class HeavyDB_Geo_PolyBoundsPtr extends SqlFunction {
2504  super("HeavyDB_Geo_PolyBoundsPtr",
2505  SqlKind.OTHER_FUNCTION,
2506  null,
2507  null,
2508  OperandTypes.family(SqlTypeFamily.ANY),
2509  SqlFunctionCategory.SYSTEM);
2510  }
2511 
2512  @Override
2513  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2514  assert opBinding.getOperandCount() == 1;
2515  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2516  return typeFactory.createSqlType(SqlTypeName.BIGINT);
2517  }
2518  }
2519 
2520  static class HeavyDB_Geo_PolyRenderGroup extends SqlFunction {
2522  super("HeavyDB_Geo_PolyRenderGroup",
2523  SqlKind.OTHER_FUNCTION,
2524  null,
2525  null,
2526  OperandTypes.family(SqlTypeFamily.ANY),
2527  SqlFunctionCategory.SYSTEM);
2528  }
2529 
2530  @Override
2531  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2532  assert opBinding.getOperandCount() == 1;
2533  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2534  return typeFactory.createSqlType(SqlTypeName.INTEGER);
2535  }
2536  }
2537 
2538  static class convert_meters_to_pixel_width extends SqlFunction {
2540  super("convert_meters_to_pixel_width",
2541  SqlKind.OTHER_FUNCTION,
2542  null,
2543  null,
2544  OperandTypes.family(SqlTypeFamily.NUMERIC,
2545  SqlTypeFamily.ANY,
2546  SqlTypeFamily.NUMERIC,
2547  SqlTypeFamily.NUMERIC,
2548  SqlTypeFamily.NUMERIC,
2549  SqlTypeFamily.NUMERIC),
2550  SqlFunctionCategory.SYSTEM);
2551  }
2552 
2553  @Override
2554  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2555  assert opBinding.getOperandCount() == 6;
2556  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2557  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2558  }
2559  }
2560 
2561  static class convert_meters_to_pixel_height extends SqlFunction {
2563  super("convert_meters_to_pixel_height",
2564  SqlKind.OTHER_FUNCTION,
2565  null,
2566  null,
2567  OperandTypes.family(SqlTypeFamily.NUMERIC,
2568  SqlTypeFamily.ANY,
2569  SqlTypeFamily.NUMERIC,
2570  SqlTypeFamily.NUMERIC,
2571  SqlTypeFamily.NUMERIC,
2572  SqlTypeFamily.NUMERIC),
2573  SqlFunctionCategory.SYSTEM);
2574  }
2575 
2576  @Override
2577  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2578  assert opBinding.getOperandCount() == 6;
2579  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2580  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
2581  }
2582  }
2583 
2584  static class is_point_in_view extends SqlFunction {
2586  super("is_point_in_view",
2587  SqlKind.OTHER_FUNCTION,
2588  null,
2589  null,
2590  OperandTypes.family(SqlTypeFamily.ANY,
2591  SqlTypeFamily.NUMERIC,
2592  SqlTypeFamily.NUMERIC,
2593  SqlTypeFamily.NUMERIC,
2594  SqlTypeFamily.NUMERIC),
2595  SqlFunctionCategory.SYSTEM);
2596  }
2597 
2598  @Override
2599  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2600  assert opBinding.getOperandCount() == 5;
2601  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2602  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
2603  }
2604  }
2605 
2606  static class is_point_size_in_view extends SqlFunction {
2608  super("is_point_size_in_view",
2609  SqlKind.OTHER_FUNCTION,
2610  null,
2611  null,
2612  OperandTypes.family(SqlTypeFamily.ANY,
2613  SqlTypeFamily.NUMERIC,
2614  SqlTypeFamily.NUMERIC,
2615  SqlTypeFamily.NUMERIC,
2616  SqlTypeFamily.NUMERIC,
2617  SqlTypeFamily.NUMERIC),
2618  SqlFunctionCategory.SYSTEM);
2619  }
2620 
2621  @Override
2622  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2623  assert opBinding.getOperandCount() == 6;
2624  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2625  return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
2626  }
2627  }
2628 
2629  public static class usTimestamp extends SqlFunction {
2630  public usTimestamp() {
2631  super("usTIMESTAMP",
2632  SqlKind.OTHER_FUNCTION,
2633  null,
2634  null,
2635  OperandTypes.STRING,
2636  SqlFunctionCategory.SYSTEM);
2637  }
2638 
2639  @Override
2640  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2641  assert opBinding.getOperandCount() == 1;
2642  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2643  return typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 6);
2644  }
2645  }
2646 
2647  public static class nsTimestamp extends SqlFunction {
2648  public nsTimestamp() {
2649  super("nsTIMESTAMP",
2650  SqlKind.OTHER_FUNCTION,
2651  null,
2652  null,
2653  OperandTypes.STRING,
2654  SqlFunctionCategory.SYSTEM);
2655  }
2656 
2657  @Override
2658  public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
2659  assert opBinding.getOperandCount() == 1;
2660  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
2661  return typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 9);
2662  }
2663  }
2664 }
2665 
2666 // End HeavyDBSqlOperatorTable.java
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)
EXTENSION_INLINE int64_t HeavyDB_Geo_PolyBoundsPtr(double *bounds, int64_t size)
final java.util.List< SqlTypeFamily > toSqlSignature()
ExtTableFunction(final String name, final ExtensionFunction sig)
EXTENSION_NOINLINE double ST_XMax(int8_t *coords, int64_t size, int32_t ic, int32_t isr, int32_t osr)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
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)
SqlCall createCall(@Nullable SqlLiteral functionQualifier, SqlParserPos pos,@Nullable SqlNode...operands)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
EXTENSION_NOINLINE double ST_XMin(int8_t *coords, int64_t size, int32_t ic, int32_t isr, int32_t osr)
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)
tuple STRING
Definition: dtypes.py:31
constexpr double f
Definition: Utm.h:31
boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > getSignatureFamilies()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType getComponentType(RelDataTypeFactory typeFactory, List< RelDataType > argTypes)
EXTENSION_NOINLINE double ST_YMin(int8_t *coords, int64_t size, int32_t ic, int32_t isr, int32_t osr)
SqlCall createCall(@Nullable SqlLiteral functionQualifier, SqlParserPos pos,@Nullable SqlNode...operands)
static java.util.List< SqlTypeFamily > getSignatureFamilies()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
EXTENSION_INLINE int32_t HeavyDB_Geo_PolyRenderGroup(int32_t render_group)
EXTENSION_NOINLINE bool is_point_in_view(int8_t *p, const int64_t psize, const int32_t ic, const double min_lon, const double max_lon, const double min_lat, const double max_lat)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
ExtFunction(final String name, final ExtensionFunction sig)
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > getSignatureFamilies()
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static java.util.List< SqlTypeFamily > getSignatureFamilies()
static void addUDF(HeavyDBSqlOperatorTable opTab, final Map< String, ExtensionFunction > extSigs)
SqlCall createCall(@Nullable SqlLiteral functionQualifier, SqlParserPos pos,@Nullable SqlNode...operands)
SqlCall createCall(@Nullable SqlLiteral functionQualifier, SqlParserPos pos,@Nullable SqlNode...operands)
EXTENSION_NOINLINE double Truncate(const double x, const int32_t y)
SqlCall createCall(@Nullable SqlLiteral functionQualifier, SqlParserPos pos,@Nullable SqlNode...operands)
string name
Definition: setup.in.py:72
RelDataType inferReturnType(SqlOperatorBinding opBinding)
static final SqlArrayValueConstructorAllowingEmpty ARRAY_VALUE_CONSTRUCTOR
RelDataType inferReturnType(SqlOperatorBinding opBinding)
void lookupOperatorOverloads(SqlIdentifier opName, SqlFunctionCategory category, SqlSyntax syntax, List< SqlOperator > operatorList, SqlNameMatcher nameMatcher)
RelDataType inferReturnType(SqlOperatorBinding opBinding)