use of com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator in project hazelcast by hazelcast.
the class HazelcastConcatOperator method checkOperandTypes.
@Override
public boolean checkOperandTypes(HazelcastCallBinding binding, boolean throwOnFailure) {
HazelcastSqlValidator validator = binding.getValidator();
for (int i = 0; i < binding.getOperandCount(); i++) {
SqlNode operand = binding.operand(i);
RelDataType operandType = binding.getOperandType(i);
if (operandType.getSqlTypeName() != VARCHAR) {
// Coerce everything to VARCHAR
RelDataType newOperandType = HazelcastTypeUtils.createType(validator.getTypeFactory(), VARCHAR, operandType.isNullable());
validator.getTypeCoercion().coerceOperandType(binding.getScope(), binding.getCall(), i, newOperandType);
}
// Set parameter converters
if (operand.getKind() == SqlKind.DYNAMIC_PARAM) {
int paramIndex = ((SqlDynamicParam) operand).getIndex();
ParameterConverter paramConverter = new AnyToVarcharParameterConverter(paramIndex, operand.getParserPosition());
validator.setParameterConverter(paramIndex, paramConverter);
}
}
return true;
}
use of com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator in project hazelcast by hazelcast.
the class HazelcastConcatWSOperator method checkOperandTypes.
@Override
public boolean checkOperandTypes(HazelcastCallBinding binding, boolean throwOnFailure) {
HazelcastSqlValidator validator = binding.getValidator();
if (binding.getOperandType(0).getSqlTypeName() != VARCHAR) {
if (throwOnFailure) {
throw binding.newValidationSignatureError();
}
return false;
}
for (int i = 1; i < binding.getOperandCount(); i++) {
SqlNode operand = binding.operand(i);
RelDataType operandType = binding.getOperandType(i);
if (operandType.getSqlTypeName() != VARCHAR) {
// Coerce everything to VARCHAR
RelDataType newOperandType = HazelcastTypeUtils.createType(validator.getTypeFactory(), VARCHAR, operandType.isNullable());
validator.getTypeCoercion().coerceOperandType(binding.getScope(), binding.getCall(), i, newOperandType);
}
// Set parameter converters
if (operand.getKind() == SqlKind.DYNAMIC_PARAM) {
int paramIndex = ((SqlDynamicParam) operand).getIndex();
ParameterConverter paramConverter = new AnyToVarcharParameterConverter(paramIndex, operand.getParserPosition());
validator.setParameterConverter(paramIndex, paramConverter);
}
}
return true;
}
use of com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator in project hazelcast by hazelcast.
the class HazelcastDynamicTableFunction method toArguments.
private static List<Object> toArguments(String functionName, List<HazelcastTableFunctionParameter> parameters, SqlOperatorBinding callBinding) {
SqlCallBinding binding = (SqlCallBinding) callBinding;
SqlCall call = binding.getCall();
HazelcastSqlValidator validator = (HazelcastSqlValidator) binding.getValidator();
return ValidationUtil.hasAssignment(call) ? fromNamedArguments(functionName, parameters, call, validator) : fromPositionalArguments(functionName, parameters, call, validator);
}
use of com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator in project hazelcast by hazelcast.
the class HazelcastBetweenOperator method checkOperandTypes.
@Override
protected boolean checkOperandTypes(HazelcastCallBinding callBinding, boolean throwOnFailure) {
assert callBinding.getOperandCount() == OPERANDS;
for (int i = 0; i < OPERANDS; ++i) {
RelDataType type = callBinding.getOperandType(i);
// fast fail-forward path.
if (type.getComparability().ordinal() < RelDataTypeComparability.ALL.ordinal()) {
if (throwOnFailure) {
throw callBinding.newValidationSignatureError();
} else {
return false;
}
}
}
HazelcastSqlValidator validator = callBinding.getValidator();
RelDataType winningType = withHigherPrecedence(callBinding.getOperandType(0), withHigherPrecedence(callBinding.getOperandType(1), callBinding.getOperandType(2)));
QueryDataType winnerQueryDataType = toHazelcastType(winningType);
// Set more flexible parameter converter that allows TINYINT/SMALLINT/INTEGER -> BIGINT conversions.
if (winnerQueryDataType.getTypeFamily().isNumeric()) {
setNumericParameterConverter(validator, callBinding.getCall().getOperandList().get(1), winnerQueryDataType);
setNumericParameterConverter(validator, callBinding.getCall().getOperandList().get(2), winnerQueryDataType);
}
return true;
}
use of com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator in project hazelcast by hazelcast.
the class HazelcastComparisonPredicateUtils method checkOperandTypes.
public static boolean checkOperandTypes(HazelcastCallBinding binding, boolean throwOnFailure) {
SqlNode first = binding.operand(0);
SqlNode second = binding.operand(1);
HazelcastSqlValidator validator = binding.getValidator();
RelDataType firstType = validator.deriveType(binding.getScope(), first);
RelDataType secondType = validator.deriveType(binding.getScope(), second);
assert !firstType.equals(validator.getUnknownType());
assert !secondType.equals(validator.getUnknownType());
return checkOperandTypes(binding, throwOnFailure, validator, first, firstType, second, secondType);
}
Aggregations