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

Constructor & Destructor Documentation

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

Definition at line 1545 of file HeavyDBSqlOperatorTable.java.

1545  {
1546  super("TRY_CAST",
1547  SqlKind.OTHER_FUNCTION,
1548  null,
1549  InferTypes.FIRST_KNOWN,
1550  null,
1551  SqlFunctionCategory.SYSTEM);
1552  }

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

1593  {
1594  final SqlNode left = callBinding.operand(0);
1595  final SqlNode right = callBinding.operand(1);
1596  if (SqlUtil.isNullLiteral(left, false) || left instanceof SqlDynamicParam) {
1597  return true;
1598  }
1599  RelDataType validatedNodeType =
1600  callBinding.getValidator().getValidatedNodeType(left);
1601  RelDataType returnType =
1602  callBinding.getValidator().deriveType(callBinding.getScope(), right);
1603  if (!SqlTypeUtil.canCastFrom(returnType, validatedNodeType, true)) {
1604  if (throwOnFailure) {
1605  throw callBinding.newError(RESOURCE.cannotCastValue(
1606  validatedNodeType.toString(), returnType.toString()));
1607  }
1608  return false;
1609  }
1610  if (SqlTypeUtil.areCharacterSetsMismatched(validatedNodeType, returnType)) {
1611  if (throwOnFailure) {
1612  // Include full type string to indicate character
1613  // set mismatch.
1614  throw callBinding.newError(RESOURCE.cannotCastValue(
1615  validatedNodeType.getFullTypeString(), returnType.getFullTypeString()));
1616  }
1617  return false;
1618  }
1619  return true;
1620  }
SqlOperandCountRange com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TryCast.getOperandCountRange ( )
inline

Definition at line 1584 of file HeavyDBSqlOperatorTable.java.

1584  {
1585  return SqlOperandCountRanges.of(2);
1586  }
String com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TryCast.getSignatureTemplate ( final int  operandsCount)
inline

Definition at line 1579 of file HeavyDBSqlOperatorTable.java.

1579  {
1580  assert operandsCount == 2;
1581  return "{0}({1} AS {2})";
1582  }
SqlSyntax com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TryCast.getSyntax ( )
inline

Definition at line 1622 of file HeavyDBSqlOperatorTable.java.

1622  {
1623  return SqlSyntax.FUNCTION;
1624  }
RelDataType com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TryCast.inferReturnType ( SqlOperatorBinding  opBinding)
inline

Definition at line 1556 of file HeavyDBSqlOperatorTable.java.

1556  {
1557  assert opBinding.getOperandCount() == 2;
1558  RelDataType ret = opBinding.getOperandType(1);
1559  RelDataType firstType = opBinding.getOperandType(0);
1560  ret = opBinding.getTypeFactory().createTypeWithNullability(
1561  ret, firstType.isNullable());
1562  if (opBinding instanceof SqlCallBinding) {
1563  SqlCallBinding callBinding = (SqlCallBinding) opBinding;
1564  SqlNode operand0 = callBinding.operand(0);
1565 
1566  // dynamic parameters and null constants need their types assigned
1567  // to them using the type they are casted to.
1568  if (((operand0 instanceof SqlLiteral)
1569  && (((SqlLiteral) operand0).getValue() == null))
1570  || (operand0 instanceof SqlDynamicParam)) {
1571  final SqlValidatorImpl validator =
1572  (SqlValidatorImpl) callBinding.getValidator();
1573  validator.setValidatedNodeType(operand0, ret);
1574  }
1575  }
1576  return ret;
1577  }
void com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TryCast.unparse ( SqlWriter  writer,
SqlCall  call,
int  leftPrec,
int  rightPrec 
)
inline

Definition at line 1626 of file HeavyDBSqlOperatorTable.java.

1626  {
1627  assert call.operandCount() == 2;
1628  final SqlWriter.Frame frame = writer.startFunCall(getName());
1629  call.operand(0).unparse(writer, 0, 0);
1630  writer.sep("AS");
1631  if (call.operand(1) instanceof SqlIntervalQualifier) {
1632  writer.sep("INTERVAL");
1633  }
1634  call.operand(1).unparse(writer, 0, 0);
1635  writer.endFunCall(frame);
1636  }
void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec)

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