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,
Out<TypeArgumentList> typeArgs) {
private static LayoutType logicalToPhysicalType(
Namespace namespace, PropertyType logicalType, Out<TypeArgumentList> typeArgs) {
typeArgs.set(TypeArgumentList.EMPTY);
boolean immutable = logicalType instanceof ScopePropertyType && ((ScopePropertyType) logicalType).immutable();
@@ -240,7 +240,7 @@ public final class LayoutCompiler {
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();
if (ap.items().nullable()) {
@@ -263,7 +263,7 @@ public final class LayoutCompiler {
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();
if (sp.items().nullable()) {
@@ -291,7 +291,7 @@ public final class LayoutCompiler {
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();
if (mp.keys().nullable()) {
@@ -299,7 +299,7 @@ public final class LayoutCompiler {
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();
if (mp.values().nullable()) {
@@ -331,7 +331,7 @@ public final class LayoutCompiler {
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();
if (tp.items().get(i).nullable()) {
@@ -366,7 +366,7 @@ public final class LayoutCompiler {
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();
if (tg.items().get(i).nullable()) {
@@ -396,11 +396,11 @@ public final class LayoutCompiler {
final Optional<Schema> udtSchema;
if (up.schemaId() == SchemaId.INVALID) {
udtSchema = ns.schemas().stream()
udtSchema = namespace.schemas().stream()
.filter(schema -> up.name().equals(schema.name()))
.findFirst();
} else {
udtSchema = ns.schemas().stream()
udtSchema = namespace.schemas().stream()
.filter(schema -> up.schemaId().equals(schema.schemaId()))
.findFirst();
if (up.name().equals(udtSchema.map(Schema::name).orElse(null))) {

View File

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

View File

@@ -30,9 +30,6 @@ public class Schema {
// Required fields
@JsonProperty(required = true)
private SchemaId id;
@JsonProperty(required = true)
private String name;
@@ -44,6 +41,9 @@ public class Schema {
@JsonProperty
private String comment;
@JsonProperty()
private SchemaId id;
@JsonProperty
private SchemaOptions options;
@@ -63,6 +63,7 @@ public class Schema {
* Initializes a new instance of the {@link Schema} class.
*/
private Schema() {
this.id = SchemaId.NONE;
this.type = TypeKind.SCHEMA;
this.partitionKeys = 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, schema, nameDupCheck, "Schema reference", "Namespace");
// Count the versions of each schema by name.
final int count = nameVersioningCheck.get(schema.name());
nameVersioningCheck.put(schema.name(), count + 1);
nameVersioningCheck.compute(schema.name(), (name, count) -> count == null ? 1 : count + 1);
}
// Enable id-less Schema references for all types with a unique version in the namespace
for (Schema schema : namespace.schemas()) {
if (nameVersioningCheck.get(schema.name()) == 1) {
Assert.duplicateCheck(SchemaIdentification.of(schema.name(), SchemaId.INVALID), schema, nameDupCheck,
"Schema reference", "Namespace");
Assert.duplicateCheck(
SchemaIdentification.of(schema.name(), SchemaId.NONE), schema, nameDupCheck,
"Schema reference", "Namespace"
);
}
}