paul-rogers commented on a change in pull request #1500: DRILL-6820: Msgpack format reader URL: https://github.com/apache/drill/pull/1500#discussion_r230655032
########## File path: contrib/format-msgpack/src/main/java/org/apache/drill/exec/store/msgpack/MsgpackReader.java ########## @@ -0,0 +1,192 @@ +/* + * 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.io.InputStream; +import java.util.BitSet; +import java.util.EnumMap; +import java.util.List; + +import org.apache.drill.common.expression.PathSegment; +import org.apache.drill.common.expression.SchemaPath; +import org.apache.drill.exec.record.MaterializedField; +import org.apache.drill.exec.store.msgpack.valuewriter.AbstractValueWriter; +import org.apache.drill.exec.store.msgpack.valuewriter.ArrayValueWriter; +import org.apache.drill.exec.store.msgpack.valuewriter.BinaryValueWriter; +import org.apache.drill.exec.store.msgpack.valuewriter.BooleanValueWriter; +import org.apache.drill.exec.store.msgpack.valuewriter.ExtensionValueWriter; +import org.apache.drill.exec.store.msgpack.valuewriter.FloatValueWriter; +import org.apache.drill.exec.store.msgpack.valuewriter.IntegerValueWriter; +import org.apache.drill.exec.store.msgpack.valuewriter.MapValueWriter; +import org.apache.drill.exec.store.msgpack.valuewriter.StringValueWriter; +import org.apache.drill.exec.vector.complex.fn.FieldSelection; +import org.apache.drill.exec.vector.complex.writer.BaseWriter; +import org.apache.drill.exec.vector.complex.writer.BaseWriter.ComplexWriter; +import org.apache.drill.exec.vector.complex.writer.BaseWriter.ListWriter; +import org.apache.drill.shaded.guava.com.google.common.collect.Lists; +import org.msgpack.core.MessageInsufficientBufferException; +import org.msgpack.core.MessagePack; +import org.msgpack.core.MessageUnpacker; +import org.msgpack.value.MapValue; +import org.msgpack.value.Value; +import org.msgpack.value.ValueType; + +import io.netty.buffer.DrillBuf; + +public class MsgpackReader { + + static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(MsgpackReader.class); + private final List<SchemaPath> columns; + private final FieldSelection rootSelection; + protected MessageUnpacker unpacker; + protected MsgpackReaderContext context; + private final boolean skipQuery; + + /** + * Collection for tracking empty array writers during reading and storing them + * for initializing empty arrays + */ + private final List<ListWriter> emptyArrayWriters = Lists.newArrayList(); + private boolean allTextMode = false; + private MapValueWriter mapValueWriter; + + public MsgpackReader(InputStream stream, MsgpackReaderContext context, DrillBuf managedBuf, List<SchemaPath> columns, + boolean skipQuery) { + + this.context = context; + this.context.workBuf = managedBuf; + this.unpacker = MessagePack.newDefaultUnpacker(stream); + this.columns = columns; + this.skipQuery = skipQuery; + rootSelection = FieldSelection.getFieldSelection(columns); + EnumMap<ValueType, AbstractValueWriter> valueWriterMap = new EnumMap<>(ValueType.class); + valueWriterMap.put(ValueType.ARRAY, new ArrayValueWriter(valueWriterMap, emptyArrayWriters)); + valueWriterMap.put(ValueType.FLOAT, new FloatValueWriter()); + valueWriterMap.put(ValueType.INTEGER, new IntegerValueWriter()); + valueWriterMap.put(ValueType.BOOLEAN, new BooleanValueWriter()); + valueWriterMap.put(ValueType.STRING, new StringValueWriter()); + valueWriterMap.put(ValueType.BINARY, new BinaryValueWriter()); + valueWriterMap.put(ValueType.EXTENSION, new ExtensionValueWriter()); Review comment: Somewhat confused here; some comments may help. Presumably, the file can contain any number of FLOAT fields, including 0. Each field needs its own state (reader, parser, whatever.) Each has its own value vector. How does it work to have one "ValueWriter" per type that takes no parameters to say which field or vector is being worked on? ---------------------------------------------------------------- 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
