drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [drill] arina-ielchiieva commented on a change in pull request #1690: DRILL-7086: Output schema for row set mechanism
Date Tue, 12 Mar 2019 13:53:15 GMT
arina-ielchiieva commented on a change in pull request #1690: DRILL-7086: Output schema for
row set mechanism
URL: https://github.com/apache/drill/pull/1690#discussion_r264646659
 
 

 ##########
 File path: exec/java-exec/src/main/java/org/apache/drill/exec/physical/rowSet/impl/ColumnBuilder.java
 ##########
 @@ -74,43 +79,96 @@
  * The single exception is the case of a list with exactly one type: in this case
  * the list metadata must contain that one type so the code knows how to build
  * the nullable array writer for that column.
+ * <p>
+ * Merges the project list with the column to be built. If the column is not
+ * projected (not in the list), then creates a dummy writer. Issues an error if
+ * the column is projected, but the implied projection type is incompatible with
+ * the actual type. (Such as trying to project an INT as x[0].)
  */
 public class ColumnBuilder {
 
-  private ColumnBuilder() { }
+  private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ColumnBuilder.class);
+
+  /**
+   * Default column transform for an unprojected column. No type conversion
+   * is needed, unprojected columns just "free-wheel": they are along for the
+   * ride, but don't do anything. They do not cause a vector to be materialized.
+   * The client, however, can still write to them, though the data is ignored.
+   */
+  public static class NoOpTransform implements ColumnTransformer {
+
+    private final ColumnMetadata columnSchema;
+
+    public NoOpTransform(ColumnMetadata columnSchema) {
+      this.columnSchema = columnSchema;
+    }
+
+    @Override
+    public AbstractWriteConverter newWriter(ScalarWriter baseWriter) {
+      assert false; // Should never be materialized
+      return null;
+    }
+
+    @Override
+    public ProjectionType projectionType() { return ProjectionType.UNPROJECTED; }
+
+    @Override
+    public ColumnMetadata inputSchema() { return columnSchema; }
+
+    @Override
+    public ColumnMetadata outputSchema() { return columnSchema; }
+  }
+
+  private final SchemaTransformer schemaTransformer;
+
+  public ColumnBuilder(SchemaTransformer schemaTransformer) {
+    this.schemaTransformer = schemaTransformer;
+  }
 
   /**
    * Implementation of the work to add a new column to this tuple given a
    * schema description of the column.
    *
    * @param parent container
-   * @param columnSchema schema of the column
+   * @param columnSchema schema of the column as provided by the client
+   * using the result set loader. This is the schema of the data to be
+   * loaded
    * @return writer for the new column
    */
-  public static ColumnState buildColumn(ContainerState parent, ColumnMetadata columnSchema)
{
+  public ColumnState buildColumn(ContainerState parent, ColumnMetadata columnSchema) {
 
     // Indicate projection in the metadata.
 
-    columnSchema.setProjected(parent.projectionType(columnSchema.name()) != ProjectionType.UNPROJECTED);
+    ProjectionType projType = parent.projectionType(columnSchema.name());
+    ColumnTransformer outputCol;
+    if (projType == ProjectionType.UNPROJECTED) {
+      PropertyAccessor.set(columnSchema, ColumnMetadata.PROJECTED_PROP, false);
+      outputCol = new NoOpTransform(columnSchema);
+    } else {
+
+      // Transform the column from input to output type.
+
+      outputCol = schemaTransformer.transform(columnSchema, projType);
+    }
 
     // Build the column
 
-    switch (columnSchema.structureType()) {
+    switch (outputCol.outputSchema().structureType()) {
 
 Review comment:
   Please indent case statements.

----------------------------------------------------------------
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

Mime
View raw message