OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction Class Reference
+ Inheritance diagram for com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction:
+ Collaboration diagram for com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction:

Public Member Functions

List< String > getParamNames ()
 
List< FunctionParameter > getParameters ()
 
SqlReturnTypeInference getRowTypeInference ()
 
Set< RelColumnMapping > getColumnMappings ()
 
String getExtendedSignature ()
 
List< String > getExtendedParamNames ()
 
int hashCode ()
 
boolean equals (final Object obj)
 
String toString ()
 
Map< String, List
< ExtArgumentType > > 
getCursorFieldTypes ()
 
List< ExtArgumentTypegetArgTypes ()
 
boolean supportsDefaultArguments ()
 
boolean isArgumentOptional (int i)
 
int getNumOptionalArguments ()
 
SqlCall rewriteCallWithDefaultArguments (SqlCall permutedCall)
 
boolean checkOperandTypes (SqlCallBinding callBinding, boolean throwOnFailure)
 

Package Functions

 ExtTableFunction (final String name, final ExtensionFunction sig)
 
Map< String, Comparable<?> > getDefaultValues ()
 
SqlLiteral createLiteralForDefaultValue (Comparable<?> value, SqlParserPos pos)
 

Private Member Functions

void debugPrint (String msg, Boolean debugMode)
 

Private Attributes

final List< ExtArgumentTypearg_types
 
final List< ExtArgumentTypeouts
 
final List< String > arg_names
 
final List< String > pretty_arg_names
 
final List< String > out_names
 
final Map< String, String > options
 
final Map< String, List
< ExtArgumentType > > 
cursor_field_types
 
final Map< String, Comparable<?> > default_values
 

Detailed Description

Definition at line 3123 of file HeavyDBSqlOperatorTable.java.

Constructor & Destructor Documentation

com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.ExtTableFunction ( final String  name,
final ExtensionFunction  sig 
)
inlinepackage

Definition at line 3124 of file HeavyDBSqlOperatorTable.java.

3124  {
3125  super(name,
3126  SqlKind.OTHER_FUNCTION,
3127  ReturnTypes.CURSOR,
3128  null,
3129  new ExtTableFunctionTypeChecker(HeavyDBSqlOperatorTable.this),
3130  SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION);
3131  arg_types = sig.getArgs();
3132  outs = sig.getOuts();
3133  out_names = sig.getOutNames();
3134  arg_names = sig.getArgNames();
3135  // pretty_arg_names will be same as arg_names, except with
3136  // arg names for cursors stripped of array elements, i.e
3137  // my_cursor_input[x, y, z] => my_cursor_input
3138  pretty_arg_names = sig.getPrettyArgNames();
3139  options = sig.getOptions();
3140  cursor_field_types = sig.getCursorFieldTypes();
3141  default_values = sig.getDefaultValues();
3142  }
string name
Definition: setup.in.py:72

Member Function Documentation

boolean com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.checkOperandTypes ( SqlCallBinding  callBinding,
boolean  throwOnFailure 
)
inline

Definition at line 3462 of file HeavyDBSqlOperatorTable.java.

3462  {
3463  // We need to override this because the default Calcite implementation adds logic to
3464  // handle default values before deferring typechecking to the operator's own
3465  // SqlOperandTypeChecker. Since we want to handle default values differently for
3466  // UDTFs, this method bypasses that logic and simply calls the type checker
3467  // directly.
3468  return getOperandTypeChecker().checkOperandTypes(callBinding, throwOnFailure);
3469  }
SqlLiteral com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.createLiteralForDefaultValue ( Comparable<?>  value,
SqlParserPos  pos 
)
inlinepackage

Definition at line 3447 of file HeavyDBSqlOperatorTable.java.

References Double, Float, and Integer.

3447  {
3448  if (value instanceof Integer || value instanceof Long || value instanceof Float
3449  || value instanceof Double) {
3450  return SqlLiteral.createExactNumeric(value.toString(), pos);
3451  } else if (value instanceof Boolean) {
3452  Boolean asBool = (Boolean) value;
3453  return SqlLiteral.createBoolean(asBool.booleanValue(), pos);
3454  } else if (value instanceof String) {
3455  return SqlLiteral.createCharString(value.toString(), pos);
3456  } else {
3457  return null;
3458  }
3459  }
void com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.debugPrint ( String  msg,
Boolean  debugMode 
)
inlineprivate

Definition at line 3219 of file HeavyDBSqlOperatorTable.java.

3219  {
3220  if (debugMode) {
3221  System.out.println(msg);
3222  }
3223  }
boolean com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.equals ( final Object  obj)
inline

Definition at line 3336 of file HeavyDBSqlOperatorTable.java.

References com.mapd.parser.server.ExtensionFunction.ExtArgumentType.Cursor.

3336  {
3337  if (obj == null) {
3338  return false;
3339  }
3340 
3341  if (getClass() != obj.getClass()) {
3342  return false;
3343  }
3344 
3345  if (this == obj) {
3346  return true;
3347  }
3348 
3349  final ExtTableFunction other = (ExtTableFunction) obj;
3350  if (!this.getName().equals(other.getName())) {
3351  return false;
3352  }
3353  if (arg_types.size() != other.arg_types.size()) {
3354  return false;
3355  }
3356 
3357  for (int i = 0; i < arg_types.size(); i++) {
3358  if (arg_types.get(i) != other.arg_types.get(i)) {
3359  return false;
3360  }
3361  if (arg_types.get(i) == ExtArgumentType.Cursor) {
3362  String paramName = this.arg_names.get(i);
3363  String otherParamName = other.getExtendedParamNames().get(i);
3364  if (!paramName.equals(otherParamName)) {
3365  return false;
3366  }
3367 
3368  List<ExtArgumentType> field_types = this.getCursorFieldTypes().get(paramName);
3369  List<ExtArgumentType> other_field_types =
3370  other.getCursorFieldTypes().get(paramName);
3371  if (field_types.size() != other_field_types.size()) {
3372  return false;
3373  }
3374  for (int j = 0; j < field_types.size(); j++) {
3375  if (field_types.get(j) != other_field_types.get(j)) {
3376  return false;
3377  }
3378  }
3379  }
3380  }
3381  return true;
3382  }
ExtTableFunction(final String name, final ExtensionFunction sig)
List<ExtArgumentType> com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getArgTypes ( )
inline

Definition at line 3393 of file HeavyDBSqlOperatorTable.java.

Referenced by com.mapd.calcite.parser.HeavyDBTypeCoercion.calculateScoreForCursorOperand().

3393  {
3394  return arg_types;
3395  }

+ Here is the caller graph for this function:

Set<RelColumnMapping> com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getColumnMappings ( )
inline

Definition at line 3225 of file HeavyDBSqlOperatorTable.java.

References Integer.

3225  {
3226  final Boolean debugMode = false;
3227  Set<RelColumnMapping> s = new HashSet<RelColumnMapping>();
3228  debugPrint("getNameAsId() -> " + getNameAsId() + ", arg_names=" + arg_names
3229  + ", out_names=" + out_names,
3230  debugMode);
3231  if (Integer.valueOf(options.getOrDefault("filter_table_function_transpose", "0"))
3232  == 1) {
3233  debugPrint("getNameAsId() -> " + getNameAsId(), debugMode);
3234  int rel_idx = -1;
3235  for (int arg_idx = 0; arg_idx < arg_names.size(); ++arg_idx) {
3236  String arg_name = arg_names.get(arg_idx);
3237  String[] fields;
3238  int start = arg_name.indexOf("[");
3239  if (start != -1) {
3240  rel_idx += 1;
3241  int end = arg_name.lastIndexOf("]");
3242  fields = arg_name.substring(start + 1, end)
3243  .replaceAll("\\s+", "")
3244  .split(",", 0);
3245  } else {
3246  fields = new String[] {arg_name};
3247  }
3248  debugPrint("fields=" + Arrays.toString(fields), debugMode);
3249  for (int field_idx = 0; field_idx < fields.length; ++field_idx) {
3250  int out_idx = out_names.indexOf(fields[field_idx]);
3251  if (out_idx >= 0) {
3252  s.add(new RelColumnMapping(out_idx, rel_idx, field_idx, false));
3253  debugPrint("out_idx, arg_idx/rel_idx, field_idx=" + out_idx + ", " + arg_idx
3254  + "/" + rel_idx + ", " + field_idx,
3255  debugMode);
3256  }
3257  }
3258  }
3259  }
3260  return s;
3261  }
Map<String, List<ExtArgumentType> > com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getCursorFieldTypes ( )
inline

Definition at line 3389 of file HeavyDBSqlOperatorTable.java.

3389  {
3390  return cursor_field_types;
3391  }
Map<String, Comparable<?> > com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getDefaultValues ( )
inlinepackage

Definition at line 3397 of file HeavyDBSqlOperatorTable.java.

3397  {
3398  return default_values;
3399  }
List<String> com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getExtendedParamNames ( )
inline

Definition at line 3322 of file HeavyDBSqlOperatorTable.java.

3322  {
3323  return this.arg_names;
3324  }
String com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getExtendedSignature ( )
inline

Definition at line 3272 of file HeavyDBSqlOperatorTable.java.

References File_Namespace.append(), com.mapd.parser.server.ExtensionFunction.ExtArgumentType.Cursor, and run_benchmark_import.type.

3272  {
3273  StringBuilder ret = new StringBuilder();
3274  ret.append("'");
3275  ret.append(this.getName());
3276  ret.append("(");
3277 
3278  for (int i = 0; i < this.arg_types.size(); i++) {
3279  if (i > 0) {
3280  ret.append(", ");
3281  }
3282 
3283  ExtArgumentType type = arg_types.get(i);
3284  String paramName = arg_names.get(i);
3285  ret.append(paramName).append(" => ");
3286 
3287  final String t = type.toString().toUpperCase(Locale.ROOT);
3288  ret.append("<").append(t);
3289  if (type == ExtArgumentType.Cursor) {
3290  List<ExtensionFunction.ExtArgumentType> field_types =
3291  cursor_field_types.get(paramName);
3292  ret.append("[");
3293  for (int j = 0; j < field_types.size(); j++) {
3294  if (j > 0) {
3295  ret.append(",");
3296  }
3297  ExtArgumentType field_type = field_types.get(j);
3298  ret.append(toSqlTypeName(field_type));
3299  if (isColumnListType(field_type)) {
3300  ExtArgumentType subtype = getValueType(field_type);
3301  ret.append("[");
3302  ret.append(toSqlTypeName(subtype));
3303  ret.append("]");
3304  } else if (isColumnArrayType(field_type) || isArrayType(field_type)) {
3305  ExtArgumentType subtype = getValueType(getValueType(field_type));
3306  ret.append("[");
3307  ret.append(toSqlTypeName(subtype));
3308  ret.append("]");
3309  }
3310  }
3311  ret.append("]");
3312  }
3313  ret.append(">");
3314  }
3315  ret.append(")'");
3316 
3317  return ret.toString();
3318  }
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.
Definition: File.cpp:158

+ Here is the call graph for this function:

int com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getNumOptionalArguments ( )
inline

Definition at line 3413 of file HeavyDBSqlOperatorTable.java.

3413  {
3414  return getDefaultValues().size();
3415  }
List<FunctionParameter> com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getParameters ( )
inline

Definition at line 3164 of file HeavyDBSqlOperatorTable.java.

References run_benchmark_import.type.

3164  {
3165  final Boolean has_names = this.pretty_arg_names != null
3166  && this.pretty_arg_names.size() == this.arg_types.size();
3167  final List<FunctionParameter> parameters = new java.util.ArrayList<>();
3168  for (int i = 0; i < this.arg_types.size(); i++) {
3169  final int arg_idx = i;
3170  parameters.add(new FunctionParameter() {
3171  public int getOrdinal() {
3172  return arg_idx;
3173  }
3174 
3175  public String getName() {
3176  if (has_names) {
3177  return pretty_arg_names.get(arg_idx);
3178  }
3179  return "arg" + arg_idx;
3180  }
3181 
3182  public RelDataType getType(RelDataTypeFactory typeFactory) {
3183  SqlTypeFamily type = toSqlTypeName(arg_types.get(arg_idx)).getFamily();
3184  return type.getDefaultConcreteType(typeFactory);
3185  }
3186 
3187  public boolean isOptional() {
3188  return false;
3189  }
3190  });
3191  }
3192  return parameters;
3193  }
List<String> com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getParamNames ( )
inline

Definition at line 3150 of file HeavyDBSqlOperatorTable.java.

SqlReturnTypeInference com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getRowTypeInference ( )
inline

Definition at line 3196 of file HeavyDBSqlOperatorTable.java.

References com.mapd.parser.server.ExtensionFunction.isColumnArrayType(), and run_benchmark_import.type.

3196  {
3197  return opBinding -> {
3198  RelDataTypeFactory fact = opBinding.getTypeFactory();
3199  FieldInfoBuilder ret = fact.builder();
3200  for (int out_idx = 0; out_idx < outs.size(); ++out_idx) {
3201  RelDataType type;
3202  if (toSqlTypeName(outs.get(out_idx)) == SqlTypeName.ARRAY) {
3203  ExtArgumentType extSubType = getValueType(outs.get(out_idx));
3204  if (ExtensionFunction.isColumnArrayType(outs.get(out_idx))) {
3205  extSubType = getValueType(extSubType);
3206  }
3207  RelDataType subtype = fact.createSqlType(toSqlTypeName(extSubType));
3208  type = fact.createArrayType(subtype, -1);
3209  } else {
3210  type = fact.createSqlType(toSqlTypeName(outs.get(out_idx)));
3211  }
3212  ret = ret.add(out_names.get(out_idx), type);
3213  ret = ret.nullable(true);
3214  }
3215  return ret.build();
3216  };
3217  }

+ Here is the call graph for this function:

int com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.hashCode ( )
inline

Definition at line 3328 of file HeavyDBSqlOperatorTable.java.

3328  {
3329  return this.getExtendedSignature().hashCode();
3330  }
boolean com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.isArgumentOptional ( int  i)
inline

Definition at line 3408 of file HeavyDBSqlOperatorTable.java.

3408  {
3409  String paramName = getParamNames().get(i);
3410  return getDefaultValues().get(paramName) != null;
3411  }
SqlCall com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.rewriteCallWithDefaultArguments ( SqlCall  permutedCall)
inline

Definition at line 3430 of file HeavyDBSqlOperatorTable.java.

3430  {
3431  for (Ord<SqlNode> operand : Ord.zip(permutedCall.getOperandList())) {
3432  if (operand.e.getClass() == SqlBasicCall.class) {
3433  SqlBasicCall operandAsCall = (SqlBasicCall) operand.e;
3434  if (operandAsCall.getOperator().getName() == "DEFAULT") {
3435  ExtTableFunction tf = (ExtTableFunction) permutedCall.getOperator();
3436  String paramName = tf.getExtendedParamNames().get(operand.i);
3437  Comparable<?> defaultVal = tf.getDefaultValues().get(paramName);
3438  SqlLiteral newOperand = createLiteralForDefaultValue(
3439  defaultVal, operand.e.getParserPosition());
3440  permutedCall.setOperand(operand.i, newOperand);
3441  }
3442  }
3443  }
3444  return permutedCall;
3445  }
ExtTableFunction(final String name, final ExtensionFunction sig)
SqlLiteral createLiteralForDefaultValue(Comparable<?> value, SqlParserPos pos)
boolean com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.supportsDefaultArguments ( )
inline

Definition at line 3401 of file HeavyDBSqlOperatorTable.java.

3401  {
3402  return (default_values.size() > 0);
3403  }
String com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.toString ( )
inline

Member Data Documentation

final List<String> com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.arg_names
private

Definition at line 3473 of file HeavyDBSqlOperatorTable.java.

final List<ExtArgumentType> com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.arg_types
private

Definition at line 3471 of file HeavyDBSqlOperatorTable.java.

final Map<String, List<ExtArgumentType> > com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.cursor_field_types
private

Definition at line 3477 of file HeavyDBSqlOperatorTable.java.

final Map<String, Comparable<?> > com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.default_values
private

Definition at line 3478 of file HeavyDBSqlOperatorTable.java.

final Map<String, String> com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.options
private

Definition at line 3476 of file HeavyDBSqlOperatorTable.java.

final List<String> com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.out_names
private

Definition at line 3475 of file HeavyDBSqlOperatorTable.java.

final List<ExtArgumentType> com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.outs
private

Definition at line 3472 of file HeavyDBSqlOperatorTable.java.

final List<String> com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.pretty_arg_names
private

Definition at line 3474 of file HeavyDBSqlOperatorTable.java.


The documentation for this class was generated from the following file: