OmniSciDB  f17484ade4
 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 2926 of file HeavyDBSqlOperatorTable.java.

Constructor & Destructor Documentation

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

Definition at line 2927 of file HeavyDBSqlOperatorTable.java.

2927  {
2928  super(name,
2929  SqlKind.OTHER_FUNCTION,
2930  ReturnTypes.CURSOR,
2931  null,
2932  new ExtTableFunctionTypeChecker(HeavyDBSqlOperatorTable.this),
2933  SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION);
2934  arg_types = sig.getArgs();
2935  outs = sig.getOuts();
2936  out_names = sig.getOutNames();
2937  arg_names = sig.getArgNames();
2938  // pretty_arg_names will be same as arg_names, except with
2939  // arg names for cursors stripped of array elements, i.e
2940  // my_cursor_input[x, y, z] => my_cursor_input
2941  pretty_arg_names = sig.getPrettyArgNames();
2942  options = sig.getOptions();
2943  cursor_field_types = sig.getCursorFieldTypes();
2944  default_values = sig.getDefaultValues();
2945  }
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 3265 of file HeavyDBSqlOperatorTable.java.

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

Definition at line 3250 of file HeavyDBSqlOperatorTable.java.

References Double, Float, and Integer.

3250  {
3251  if (value instanceof Integer || value instanceof Long || value instanceof Float
3252  || value instanceof Double) {
3253  return SqlLiteral.createExactNumeric(value.toString(), pos);
3254  } else if (value instanceof Boolean) {
3255  Boolean asBool = (Boolean) value;
3256  return SqlLiteral.createBoolean(asBool.booleanValue(), pos);
3257  } else if (value instanceof String) {
3258  return SqlLiteral.createCharString(value.toString(), pos);
3259  } else {
3260  return null;
3261  }
3262  }
void com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.debugPrint ( String  msg,
Boolean  debugMode 
)
inlineprivate

Definition at line 3022 of file HeavyDBSqlOperatorTable.java.

3022  {
3023  if (debugMode) {
3024  System.out.println(msg);
3025  }
3026  }
boolean com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.equals ( final Object  obj)
inline

Definition at line 3139 of file HeavyDBSqlOperatorTable.java.

References Cursor.

3139  {
3140  if (obj == null) {
3141  return false;
3142  }
3143 
3144  if (getClass() != obj.getClass()) {
3145  return false;
3146  }
3147 
3148  if (this == obj) {
3149  return true;
3150  }
3151 
3152  final ExtTableFunction other = (ExtTableFunction) obj;
3153  if (!this.getName().equals(other.getName())) {
3154  return false;
3155  }
3156  if (arg_types.size() != other.arg_types.size()) {
3157  return false;
3158  }
3159 
3160  for (int i = 0; i < arg_types.size(); i++) {
3161  if (arg_types.get(i) != other.arg_types.get(i)) {
3162  return false;
3163  }
3164  if (arg_types.get(i) == ExtArgumentType.Cursor) {
3165  String paramName = this.arg_names.get(i);
3166  String otherParamName = other.getExtendedParamNames().get(i);
3167  if (!paramName.equals(otherParamName)) {
3168  return false;
3169  }
3170 
3171  List<ExtArgumentType> field_types = this.getCursorFieldTypes().get(paramName);
3172  List<ExtArgumentType> other_field_types =
3173  other.getCursorFieldTypes().get(paramName);
3174  if (field_types.size() != other_field_types.size()) {
3175  return false;
3176  }
3177  for (int j = 0; j < field_types.size(); j++) {
3178  if (field_types.get(j) != other_field_types.get(j)) {
3179  return false;
3180  }
3181  }
3182  }
3183  }
3184  return true;
3185  }
ExtTableFunction(final String name, final ExtensionFunction sig)
List<ExtArgumentType> com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getArgTypes ( )
inline

Definition at line 3196 of file HeavyDBSqlOperatorTable.java.

3196  {
3197  return arg_types;
3198  }
Set<RelColumnMapping> com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getColumnMappings ( )
inline

Definition at line 3028 of file HeavyDBSqlOperatorTable.java.

References Integer.

3028  {
3029  final Boolean debugMode = false;
3030  Set<RelColumnMapping> s = new HashSet<RelColumnMapping>();
3031  debugPrint("getNameAsId() -> " + getNameAsId() + ", arg_names=" + arg_names
3032  + ", out_names=" + out_names,
3033  debugMode);
3034  if (Integer.valueOf(options.getOrDefault("filter_table_function_transpose", "0"))
3035  == 1) {
3036  debugPrint("getNameAsId() -> " + getNameAsId(), debugMode);
3037  int rel_idx = -1;
3038  for (int arg_idx = 0; arg_idx < arg_names.size(); ++arg_idx) {
3039  String arg_name = arg_names.get(arg_idx);
3040  String[] fields;
3041  int start = arg_name.indexOf("[");
3042  if (start != -1) {
3043  rel_idx += 1;
3044  int end = arg_name.lastIndexOf("]");
3045  fields = arg_name.substring(start + 1, end)
3046  .replaceAll("\\s+", "")
3047  .split(",", 0);
3048  } else {
3049  fields = new String[] {arg_name};
3050  }
3051  debugPrint("fields=" + Arrays.toString(fields), debugMode);
3052  for (int field_idx = 0; field_idx < fields.length; ++field_idx) {
3053  int out_idx = out_names.indexOf(fields[field_idx]);
3054  if (out_idx >= 0) {
3055  s.add(new RelColumnMapping(out_idx, rel_idx, field_idx, false));
3056  debugPrint("out_idx, arg_idx/rel_idx, field_idx=" + out_idx + ", " + arg_idx
3057  + "/" + rel_idx + ", " + field_idx,
3058  debugMode);
3059  }
3060  }
3061  }
3062  }
3063  return s;
3064  }
Map<String, List<ExtArgumentType> > com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getCursorFieldTypes ( )
inline

Definition at line 3192 of file HeavyDBSqlOperatorTable.java.

3192  {
3193  return cursor_field_types;
3194  }
Map<String, Comparable<?> > com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getDefaultValues ( )
inlinepackage

Definition at line 3200 of file HeavyDBSqlOperatorTable.java.

3200  {
3201  return default_values;
3202  }
List<String> com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getExtendedParamNames ( )
inline

Definition at line 3125 of file HeavyDBSqlOperatorTable.java.

3125  {
3126  return this.arg_names;
3127  }
String com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getExtendedSignature ( )
inline

Definition at line 3075 of file HeavyDBSqlOperatorTable.java.

References File_Namespace.append(), and run_benchmark_import.type.

3075  {
3076  StringBuilder ret = new StringBuilder();
3077  ret.append("'");
3078  ret.append(this.getName());
3079  ret.append("(");
3080 
3081  for (int i = 0; i < this.arg_types.size(); i++) {
3082  if (i > 0) {
3083  ret.append(", ");
3084  }
3085 
3086  ExtArgumentType type = arg_types.get(i);
3087  String paramName = arg_names.get(i);
3088  ret.append(paramName).append(" => ");
3089 
3090  final String t = type.toString().toUpperCase(Locale.ROOT);
3091  ret.append("<").append(t);
3092  if (type == ExtArgumentType.Cursor) {
3093  List<ExtensionFunction.ExtArgumentType> field_types =
3094  cursor_field_types.get(paramName);
3095  ret.append("[");
3096  for (int j = 0; j < field_types.size(); j++) {
3097  if (j > 0) {
3098  ret.append(",");
3099  }
3100  ExtArgumentType field_type = field_types.get(j);
3101  ret.append(toSqlTypeName(field_type));
3102  if (isColumnListType(field_type)) {
3103  ExtArgumentType subtype = getValueType(field_type);
3104  ret.append("[");
3105  ret.append(toSqlTypeName(subtype));
3106  ret.append("]");
3107  } else if (isColumnArrayType(field_type) || isArrayType(field_type)) {
3108  ExtArgumentType subtype = getValueType(getValueType(field_type));
3109  ret.append("[");
3110  ret.append(toSqlTypeName(subtype));
3111  ret.append("]");
3112  }
3113  }
3114  ret.append("]");
3115  }
3116  ret.append(">");
3117  }
3118  ret.append(")'");
3119 
3120  return ret.toString();
3121  }
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 3216 of file HeavyDBSqlOperatorTable.java.

3216  {
3217  return getDefaultValues().size();
3218  }
List<FunctionParameter> com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getParameters ( )
inline

Definition at line 2967 of file HeavyDBSqlOperatorTable.java.

References run_benchmark_import.type.

2967  {
2968  final Boolean has_names = this.pretty_arg_names != null
2969  && this.pretty_arg_names.size() == this.arg_types.size();
2970  final List<FunctionParameter> parameters = new java.util.ArrayList<>();
2971  for (int i = 0; i < this.arg_types.size(); i++) {
2972  final int arg_idx = i;
2973  parameters.add(new FunctionParameter() {
2974  public int getOrdinal() {
2975  return arg_idx;
2976  }
2977 
2978  public String getName() {
2979  if (has_names) {
2980  return pretty_arg_names.get(arg_idx);
2981  }
2982  return "arg" + arg_idx;
2983  }
2984 
2985  public RelDataType getType(RelDataTypeFactory typeFactory) {
2986  SqlTypeFamily type = toSqlTypeName(arg_types.get(arg_idx)).getFamily();
2987  return type.getDefaultConcreteType(typeFactory);
2988  }
2989 
2990  public boolean isOptional() {
2991  return false;
2992  }
2993  });
2994  }
2995  return parameters;
2996  }
List<String> com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.getParamNames ( )
inline

Definition at line 2953 of file HeavyDBSqlOperatorTable.java.

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

Definition at line 2999 of file HeavyDBSqlOperatorTable.java.

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

2999  {
3000  return opBinding -> {
3001  RelDataTypeFactory fact = opBinding.getTypeFactory();
3002  FieldInfoBuilder ret = fact.builder();
3003  for (int out_idx = 0; out_idx < outs.size(); ++out_idx) {
3004  RelDataType type;
3005  if (toSqlTypeName(outs.get(out_idx)) == SqlTypeName.ARRAY) {
3006  ExtArgumentType extSubType = getValueType(outs.get(out_idx));
3007  if (ExtensionFunction.isColumnArrayType(outs.get(out_idx))) {
3008  extSubType = getValueType(extSubType);
3009  }
3010  RelDataType subtype = fact.createSqlType(toSqlTypeName(extSubType));
3011  type = fact.createArrayType(subtype, -1);
3012  } else {
3013  type = fact.createSqlType(toSqlTypeName(outs.get(out_idx)));
3014  }
3015  ret = ret.add(out_names.get(out_idx), type);
3016  ret = ret.nullable(true);
3017  }
3018  return ret.build();
3019  };
3020  }

+ Here is the call graph for this function:

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

Definition at line 3131 of file HeavyDBSqlOperatorTable.java.

3131  {
3132  return this.getExtendedSignature().hashCode();
3133  }
boolean com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.isArgumentOptional ( int  i)
inline

Definition at line 3211 of file HeavyDBSqlOperatorTable.java.

3211  {
3212  String paramName = getParamNames().get(i);
3213  return getDefaultValues().get(paramName) != null;
3214  }
SqlCall com.mapd.calcite.parser.HeavyDBSqlOperatorTable.ExtTableFunction.rewriteCallWithDefaultArguments ( SqlCall  permutedCall)
inline

Definition at line 3233 of file HeavyDBSqlOperatorTable.java.

3233  {
3234  for (Ord<SqlNode> operand : Ord.zip(permutedCall.getOperandList())) {
3235  if (operand.e.getClass() == SqlBasicCall.class) {
3236  SqlBasicCall operandAsCall = (SqlBasicCall) operand.e;
3237  if (operandAsCall.getOperator().getName() == "DEFAULT") {
3238  ExtTableFunction tf = (ExtTableFunction) permutedCall.getOperator();
3239  String paramName = tf.getExtendedParamNames().get(operand.i);
3240  Comparable<?> defaultVal = tf.getDefaultValues().get(paramName);
3241  SqlLiteral newOperand = createLiteralForDefaultValue(
3242  defaultVal, operand.e.getParserPosition());
3243  permutedCall.setOperand(operand.i, newOperand);
3244  }
3245  }
3246  }
3247  return permutedCall;
3248  }
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 3204 of file HeavyDBSqlOperatorTable.java.

3204  {
3205  return (default_values.size() > 0);
3206  }
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 3276 of file HeavyDBSqlOperatorTable.java.

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

Definition at line 3274 of file HeavyDBSqlOperatorTable.java.

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

Definition at line 3280 of file HeavyDBSqlOperatorTable.java.

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

Definition at line 3281 of file HeavyDBSqlOperatorTable.java.

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

Definition at line 3279 of file HeavyDBSqlOperatorTable.java.

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

Definition at line 3278 of file HeavyDBSqlOperatorTable.java.

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

Definition at line 3275 of file HeavyDBSqlOperatorTable.java.

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

Definition at line 3277 of file HeavyDBSqlOperatorTable.java.


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