[ 
https://issues.apache.org/jira/browse/DRILL-7278?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16854852#comment-16854852
 ] 

ASF GitHub Bot commented on DRILL-7278:
---------------------------------------

arina-ielchiieva commented on pull request #1797: DRILL-7278: Refactor result 
set loader projection mechanism
URL: https://github.com/apache/drill/pull/1797#discussion_r289941138
 
 

 ##########
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/scan/project/projSet/TypeConverter.java
 ##########
 @@ -0,0 +1,168 @@
+/*
+ * 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.projSet;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.drill.common.exceptions.CustomErrorContext;
+import org.apache.drill.common.exceptions.UserException;
+import org.apache.drill.exec.record.metadata.ColumnMetadata;
+import org.apache.drill.exec.record.metadata.TupleMetadata;
+import org.apache.drill.exec.vector.accessor.convert.ColumnConversionFactory;
+import org.apache.drill.exec.vector.accessor.convert.StandardConversions;
+import 
org.apache.drill.exec.vector.accessor.convert.StandardConversions.ConversionDefn;
+import 
org.apache.drill.exec.vector.accessor.convert.StandardConversions.ConversionType;
+
+public class TypeConverter {
+  private static final org.slf4j.Logger logger =
+      org.slf4j.LoggerFactory.getLogger(TypeConverter.class);
+
+  public static class Builder {
+    private TupleMetadata providedSchema;
+    private TypeConverter.CustomTypeTransform transform;
+    private Map<String, String> properties;
+    private CustomErrorContext errorContext;
+
+    public Builder providedSchema(TupleMetadata schema) {
+      providedSchema = schema;
+      return this;
+    }
+
+    public Builder transform(TypeConverter.CustomTypeTransform transform) {
+      this.transform = transform;
+      return this;
+    }
+
+    public Builder properties(Map<String, String> properties) {
+      this.properties = properties;
+      return this;
+    }
+
+    public Builder setConversionProperty(String key, String value) {
+      if (key == null || value == null) {
+        return this;
+      }
+      if (properties == null) {
+        properties = new HashMap<>();
+      }
+      properties.put(key, value);
+      return this;
+    }
+
+    public Builder errorContext(CustomErrorContext errorContext) {
+      this.errorContext = errorContext;
+      return this;
+    }
+
+    public TypeConverter build() {
+      return new TypeConverter(this);
+    }
+  }
+
+  public static interface CustomTypeTransform {
+    ColumnConversionFactory transform(ColumnMetadata inputDefn,
+        Map<String, String> properties,
+        ColumnMetadata outputDefn, ConversionDefn defn);
+  }
+
+  private final TupleMetadata providedSchema;
+  private final TypeConverter.CustomTypeTransform customTransform;
+  private final Map<String, String> properties;
+  private final CustomErrorContext errorContext;
+
+  public static Builder builder() { return new Builder(); }
+
+  public TypeConverter(Builder builder) {
+    this.providedSchema = builder.providedSchema;
+    this.customTransform = builder.transform;
+    this.properties = builder.properties;
+    this.errorContext = builder.errorContext;
+  }
+
+  public TypeConverter(TypeConverter parent,
+      TupleMetadata childSchema) {
+    this.providedSchema = childSchema;
+    this.customTransform = parent.customTransform;
+    this.properties = parent.properties;
+    this.errorContext = parent.errorContext;
+  }
+
+  public TupleMetadata providedSchema() { return providedSchema; }
+
+  public ColumnConversionFactory conversionFactory(ColumnMetadata inputSchema,
+      ColumnMetadata outputCol) {
+    if (outputCol == null) {
+      return customConversion(inputSchema);
+    } else {
+      return schemaBasedConversion(inputSchema, outputCol);
+    }
+  }
+
+  private ColumnConversionFactory customConversion(ColumnMetadata inputSchema) 
{
+    if (customTransform == null) {
+      return null;
+    }
+    return customTransform.transform(inputSchema, properties, null, null);
+  }
+
+  public ColumnConversionFactory schemaBasedConversion(ColumnMetadata 
inputSchema,
+      ColumnMetadata outputCol) {
+
+    // Custom transforms take priority. Allows replacing the standard
+    // conversions. Also allows conversions between the same type, such
+    // as rescaling units.
+
+    ConversionDefn defn = StandardConversions.analyze(inputSchema, outputCol);
+    if (customTransform != null) {
 
 Review comment:
   Do you think it could be better if instead of checking for nulls we could 
have some dummy implementation that does nothing?
 
----------------------------------------------------------------
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:
us...@infra.apache.org


> Refactor result set loader projection mechanism
> -----------------------------------------------
>
>                 Key: DRILL-7278
>                 URL: https://issues.apache.org/jira/browse/DRILL-7278
>             Project: Apache Drill
>          Issue Type: Improvement
>    Affects Versions: 1.16.0
>            Reporter: Paul Rogers
>            Assignee: Paul Rogers
>            Priority: Major
>             Fix For: 1.17.0
>
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to