From 6f6ccc1e71de999c133341e25ed364948fb6d4fb Mon Sep 17 00:00:00 2001 From: Jiefan Li Date: Wed, 31 Aug 2022 07:40:19 -0700 Subject: [PATCH] Coral-Schema: Add support for LogicalValues --- .../coral/schema/avro/RelToAvroSchemaConverter.java | 6 ++++-- .../schema/avro/ViewToAvroSchemaConverterTests.java | 7 +++++++ .../resources/testSelectWithoutBaseTable-expected.avsc | 10 ++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 coral-schema/src/test/resources/testSelectWithoutBaseTable-expected.avsc diff --git a/coral-schema/src/main/java/com/linkedin/coral/schema/avro/RelToAvroSchemaConverter.java b/coral-schema/src/main/java/com/linkedin/coral/schema/avro/RelToAvroSchemaConverter.java index 87690b29e..24557d9ce 100644 --- a/coral-schema/src/main/java/com/linkedin/coral/schema/avro/RelToAvroSchemaConverter.java +++ b/coral-schema/src/main/java/com/linkedin/coral/schema/avro/RelToAvroSchemaConverter.java @@ -197,8 +197,10 @@ public RelNode visit(TableFunctionScan tableFunctionScan) { @Override public RelNode visit(LogicalValues logicalValues) { - // TODO: implement this method - return super.visit(logicalValues); + RelNode relNode = super.visit(logicalValues); + schemaMap.put(logicalValues, + RelDataTypeToAvroType.relDataTypeToAvroTypeNonNullable(logicalValues.getRowType(), "literalvalue")); + return relNode; } @Override diff --git a/coral-schema/src/test/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverterTests.java b/coral-schema/src/test/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverterTests.java index dd381f839..4b5601aff 100644 --- a/coral-schema/src/test/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverterTests.java +++ b/coral-schema/src/test/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverterTests.java @@ -1024,5 +1024,12 @@ public void testLowercaseSchema() { Assert.assertEquals(actualSchema.toString(true), TestUtils.loadSchema("testLowercaseSchema-expected.avsc")); } + @Test + public void testSelectWithoutBaseTable() { + final ViewToAvroSchemaConverter viewToAvroSchemaConverter = ViewToAvroSchemaConverter.create(hiveMetastoreClient); + final Schema actualSchema = viewToAvroSchemaConverter.toAvroSchema("SELECT 1 intCol"); + + Assert.assertEquals(actualSchema.toString(true), TestUtils.loadSchema("testSelectWithoutBaseTable-expected.avsc")); + } // TODO: add more unit tests } diff --git a/coral-schema/src/test/resources/testSelectWithoutBaseTable-expected.avsc b/coral-schema/src/test/resources/testSelectWithoutBaseTable-expected.avsc new file mode 100644 index 000000000..ed51a5205 --- /dev/null +++ b/coral-schema/src/test/resources/testSelectWithoutBaseTable-expected.avsc @@ -0,0 +1,10 @@ +{ + "type" : "record", + "name" : "literalvalue", + "namespace" : "rel_avro", + "fields" : [ { + "name" : "intCol", + "type" : [ "null", "int" ], + "doc" : "Field created from view literal with value: 1" + } ] +} \ No newline at end of file