use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.
the class KvMetadataJavaResolver method resolveObjectMetadata.
private KvMetadata resolveObjectMetadata(boolean isKey, List<MappingField> resolvedFields, Map<QueryPath, MappingField> fieldsByPath, Class<?> clazz) {
Map<String, Class<?>> typesByNames = FieldsUtil.resolveClass(clazz);
List<TableField> fields = new ArrayList<>();
Map<String, String> typeNamesByPaths = new HashMap<>();
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));
if (path.getPath() != null && typesByNames.get(path.getPath()) != null) {
typeNamesByPaths.put(path.getPath(), typesByNames.get(path.getPath()).getName());
}
}
maybeAddDefaultField(isKey, resolvedFields, fields, QueryDataType.OBJECT);
return new KvMetadata(fields, GenericQueryTargetDescriptor.DEFAULT, new PojoUpsertTargetDescriptor(clazz.getName(), typeNamesByPaths));
}
use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.
the class KvMetadataJavaResolver method resolveMetadata.
public KvMetadata resolveMetadata(boolean isKey, List<MappingField> resolvedFields, Class<?> clazz) {
QueryDataType type = QueryDataTypeUtils.resolveTypeForClass(clazz);
Map<QueryPath, MappingField> fields = extractFields(resolvedFields, isKey);
if (type != QueryDataType.OBJECT) {
return resolvePrimitiveMetadata(isKey, resolvedFields, fields, type);
} else {
return resolveObjectMetadata(isKey, resolvedFields, fields, clazz);
}
}
use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.
the class CompactUpsertTarget method createInjector.
@Override
@SuppressWarnings("checkstyle:ReturnCount")
public UpsertInjector createInjector(@Nullable String path, QueryDataType queryDataType) {
if (path == null) {
return FAILING_TOP_LEVEL_INJECTOR;
}
boolean hasField = schema.hasField(path);
if (!hasField) {
return value -> {
throw QueryException.error("Unable to inject a non-null value to \"" + path + "\"");
};
}
FieldKind kind = schema.getField(path).getKind();
switch(kind) {
case STRING:
return value -> builder.setString(path, (String) value);
case NULLABLE_BOOLEAN:
return value -> builder.setNullableBoolean(path, (Boolean) value);
case NULLABLE_INT8:
return value -> builder.setNullableInt8(path, (Byte) value);
case NULLABLE_INT16:
return value -> builder.setNullableInt16(path, (Short) value);
case NULLABLE_INT32:
return value -> builder.setNullableInt32(path, (Integer) value);
case NULLABLE_INT64:
return value -> builder.setNullableInt64(path, (Long) value);
case DECIMAL:
return value -> builder.setDecimal(path, (BigDecimal) value);
case NULLABLE_FLOAT32:
return value -> builder.setNullableFloat32(path, (Float) value);
case NULLABLE_FLOAT64:
return value -> builder.setNullableFloat64(path, (Double) value);
case TIME:
return value -> builder.setTime(path, (LocalTime) value);
case DATE:
return value -> builder.setDate(path, (LocalDate) value);
case TIMESTAMP:
return value -> builder.setTimestamp(path, (LocalDateTime) value);
case TIMESTAMP_WITH_TIMEZONE:
return value -> builder.setTimestampWithTimezone(path, (OffsetDateTime) value);
default:
throw QueryException.error(kind + " kind is not supported in SQL with Compact format!");
}
}
use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.
the class OptUtils method convert.
/**
* Converts a {@link TableField} to {@link RelDataType}.
*/
public static RelDataType convert(TableField field, RelDataTypeFactory typeFactory) {
QueryDataType fieldType = field.getType();
SqlTypeName sqlTypeName = HazelcastTypeUtils.toCalciteType(fieldType);
if (sqlTypeName == null) {
throw new IllegalStateException("Unsupported type family: " + fieldType + ", getSqlTypeName should never return null.");
}
if (sqlTypeName == SqlTypeName.OTHER) {
return convertCustomType(fieldType);
} else {
RelDataType relType = typeFactory.createSqlType(sqlTypeName);
return typeFactory.createTypeWithNullability(relType, true);
}
}
use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.
the class KvMetadataAvroResolver method schema.
private Schema schema(List<TableField> fields) {
QueryPath[] paths = paths(fields);
QueryDataType[] types = types(fields);
FieldAssembler<Schema> schema = SchemaBuilder.record("jet.sql").fields();
for (int i = 0; i < fields.size(); i++) {
String path = paths[i].getPath();
if (path == null) {
continue;
}
QueryDataType type = types[i];
switch(type.getTypeFamily()) {
case BOOLEAN:
schema = schema.name(path).type().unionOf().nullType().and().booleanType().endUnion().nullDefault();
break;
case TINYINT:
case SMALLINT:
case INTEGER:
schema = schema.name(path).type().unionOf().nullType().and().intType().endUnion().nullDefault();
break;
case BIGINT:
schema = schema.name(path).type().unionOf().nullType().and().longType().endUnion().nullDefault();
break;
case REAL:
schema = schema.name(path).type().unionOf().nullType().and().floatType().endUnion().nullDefault();
break;
case DOUBLE:
schema = schema.name(path).type().unionOf().nullType().and().doubleType().endUnion().nullDefault();
break;
case DECIMAL:
case TIME:
case DATE:
case TIMESTAMP:
case TIMESTAMP_WITH_TIME_ZONE:
case VARCHAR:
schema = schema.name(path).type().unionOf().nullType().and().stringType().endUnion().nullDefault();
break;
case OBJECT:
schema = schema.name(path).type().unionOf().nullType().and().booleanType().and().intType().and().longType().and().floatType().and().doubleType().and().stringType().endUnion().nullDefault();
break;
default:
throw new IllegalArgumentException("Unknown type: " + type.getTypeFamily());
}
}
return schema.endRecord();
}
Aggregations