use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.
the class HazelcastTypeCoercion method rowTypeElementCoercion.
@SuppressWarnings("checkstyle:BooleanExpressionComplexity")
public boolean rowTypeElementCoercion(SqlValidatorScope scope, SqlNode rowElement, RelDataType targetType, Consumer<SqlNode> replaceFn) {
if (targetType.equals(scope.getValidator().getUnknownType())) {
return false;
}
RelDataType sourceType = validator.deriveType(scope, rowElement);
QueryDataType sourceHzType = HazelcastTypeUtils.toHazelcastType(sourceType);
QueryDataType targetHzType = HazelcastTypeUtils.toHazelcastType(targetType);
if (sourceHzType.getTypeFamily() == targetHzType.getTypeFamily() || targetHzType == OBJECT) {
// Do nothing.
return true;
}
boolean valid = sourceAndTargetAreNumeric(targetHzType, sourceHzType) || sourceAndTargetAreTemporalAndSourceCanBeConvertedToTarget(targetHzType, sourceHzType) || targetIsTemporalAndSourceIsVarcharLiteral(targetHzType, sourceHzType, rowElement) || sourceHzType.getTypeFamily() == QueryDataTypeFamily.NULL || sourceHzType.getTypeFamily() == QueryDataTypeFamily.VARCHAR && targetHzType.getTypeFamily() == QueryDataTypeFamily.JSON;
if (!valid) {
// Types cannot be converted to each other, fail to coerce
return false;
}
// Types are in the same group, cast source to target.
coerceNode(scope, rowElement, targetType, replaceFn);
return true;
}
use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.
the class FieldsUtil method resolveCompact.
/**
* Resolve the list of fields from a schema {@link com.hazelcast.internal.serialization.impl.compact.Schema},
* along with their {@link QueryDataType}.
*/
@Nonnull
public static SortedMap<String, QueryDataType> resolveCompact(@Nonnull Schema schema) {
SortedMap<String, QueryDataType> fields = new TreeMap<>();
// Add regular fields.
for (String name : schema.getFieldNames()) {
FieldKind compactKind = schema.getField(name).getKind();
QueryDataType type = resolveType(compactKind);
fields.putIfAbsent(name, type);
}
return fields;
}
use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.
the class MapIndexScanExecIterator method validateConverterTypes.
private void validateConverterTypes(InternalIndex index, String mapName, List<QueryDataType> expectedConverterTypes, List<QueryDataType> actualConverterTypes) {
for (int i = 0; i < Math.min(expectedConverterTypes.size(), actualConverterTypes.size()); i++) {
QueryDataType expected = expectedConverterTypes.get(i);
QueryDataType actual = actualConverterTypes.get(i);
if (!expected.equals(actual)) {
String component = index.getComponents()[i];
throw QueryException.error(SqlErrorCode.INDEX_INVALID, "Cannot use the index \"" + index.getName() + "\" of the IMap \"" + mapName + "\" because it has component \"" + component + "\" of type " + actual.getTypeFamily() + ", but " + expected.getTypeFamily() + " was expected");
}
}
if (expectedConverterTypes.size() > actualConverterTypes.size()) {
QueryDataType expected = expectedConverterTypes.get(actualConverterTypes.size());
String component = index.getComponents()[actualConverterTypes.size()];
throw QueryException.error(SqlErrorCode.INDEX_INVALID, "Cannot use the index \"" + index.getName() + "\" of the IMap \"" + mapName + "\" because it does not have suitable converter for component \"" + component + "\" (expected " + expected.getTypeFamily() + ")");
}
}
use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.
the class ColumnExpression method create.
public static ColumnExpression<?> create(int index, QueryDataType type) {
// Canonicalize the column type: currently values of non-canonical types,
// like QueryDataType.VARCHAR_CHARACTER, are canonicalized to values of
// some other canonical type, like QueryDataType.VARCHAR. That kind of
// changes the observed type of a column to a canonical one.
Class<?> canonicalClass = type.getConverter().getNormalizedValueClass();
QueryDataType canonicalType = QueryDataTypeUtils.resolveTypeForClass(canonicalClass);
return new ColumnExpression<>(index, canonicalType);
}
use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.
the class MapTableUtils method indexConverterToSqlTypes.
public static List<QueryDataType> indexConverterToSqlTypes(TypeConverter converter) {
if (converter == null) {
return Collections.emptyList();
}
if (converter instanceof CompositeConverter) {
CompositeConverter converter0 = ((CompositeConverter) converter);
List<QueryDataType> res = new ArrayList<>(converter0.getComponentCount());
for (int i = 0; i < converter0.getComponentCount(); i++) {
QueryDataType type = indexConverterToSqlType(converter0.getComponentConverter(i));
if (type == null) {
break;
} else {
res.add(type);
}
}
if (!res.isEmpty()) {
return res;
}
} else {
QueryDataType type = indexConverterToSqlType(converter);
if (type != null) {
return Collections.singletonList(type);
}
}
return Collections.emptyList();
}
Aggregations