-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support more types in converting RelDatatype to Avro type (#29)
Co-authored-by: Wenye Zhang <[email protected]>
- Loading branch information
1 parent
5bf50c5
commit 05ebc22
Showing
8 changed files
with
437 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
coral-schema/src/test/java/com/linkedin/coral/schema/avro/RelDataTypeToAvroTypeTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Copyright 2020 LinkedIn Corporation. All rights reserved. | ||
* Licensed under the BSD-2 Clause license. | ||
* See LICENSE in the project root for license information. | ||
*/ | ||
package com.linkedin.coral.schema.avro; | ||
|
||
import com.linkedin.coral.hive.hive2rel.HiveToRelConverter; | ||
import org.apache.avro.Schema; | ||
import org.apache.calcite.rel.RelNode; | ||
import org.apache.hadoop.hive.metastore.api.MetaException; | ||
import org.apache.hadoop.hive.ql.metadata.HiveException; | ||
import org.testng.Assert; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
|
||
public class RelDataTypeToAvroTypeTests { | ||
private HiveToRelConverter hiveToRelConverter; | ||
|
||
@BeforeClass | ||
public void beforeClass() throws HiveException, MetaException { | ||
hiveToRelConverter = TestUtils.setupRelDataTypeToAvroTypeTests(); | ||
} | ||
|
||
@Test | ||
public void testNestedRecord() { | ||
String viewSql = "CREATE VIEW v AS SELECT * FROM basecomplex"; | ||
|
||
TestUtils.executeCreateViewQuery("default", "v", viewSql); | ||
RelNode relNode = hiveToRelConverter.convertView("default", "v"); | ||
Schema actualAvroType = RelDataTypeToAvroType.relDataTypeToAvroTypeNonNullable(relNode.getRowType(), "nestedRecord"); | ||
|
||
Assert.assertEquals(actualAvroType.toString(true), | ||
TestUtils.loadSchema("rel2avro-testNestedRecord-expected.avsc")); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
coral-schema/src/test/resources/base-nested-complex.avsc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
{ | ||
"type" : "record", | ||
"name" : "basenestedcomplex", | ||
"namespace" : "coral.schema.avro.base.nested.complex", | ||
"fields" : [ { | ||
"name" : "id", | ||
"type" : "int" | ||
}, { | ||
"name" : "array_col", | ||
"type" : [ "null", { | ||
"type" : "array", | ||
"items" : [ "null", { | ||
"type" : "record", | ||
"name" : "Array_Col", | ||
"namespace" : "coral.schema.avro.base.nested.complex.basenestedcomplex", | ||
"fields" : [ { | ||
"name" : "Bool_Field", | ||
"type" : [ "null", "boolean" ], | ||
"default" : null | ||
}, { | ||
"name" : "Int_Field", | ||
"type" : [ "null", "int" ] | ||
}, { | ||
"name" : "Bigint_Field", | ||
"type" : [ "null", "long" ], | ||
"default" : null | ||
}, { | ||
"name" : "Float_Field", | ||
"type" : [ "null", "float" ] | ||
}, { | ||
"name" : "Double_Field", | ||
"type" : [ "null", "double" ], | ||
"default" : null | ||
}, { | ||
"name" : "Date_String_Field", | ||
"type" : [ "null", "string" ] | ||
}, { | ||
"name" : "String_Field", | ||
"type" : [ "null", "string" ], | ||
"default" : null | ||
}, { | ||
"name" : "Array_Col_1", | ||
"type" : [ "null", { | ||
"type" : "array", | ||
"items" : { | ||
"type" : "array", | ||
"items" : "string" | ||
} | ||
} ], | ||
"default" : null | ||
}, { | ||
"name" : "Array_Col_2", | ||
"type" : [ "null", { | ||
"type" : "array", | ||
"items" : { | ||
"type" : "map", | ||
"values" : "string" | ||
} | ||
} ], | ||
"default" : null | ||
}, { | ||
"name" : "Map_Col_3", | ||
"type" : [ "null", { | ||
"type" : "map", | ||
"values" : { | ||
"type" : "map", | ||
"values" : "string" | ||
} | ||
} ], | ||
"default" : null | ||
}, { | ||
"name" : "Map_Col_4", | ||
"type" : [ "null", { | ||
"type" : "map", | ||
"values" : { | ||
"type" : "array", | ||
"items" : "string" | ||
} | ||
} ], | ||
"default" : null | ||
} ] | ||
} ] | ||
} ], | ||
"default" : null | ||
}, { | ||
"name" : "struct_col", | ||
"type" : [ "null", { | ||
"type" : "record", | ||
"name" : "Struct_col", | ||
"namespace" : "coral.schema.avro.base.nested.complex.basenestedcomplex", | ||
"fields" : [ { | ||
"name" : "bool_field", | ||
"type" : [ "null", "boolean" ], | ||
"default" : null | ||
}, { | ||
"name" : "int_field", | ||
"type" : [ "null", "int" ], | ||
"default" : null | ||
}, { | ||
"name" : "bigint_field", | ||
"type" : [ "null", "long" ], | ||
"default" : null | ||
}, { | ||
"name" : "float_field", | ||
"type" : [ "null", "float" ], | ||
"default" : null | ||
}, { | ||
"name" : "double_field", | ||
"type" : [ "null", "double" ], | ||
"default" : null | ||
}, { | ||
"name" : "date_string_field", | ||
"type" : [ "null", "string" ], | ||
"default" : null | ||
}, { | ||
"name" : "string_field", | ||
"type" : [ "null", "string" ], | ||
"default" : null | ||
} ] | ||
} ], | ||
"default" : null | ||
} ] | ||
} |
Oops, something went wrong.