Skip to content

Commit

Permalink
new UT + spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinGe00 committed May 4, 2024
1 parent ea37ff4 commit 0957a75
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2017-2023 LinkedIn Corporation. All rights reserved.
* Copyright 2017-2024 LinkedIn Corporation. All rights reserved.
* Licensed under the BSD-2 Clause license.
* See LICENSE in the project root for license information.
*/
Expand Down Expand Up @@ -96,6 +96,20 @@ public void testTableWithUnion() {
assertEquals(rowType.toString(), expectedTypeString);
}

@Test
public void testTableWithSingleUnion() {
final RelDataTypeFactory typeFactory = new JavaTypeFactoryImpl();

Table unionTable = getTable("default", "single_union");
// single_union(foo uniontype<array<string>>)
// expected outcome schema: struct<tag:int, field0:array<string>>
RelDataType rowType = unionTable.getRowType(typeFactory);
assertNotNull(rowType);

String expectedTypeString = "RecordType(RecordType(INTEGER tag, VARCHAR(65536) ARRAY field0) foo)";
assertEquals(rowType.toString(), expectedTypeString);
}

@Test
public void testTableWithUnionComplex() throws Exception {
// Two complex scenarios for union:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ public void testUnionExtractUDF() {
// Single type uniontypes should not be unwrapped into the underlying type
@Test
public void testSingleTypeUnion() {
final String sql = "SELECT bar from union_table";
final String sql = "SELECT foo from union_table";
RelNode rel = toRel(sql);
RelDataTypeFieldImpl unionRowType = (RelDataTypeFieldImpl) rel.getRowType().getFieldList().get(0);
assertTrue(unionRowType.getValue().getFieldList().get(0).getKey().equals("tag")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ public static TestHive setupDefaultHive(HiveConf conf) throws IOException {
}

driver.run(
"CREATE TABLE IF NOT EXISTS union_table(foo uniontype<int, double, array<string>, struct<a:int,b:string>>, bar uniontype<array<string>>)");
"CREATE TABLE IF NOT EXISTS union_table(foo uniontype<int, double, array<string>, struct<a:int,b:string>>)");

driver.run("CREATE TABLE IF NOT EXISTS single_union(foo uniontype<array<string>>)");

// Nested union case.
// We don't put a union directly under a union since sources like https://avro.apache.org/docs/current/spec.html#Unions
Expand All @@ -212,8 +214,8 @@ public static TestHive setupDefaultHive(HiveConf conf) throws IOException {
new TestHive.DB("test", ImmutableList.of("tableOne", "tableTwo", "tableOneView")),
new TestHive.DB("default",
ImmutableList.of("bar", "complex", "foo", "foo_view", "null_check_view", "null_check_wrapper",
"schema_evolve", "view_schema_evolve", "view_schema_evolve_wrapper", "union_table", "nested_union",
"duplicate_column_name_a", "duplicate_column_name_b", "view_namesake_column_names")),
"schema_evolve", "view_schema_evolve", "view_schema_evolve_wrapper", "union_table", "single_union",
"nested_union", "duplicate_column_name_a", "duplicate_column_name_b", "view_namesake_column_names")),
new TestHive.DB("fuzzy_union",
ImmutableList.of("tableA", "tableB", "tableC", "union_view", "union_view_with_more_than_two_tables",
"union_view_with_alias", "union_view_single_branch_evolved",
Expand Down

0 comments on commit 0957a75

Please sign in to comment.