OmniSciDB  c1a53651b2
 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 1300 of file HeavyDBSqlOperatorTable.java.

Constructor & Destructor Documentation

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

Definition at line 1303 of file HeavyDBSqlOperatorTable.java.

1303  {
1304  super("TRY_CAST",
1305  SqlKind.OTHER_FUNCTION,
1306  null,
1307  InferTypes.FIRST_KNOWN,
1308  null,
1309  SqlFunctionCategory.SYSTEM);
1310  }

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 1351 of file HeavyDBSqlOperatorTable.java.

1351  {
1352  final SqlNode left = callBinding.operand(0);
1353  final SqlNode right = callBinding.operand(1);
1354  if (SqlUtil.isNullLiteral(left, false) || left instanceof SqlDynamicParam) {
1355  return true;
1356  }
1357  RelDataType validatedNodeType =
1358  callBinding.getValidator().getValidatedNodeType(left);
1359  RelDataType returnType =
1360  callBinding.getValidator().deriveType(callBinding.getScope(), right);
1361  if (!SqlTypeUtil.canCastFrom(returnType, validatedNodeType, true)) {
1362  if (throwOnFailure) {
1363  throw callBinding.newError(RESOURCE.cannotCastValue(
1364  validatedNodeType.toString(), returnType.toString()));
1365  }
1366  return false;
1367  }
1368  if (SqlTypeUtil.areCharacterSetsMismatched(validatedNodeType, returnType)) {
1369  if (throwOnFailure) {
1370  // Include full type string to indicate character
1371  // set mismatch.
1372  throw callBinding.newError(RESOURCE.cannotCastValue(
1373  validatedNodeType.getFullTypeString(), returnType.getFullTypeString()));
1374  }
1375  return false;
1376  }
1377  return true;
1378  }
SqlOperandCountRange com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TryCast.getOperandCountRange ( )
inline

Definition at line 1342 of file HeavyDBSqlOperatorTable.java.

1342  {
1343  return SqlOperandCountRanges.of(2);
1344  }
String com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TryCast.getSignatureTemplate ( final int  operandsCount)
inline

Definition at line 1337 of file HeavyDBSqlOperatorTable.java.

1337  {
1338  assert operandsCount == 2;
1339  return "{0}({1} AS {2})";
1340  }
SqlSyntax com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TryCast.getSyntax ( )
inline

Definition at line 1380 of file HeavyDBSqlOperatorTable.java.

1380  {
1381  return SqlSyntax.FUNCTION;
1382  }
RelDataType com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TryCast.inferReturnType ( SqlOperatorBinding  opBinding)
inline

Definition at line 1314 of file HeavyDBSqlOperatorTable.java.

1314  {
1315  assert opBinding.getOperandCount() == 2;
1316  RelDataType ret = opBinding.getOperandType(1);
1317  RelDataType firstType = opBinding.getOperandType(0);
1318  ret = opBinding.getTypeFactory().createTypeWithNullability(
1319  ret, firstType.isNullable());
1320  if (opBinding instanceof SqlCallBinding) {
1321  SqlCallBinding callBinding = (SqlCallBinding) opBinding;
1322  SqlNode operand0 = callBinding.operand(0);
1323 
1324  // dynamic parameters and null constants need their types assigned
1325  // to them using the type they are casted to.
1326  if (((operand0 instanceof SqlLiteral)
1327  && (((SqlLiteral) operand0).getValue() == null))
1328  || (operand0 instanceof SqlDynamicParam)) {
1329  final SqlValidatorImpl validator =
1330  (SqlValidatorImpl) callBinding.getValidator();
1331  validator.setValidatedNodeType(operand0, ret);
1332  }
1333  }
1334  return ret;
1335  }
void com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TryCast.unparse ( SqlWriter  writer,
SqlCall  call,
int  leftPrec,
int  rightPrec 
)
inline

Definition at line 1384 of file HeavyDBSqlOperatorTable.java.

1384  {
1385  assert call.operandCount() == 2;
1386  final SqlWriter.Frame frame = writer.startFunCall(getName());
1387  call.operand(0).unparse(writer, 0, 0);
1388  writer.sep("AS");
1389  if (call.operand(1) instanceof SqlIntervalQualifier) {
1390  writer.sep("INTERVAL");
1391  }
1392  call.operand(1).unparse(writer, 0, 0);
1393  writer.endFunCall(frame);
1394  }
void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec)

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