You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by GitBox <gi...@apache.org> on 2020/04/11 15:16:35 UTC

[GitHub] [drill] arina-ielchiieva commented on a change in pull request #2051: DRILL-7696: EVF v2 scan schema resolution

arina-ielchiieva commented on a change in pull request #2051: DRILL-7696: EVF v2 scan schema resolution
URL: https://github.com/apache/drill/pull/2051#discussion_r407073746
 
 

 ##########
 File path: exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/scan/v3/schema/ScanSchemaResolver.java
 ##########
 @@ -0,0 +1,367 @@
+/*
+ * 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.v3.schema;
+
+import org.apache.drill.common.exceptions.CustomErrorContext;
+import org.apache.drill.common.exceptions.UserException;
+import org.apache.drill.exec.physical.impl.scan.v3.schema.DynamicSchemaFilter.DynamicTupleFilter;
+import org.apache.drill.exec.physical.impl.scan.v3.schema.MutableTupleMetadata.ColumnHandle;
+import org.apache.drill.exec.physical.impl.scan.v3.schema.ScanSchemaTracker.ProjectionType;
+import org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter;
+import org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult;
+import org.apache.drill.exec.record.metadata.ColumnMetadata;
+import org.apache.drill.exec.record.metadata.DynamicColumn;
+import org.apache.drill.exec.record.metadata.TupleMetadata;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Resolves a schema against the existing scan schema.
+ * Expands columns by comparing the existing scan schema with
+ * a "revised" (provided or reader) schema, adjusting the scan schema
+ * accordingly. Maps are expanded recursively. Other columns
+ * must match types (concrete columns) or the type must match projection
+ * (for dynamic columns.)
+ * <ul>
+ * <li>Resolves a provided schema against the projection list.
+ * The provided schema can be strict (converts a wildcard into
+ * an explicit projection) or lenient (the reader can add
+ * additional columns to a wildcard.)</li>
+ * <li>Resolves an early reader schema against the projection list
+ * and optional provided schema.</li>
+ * <li>Resolves a reader output schema against a dynamic (projection
+ * list), concreted (provided or prior reader) schema) or combination.
+ * </ul>
+ * <p>
+ * In practice, the logic is simpler: given a schema (dynamic, concrete
+ * or combination), further resolve the schema using the input schema
+ * provided. Resolve dynamic columns, verify consistency of concrete
+ * columns.
+ * <p>
+ * Projected columns start as <i>dynamic</i> (no type). Columns
+ * are resolved to a known type as a schema identifies that type.
+ * Subsequent schemas are obligated to use that same type to avoid
+ * an inconsistent schema change downstream.
+ * <p>
+ * Expands columns by comparing the existing scan schema with
+ * a "revised" (provided or reader) schema, adjusting the scan schema
+ * accordingly. Maps are expanded recursively. Other columns
+ * must match types (concrete columns) or the type must match projection
+ * (for dynamic columns.)
+ * <p>
+ * A "resolved" projection list is a list of concrete columns: table
+ * columns, nulls, file metadata or partition metadata. An unresolved list
+ * has either table column names, but no match, or a wildcard column.
+ * <p>
+ * The idea is that the projection list moves through stages of resolution
+ * depending on which information is available. An "early schema" table
+ * provides schema information up front, and so allows fully resolving
+ * the projection list on table open. A "late schema" table allows only a
+ * partially resolved projection list, with the remainder of resolution
+ * happening on the first (or perhaps every) batch.
+ */
+public class ScanSchemaResolver {
+  private static final Logger logger = LoggerFactory.getLogger(ScanSchemaResolver.class);
+
+  public enum Mode {
+    STRICT_PROVIDED_SCHEMA,
+    LENIENT_PROVIDED_SCHEMA,
+    EARLY_READER_SCHEMA,
+    READER_SCHEMA,
+    MISSING_COLS
+  }
+
+  private final MutableTupleMetadata schema;
+  private final Mode mode;
+  private final boolean isProjectAll;
+  private final boolean allowMapAdditions;
+  private final String source;
+  private final CustomErrorContext errorContext;
+
+  public ScanSchemaResolver(MutableTupleMetadata schema, Mode mode,
+      boolean allowMapAdditions,
+      CustomErrorContext errorContext) {
+    this.schema = schema;
+    this.isProjectAll = schema.projectionType() == ProjectionType.ALL;
+    this.mode = mode;
+    this.errorContext = errorContext;
+    this.allowMapAdditions = allowMapAdditions;
+    switch (mode) {
+      case LENIENT_PROVIDED_SCHEMA:
 
 Review comment:
   You enum can have this names already and you won't have to do the switch:
   ```
    public enum Mode {
        STRICT_PROVIDED_SCHEMA("Provided),
         ...
   
        private final String source;
   
        Mode(String source) {
          this.source = source;
        }
   
        public String source() {
           return source;
       }
   
      }
   
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services