Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TypedTabledEntity build #94

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ object TypedTabledEntity {
subVersions: Set[SchemaSubVersion],
schemas: NonEmptyList[SelfDescribingSchema[Schema]]
): Option[TypedTabledEntity] =
schemas
.traverse(sds => fieldFromSchema(tabledEntity, sds.schema).map((_, sds)))
schemas.toList
.flatMap { sds =>
fieldFromSchema(tabledEntity, sds.schema).map((_, sds))
}
.toNel
.map { nel =>
val (rootField, rootSchema) = nel.head
val tte = TypedTabledEntity(tabledEntity, rootField, Set(keyToSubVersion(rootSchema.self.schemaKey)), Nil)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#",
"self": {
"vendor": "myvendor",
"name": "test_empty_prop",
"format": "jsonschema",
"version": "1-0-0"
},
"properties": {},
"additionalProperties": false,
"type": "object"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#",
"self": {
"vendor": "myvendor",
"name": "test_empty_prop",
"format": "jsonschema",
"version": "1-0-1"
},
"properties": {
"myString": {"type": "string"}
},
"additionalProperties": false,
"type": "object"
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class NonAtomicFieldsSpec extends Specification with CatsEffect {
return nothing for the Iglu Central ad_break_end_event schema $ue4
return a JSON field for the Iglu Central anything-a schema $ue5
return a field prefixed with underscore if field starts with a digit $ueDigit
return a merged schema if the batch has a schema with empty properties and additionalProperties=false $emptyProp

when resolving for known schemas in contexts should
return an un-merged schema if the batch uses the first schema in a series $c1
Expand Down Expand Up @@ -229,6 +230,37 @@ class NonAtomicFieldsSpec extends Specification with CatsEffect {
}
}

def emptyProp = {
val tabledEntity = TabledEntity(TabledEntity.UnstructEvent, "myvendor", "test_empty_prop", 1)

val input = Map(
tabledEntity -> Set((0, 1), (0, 0))
)

val expected = {
val expectedStruct = Type.Struct(
NonEmptyVector.of(
Field("my_string", Type.String, Nullable).copy(accessors = Set("myString"))
)
)

val expectedField = Field("unstruct_event_myvendor_test_empty_prop_1", expectedStruct, Nullable, Set.empty)

TypedTabledEntity(
tabledEntity,
expectedField,
Set((0, 1)),
Nil
)
}

NonAtomicFields.resolveTypes(embeddedResolver, input, List.empty).map { case NonAtomicFields.Result(fields, failures) =>
(failures must beEmpty) and
(fields must haveSize(1)) and
(fields.head must beEqualTo(expected))
}
}

def c1 = {

val tabledEntity = TabledEntity(TabledEntity.Context, "myvendor", "myschema", 7)
Expand Down
Loading