arnToSchemaKey = new java.util.HashMap<>();
+ for (Schema s : schemaStore.scan(k -> true)) {
+ arnToSchemaKey.put(s.getSchemaArn(), schemaKey(s.getRegistryName(), s.getSchemaName()));
+ }
+ for (SchemaVersion v : versionStore.scan(k -> true)) {
+ String schemaKey = arnToSchemaKey.get(v.getSchemaArn());
+ if (schemaKey == null) {
+ continue;
+ }
+ indexVersion(schemaKey, v);
+ }
+ }
+
+ private static String canonicalHash(String definition, String dataFormat) {
+ String canonical;
+ try {
+ canonical = SchemaCompatibilityChecker.canonicalize(definition, dataFormat);
+ } catch (RuntimeException e) {
+ canonical = definition;
+ }
+ return sha256Hex(canonical);
+ }
+
+ private static String sha256Hex(String input) {
+ try {
+ MessageDigest md = MessageDigest.getInstance("SHA-256");
+ return HexFormat.of().formatHex(md.digest(input.getBytes(StandardCharsets.UTF_8)));
+ } catch (NoSuchAlgorithmException e) {
+ throw new IllegalStateException("SHA-256 not available", e);
+ }
+ }
+
+ private Registry autoCreateDefaultRegistry(String region) {
+ Registry registry = new Registry(DEFAULT_REGISTRY_NAME);
+ registry.setRegistryArn(buildRegistryArn(region, DEFAULT_REGISTRY_NAME));
+ registryStore.put(DEFAULT_REGISTRY_NAME, registry);
+ LOG.infov("Auto-created default Glue Registry");
+ return registry;
+ }
+
+ String resolveRegistryName(RegistryId registryId) {
+ if (registryId == null) {
+ return DEFAULT_REGISTRY_NAME;
+ }
+ if (registryId.getRegistryArn() != null && !registryId.getRegistryArn().isBlank()) {
+ return parseRegistryNameFromArn(registryId.getRegistryArn());
+ }
+ if (registryId.getRegistryName() != null && !registryId.getRegistryName().isBlank()) {
+ return registryId.getRegistryName();
+ }
+ return DEFAULT_REGISTRY_NAME;
+ }
+
+ private String parseRegistryNameFromArn(String arn) {
+ int slash = arn.indexOf("registry/");
+ if (slash < 0) {
+ throw new AwsException("InvalidInputException", "Invalid registry ARN: " + arn, 400);
+ }
+ String name = arn.substring(slash + "registry/".length());
+ if (name.isBlank()) {
+ throw new AwsException("InvalidInputException", "Invalid registry ARN: " + arn, 400);
+ }
+ return name;
+ }
+
+ private String buildRegistryArn(String region, String name) {
+ return regionResolver.buildArn("glue", region, "registry/" + name);
+ }
+
+ private String buildSchemaArn(String region, String registryName, String schemaName) {
+ return regionResolver.buildArn("glue", region, "schema/" + registryName + "/" + schemaName);
+ }
+
+ private static String schemaKey(String registryName, String schemaName) {
+ return registryName + ":" + schemaName;
+ }
+
+ private void validateName(String name, String field) {
+ if (name == null || name.isBlank()) {
+ throw new AwsException("InvalidInputException", field + " is required", 400);
+ }
+ if (name.length() > NAME_MAX_LENGTH) {
+ throw new AwsException("InvalidInputException", field + " exceeds " + NAME_MAX_LENGTH + " characters", 400);
+ }
+ if (!NAME_PATTERN.matcher(name).matches()) {
+ throw new AwsException("InvalidInputException",
+ field + " must match " + NAME_PATTERN.pattern(), 400);
+ }
+ }
+
+ private void validateDataFormat(String dataFormat) {
+ if (dataFormat == null || !DATA_FORMATS.contains(dataFormat)) {
+ throw new AwsException("InvalidInputException",
+ "DataFormat must be one of " + DATA_FORMATS, 400);
+ }
+ }
+
+ private void validateCompatibility(String compatibility) {
+ if (!COMPATIBILITY_MODES.contains(compatibility)) {
+ throw new AwsException("InvalidInputException",
+ "Compatibility must be one of " + COMPATIBILITY_MODES, 400);
+ }
+ }
+
+ private void validateDefinitionRequired(String definition) {
+ if (definition == null || definition.isBlank()) {
+ throw new AwsException("InvalidInputException", "SchemaDefinition is required", 400);
+ }
+ if (definition.length() > MAX_SCHEMA_DEFINITION_LENGTH) {
+ throw new AwsException("InvalidInputException",
+ "SchemaDefinition exceeds " + MAX_SCHEMA_DEFINITION_LENGTH + " characters", 400);
+ }
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/SchemaCompatibilityChecker.java b/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/SchemaCompatibilityChecker.java
new file mode 100644
index 0000000000..0063973af7
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/SchemaCompatibilityChecker.java
@@ -0,0 +1,146 @@
+package io.github.hectorvent.floci.services.glue.schemaregistry;
+
+import io.apicurio.registry.content.ContentHandle;
+import io.apicurio.registry.content.canon.AvroContentCanonicalizer;
+import io.apicurio.registry.content.canon.ContentCanonicalizer;
+import io.apicurio.registry.content.canon.JsonContentCanonicalizer;
+import io.apicurio.registry.content.canon.ProtobufContentCanonicalizer;
+import io.apicurio.registry.rules.compatibility.AvroCompatibilityChecker;
+import io.apicurio.registry.rules.compatibility.CompatibilityChecker;
+import io.apicurio.registry.rules.compatibility.CompatibilityDifference;
+import io.apicurio.registry.rules.compatibility.CompatibilityExecutionResult;
+import io.apicurio.registry.rules.compatibility.CompatibilityLevel;
+import io.apicurio.registry.rules.compatibility.JsonSchemaCompatibilityChecker;
+import io.apicurio.registry.rules.compatibility.ProtobufCompatibilityChecker;
+import io.apicurio.registry.rules.validity.AvroContentValidator;
+import io.apicurio.registry.rules.validity.ContentValidator;
+import io.apicurio.registry.rules.validity.JsonSchemaContentValidator;
+import io.apicurio.registry.rules.validity.ProtobufContentValidator;
+import io.apicurio.registry.rules.validity.ValidityLevel;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * Glue → Apicurio adapter for schema compatibility, validation, and canonicalization.
+ * Pure utility — no CDI. Stateless.
+ */
+public final class SchemaCompatibilityChecker {
+
+ public record Result(boolean compatible, String reason) {
+ public static Result ok() {
+ return new Result(true, null);
+ }
+ }
+
+ private SchemaCompatibilityChecker() {}
+
+ /**
+ * Check whether {@code newDefinition} is compatible with {@code existingDefinitions}
+ * under the given Glue compatibility {@code mode}.
+ *
+ * {@code existingDefinitions} must be ordered by version ascending (oldest first,
+ * latest last). For non-transitive modes (BACKWARD/FORWARD/FULL) only the latest
+ * existing version is compared; for transitive modes (BACKWARD_ALL/FORWARD_ALL/FULL_ALL)
+ * every prior version is compared.
+ */
+ public static Result check(String mode, List existingDefinitions, String newDefinition, String dataFormat) {
+ if (mode == null || existingDefinitions == null || existingDefinitions.isEmpty()) {
+ return Result.ok();
+ }
+ if ("NONE".equals(mode) || "DISABLED".equals(mode)) {
+ return Result.ok();
+ }
+ CompatibilityLevel level = toApicurioLevel(mode);
+ CompatibilityChecker checker = checkerFor(dataFormat);
+
+ List existing = existingDefinitions.stream()
+ .map(ContentHandle::create)
+ .collect(Collectors.toList());
+ ContentHandle proposed = ContentHandle.create(newDefinition);
+
+ CompatibilityExecutionResult result = checker.testCompatibility(level, existing, proposed, Map.of());
+ if (result.isCompatible()) {
+ return Result.ok();
+ }
+ return new Result(false, formatDifferences(result));
+ }
+
+ public static String canonicalize(String definition, String dataFormat) {
+ ContentCanonicalizer canon = canonicalizerFor(dataFormat);
+ ContentHandle handle = ContentHandle.create(definition);
+ return canon.canonicalize(handle, Map.of()).content();
+ }
+
+ /**
+ * Validate that {@code definition} is parseable for the declared {@code dataFormat}.
+ * @return null when valid; an error message when invalid.
+ */
+ public static String validateDefinition(String definition, String dataFormat) {
+ ContentValidator validator = validatorFor(dataFormat);
+ try {
+ validator.validate(ValidityLevel.SYNTAX_ONLY, ContentHandle.create(definition), Map.of());
+ return null;
+ } catch (RuntimeException e) {
+ return e.getMessage() != null ? e.getMessage() : e.getClass().getSimpleName();
+ }
+ }
+
+ private static CompatibilityLevel toApicurioLevel(String glueMode) {
+ return switch (glueMode) {
+ case "NONE", "DISABLED" -> CompatibilityLevel.NONE;
+ case "BACKWARD" -> CompatibilityLevel.BACKWARD;
+ case "BACKWARD_ALL" -> CompatibilityLevel.BACKWARD_TRANSITIVE;
+ case "FORWARD" -> CompatibilityLevel.FORWARD;
+ case "FORWARD_ALL" -> CompatibilityLevel.FORWARD_TRANSITIVE;
+ case "FULL" -> CompatibilityLevel.FULL;
+ case "FULL_ALL" -> CompatibilityLevel.FULL_TRANSITIVE;
+ default -> throw new IllegalArgumentException("Unknown compatibility mode: " + glueMode);
+ };
+ }
+
+ private static CompatibilityChecker checkerFor(String dataFormat) {
+ return switch (dataFormat) {
+ case "AVRO" -> new AvroCompatibilityChecker();
+ case "JSON" -> new JsonSchemaCompatibilityChecker();
+ case "PROTOBUF" -> new ProtobufCompatibilityChecker();
+ default -> throw new IllegalArgumentException("Unsupported DataFormat: " + dataFormat);
+ };
+ }
+
+ private static ContentCanonicalizer canonicalizerFor(String dataFormat) {
+ return switch (dataFormat) {
+ case "AVRO" -> new AvroContentCanonicalizer();
+ case "JSON" -> new JsonContentCanonicalizer();
+ case "PROTOBUF" -> new ProtobufContentCanonicalizer();
+ default -> throw new IllegalArgumentException("Unsupported DataFormat: " + dataFormat);
+ };
+ }
+
+ private static ContentValidator validatorFor(String dataFormat) {
+ return switch (dataFormat) {
+ case "AVRO" -> new AvroContentValidator();
+ case "JSON" -> new JsonSchemaContentValidator();
+ case "PROTOBUF" -> new ProtobufContentValidator();
+ default -> throw new IllegalArgumentException("Unsupported DataFormat: " + dataFormat);
+ };
+ }
+
+ private static String formatDifferences(CompatibilityExecutionResult result) {
+ if (result.getIncompatibleDifferences() == null || result.getIncompatibleDifferences().isEmpty()) {
+ return "Schema is incompatible";
+ }
+ return result.getIncompatibleDifferences().stream()
+ .map(d -> {
+ var rv = d.asRuleViolation();
+ String desc = rv != null ? rv.getDescription() : null;
+ String ctx = rv != null ? rv.getContext() : null;
+ if (desc == null) {
+ return d.toString();
+ }
+ return ctx == null ? desc : desc + " at " + ctx;
+ })
+ .collect(Collectors.joining("; "));
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/SchemaToColumnsConverter.java b/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/SchemaToColumnsConverter.java
new file mode 100644
index 0000000000..85de4a3f8b
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/SchemaToColumnsConverter.java
@@ -0,0 +1,267 @@
+package io.github.hectorvent.floci.services.glue.schemaregistry;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.squareup.wire.schema.Field;
+import com.squareup.wire.schema.Location;
+import com.squareup.wire.schema.internal.parser.FieldElement;
+import com.squareup.wire.schema.internal.parser.MessageElement;
+import com.squareup.wire.schema.internal.parser.ProtoFileElement;
+import com.squareup.wire.schema.internal.parser.ProtoParser;
+import com.squareup.wire.schema.internal.parser.TypeElement;
+import io.github.hectorvent.floci.services.glue.model.Column;
+import org.apache.avro.LogicalType;
+import org.apache.avro.LogicalTypes;
+import org.apache.avro.Schema;
+import org.jboss.logging.Logger;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Converts a registered schema definition (Avro / JSON Schema / Protobuf source) into a list
+ * of Glue Catalog {@link Column} objects with Hive-style type strings.
+ *
+ * Top-level fields only — no flattening of nested records. Unknown / unsupported types
+ * fall back to {@code string}. Parse failures log a warning and return an empty list (the
+ * Catalog read should still succeed).
+ */
+public final class SchemaToColumnsConverter {
+
+ private static final Logger LOG = Logger.getLogger(SchemaToColumnsConverter.class);
+ private static final ObjectMapper MAPPER = new ObjectMapper();
+
+ private SchemaToColumnsConverter() {}
+
+ public static List toColumns(String dataFormat, String definition) {
+ if (dataFormat == null || definition == null || definition.isBlank()) {
+ return List.of();
+ }
+ try {
+ return switch (dataFormat) {
+ case "AVRO" -> avroColumns(definition);
+ case "JSON" -> jsonColumns(definition);
+ case "PROTOBUF" -> protobufColumns(definition);
+ default -> List.of();
+ };
+ } catch (RuntimeException e) {
+ LOG.warnv("Failed to convert {0} schema to columns: {1}", dataFormat, e.getMessage());
+ return List.of();
+ }
+ }
+
+ // ---- Avro -----------------------------------------------------------
+
+ private static List avroColumns(String definition) {
+ Schema schema = new Schema.Parser().parse(definition);
+ if (schema.getType() != Schema.Type.RECORD) {
+ return List.of();
+ }
+ List out = new ArrayList<>(schema.getFields().size());
+ for (Schema.Field field : schema.getFields()) {
+ out.add(new Column(field.name(), avroToHive(field.schema())));
+ }
+ return out;
+ }
+
+ private static String avroToHive(Schema s) {
+ String logical = avroLogicalTypeToHive(s);
+ if (logical != null) {
+ return logical;
+ }
+ return switch (s.getType()) {
+ case LONG -> "bigint";
+ case INT -> "int";
+ case STRING, ENUM -> "string";
+ case BOOLEAN -> "boolean";
+ case DOUBLE -> "double";
+ case FLOAT -> "float";
+ case BYTES, FIXED -> "binary";
+ case NULL -> "string";
+ case UNION -> avroUnionToHive(s);
+ case RECORD -> avroRecordToHive(s);
+ case ARRAY -> "array<" + avroToHive(s.getElementType()) + ">";
+ case MAP -> "map";
+ };
+ }
+
+ private static String avroLogicalTypeToHive(Schema s) {
+ LogicalType logical = s.getLogicalType();
+ if (logical == null) {
+ return null;
+ }
+ if (logical instanceof LogicalTypes.Decimal d) {
+ return "decimal(" + d.getPrecision() + "," + d.getScale() + ")";
+ }
+ return switch (logical.getName()) {
+ case "date" -> "date";
+ case "timestamp-millis", "timestamp-micros",
+ "local-timestamp-millis", "local-timestamp-micros" -> "timestamp";
+ // Hive has no TIME type — surface as string so downstream readers see the raw value.
+ case "time-millis", "time-micros", "uuid" -> "string";
+ default -> null;
+ };
+ }
+
+ private static String avroUnionToHive(Schema s) {
+ List types = s.getTypes();
+ if (types.size() == 2) {
+ if (types.get(0).getType() == Schema.Type.NULL) return avroToHive(types.get(1));
+ if (types.get(1).getType() == Schema.Type.NULL) return avroToHive(types.get(0));
+ }
+ return "string";
+ }
+
+ private static String avroRecordToHive(Schema s) {
+ StringBuilder sb = new StringBuilder("struct<");
+ boolean first = true;
+ for (Schema.Field f : s.getFields()) {
+ if (!first) sb.append(",");
+ sb.append(f.name()).append(":").append(avroToHive(f.schema()));
+ first = false;
+ }
+ return sb.append(">").toString();
+ }
+
+ // ---- JSON Schema ----------------------------------------------------
+
+ private static List jsonColumns(String definition) {
+ JsonNode root;
+ try {
+ root = MAPPER.readTree(definition);
+ } catch (Exception e) {
+ LOG.warnv("Invalid JSON Schema: {0}", e.getMessage());
+ return List.of();
+ }
+ if (!"object".equals(root.path("type").asText())) {
+ return List.of();
+ }
+ JsonNode properties = root.get("properties");
+ if (properties == null || !properties.isObject()) {
+ return List.of();
+ }
+ List out = new ArrayList<>();
+ for (Iterator> it = properties.fields(); it.hasNext(); ) {
+ Map.Entry e = it.next();
+ out.add(new Column(e.getKey(), jsonToHive(e.getValue())));
+ }
+ return out;
+ }
+
+ private static String jsonToHive(JsonNode node) {
+ String t = node.path("type").asText("string");
+ return switch (t) {
+ case "string" -> "string";
+ case "integer" -> "bigint";
+ case "number" -> "double";
+ case "boolean" -> "boolean";
+ case "array" -> {
+ JsonNode items = node.get("items");
+ yield "array<" + (items != null && items.isObject() ? jsonToHive(items) : "string") + ">";
+ }
+ case "object" -> jsonObjectToHive(node);
+ default -> "string";
+ };
+ }
+
+ private static String jsonObjectToHive(JsonNode node) {
+ JsonNode properties = node.get("properties");
+ if (properties == null || !properties.isObject() || !properties.fields().hasNext()) {
+ return "struct<>";
+ }
+ StringBuilder sb = new StringBuilder("struct<");
+ boolean first = true;
+ for (Iterator> it = properties.fields(); it.hasNext(); ) {
+ Map.Entry e = it.next();
+ if (!first) sb.append(",");
+ sb.append(e.getKey()).append(":").append(jsonToHive(e.getValue()));
+ first = false;
+ }
+ return sb.append(">").toString();
+ }
+
+ // ---- Protobuf (parsed via Wire — bypasses Apicurio's well-known-deps issue) -------
+
+ private static List protobufColumns(String definition) {
+ ProtoFileElement file;
+ try {
+ Location loc = Location.get("schema.proto");
+ file = new ProtoParser(loc, definition.toCharArray()).readProtoFile();
+ } catch (Exception e) {
+ LOG.warnv("Invalid Protobuf schema: {0}", e.getMessage());
+ return List.of();
+ }
+ MessageElement target = firstMessage(file.getTypes());
+ if (target == null) {
+ return List.of();
+ }
+ Map nestedByName = collectMessages(file.getTypes(), new HashMap<>());
+ List out = new ArrayList<>(target.getFields().size());
+ for (FieldElement f : target.getFields()) {
+ out.add(new Column(f.getName(), protobufToHive(f, nestedByName)));
+ }
+ return out;
+ }
+
+ private static MessageElement firstMessage(List types) {
+ for (TypeElement t : types) {
+ if (t instanceof MessageElement m) return m;
+ }
+ return null;
+ }
+
+ private static Map collectMessages(List types, Map acc) {
+ for (TypeElement t : types) {
+ if (t instanceof MessageElement m) {
+ acc.put(m.getName(), m);
+ collectMessages(m.getNestedTypes(), acc);
+ }
+ }
+ return acc;
+ }
+
+ private static String protobufToHive(FieldElement field, Map messages) {
+ String base = protobufBaseTypeToHive(field.getType(), messages);
+ return field.getLabel() == Field.Label.REPEATED ? "array<" + base + ">" : base;
+ }
+
+ private static String protobufBaseTypeToHive(String type, Map messages) {
+ if (type.startsWith("map<") && type.endsWith(">")) {
+ // Wire preserves the literal "map" syntax in field types.
+ String inner = type.substring(4, type.length() - 1);
+ int comma = inner.indexOf(',');
+ if (comma > 0) {
+ String valueType = inner.substring(comma + 1).trim();
+ return "map";
+ }
+ return "map";
+ }
+ return switch (type) {
+ case "int32", "uint32", "sint32", "fixed32", "sfixed32" -> "int";
+ case "int64", "uint64", "sint64", "fixed64", "sfixed64" -> "bigint";
+ case "float" -> "float";
+ case "double" -> "double";
+ case "bool" -> "boolean";
+ case "string" -> "string";
+ case "bytes" -> "binary";
+ default -> {
+ MessageElement nested = messages.get(type);
+ yield nested != null ? protobufMessageToHive(nested, messages) : "string";
+ }
+ };
+ }
+
+ private static String protobufMessageToHive(MessageElement msg, Map messages) {
+ StringBuilder sb = new StringBuilder("struct<");
+ boolean first = true;
+ for (FieldElement f : msg.getFields()) {
+ if (!first) sb.append(",");
+ sb.append(f.getName()).append(":").append(protobufToHive(f, messages));
+ first = false;
+ }
+ return sb.append(">").toString();
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/model/MetadataInfo.java b/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/model/MetadataInfo.java
new file mode 100644
index 0000000000..e455e6ef01
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/model/MetadataInfo.java
@@ -0,0 +1,66 @@
+package io.github.hectorvent.floci.services.glue.schemaregistry.model;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+import java.time.Instant;
+import java.util.List;
+
+@RegisterForReflection
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class MetadataInfo {
+
+ @JsonProperty("MetadataValue")
+ private String metadataValue;
+
+ @JsonProperty("CreatedTime")
+ @JsonFormat(shape = JsonFormat.Shape.STRING)
+ private Instant createdTime;
+
+ @JsonProperty("OtherMetadataValueList")
+ private List otherMetadataValueList;
+
+ public MetadataInfo() {}
+
+ public MetadataInfo(String metadataValue, Instant createdTime) {
+ this.metadataValue = metadataValue;
+ this.createdTime = createdTime;
+ }
+
+ public String getMetadataValue() { return metadataValue; }
+ public void setMetadataValue(String metadataValue) { this.metadataValue = metadataValue; }
+
+ public Instant getCreatedTime() { return createdTime; }
+ public void setCreatedTime(Instant createdTime) { this.createdTime = createdTime; }
+
+ public List getOtherMetadataValueList() { return otherMetadataValueList; }
+ public void setOtherMetadataValueList(List otherMetadataValueList) {
+ this.otherMetadataValueList = otherMetadataValueList;
+ }
+
+ @RegisterForReflection
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ public static class OtherMetadataValueListItem {
+ @JsonProperty("MetadataValue")
+ private String metadataValue;
+
+ @JsonProperty("CreatedTime")
+ @JsonFormat(shape = JsonFormat.Shape.STRING)
+ private Instant createdTime;
+
+ public OtherMetadataValueListItem() {}
+
+ public OtherMetadataValueListItem(String metadataValue, Instant createdTime) {
+ this.metadataValue = metadataValue;
+ this.createdTime = createdTime;
+ }
+
+ public String getMetadataValue() { return metadataValue; }
+ public void setMetadataValue(String metadataValue) { this.metadataValue = metadataValue; }
+
+ public Instant getCreatedTime() { return createdTime; }
+ public void setCreatedTime(Instant createdTime) { this.createdTime = createdTime; }
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/model/Registry.java b/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/model/Registry.java
new file mode 100644
index 0000000000..c4140cda4f
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/model/Registry.java
@@ -0,0 +1,67 @@
+package io.github.hectorvent.floci.services.glue.schemaregistry.model;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+import java.time.Instant;
+import java.util.Map;
+
+@RegisterForReflection
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class Registry {
+
+ @JsonProperty("RegistryName")
+ private String registryName;
+
+ @JsonProperty("RegistryArn")
+ private String registryArn;
+
+ @JsonProperty("Description")
+ private String description;
+
+ @JsonProperty("Status")
+ private String status;
+
+ @JsonProperty("CreatedTime")
+ @JsonFormat(shape = JsonFormat.Shape.STRING)
+ private Instant createdTime;
+
+ @JsonProperty("UpdatedTime")
+ @JsonFormat(shape = JsonFormat.Shape.STRING)
+ private Instant updatedTime;
+
+ @JsonProperty("Tags")
+ private Map tags;
+
+ public Registry() {}
+
+ public Registry(String registryName) {
+ this.registryName = registryName;
+ this.createdTime = Instant.now();
+ this.updatedTime = this.createdTime;
+ this.status = "AVAILABLE";
+ }
+
+ public String getRegistryName() { return registryName; }
+ public void setRegistryName(String registryName) { this.registryName = registryName; }
+
+ public String getRegistryArn() { return registryArn; }
+ public void setRegistryArn(String registryArn) { this.registryArn = registryArn; }
+
+ public String getDescription() { return description; }
+ public void setDescription(String description) { this.description = description; }
+
+ public String getStatus() { return status; }
+ public void setStatus(String status) { this.status = status; }
+
+ public Instant getCreatedTime() { return createdTime; }
+ public void setCreatedTime(Instant createdTime) { this.createdTime = createdTime; }
+
+ public Instant getUpdatedTime() { return updatedTime; }
+ public void setUpdatedTime(Instant updatedTime) { this.updatedTime = updatedTime; }
+
+ public Map getTags() { return tags; }
+ public void setTags(Map tags) { this.tags = tags; }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/model/RegistryId.java b/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/model/RegistryId.java
new file mode 100644
index 0000000000..80ace4f96d
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/model/RegistryId.java
@@ -0,0 +1,29 @@
+package io.github.hectorvent.floci.services.glue.schemaregistry.model;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+@RegisterForReflection
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class RegistryId {
+
+ @JsonProperty("RegistryName")
+ private String registryName;
+
+ @JsonProperty("RegistryArn")
+ private String registryArn;
+
+ public RegistryId() {}
+
+ public RegistryId(String registryName, String registryArn) {
+ this.registryName = registryName;
+ this.registryArn = registryArn;
+ }
+
+ public String getRegistryName() { return registryName; }
+ public void setRegistryName(String registryName) { this.registryName = registryName; }
+
+ public String getRegistryArn() { return registryArn; }
+ public void setRegistryArn(String registryArn) { this.registryArn = registryArn; }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/model/Schema.java b/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/model/Schema.java
new file mode 100644
index 0000000000..0e61d396b3
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/model/Schema.java
@@ -0,0 +1,102 @@
+package io.github.hectorvent.floci.services.glue.schemaregistry.model;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+import java.time.Instant;
+import java.util.Map;
+
+@RegisterForReflection
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class Schema {
+
+ @JsonProperty("RegistryName")
+ private String registryName;
+
+ @JsonProperty("RegistryArn")
+ private String registryArn;
+
+ @JsonProperty("SchemaName")
+ private String schemaName;
+
+ @JsonProperty("SchemaArn")
+ private String schemaArn;
+
+ @JsonProperty("Description")
+ private String description;
+
+ @JsonProperty("DataFormat")
+ private String dataFormat;
+
+ @JsonProperty("Compatibility")
+ private String compatibility;
+
+ @JsonProperty("SchemaStatus")
+ private String schemaStatus;
+
+ @JsonProperty("SchemaCheckpoint")
+ private Long schemaCheckpoint;
+
+ @JsonProperty("LatestSchemaVersion")
+ private Long latestSchemaVersion;
+
+ @JsonProperty("NextSchemaVersion")
+ private Long nextSchemaVersion;
+
+ @JsonProperty("CreatedTime")
+ @JsonFormat(shape = JsonFormat.Shape.STRING)
+ private Instant createdTime;
+
+ @JsonProperty("UpdatedTime")
+ @JsonFormat(shape = JsonFormat.Shape.STRING)
+ private Instant updatedTime;
+
+ @JsonProperty("Tags")
+ private Map tags;
+
+ public Schema() {}
+
+ public String getRegistryName() { return registryName; }
+ public void setRegistryName(String registryName) { this.registryName = registryName; }
+
+ public String getRegistryArn() { return registryArn; }
+ public void setRegistryArn(String registryArn) { this.registryArn = registryArn; }
+
+ public String getSchemaName() { return schemaName; }
+ public void setSchemaName(String schemaName) { this.schemaName = schemaName; }
+
+ public String getSchemaArn() { return schemaArn; }
+ public void setSchemaArn(String schemaArn) { this.schemaArn = schemaArn; }
+
+ public String getDescription() { return description; }
+ public void setDescription(String description) { this.description = description; }
+
+ public String getDataFormat() { return dataFormat; }
+ public void setDataFormat(String dataFormat) { this.dataFormat = dataFormat; }
+
+ public String getCompatibility() { return compatibility; }
+ public void setCompatibility(String compatibility) { this.compatibility = compatibility; }
+
+ public String getSchemaStatus() { return schemaStatus; }
+ public void setSchemaStatus(String schemaStatus) { this.schemaStatus = schemaStatus; }
+
+ public Long getSchemaCheckpoint() { return schemaCheckpoint; }
+ public void setSchemaCheckpoint(Long schemaCheckpoint) { this.schemaCheckpoint = schemaCheckpoint; }
+
+ public Long getLatestSchemaVersion() { return latestSchemaVersion; }
+ public void setLatestSchemaVersion(Long latestSchemaVersion) { this.latestSchemaVersion = latestSchemaVersion; }
+
+ public Long getNextSchemaVersion() { return nextSchemaVersion; }
+ public void setNextSchemaVersion(Long nextSchemaVersion) { this.nextSchemaVersion = nextSchemaVersion; }
+
+ public Instant getCreatedTime() { return createdTime; }
+ public void setCreatedTime(Instant createdTime) { this.createdTime = createdTime; }
+
+ public Instant getUpdatedTime() { return updatedTime; }
+ public void setUpdatedTime(Instant updatedTime) { this.updatedTime = updatedTime; }
+
+ public Map getTags() { return tags; }
+ public void setTags(Map tags) { this.tags = tags; }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/model/SchemaId.java b/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/model/SchemaId.java
new file mode 100644
index 0000000000..dd8105cc33
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/model/SchemaId.java
@@ -0,0 +1,36 @@
+package io.github.hectorvent.floci.services.glue.schemaregistry.model;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+@RegisterForReflection
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class SchemaId {
+
+ @JsonProperty("SchemaArn")
+ private String schemaArn;
+
+ @JsonProperty("SchemaName")
+ private String schemaName;
+
+ @JsonProperty("RegistryName")
+ private String registryName;
+
+ public SchemaId() {}
+
+ public SchemaId(String registryName, String schemaName, String schemaArn) {
+ this.registryName = registryName;
+ this.schemaName = schemaName;
+ this.schemaArn = schemaArn;
+ }
+
+ public String getSchemaArn() { return schemaArn; }
+ public void setSchemaArn(String schemaArn) { this.schemaArn = schemaArn; }
+
+ public String getSchemaName() { return schemaName; }
+ public void setSchemaName(String schemaName) { this.schemaName = schemaName; }
+
+ public String getRegistryName() { return registryName; }
+ public void setRegistryName(String registryName) { this.registryName = registryName; }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/model/SchemaVersion.java b/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/model/SchemaVersion.java
new file mode 100644
index 0000000000..88135d122b
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/glue/schemaregistry/model/SchemaVersion.java
@@ -0,0 +1,58 @@
+package io.github.hectorvent.floci.services.glue.schemaregistry.model;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+import java.time.Instant;
+
+@RegisterForReflection
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class SchemaVersion {
+
+ @JsonProperty("SchemaVersionId")
+ private String schemaVersionId;
+
+ @JsonProperty("SchemaArn")
+ private String schemaArn;
+
+ @JsonProperty("VersionNumber")
+ private Long versionNumber;
+
+ @JsonProperty("Status")
+ private String status;
+
+ @JsonProperty("SchemaDefinition")
+ private String schemaDefinition;
+
+ @JsonProperty("DataFormat")
+ private String dataFormat;
+
+ @JsonProperty("CreatedTime")
+ @JsonFormat(shape = JsonFormat.Shape.STRING)
+ private Instant createdTime;
+
+ public SchemaVersion() {}
+
+ public String getSchemaVersionId() { return schemaVersionId; }
+ public void setSchemaVersionId(String schemaVersionId) { this.schemaVersionId = schemaVersionId; }
+
+ public String getSchemaArn() { return schemaArn; }
+ public void setSchemaArn(String schemaArn) { this.schemaArn = schemaArn; }
+
+ public Long getVersionNumber() { return versionNumber; }
+ public void setVersionNumber(Long versionNumber) { this.versionNumber = versionNumber; }
+
+ public String getStatus() { return status; }
+ public void setStatus(String status) { this.status = status; }
+
+ public String getSchemaDefinition() { return schemaDefinition; }
+ public void setSchemaDefinition(String schemaDefinition) { this.schemaDefinition = schemaDefinition; }
+
+ public String getDataFormat() { return dataFormat; }
+ public void setDataFormat(String dataFormat) { this.dataFormat = dataFormat; }
+
+ public Instant getCreatedTime() { return createdTime; }
+ public void setCreatedTime(Instant createdTime) { this.createdTime = createdTime; }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/glue/GlueCatalogSchemaBindingIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/glue/GlueCatalogSchemaBindingIntegrationTest.java
new file mode 100644
index 0000000000..641a8c3417
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/glue/GlueCatalogSchemaBindingIntegrationTest.java
@@ -0,0 +1,154 @@
+package io.github.hectorvent.floci.services.glue;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.notNullValue;
+
+@QuarkusTest
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+class GlueCatalogSchemaBindingIntegrationTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String REGISTRY = "binding-registry";
+ private static final String SCHEMA = "users";
+ private static final String DATABASE = "binding-db";
+ private static final String TABLE = "users_table";
+
+ private static final String AVRO_V1 =
+ "{\\\"type\\\":\\\"record\\\",\\\"name\\\":\\\"User\\\",\\\"namespace\\\":\\\"x\\\","
+ + "\\\"fields\\\":[{\\\"name\\\":\\\"id\\\",\\\"type\\\":\\\"long\\\"},"
+ + "{\\\"name\\\":\\\"name\\\",\\\"type\\\":\\\"string\\\"}]}";
+
+ private static final String AVRO_V2 =
+ "{\\\"type\\\":\\\"record\\\",\\\"name\\\":\\\"User\\\",\\\"namespace\\\":\\\"x\\\","
+ + "\\\"fields\\\":[{\\\"name\\\":\\\"id\\\",\\\"type\\\":\\\"long\\\"},"
+ + "{\\\"name\\\":\\\"name\\\",\\\"type\\\":\\\"string\\\"},"
+ + "{\\\"name\\\":\\\"email\\\",\\\"type\\\":[\\\"null\\\",\\\"string\\\"],\\\"default\\\":null}]}";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ @Test
+ @Order(1)
+ void seed_registryAndSchemaAndDatabase() {
+ given().contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSGlue.CreateRegistry")
+ .body("{ \"RegistryName\": \"" + REGISTRY + "\" }")
+ .when().post("/").then().statusCode(200);
+
+ given().contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSGlue.CreateSchema")
+ .body("{"
+ + " \"RegistryId\": { \"RegistryName\": \"" + REGISTRY + "\" },"
+ + " \"SchemaName\": \"" + SCHEMA + "\","
+ + " \"DataFormat\": \"AVRO\","
+ + " \"Compatibility\": \"BACKWARD\","
+ + " \"SchemaDefinition\": \"" + AVRO_V1 + "\""
+ + " }")
+ .when().post("/").then().statusCode(200);
+
+ given().contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSGlue.CreateDatabase")
+ .body("{ \"DatabaseInput\": { \"Name\": \"" + DATABASE + "\" } }")
+ .when().post("/").then().statusCode(200);
+ }
+
+ @Test
+ @Order(2)
+ void createTableWithSchemaReferenceLatest() {
+ given().contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSGlue.CreateTable")
+ .body("{"
+ + " \"DatabaseName\": \"" + DATABASE + "\","
+ + " \"TableInput\": {"
+ + " \"Name\": \"" + TABLE + "\","
+ + " \"StorageDescriptor\": {"
+ + " \"Location\": \"s3://bucket/users/\","
+ + " \"Columns\": [],"
+ + " \"SchemaReference\": {"
+ + " \"SchemaId\": { \"RegistryName\": \"" + REGISTRY + "\", \"SchemaName\": \"" + SCHEMA + "\" }"
+ + " }"
+ + " }"
+ + " } }")
+ .when().post("/").then().statusCode(200);
+ }
+
+ @Test
+ @Order(3)
+ void getTableReturnsColumnsDerivedFromV1() {
+ given().contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSGlue.GetTable")
+ .body("{ \"DatabaseName\": \"" + DATABASE + "\", \"Name\": \"" + TABLE + "\" }")
+ .when().post("/").then()
+ .statusCode(200)
+ .body("Table.Name", equalTo(TABLE))
+ .body("Table.StorageDescriptor.Columns", hasSize(2))
+ .body("Table.StorageDescriptor.Columns[0].Name", equalTo("id"))
+ .body("Table.StorageDescriptor.Columns[0].Type", equalTo("bigint"))
+ .body("Table.StorageDescriptor.Columns[1].Name", equalTo("name"))
+ .body("Table.StorageDescriptor.Columns[1].Type", equalTo("string"))
+ .body("Table.StorageDescriptor.SchemaReference", notNullValue());
+ }
+
+ @Test
+ @Order(4)
+ void registerV2AndGetTableReflectsLatestSchema() {
+ given().contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSGlue.RegisterSchemaVersion")
+ .body("{ \"SchemaId\": { \"RegistryName\": \"" + REGISTRY + "\", \"SchemaName\": \"" + SCHEMA + "\" },"
+ + " \"SchemaDefinition\": \"" + AVRO_V2 + "\" }")
+ .when().post("/").then().statusCode(200);
+
+ given().contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSGlue.GetTable")
+ .body("{ \"DatabaseName\": \"" + DATABASE + "\", \"Name\": \"" + TABLE + "\" }")
+ .when().post("/").then()
+ .statusCode(200)
+ .body("Table.StorageDescriptor.Columns", hasSize(3))
+ .body("Table.StorageDescriptor.Columns[2].Name", equalTo("email"))
+ .body("Table.StorageDescriptor.Columns[2].Type", equalTo("string"));
+ }
+
+ @Test
+ @Order(5)
+ void createTableWithBrokenReferenceReturns400() {
+ given().contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSGlue.CreateTable")
+ .body("{"
+ + " \"DatabaseName\": \"" + DATABASE + "\","
+ + " \"TableInput\": {"
+ + " \"Name\": \"broken-table\","
+ + " \"StorageDescriptor\": {"
+ + " \"Location\": \"s3://bucket/x/\","
+ + " \"SchemaReference\": {"
+ + " \"SchemaId\": { \"RegistryName\": \"" + REGISTRY + "\", \"SchemaName\": \"does-not-exist\" }"
+ + " }"
+ + " }"
+ + " } }")
+ .when().post("/").then()
+ .statusCode(400)
+ .body("__type", equalTo("EntityNotFoundException"));
+ }
+
+ @Test
+ @Order(6)
+ void getTablesAppliesResolutionToEachTable() {
+ given().contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSGlue.GetTables")
+ .body("{ \"DatabaseName\": \"" + DATABASE + "\" }")
+ .when().post("/").then()
+ .statusCode(200)
+ .body("TableList[0].StorageDescriptor.Columns", hasSize(3));
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/glue/GlueServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/glue/GlueServiceTest.java
new file mode 100644
index 0000000000..698d312224
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/glue/GlueServiceTest.java
@@ -0,0 +1,207 @@
+package io.github.hectorvent.floci.services.glue;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.storage.InMemoryStorage;
+import io.github.hectorvent.floci.core.storage.StorageBackend;
+import io.github.hectorvent.floci.core.storage.StorageFactory;
+import io.github.hectorvent.floci.services.glue.model.Column;
+import io.github.hectorvent.floci.services.glue.model.Database;
+import io.github.hectorvent.floci.services.glue.model.Partition;
+import io.github.hectorvent.floci.services.glue.model.SchemaReference;
+import io.github.hectorvent.floci.services.glue.model.StorageDescriptor;
+import io.github.hectorvent.floci.services.glue.model.Table;
+import io.github.hectorvent.floci.services.glue.schemaregistry.GlueSchemaRegistryService;
+import io.github.hectorvent.floci.services.glue.schemaregistry.model.RegistryId;
+import io.github.hectorvent.floci.services.glue.schemaregistry.model.SchemaId;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class GlueServiceTest {
+
+ private static final String REGION = "us-east-1";
+ private static final String ACCOUNT_ID = "000000000000";
+
+ private static final String AVRO_V1 =
+ "{\"type\":\"record\",\"name\":\"User\",\"namespace\":\"x\","
+ + "\"fields\":[{\"name\":\"id\",\"type\":\"long\"}]}";
+
+ private static final String AVRO_V2 =
+ "{\"type\":\"record\",\"name\":\"User\",\"namespace\":\"x\","
+ + "\"fields\":[{\"name\":\"id\",\"type\":\"long\"},"
+ + "{\"name\":\"email\",\"type\":[\"null\",\"string\"],\"default\":null}]}";
+
+ private GlueService glueService;
+ private GlueSchemaRegistryService schemaRegistryService;
+
+ @BeforeEach
+ void setUp() {
+ RegionResolver regionResolver = new RegionResolver(REGION, ACCOUNT_ID);
+ StorageFactory storageFactory = new InMemoryStorageFactory();
+ schemaRegistryService = new GlueSchemaRegistryService(storageFactory, regionResolver);
+ glueService = new GlueService(
+ new InMemoryStorage(),
+ new InMemoryStorage(),
+ new InMemoryStorage(),
+ schemaRegistryService, regionResolver);
+ glueService.createDatabase(new Database("db1"));
+ }
+
+ @Test
+ void getTableWithoutSchemaReferenceReturnsColumnsUnchanged() {
+ Table table = new Table();
+ table.setName("plain");
+ StorageDescriptor sd = new StorageDescriptor();
+ sd.setColumns(java.util.List.of(new Column("a", "string")));
+ table.setStorageDescriptor(sd);
+ glueService.createTable("db1", table);
+
+ Table fetched = glueService.getTable("db1", "plain");
+
+ assertEquals(1, fetched.getStorageDescriptor().getColumns().size());
+ assertEquals("a", fetched.getStorageDescriptor().getColumns().get(0).getName());
+ assertNull(fetched.getStorageDescriptor().getSchemaReference());
+ }
+
+ @Test
+ void getTableWithValidSchemaReferenceReturnsDerivedColumns() {
+ schemaRegistryService.createRegistry("r1", null, null, REGION);
+ schemaRegistryService.createSchema(new RegistryId("r1", null),
+ "users", "AVRO", "BACKWARD", null, AVRO_V1, null, REGION);
+
+ Table table = tableReferencing("r1", "users", null, null);
+ glueService.createTable("db1", table);
+
+ Table fetched = glueService.getTable("db1", "withref");
+
+ assertEquals(1, fetched.getStorageDescriptor().getColumns().size());
+ assertEquals("id", fetched.getStorageDescriptor().getColumns().get(0).getName());
+ assertEquals("bigint", fetched.getStorageDescriptor().getColumns().get(0).getType());
+ assertNotNull(fetched.getStorageDescriptor().getSchemaReference());
+ }
+
+ @Test
+ void getTablePicksUpNewVersionWhenPinnedToLatest() {
+ schemaRegistryService.createRegistry("r1", null, null, REGION);
+ schemaRegistryService.createSchema(new RegistryId("r1", null),
+ "users", "AVRO", "BACKWARD", null, AVRO_V1, null, REGION);
+ Table storedTable = tableReferencing("r1", "users", null, null);
+ glueService.createTable("db1", storedTable);
+
+ Table firstFetch = glueService.getTable("db1", "withref");
+
+ assertEquals(1, firstFetch.getStorageDescriptor().getColumns().size());
+ assertTrue(storedTable.getStorageDescriptor().getColumns() == null
+ || storedTable.getStorageDescriptor().getColumns().isEmpty());
+
+ // Register v2 — adds optional email field.
+ schemaRegistryService.registerSchemaVersion(
+ new SchemaId("r1", "users", null), AVRO_V2, REGION);
+
+ Table fetched = glueService.getTable("db1", "withref");
+
+ assertEquals(2, fetched.getStorageDescriptor().getColumns().size());
+ assertEquals("email", fetched.getStorageDescriptor().getColumns().get(1).getName());
+ }
+
+ @Test
+ void getTablePinnedToVersionNumberStaysOnThatVersion() {
+ schemaRegistryService.createRegistry("r1", null, null, REGION);
+ schemaRegistryService.createSchema(new RegistryId("r1", null),
+ "users", "AVRO", "BACKWARD", null, AVRO_V1, null, REGION);
+ glueService.createTable("db1", tableReferencing("r1", "users", 1L, null));
+ schemaRegistryService.registerSchemaVersion(
+ new SchemaId("r1", "users", null), AVRO_V2, REGION);
+
+ Table fetched = glueService.getTable("db1", "withref");
+
+ assertEquals(1, fetched.getStorageDescriptor().getColumns().size(), "should still see v1");
+ }
+
+ @Test
+ void createTableWithBrokenSchemaReferenceThrows() {
+ Table table = tableReferencing("does-not-exist", "users", null, null);
+
+ AwsException ex = assertThrows(AwsException.class,
+ () -> glueService.createTable("db1", table));
+ assertEquals("EntityNotFoundException", ex.getErrorCode());
+ }
+
+ @Test
+ void getTableWithStaleSchemaReferenceReturnsTableTolerantly() {
+ schemaRegistryService.createRegistry("r1", null, null, REGION);
+ schemaRegistryService.createSchema(new RegistryId("r1", null),
+ "users", "AVRO", "BACKWARD", null, AVRO_V1, null, REGION);
+ glueService.createTable("db1", tableReferencing("r1", "users", null, null));
+
+ // Delete the underlying schema after the table was created.
+ schemaRegistryService.deleteSchema(new SchemaId("r1", "users", null), REGION);
+
+ Table fetched = glueService.getTable("db1", "withref");
+
+ // Tolerant path: table is returned, columns are whatever was stored at create
+ // time (in our case nothing — we never wrote columns explicitly).
+ assertNotNull(fetched);
+ assertNotNull(fetched.getStorageDescriptor().getSchemaReference());
+ assertTrue(fetched.getStorageDescriptor().getColumns() == null
+ || fetched.getStorageDescriptor().getColumns().isEmpty());
+ }
+
+ @Test
+ void getTablesAppliesResolutionToEachTable() {
+ schemaRegistryService.createRegistry("r1", null, null, REGION);
+ schemaRegistryService.createSchema(new RegistryId("r1", null),
+ "users", "AVRO", "BACKWARD", null, AVRO_V1, null, REGION);
+ glueService.createTable("db1", tableReferencing("r1", "users", null, null));
+ Table plain = new Table();
+ plain.setName("plain");
+ StorageDescriptor sd = new StorageDescriptor();
+ plain.setStorageDescriptor(sd);
+ glueService.createTable("db1", plain);
+
+ var tables = glueService.getTables("db1");
+
+ assertEquals(2, tables.size());
+ for (Table t : tables) {
+ if ("withref".equals(t.getName())) {
+ assertEquals(1, t.getStorageDescriptor().getColumns().size());
+ }
+ }
+ }
+
+ private Table tableReferencing(String registryName, String schemaName, Long versionNumber, String versionId) {
+ Table table = new Table();
+ table.setName("withref");
+ StorageDescriptor sd = new StorageDescriptor();
+ SchemaReference ref = new SchemaReference();
+ SchemaId schemaId = new SchemaId(registryName, schemaName, null);
+ ref.setSchemaId(schemaId);
+ ref.setSchemaVersionNumber(versionNumber);
+ ref.setSchemaVersionId(versionId);
+ sd.setSchemaReference(ref);
+ table.setStorageDescriptor(sd);
+ return table;
+ }
+
+ private static final class InMemoryStorageFactory extends StorageFactory {
+ private InMemoryStorageFactory() {
+ super(null, null);
+ }
+
+ @Override
+ public StorageBackend create(String serviceName,
+ String fileName,
+ TypeReference