diff options
Diffstat (limited to 'exec/java-exec')
6 files changed, 27 insertions, 24 deletions
diff --git a/exec/java-exec/src/main/antlr4/org/apache/drill/exec/record/metadata/schema/parser/SchemaLexer.g4 b/exec/java-exec/src/main/antlr4/org/apache/drill/exec/record/metadata/schema/parser/SchemaLexer.g4 index bc508d0e5..62d9f100e 100644 --- a/exec/java-exec/src/main/antlr4/org/apache/drill/exec/record/metadata/schema/parser/SchemaLexer.g4 +++ b/exec/java-exec/src/main/antlr4/org/apache/drill/exec/record/metadata/schema/parser/SchemaLexer.g4 @@ -55,6 +55,7 @@ MINUTE: 'MINUTE'; SECOND: 'SECOND'; MAP: 'MAP'; +STRUCT: 'STRUCT'; ARRAY: 'ARRAY'; // symbols diff --git a/exec/java-exec/src/main/antlr4/org/apache/drill/exec/record/metadata/schema/parser/SchemaParser.g4 b/exec/java-exec/src/main/antlr4/org/apache/drill/exec/record/metadata/schema/parser/SchemaParser.g4 index 5d578fe0b..a4854be32 100644 --- a/exec/java-exec/src/main/antlr4/org/apache/drill/exec/record/metadata/schema/parser/SchemaParser.g4 +++ b/exec/java-exec/src/main/antlr4/org/apache/drill/exec/record/metadata/schema/parser/SchemaParser.g4 @@ -31,13 +31,13 @@ columns: column_def (COMMA column_def)*; column_def: column property_values?; -column: (primitive_column | map_column | simple_array_column | complex_array_column); +column: (primitive_column | struct_column | simple_array_column | complex_array_column); primitive_column: column_id simple_type nullability? format_value? default_value?; simple_array_column: column_id simple_array_type nullability?; -map_column: column_id map_type nullability?; +struct_column: column_id struct_type nullability?; complex_array_column: column_id complex_array_type nullability?; @@ -65,11 +65,11 @@ simple_type complex_type: (simple_array_type | complex_array_type); -simple_array_type: ARRAY LEFT_ANGLE_BRACKET (simple_type | map_type) RIGHT_ANGLE_BRACKET; +simple_array_type: ARRAY LEFT_ANGLE_BRACKET (simple_type | struct_type) RIGHT_ANGLE_BRACKET; complex_array_type: ARRAY LEFT_ANGLE_BRACKET complex_type RIGHT_ANGLE_BRACKET; -map_type: MAP LEFT_ANGLE_BRACKET columns RIGHT_ANGLE_BRACKET; +struct_type: STRUCT LEFT_ANGLE_BRACKET columns RIGHT_ANGLE_BRACKET; nullability: NOT NULL; diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/UnionFunctions.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/UnionFunctions.java index d63d3d634..4efa0c564 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/UnionFunctions.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/UnionFunctions.java @@ -330,7 +330,7 @@ public class UnionFunctions { } @SuppressWarnings("unused") - @FunctionTemplate(name = "IS_MAP", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls=NullHandling.INTERNAL) + @FunctionTemplate(names = {"IS_MAP", "IS_STRUCT"}, scope = FunctionTemplate.FunctionScope.SIMPLE, nulls=NullHandling.INTERNAL) public static class UnionIsMap implements DrillSimpleFunc { @Param UnionHolder in; diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/record/metadata/schema/parser/SchemaVisitor.java b/exec/java-exec/src/main/java/org/apache/drill/exec/record/metadata/schema/parser/SchemaVisitor.java index c49007b65..6ea682bba 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/record/metadata/schema/parser/SchemaVisitor.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/record/metadata/schema/parser/SchemaVisitor.java @@ -110,10 +110,10 @@ public class SchemaVisitor extends SchemaParserBaseVisitor<TupleMetadata> { } @Override - public ColumnMetadata visitMap_column(SchemaParser.Map_columnContext ctx) { + public ColumnMetadata visitStruct_column(SchemaParser.Struct_columnContext ctx) { String name = ctx.column_id().accept(new IdVisitor()); - // Drill does not distinguish between nullable and not null map, by default they are not null - return ctx.map_type().accept(new TypeVisitor(name, TypeProtos.DataMode.REQUIRED)); + // Drill does not distinguish between nullable and not null structs, by default they are not null + return ctx.struct_type().accept(new TypeVisitor(name, TypeProtos.DataMode.REQUIRED)); } @Override @@ -277,7 +277,9 @@ public class SchemaVisitor extends SchemaParserBaseVisitor<TupleMetadata> { } @Override - public ColumnMetadata visitMap_type(SchemaParser.Map_typeContext ctx) { + public ColumnMetadata visitStruct_type(SchemaParser.Struct_typeContext ctx) { + // internally Drill refers to structs as maps and currently does not have true map notion + // Drill maps will be renamed to structs in future MapBuilder builder = new MapBuilder(null, name, mode); ColumnDefVisitor visitor = new ColumnDefVisitor(); ctx.columns().column_def().forEach( @@ -308,7 +310,7 @@ public class SchemaVisitor extends SchemaParserBaseVisitor<TupleMetadata> { @Override public ColumnMetadata visitSimple_array_type(SchemaParser.Simple_array_typeContext ctx) { TypeVisitor visitor = new TypeVisitor(name, TypeProtos.DataMode.REPEATED); - return ctx.map_type() == null ? ctx.simple_type().accept(visitor) : ctx.map_type().accept(visitor); + return ctx.struct_type() == null ? ctx.simple_type().accept(visitor) : ctx.struct_type().accept(visitor); } @Override diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/record/metadata/schema/parser/TestParserErrorHandling.java b/exec/java-exec/src/test/java/org/apache/drill/exec/record/metadata/schema/parser/TestParserErrorHandling.java index 110efeb7e..320e14648 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/record/metadata/schema/parser/TestParserErrorHandling.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/record/metadata/schema/parser/TestParserErrorHandling.java @@ -104,15 +104,15 @@ public class TestParserErrorHandling { @Test public void testUnclosedAngleBracket() { - String schema = "col map<m array<int> not null"; + String schema = "col struct<m array<int> not null"; thrown.expect(SchemaParsingException.class); thrown.expectMessage("missing '>' at '<EOF>'"); SchemaExprParser.parseSchema(schema); } @Test - public void testMissingColumnNameForMap() { - String schema = "col map<int> not null"; + public void testMissingColumnNameForStruct() { + String schema = "col struct<int> not null"; thrown.expect(SchemaParsingException.class); thrown.expectMessage("mismatched input 'int' expecting {ID, QUOTED_ID}"); SchemaExprParser.parseSchema(schema); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/record/metadata/schema/parser/TestSchemaParser.java b/exec/java-exec/src/test/java/org/apache/drill/exec/record/metadata/schema/parser/TestSchemaParser.java index eaae0a50e..09b4c8aba 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/record/metadata/schema/parser/TestSchemaParser.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/record/metadata/schema/parser/TestSchemaParser.java @@ -178,11 +178,11 @@ public class TestSchemaParser { .addRepeatedList("nested_array") .addArray(TypeProtos.MinorType.INT) .resumeSchema() - .addMapArray("map_array") + .addMapArray("struct_array") .addNullable("m1", TypeProtos.MinorType.INT) .addNullable("m2", TypeProtos.MinorType.VARCHAR) .resumeSchema() - .addRepeatedList("nested_array_map") + .addRepeatedList("nested_array_struct") .addMapArray() .addNullable("nm1", TypeProtos.MinorType.INT) .addNullable("nm2", TypeProtos.MinorType.VARCHAR) @@ -192,26 +192,26 @@ public class TestSchemaParser { checkSchema("simple_array array<int>" + ", nested_array array<array<int>>" - + ", map_array array<map<m1 int, m2 varchar>>" - + ", nested_array_map array<array<map<nm1 int, nm2 varchar>>>", + + ", struct_array array<struct<m1 int, m2 varchar>>" + + ", nested_array_struct array<array<struct<nm1 int, nm2 varchar>>>", schema); } @Test - public void testMap() { + public void testStruct() { TupleMetadata schema = new SchemaBuilder() - .addMap("map_col") + .addMap("struct_col") .addNullable("int_col", TypeProtos.MinorType.INT) .addArray("array_col", TypeProtos.MinorType.INT) - .addMap("nested_map") + .addMap("nested_struct") .addNullable("m1", TypeProtos.MinorType.INT) .addNullable("m2", TypeProtos.MinorType.VARCHAR) .resumeMap() .resumeSchema() .buildSchema(); - checkSchema("map_col map<int_col int, array_col array<int>, nested_map map<m1 int, m2 varchar>>", schema); + checkSchema("struct_col struct<int_col int, array_col array<int>, nested_struct struct<m1 int, m2 varchar>>", schema); } @Test @@ -222,8 +222,8 @@ public class TestSchemaParser { } @Test - public void testModeForMapType() { - TupleMetadata schema = SchemaExprParser.parseSchema("m map<m1 int not null, m2 varchar>"); + public void testModeForStructType() { + TupleMetadata schema = SchemaExprParser.parseSchema("m struct<m1 int not null, m2 varchar>"); ColumnMetadata map = schema.metadata("m"); assertTrue(map.isMap()); assertEquals(TypeProtos.DataMode.REQUIRED, map.mode()); @@ -236,7 +236,7 @@ public class TestSchemaParser { @Test public void testModeForRepeatedType() { TupleMetadata schema = SchemaExprParser.parseSchema( - "a array<int>, aa array<array<int>>, ma array<map<m1 int not null, m2 varchar>>"); + "a array<int>, aa array<array<int>>, ma array<struct<m1 int not null, m2 varchar>>"); assertTrue(schema.metadata("a").isArray()); |