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:14 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_r264644777
 
 

 ##########
 File path: exec/java-exec/src/main/java/org/apache/drill/exec/physical/rowSet/impl/AbstractSchemaTransformer.java
 ##########
 @@ -0,0 +1,230 @@
+/*
+ * 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.rowSet.impl;
+
+import org.apache.drill.exec.record.metadata.ColumnMetadata;
+import org.apache.drill.exec.record.metadata.ProjectionType;
+import org.apache.drill.exec.record.metadata.TupleMetadata;
+import org.apache.drill.exec.vector.accessor.ScalarWriter;
+import org.apache.drill.exec.vector.accessor.convert.AbstractWriteConverter;
+import org.apache.drill.exec.vector.accessor.convert.ColumnConversionFactory;
+import org.apache.drill.exec.vector.accessor.convert.ConvertStringToDate;
+import org.apache.drill.exec.vector.accessor.convert.ConvertStringToDouble;
+import org.apache.drill.exec.vector.accessor.convert.ConvertStringToInt;
+import org.apache.drill.exec.vector.accessor.convert.ConvertStringToInterval;
+import org.apache.drill.exec.vector.accessor.convert.ConvertStringToLong;
+import org.apache.drill.exec.vector.accessor.convert.ConvertStringToTime;
+import org.apache.drill.exec.vector.accessor.convert.ConvertStringToTimeStamp;
+
+/**
+ * Base class for plugin-specific type transforms. Handles basic type
+ * checking. Assumes a type conversion is needed only if the output
+ * column is defined and has a type or mode different than the input.
+ * Else, assumes no transform is needed. Subclases can change or enhance
+ * this policy. The subclass provides the actual per-column transform logic.
+ */
+
+public abstract class AbstractSchemaTransformer implements SchemaTransformer {
+
+  /**
+   * A no-op transform that simply keeps the input column schema and
+   * writer without any changes.
+   */
+  public static class PassThroughColumnTransform implements ColumnTransformer {
+
+    private final ColumnMetadata colDefn;
+    private final ProjectionType projType;
+
+    public PassThroughColumnTransform(ColumnMetadata colDefn, ProjectionType projType) {
+      this.colDefn = colDefn;
+      this.projType = projType;
+    }
+
+    @Override
+    public AbstractWriteConverter newWriter(ScalarWriter baseWriter) {
+      return null;
+    }
+
+    @Override
+    public ProjectionType projectionType() { return projType; }
+
+    @Override
+    public ColumnMetadata inputSchema() { return colDefn; }
+
+    @Override
+    public ColumnMetadata outputSchema() { return colDefn; }
+  }
+
+  /**
+   * Full column transform that has separate input and output types
+   * and provides a type conversion writer to convert between the
+   * two. The conversion writer factory is provided via composition,
+   * not by subclassing this class.
+   */
+  public static class ColumnTransformImpl implements ColumnTransformer {
+
+    private final ColumnMetadata inputSchema;
+    private final ColumnMetadata outputSchema;
+    private final ProjectionType projType;
+    private final ColumnConversionFactory conversionFactory;
+
+    public ColumnTransformImpl(ColumnMetadata inputSchema, ColumnMetadata outputSchema,
+        ProjectionType projType, ColumnConversionFactory conversionFactory) {
+      this.inputSchema = inputSchema;
+      this.outputSchema = outputSchema;
+      this.projType = projType;
+      this.conversionFactory = conversionFactory;
+    }
+
+    @Override
+    public AbstractWriteConverter newWriter(ScalarWriter baseWriter) {
+      if (conversionFactory == null) {
+        return null;
+      }
+      return conversionFactory.newWriter(baseWriter);
+    }
+
+    @Override
+    public ProjectionType projectionType() { return projType; }
+
+    @Override
+    public ColumnMetadata inputSchema() { return inputSchema; }
+
+    @Override
+    public ColumnMetadata outputSchema() { return outputSchema; }
+  }
+
+  protected final TupleMetadata outputSchema;
+
+  public AbstractSchemaTransformer(TupleMetadata outputSchema) {
+    this.outputSchema = outputSchema;
+  }
+
+  protected ColumnTransformer nullTransform(ColumnMetadata inputSchema,
+      ProjectionType projType) {
+    return new PassThroughColumnTransform(inputSchema, projType);
+  }
+
+  /**
+   * Implement a basic policy to pass through input columns for which there
+   * is no matching output column, and to do a type conversion only if types
+   * and modes differ.
+   * <p>
+   * Subclasses can change this behavior if, say, they want to do conversion
+   * even if the types are the same (such as parsing a VARCHAR field to produce
+   * another VARCHAR.)
+   */
+  @Override
+  public ColumnTransformer transform(ColumnMetadata inputSchema,
+      ProjectionType projType) {
+
+    // Should never get an unprojected column; should be handled
+    // by the caller.
+
+    assert projType != ProjectionType.UNPROJECTED;
+
+    // If no matching column, assume a pass-through transform
+
+    ColumnMetadata outputCol = outputSchema.metadata(inputSchema.name());
+    if (outputCol == null) {
+      return nullTransform(inputSchema, projType);
+    }
+
+    // If the types and modes match, assume a pass-through transform
+
+    if (outputCol.type() == inputSchema.type() &&
+        outputCol.mode() == inputSchema.mode()) {
+      return nullTransform(inputSchema, projType);
+    }
+
+    return buildTransform(inputSchema, outputCol, projType);
+  }
+
+  /**
+   * Overridden to provide a conversion between input an output types.
+   *
+   * @param outputDefn the column schema for the output vector to be produced
+   * by this operator
+   * @param inputDefn the column schema for the input column which the
+   * client code (e.g. reader) wants to produce
+   * @param projType the kind of projection requested for this column.
+   * Generally just retained and returned, but not used
+   * @return a column transformer to implement the conversion
+   * @throws UserException if the implementation does not support the
+   * requested transform, or if the column properties used are invalid
+   */
+  protected ColumnTransformer buildTransform(ColumnMetadata inputDefn,
+      ColumnMetadata outputDefn, ProjectionType projType) {
+    return new ColumnTransformImpl(inputDefn, outputDefn, projType,
+        AbstractWriteConverter.factory(
+            transformClass(inputDefn, outputDefn)));
+  }
+
+  /**
+   * Simplified form of the above which returns the class to use for the transform.
+   *
+   * @param outputDefn
 
 Review comment:
   Please add javadoc.

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