From bb288a095f47e6a0bf4133fb05f6390411ba0ee4 Mon Sep 17 00:00:00 2001 From: Oguzhan Unlu Date: Fri, 13 Sep 2024 17:41:19 +0300 Subject: [PATCH] Add field starting with digit test --- .../schemas/myvendor/digit/jsonschema/1-0-0 | 14 ++++++++ .../transform/NonAtomicFieldsSpec.scala | 32 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 modules/loaders-common/src/test/resources/iglu-client-embedded/schemas/myvendor/digit/jsonschema/1-0-0 diff --git a/modules/loaders-common/src/test/resources/iglu-client-embedded/schemas/myvendor/digit/jsonschema/1-0-0 b/modules/loaders-common/src/test/resources/iglu-client-embedded/schemas/myvendor/digit/jsonschema/1-0-0 new file mode 100644 index 00000000..2610e5f7 --- /dev/null +++ b/modules/loaders-common/src/test/resources/iglu-client-embedded/schemas/myvendor/digit/jsonschema/1-0-0 @@ -0,0 +1,14 @@ +{ + "$schema": "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#", + "self": { + "vendor": "myvendor", + "name": "digit", + "format": "jsonschema", + "version": "1-0-0" + }, + "type": "object", + "properties": { + "1col_a": {"type": "string"} + }, + "required": ["1col_a"] +} diff --git a/modules/loaders-common/src/test/scala/com.snowplowanalytics.snowplow.loaders/transform/NonAtomicFieldsSpec.scala b/modules/loaders-common/src/test/scala/com.snowplowanalytics.snowplow.loaders/transform/NonAtomicFieldsSpec.scala index eda10d39..062fd4db 100644 --- a/modules/loaders-common/src/test/scala/com.snowplowanalytics.snowplow.loaders/transform/NonAtomicFieldsSpec.scala +++ b/modules/loaders-common/src/test/scala/com.snowplowanalytics.snowplow.loaders/transform/NonAtomicFieldsSpec.scala @@ -28,6 +28,7 @@ class NonAtomicFieldsSpec extends Specification with CatsEffect { return a merged schema if the batch uses all schemas in a series $ue3 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 when resolving for known schemas in contexts should return an un-merged schema if the batch uses the first schema in a series $c1 @@ -197,6 +198,37 @@ class NonAtomicFieldsSpec extends Specification with CatsEffect { } + def ueDigit = { + val tabledEntity = TabledEntity(TabledEntity.UnstructEvent, "myvendor", "digit", 1) + + val input = Map( + tabledEntity -> Set((0, 0)) + ) + + val expected = { + val expectedStruct = Type.Struct( + NonEmptyVector.of( + Field("_1col_a", Type.String, Required).copy(accessors = Set("1col_a")) + ) + ) + + val expectedField = Field("unstruct_event_myvendor_digit_1", expectedStruct, Nullable, Set.empty) + + TypedTabledEntity( + tabledEntity, + expectedField, + Set((0, 0)), + 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)