17 package com.mapd.parser.server;
19 import org.apache.calcite.avatica.util.TimeUnit;
20 import org.apache.calcite.rel.type.RelDataType;
21 import org.apache.calcite.rel.type.RelDataTypeFactory;
22 import org.apache.calcite.sql.SqlIntervalQualifier;
23 import org.apache.calcite.sql.parser.SqlParserPos;
24 import org.apache.calcite.sql.type.SqlTypeFamily;
25 import org.apache.calcite.sql.type.SqlTypeName;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import java.lang.Comparable;
30 import java.util.ArrayList;
31 import java.util.EnumSet;
32 import java.util.HashMap;
33 import java.util.List;
38 final static Logger
HEAVYDBLOGGER = LoggerFactory.getLogger(ExtensionFunction.class);
137 this.isRowUdf =
true;
139 this.cursor_field_types = null;
140 this.default_values = null;
144 final List<ExtArgumentType>
outs,
145 final List<String>
names,
146 final Map<String, String>
options,
153 this.isRowUdf =
false;
154 this.annotations = null;
162 return this.default_values;
167 return this.cursor_field_types;
179 if (this.
names != null) {
180 return this.names.subList(0, this.args.size());
186 if (this.
names != null) {
187 List<String> pretty_names =
new ArrayList<String>();
188 for (
int arg_idx = 0; arg_idx < this.args.size(); ++arg_idx) {
191 pretty_names.add(this.names.get(arg_idx).
split(
"\\[", 2)[0]);
199 if (this.
names != null) {
200 return this.names.subList(this.args.size(), this.
names.size());
210 assert this.isRowUdf();
216 return new HashMap<String, String>(this.options);
222 return this.isRowUdf;
226 return !this.isRowUdf();
230 HEAVYDBLOGGER.debug(
"Extensionfunction::toJson: " +
name);
231 StringBuilder json_cons =
new StringBuilder();
232 json_cons.append(
"{");
235 json_cons.append(
"\"annotations\":");
236 List<String> anns =
new ArrayList<String>();
237 for (
final Map<String, String> m : this.
annotations) {
238 List<String> lst =
new ArrayList<String>();
239 for (
final Map.Entry<String, String> kv : m.entrySet()) {
240 lst.add(
"\"" + kv.getKey() +
"\":\"" + kv.getValue() +
"\"");
242 anns.add(
"{" + ExtensionFunctionSignatureParser.join(lst,
",") +
"}");
244 json_cons.append(
"[" + ExtensionFunctionSignatureParser.join(anns,
",") +
"],");
247 json_cons.append(
"\"outs\":");
248 json_cons.append(
"[");
249 List<String> param_list =
new ArrayList<String>();
253 json_cons.append(ExtensionFunctionSignatureParser.join(param_list,
","));
254 json_cons.append(
"],");
256 json_cons.append(
"\"args\":");
257 json_cons.append(
"[");
258 List<String> param_list =
new ArrayList<String>();
262 json_cons.append(ExtensionFunctionSignatureParser.join(param_list,
","));
263 json_cons.append(
"]");
264 json_cons.append(
"}");
265 return json_cons.toString();
309 return "Array<float>";
311 return "Array<double>";
313 return "Array<bool>";
315 return "Array<TextEncodingDict>";
319 return "Column<i16>";
321 return "Column<i32>";
323 return "Column<i64>";
325 return "Column<float>";
327 return "Column<double>";
329 return "Column<bool>";
331 return "Column<TextEncodingDict>";
333 return "Column<timestamp>";
337 return "GeoMultiPoint";
341 return "GeoLineString";
343 return "GeoMultiLineString";
347 return "GeoMultiPolygon";
351 return "TextEncodingNone";
353 return "TextEncodingDict";
355 return "ColumnList<i8>";
357 return "ColumnList<i16>";
359 return "ColumnList<i32>";
361 return "ColumnList<i64>";
363 return "ColumnList<float>";
365 return "ColumnList<double>";
367 return "ColumnList<bool>";
369 return "ColumnList<TextEncodingDict>";
371 return "Column<Array<i8>>";
373 return "Column<Array<i16>>";
375 return "Column<Array<i32>>";
377 return "Column<Array<i64>>";
379 return "Column<Array<float>>";
381 return "Column<Array<double>>";
383 return "Column<Array<bool>>";
385 return "Column<Array<TextEncodingDict>>";
387 return "ColumnList<Array<i8>>";
389 return "ColumnList<Array<i16>>";
391 return "ColumnList<Array<i32>>";
393 return "ColumnList<Array<i64>>";
395 return "ColumnList<Array<float>>";
397 return "ColumnList<Array<double>>";
399 return "ColumnList<Array<bool>>";
401 return "ColumnList<Array<TextEncodingDict>>";
403 return "DayTimeInterval";
405 return "YearMonthTimeInterval";
407 return "Column<GeoPoint>";
409 return "Column<GeoLineString>";
411 return "Column<GeoPolygon>";
413 return "Column<GeoMultiPoint>";
415 return "Column<GeoMultiLineString>";
417 return "Column<GeoMultiPolygon>";
419 return "ColumnList<GeoPoint>";
421 return "ColumnList<GeoLineString>";
423 return "ColumnList<GeoPolygon>";
425 return "ColumnList<GeoMultiPoint>";
427 return "ColumnList<GeoMultiLineString>";
429 return "ColumnList<GeoMultiPolygon>";
431 return "Array<TextEncodingNone>";
433 return "Column<TextEncodingNone>";
435 return "ColumnList<TextEncodingNone>";
437 return "Column<Array<TextEncodingNone>>";
439 return "ColumnList<Array<TextEncodingNone>>";
441 HEAVYDBLOGGER.info(
"Extensionfunction::typeName: unknown type=`" + type +
"`");
446 private static String
dq(
final String str) {
447 return "\"" + str +
"\"";
450 private final List<ExtArgumentType>
args;
451 private final List<ExtArgumentType>
outs;
457 private final Map<String, List<ExtArgumentType>>
462 java.util.List<SqlTypeFamily> sql_sig =
new java.util.ArrayList<SqlTypeFamily>();
464 for (
int arg_idx = 0; arg_idx < this.getArgs().size(); ++arg_idx) {
479 return type == ExtArgumentType.PInt8 || type == ExtArgumentType.PInt16
480 || type == ExtArgumentType.PInt32 || type == ExtArgumentType.PInt64
481 || type == ExtArgumentType.PFloat || type == ExtArgumentType.PDouble
486 return type == ExtArgumentType.ColumnArrayInt8
487 || type == ExtArgumentType.ColumnArrayInt16
488 || type == ExtArgumentType.ColumnArrayInt32
489 || type == ExtArgumentType.ColumnArrayInt64
490 || type == ExtArgumentType.ColumnArrayFloat
491 || type == ExtArgumentType.ColumnArrayDouble
492 || type == ExtArgumentType.ColumnArrayBool
493 || type == ExtArgumentType.ColumnArrayTextEncodingDict
498 return type == ExtArgumentType.ArrayInt8 || type == ExtArgumentType.ArrayInt16
499 || type == ExtArgumentType.ArrayInt32 || type == ExtArgumentType.ArrayInt64
500 || type == ExtArgumentType.ArrayFloat || type == ExtArgumentType.ArrayDouble
501 || type == ExtArgumentType.ArrayBool
502 || type == ExtArgumentType.ArrayTextEncodingDict
507 return type == ExtArgumentType.ColumnListArrayInt8
508 || type == ExtArgumentType.ColumnListArrayInt16
509 || type == ExtArgumentType.ColumnListArrayInt32
510 || type == ExtArgumentType.ColumnListArrayInt64
511 || type == ExtArgumentType.ColumnListArrayFloat
512 || type == ExtArgumentType.ColumnListArrayDouble
513 || type == ExtArgumentType.ColumnListArrayBool
514 || type == ExtArgumentType.ColumnListArrayTextEncodingDict
519 return type == ExtArgumentType.ColumnInt8 || type == ExtArgumentType.ColumnInt16
520 || type == ExtArgumentType.ColumnInt32 || type == ExtArgumentType.ColumnInt64
521 || type == ExtArgumentType.ColumnFloat || type == ExtArgumentType.ColumnDouble
522 || type == ExtArgumentType.ColumnBool
523 || type == ExtArgumentType.ColumnTextEncodingDict
524 || type == ExtArgumentType.ColumnTextEncodingNone
526 || type == ExtArgumentType.ColumnGeoPoint
527 || type == ExtArgumentType.ColumnGeoLineString
528 || type == ExtArgumentType.ColumnGeoPolygon
529 || type == ExtArgumentType.ColumnGeoMultiPoint
530 || type == ExtArgumentType.ColumnGeoMultiLineString
535 return type == ExtArgumentType.ColumnListInt8
536 || type == ExtArgumentType.ColumnListInt16
537 || type == ExtArgumentType.ColumnListInt32
538 || type == ExtArgumentType.ColumnListInt64
539 || type == ExtArgumentType.ColumnListFloat
540 || type == ExtArgumentType.ColumnListDouble
541 || type == ExtArgumentType.ColumnListBool
542 || type == ExtArgumentType.ColumnListTextEncodingDict
543 || type == ExtArgumentType.ColumnListTextEncodingNone
545 || type == ExtArgumentType.ColumnListGeoLineString
546 || type == ExtArgumentType.ColumnListGeoPolygon
547 || type == ExtArgumentType.ColumnListGeoMultiPoint
548 || type == ExtArgumentType.ColumnListGeoMultiLineString
653 HEAVYDBLOGGER.error(
"getValueType: no value for type " +
type);
659 return ExtArgumentType.valueOf(
type);
674 return factory.createTypeWithNullability(
686 return factory.createTypeWithNullability(
687 factory.createArrayType(
691 return factory.createTypeWithNullability(
694 return factory.createTypeWithNullability(
697 SqlIntervalQualifier yearMonthIntervalQualifier =
698 new SqlIntervalQualifier(TimeUnit.MONTH, null, SqlParserPos.ZERO);
699 return factory.createSqlIntervalType(yearMonthIntervalQualifier);
701 SqlIntervalQualifier dayTimeIntervalQualifier =
702 new SqlIntervalQualifier(TimeUnit.DAY, null, SqlParserPos.ZERO);
703 return factory.createSqlIntervalType(dayTimeIntervalQualifier);
705 return factory.createTypeWithNullability(
715 return SqlTypeName.BOOLEAN;
718 return SqlTypeName.TINYINT;
721 return SqlTypeName.SMALLINT;
724 return SqlTypeName.INTEGER;
727 return SqlTypeName.BIGINT;
730 return SqlTypeName.FLOAT;
733 return SqlTypeName.DOUBLE;
750 return SqlTypeName.ARRAY;
760 return SqlTypeName.ARRAY;
773 return SqlTypeName.GEOMETRY;
775 return SqlTypeName.CURSOR;
780 return SqlTypeName.VARCHAR;
783 return SqlTypeName.TIMESTAMP;
808 return SqlTypeName.COLUMN_LIST;
810 return SqlTypeName.INTERVAL_DAY_HOUR;
812 return SqlTypeName.INTERVAL_YEAR_MONTH;
818 Set<SqlTypeName> allSqlTypeNames = EnumSet.allOf(SqlTypeName.class);
819 HEAVYDBLOGGER.error(
"toSqlTypeName: unknown type " + type +
" to be mapped to {"
820 + allSqlTypeNames +
"}");
ColumnListTextEncodingNone
static RelDataType toRelDataType(final ExtArgumentType type, RelDataTypeFactory factory)
final java.util.List< SqlTypeFamily > toSqlSignature()
size_t append(FILE *f, const size_t size, const int8_t *buf)
Appends the specified number of bytes to the end of the file f from buf.
ExtensionFunction(final List< ExtArgumentType > args, final List< ExtArgumentType > outs, final List< String > names, final Map< String, String > options, final Map< String, List< ExtArgumentType >> cursor_field_types, final Map< String, java.lang.Comparable<?>> default_values)
static SqlTypeName toSqlTypeName(final ExtArgumentType type)
Map< String, List< ExtArgumentType > > getCursorFieldTypes()
final Map< String, String > options
Simplified core of GeoJSON Polygon coordinates definition.
final ExtArgumentType ret
List< ExtArgumentType > getOuts()
final Map< String, Comparable<?> > default_values
String toJson(final String name)
ColumnArrayTextEncodingDict
List< String > getPrettyArgNames()
final List< String > names
Map< String, Comparable<?> > getDefaultValues()
static boolean isColumnListArrayType(final ExtArgumentType type)
Simplified core of GeoJSON MultiPolygon coordinates definition.
static boolean isColumnListType(final ExtArgumentType type)
static boolean isColumnType(final ExtArgumentType type)
ColumnArrayTextEncodingNone
static boolean isColumnArrayType(final ExtArgumentType type)
List< String > getArgNames()
Map< String, String > getOptions()
List< ExtArgumentType > getArgs()
final List< ExtArgumentType > args
static final Logger HEAVYDBLOGGER
ColumnListGeoMultiLineString
ExtensionFunction(final List< ExtArgumentType > args, final ExtArgumentType ret, final List< Map< String, String >> annotations)
ColumnListGeoMultiPolygon
static String typeName(final ExtArgumentType type)
ColumnListArrayTextEncodingNone
ColumnListTextEncodingDict
final List< Map< String, String > > annotations
static boolean isArrayType(final ExtArgumentType type)
static ExtArgumentType toSqlTypeName(final String type)
static String dq(final String str)
ColumnListArrayTextEncodingDict
final Map< String, List< ExtArgumentType > > cursor_field_types
static boolean isPointerType(final ExtArgumentType type)
static ExtArgumentType getValueType(final ExtArgumentType type)
final List< ExtArgumentType > outs
List< String > getOutNames()