Progressed on deserializing schemas.

This commit is contained in:
David Noble
2019-09-17 21:03:41 -07:00
parent 60d7d73b14
commit 4c77aef689
4 changed files with 21 additions and 27 deletions

View File

@@ -153,8 +153,8 @@ public final class LayoutCompiler {
} }
} }
private static LayoutType logicalToPhysicalType(Namespace ns, PropertyType logicalType, private static LayoutType logicalToPhysicalType(
Out<TypeArgumentList> typeArgs) { Namespace namespace, PropertyType logicalType, Out<TypeArgumentList> typeArgs) {
typeArgs.set(TypeArgumentList.EMPTY); typeArgs.set(TypeArgumentList.EMPTY);
boolean immutable = logicalType instanceof ScopePropertyType && ((ScopePropertyType) logicalType).immutable(); boolean immutable = logicalType instanceof ScopePropertyType && ((ScopePropertyType) logicalType).immutable();
@@ -240,7 +240,7 @@ public final class LayoutCompiler {
final Out<TypeArgumentList> out = new Out<>(); final Out<TypeArgumentList> out = new Out<>();
LayoutType itemType = LayoutCompiler.logicalToPhysicalType(ns, ap.items(), out); LayoutType itemType = LayoutCompiler.logicalToPhysicalType(namespace, ap.items(), out);
TypeArgumentList itemTypeArgs = out.get(); TypeArgumentList itemTypeArgs = out.get();
if (ap.items().nullable()) { if (ap.items().nullable()) {
@@ -263,7 +263,7 @@ public final class LayoutCompiler {
final Out<TypeArgumentList> out = new Out<>(); final Out<TypeArgumentList> out = new Out<>();
LayoutType itemType = LayoutCompiler.logicalToPhysicalType(ns, sp.items(), out); LayoutType itemType = LayoutCompiler.logicalToPhysicalType(namespace, sp.items(), out);
TypeArgumentList itemTypeArgs = out.get(); TypeArgumentList itemTypeArgs = out.get();
if (sp.items().nullable()) { if (sp.items().nullable()) {
@@ -291,7 +291,7 @@ public final class LayoutCompiler {
final Out<TypeArgumentList> out = new Out<>(); final Out<TypeArgumentList> out = new Out<>();
LayoutType keyType = LayoutCompiler.logicalToPhysicalType(ns, mp.keys(), out); LayoutType keyType = LayoutCompiler.logicalToPhysicalType(namespace, mp.keys(), out);
TypeArgumentList keyTypeArgs = out.get(); TypeArgumentList keyTypeArgs = out.get();
if (mp.keys().nullable()) { if (mp.keys().nullable()) {
@@ -299,7 +299,7 @@ public final class LayoutCompiler {
keyType = keyType.isImmutable() ? LayoutTypes.IMMUTABLE_NULLABLE : LayoutTypes.NULLABLE; keyType = keyType.isImmutable() ? LayoutTypes.IMMUTABLE_NULLABLE : LayoutTypes.NULLABLE;
} }
LayoutType valueType = LayoutCompiler.logicalToPhysicalType(ns, mp.values(), out); LayoutType valueType = LayoutCompiler.logicalToPhysicalType(namespace, mp.values(), out);
TypeArgumentList valueTypeArgs = out.get(); TypeArgumentList valueTypeArgs = out.get();
if (mp.values().nullable()) { if (mp.values().nullable()) {
@@ -331,7 +331,7 @@ public final class LayoutCompiler {
for (int i = 0; i < tp.items().size(); i++) { for (int i = 0; i < tp.items().size(); i++) {
LayoutType itemType = LayoutCompiler.logicalToPhysicalType(ns, tp.items().get(i), out); LayoutType itemType = LayoutCompiler.logicalToPhysicalType(namespace, tp.items().get(i), out);
TypeArgumentList itemTypeArgs = out.get(); TypeArgumentList itemTypeArgs = out.get();
if (tp.items().get(i).nullable()) { if (tp.items().get(i).nullable()) {
@@ -366,7 +366,7 @@ public final class LayoutCompiler {
for (int i = 0; i < tg.items().size(); i++) { for (int i = 0; i < tg.items().size(); i++) {
LayoutType itemType = LayoutCompiler.logicalToPhysicalType(ns, tg.items().get(i), out); LayoutType itemType = LayoutCompiler.logicalToPhysicalType(namespace, tg.items().get(i), out);
TypeArgumentList itemTypeArgs = out.get(); TypeArgumentList itemTypeArgs = out.get();
if (tg.items().get(i).nullable()) { if (tg.items().get(i).nullable()) {
@@ -396,11 +396,11 @@ public final class LayoutCompiler {
final Optional<Schema> udtSchema; final Optional<Schema> udtSchema;
if (up.schemaId() == SchemaId.INVALID) { if (up.schemaId() == SchemaId.INVALID) {
udtSchema = ns.schemas().stream() udtSchema = namespace.schemas().stream()
.filter(schema -> up.name().equals(schema.name())) .filter(schema -> up.name().equals(schema.name()))
.findFirst(); .findFirst();
} else { } else {
udtSchema = ns.schemas().stream() udtSchema = namespace.schemas().stream()
.filter(schema -> up.schemaId().equals(schema.schemaId())) .filter(schema -> up.schemaId().equals(schema.schemaId()))
.findFirst(); .findFirst();
if (up.name().equals(udtSchema.map(Schema::name).orElse(null))) { if (up.name().equals(udtSchema.map(Schema::name).orElse(null))) {

View File

@@ -43,23 +43,17 @@ public final class SystemSchema {
@SuppressWarnings("StatementWithEmptyBody") @SuppressWarnings("StatementWithEmptyBody")
private static final Supplier<LayoutResolver> layoutResolver = Suppliers.memoize(() -> { private static final Supplier<LayoutResolver> layoutResolver = Suppliers.memoize(() -> {
final String json; final Optional<Namespace> namespace;
try (final InputStream stream = getResourceAsStream("SystemSchema.json")) { try (final InputStream stream = getResourceAsStream("SystemSchema.json")) {
Optional<Namespace> namespace = Namespace.parse(stream); namespace = Namespace.parse(stream);
ByteBuf buffer = Unpooled.buffer();
while (buffer.writeBytes(stream, 8192) == 8192) { }
json = buffer.readCharSequence(buffer.readableBytes(), StandardCharsets.UTF_8).toString();
} catch (IOException cause) { } catch (IOException cause) {
String message = lenientFormat("Failed to load SystemSchema.json due to %s", cause); String message = lenientFormat("Failed to load SystemSchema.json due to %s", cause);
throw new IllegalStateException(message, cause); throw new IllegalStateException(message, cause);
} }
Optional<Namespace> namespace = Namespace.parse(json);
checkState(namespace.isPresent(), "Failed to parse SystemSchema.json");
return new LayoutResolverNamespace(namespace.get()); return new LayoutResolverNamespace(namespace.get());
}); });

View File

@@ -30,9 +30,6 @@ public class Schema {
// Required fields // Required fields
@JsonProperty(required = true)
private SchemaId id;
@JsonProperty(required = true) @JsonProperty(required = true)
private String name; private String name;
@@ -44,6 +41,9 @@ public class Schema {
@JsonProperty @JsonProperty
private String comment; private String comment;
@JsonProperty()
private SchemaId id;
@JsonProperty @JsonProperty
private SchemaOptions options; private SchemaOptions options;
@@ -63,6 +63,7 @@ public class Schema {
* Initializes a new instance of the {@link Schema} class. * Initializes a new instance of the {@link Schema} class.
*/ */
private Schema() { private Schema() {
this.id = SchemaId.NONE;
this.type = TypeKind.SCHEMA; this.type = TypeKind.SCHEMA;
this.partitionKeys = Collections.emptyList(); this.partitionKeys = Collections.emptyList();
this.primaryKeys = Collections.emptyList(); this.primaryKeys = Collections.emptyList();

View File

@@ -37,18 +37,17 @@ public final class SchemaValidator {
Assert.duplicateCheck(identification.id(), schema, idDupCheck, "Schema id", "Namespace"); Assert.duplicateCheck(identification.id(), schema, idDupCheck, "Schema id", "Namespace");
Assert.duplicateCheck(identification, schema, nameDupCheck, "Schema reference", "Namespace"); Assert.duplicateCheck(identification, schema, nameDupCheck, "Schema reference", "Namespace");
// Count the versions of each schema by name. nameVersioningCheck.compute(schema.name(), (name, count) -> count == null ? 1 : count + 1);
final int count = nameVersioningCheck.get(schema.name());
nameVersioningCheck.put(schema.name(), count + 1);
} }
// Enable id-less Schema references for all types with a unique version in the namespace // Enable id-less Schema references for all types with a unique version in the namespace
for (Schema schema : namespace.schemas()) { for (Schema schema : namespace.schemas()) {
if (nameVersioningCheck.get(schema.name()) == 1) { if (nameVersioningCheck.get(schema.name()) == 1) {
Assert.duplicateCheck(SchemaIdentification.of(schema.name(), SchemaId.INVALID), schema, nameDupCheck, Assert.duplicateCheck(
"Schema reference", "Namespace"); SchemaIdentification.of(schema.name(), SchemaId.NONE), schema, nameDupCheck,
"Schema reference", "Namespace"
);
} }
} }