diff --git a/ballerina/Module.md b/ballerina/Module.md index 61d8f49..49650a4 100644 --- a/ballerina/Module.md +++ b/ballerina/Module.md @@ -1,46 +1,46 @@ -## Overview - -Avro is an open-source data serialization system that enables efficient binary serialization and deserialization. It allows users to define schemas for structured data, providing better representation and fast serialization/deserialization. Avro's schema evolution capabilities ensure compatibility and flexibility in evolving data systems. - -The Ballerina Avro module provides the capability to efficiently serialize and deserialize data using Avro schemas. - -## Schema - -The `Schema` instance accepts an Avro schema in `string` format. If the provided schema is not valid according to Avro, an error is returned. The client can be used to serialize data into bytes using the defined schema and deserialize the bytes back to the correct data type based on the schema. - -A `Schema` can be defined using the `string` value of an Avro schema as shown below. - -```ballerina -avro:Schema schema = check new(string `{"type": "int", "namespace": "example.data" }`); -``` - -### APIs associated with Avro - -- **toAvro**: Serializes the given data according to the Avro format. -- **fromAvro**: Deserializes the given Avro encoded message to the given data type. - -#### `toAvro` - -Serializes the given data according to the Avro format. - -```ballerina -import ballerina/avro; - -public function main() returns error? { - int value = 5; - byte[] serializeData = check schema.toAvro(value); -} -``` - -#### `fromAvro` - -Deserializes the given Avro encoded message to the given data type. - -```ballerina -import ballerina/avro; - -public function main() returns error? { - byte[] data = // Avro encoded message ; - int deserializeData = check schema.fromAvro(data); -} -``` +## Overview + +Avro is an open-source data serialization system that enables efficient binary serialization and deserialization. It allows users to define schemas for structured data, providing better representation and fast serialization/deserialization. Avro's schema evolution capabilities ensure compatibility and flexibility in evolving data systems. + +The Ballerina Avro module provides the capability to efficiently serialize and deserialize data using Avro schemas. + +## Schema + +The `Schema` instance accepts an Avro schema in `string` format. If the provided schema is not valid according to Avro, an error is returned. The client can be used to serialize data into bytes using the defined schema and deserialize the bytes back to the correct data type based on the schema. + +A `Schema` can be defined using the `string` value of an Avro schema as shown below. + +```ballerina +avro:Schema schema = check new(string `{"type": "int", "namespace": "example.data" }`); +``` + +### APIs associated with Avro + +- **toAvro**: Serializes the given data according to the Avro format. +- **fromAvro**: Deserializes the given Avro encoded message to the given data type. + +#### `toAvro` + +Serializes the given data according to the Avro format. + +```ballerina +import ballerina/avro; + +public function main() returns error? { + int value = 5; + byte[] serializeData = check schema.toAvro(value); +} +``` + +#### `fromAvro` + +Deserializes the given Avro encoded message to the given data type. + +```ballerina +import ballerina/avro; + +public function main() returns error? { + byte[] data = // Avro encoded message ; + int deserializeData = check schema.fromAvro(data); +} +``` diff --git a/ballerina/Package.md b/ballerina/Package.md index 2f4530d..42b7516 100644 --- a/ballerina/Package.md +++ b/ballerina/Package.md @@ -1,46 +1,46 @@ -## Package overview - -Avro is an open-source data serialization system that enables efficient binary serialization and deserialization. It allows users to define schemas for structured data, providing better representation and fast serialization/deserialization. Avro's schema evolution capabilities ensure compatibility and flexibility in evolving data systems. - -The Ballerina Avro module provides the capability to efficiently serialize and deserialize data using Avro schemas. - -## Schema - -The `Schema` instance accepts an Avro schema in `string` format. If the provided schema is not valid according to Avro, an error is returned. The client can be used to serialize data into bytes using the defined schema and deserialize the bytes back to the correct data type based on the schema. - -A `Schema` can be defined using the `string` value of an Avro schema as shown below. - -```ballerina -avro:Schema schema = check new(string `{"type": "int", "namespace": "example.data" }`); -``` - -### APIs associated with Avro - -- **toAvro**: Serializes the given data according to the Avro format. -- **fromAvro**: Deserializes the given Avro encoded message to the given data type. - -#### `toAvro` - -Serializes the given data according to the Avro format. - -```ballerina -import ballerina/avro; - -public function main() returns error? { - int value = 5; - byte[] serializeData = check schema.toAvro(value); -} -``` - -#### `fromAvro` - -Deserializes the given Avro encoded message to the given data type. - -```ballerina -import ballerina/avro; - -public function main() returns error? { - byte[] data = // Avro encoded message ; - int deserializeData = check schema.fromAvro(data); -} -``` +## Package overview + +Avro is an open-source data serialization system that enables efficient binary serialization and deserialization. It allows users to define schemas for structured data, providing better representation and fast serialization/deserialization. Avro's schema evolution capabilities ensure compatibility and flexibility in evolving data systems. + +The Ballerina Avro module provides the capability to efficiently serialize and deserialize data using Avro schemas. + +## Schema + +The `Schema` instance accepts an Avro schema in `string` format. If the provided schema is not valid according to Avro, an error is returned. The client can be used to serialize data into bytes using the defined schema and deserialize the bytes back to the correct data type based on the schema. + +A `Schema` can be defined using the `string` value of an Avro schema as shown below. + +```ballerina +avro:Schema schema = check new(string `{"type": "int", "namespace": "example.data" }`); +``` + +### APIs associated with Avro + +- **toAvro**: Serializes the given data according to the Avro format. +- **fromAvro**: Deserializes the given Avro encoded message to the given data type. + +#### `toAvro` + +Serializes the given data according to the Avro format. + +```ballerina +import ballerina/avro; + +public function main() returns error? { + int value = 5; + byte[] serializeData = check schema.toAvro(value); +} +``` + +#### `fromAvro` + +Deserializes the given Avro encoded message to the given data type. + +```ballerina +import ballerina/avro; + +public function main() returns error? { + byte[] data = // Avro encoded message ; + int deserializeData = check schema.fromAvro(data); +} +``` diff --git a/ballerina/build.gradle b/ballerina/build.gradle index 51134ec..734004c 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -1,130 +1,130 @@ -/* - * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com) - * - * WSO2 LLC. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.tools.ant.taskdefs.condition.Os - -plugins { - id 'io.ballerina.plugin' -} - -description = 'Ballerina - Avro Ballerina' - -def packageName = "avro" -def packageOrg = "ballerina" -def tomlVersion = stripBallerinaExtensionVersion("${project.version}") -def ballerinaTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/Ballerina.toml") -def ballerinaTomlFile = new File("$project.projectDir/Ballerina.toml") - -def stripBallerinaExtensionVersion(String extVersion) { - if (extVersion.matches(project.ext.timestampedVersionRegex)) { - def splitVersion = extVersion.split('-') - if (splitVersion.length > 3) { - def strippedValues = splitVersion[0..-4] - return strippedValues.join('-') - } else { - return extVersion - } - } else { - return extVersion.replace("${project.ext.snapshotVersion}", "") - } -} - -apply plugin: 'io.ballerina.plugin' - -ballerina { - packageOrganization = packageOrg - module = packageName - langVersion = ballerinaLangVersion -} - -configurations { - externalJars -} - -dependencies { - jbalTools("org.ballerinalang:jballerina-tools:${ballerinaLangVersion}") { - transitive = false - } - externalJars(group: 'org.apache.avro', name: 'avro', version: "${avroVersion}") { - transitive = false - } - externalJars(group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: "${jacksonVersion}") { - transitive = false - } - externalJars(group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: "${jacksonVersion}") { - transitive = false - } - externalJars(group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: "${jacksonVersion}") { - transitive = false - } - externalJars(group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-avro', version: "${jacksonVersion}") { - transitive = false - } -} - -task updateTomlFiles { - doLast { - def newConfig = ballerinaTomlFilePlaceHolder.text.replace("@project.version@", project.version) - newConfig = newConfig.replace("@toml.version@", tomlVersion) - newConfig = newConfig.replace("@avro.version@", project.avroVersion) - newConfig = newConfig.replace("@jackson.version@", project.jacksonVersion) - ballerinaTomlFile.text = newConfig - } -} - -task commitTomlFiles { - doLast { - project.exec { - ignoreExitValue true - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine 'cmd', '/c', "git commit -m \"[Automated] Update the native jar versions\" Ballerina.toml Dependencies.toml" - } else { - commandLine 'sh', '-c', "git commit -m '[Automated] Update the native jar versions' Ballerina.toml Dependencies.toml" - } - } - } -} - -publishing { - publications { - maven(MavenPublication) { - artifact source: createArtifactZip, extension: 'zip' - } - } - - repositories { - maven { - name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/ballerina-platform/module-ballerina-${packageName}") - credentials { - username = System.getenv("publishUser") - password = System.getenv("publishPAT") - } - } - } -} - -updateTomlFiles.dependsOn copyStdlibs - -test.dependsOn ":${packageName}-native:build" - -build.dependsOn "generatePomFileForMavenPublication" -build.dependsOn ":${packageName}-native:build" - -publishToMavenLocal.dependsOn build -publish.dependsOn build +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com) + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.tools.ant.taskdefs.condition.Os + +plugins { + id 'io.ballerina.plugin' +} + +description = 'Ballerina - Avro Ballerina' + +def packageName = "avro" +def packageOrg = "ballerina" +def tomlVersion = stripBallerinaExtensionVersion("${project.version}") +def ballerinaTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/Ballerina.toml") +def ballerinaTomlFile = new File("$project.projectDir/Ballerina.toml") + +def stripBallerinaExtensionVersion(String extVersion) { + if (extVersion.matches(project.ext.timestampedVersionRegex)) { + def splitVersion = extVersion.split('-') + if (splitVersion.length > 3) { + def strippedValues = splitVersion[0..-4] + return strippedValues.join('-') + } else { + return extVersion + } + } else { + return extVersion.replace("${project.ext.snapshotVersion}", "") + } +} + +apply plugin: 'io.ballerina.plugin' + +ballerina { + packageOrganization = packageOrg + module = packageName + langVersion = ballerinaLangVersion +} + +configurations { + externalJars +} + +dependencies { + jbalTools("org.ballerinalang:jballerina-tools:${ballerinaLangVersion}") { + transitive = false + } + externalJars(group: 'org.apache.avro', name: 'avro', version: "${avroVersion}") { + transitive = false + } + externalJars(group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: "${jacksonVersion}") { + transitive = false + } + externalJars(group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: "${jacksonVersion}") { + transitive = false + } + externalJars(group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: "${jacksonVersion}") { + transitive = false + } + externalJars(group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-avro', version: "${jacksonVersion}") { + transitive = false + } +} + +task updateTomlFiles { + doLast { + def newConfig = ballerinaTomlFilePlaceHolder.text.replace("@project.version@", project.version) + newConfig = newConfig.replace("@toml.version@", tomlVersion) + newConfig = newConfig.replace("@avro.version@", project.avroVersion) + newConfig = newConfig.replace("@jackson.version@", project.jacksonVersion) + ballerinaTomlFile.text = newConfig + } +} + +task commitTomlFiles { + doLast { + project.exec { + ignoreExitValue true + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine 'cmd', '/c', "git commit -m \"[Automated] Update the native jar versions\" Ballerina.toml Dependencies.toml" + } else { + commandLine 'sh', '-c', "git commit -m '[Automated] Update the native jar versions' Ballerina.toml Dependencies.toml" + } + } + } +} + +publishing { + publications { + maven(MavenPublication) { + artifact source: createArtifactZip, extension: 'zip' + } + } + + repositories { + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/ballerina-platform/module-ballerina-${packageName}") + credentials { + username = System.getenv("publishUser") + password = System.getenv("publishPAT") + } + } + } +} + +updateTomlFiles.dependsOn copyStdlibs + +test.dependsOn ":${packageName}-native:build" + +build.dependsOn "generatePomFileForMavenPublication" +build.dependsOn ":${packageName}-native:build" + +publishToMavenLocal.dependsOn build +publish.dependsOn build diff --git a/ballerina/schema.bal b/ballerina/schema.bal index 8801ef3..fd30987 100644 --- a/ballerina/schema.bal +++ b/ballerina/schema.bal @@ -1,66 +1,66 @@ -// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com). -// -// WSO2 LLC. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/jballerina.java; - -public class Schema { - - # Generates a schema for a given data type. - # - # ```ballerina - # avro:Schema schema = check new(string `{"type": "int", "name" : "intValue", "namespace": "data" }`); - # ``` - # - # + schema - The Avro schema string - # + return - An `avro:Error` if the schema is not valid or else `()` - public isolated function init(string schema) returns Error? { - self.generateSchema(schema); - } - - isolated function generateSchema(string schema) = @java:Method { - 'class: "io.ballerina.lib.avro.Avro" - } external; - - # Serializes the given data according to the Avro format. - # - # ```ballerina - # avro:Schema schema = check new(string `{"type": "int", "name" : "data", "namespace": "example.avro" }`); - # int value = 5; - # byte[] serializedData = check avro.toAvro(value); - # ``` - # - # + data - The data to be serialized - # + return - A `byte` array of the serialized data or else an `avro:Error` - public isolated function toAvro(anydata data) returns byte[]|Error = @java:Method { - 'class: "io.ballerina.lib.avro.Avro" - } external; - - # Deserializes the given Avro encoded message to the given data type. - # - # ```ballerina - # avro:Schema schema = check new(string `{"type": "int", "name" : "data", "namespace": "example.avro" }`); - # byte[] data = // Avro encoded message ; - # int deserializedData = check schema.fromAvro(data); - # ``` - # - # + data - The Avro serialized data - # + targetType - Default parameter use to infer the user specified type - # + return - A deserialized data with the given type or else an `avro:Error` - public isolated function fromAvro(byte[] data, typedesc targetType = <>) - returns targetType|Error = @java:Method { - 'class: "io.ballerina.lib.avro.Avro" - } external; -} +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/jballerina.java; + +public class Schema { + + # Generates a schema for a given data type. + # + # ```ballerina + # avro:Schema schema = check new(string `{"type": "int", "name" : "intValue", "namespace": "data" }`); + # ``` + # + # + schema - The Avro schema string + # + return - An `avro:Error` if the schema is not valid or else `()` + public isolated function init(string schema) returns Error? { + self.generateSchema(schema); + } + + isolated function generateSchema(string schema) = @java:Method { + 'class: "io.ballerina.lib.avro.Avro" + } external; + + # Serializes the given data according to the Avro format. + # + # ```ballerina + # avro:Schema schema = check new(string `{"type": "int", "name" : "data", "namespace": "example.avro" }`); + # int value = 5; + # byte[] serializedData = check avro.toAvro(value); + # ``` + # + # + data - The data to be serialized + # + return - A `byte` array of the serialized data or else an `avro:Error` + public isolated function toAvro(anydata data) returns byte[]|Error = @java:Method { + 'class: "io.ballerina.lib.avro.Avro" + } external; + + # Deserializes the given Avro encoded message to the given data type. + # + # ```ballerina + # avro:Schema schema = check new(string `{"type": "int", "name" : "data", "namespace": "example.avro" }`); + # byte[] data = // Avro encoded message ; + # int deserializedData = check schema.fromAvro(data); + # ``` + # + # + data - The Avro serialized data + # + targetType - Default parameter use to infer the user specified type + # + return - A deserialized data with the given type or else an `avro:Error` + public isolated function fromAvro(byte[] data, typedesc targetType = <>) + returns targetType|Error = @java:Method { + 'class: "io.ballerina.lib.avro.Avro" + } external; +} diff --git a/ballerina/tests/resources/schema_1.json b/ballerina/tests/resources/schema_1.json index eceb152..7fe8c63 100644 --- a/ballerina/tests/resources/schema_1.json +++ b/ballerina/tests/resources/schema_1.json @@ -1,306 +1,306 @@ -{ - "connect.name": "PROD_HALoConnect_S1DB.HALOEventsDB.VIP.UC_ST_VIPOfferStatus.Envelope", - "connect.version": 1, - "fields": [ - { - "default": null, - "name": "before", - "type": [ - "null", - { - "connect.name": "PROD_HALoConnect_S1DB.HALOEventsDB.VIP.UC_ST_VIPOfferStatus.Value", - "fields": [ - { - "name": "ID", - "type": "long" - }, - { - "default": null, - "name": "OfferID", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "PropertyId", - "type": [ - "null", - "long" - ] - }, - { - "default": null, - "name": "PlayerUnityID", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "HALoOfferStatus", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "StatusDateTime", - "type": [ - "null", - { - "connect.name": "io.debezium.time.Timestamp", - "connect.version": 1, - "type": "long" - } - ] - }, - { - "default": null, - "name": "OfferSegmentID", - "type": [ - "null", - "long" - ] - }, - { - "default": null, - "name": "RedemptionDate", - "type": [ - "null", - { - "connect.name": "io.debezium.time.Timestamp", - "connect.version": 1, - "type": "long" - } - ] - }, - { - "default": null, - "name": "OfferItemID", - "type": [ - "null", - "long" - ] - }, - { - "default": null, - "name": "OfferPrizeCode", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "AmountRedeemed", - "type": [ - "null", - "double" - ] - }, - { - "default": null, - "name": "ItemQuantity", - "type": [ - "null", - "int" - ] - }, - { - "default": null, - "name": "OfferType", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "CreatedDate", - "type": [ - "null", - { - "connect.name": "io.debezium.time.Timestamp", - "connect.version": 1, - "type": "long" - } - ] - }, - { - "default": null, - "name": "CreatedBy", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "UpdatedDate", - "type": [ - "null", - { - "connect.name": "io.debezium.time.Timestamp", - "connect.version": 1, - "type": "long" - } - ] - }, - { - "default": null, - "name": "UpdatedBy", - "type": [ - "null", - "string" - ] - } - ], - "name": "Value", - "type": "record" - } - ] - }, - { - "default": null, - "name": "after", - "type": [ - "null", - "Value" - ] - }, - { - "name": "source", - "type": { - "connect.name": "io.debezium.connector.sqlserver.Source", - "fields": [ - { - "name": "version", - "type": "string" - }, - { - "name": "connector", - "type": "string" - }, - { - "name": "name", - "type": "string" - }, - { - "name": "ts_ms", - "type": "long" - }, - { - "default": "false", - "name": "snapshot", - "type": [ - { - "connect.default": "false", - "connect.name": "io.debezium.data.Enum", - "connect.parameters": { - "allowed": "true,last,false,incremental" - }, - "connect.version": 1, - "type": "string" - }, - "null" - ] - }, - { - "name": "db", - "type": "string" - }, - { - "default": null, - "name": "sequence", - "type": [ - "null", - "string" - ] - }, - { - "name": "schema", - "type": "string" - }, - { - "name": "table", - "type": "string" - }, - { - "default": null, - "name": "change_lsn", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "commit_lsn", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "event_serial_no", - "type": [ - "null", - "long" - ] - } - ], - "name": "Source", - "namespace": "io.debezium.connector.sqlserver", - "type": "record" - } - }, - { - "name": "op", - "type": "string" - }, - { - "default": null, - "name": "ts_ms", - "type": [ - "null", - "long" - ] - }, - { - "default": null, - "name": "transaction", - "type": [ - "null", - { - "connect.name": "event.block", - "connect.version": 1, - "fields": [ - { - "name": "id", - "type": "string" - }, - { - "name": "total_order", - "type": "long" - }, - { - "name": "data_collection_order", - "type": "long" - } - ], - "name": "block", - "namespace": "event", - "type": "record" - } - ] - } - ], - "name": "Envelope", - "namespace": "PROD_HALoConnect_S1DB.HALOEventsDB.VIP.UC_ST_VIPOfferStatus", - "type": "record" -} +{ + "connect.name": "PROD_HALoConnect_S1DB.HALOEventsDB.VIP.UC_ST_VIPOfferStatus.Envelope", + "connect.version": 1, + "fields": [ + { + "default": null, + "name": "before", + "type": [ + "null", + { + "connect.name": "PROD_HALoConnect_S1DB.HALOEventsDB.VIP.UC_ST_VIPOfferStatus.Value", + "fields": [ + { + "name": "ID", + "type": "long" + }, + { + "default": null, + "name": "OfferID", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "PropertyId", + "type": [ + "null", + "long" + ] + }, + { + "default": null, + "name": "PlayerUnityID", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "HALoOfferStatus", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "StatusDateTime", + "type": [ + "null", + { + "connect.name": "io.debezium.time.Timestamp", + "connect.version": 1, + "type": "long" + } + ] + }, + { + "default": null, + "name": "OfferSegmentID", + "type": [ + "null", + "long" + ] + }, + { + "default": null, + "name": "RedemptionDate", + "type": [ + "null", + { + "connect.name": "io.debezium.time.Timestamp", + "connect.version": 1, + "type": "long" + } + ] + }, + { + "default": null, + "name": "OfferItemID", + "type": [ + "null", + "long" + ] + }, + { + "default": null, + "name": "OfferPrizeCode", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "AmountRedeemed", + "type": [ + "null", + "double" + ] + }, + { + "default": null, + "name": "ItemQuantity", + "type": [ + "null", + "int" + ] + }, + { + "default": null, + "name": "OfferType", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "CreatedDate", + "type": [ + "null", + { + "connect.name": "io.debezium.time.Timestamp", + "connect.version": 1, + "type": "long" + } + ] + }, + { + "default": null, + "name": "CreatedBy", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "UpdatedDate", + "type": [ + "null", + { + "connect.name": "io.debezium.time.Timestamp", + "connect.version": 1, + "type": "long" + } + ] + }, + { + "default": null, + "name": "UpdatedBy", + "type": [ + "null", + "string" + ] + } + ], + "name": "Value", + "type": "record" + } + ] + }, + { + "default": null, + "name": "after", + "type": [ + "null", + "Value" + ] + }, + { + "name": "source", + "type": { + "connect.name": "io.debezium.connector.sqlserver.Source", + "fields": [ + { + "name": "version", + "type": "string" + }, + { + "name": "connector", + "type": "string" + }, + { + "name": "name", + "type": "string" + }, + { + "name": "ts_ms", + "type": "long" + }, + { + "default": "false", + "name": "snapshot", + "type": [ + { + "connect.default": "false", + "connect.name": "io.debezium.data.Enum", + "connect.parameters": { + "allowed": "true,last,false,incremental" + }, + "connect.version": 1, + "type": "string" + }, + "null" + ] + }, + { + "name": "db", + "type": "string" + }, + { + "default": null, + "name": "sequence", + "type": [ + "null", + "string" + ] + }, + { + "name": "schema", + "type": "string" + }, + { + "name": "table", + "type": "string" + }, + { + "default": null, + "name": "change_lsn", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "commit_lsn", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "event_serial_no", + "type": [ + "null", + "long" + ] + } + ], + "name": "Source", + "namespace": "io.debezium.connector.sqlserver", + "type": "record" + } + }, + { + "name": "op", + "type": "string" + }, + { + "default": null, + "name": "ts_ms", + "type": [ + "null", + "long" + ] + }, + { + "default": null, + "name": "transaction", + "type": [ + "null", + { + "connect.name": "event.block", + "connect.version": 1, + "fields": [ + { + "name": "id", + "type": "string" + }, + { + "name": "total_order", + "type": "long" + }, + { + "name": "data_collection_order", + "type": "long" + } + ], + "name": "block", + "namespace": "event", + "type": "record" + } + ] + } + ], + "name": "Envelope", + "namespace": "PROD_HALoConnect_S1DB.HALOEventsDB.VIP.UC_ST_VIPOfferStatus", + "type": "record" +} diff --git a/ballerina/tests/resources/schema_2.json b/ballerina/tests/resources/schema_2.json index 89e57e8..dc41ba1 100644 --- a/ballerina/tests/resources/schema_2.json +++ b/ballerina/tests/resources/schema_2.json @@ -1,506 +1,506 @@ -{ - "connect.name": "PROD_VIPDB.VIPDB.dbo.CorePlayerInformation_Staging01.Envelope", - "connect.version": 1, - "fields": [ - { - "default": null, - "name": "before", - "type": [ - "null", - { - "connect.name": "PROD_VIPDB.VIPDB.dbo.CorePlayerInformation_Staging01.Value", - "fields": [ - { - "name": "CorePlayerID", - "type": "int" - }, - { - "default": null, - "name": "AccountNumber", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "LastName", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "FirstName", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "MiddleName", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "Gender", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "Language", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "Discreet", - "type": [ - "null", - "boolean" - ] - }, - { - "default": null, - "name": "Deceased", - "type": [ - "null", - "boolean" - ] - }, - { - "default": null, - "name": "IsBanned", - "type": [ - "null", - "boolean" - ] - }, - { - "default": null, - "name": "EmailAddress", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "IsVerified", - "type": [ - "null", - "boolean" - ] - }, - { - "default": null, - "name": "EmailStatus", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "MobilePhone", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "HomePhone", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "HomeStreetAddress", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "HomeCity", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "HomeState", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "HomePostalCode", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "HomeCountry", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "AltStreetAddress", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "AltCity", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "AltState", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "AltCountry", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "DateOfBirth", - "type": [ - "null", - { - "connect.name": "io.debezium.time.Timestamp", - "connect.version": 1, - "type": "long" - } - ] - }, - { - "default": null, - "name": "EnrollDate", - "type": [ - "null", - { - "connect.name": "io.debezium.time.Timestamp", - "connect.version": 1, - "type": "long" - } - ] - }, - { - "default": null, - "name": "PredomPropertyId", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "AccountType", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "InsertDtm", - "type": [ - "null", - { - "connect.name": "io.debezium.time.Timestamp", - "connect.version": 1, - "type": "long" - } - ] - }, - { - "default": null, - "name": "AltPostalCode", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "BatchID", - "type": [ - "null", - "int" - ] - }, - { - "default": null, - "name": "GlobalRank", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "GlobalValuationScore", - "type": [ - "null", - "double" - ] - }, - { - "default": null, - "name": "PlayerType", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "AccountStatus", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "RegistrationSource", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "BannedReason", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "TierCode", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "TierName", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "TierEndDate", - "type": [ - "null", - { - "connect.name": "io.debezium.time.Timestamp", - "connect.version": 1, - "type": "long" - } - ] - }, - { - "default": null, - "name": "VIPFlag", - "type": [ - "null", - "boolean" - ] - } - ], - "name": "Value", - "type": "record" - } - ] - }, - { - "default": null, - "name": "after", - "type": [ - "null", - "Value" - ] - }, - { - "name": "source", - "type": { - "connect.name": "io.debezium.connector.sqlserver.Source", - "fields": [ - { - "name": "version", - "type": "string" - }, - { - "name": "connector", - "type": "string" - }, - { - "name": "name", - "type": "string" - }, - { - "name": "ts_ms", - "type": "long" - }, - { - "default": "false", - "name": "snapshot", - "type": [ - { - "connect.default": "false", - "connect.name": "io.debezium.data.Enum", - "connect.parameters": { - "allowed": "true,last,false,incremental" - }, - "connect.version": 1, - "type": "string" - }, - "null" - ] - }, - { - "name": "db", - "type": "string" - }, - { - "default": null, - "name": "sequence", - "type": [ - "null", - "string" - ] - }, - { - "name": "schema", - "type": "string" - }, - { - "name": "table", - "type": "string" - }, - { - "default": null, - "name": "change_lsn", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "commit_lsn", - "type": [ - "null", - "string" - ] - }, - { - "default": null, - "name": "event_serial_no", - "type": [ - "null", - "long" - ] - } - ], - "name": "Source", - "namespace": "io.debezium.connector.sqlserver", - "type": "record" - } - }, - { - "name": "op", - "type": "string" - }, - { - "default": null, - "name": "ts_ms", - "type": [ - "null", - "long" - ] - }, - { - "default": null, - "name": "transaction", - "type": [ - "null", - { - "connect.name": "event.block", - "connect.version": 1, - "fields": [ - { - "name": "id", - "type": "string" - }, - { - "name": "total_order", - "type": "long" - }, - { - "name": "data_collection_order", - "type": "long" - } - ], - "name": "block", - "namespace": "event", - "type": "record" - } - ] - }, - { - "default": null, - "name": "MessageSource", - "type": [ - "null", - "string" - ] - } - ], - "name": "Envelope", - "namespace": "PROD_VIPDB.VIPDB.dbo.CorePlayerInformation_Staging01", - "type": "record" -} +{ + "connect.name": "PROD_VIPDB.VIPDB.dbo.CorePlayerInformation_Staging01.Envelope", + "connect.version": 1, + "fields": [ + { + "default": null, + "name": "before", + "type": [ + "null", + { + "connect.name": "PROD_VIPDB.VIPDB.dbo.CorePlayerInformation_Staging01.Value", + "fields": [ + { + "name": "CorePlayerID", + "type": "int" + }, + { + "default": null, + "name": "AccountNumber", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "LastName", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "FirstName", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "MiddleName", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "Gender", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "Language", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "Discreet", + "type": [ + "null", + "boolean" + ] + }, + { + "default": null, + "name": "Deceased", + "type": [ + "null", + "boolean" + ] + }, + { + "default": null, + "name": "IsBanned", + "type": [ + "null", + "boolean" + ] + }, + { + "default": null, + "name": "EmailAddress", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "IsVerified", + "type": [ + "null", + "boolean" + ] + }, + { + "default": null, + "name": "EmailStatus", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "MobilePhone", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "HomePhone", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "HomeStreetAddress", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "HomeCity", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "HomeState", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "HomePostalCode", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "HomeCountry", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "AltStreetAddress", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "AltCity", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "AltState", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "AltCountry", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "DateOfBirth", + "type": [ + "null", + { + "connect.name": "io.debezium.time.Timestamp", + "connect.version": 1, + "type": "long" + } + ] + }, + { + "default": null, + "name": "EnrollDate", + "type": [ + "null", + { + "connect.name": "io.debezium.time.Timestamp", + "connect.version": 1, + "type": "long" + } + ] + }, + { + "default": null, + "name": "PredomPropertyId", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "AccountType", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "InsertDtm", + "type": [ + "null", + { + "connect.name": "io.debezium.time.Timestamp", + "connect.version": 1, + "type": "long" + } + ] + }, + { + "default": null, + "name": "AltPostalCode", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "BatchID", + "type": [ + "null", + "int" + ] + }, + { + "default": null, + "name": "GlobalRank", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "GlobalValuationScore", + "type": [ + "null", + "double" + ] + }, + { + "default": null, + "name": "PlayerType", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "AccountStatus", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "RegistrationSource", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "BannedReason", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "TierCode", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "TierName", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "TierEndDate", + "type": [ + "null", + { + "connect.name": "io.debezium.time.Timestamp", + "connect.version": 1, + "type": "long" + } + ] + }, + { + "default": null, + "name": "VIPFlag", + "type": [ + "null", + "boolean" + ] + } + ], + "name": "Value", + "type": "record" + } + ] + }, + { + "default": null, + "name": "after", + "type": [ + "null", + "Value" + ] + }, + { + "name": "source", + "type": { + "connect.name": "io.debezium.connector.sqlserver.Source", + "fields": [ + { + "name": "version", + "type": "string" + }, + { + "name": "connector", + "type": "string" + }, + { + "name": "name", + "type": "string" + }, + { + "name": "ts_ms", + "type": "long" + }, + { + "default": "false", + "name": "snapshot", + "type": [ + { + "connect.default": "false", + "connect.name": "io.debezium.data.Enum", + "connect.parameters": { + "allowed": "true,last,false,incremental" + }, + "connect.version": 1, + "type": "string" + }, + "null" + ] + }, + { + "name": "db", + "type": "string" + }, + { + "default": null, + "name": "sequence", + "type": [ + "null", + "string" + ] + }, + { + "name": "schema", + "type": "string" + }, + { + "name": "table", + "type": "string" + }, + { + "default": null, + "name": "change_lsn", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "commit_lsn", + "type": [ + "null", + "string" + ] + }, + { + "default": null, + "name": "event_serial_no", + "type": [ + "null", + "long" + ] + } + ], + "name": "Source", + "namespace": "io.debezium.connector.sqlserver", + "type": "record" + } + }, + { + "name": "op", + "type": "string" + }, + { + "default": null, + "name": "ts_ms", + "type": [ + "null", + "long" + ] + }, + { + "default": null, + "name": "transaction", + "type": [ + "null", + { + "connect.name": "event.block", + "connect.version": 1, + "fields": [ + { + "name": "id", + "type": "string" + }, + { + "name": "total_order", + "type": "long" + }, + { + "name": "data_collection_order", + "type": "long" + } + ], + "name": "block", + "namespace": "event", + "type": "record" + } + ] + }, + { + "default": null, + "name": "MessageSource", + "type": [ + "null", + "string" + ] + } + ], + "name": "Envelope", + "namespace": "PROD_VIPDB.VIPDB.dbo.CorePlayerInformation_Staging01", + "type": "record" +} diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index 70e715b..3ad40ee 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -1,659 +1,659 @@ -// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com). -// -// WSO2 LLC. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/io; -import ballerina/test; - -@test:Config {} -public isolated function testEnums() returns error? { - string schema = string ` - { - "type" : "enum", - "name" : "Numbers", - "namespace": "data", - "symbols" : [ "ONE", "TWO", "THREE", "FOUR" ] - }`; - - Numbers number = "ONE"; - - Schema avro = check new (schema); - byte[] encode = check avro.toAvro(number); - Numbers deserialize = check avro.fromAvro(encode); - test:assertEquals(number, deserialize); -} - -@test:Config { - groups: ["errors"] -} -public isolated function testEnumsWithString() returns error? { - string schema = string ` - { - "type" : "enum", - "name" : "Numbers", - "namespace": "data", - "symbols" : [ "ONE", "TWO", "THREE", "FOUR" ] - }`; - - string number = "FIVE"; - - Schema avro = check new (schema); - byte[]|error encode = avro.toAvro(number); - test:assertTrue(encode is error); -} - -@test:Config {} -public isolated function testMaps() returns error? { - string schema = string ` - { - "type": "map", - "values" : "int", - "default": {} - }`; - - map colors = {"red": 0, "green": 1, "blue": 2}; - - Schema avro = check new (schema); - byte[] encode = check avro.toAvro(colors); - map deserialize = check avro.fromAvro(encode); - test:assertEquals(colors, deserialize); -} - -@test:Config {} -public isolated function testNestedRecords() returns error? { - string schema = string ` - { - "namespace": "example.avro", - "type": "record", - "name": "Lecturer", - "fields": [ - { - "name": "name", - "type": "string" - }, - { - "name": "instructor", - "type": { - "name": "Instructor", - "type": "record", - "fields": [ - { - "name": "name", - "type": "string" - }, - { - "name": "student", - "type": { - "type": "record", - "name": "Student", - "fields": [ - { - "name": "name", - "type": "string" - }, - { - "name": "subject", - "type": "string" - } - ] - } - } - ] - } - } - ] - }`; - - Lecturer lecturer = { - name: "John", - instructor: { - name: "Liam", - student: { - name: "Sam", - subject: "geology" - } - } - }; - - Schema avro = check new (schema); - byte[] serialize = check avro.toAvro(lecturer); - Lecturer deserialize = check avro.fromAvro(serialize); - test:assertEquals(lecturer, deserialize); -} - -@test:Config {} -public isolated function testArraysInRecords() returns error? { - string schema = string ` - { - "namespace": "example.avro", - "type": "record", - "name": "Student", - "fields": [ - {"name": "name", "type": "string"}, - {"name": "colors", "type": {"type": "array", "items": "string"}} - ] - }`; - - Color colors = { - name: "Red", - colors: ["maroon", "dark red", "light red"] - }; - - Schema avro = check new (schema); - byte[] serialize = check avro.toAvro(colors); - Color deserialize = check avro.fromAvro(serialize); - test:assertEquals(colors, deserialize); -} - -@test:Config { - groups: ["errors", "qwe"] -} -public isolated function testArraysInRecordsWithInvalidSchema() returns error? { - string schema = string ` - { - "namespace": "example.avro", - "type": "record", - "name": "Student", - "fields": [ - {"name": "name", "type": "string"}, - {"name": "colors", "type": {"type": "array", "items": "string"}} - ] - }`; - - Color colors = { - name: "Red", - colors: ["maroon", "dark red", "light red"] - }; - - Schema avroProducer = check new (schema); - byte[] serialize = check avroProducer.toAvro(colors); - - string schema2 = string ` - { - "namespace": "example.avro", - "type": "record", - "name": "Student", - "fields": [ - {"name": "name", "type": "string"}, - {"name": "colors", "type": {"type": "array", "items": "int"}} - ] - }`; - Schema avroConsumer = check new (schema2); - Color|Error deserialize = avroConsumer.fromAvro(serialize); - test:assertTrue(deserialize is Error); -} - -@test:Config {} -public isolated function testRecords() returns error? { - string schema = string ` - { - "namespace": "example.avro", - "type": "record", - "name": "Student", - "fields": [ - {"name": "name", "type": "string"}, - {"name": "subject", "type": "string"} - ] - }`; - - Student student = { - name: "Liam", - subject: "geology" - }; - - Schema avro = check new (schema); - byte[] serialize = check avro.toAvro(student); - Student deserialize = check avro.fromAvro(serialize); - test:assertEquals(student, deserialize); -} - -@test:Config {} -public isolated function testRecordsWithDifferentTypeOfFields() returns error? { - string schema = string ` - { - "namespace": "example.avro", - "type": "record", - "name": "Student", - "fields": [ - {"name": "name", "type": "string"}, - {"name": "age", "type": "int"} - ] - }`; - - Person student = { - name: "Liam", - age: 52 - }; - - Schema avro = check new (schema); - byte[] encode = check avro.toAvro(student); - Person deserialize = check avro.fromAvro(encode); - test:assertEquals(student, deserialize); -} - -@test:Config {} -public isolated function testRecordsWithUnionTypes() returns error? { - string schema = string ` - { - "namespace": "example.avro", - "type": "record", - "name": "Course", - "fields": [ - {"name": "name", "type": ["string", "null"]}, - {"name": "credits", "type": ["int", "null"]} - ] - }`; - - Course course = { - name: (), - credits: () - }; - - Schema avro = check new (schema); - byte[] serialize = check avro.toAvro(course); - Course deserialize = check avro.fromAvro(serialize); - test:assertEquals(course, deserialize); -} - -@test:Config {} -public isolated function testArrays() returns error? { - string schema = string ` - { - "type": "array", - "name" : "StringArray", - "namespace": "data", - "items": "string" - }`; - - string[] colors = ["red", "green", "blue"]; - - Schema avro = check new (schema); - byte[] encode = check avro.toAvro(colors); - string[] deserializeJson = check avro.fromAvro(encode); - test:assertEquals(deserializeJson, colors); -} - -@test:Config {} -public isolated function testIntValue() returns error? { - string schema = string ` - { - "type": "int", - "name" : "intValue", - "namespace": "data" - }`; - - int value = 5; - - Schema avro = check new (schema); - byte[] encode = check avro.toAvro(value); - int deserializeJson = check avro.fromAvro(encode); - test:assertEquals(deserializeJson, value); -} - -@test:Config {} -public isolated function testFloatValue() returns error? { - string schema = string ` - { - "type": "float", - "name" : "floatValue", - "namespace": "data" - }`; - - float value = 5.5; - - Schema avro = check new (schema); - byte[] encode = check avro.toAvro(value); - float deserializeJson = check avro.fromAvro(encode); - test:assertEquals(deserializeJson, value); -} - -@test:Config {} -public isolated function testDoubleValue() returns error? { - string schema = string ` - { - "type": "double", - "name" : "doubleValue", - "namespace": "data" - }`; - - float value = 5.5595; - - Schema avro = check new (schema); - byte[] encode = check avro.toAvro(value); - float deserializeJson = check avro.fromAvro(encode); - test:assertEquals(deserializeJson, value); -} - -@test:Config {} -public isolated function testLongValue() returns error? { - string schema = string ` - { - "type": "long", - "name" : "longValue", - "namespace": "data" - }`; - - int value = 555950000000000000; - Schema avro = check new (schema); - byte[] encode = check avro.toAvro(value); - int deserializeJson = check avro.fromAvro(encode); - test:assertEquals(deserializeJson, value); -} - -@test:Config { - groups: ["primitive"] -} -public isolated function testStringValue() returns error? { - string schema = string ` - { - "type": "string", - "name" : "stringValue", - "namespace": "data" - }`; - - string value = "test"; - Schema avro = check new (schema); - byte[] encode = check avro.toAvro(value); - string deserializeJson = check avro.fromAvro(encode); - test:assertEquals(deserializeJson, value); -} - -@test:Config {} -public isolated function testBoolean() returns error? { - string schema = string ` - { - "type": "boolean", - "name" : "booleanValue", - "namespace": "data" - }`; - - boolean value = true; - Schema avro = check new (schema); - byte[] encode = check avro.toAvro(value); - boolean deserializeJson = check avro.fromAvro(encode); - test:assertEquals(deserializeJson, value); -} - -@test:Config {} -public isolated function testNullValues() returns error? { - string schema = string ` - { - "type": "null", - "name" : "nullValue", - "namespace": "data" - }`; - - Schema avro = check new (schema); - byte[] encode = check avro.toAvro(()); - () deserializeJson = check avro.fromAvro(encode); - test:assertEquals(deserializeJson, ()); -} - -@test:Config {} -public isolated function testNullValuesWithNonNullData() returns error? { - string schema = string ` - { - "type": "null", - "name" : "nullValue", - "namespace": "data" - }`; - - Schema avro = check new (schema); - byte[]|error encode = avro.toAvro("string"); - test:assertTrue(encode is error); -} - -@test:Config {} -public isolated function testFixed() returns error? { - string schema = string ` - { - "type": "fixed", - "name": "name", - "size": 16 - }`; - - byte[] value = "u00ffffffffffffx".toBytes(); - - Schema avro = check new (schema); - byte[] encode = check avro.toAvro(value); - byte[] deserialize = check avro.fromAvro(encode); - test:assertEquals(deserialize, value); -} - -@test:Config {} -public function testDbSchemaWithRecords() returns error? { - string schema = string ` - { - "connect.name": "io.debezium.connector.sqlserver.SchemaChangeKey", - "connect.version": 1, - "fields": [ - { - "name": "databaseName", - "type": "string" - } - ], - "name": "SchemaChangeKey", - "namespace": "io.debezium.connector.sqlserver", - "type": "record" - }`; - - SchemaChangeKey changeKey = { - databaseName: "my-db" - }; - - Schema avro = check new (schema); - byte[] serialize = check avro.toAvro(changeKey); - SchemaChangeKey deserialize = check avro.fromAvro(serialize); - test:assertEquals(changeKey, deserialize); - -} - -@test:Config {} -public function testComplexDbSchema() returns error? { - string jsonFileName = string `tests/resources/schema_1.json`; - json result = check io:fileReadJson(jsonFileName); - string schema = result.toString(); - - Envelope envelope = { - before: { - ID: 1, - OfferID: "offer1", - PropertyId: 100, - PlayerUnityID: "player1", - HALoOfferStatus: "status1", - StatusDateTime: 1633020142, - OfferSegmentID: 200, - RedemptionDate: 1633020142, - OfferItemID: 300, - OfferPrizeCode: "prize1", - AmountRedeemed: 500.0, - ItemQuantity: 5, - OfferType: "type1", - CreatedDate: 1633020142, - CreatedBy: "creator1", - UpdatedDate: 1633020142, - UpdatedBy: "updater1" - }, - after: { - ID: 2, - OfferID: "offer2", - PropertyId: 101, - PlayerUnityID: "player2", - HALoOfferStatus: "status2", - StatusDateTime: 1633020143, - OfferSegmentID: 201, - RedemptionDate: 1633020143, - OfferItemID: 301, - OfferPrizeCode: "prize2", - AmountRedeemed: 600.0, - ItemQuantity: 6, - OfferType: "type2", - CreatedDate: 1633020143, - CreatedBy: "creator2", - UpdatedDate: 1633020143, - UpdatedBy: "updater2" - }, - 'source: { - version: "1.0", - connector: "connector1", - name: "source1", - ts_ms: 1633020144, - snapshot: "snapshot1", - db: "db1", - sequence: "sequence1", - schema: "schema1", - 'table: "table1", - change_lsn: "lsn1", - commit_lsn: "lsn2", - event_serial_no: 1 - }, - op: "op1", - ts_ms: 1633020145, - 'transaction: { - id: "transaction1", - total_order: 1, - data_collection_order: 1 - } - }; - - Schema avro = check new (schema); - byte[] serialize = check avro.toAvro(envelope); - Envelope deserialize = check avro.fromAvro(serialize); - test:assertEquals(envelope, deserialize); -} - -@test:Config { -} -public function testComplexDbSchemaWithNestedRecords() returns error? { - string jsonFileName = string `tests/resources/schema_2.json`; - json result = check io:fileReadJson(jsonFileName); - string schema = result.toString(); - - Envelope2 envelope2 = { - before: { - CorePlayerID: 123, - AccountNumber: "123456", - LastName: "Doe", - FirstName: "John", - MiddleName: "M", - Gender: "M", - Language: "English", - Discreet: false, - Deceased: false, - IsBanned: false, - EmailAddress: "john.doe@example.com", - IsVerified: true, - EmailStatus: "Verified", - MobilePhone: "1234567890", - HomePhone: "0987654321", - HomeStreetAddress: "123 Street", - HomeCity: "City", - HomeState: "State", - HomePostalCode: "12345", - HomeCountry: "Country", - AltStreetAddress: "456 Street", - AltCity: "Alt City", - AltState: "Alt State", - AltCountry: "Alt Country", - DateOfBirth: 1234567890, - EnrollDate: 1234567890, - PredomPropertyId: "PropertyId", - AccountType: "Type", - InsertDtm: 1234567890, - AltPostalCode: "54321", - BatchID: 123, - GlobalRank: "Rank", - GlobalValuationScore: 1.0, - PlayerType: "Type", - AccountStatus: "Status", - RegistrationSource: "Source", - BannedReason: "Reason", - TierCode: "Code", - TierName: "Name", - TierEndDate: 1234567890, - VIPFlag: false - }, - after: { - CorePlayerID: 456, - AccountNumber: "654321", - LastName: "Smith", - FirstName: "Jane", - MiddleName: "K", - Gender: "F", - Language: "Spanish", - Discreet: true, - Deceased: false, - IsBanned: false, - EmailAddress: "jane.smith@example.com", - IsVerified: false, - EmailStatus: "Unverified", - MobilePhone: "0987654321", - HomePhone: "1234567890", - HomeStreetAddress: "456 Street", - HomeCity: "Alt City", - HomeState: "Alt State", - HomePostalCode: "54321", - HomeCountry: "Alt Country", - AltStreetAddress: "123 Street", - AltCity: "City", - AltState: "State", - AltCountry: "Country", - DateOfBirth: 9876543210, - EnrollDate: 9876543210, - PredomPropertyId: "AltPropertyId", - AccountType: "AltType", - InsertDtm: 9876543210, - AltPostalCode: "12345", - BatchID: 456, - GlobalRank: "AltRank", - GlobalValuationScore: 2.0, - PlayerType: "AltType", - AccountStatus: "AltStatus", - RegistrationSource: "AltSource", - BannedReason: "AltReason", - TierCode: "AltCode", - TierName: "AltName", - TierEndDate: 9876543210, - VIPFlag: true - }, - 'source: { - version: "1.0", - connector: "connector", - name: "name", - ts_ms: 123456789, - snapshot: "snapshot", - db: "db", - sequence: "sequence", - schema: "schema", - 'table: "table", - change_lsn: "lsn", - commit_lsn: "lsn", - event_serial_no: 1 - }, - op: "op", - ts_ms: 123456789, - 'transaction: { - id: "id", - total_order: 1, - data_collection_order: 1 - }, - MessageSource: "MessageSource" - }; - - Schema avro = check new (schema); - byte[] serialize = check avro.toAvro(envelope2); - Envelope2 deserialize = check avro.fromAvro(serialize); - test:assertEquals(envelope2, deserialize); -} +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/io; +import ballerina/test; + +@test:Config {} +public isolated function testEnums() returns error? { + string schema = string ` + { + "type" : "enum", + "name" : "Numbers", + "namespace": "data", + "symbols" : [ "ONE", "TWO", "THREE", "FOUR" ] + }`; + + Numbers number = "ONE"; + + Schema avro = check new (schema); + byte[] encode = check avro.toAvro(number); + Numbers deserialize = check avro.fromAvro(encode); + test:assertEquals(number, deserialize); +} + +@test:Config { + groups: ["errors"] +} +public isolated function testEnumsWithString() returns error? { + string schema = string ` + { + "type" : "enum", + "name" : "Numbers", + "namespace": "data", + "symbols" : [ "ONE", "TWO", "THREE", "FOUR" ] + }`; + + string number = "FIVE"; + + Schema avro = check new (schema); + byte[]|error encode = avro.toAvro(number); + test:assertTrue(encode is error); +} + +@test:Config {} +public isolated function testMaps() returns error? { + string schema = string ` + { + "type": "map", + "values" : "int", + "default": {} + }`; + + map colors = {"red": 0, "green": 1, "blue": 2}; + + Schema avro = check new (schema); + byte[] encode = check avro.toAvro(colors); + map deserialize = check avro.fromAvro(encode); + test:assertEquals(colors, deserialize); +} + +@test:Config {} +public isolated function testNestedRecords() returns error? { + string schema = string ` + { + "namespace": "example.avro", + "type": "record", + "name": "Lecturer", + "fields": [ + { + "name": "name", + "type": "string" + }, + { + "name": "instructor", + "type": { + "name": "Instructor", + "type": "record", + "fields": [ + { + "name": "name", + "type": "string" + }, + { + "name": "student", + "type": { + "type": "record", + "name": "Student", + "fields": [ + { + "name": "name", + "type": "string" + }, + { + "name": "subject", + "type": "string" + } + ] + } + } + ] + } + } + ] + }`; + + Lecturer lecturer = { + name: "John", + instructor: { + name: "Liam", + student: { + name: "Sam", + subject: "geology" + } + } + }; + + Schema avro = check new (schema); + byte[] serialize = check avro.toAvro(lecturer); + Lecturer deserialize = check avro.fromAvro(serialize); + test:assertEquals(lecturer, deserialize); +} + +@test:Config {} +public isolated function testArraysInRecords() returns error? { + string schema = string ` + { + "namespace": "example.avro", + "type": "record", + "name": "Student", + "fields": [ + {"name": "name", "type": "string"}, + {"name": "colors", "type": {"type": "array", "items": "string"}} + ] + }`; + + Color colors = { + name: "Red", + colors: ["maroon", "dark red", "light red"] + }; + + Schema avro = check new (schema); + byte[] serialize = check avro.toAvro(colors); + Color deserialize = check avro.fromAvro(serialize); + test:assertEquals(colors, deserialize); +} + +@test:Config { + groups: ["errors", "qwe"] +} +public isolated function testArraysInRecordsWithInvalidSchema() returns error? { + string schema = string ` + { + "namespace": "example.avro", + "type": "record", + "name": "Student", + "fields": [ + {"name": "name", "type": "string"}, + {"name": "colors", "type": {"type": "array", "items": "string"}} + ] + }`; + + Color colors = { + name: "Red", + colors: ["maroon", "dark red", "light red"] + }; + + Schema avroProducer = check new (schema); + byte[] serialize = check avroProducer.toAvro(colors); + + string schema2 = string ` + { + "namespace": "example.avro", + "type": "record", + "name": "Student", + "fields": [ + {"name": "name", "type": "string"}, + {"name": "colors", "type": {"type": "array", "items": "int"}} + ] + }`; + Schema avroConsumer = check new (schema2); + Color|Error deserialize = avroConsumer.fromAvro(serialize); + test:assertTrue(deserialize is Error); +} + +@test:Config {} +public isolated function testRecords() returns error? { + string schema = string ` + { + "namespace": "example.avro", + "type": "record", + "name": "Student", + "fields": [ + {"name": "name", "type": "string"}, + {"name": "subject", "type": "string"} + ] + }`; + + Student student = { + name: "Liam", + subject: "geology" + }; + + Schema avro = check new (schema); + byte[] serialize = check avro.toAvro(student); + Student deserialize = check avro.fromAvro(serialize); + test:assertEquals(student, deserialize); +} + +@test:Config {} +public isolated function testRecordsWithDifferentTypeOfFields() returns error? { + string schema = string ` + { + "namespace": "example.avro", + "type": "record", + "name": "Student", + "fields": [ + {"name": "name", "type": "string"}, + {"name": "age", "type": "int"} + ] + }`; + + Person student = { + name: "Liam", + age: 52 + }; + + Schema avro = check new (schema); + byte[] encode = check avro.toAvro(student); + Person deserialize = check avro.fromAvro(encode); + test:assertEquals(student, deserialize); +} + +@test:Config {} +public isolated function testRecordsWithUnionTypes() returns error? { + string schema = string ` + { + "namespace": "example.avro", + "type": "record", + "name": "Course", + "fields": [ + {"name": "name", "type": ["string", "null"]}, + {"name": "credits", "type": ["int", "null"]} + ] + }`; + + Course course = { + name: (), + credits: () + }; + + Schema avro = check new (schema); + byte[] serialize = check avro.toAvro(course); + Course deserialize = check avro.fromAvro(serialize); + test:assertEquals(course, deserialize); +} + +@test:Config {} +public isolated function testArrays() returns error? { + string schema = string ` + { + "type": "array", + "name" : "StringArray", + "namespace": "data", + "items": "string" + }`; + + string[] colors = ["red", "green", "blue"]; + + Schema avro = check new (schema); + byte[] encode = check avro.toAvro(colors); + string[] deserializeJson = check avro.fromAvro(encode); + test:assertEquals(deserializeJson, colors); +} + +@test:Config {} +public isolated function testIntValue() returns error? { + string schema = string ` + { + "type": "int", + "name" : "intValue", + "namespace": "data" + }`; + + int value = 5; + + Schema avro = check new (schema); + byte[] encode = check avro.toAvro(value); + int deserializeJson = check avro.fromAvro(encode); + test:assertEquals(deserializeJson, value); +} + +@test:Config {} +public isolated function testFloatValue() returns error? { + string schema = string ` + { + "type": "float", + "name" : "floatValue", + "namespace": "data" + }`; + + float value = 5.5; + + Schema avro = check new (schema); + byte[] encode = check avro.toAvro(value); + float deserializeJson = check avro.fromAvro(encode); + test:assertEquals(deserializeJson, value); +} + +@test:Config {} +public isolated function testDoubleValue() returns error? { + string schema = string ` + { + "type": "double", + "name" : "doubleValue", + "namespace": "data" + }`; + + float value = 5.5595; + + Schema avro = check new (schema); + byte[] encode = check avro.toAvro(value); + float deserializeJson = check avro.fromAvro(encode); + test:assertEquals(deserializeJson, value); +} + +@test:Config {} +public isolated function testLongValue() returns error? { + string schema = string ` + { + "type": "long", + "name" : "longValue", + "namespace": "data" + }`; + + int value = 555950000000000000; + Schema avro = check new (schema); + byte[] encode = check avro.toAvro(value); + int deserializeJson = check avro.fromAvro(encode); + test:assertEquals(deserializeJson, value); +} + +@test:Config { + groups: ["primitive"] +} +public isolated function testStringValue() returns error? { + string schema = string ` + { + "type": "string", + "name" : "stringValue", + "namespace": "data" + }`; + + string value = "test"; + Schema avro = check new (schema); + byte[] encode = check avro.toAvro(value); + string deserializeJson = check avro.fromAvro(encode); + test:assertEquals(deserializeJson, value); +} + +@test:Config {} +public isolated function testBoolean() returns error? { + string schema = string ` + { + "type": "boolean", + "name" : "booleanValue", + "namespace": "data" + }`; + + boolean value = true; + Schema avro = check new (schema); + byte[] encode = check avro.toAvro(value); + boolean deserializeJson = check avro.fromAvro(encode); + test:assertEquals(deserializeJson, value); +} + +@test:Config {} +public isolated function testNullValues() returns error? { + string schema = string ` + { + "type": "null", + "name" : "nullValue", + "namespace": "data" + }`; + + Schema avro = check new (schema); + byte[] encode = check avro.toAvro(()); + () deserializeJson = check avro.fromAvro(encode); + test:assertEquals(deserializeJson, ()); +} + +@test:Config {} +public isolated function testNullValuesWithNonNullData() returns error? { + string schema = string ` + { + "type": "null", + "name" : "nullValue", + "namespace": "data" + }`; + + Schema avro = check new (schema); + byte[]|error encode = avro.toAvro("string"); + test:assertTrue(encode is error); +} + +@test:Config {} +public isolated function testFixed() returns error? { + string schema = string ` + { + "type": "fixed", + "name": "name", + "size": 16 + }`; + + byte[] value = "u00ffffffffffffx".toBytes(); + + Schema avro = check new (schema); + byte[] encode = check avro.toAvro(value); + byte[] deserialize = check avro.fromAvro(encode); + test:assertEquals(deserialize, value); +} + +@test:Config {} +public function testDbSchemaWithRecords() returns error? { + string schema = string ` + { + "connect.name": "io.debezium.connector.sqlserver.SchemaChangeKey", + "connect.version": 1, + "fields": [ + { + "name": "databaseName", + "type": "string" + } + ], + "name": "SchemaChangeKey", + "namespace": "io.debezium.connector.sqlserver", + "type": "record" + }`; + + SchemaChangeKey changeKey = { + databaseName: "my-db" + }; + + Schema avro = check new (schema); + byte[] serialize = check avro.toAvro(changeKey); + SchemaChangeKey deserialize = check avro.fromAvro(serialize); + test:assertEquals(changeKey, deserialize); + +} + +@test:Config {} +public function testComplexDbSchema() returns error? { + string jsonFileName = string `tests/resources/schema_1.json`; + json result = check io:fileReadJson(jsonFileName); + string schema = result.toString(); + + Envelope envelope = { + before: { + ID: 1, + OfferID: "offer1", + PropertyId: 100, + PlayerUnityID: "player1", + HALoOfferStatus: "status1", + StatusDateTime: 1633020142, + OfferSegmentID: 200, + RedemptionDate: 1633020142, + OfferItemID: 300, + OfferPrizeCode: "prize1", + AmountRedeemed: 500.0, + ItemQuantity: 5, + OfferType: "type1", + CreatedDate: 1633020142, + CreatedBy: "creator1", + UpdatedDate: 1633020142, + UpdatedBy: "updater1" + }, + after: { + ID: 2, + OfferID: "offer2", + PropertyId: 101, + PlayerUnityID: "player2", + HALoOfferStatus: "status2", + StatusDateTime: 1633020143, + OfferSegmentID: 201, + RedemptionDate: 1633020143, + OfferItemID: 301, + OfferPrizeCode: "prize2", + AmountRedeemed: 600.0, + ItemQuantity: 6, + OfferType: "type2", + CreatedDate: 1633020143, + CreatedBy: "creator2", + UpdatedDate: 1633020143, + UpdatedBy: "updater2" + }, + 'source: { + version: "1.0", + connector: "connector1", + name: "source1", + ts_ms: 1633020144, + snapshot: "snapshot1", + db: "db1", + sequence: "sequence1", + schema: "schema1", + 'table: "table1", + change_lsn: "lsn1", + commit_lsn: "lsn2", + event_serial_no: 1 + }, + op: "op1", + ts_ms: 1633020145, + 'transaction: { + id: "transaction1", + total_order: 1, + data_collection_order: 1 + } + }; + + Schema avro = check new (schema); + byte[] serialize = check avro.toAvro(envelope); + Envelope deserialize = check avro.fromAvro(serialize); + test:assertEquals(envelope, deserialize); +} + +@test:Config { +} +public function testComplexDbSchemaWithNestedRecords() returns error? { + string jsonFileName = string `tests/resources/schema_2.json`; + json result = check io:fileReadJson(jsonFileName); + string schema = result.toString(); + + Envelope2 envelope2 = { + before: { + CorePlayerID: 123, + AccountNumber: "123456", + LastName: "Doe", + FirstName: "John", + MiddleName: "M", + Gender: "M", + Language: "English", + Discreet: false, + Deceased: false, + IsBanned: false, + EmailAddress: "john.doe@example.com", + IsVerified: true, + EmailStatus: "Verified", + MobilePhone: "1234567890", + HomePhone: "0987654321", + HomeStreetAddress: "123 Street", + HomeCity: "City", + HomeState: "State", + HomePostalCode: "12345", + HomeCountry: "Country", + AltStreetAddress: "456 Street", + AltCity: "Alt City", + AltState: "Alt State", + AltCountry: "Alt Country", + DateOfBirth: 1234567890, + EnrollDate: 1234567890, + PredomPropertyId: "PropertyId", + AccountType: "Type", + InsertDtm: 1234567890, + AltPostalCode: "54321", + BatchID: 123, + GlobalRank: "Rank", + GlobalValuationScore: 1.0, + PlayerType: "Type", + AccountStatus: "Status", + RegistrationSource: "Source", + BannedReason: "Reason", + TierCode: "Code", + TierName: "Name", + TierEndDate: 1234567890, + VIPFlag: false + }, + after: { + CorePlayerID: 456, + AccountNumber: "654321", + LastName: "Smith", + FirstName: "Jane", + MiddleName: "K", + Gender: "F", + Language: "Spanish", + Discreet: true, + Deceased: false, + IsBanned: false, + EmailAddress: "jane.smith@example.com", + IsVerified: false, + EmailStatus: "Unverified", + MobilePhone: "0987654321", + HomePhone: "1234567890", + HomeStreetAddress: "456 Street", + HomeCity: "Alt City", + HomeState: "Alt State", + HomePostalCode: "54321", + HomeCountry: "Alt Country", + AltStreetAddress: "123 Street", + AltCity: "City", + AltState: "State", + AltCountry: "Country", + DateOfBirth: 9876543210, + EnrollDate: 9876543210, + PredomPropertyId: "AltPropertyId", + AccountType: "AltType", + InsertDtm: 9876543210, + AltPostalCode: "12345", + BatchID: 456, + GlobalRank: "AltRank", + GlobalValuationScore: 2.0, + PlayerType: "AltType", + AccountStatus: "AltStatus", + RegistrationSource: "AltSource", + BannedReason: "AltReason", + TierCode: "AltCode", + TierName: "AltName", + TierEndDate: 9876543210, + VIPFlag: true + }, + 'source: { + version: "1.0", + connector: "connector", + name: "name", + ts_ms: 123456789, + snapshot: "snapshot", + db: "db", + sequence: "sequence", + schema: "schema", + 'table: "table", + change_lsn: "lsn", + commit_lsn: "lsn", + event_serial_no: 1 + }, + op: "op", + ts_ms: 123456789, + 'transaction: { + id: "id", + total_order: 1, + data_collection_order: 1 + }, + MessageSource: "MessageSource" + }; + + Schema avro = check new (schema); + byte[] serialize = check avro.toAvro(envelope2); + Envelope2 deserialize = check avro.fromAvro(serialize); + test:assertEquals(envelope2, deserialize); +} diff --git a/ballerina/tests/types.bal b/ballerina/tests/types.bal index 5658dbc..ef73d18 100644 --- a/ballerina/tests/types.bal +++ b/ballerina/tests/types.bal @@ -1,186 +1,186 @@ -// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com). -// -// WSO2 LLC. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -public type Student record { - string name; - string subject; -}; - -public type Person record { - string name; - int age; -}; - -public type Course record { - string? name; - int? credits; -}; - -public type Instructor record { - string? name; - Student student; -}; - -public type Lecturer record { - string? name; - Instructor instructor; -}; - -public type Color record { - string? name; - string[] colors; -}; - -public type FixedRec record { - byte[] fixed_field; - string other_field; -}; - -enum Numbers { - ONE, - TWO, - THREE, - FOUR -}; - -public type SchemaChangeKey record { - string databaseName; -}; - -public type Value record { - int ID; - string? OfferID; - int? PropertyId; - string? PlayerUnityID; - string? HALoOfferStatus; - int? StatusDateTime; - int? OfferSegmentID; - int? RedemptionDate; - int? OfferItemID; - string? OfferPrizeCode; - float? AmountRedeemed; - int? ItemQuantity; - string? OfferType; - int? CreatedDate; - string? CreatedBy; - int? UpdatedDate; - string? UpdatedBy; -}; - -public type Source record { - string version; - string connector; - string name; - int ts_ms; - string snapshot; - string db; - string? sequence; - string schema; - string 'table; - string? change_lsn; - string? commit_lsn; - int? event_serial_no; -}; - -public type Block record { - string id; - int total_order; - int data_collection_order; -}; - -public type Envelope record { - Value? before; - Value? after; - Source 'source; - string op; - int? ts_ms; - Block? 'transaction; -}; - -public type Value2 record { - int CorePlayerID; - string? AccountNumber; - string? LastName; - string? FirstName; - string? MiddleName; - string? Gender; - string? Language; - boolean? Discreet; - boolean? Deceased; - boolean? IsBanned; - string? EmailAddress; - boolean? IsVerified; - string? EmailStatus; - string? MobilePhone; - string? HomePhone; - string? HomeStreetAddress; - string? HomeCity; - string? HomeState; - string? HomePostalCode; - string? HomeCountry; - string? AltStreetAddress; - string? AltCity; - string? AltState; - string? AltCountry; - int? DateOfBirth; - int? EnrollDate; - string? PredomPropertyId; - string? AccountType; - int? InsertDtm; - string? AltPostalCode; - int? BatchID; - string? GlobalRank; - float? GlobalValuationScore; - string? PlayerType; - string? AccountStatus; - string? RegistrationSource; - string? BannedReason; - string? TierCode; - string? TierName; - int? TierEndDate; - boolean? VIPFlag; -}; - -public type Source2 record { - string version; - string connector; - string name; - int ts_ms; - string snapshot; - string db; - string? sequence; - string schema; - string 'table; - string? change_lsn; - string? commit_lsn; - int? event_serial_no; -}; - -public type Block2 record { - string id; - int total_order; - int data_collection_order; -}; - -public type Envelope2 record { - Value2? before; - Value2? after; - Source2 'source; - string op; - int? ts_ms; - Block2? 'transaction; - string? MessageSource; -}; +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public type Student record { + string name; + string subject; +}; + +public type Person record { + string name; + int age; +}; + +public type Course record { + string? name; + int? credits; +}; + +public type Instructor record { + string? name; + Student student; +}; + +public type Lecturer record { + string? name; + Instructor instructor; +}; + +public type Color record { + string? name; + string[] colors; +}; + +public type FixedRec record { + byte[] fixed_field; + string other_field; +}; + +enum Numbers { + ONE, + TWO, + THREE, + FOUR +}; + +public type SchemaChangeKey record { + string databaseName; +}; + +public type Value record { + int ID; + string? OfferID; + int? PropertyId; + string? PlayerUnityID; + string? HALoOfferStatus; + int? StatusDateTime; + int? OfferSegmentID; + int? RedemptionDate; + int? OfferItemID; + string? OfferPrizeCode; + float? AmountRedeemed; + int? ItemQuantity; + string? OfferType; + int? CreatedDate; + string? CreatedBy; + int? UpdatedDate; + string? UpdatedBy; +}; + +public type Source record { + string version; + string connector; + string name; + int ts_ms; + string snapshot; + string db; + string? sequence; + string schema; + string 'table; + string? change_lsn; + string? commit_lsn; + int? event_serial_no; +}; + +public type Block record { + string id; + int total_order; + int data_collection_order; +}; + +public type Envelope record { + Value? before; + Value? after; + Source 'source; + string op; + int? ts_ms; + Block? 'transaction; +}; + +public type Value2 record { + int CorePlayerID; + string? AccountNumber; + string? LastName; + string? FirstName; + string? MiddleName; + string? Gender; + string? Language; + boolean? Discreet; + boolean? Deceased; + boolean? IsBanned; + string? EmailAddress; + boolean? IsVerified; + string? EmailStatus; + string? MobilePhone; + string? HomePhone; + string? HomeStreetAddress; + string? HomeCity; + string? HomeState; + string? HomePostalCode; + string? HomeCountry; + string? AltStreetAddress; + string? AltCity; + string? AltState; + string? AltCountry; + int? DateOfBirth; + int? EnrollDate; + string? PredomPropertyId; + string? AccountType; + int? InsertDtm; + string? AltPostalCode; + int? BatchID; + string? GlobalRank; + float? GlobalValuationScore; + string? PlayerType; + string? AccountStatus; + string? RegistrationSource; + string? BannedReason; + string? TierCode; + string? TierName; + int? TierEndDate; + boolean? VIPFlag; +}; + +public type Source2 record { + string version; + string connector; + string name; + int ts_ms; + string snapshot; + string db; + string? sequence; + string schema; + string 'table; + string? change_lsn; + string? commit_lsn; + int? event_serial_no; +}; + +public type Block2 record { + string id; + int total_order; + int data_collection_order; +}; + +public type Envelope2 record { + Value2? before; + Value2? after; + Source2 'source; + string op; + int? ts_ms; + Block2? 'transaction; + string? MessageSource; +};