Skip to content

Commit

Permalink
Bump schema-ddl to 0.25.0
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzhanunlu committed Oct 1, 2024
1 parent ed6234f commit a5993cd
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
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": "digit",
"format": "jsonschema",
"version": "1-0-0"
},
"type": "object",
"properties": {
"1col_a": {"type": "string"}
},
"required": ["1col_a"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ class TransformStructuredSpec extends Specification {
Field("my_string", Type.String, Required)
)

private val simpleOneFieldStartingWithDigitSchema =
NonEmptyVector.of(
Field("1my_string", Type.String, Required)
)

private val schemaWithAllPossibleTypes =
NonEmptyVector.of(
Field("my_string", Type.String, Required),
Expand Down Expand Up @@ -71,7 +76,9 @@ class TransformStructuredSpec extends Specification {
Successful transformation:
Valid event with only atomic fields (no custom entities) $onlyAtomic
Valid event with one custom context $oneContext
Valid event with one custom context starting with digit $oneContextDigit
Valid unstruct event $unstruct
Valid unstruct event with field starting with digit $unstructDigit
Valid event with two custom contexts, same major version $twoContextsSameMajor
Valid event with two custom contexts, different major version $twoContextsDifferentMajor
Valid event with each different type of atomic field $onlyAtomicAllTypes
Expand Down Expand Up @@ -120,6 +127,18 @@ class TransformStructuredSpec extends Specification {
assertSuccessful(inputEvent, batchInfo, expectedAllEntities = expectedOutput)
}

def unstructDigit = {
val inputEvent =
createEvent(unstruct = Some(sdj(data = json"""{ "1my_string": "abc"}""", key = "iglu:com.example/mySchema/jsonschema/1-0-0")))
val batchInfo = Result(
fields = Vector(mySchemaUnstruct(model = 1, subVersions = Set((0, 0)), simpleOneFieldStartingWithDigitSchema)),
igluFailures = List.empty
)
val expectedOutput = List(NamedValue(name = "unstruct_event_com_example_my_schema_1", value = json"""{ "_1my_string": "abc"}"""))

assertSuccessful(inputEvent, batchInfo, expectedAllEntities = expectedOutput)
}

def oneContext = {
val inputEvent =
createEvent(contexts = List(sdj(data = json"""{ "my_string": "abc"}""", key = "iglu:com.example/mySchema/jsonschema/1-0-0")))
Expand All @@ -134,6 +153,20 @@ class TransformStructuredSpec extends Specification {
assertSuccessful(inputEvent, batchInfo, expectedAllEntities = expectedOutput)
}

def oneContextDigit = {
val inputEvent =
createEvent(contexts = List(sdj(data = json"""{ "1my_string": "abc"}""", key = "iglu:com.example/mySchema/jsonschema/1-0-0")))
val batchInfo = Result(
fields = Vector(mySchemaContexts(model = 1, subVersions = Set((0, 0)), simpleOneFieldStartingWithDigitSchema)),
igluFailures = List.empty
)
val expectedOutput = List(
NamedValue(name = "contexts_com_example_my_schema_1", value = json"""[{ "_schema_version": "1-0-0", "_1my_string": "abc"}]""")
)

assertSuccessful(inputEvent, batchInfo, expectedAllEntities = expectedOutput)
}

def twoContextsDifferentMajor = {
val inputEvent = createEvent(contexts =
List(
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object Dependencies {
val azureSdk = "1.11.4"

// Snowplow
val schemaDdl = "0.23.0"
val schemaDdl = "0.25.0"
val badrows = "2.3.0"
val igluClient = "3.2.0"
val tracker = "2.0.0"
Expand Down

0 comments on commit a5993cd

Please sign in to comment.