OmniSciDB  a5dc49c757
 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 1654 of file HeavyDBSqlOperatorTable.java.

Constructor & Destructor Documentation

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

Definition at line 1657 of file HeavyDBSqlOperatorTable.java.

1657  {
1658  super("TRY_CAST",
1659  SqlKind.OTHER_FUNCTION,
1660  null,
1661  InferTypes.FIRST_KNOWN,
1662  null,
1663  SqlFunctionCategory.SYSTEM);
1664  }

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

1705  {
1706  final SqlNode left = callBinding.operand(0);
1707  final SqlNode right = callBinding.operand(1);
1708  if (SqlUtil.isNullLiteral(left, false) || left instanceof SqlDynamicParam) {
1709  return true;
1710  }
1711  RelDataType validatedNodeType =
1712  callBinding.getValidator().getValidatedNodeType(left);
1713  RelDataType returnType =
1714  callBinding.getValidator().deriveType(callBinding.getScope(), right);
1715  if (!SqlTypeUtil.canCastFrom(returnType, validatedNodeType, true)) {
1716  if (throwOnFailure) {
1717  throw callBinding.newError(RESOURCE.cannotCastValue(
1718  validatedNodeType.toString(), returnType.toString()));
1719  }
1720  return false;
1721  }
1722  if (SqlTypeUtil.areCharacterSetsMismatched(validatedNodeType, returnType)) {
1723  if (throwOnFailure) {
1724  // Include full type string to indicate character
1725  // set mismatch.
1726  throw callBinding.newError(RESOURCE.cannotCastValue(
1727  validatedNodeType.getFullTypeString(), returnType.getFullTypeString()));
1728  }
1729  return false;
1730  }
1731  return true;
1732  }
SqlOperandCountRange com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TryCast.getOperandCountRange ( )
inline

Definition at line 1696 of file HeavyDBSqlOperatorTable.java.

1696  {
1697  return SqlOperandCountRanges.of(2);
1698  }
String com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TryCast.getSignatureTemplate ( final int  operandsCount)
inline

Definition at line 1691 of file HeavyDBSqlOperatorTable.java.

1691  {
1692  assert operandsCount == 2;
1693  return "{0}({1} AS {2})";
1694  }
SqlSyntax com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TryCast.getSyntax ( )
inline

Definition at line 1734 of file HeavyDBSqlOperatorTable.java.

1734  {
1735  return SqlSyntax.FUNCTION;
1736  }
RelDataType com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TryCast.inferReturnType ( SqlOperatorBinding  opBinding)
inline

Definition at line 1668 of file HeavyDBSqlOperatorTable.java.

1668  {
1669  assert opBinding.getOperandCount() == 2;
1670  RelDataType ret = opBinding.getOperandType(1);
1671  RelDataType firstType = opBinding.getOperandType(0);
1672  ret = opBinding.getTypeFactory().createTypeWithNullability(
1673  ret, firstType.isNullable());
1674  if (opBinding instanceof SqlCallBinding) {
1675  SqlCallBinding callBinding = (SqlCallBinding) opBinding;
1676  SqlNode operand0 = callBinding.operand(0);
1677 
1678  // dynamic parameters and null constants need their types assigned
1679  // to them using the type they are casted to.
1680  if (((operand0 instanceof SqlLiteral)
1681  && (((SqlLiteral) operand0).getValue() == null))
1682  || (operand0 instanceof SqlDynamicParam)) {
1683  final SqlValidatorImpl validator =
1684  (SqlValidatorImpl) callBinding.getValidator();
1685  validator.setValidatedNodeType(operand0, ret);
1686  }
1687  }
1688  return ret;
1689  }
void com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TryCast.unparse ( SqlWriter  writer,
SqlCall  call,
int  leftPrec,
int  rightPrec 
)
inline

Definition at line 1738 of file HeavyDBSqlOperatorTable.java.

1738  {
1739  assert call.operandCount() == 2;
1740  final SqlWriter.Frame frame = writer.startFunCall(getName());
1741  call.operand(0).unparse(writer, 0, 0);
1742  writer.sep("AS");
1743  if (call.operand(1) instanceof SqlIntervalQualifier) {
1744  writer.sep("INTERVAL");
1745  }
1746  call.operand(1).unparse(writer, 0, 0);
1747  writer.endFunCall(frame);
1748  }
void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec)

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