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);
}
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;
}
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();
}
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;
}
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;
}
Aggregations