Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloem committed Nov 23, 2022
1 parent a14c8c4 commit 342edca
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ class BeamModulePlugin implements Plugin<Project> {
joda_time : "joda-time:joda-time:2.10.10",
jsonassert : "org.skyscreamer:jsonassert:1.5.0",
jsr305 : "com.google.code.findbugs:jsr305:$jsr305_version",
json_org : "org.json:json:20200518", // Try to keep in sync with google_cloud_platform_libraries_bom transitive deps.
json_org : "org.json:json", // Try to keep in sync with google_cloud_platform_libraries_bom transitive deps.
everit_json_schema : "com.github.erosb:everit-json-schema:${everit_json_version}",
junit : "junit:junit:4.13.1",
kafka : "org.apache.kafka:kafka_2.11:$kafka_version",
Expand Down
6 changes: 4 additions & 2 deletions sdks/java/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ dependencies {
shadow library.java.avro
shadow library.java.snappy_java
shadow library.java.joda_time
shadow library.java.json_org
implementation enforcedPlatform(library.java.google_cloud_platform_libraries_bom)
permitUnusedDeclared enforcedPlatform(library.java.google_cloud_platform_libraries_bom)
provided library.java.json_org
// com.github.everit JSON schema validation library is used for json-schema.org validation.
// to aoid forcing the library onto users, we ask users to provide it rather than include
// to avoid forcing the library onto users, we ask users to provide it rather than include
// it by default.
// It is only used for optional functionality in JsonUtils schema parsing and conversion.
provided library.java.everit_json_schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class JsonSchemaConversionTest {
@Test
public void testBasicJsonSchemaToBeamSchema() throws IOException {
try (InputStream inputStream =
getClass().getResourceAsStream("/schemas/json/basic_json_schema.json")) {
getClass().getResourceAsStream("/json-schema/basic_json_schema.json")) {
String stringJsonSchema = new String(ByteStreams.toByteArray(inputStream), "UTF-8");
Schema parsedSchema = JsonUtils.beamSchemaFromJsonSchema(stringJsonSchema);

Expand All @@ -57,7 +57,7 @@ public void testBasicJsonSchemaToBeamSchema() throws IOException {
@Test
public void testNestedStructsJsonSchemaToBeamSchema() throws IOException {
try (InputStream inputStream =
getClass().getResourceAsStream("/schemas/json/nested_arrays_objects_json_schema.json")) {
getClass().getResourceAsStream("/json-schema/nested_arrays_objects_json_schema.json")) {
String stringJsonSchema = new String(ByteStreams.toByteArray(inputStream), "UTF-8");
Schema parsedSchema = JsonUtils.beamSchemaFromJsonSchema(stringJsonSchema);

Expand All @@ -77,7 +77,7 @@ public void testNestedStructsJsonSchemaToBeamSchema() throws IOException {
@Test
public void testArrayNestedArrayObjectJsonSchemaToBeamSchema() throws IOException {
try (InputStream inputStream =
getClass().getResourceAsStream("/schemas/json/array_nested_array_json_schema.json")) {
getClass().getResourceAsStream("/json-schema/array_nested_array_json_schema.json")) {
String stringJsonSchema = new String(ByteStreams.toByteArray(inputStream), "UTF-8");
Schema parsedSchema = JsonUtils.beamSchemaFromJsonSchema(stringJsonSchema);

Expand All @@ -98,7 +98,7 @@ public void testArrayNestedArrayObjectJsonSchemaToBeamSchema() throws IOExceptio
public void testObjectNestedObjectArrayJsonSchemaToBeamSchema() throws IOException {
try (InputStream inputStream =
getClass()
.getResourceAsStream("/schemas/json/object_nested_object_and_array_json_schema.json")) {
.getResourceAsStream("/json-schema/object_nested_object_and_array_json_schema.json")) {
String stringJsonSchema = new String(ByteStreams.toByteArray(inputStream), "UTF-8");
Schema parsedSchema = JsonUtils.beamSchemaFromJsonSchema(stringJsonSchema);

Expand All @@ -125,10 +125,36 @@ public void testObjectNestedObjectArrayJsonSchemaToBeamSchema() throws IOExcepti
}
}

@Test
public void testArrayWithNestedRefsBeamSchema() throws IOException {
try (InputStream inputStream =
getClass().getResourceAsStream("/json-schema/ref_with_ref_json_schema.json")) {
String stringJsonSchema = new String(ByteStreams.toByteArray(inputStream), "UTF-8");
Schema parsedSchema = JsonUtils.beamSchemaFromJsonSchema(stringJsonSchema);

assertThat(parsedSchema.getFieldNames(), containsInAnyOrder("vegetables"));
assertThat(
parsedSchema.getFields().stream().map(Schema.Field::getType).collect(Collectors.toList()),
containsInAnyOrder(
Schema.FieldType.array(
Schema.FieldType.row(
Schema.of(
Schema.Field.of("veggieName", Schema.FieldType.STRING),
Schema.Field.of("veggieLike", Schema.FieldType.BOOLEAN),
Schema.Field.of(
"origin",
Schema.FieldType.row(
Schema.of(
Schema.Field.of("country", Schema.FieldType.STRING),
Schema.Field.of("town", Schema.FieldType.STRING),
Schema.Field.of("region", Schema.FieldType.STRING)))))))));
}
}

@Test
public void testUnsupportedTupleArrays() throws IOException {
try (InputStream inputStream =
getClass().getResourceAsStream("/schemas/json/unsupported_tuple_arrays.json")) {
getClass().getResourceAsStream("/json-schema/unsupported_tuple_arrays.json")) {
String stringJsonSchema = new String(ByteStreams.toByteArray(inputStream), "UTF-8");

IllegalArgumentException thrownException =
Expand All @@ -146,7 +172,7 @@ public void testUnsupportedTupleArrays() throws IOException {
@Test
public void testUnsupportedNestedTupleArrays() throws IOException {
try (InputStream inputStream =
getClass().getResourceAsStream("/schemas/json/unsupported_nested_tuple_array.json")) {
getClass().getResourceAsStream("/json-schema/unsupported_nested_tuple_array.json")) {
String stringJsonSchema = new String(ByteStreams.toByteArray(inputStream), "UTF-8");

IllegalArgumentException thrownException =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"$id": "https://example.com/arrays.schema.json",
"type": "object",
"properties": {
"vegetables": {
"type": "array",
"items": { "$ref": "#/$defs/veggie" }
}
},
"$defs": {
"veggie": {
"type": "object",
"required": [ "veggieName", "veggieLike" ],
"properties": {
"veggieName": {
"type": "string",
"description": "The name of the vegetable."
},
"veggieLike": {
"type": "boolean",
"description": "Do I like this vegetable?"
},
"origin": {
"$ref": "#/$defs/location"
}
}
},
"location": {
"type": "object",
"properties": {
"country": {
"type": "string"
},
"region": {
"type": "string"
},
"town": {
"type": "string"
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
*/
package org.apache.beam.sdk.tpcds;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
Expand Down Expand Up @@ -142,8 +143,10 @@ public void testWarehouseTable() throws Exception {
public void testGetAllTableNames() throws IOException {
List<String> tableNames = TableSchemaJSONLoader.getAllTableNames();
Collections.sort(tableNames);
List<String> expectedTableNames =
Arrays.asList(

assertThat(
tableNames,
containsInAnyOrder(
"call_center",
"catalog_page",
"catalog_returns",
Expand All @@ -167,12 +170,6 @@ public void testGetAllTableNames() throws IOException {
"web_page",
"web_returns",
"web_sales",
"web_site");

assertEquals(expectedTableNames.size(), tableNames.size());

for (int i = 0; i < tableNames.size(); i++) {
assertEquals(expectedTableNames.get(i), tableNames.get(i));
}
"web_site"));
}
}

0 comments on commit 342edca

Please sign in to comment.