use of com.hazelcast.sql.impl.schema.MappingField 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.schema.MappingField in project hazelcast by hazelcast.
the class MappingColumnsTable method rows.
@Override
protected List<Object[]> rows() {
List<Object[]> rows = new ArrayList<>(mappings.size());
for (Mapping mapping : mappings) {
List<MappingField> fields = mapping.fields();
for (int i = 0; i < fields.size(); i++) {
MappingField field = fields.get(i);
Object[] row = new Object[] { catalog(), schema, mapping.name(), field.name(), field.externalName(), i + 1, String.valueOf(true), field.type().getTypeFamily().name() };
rows.add(row);
}
}
for (View view : views) {
for (int i = 0; i < view.viewColumnNames().size(); i++) {
Object[] row = new Object[] { catalog(), schema, view.name(), view.viewColumnNames().get(i), null, i + 1, String.valueOf(true), view.viewColumnTypes().get(i).getTypeFamily().name() };
rows.add(row);
}
}
return rows;
}
use of com.hazelcast.sql.impl.schema.MappingField 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.schema.MappingField 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.schema.MappingField 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());
});
}
Aggregations