use of com.hazelcast.sql.impl.schema.MappingField 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));
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class KvMetadataJavaResolver method resolvePrimitiveMetadata.
private KvMetadata resolvePrimitiveMetadata(boolean isKey, List<MappingField> resolvedFields, Map<QueryPath, MappingField> fieldsByPath, QueryDataType type) {
List<TableField> fields = new ArrayList<>();
QueryPath path = isKey ? QueryPath.KEY_PATH : QueryPath.VALUE_PATH;
MappingField field = fieldsByPath.get(path);
if (field != null) {
fields.add(new MapTableField(field.name(), field.type(), false, path));
}
maybeAddDefaultField(isKey, resolvedFields, fields, type);
return new KvMetadata(fields, GenericQueryTargetDescriptor.DEFAULT, PrimitiveUpsertTargetDescriptor.INSTANCE);
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class JsonResolver method resolveFields.
static List<MappingField> resolveFields(Map<String, Object> json) {
Map<String, MappingField> fields = new LinkedHashMap<>();
for (Entry<String, Object> entry : json.entrySet()) {
String name = entry.getKey();
QueryDataType type = resolveType(entry.getValue());
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 SqlCreateMapping method unparse.
public static String unparse(Mapping mapping) {
SqlPrettyWriter writer = new SqlPrettyWriter(SqlPrettyWriter.config());
writer.keyword("CREATE MAPPING");
writer.identifier(mapping.name(), true);
// external name defaults to mapping name - omit it if it's equal
if (mapping.externalName() != null && !mapping.externalName().equals(mapping.name())) {
writer.keyword("EXTERNAL NAME");
writer.identifier(mapping.externalName(), true);
}
List<MappingField> fields = mapping.fields();
if (fields.size() > 0) {
SqlWriter.Frame frame = writer.startList("(", ")");
for (MappingField field : fields) {
printIndent(writer);
writer.identifier(field.name(), true);
writer.print(field.type().getTypeFamily().toString());
if (field.externalName() != null) {
writer.print(" ");
writer.keyword("EXTERNAL NAME");
writer.identifier(field.externalName(), true);
}
}
writer.newlineAndIndent();
writer.endList(frame);
}
writer.newlineAndIndent();
writer.keyword("TYPE");
writer.print(mapping.type());
Map<String, String> options = mapping.options();
if (options.size() > 0) {
writer.newlineAndIndent();
writer.keyword("OPTIONS");
SqlWriter.Frame withFrame = writer.startList("(", ")");
for (Map.Entry<String, String> option : options.entrySet()) {
printIndent(writer);
writer.literal(writer.getDialect().quoteStringLiteral(option.getKey()));
writer.print("= ");
writer.literal(writer.getDialect().quoteStringLiteral(option.getValue()));
}
writer.newlineAndIndent();
writer.endList(withFrame);
}
return writer.toString();
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class MetadataCompactResolverTest method test_objectIsForbiddenForCompact.
@Test
@Parameters({ "true, __key", "false, this" })
public void test_objectIsForbiddenForCompact(boolean key, String prefix) {
InternalSerializationService ss = createSerializationService();
Map<String, String> options = ImmutableMap.of((key ? OPTION_KEY_COMPACT_TYPE_NAME : OPTION_VALUE_COMPACT_TYPE_NAME), "testAll");
List<MappingField> fields = asList(field("object", QueryDataType.OBJECT, prefix + ".object"));
assertThatThrownBy(() -> INSTANCE.resolveAndValidateFields(key, fields, options, ss).collect(Collectors.toList())).isInstanceOf(QueryException.class).hasMessageContaining("Cannot derive Compact type for '" + QueryDataTypeFamily.OBJECT + "'");
}
Aggregations