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 inferReturnType.
// ~ Methods ----------------------------------------------------------------
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
assert opBinding.getOperandCount() == 2;
RelDataType ret = opBinding.getOperandType(1);
RelDataType firstType = opBinding.getOperandType(0);
ret = opBinding.getTypeFactory().createTypeWithNullability(ret, firstType.isNullable());
if (opBinding instanceof SqlCallBinding) {
SqlCallBinding callBinding = (SqlCallBinding) opBinding;
SqlNode operand0 = callBinding.operand(0);
// to them using the type they are casted to.
if (((operand0 instanceof SqlLiteral) && (((SqlLiteral) operand0).getValue() == null)) || (operand0 instanceof SqlDynamicParam)) {
final SqlValidatorImpl validator = (SqlValidatorImpl) callBinding.getValidator();
validator.setValidatedNodeType(operand0, ret);
}
}
return ret;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class SqlMultisetValueConstructor method checkOperandTypes.
public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
final List<RelDataType> argTypes = SqlTypeUtil.deriveAndCollectTypes(callBinding.getValidator(), callBinding.getScope(), callBinding.operands());
if (argTypes.size() == 0) {
throw callBinding.newValidationError(RESOURCE.requireAtLeastOneArg());
}
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 SqlOverlapsOperator method checkOperandTypes.
public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
if (!OperandTypes.PERIOD.checkSingleOperandType(callBinding, callBinding.operand(0), 0, throwOnFailure)) {
return false;
}
final SqlSingleOperandTypeChecker rightChecker;
switch(kind) {
case CONTAINS:
rightChecker = OperandTypes.PERIOD_OR_DATETIME;
break;
default:
rightChecker = OperandTypes.PERIOD;
break;
}
if (!rightChecker.checkSingleOperandType(callBinding, callBinding.operand(1), 0, throwOnFailure)) {
return false;
}
final RelDataType t0 = callBinding.getOperandType(0);
final RelDataType t1 = callBinding.getOperandType(1);
if (!SqlTypeUtil.isDatetime(t1)) {
final RelDataType t00 = t0.getFieldList().get(0).getType();
final RelDataType t10 = t1.getFieldList().get(0).getType();
if (!SqlTypeUtil.sameNamedType(t00, t10)) {
if (throwOnFailure) {
throw callBinding.newValidationSignatureError();
}
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 SqlDatetimePlusOperator method inferReturnType.
// ~ Methods ----------------------------------------------------------------
@Override
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
final RelDataType leftType = opBinding.getOperandType(0);
final IntervalSqlType unitType = (IntervalSqlType) opBinding.getOperandType(1);
switch(unitType.getIntervalQualifier().getStartUnit()) {
case HOUR:
case MINUTE:
case SECOND:
case MILLISECOND:
case MICROSECOND:
return typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIMESTAMP), leftType.isNullable() || unitType.isNullable());
default:
return leftType;
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class SqlDotOperator method deriveType.
@Override
public RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call) {
RelDataType nodeType = validator.deriveType(scope, call.getOperandList().get(0));
assert nodeType != null;
final String fieldName = call.getOperandList().get(1).toString();
RelDataTypeField field = nodeType.getField(fieldName, false, false);
if (field == null) {
throw SqlUtil.newContextException(SqlParserPos.ZERO, Static.RESOURCE.unknownField(fieldName));
}
RelDataType type = field.getType();
// Validate and determine coercibility and resulting collation
// name of binary operator if needed.
type = adjustType(validator, call, type);
SqlValidatorUtil.checkCharsetAndCollateConsistentIfCharType(type);
return type;
}
Aggregations