[
https://issues.apache.org/jira/browse/DRILL-6791?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16686539#comment-16686539
]
ASF GitHub Bot commented on DRILL-6791:
---------------------------------------
arina-ielchiieva commented on a change in pull request #1501: DRILL-6791: Scan
projection framework
URL: https://github.com/apache/drill/pull/1501#discussion_r233455585
##########
File path:
exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/scan/project/TestNullColumnLoader.java
##########
@@ -0,0 +1,329 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.physical.impl.scan.project;
+
+import static org.junit.Assert.assertSame;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.drill.common.types.TypeProtos.DataMode;
+import org.apache.drill.common.types.TypeProtos.MajorType;
+import org.apache.drill.common.types.TypeProtos.MinorType;
+import org.apache.drill.common.types.Types;
+import org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder;
+import org.apache.drill.exec.physical.impl.scan.project.NullColumnLoader;
+import org.apache.drill.exec.physical.impl.scan.project.ResolvedNullColumn;
+import org.apache.drill.exec.physical.rowSet.ResultVectorCache;
+import org.apache.drill.exec.physical.rowSet.impl.NullResultVectorCacheImpl;
+import org.apache.drill.exec.physical.rowSet.impl.ResultVectorCacheImpl;
+import org.apache.drill.exec.record.BatchSchema;
+import org.apache.drill.exec.record.VectorContainer;
+import org.apache.drill.exec.vector.ValueVector;
+import org.apache.drill.test.SubOperatorTest;
+import org.apache.drill.test.rowSet.RowSet.SingleRowSet;
+import org.apache.drill.test.rowSet.schema.SchemaBuilder;
+import org.apache.drill.test.rowSet.RowSetComparison;
+import org.junit.Test;
+
+/**
+ * Test the mechanism that handles all-null columns during projection.
+ * An all-null column is one projected in the query, but which does
+ * not actually exist in the underlying data source (or input
+ * operator.)
+ * <p>
+ * In anticipation of having type information, this mechanism
+ * can create the classic nullable Int null column, or one of
+ * any other type and mode.
+ */
+
+public class TestNullColumnLoader extends SubOperatorTest {
+
+ private ResolvedNullColumn makeNullCol(String name, MajorType nullType) {
+
+ // For this test, we don't need the projection, so just
+ // set it to null.
+
+ return new ResolvedNullColumn(name, nullType, null, 0);
+ }
+
+ private ResolvedNullColumn makeNullCol(String name) {
+ return makeNullCol(name, null);
+ }
+
+ /**
+ * Test the simplest case: default null type, nothing in the vector
+ * cache. Specify no column type, the special NULL type, or a
+ * predefined type. Output types should be set accordingly.
+ */
+
+ @Test
+ public void testBasics() {
+
+ final List<ResolvedNullColumn> defns = new ArrayList<>();
+ defns.add(makeNullCol("unspecified", null));
+ defns.add(makeNullCol("nullType", Types.optional(MinorType.NULL)));
+ defns.add(makeNullCol("specifiedOpt", Types.optional(MinorType.VARCHAR)));
+ defns.add(makeNullCol("specifiedReq", Types.required(MinorType.VARCHAR)));
+ defns.add(makeNullCol("specifiedArray",
Types.repeated(MinorType.VARCHAR)));
+
+ final ResultVectorCache cache = new
NullResultVectorCacheImpl(fixture.allocator());
+ final NullColumnLoader staticLoader = new NullColumnLoader(cache, defns,
null, false);
+
+ // Create a batch
+
+ final VectorContainer output = staticLoader.load(2);
+
+ // Verify values and types
+
+ final BatchSchema expectedSchema = new SchemaBuilder()
+ .add("unspecified", NullColumnLoader.DEFAULT_NULL_TYPE)
+ .add("nullType", NullColumnLoader.DEFAULT_NULL_TYPE)
+ .addNullable("specifiedOpt", MinorType.VARCHAR)
+ .addNullable("specifiedReq", MinorType.VARCHAR)
+ .addArray("specifiedArray", MinorType.VARCHAR)
+ .build();
+ final SingleRowSet expected = fixture.rowSetBuilder(expectedSchema)
+ .addRow(null, null, null, null, new String[] {})
+ .addRow(null, null, null, null, new String[] {})
+ .build();
+
+ new RowSetComparison(expected)
+ .verifyAndClearAll(fixture.wrap(output));
+ staticLoader.close();
+ }
+
+ /**
+ * Test the ability to use a type other than nullable INT for null
+ * columns. This occurs, for example, in the CSV reader where no
+ * column is ever INT (nullable or otherwise) and we want our null
+ * columns to be (non-nullable) VARCHAR.
+ */
+
+ @Test
+ public void testCustomNullType() {
+
+ final List<ResolvedNullColumn> defns = new ArrayList<>();
+ defns.add(makeNullCol("unspecified", null));
+ defns.add(makeNullCol("nullType", MajorType.newBuilder()
+ .setMinorType(MinorType.NULL)
+ .setMode(DataMode.OPTIONAL)
+ .build()));
+ defns.add(makeNullCol("nullTypeReq", MajorType.newBuilder()
+ .setMinorType(MinorType.NULL)
+ .setMode(DataMode.REQUIRED)
Review comment:
How null can be required?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Merge scan projection framework into master
> -------------------------------------------
>
> Key: DRILL-6791
> URL: https://issues.apache.org/jira/browse/DRILL-6791
> Project: Apache Drill
> Issue Type: Improvement
> Affects Versions: 1.15.0
> Reporter: Paul Rogers
> Assignee: Paul Rogers
> Priority: Major
> Fix For: 1.15.0
>
>
> Merge the next set of "result set loader" code into master via a PR. This one
> covers the "schema projection" mechanism which:
> * Handles none (SELECT COUNT\(*)), some (SELECT a, b, x) and all (SELECT *)
> projection.
> * Handles null columns (for projection a column "x" that does not exist in
> the base table.)
> * Handles constant columns as used for file metadata (AKA "implicit" columns).
> * Handle schema persistence: the need to reuse the same vectors across
> different scanners
> * Provides a framework for consuming externally-supplied metadata
> * Since we don't yet have a way to provide "real" metadata, obtains metadata
> hints from previous batches and from the projection list (a.b implies that
> "a" is a map, c[0] implies that "c" is an array, etc.)
> * Handles merging the set of data source columns and null columns to create
> the final output batch.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)