Skip to content

Commit

Permalink
Coral-Schema: Return nullable schema for inner RelDataType (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
ljfgem authored Mar 17, 2023
1 parent 37f827e commit 806b18e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package com.linkedin.coral.schema.avro;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -79,10 +78,7 @@ static Schema relDataTypeToAvroTypeNonNullable(@Nonnull RelDataType relDataType,

private static Schema relDataTypeToAvroType(RelDataType relDataType, String recordName) {
final Schema avroSchema = relDataTypeToAvroTypeNonNullable(relDataType, recordName);
if (relDataType.isNullable() && avroSchema.getType() != Schema.Type.NULL) {
return Schema.createUnion(Arrays.asList(Schema.create(Schema.Type.NULL), avroSchema));
}
return avroSchema;
return SchemaUtilities.makeNullable(avroSchema, false);
}

private static Schema basicSqlTypeToAvroType(BasicSqlType relDataType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name" : "col1",
"type" : [ "null", {
"type" : "array",
"items" : "string"
"items" : [ "null", "string" ]
} ],
"doc" : "Field created in view by applying operator 'CASE' with argument(s): true, value with type VARCHAR(65535) ARRAY, value with type VARCHAR(65535) ARRAY"
} ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
"namespace" : "default.foo_udf_return_struct.foo_udf_return_struct",
"fields" : [ {
"name" : "isEven",
"type" : "boolean"
"type" : [ "null", "boolean" ]
}, {
"name" : "number",
"type" : "int"
"type" : [ "null", "int" ]
} ]
},
"doc" : "Field created in view by applying UDF 'com.linkedin.coral.hive.hive2rel.CoralTestUDFReturnStruct' with argument(s): coral.schema.avro.base.complex.basecomplex.Id"
Expand Down

0 comments on commit 806b18e

Please sign in to comment.