Search in sources :

Example 6 with ParameterConverter

use of com.hazelcast.sql.impl.ParameterConverter 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;
}
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)

Example 7 with ParameterConverter

use of com.hazelcast.sql.impl.ParameterConverter in project hazelcast by hazelcast.

the class HazelcastSqlValidator method getArgumentAt.

public Object getArgumentAt(int index) {
    ParameterConverter parameterConverter = parameterConverterMap.get(index);
    Object argument = arguments.get(index);
    return parameterConverter.convert(argument);
}
Also used : ParameterConverter(com.hazelcast.sql.impl.ParameterConverter) AbstractParameterConverter(com.hazelcast.jet.sql.impl.validate.param.AbstractParameterConverter)

Example 8 with ParameterConverter

use of com.hazelcast.sql.impl.ParameterConverter in project hazelcast by hazelcast.

the class HazelcastSqlValidator method getParameterConverters.

public ParameterConverter[] getParameterConverters(SqlNode node) {
    // Get original parameter row type.
    RelDataType rowType = getParameterRowType(node);
    // Create precedence-based converters with optional override by a more specialized converters.
    ParameterConverter[] res = new ParameterConverter[rowType.getFieldCount()];
    for (int i = 0; i < res.length; i++) {
        ParameterConverter converter = parameterConverterMap.get(i);
        if (converter == null) {
            QueryDataType targetType = HazelcastTypeUtils.toHazelcastType(rowType.getFieldList().get(i).getType());
            converter = AbstractParameterConverter.from(targetType, i, parameterPositionMap.get(i));
        }
        res[i] = converter;
    }
    return res;
}
Also used : ParameterConverter(com.hazelcast.sql.impl.ParameterConverter) AbstractParameterConverter(com.hazelcast.jet.sql.impl.validate.param.AbstractParameterConverter) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 9 with ParameterConverter

use of com.hazelcast.sql.impl.ParameterConverter in project hazelcast by hazelcast.

the class HazelcastComparisonPredicateUtils method setNumericParameterConverter.

private static 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)

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