Search in sources :

Example 56 with QueryDataType

use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.

the class KvMetadataJsonResolver method resolveMetadata.

@Override
public KvMetadata resolveMetadata(boolean isKey, List<MappingField> resolvedFields, Map<String, String> options, InternalSerializationService serializationService) {
    Map<QueryPath, MappingField> fieldsByPath = extractFields(resolvedFields, isKey);
    List<TableField> fields = new ArrayList<>();
    for (Entry<QueryPath, MappingField> entry : fieldsByPath.entrySet()) {
        QueryPath path = entry.getKey();
        QueryDataType type = entry.getValue().type();
        String name = entry.getValue().name();
        fields.add(new MapTableField(name, type, false, path));
    }
    maybeAddDefaultField(isKey, resolvedFields, fields, QueryDataType.OBJECT);
    return new KvMetadata(fields, JsonQueryTargetDescriptor.INSTANCE, JsonUpsertTargetDescriptor.INSTANCE);
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) ArrayList(java.util.ArrayList) MappingField(com.hazelcast.sql.impl.schema.MappingField) TableField(com.hazelcast.sql.impl.schema.TableField) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField)

Example 57 with QueryDataType

use of com.hazelcast.sql.impl.type.QueryDataType 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 58 with QueryDataType

use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.

the class HazelcastCallBinding method getOperandTypes.

private static String getOperandTypes(SqlValidator validator, SqlCall call, SqlValidatorScope scope) {
    StringJoiner res = new StringJoiner(", ", "[", "]");
    for (SqlNode operand : getOperands(call)) {
        RelDataType calciteType = validator.deriveType(scope, operand);
        String typeName;
        if (calciteType.getSqlTypeName() == SqlTypeName.NULL) {
            typeName = validator.getUnknownType().toString();
        } else if (calciteType.getSqlTypeName() == SqlTypeName.ROW || calciteType.getSqlTypeName() == SqlTypeName.COLUMN_LIST) {
            typeName = calciteType.getSqlTypeName().toString();
        } else if (calciteType.getSqlTypeName() == SqlTypeName.SYMBOL) {
            typeName = "SYMBOL";
        } else if (calciteType.getSqlTypeName() == SqlTypeName.CURSOR) {
            typeName = "CURSOR";
        } else {
            QueryDataType hazelcastType = HazelcastTypeUtils.toHazelcastType(calciteType);
            if (hazelcastType.getTypeFamily().getPublicType() != null) {
                typeName = hazelcastType.getTypeFamily().getPublicType().toString();
            } else {
                typeName = calciteType.getSqlTypeName().toString();
            }
        }
        res.add(typeName);
    }
    return res.toString();
}
Also used : QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) RelDataType(org.apache.calcite.rel.type.RelDataType) StringJoiner(java.util.StringJoiner) SqlNode(org.apache.calcite.sql.SqlNode)

Example 59 with QueryDataType

use of com.hazelcast.sql.impl.type.QueryDataType 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;
}
Also used : QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) RelDataType(org.apache.calcite.rel.type.RelDataType) HazelcastSqlValidator(com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator)

Example 60 with QueryDataType

use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.

the class HazelcastComparisonPredicateUtils method checkOperandTypesWithPrecedence.

private static boolean checkOperandTypesWithPrecedence(HazelcastCallBinding callBinding, boolean throwOnFailure, HazelcastSqlValidator validator, SqlNode high, RelDataType highType, SqlNode low, RelDataType lowType, int lowIndex) {
    QueryDataType highHZType = HazelcastTypeUtils.toHazelcastType(highType);
    QueryDataType lowHZType = HazelcastTypeUtils.toHazelcastType(lowType);
    if (highHZType.getTypeFamily().isNumeric()) {
        // Set flexible parameter converter that allows TINYINT/SMALLINT/INTEGER -> BIGINT conversions
        setNumericParameterConverter(validator, high, highHZType);
        setNumericParameterConverter(validator, low, highHZType);
    }
    boolean valid = validator.getTypeCoercion().rowTypeElementCoercion(callBinding.getScope(), low, highType, lowOperandNode -> callBinding.getCall().setOperand(lowIndex, lowOperandNode));
    if (valid && highHZType == QueryDataType.OBJECT && lowHZType != QueryDataType.OBJECT) {
        valid = false;
    }
    // Types cannot be converted to each other.
    if (!valid && throwOnFailure) {
        throw callBinding.newValidationSignatureError();
    }
    return valid;
}
Also used : QueryDataType(com.hazelcast.sql.impl.type.QueryDataType)

Aggregations

QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)61 QueryPath (com.hazelcast.sql.impl.extract.QueryPath)23 MappingField (com.hazelcast.sql.impl.schema.MappingField)17 ArrayList (java.util.ArrayList)16 TableField (com.hazelcast.sql.impl.schema.TableField)14 MapTableField (com.hazelcast.sql.impl.schema.map.MapTableField)13 HazelcastTable (com.hazelcast.jet.sql.impl.schema.HazelcastTable)10 RelDataType (org.apache.calcite.rel.type.RelDataType)7 OptimizerTestSupport (com.hazelcast.jet.sql.impl.opt.OptimizerTestSupport)6 IndexScanMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel)6 FullScanPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.FullScanPhysicalRel)5 Nonnull (javax.annotation.Nonnull)5 IndexEqualsFilter (com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter)4 Test (org.junit.Test)4 IndexType (com.hazelcast.config.IndexType)3 KvMetadata (com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 HashMap (java.util.HashMap)3 List (java.util.List)3