paul-rogers commented on a change in pull request #1114: Drill-6104: Added Logfile Reader URL: https://github.com/apache/drill/pull/1114#discussion_r200863699
########## File path: exec/java-exec/src/main/java/org/apache/drill/exec/store/log/LogRecordReader.java ########## @@ -0,0 +1,750 @@ +/* + * 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.log; + +import com.google.common.base.Charsets; +import org.apache.drill.common.exceptions.UserException; +import org.apache.drill.common.expression.SchemaPath; +import org.apache.drill.common.types.TypeProtos.MinorType; +import org.apache.drill.common.types.Types; +import org.apache.drill.exec.exception.SchemaChangeException; +import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.OperatorContext; +import org.apache.drill.exec.physical.impl.OutputMutator; +import org.apache.drill.exec.record.MaterializedField; +import org.apache.drill.exec.store.AbstractRecordReader; +import org.apache.drill.exec.store.dfs.DrillFileSystem; +import org.apache.drill.exec.store.dfs.easy.FileWork; +import org.apache.drill.exec.vector.NullableIntVector; +import org.apache.drill.exec.vector.NullableBigIntVector; +import org.apache.drill.exec.vector.NullableSmallIntVector; +import org.apache.drill.exec.vector.NullableFloat4Vector; +import org.apache.drill.exec.vector.NullableFloat8Vector; +import org.apache.drill.exec.vector.BaseValueVector; +import org.apache.drill.exec.vector.NullableDateVector; +import org.apache.drill.exec.vector.NullableVarCharVector; +import org.apache.drill.exec.vector.NullableTimeStampVector; +import org.apache.drill.exec.vector.NullableTimeVector; + + + + +import org.apache.hadoop.fs.Path; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +public class LogRecordReader extends AbstractRecordReader { + + private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(LogRecordReader.class); + + private abstract static class ColumnDefn { + public final String name; + public final int index; + public final String format; + + public ColumnDefn(String name, int index) { + this.name = name; + this.index = index; + this.format = ""; + } + + public ColumnDefn(String name, int index, String format) { + this.name = name; + this.index = index; + this.format = format; + } + + public abstract void define(OutputMutator outputMutator) throws SchemaChangeException; + + public abstract void load(int rowIndex, String value); + + @Override + //For testing + public String toString() { + return "Name: " + name + ", Index: " + index; + } + } + + private static class VarCharDefn extends ColumnDefn { + + private NullableVarCharVector.Mutator mutator; + + public VarCharDefn(String name, int index) { + super(name, index); + } + + @Override + public void define(OutputMutator outputMutator) throws SchemaChangeException { + MaterializedField field = MaterializedField.create(name, + Types.optional(MinorType.VARCHAR)); + mutator = outputMutator.addField(field, NullableVarCharVector.class).getMutator(); + } + + @Override + public void load(int rowIndex, String value) { + mutator.set(rowIndex, value.getBytes()); + } + } + + private static class BigIntDefn extends ColumnDefn { + + private NullableBigIntVector.Mutator mutator; + + public BigIntDefn(String name, int index) { + super(name, index); + } + + @Override + public void define(OutputMutator outputMutator) throws SchemaChangeException { + MaterializedField field = MaterializedField.create(name, + Types.optional(MinorType.BIGINT)); + mutator = outputMutator.addField(field, NullableBigIntVector.class).getMutator(); + } + + @Override + public void load(int rowIndex, String value) { + try { + mutator.set(rowIndex, Long.parseLong(value)); + } catch (NumberFormatException e) { + throw UserException + .dataReadError(e) + .addContext("Failed to parse an INT field") + .addContext("Column", name) + .addContext("Position", index) + .addContext("Value", value) + .build(logger); + } + } + } + + private static class SmallIntDefn extends ColumnDefn { + + private NullableSmallIntVector.Mutator mutator; + + public SmallIntDefn(String name, int index) { + super(name, index); + } + + @Override + public void define(OutputMutator outputMutator) throws SchemaChangeException { + MaterializedField field = MaterializedField.create(name, + Types.optional(MinorType.BIGINT)); Review comment: Hmm... Kind of confused. The class name is `SmallIntDefn`, the mutter is for `NullableSmallIntVector`, but the minor type being used is `BIGINT`. In fact, this tells us that we never tested this field type. Should we go back and make sure that we have a consistent story across accepted type names, supported types internally, and unit tests? ---------------------------------------------------------------- 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
