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

Public Member Functions

 TryCast ()
 
RelDataType inferReturnType (SqlOperatorBinding opBinding)
 
String getSignatureTemplate (final int operandsCount)
 
SqlOperandCountRange getOperandCountRange ()
 
boolean checkOperandTypes (SqlCallBinding callBinding, boolean throwOnFailure)
 
SqlSyntax getSyntax ()
 
void unparse (SqlWriter writer, SqlCall call, int leftPrec, int rightPrec)
 

Detailed Description

Definition at line 1286 of file HeavyDBSqlOperatorTable.java.

Constructor & Destructor Documentation

com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TryCast.TryCast ( )
inline

Definition at line 1289 of file HeavyDBSqlOperatorTable.java.

1289  {
1290  super("TRY_CAST",
1291  SqlKind.OTHER_FUNCTION,
1292  null,
1293  InferTypes.FIRST_KNOWN,
1294  null,
1295  SqlFunctionCategory.SYSTEM);
1296  }

Member Function Documentation

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

Makes sure that the number and types of arguments are allowable. Operators (such as "ROW" and "AS") which do not check their arguments can override this method.

Definition at line 1337 of file HeavyDBSqlOperatorTable.java.

1337  {
1338  final SqlNode left = callBinding.operand(0);
1339  final SqlNode right = callBinding.operand(1);
1340  if (SqlUtil.isNullLiteral(left, false) || left instanceof SqlDynamicParam) {
1341  return true;
1342  }
1343  RelDataType validatedNodeType =
1344  callBinding.getValidator().getValidatedNodeType(left);
1345  RelDataType returnType =
1346  callBinding.getValidator().deriveType(callBinding.getScope(), right);
1347  if (!SqlTypeUtil.canCastFrom(returnType, validatedNodeType, true)) {
1348  if (throwOnFailure) {
1349  throw callBinding.newError(RESOURCE.cannotCastValue(
1350  validatedNodeType.toString(), returnType.toString()));
1351  }
1352  return false;
1353  }
1354  if (SqlTypeUtil.areCharacterSetsMismatched(validatedNodeType, returnType)) {
1355  if (throwOnFailure) {
1356  // Include full type string to indicate character
1357  // set mismatch.
1358  throw callBinding.newError(RESOURCE.cannotCastValue(
1359  validatedNodeType.getFullTypeString(), returnType.getFullTypeString()));
1360  }
1361  return false;
1362  }
1363  return true;
1364  }
SqlOperandCountRange com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TryCast.getOperandCountRange ( )
inline

Definition at line 1328 of file HeavyDBSqlOperatorTable.java.

1328  {
1329  return SqlOperandCountRanges.of(2);
1330  }
String com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TryCast.getSignatureTemplate ( final int  operandsCount)
inline

Definition at line 1323 of file HeavyDBSqlOperatorTable.java.

1323  {
1324  assert operandsCount == 2;
1325  return "{0}({1} AS {2})";
1326  }
SqlSyntax com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TryCast.getSyntax ( )
inline

Definition at line 1366 of file HeavyDBSqlOperatorTable.java.

1366  {
1367  return SqlSyntax.FUNCTION;
1368  }
RelDataType com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TryCast.inferReturnType ( SqlOperatorBinding  opBinding)
inline

Definition at line 1300 of file HeavyDBSqlOperatorTable.java.

1300  {
1301  assert opBinding.getOperandCount() == 2;
1302  RelDataType ret = opBinding.getOperandType(1);
1303  RelDataType firstType = opBinding.getOperandType(0);
1304  ret = opBinding.getTypeFactory().createTypeWithNullability(
1305  ret, firstType.isNullable());
1306  if (opBinding instanceof SqlCallBinding) {
1307  SqlCallBinding callBinding = (SqlCallBinding) opBinding;
1308  SqlNode operand0 = callBinding.operand(0);
1309 
1310  // dynamic parameters and null constants need their types assigned
1311  // to them using the type they are casted to.
1312  if (((operand0 instanceof SqlLiteral)
1313  && (((SqlLiteral) operand0).getValue() == null))
1314  || (operand0 instanceof SqlDynamicParam)) {
1315  final SqlValidatorImpl validator =
1316  (SqlValidatorImpl) callBinding.getValidator();
1317  validator.setValidatedNodeType(operand0, ret);
1318  }
1319  }
1320  return ret;
1321  }
void com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TryCast.unparse ( SqlWriter  writer,
SqlCall  call,
int  leftPrec,
int  rightPrec 
)
inline

Definition at line 1370 of file HeavyDBSqlOperatorTable.java.

1370  {
1371  assert call.operandCount() == 2;
1372  final SqlWriter.Frame frame = writer.startFunCall(getName());
1373  call.operand(0).unparse(writer, 0, 0);
1374  writer.sep("AS");
1375  if (call.operand(1) instanceof SqlIntervalQualifier) {
1376  writer.sep("INTERVAL");
1377  }
1378  call.operand(1).unparse(writer, 0, 0);
1379  writer.endFunCall(frame);
1380  }
void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec)

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