use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class RexUtil method compatibleTypes.
/**
* Returns whether the type of an array of expressions is compatible with a
* struct type.
*
* @param exprs Array of expressions
* @param type Type
* @param litmus What to do if an error is detected (there is a mismatch)
*
* @return Whether every expression has the same type as the corresponding
* member of the struct type
*
* @see RelOptUtil#eq(String, RelDataType, String, RelDataType, org.apache.calcite.util.Litmus)
*/
public static boolean compatibleTypes(List<RexNode> exprs, RelDataType type, Litmus litmus) {
final List<RelDataTypeField> fields = type.getFieldList();
if (exprs.size() != fields.size()) {
return litmus.fail("rowtype mismatches expressions");
}
for (int i = 0; i < fields.size(); i++) {
final RelDataType exprType = exprs.get(i).getType();
final RelDataType fieldType = fields.get(i).getType();
if (!RelOptUtil.eq("type1", exprType, "type2", fieldType, litmus)) {
return litmus.fail(null);
}
}
return litmus.succeed();
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class SqlItemOperator method checkOperandTypes.
@Override
public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
final SqlNode left = callBinding.operand(0);
final SqlNode right = callBinding.operand(1);
if (!ARRAY_OR_MAP.checkSingleOperandType(callBinding, left, 0, throwOnFailure)) {
return false;
}
final RelDataType operandType = callBinding.getOperandType(0);
final SqlSingleOperandTypeChecker checker = getChecker(operandType);
return checker.checkSingleOperandType(callBinding, right, 0, throwOnFailure);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class SqlLiteralChainOperator method inferReturnType.
// Result type is the same as all the args, but its size is the
// total size.
// REVIEW mb 8/8/04: Possibly this can be achieved by combining
// the strategy useFirstArgType with a new transformer.
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
// Here we know all the operands have the same type,
// which has a size (precision), but not a scale.
RelDataType ret = opBinding.getOperandType(0);
SqlTypeName typeName = ret.getSqlTypeName();
assert typeName.allowsPrecNoScale() : "LiteralChain has impossible operand type " + typeName;
int size = 0;
for (RelDataType type : opBinding.collectOperandTypes()) {
size += type.getPrecision();
assert type.getSqlTypeName() == typeName;
}
return opBinding.getTypeFactory().createSqlType(typeName, size);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class SqlMultisetQueryConstructor method checkOperandTypes.
public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
final List<RelDataType> argTypes = SqlTypeUtil.deriveAndCollectTypes(callBinding.getValidator(), callBinding.getScope(), callBinding.operands());
final RelDataType componentType = getComponentType(callBinding.getTypeFactory(), argTypes);
if (null == componentType) {
if (throwOnFailure) {
throw callBinding.newValidationError(RESOURCE.needSameTypeParameter());
}
return false;
}
return true;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class SqlCastFunction method checkOperandTypes.
/**
* 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.
*/
public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
final SqlNode left = callBinding.operand(0);
final SqlNode right = callBinding.operand(1);
if (SqlUtil.isNullLiteral(left, false) || left instanceof SqlDynamicParam) {
return true;
}
RelDataType validatedNodeType = callBinding.getValidator().getValidatedNodeType(left);
RelDataType returnType = callBinding.getValidator().deriveType(callBinding.getScope(), right);
if (!SqlTypeUtil.canCastFrom(returnType, validatedNodeType, true)) {
if (throwOnFailure) {
throw callBinding.newError(RESOURCE.cannotCastValue(validatedNodeType.toString(), returnType.toString()));
}
return false;
}
if (SqlTypeUtil.areCharacterSetsMismatched(validatedNodeType, returnType)) {
if (throwOnFailure) {
// set mismatch.
throw callBinding.newError(RESOURCE.cannotCastValue(validatedNodeType.getFullTypeString(), returnType.getFullTypeString()));
}
return false;
}
return true;
}
Aggregations