use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class MetadataCompactResolver method resolveMetadata.
@Override
public KvMetadata resolveMetadata(boolean isKey, List<MappingField> resolvedFields, Map<String, String> options, InternalSerializationService serializationService) {
Map<QueryPath, MappingField> fieldsByPath = extractFields(resolvedFields, isKey);
String typeNameProperty = isKey ? OPTION_KEY_COMPACT_TYPE_NAME : OPTION_VALUE_COMPACT_TYPE_NAME;
String typeName = options.get(typeNameProperty);
List<TableField> fields = new ArrayList<>(fieldsByPath.size());
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);
Schema schema = resolveSchema(typeName, fieldsByPath);
return new KvMetadata(fields, GenericQueryTargetDescriptor.DEFAULT, new CompactUpsertTargetDescriptor(schema));
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class MetadataCompactResolver method resolveSchema.
private Schema resolveSchema(String typeName, Map<QueryPath, MappingField> fields) {
SchemaWriter schemaWriter = new SchemaWriter(typeName);
for (Entry<QueryPath, MappingField> entry : fields.entrySet()) {
String name = entry.getKey().getPath();
QueryDataType type = entry.getValue().type();
schemaWriter.addField(new FieldDescriptor(name, resolveToCompactKind(type.getTypeFamily())));
}
return schemaWriter.build();
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class MetadataPortableResolver method resolveFields.
Stream<MappingField> resolveFields(boolean isKey, @Nullable ClassDefinition clazz) {
if (clazz == null || clazz.getFieldCount() == 0) {
// ClassDefinition does not exist, or it is empty, map the whole value
String name = isKey ? KEY : VALUE;
return Stream.of(new MappingField(name, QueryDataType.OBJECT, name));
}
return clazz.getFieldNames().stream().map(name -> {
QueryPath path = new QueryPath(name, isKey);
QueryDataType type = resolvePortableType(clazz.getFieldType(name));
return new MappingField(name, type, path.toString());
});
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class MetadataPortableResolver method resolveClassDefinition.
@Nonnull
private static ClassDefinition resolveClassDefinition(boolean isKey, Map<String, String> options, Collection<MappingField> fields, InternalSerializationService serializationService) {
Tuple3<Integer, Integer, Integer> settings = settings(isKey, options);
// noinspection ConstantConditions
ClassDefinition classDefinition = serializationService.getPortableContext().lookupClassDefinition(settings.f0(), settings.f1(), settings.f2());
if (classDefinition != null) {
return classDefinition;
}
ClassDefinitionBuilder classDefinitionBuilder = new ClassDefinitionBuilder(settings.f0(), settings.f1(), settings.f2());
for (MappingField field : fields) {
String name = field.name();
QueryDataType type = field.type();
switch(type.getTypeFamily()) {
case BOOLEAN:
classDefinitionBuilder.addBooleanField(name);
break;
case TINYINT:
classDefinitionBuilder.addByteField(name);
break;
case SMALLINT:
classDefinitionBuilder.addShortField(name);
break;
case INTEGER:
classDefinitionBuilder.addIntField(name);
break;
case BIGINT:
classDefinitionBuilder.addLongField(name);
break;
case REAL:
classDefinitionBuilder.addFloatField(name);
break;
case DOUBLE:
classDefinitionBuilder.addDoubleField(name);
break;
case DECIMAL:
classDefinitionBuilder.addDecimalField(name);
break;
case VARCHAR:
classDefinitionBuilder.addStringField(name);
break;
case TIME:
classDefinitionBuilder.addTimeField(name);
break;
case DATE:
classDefinitionBuilder.addDateField(name);
break;
case TIMESTAMP:
classDefinitionBuilder.addTimestampField(name);
break;
case TIMESTAMP_WITH_TIME_ZONE:
classDefinitionBuilder.addTimestampWithTimezoneField(name);
break;
default:
}
}
return classDefinitionBuilder.build();
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class MetadataPortableResolver method resolveMetadata.
@Override
public KvMetadata resolveMetadata(boolean isKey, List<MappingField> resolvedFields, Map<String, String> options, InternalSerializationService serializationService) {
Map<QueryPath, MappingField> fieldsByPath = extractFields(resolvedFields, isKey);
ClassDefinition clazz = resolveClassDefinition(isKey, options, fieldsByPath.values(), serializationService);
return resolveMetadata(isKey, resolvedFields, fieldsByPath, clazz);
}
Aggregations