Search in sources :

Example 1 with ParameterConverter

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;
}
Also used : ParameterConverter(com.hazelcast.sql.impl.ParameterConverter)

Example 2 with ParameterConverter

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);
}
Also used : ParameterConverter(com.hazelcast.sql.impl.ParameterConverter) RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 3 with ParameterConverter

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);
    }
}
Also used : SqlDynamicParam(org.apache.calcite.sql.SqlDynamicParam) NumericPrecedenceParameterConverter(com.hazelcast.jet.sql.impl.validate.param.NumericPrecedenceParameterConverter) ParameterConverter(com.hazelcast.sql.impl.ParameterConverter) NumericPrecedenceParameterConverter(com.hazelcast.jet.sql.impl.validate.param.NumericPrecedenceParameterConverter)

Example 4 with ParameterConverter

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;
}
Also used : IntStream(java.util.stream.IntStream) OptimizerContext(com.hazelcast.jet.sql.impl.OptimizerContext) LogicalRules(com.hazelcast.jet.sql.impl.opt.logical.LogicalRules) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) PhysicalRules(com.hazelcast.jet.sql.impl.opt.physical.PhysicalRules) SCHEMA_NAME_PUBLIC(com.hazelcast.jet.sql.impl.schema.TableResolverImpl.SCHEMA_NAME_PUBLIC) RelOptUtil(org.apache.calcite.plan.RelOptUtil) QueryParameterMetadata(com.hazelcast.sql.impl.QueryParameterMetadata) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) ParameterConverter(com.hazelcast.sql.impl.ParameterConverter) Collectors.toMap(java.util.stream.Collectors.toMap) LogicalRel(com.hazelcast.jet.sql.impl.opt.logical.LogicalRel) Arrays.asList(java.util.Arrays.asList) ConstantTableStatistics(com.hazelcast.sql.impl.schema.ConstantTableStatistics) HazelcastSchemaUtils(com.hazelcast.jet.sql.impl.schema.HazelcastSchemaUtils) QueryUtils(com.hazelcast.sql.impl.QueryUtils) PartitionedMapTable(com.hazelcast.sql.impl.schema.map.PartitionedMapTable) SqlParserPos(org.apache.calcite.sql.parser.SqlParserPos) StrictParameterConverter(com.hazelcast.jet.sql.impl.validate.param.StrictParameterConverter) HazelcastTableStatistic(com.hazelcast.jet.sql.impl.schema.HazelcastTableStatistic) Collections.emptyList(java.util.Collections.emptyList) SqlTestSupport(com.hazelcast.jet.sql.SqlTestSupport) SqlExplainLevel(org.apache.calcite.sql.SqlExplainLevel) RelNode(org.apache.calcite.rel.RelNode) HazelcastSchema(com.hazelcast.jet.sql.impl.schema.HazelcastSchema) Objects(java.util.Objects) TableField(com.hazelcast.sql.impl.schema.TableField) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) StringReader(java.io.StringReader) QueryParseResult(com.hazelcast.jet.sql.impl.parse.QueryParseResult) MapTableIndex(com.hazelcast.sql.impl.schema.map.MapTableIndex) Function.identity(java.util.function.Function.identity) BufferedReader(java.io.BufferedReader) Arrays.stream(java.util.Arrays.stream) PhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.PhysicalRel) StrictParameterConverter(com.hazelcast.jet.sql.impl.validate.param.StrictParameterConverter) ParameterConverter(com.hazelcast.sql.impl.ParameterConverter) StrictParameterConverter(com.hazelcast.jet.sql.impl.validate.param.StrictParameterConverter) QueryParameterMetadata(com.hazelcast.sql.impl.QueryParameterMetadata) OptimizerContext(com.hazelcast.jet.sql.impl.OptimizerContext)

Example 5 with ParameterConverter

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;
}
Also used : SqlDynamicParam(org.apache.calcite.sql.SqlDynamicParam) ParameterConverter(com.hazelcast.sql.impl.ParameterConverter) AnyToVarcharParameterConverter(com.hazelcast.jet.sql.impl.validate.param.AnyToVarcharParameterConverter) AnyToVarcharParameterConverter(com.hazelcast.jet.sql.impl.validate.param.AnyToVarcharParameterConverter) HazelcastSqlValidator(com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

ParameterConverter (com.hazelcast.sql.impl.ParameterConverter)9 RelDataType (org.apache.calcite.rel.type.RelDataType)4 SqlDynamicParam (org.apache.calcite.sql.SqlDynamicParam)4 HazelcastSqlValidator (com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator)2 AbstractParameterConverter (com.hazelcast.jet.sql.impl.validate.param.AbstractParameterConverter)2 AnyToVarcharParameterConverter (com.hazelcast.jet.sql.impl.validate.param.AnyToVarcharParameterConverter)2 NumericPrecedenceParameterConverter (com.hazelcast.jet.sql.impl.validate.param.NumericPrecedenceParameterConverter)2 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)2 SqlNode (org.apache.calcite.sql.SqlNode)2 SqlTestSupport (com.hazelcast.jet.sql.SqlTestSupport)1 OptimizerContext (com.hazelcast.jet.sql.impl.OptimizerContext)1 LogicalRel (com.hazelcast.jet.sql.impl.opt.logical.LogicalRel)1 LogicalRules (com.hazelcast.jet.sql.impl.opt.logical.LogicalRules)1 PhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.PhysicalRel)1 PhysicalRules (com.hazelcast.jet.sql.impl.opt.physical.PhysicalRules)1 QueryParseResult (com.hazelcast.jet.sql.impl.parse.QueryParseResult)1 HazelcastSchema (com.hazelcast.jet.sql.impl.schema.HazelcastSchema)1 HazelcastSchemaUtils (com.hazelcast.jet.sql.impl.schema.HazelcastSchemaUtils)1 HazelcastTable (com.hazelcast.jet.sql.impl.schema.HazelcastTable)1 HazelcastTableStatistic (com.hazelcast.jet.sql.impl.schema.HazelcastTableStatistic)1