paul-rogers commented on a change in pull request #1500: DRILL-6820: Msgpack format reader URL: https://github.com/apache/drill/pull/1500#discussion_r230650357
########## 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; Review comment: This flag would mean that you have to tinker with the format plugin config to run a query to learn the schema. Since there is no SQL way to do this, it would be a cumbersome manual operation, and won't work well in a multi-user system. A better (though far from ideal) option is to use a session option: at least that can be set per-user and won't collide with settings by other users. (The JSON and other readers use that trick.) ---------------------------------------------------------------- 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
