use of com.hazelcast.sql.impl.ParameterConverter in project hazelcast by hazelcast.
the class PlanExecutor method prepareArguments.
private List<Object> prepareArguments(QueryParameterMetadata parameterMetadata, List<Object> arguments) {
assert arguments != null;
int parameterCount = parameterMetadata.getParameterCount();
if (parameterCount != arguments.size()) {
throw QueryException.error(SqlErrorCode.DATA_EXCEPTION, "Unexpected parameter count: expected " + parameterCount + ", got " + arguments.size());
}
for (int i = 0; i < arguments.size(); ++i) {
Object value = arguments.get(i);
ParameterConverter parameterConverter = parameterMetadata.getParameterConverter(i);
Object newValue = parameterConverter.convert(value);
if (newValue != value) {
arguments.set(i, newValue);
}
}
return arguments;
}
use of com.hazelcast.sql.impl.ParameterConverter in project hazelcast by hazelcast.
the class AbstractOperandChecker method validateDynamicParam.
private void validateDynamicParam(SqlDynamicParam operand, HazelcastSqlValidator validator) {
// Set parameter type
RelDataType type = getTargetType(validator.getTypeFactory(), true);
validator.setValidatedNodeType(operand, type);
// Set parameter converter
ParameterConverter converter = parameterConverter(operand);
validator.setParameterConverter(operand.getIndex(), converter);
}
use of com.hazelcast.sql.impl.ParameterConverter in project hazelcast by hazelcast.
the class HazelcastBetweenOperator method setNumericParameterConverter.
private void setNumericParameterConverter(HazelcastSqlValidator validator, SqlNode node, QueryDataType type) {
if (node.getKind() == SqlKind.DYNAMIC_PARAM) {
SqlDynamicParam node0 = (SqlDynamicParam) node;
ParameterConverter converter = new NumericPrecedenceParameterConverter(node0.getIndex(), node.getParserPosition(), type);
validator.setParameterConverter(node0.getIndex(), converter);
}
}
use of com.hazelcast.sql.impl.ParameterConverter in project hazelcast by hazelcast.
the class OptimizerTestSupport method context.
private static OptimizerContext context(HazelcastSchema schema, QueryDataType... parameterTypes) {
OptimizerContext context = OptimizerContext.create(HazelcastSchemaUtils.createCatalog(schema), QueryUtils.prepareSearchPaths(null, null), emptyList(), 1, name -> null);
ParameterConverter[] parameterConverters = IntStream.range(0, parameterTypes.length).mapToObj(i -> new StrictParameterConverter(i, SqlParserPos.ZERO, parameterTypes[i])).toArray(ParameterConverter[]::new);
QueryParameterMetadata parameterMetadata = new QueryParameterMetadata(parameterConverters);
context.setParameterMetadata(parameterMetadata);
return context;
}
use of com.hazelcast.sql.impl.ParameterConverter 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;
}
Aggregations