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

Public Member Functions

boolean isOptional (int argIndex)
 
boolean doesOperandTypeMatch (ExtTableFunction tf, SqlCallBinding callBinding, SqlNode node, int iFormalOperand)
 
boolean checkOperandTypes (SqlCallBinding callBinding, boolean throwOnFailure)
 
boolean doesCursorOperandTypeMatch (ExtTableFunction tf, int iFormalOperand, RelDataType actualOperand)
 
List< ExtTableFunctiongetOperatorOverloads (SqlOperator op)
 
SqlOperandCountRange getOperandCountRange ()
 
String getAllowedSignatures (SqlOperator op, String opName)
 
Consistency getConsistency ()
 

Package Functions

 ExtTableFunctionTypeChecker (HeavyDBSqlOperatorTable opTable)
 

Package Attributes

final HeavyDBSqlOperatorTable opTable
 

Detailed Description

Definition at line 30 of file ExtTableFunctionTypeChecker.java.

Constructor & Destructor Documentation

com.mapd.calcite.parser.ExtTableFunctionTypeChecker.ExtTableFunctionTypeChecker ( HeavyDBSqlOperatorTable  opTable)
inlinepackage

Definition at line 33 of file ExtTableFunctionTypeChecker.java.

References com.mapd.calcite.parser.ExtTableFunctionTypeChecker.opTable.

33  {
34  this.opTable = opTable;
35  }

Member Function Documentation

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

Definition at line 74 of file ExtTableFunctionTypeChecker.java.

References com.mapd.calcite.parser.ExtTableFunctionTypeChecker.doesOperandTypeMatch(), and com.mapd.calcite.parser.ExtTableFunctionTypeChecker.getOperatorOverloads().

74  {
75  Set<ExtTableFunction> candidateOverloads = new HashSet<ExtTableFunction>(
76  getOperatorOverloads(callBinding.getOperator()));
77 
78  // Remove all candidates whose number of formal args doesn't match the
79  // call's number of real args.
80  candidateOverloads.removeIf(
81  tf -> tf.getArgTypes().size() != callBinding.getOperandCount());
82 
83  SqlNode[] operandArray = new SqlNode[callBinding.getCall().getOperandList().size()];
84  for (Ord<SqlNode> arg : Ord.zip(callBinding.getCall().getOperandList())) {
85  operandArray[arg.i] = arg.e;
86  }
87 
88  // Construct a candidate call binding for each overload. We need to do this because
89  // type inference of operands may differ depending on which operator is used. Thus,
90  // typechecking needs to be done on a candidate call-by-call basis.
91  HashMap<ExtTableFunction, SqlCallBinding> candidateBindings =
92  new HashMap<>(candidateOverloads.size());
93  for (ExtTableFunction tf : candidateOverloads) {
94  SqlBasicCall newCall = new SqlBasicCall(
95  tf, operandArray, callBinding.getCall().getParserPosition());
96  SqlCallBinding candidateBinding = new SqlCallBinding(
97  callBinding.getValidator(), callBinding.getScope(), newCall);
98  candidateBindings.put(tf, candidateBinding);
99  }
100 
101  for (int i = 0; i < operandArray.length; i++) {
102  int idx = i;
103  candidateOverloads.removeIf(tf
105  tf, candidateBindings.get(tf), operandArray[idx], idx));
106  }
107 
108  // If there are no candidates left, the call is invalid.
109  if (candidateOverloads.size() == 0) {
110  if (throwOnFailure) {
111  throw(callBinding.newValidationSignatureError());
112  }
113  return false;
114  }
115 
116  // If there are candidates left, and the current bound operator
117  // is not one of them, rewrite the call to use the a better binding.
118  if (!candidateOverloads.isEmpty()
119  && !candidateOverloads.contains(callBinding.getOperator())) {
120  ExtTableFunction optimal = candidateOverloads.iterator().next();
121  ((SqlBasicCall) callBinding.getCall()).setOperator(optimal);
122  }
123 
124  return true;
125  }
List< ExtTableFunction > getOperatorOverloads(SqlOperator op)
boolean doesOperandTypeMatch(ExtTableFunction tf, SqlCallBinding callBinding, SqlNode node, int iFormalOperand)

+ Here is the call graph for this function:

boolean com.mapd.calcite.parser.ExtTableFunctionTypeChecker.doesCursorOperandTypeMatch ( ExtTableFunction  tf,
int  iFormalOperand,
RelDataType  actualOperand 
)
inline

Definition at line 127 of file ExtTableFunctionTypeChecker.java.

Referenced by com.mapd.calcite.parser.ExtTableFunctionTypeChecker.doesOperandTypeMatch().

128  {
129  String formalOperandName = tf.getExtendedParamNames().get(iFormalOperand);
130  List<ExtensionFunction.ExtArgumentType> formalFieldTypes =
131  tf.getCursorFieldTypes().get(formalOperandName);
132  List<RelDataTypeField> actualFieldList = actualOperand.getFieldList();
133 
134  // runtime functions may not have CURSOR field type information, so we default
135  // to old behavior of assuming they typecheck
136  if (formalFieldTypes.size() == 0) {
137  System.out.println(
138  "Warning: UDTF has no CURSOR field subtype data. Proceeding assuming CURSOR typechecks.");
139  return true;
140  }
141 
142  int iFormal = 0;
143  int iActual = 0;
144  while (iActual < actualFieldList.size() && iFormal < formalFieldTypes.size()) {
145  ExtensionFunction.ExtArgumentType extType = formalFieldTypes.get(iFormal);
146  SqlTypeName formalType = ExtensionFunction.toSqlTypeName(extType);
147  SqlTypeName actualType = actualFieldList.get(iActual).getValue().getSqlTypeName();
148 
149  if (formalType == SqlTypeName.COLUMN_LIST) {
150  ExtensionFunction.ExtArgumentType colListSubtype =
151  ExtensionFunction.getValueType(extType);
152  SqlTypeName colListType = ExtensionFunction.toSqlTypeName(colListSubtype);
153 
154  if (actualType != colListType) {
155  return false;
156  }
157 
158  int colListSize = 0;
159  int numFormalArgumentsLeft = (formalFieldTypes.size() - 1) - iFormal;
160  while (iActual + colListSize
161  < (actualFieldList.size() - numFormalArgumentsLeft)) {
162  actualType =
163  actualFieldList.get(iActual + colListSize).getValue().getSqlTypeName();
164  if (actualType != colListType) {
165  break;
166  }
167  colListSize++;
168  }
169  iActual += colListSize - 1;
170  } else if (formalType != actualType) {
171  return false;
172  }
173  iFormal++;
174  iActual++;
175  }
176 
177  if (iActual < actualFieldList.size()) {
178  return false;
179  }
180 
181  return true;
182  }

+ Here is the caller graph for this function:

boolean com.mapd.calcite.parser.ExtTableFunctionTypeChecker.doesOperandTypeMatch ( ExtTableFunction  tf,
SqlCallBinding  callBinding,
SqlNode  node,
int  iFormalOperand 
)
inline

Definition at line 46 of file ExtTableFunctionTypeChecker.java.

References shared.contains(), com.mapd.calcite.parser.ExtTableFunctionTypeChecker.doesCursorOperandTypeMatch(), run_benchmark_import.type, and typeName().

Referenced by com.mapd.calcite.parser.ExtTableFunctionTypeChecker.checkOperandTypes().

49  {
50  SqlCall permutedCall = callBinding.permutedCall();
51  SqlNode permutedOperand = permutedCall.operand(iFormalOperand);
52  RelDataType type;
53 
54  // For candidate calls to incompatible operators, type inference of operands may fail.
55  // In that case, we just catch the exception and invalidade the candidate.
56  try {
57  type = callBinding.getValidator().deriveType(
58  callBinding.getScope(), permutedOperand);
59  } catch (Exception e) {
60  return false;
61  }
62  SqlTypeName typeName = type.getSqlTypeName();
63 
64  if (typeName == SqlTypeName.CURSOR) {
65  SqlCall cursorCall = (SqlCall) permutedOperand;
66  RelDataType cursorType = callBinding.getValidator().deriveType(
67  callBinding.getScope(), cursorCall.operand(0));
68  return doesCursorOperandTypeMatch(tf, iFormalOperand, cursorType);
69  } else {
70  return tf.getArgTypes().get(iFormalOperand).getTypeNames().contains(typeName);
71  }
72  }
bool contains(const T &container, const U &element)
Definition: misc.h:195
boolean doesCursorOperandTypeMatch(ExtTableFunction tf, int iFormalOperand, RelDataType actualOperand)
std::string typeName(const T *v)
Definition: toString.h:103

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

String com.mapd.calcite.parser.ExtTableFunctionTypeChecker.getAllowedSignatures ( SqlOperator  op,
String  opName 
)
inline

Definition at line 202 of file ExtTableFunctionTypeChecker.java.

References com.mapd.calcite.parser.ExtTableFunctionTypeChecker.getOperatorOverloads().

202  {
203  List<ExtTableFunction> overloads = getOperatorOverloads(op);
204  return String.join(System.lineSeparator() + "\t",
205  overloads.stream()
206  .map(tf -> tf.getExtendedSignature())
207  .collect(Collectors.toList()));
208  }
List< ExtTableFunction > getOperatorOverloads(SqlOperator op)

+ Here is the call graph for this function:

Consistency com.mapd.calcite.parser.ExtTableFunctionTypeChecker.getConsistency ( )
inline

Definition at line 210 of file ExtTableFunctionTypeChecker.java.

210  {
211  return Consistency.NONE;
212  }
SqlOperandCountRange com.mapd.calcite.parser.ExtTableFunctionTypeChecker.getOperandCountRange ( )
inline

Definition at line 198 of file ExtTableFunctionTypeChecker.java.

198  {
199  return SqlOperandCountRanges.any();
200  }
List<ExtTableFunction> com.mapd.calcite.parser.ExtTableFunctionTypeChecker.getOperatorOverloads ( SqlOperator  op)
inline

Definition at line 184 of file ExtTableFunctionTypeChecker.java.

Referenced by com.mapd.calcite.parser.ExtTableFunctionTypeChecker.checkOperandTypes(), and com.mapd.calcite.parser.ExtTableFunctionTypeChecker.getAllowedSignatures().

184  {
185  List<SqlOperator> overloads = new ArrayList<>();
186  opTable.lookupOperatorOverloads(op.getNameAsId(),
187  SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION,
188  SqlSyntax.FUNCTION,
189  overloads,
190  SqlNameMatchers.liberal());
191 
192  return overloads.stream()
193  .filter(p -> p instanceof ExtTableFunction)
194  .map(p -> (ExtTableFunction) p)
195  .collect(Collectors.toList());
196  }

+ Here is the caller graph for this function:

boolean com.mapd.calcite.parser.ExtTableFunctionTypeChecker.isOptional ( int  argIndex)
inline

Definition at line 37 of file ExtTableFunctionTypeChecker.java.

37  {
38  // We need to mark all arguments as optional, otherwise Calcite may invalidate some
39  // valid calls during the validation process. This is because if it previously bound
40  // the call to a UDTF operator that receives more arguments, it fills up the missing
41  // arguments with DEFAULTs. DEFAULT arguments however will not get to the typechecking
42  // stage if they are not optional for that oeprator.
43  return true;
44  }

Member Data Documentation

final HeavyDBSqlOperatorTable com.mapd.calcite.parser.ExtTableFunctionTypeChecker.opTable
package

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