OmniSciDB  72c90bc290
 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 2982 of file HeavyDBSqlOperatorTable.java.

Constructor & Destructor Documentation

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

Definition at line 2983 of file HeavyDBSqlOperatorTable.java.

2983  {
2984  super(name,
2985  SqlKind.OTHER_FUNCTION,
2986  ReturnTypes.CURSOR,
2987  null,
2988  new ExtTableFunctionTypeChecker(HeavyDBSqlOperatorTable.this),
2989  SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION);
2990  arg_types = sig.getArgs();
2991  outs = sig.getOuts();
2992  out_names = sig.getOutNames();
2993  arg_names = sig.getArgNames();
2994  // pretty_arg_names will be same as arg_names, except with
2995  // arg names for cursors stripped of array elements, i.e
2996  // my_cursor_input[x, y, z] => my_cursor_input
2997  pretty_arg_names = sig.getPrettyArgNames();
2998  options = sig.getOptions();
2999  cursor_field_types = sig.getCursorFieldTypes();
3000  default_values = sig.getDefaultValues();
3001  }
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 3321 of file HeavyDBSqlOperatorTable.java.

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

Definition at line 3306 of file HeavyDBSqlOperatorTable.java.

References Double, Float, and Integer.

3306  {
3307  if (value instanceof Integer || value instanceof Long || value instanceof Float
3308  || value instanceof Double) {
3309  return SqlLiteral.createExactNumeric(value.toString(), pos);
3310  } else if (value instanceof Boolean) {
3311  Boolean asBool = (Boolean) value;
3312  return SqlLiteral.createBoolean(asBool.booleanValue(), pos);
3313  } else if (value instanceof String) {
3314  return SqlLiteral.createCharString(value.toString(), pos);
3315  } else {
3316  return null;
3317  }
3318  }
void com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.debugPrint ( String  msg,
Boolean  debugMode 
)
inlineprivate

Definition at line 3078 of file HeavyDBSqlOperatorTable.java.

3078  {
3079  if (debugMode) {
3080  System.out.println(msg);
3081  }
3082  }
boolean com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.equals ( final Object  obj)
inline

Definition at line 3195 of file HeavyDBSqlOperatorTable.java.

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

3195  {
3196  if (obj == null) {
3197  return false;
3198  }
3199 
3200  if (getClass() != obj.getClass()) {
3201  return false;
3202  }
3203 
3204  if (this == obj) {
3205  return true;
3206  }
3207 
3208  final ExtTableFunction other = (ExtTableFunction) obj;
3209  if (!this.getName().equals(other.getName())) {
3210  return false;
3211  }
3212  if (arg_types.size() != other.arg_types.size()) {
3213  return false;
3214  }
3215 
3216  for (int i = 0; i < arg_types.size(); i++) {
3217  if (arg_types.get(i) != other.arg_types.get(i)) {
3218  return false;
3219  }
3220  if (arg_types.get(i) == ExtArgumentType.Cursor) {
3221  String paramName = this.arg_names.get(i);
3222  String otherParamName = other.getExtendedParamNames().get(i);
3223  if (!paramName.equals(otherParamName)) {
3224  return false;
3225  }
3226 
3227  List<ExtArgumentType> field_types = this.getCursorFieldTypes().get(paramName);
3228  List<ExtArgumentType> other_field_types =
3229  other.getCursorFieldTypes().get(paramName);
3230  if (field_types.size() != other_field_types.size()) {
3231  return false;
3232  }
3233  for (int j = 0; j < field_types.size(); j++) {
3234  if (field_types.get(j) != other_field_types.get(j)) {
3235  return false;
3236  }
3237  }
3238  }
3239  }
3240  return true;
3241  }
ExtTableFunction(final String name, final ExtensionFunction sig)
List<ExtArgumentType> com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getArgTypes ( )
inline

Definition at line 3252 of file HeavyDBSqlOperatorTable.java.

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

3252  {
3253  return arg_types;
3254  }

+ Here is the caller graph for this function:

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

Definition at line 3084 of file HeavyDBSqlOperatorTable.java.

References Integer.

3084  {
3085  final Boolean debugMode = false;
3086  Set<RelColumnMapping> s = new HashSet<RelColumnMapping>();
3087  debugPrint("getNameAsId() -> " + getNameAsId() + ", arg_names=" + arg_names
3088  + ", out_names=" + out_names,
3089  debugMode);
3090  if (Integer.valueOf(options.getOrDefault("filter_table_function_transpose", "0"))
3091  == 1) {
3092  debugPrint("getNameAsId() -> " + getNameAsId(), debugMode);
3093  int rel_idx = -1;
3094  for (int arg_idx = 0; arg_idx < arg_names.size(); ++arg_idx) {
3095  String arg_name = arg_names.get(arg_idx);
3096  String[] fields;
3097  int start = arg_name.indexOf("[");
3098  if (start != -1) {
3099  rel_idx += 1;
3100  int end = arg_name.lastIndexOf("]");
3101  fields = arg_name.substring(start + 1, end)
3102  .replaceAll("\\s+", "")
3103  .split(",", 0);
3104  } else {
3105  fields = new String[] {arg_name};
3106  }
3107  debugPrint("fields=" + Arrays.toString(fields), debugMode);
3108  for (int field_idx = 0; field_idx < fields.length; ++field_idx) {
3109  int out_idx = out_names.indexOf(fields[field_idx]);
3110  if (out_idx >= 0) {
3111  s.add(new RelColumnMapping(out_idx, rel_idx, field_idx, false));
3112  debugPrint("out_idx, arg_idx/rel_idx, field_idx=" + out_idx + ", " + arg_idx
3113  + "/" + rel_idx + ", " + field_idx,
3114  debugMode);
3115  }
3116  }
3117  }
3118  }
3119  return s;
3120  }
Map<String, List<ExtArgumentType> > com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getCursorFieldTypes ( )
inline

Definition at line 3248 of file HeavyDBSqlOperatorTable.java.

3248  {
3249  return cursor_field_types;
3250  }
Map<String, Comparable<?> > com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getDefaultValues ( )
inlinepackage

Definition at line 3256 of file HeavyDBSqlOperatorTable.java.

3256  {
3257  return default_values;
3258  }
List<String> com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getExtendedParamNames ( )
inline

Definition at line 3181 of file HeavyDBSqlOperatorTable.java.

3181  {
3182  return this.arg_names;
3183  }
String com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getExtendedSignature ( )
inline

Definition at line 3131 of file HeavyDBSqlOperatorTable.java.

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

3131  {
3132  StringBuilder ret = new StringBuilder();
3133  ret.append("'");
3134  ret.append(this.getName());
3135  ret.append("(");
3136 
3137  for (int i = 0; i < this.arg_types.size(); i++) {
3138  if (i > 0) {
3139  ret.append(", ");
3140  }
3141 
3142  ExtArgumentType type = arg_types.get(i);
3143  String paramName = arg_names.get(i);
3144  ret.append(paramName).append(" => ");
3145 
3146  final String t = type.toString().toUpperCase(Locale.ROOT);
3147  ret.append("<").append(t);
3148  if (type == ExtArgumentType.Cursor) {
3149  List<ExtensionFunction.ExtArgumentType> field_types =
3150  cursor_field_types.get(paramName);
3151  ret.append("[");
3152  for (int j = 0; j < field_types.size(); j++) {
3153  if (j > 0) {
3154  ret.append(",");
3155  }
3156  ExtArgumentType field_type = field_types.get(j);
3157  ret.append(toSqlTypeName(field_type));
3158  if (isColumnListType(field_type)) {
3159  ExtArgumentType subtype = getValueType(field_type);
3160  ret.append("[");
3161  ret.append(toSqlTypeName(subtype));
3162  ret.append("]");
3163  } else if (isColumnArrayType(field_type) || isArrayType(field_type)) {
3164  ExtArgumentType subtype = getValueType(getValueType(field_type));
3165  ret.append("[");
3166  ret.append(toSqlTypeName(subtype));
3167  ret.append("]");
3168  }
3169  }
3170  ret.append("]");
3171  }
3172  ret.append(">");
3173  }
3174  ret.append(")'");
3175 
3176  return ret.toString();
3177  }
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 3272 of file HeavyDBSqlOperatorTable.java.

3272  {
3273  return getDefaultValues().size();
3274  }
List<FunctionParameter> com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getParameters ( )
inline

Definition at line 3023 of file HeavyDBSqlOperatorTable.java.

References run_benchmark_import.type.

3023  {
3024  final Boolean has_names = this.pretty_arg_names != null
3025  && this.pretty_arg_names.size() == this.arg_types.size();
3026  final List<FunctionParameter> parameters = new java.util.ArrayList<>();
3027  for (int i = 0; i < this.arg_types.size(); i++) {
3028  final int arg_idx = i;
3029  parameters.add(new FunctionParameter() {
3030  public int getOrdinal() {
3031  return arg_idx;
3032  }
3033 
3034  public String getName() {
3035  if (has_names) {
3036  return pretty_arg_names.get(arg_idx);
3037  }
3038  return "arg" + arg_idx;
3039  }
3040 
3041  public RelDataType getType(RelDataTypeFactory typeFactory) {
3042  SqlTypeFamily type = toSqlTypeName(arg_types.get(arg_idx)).getFamily();
3043  return type.getDefaultConcreteType(typeFactory);
3044  }
3045 
3046  public boolean isOptional() {
3047  return false;
3048  }
3049  });
3050  }
3051  return parameters;
3052  }
List<String> com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getParamNames ( )
inline

Definition at line 3009 of file HeavyDBSqlOperatorTable.java.

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

Definition at line 3055 of file HeavyDBSqlOperatorTable.java.

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

3055  {
3056  return opBinding -> {
3057  RelDataTypeFactory fact = opBinding.getTypeFactory();
3058  FieldInfoBuilder ret = fact.builder();
3059  for (int out_idx = 0; out_idx < outs.size(); ++out_idx) {
3060  RelDataType type;
3061  if (toSqlTypeName(outs.get(out_idx)) == SqlTypeName.ARRAY) {
3062  ExtArgumentType extSubType = getValueType(outs.get(out_idx));
3063  if (ExtensionFunction.isColumnArrayType(outs.get(out_idx))) {
3064  extSubType = getValueType(extSubType);
3065  }
3066  RelDataType subtype = fact.createSqlType(toSqlTypeName(extSubType));
3067  type = fact.createArrayType(subtype, -1);
3068  } else {
3069  type = fact.createSqlType(toSqlTypeName(outs.get(out_idx)));
3070  }
3071  ret = ret.add(out_names.get(out_idx), type);
3072  ret = ret.nullable(true);
3073  }
3074  return ret.build();
3075  };
3076  }

+ Here is the call graph for this function:

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

Definition at line 3187 of file HeavyDBSqlOperatorTable.java.

3187  {
3188  return this.getExtendedSignature().hashCode();
3189  }
boolean com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.isArgumentOptional ( int  i)
inline

Definition at line 3267 of file HeavyDBSqlOperatorTable.java.

3267  {
3268  String paramName = getParamNames().get(i);
3269  return getDefaultValues().get(paramName) != null;
3270  }
SqlCall com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.rewriteCallWithDefaultArguments ( SqlCall  permutedCall)
inline

Definition at line 3289 of file HeavyDBSqlOperatorTable.java.

3289  {
3290  for (Ord<SqlNode> operand : Ord.zip(permutedCall.getOperandList())) {
3291  if (operand.e.getClass() == SqlBasicCall.class) {
3292  SqlBasicCall operandAsCall = (SqlBasicCall) operand.e;
3293  if (operandAsCall.getOperator().getName() == "DEFAULT") {
3294  ExtTableFunction tf = (ExtTableFunction) permutedCall.getOperator();
3295  String paramName = tf.getExtendedParamNames().get(operand.i);
3296  Comparable<?> defaultVal = tf.getDefaultValues().get(paramName);
3297  SqlLiteral newOperand = createLiteralForDefaultValue(
3298  defaultVal, operand.e.getParserPosition());
3299  permutedCall.setOperand(operand.i, newOperand);
3300  }
3301  }
3302  }
3303  return permutedCall;
3304  }
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 3260 of file HeavyDBSqlOperatorTable.java.

3260  {
3261  return (default_values.size() > 0);
3262  }
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 3332 of file HeavyDBSqlOperatorTable.java.

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

Definition at line 3330 of file HeavyDBSqlOperatorTable.java.

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

Definition at line 3336 of file HeavyDBSqlOperatorTable.java.

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

Definition at line 3337 of file HeavyDBSqlOperatorTable.java.

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

Definition at line 3335 of file HeavyDBSqlOperatorTable.java.

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

Definition at line 3334 of file HeavyDBSqlOperatorTable.java.

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

Definition at line 3331 of file HeavyDBSqlOperatorTable.java.

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

Definition at line 3333 of file HeavyDBSqlOperatorTable.java.


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