use of com.hazelcast.sql.impl.extract.QueryPath in project hazelcast by hazelcast.
the class MetadataPortableResolver method resolveAndValidateFields.
private static Stream<MappingField> resolveAndValidateFields(boolean isKey, Map<QueryPath, MappingField> userFieldsByPath, @Nullable ClassDefinition clazz) {
if (clazz == null) {
// CLassDefinition does not exist, make sure there are no OBJECT fields
return userFieldsByPath.values().stream().peek(mappingField -> {
QueryDataType type = mappingField.type();
if (type == QueryDataType.OBJECT) {
throw QueryException.error("Cannot derive Portable type for '" + type.getTypeFamily() + "'");
}
});
}
for (String name : clazz.getFieldNames()) {
QueryPath path = new QueryPath(name, isKey);
QueryDataType type = resolvePortableType(clazz.getFieldType(name));
MappingField userField = userFieldsByPath.get(path);
if (userField != null && !type.getTypeFamily().equals(userField.type().getTypeFamily())) {
throw QueryException.error("Mismatch between declared and resolved type: " + userField.name());
}
}
return userFieldsByPath.values().stream();
}
use of com.hazelcast.sql.impl.extract.QueryPath in project hazelcast by hazelcast.
the class KvMetadataAvroResolver 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, AvroQueryTargetDescriptor.INSTANCE, new AvroUpsertTargetDescriptor(schema(fields).toString()));
}
use of com.hazelcast.sql.impl.extract.QueryPath in project hazelcast by hazelcast.
the class KvMetadataJavaResolver method resolveAndValidateObjectFields.
private Stream<MappingField> resolveAndValidateObjectFields(boolean isKey, List<MappingField> userFields, Class<?> clazz) {
Map<QueryPath, MappingField> userFieldsByPath = extractFields(userFields, isKey);
for (Entry<String, Class<?>> classField : FieldsUtil.resolveClass(clazz).entrySet()) {
QueryPath path = new QueryPath(classField.getKey(), isKey);
QueryDataType type = QueryDataTypeUtils.resolveTypeForClass(classField.getValue());
MappingField userField = userFieldsByPath.get(path);
if (userField != null && !type.getTypeFamily().equals(userField.type().getTypeFamily())) {
throw QueryException.error("Mismatch between declared and resolved type for field '" + userField.name() + "'. Declared: " + userField.type().getTypeFamily() + ", resolved: " + type.getTypeFamily());
}
}
return userFieldsByPath.values().stream();
}
use of com.hazelcast.sql.impl.extract.QueryPath in project hazelcast by hazelcast.
the class KvMetadataJavaResolver method resolveObjectFields.
private Stream<MappingField> resolveObjectFields(boolean isKey, Class<?> clazz) {
Map<String, Class<?>> fieldsInClass = FieldsUtil.resolveClass(clazz);
if (fieldsInClass.isEmpty()) {
// we didn't find any non-object fields in the class, map the whole value (e.g. in java.lang.Object)
String name = isKey ? KEY : VALUE;
return Stream.of(new MappingField(name, QueryDataType.OBJECT, name));
}
return fieldsInClass.entrySet().stream().map(classField -> {
QueryPath path = new QueryPath(classField.getKey(), isKey);
QueryDataType type = QueryDataTypeUtils.resolveTypeForClass(classField.getValue());
String name = classField.getKey();
return new MappingField(name, type, path.toString());
});
}
use of com.hazelcast.sql.impl.extract.QueryPath in project hazelcast by hazelcast.
the class KvMetadataJavaResolver method resolvePrimitiveField.
private Stream<MappingField> resolvePrimitiveField(boolean isKey, QueryDataType type) {
QueryPath path = isKey ? QueryPath.KEY_PATH : QueryPath.VALUE_PATH;
String name = isKey ? KEY : VALUE;
String externalName = path.toString();
return Stream.of(new MappingField(name, type, externalName));
}
Aggregations