use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class AvroResolver method resolveFields.
static List<MappingField> resolveFields(Schema schema) {
Map<String, MappingField> fields = new LinkedHashMap<>();
for (Schema.Field avroField : schema.getFields()) {
String name = avroField.name();
QueryDataType type = resolveType(avroField.schema().getType());
MappingField field = new MappingField(name, type);
fields.putIfAbsent(field.name(), field);
}
return new ArrayList<>(fields.values());
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class CsvResolver method resolveFields.
static List<MappingField> resolveFields(Set<String> header) {
Map<String, MappingField> fields = new LinkedHashMap<>();
for (String name : header) {
MappingField field = new MappingField(name, QueryDataType.VARCHAR);
fields.putIfAbsent(field.name(), field);
}
return new ArrayList<>(fields.values());
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class MetadataCompactResolver method resolveAndValidateFields.
@Override
public Stream<MappingField> resolveAndValidateFields(boolean isKey, List<MappingField> userFields, Map<String, String> options, InternalSerializationService serializationService) {
if (userFields.isEmpty()) {
throw QueryException.error("Column list is required for Compact format");
}
String typeNameProperty = isKey ? OPTION_KEY_COMPACT_TYPE_NAME : OPTION_VALUE_COMPACT_TYPE_NAME;
String typeName = options.get(typeNameProperty);
if (typeName == null) {
throw QueryException.error("Unable to resolve table metadata. Missing ['typeName'] option");
}
Map<QueryPath, MappingField> fields = extractFields(userFields, isKey);
return fields.entrySet().stream().map(entry -> {
QueryPath path = entry.getKey();
if (path.getPath() == null) {
throw QueryException.error("Cannot use the '" + path + "' field with Compact serialization");
}
QueryDataType type = entry.getValue().type();
if (type == QueryDataType.OBJECT) {
throw QueryException.error("Cannot derive Compact type for '" + type.getTypeFamily() + "'");
}
return entry.getValue();
});
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class MetadataPortableResolver method resolveAndValidateFields.
@Override
public Stream<MappingField> resolveAndValidateFields(boolean isKey, List<MappingField> userFields, Map<String, String> options, InternalSerializationService serializationService) {
Map<QueryPath, MappingField> userFieldsByPath = extractFields(userFields, isKey);
ClassDefinition classDefinition = findClassDefinition(isKey, options, serializationService);
return userFields.isEmpty() ? resolveFields(isKey, classDefinition) : resolveAndValidateFields(isKey, userFieldsByPath, classDefinition);
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class MetadataPortableResolver method resolveMetadata.
private static KvMetadata resolveMetadata(boolean isKey, List<MappingField> resolvedFields, Map<QueryPath, MappingField> fieldsByPath, @Nonnull ClassDefinition clazz) {
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, GenericQueryTargetDescriptor.DEFAULT, new PortableUpsertTargetDescriptor(clazz));
}
Aggregations