paul-rogers commented on a change in pull request #1500: DRILL-6820: Msgpack 
format reader
URL: https://github.com/apache/drill/pull/1500#discussion_r230651284
 
 

 ##########
 File path: 
contrib/format-msgpack/src/main/java/org/apache/drill/exec/store/msgpack/MsgpackFormatPlugin.java
 ##########
 @@ -0,0 +1,212 @@
+/*
+ * 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.store.msgpack;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.drill.common.expression.SchemaPath;
+import org.apache.drill.common.logical.FormatPluginConfig;
+import org.apache.drill.common.logical.StoragePluginConfig;
+import org.apache.drill.exec.ops.FragmentContext;
+import org.apache.drill.exec.proto.UserBitShared.CoreOperatorType;
+import org.apache.drill.exec.server.DrillbitContext;
+import org.apache.drill.exec.store.RecordReader;
+import org.apache.drill.exec.store.RecordWriter;
+import org.apache.drill.exec.store.dfs.DrillFileSystem;
+import org.apache.drill.exec.store.dfs.FormatMatcher;
+import org.apache.drill.exec.store.dfs.easy.EasyFormatPlugin;
+import org.apache.drill.exec.store.dfs.easy.EasyWriter;
+import org.apache.drill.exec.store.dfs.easy.FileWork;
+import 
org.apache.drill.exec.store.msgpack.MsgpackFormatPlugin.MsgpackFormatConfig;
+import org.apache.drill.shaded.guava.com.google.common.collect.ImmutableList;
+import org.apache.hadoop.conf.Configuration;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+
+public class MsgpackFormatPlugin extends EasyFormatPlugin<MsgpackFormatConfig> 
{
+
+  private static final boolean IS_COMPRESSIBLE = true;
+  public static final String DEFAULT_NAME = "msgpack";
+
+  public MsgpackFormatPlugin(String name, DrillbitContext context, 
Configuration fsConf,
+      StoragePluginConfig storageConfig) {
+    this(name, context, fsConf, storageConfig, new MsgpackFormatConfig());
+  }
+
+  public MsgpackFormatPlugin(String name, DrillbitContext context, 
Configuration fsConf, StoragePluginConfig config,
+      MsgpackFormatConfig formatPluginConfig) {
+    super(name, context, fsConf, config, formatPluginConfig, true, false, 
false, IS_COMPRESSIBLE,
+        formatPluginConfig.getExtensions(), DEFAULT_NAME);
+  }
+
+  @Override
+  public FormatMatcher getMatcher() {
+    return super.getMatcher();
+  }
+
+  @Override
+  public RecordReader getRecordReader(FragmentContext context, DrillFileSystem 
dfs, FileWork fileWork,
+      List<SchemaPath> columns, String userName) {
+    return new MsgpackRecordReader(getConfig(), context, fileWork.getPath(), 
dfs, columns);
+  }
+
+  @Override
+  public RecordWriter getRecordWriter(FragmentContext context, EasyWriter 
writer) throws IOException {
+    throw new UnsupportedOperationException();
+  }
+
+  @JsonTypeName("msgpack")
+  public static class MsgpackFormatConfig implements FormatPluginConfig {
+
+    public List<String> extensions = ImmutableList.of("mp");
+    private boolean readBinaryAsString = false;
+    private boolean lenient = true;
+    private boolean printToConsole = true;
+    private boolean learnSchema = true;
+    private boolean useSchema = true;
+    private static final List<String> DEFAULT_EXTS = ImmutableList.of("mp");
+
+    @JsonInclude(JsonInclude.Include.NON_DEFAULT)
+    public List<String> getExtensions() {
+      if (extensions == null) {
+        // when loading an old JSONFormatConfig that doesn't contain an
+        // "extensions"
+        // attribute
+        return DEFAULT_EXTS;
+      }
+      return extensions;
+    }
+
+    @JsonInclude(JsonInclude.Include.ALWAYS)
+    public boolean isReadBinaryAsString() {
+      return readBinaryAsString;
+    }
+
+    @JsonInclude(JsonInclude.Include.ALWAYS)
+    public boolean isLenient() {
+      return lenient;
+    }
+
+    @JsonInclude(JsonInclude.Include.ALWAYS)
+    public boolean isPrintToConsole() {
+      return printToConsole;
+    }
+
+    @JsonInclude(JsonInclude.Include.ALWAYS)
+    public boolean isLearnSchema() {
+      return learnSchema;
+    }
+
+    @JsonInclude(JsonInclude.Include.ALWAYS)
+    public boolean isUseSchema() {
+      return useSchema;
+    }
+
+    public void setUseSchema(boolean useSchema) {
+      this.useSchema = useSchema;
+    }
+
+    public void setLearnSchema(boolean learnSchema) {
+      this.learnSchema = learnSchema;
+    }
+
+    public void setExtensions(List<String> extensions) {
+      this.extensions = extensions;
+    }
+
+    public void setLenient(boolean lenient) {
+      this.lenient = lenient;
+    }
+
+    public void setReadBinaryAsString(boolean readBinaryAsString) {
+      this.readBinaryAsString = readBinaryAsString;
+    }
+
+    public void setPrintToConsole(boolean printToConsole) {
+      this.printToConsole = printToConsole;
+    }
+
+    @Override
+    public int hashCode() {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + ((extensions == null) ? 0 : 
extensions.hashCode());
+      result = prime * result + (learnSchema ? 1231 : 1237);
+      result = prime * result + (printToConsole ? 1231 : 1237);
+      result = prime * result + (lenient ? 1231 : 1237);
+      result = prime * result + (readBinaryAsString ? 1231 : 1237);
+      result = prime * result + (useSchema ? 1231 : 1237);
+      return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+      if (this == obj) {
 
 Review comment:
   See comment above for the terse way to do this.

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


With regards,
Apache Git Services

Reply via email to