paul-rogers commented on a change in pull request #1951: DRILL-7454: Convert Avro to EVF URL: https://github.com/apache/drill/pull/1951#discussion_r365603939
########## File path: exec/java-exec/src/main/java/org/apache/drill/exec/store/avro/ColumnConverter.java ########## @@ -0,0 +1,261 @@ +/* + * 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.avro; + +import org.apache.avro.generic.GenericArray; +import org.apache.avro.generic.GenericFixed; +import org.apache.avro.generic.GenericRecord; +import org.apache.avro.util.Utf8; +import org.apache.drill.exec.record.metadata.ColumnMetadata; +import org.apache.drill.exec.record.metadata.TupleMetadata; +import org.apache.drill.exec.vector.accessor.ArrayWriter; +import org.apache.drill.exec.vector.accessor.DictWriter; +import org.apache.drill.exec.vector.accessor.ScalarWriter; +import org.apache.drill.exec.vector.accessor.TupleWriter; +import org.apache.drill.shaded.guava.com.google.common.base.Charsets; +import org.joda.time.DateTimeConstants; +import org.joda.time.Period; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.IntBuffer; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; +import java.util.stream.IntStream; + +/** + * Converts and sets given value into the specific column writer. + */ +public interface ColumnConverter { + + void convert(Object value); + + /** + * Does nothing, is used when column is not projected to avoid unnecessary + * column values conversions and writes. + */ + class DummyColumnConverter implements ColumnConverter { + + public static final DummyColumnConverter INSTANCE = new DummyColumnConverter(); + + @Override + public void convert(Object value) { + // do nothing + } + } + + /** + * Converts and writes scalar values using provided {@link #valueConverter}. + * {@link #valueConverter} has different implementation depending + * on the scalar value type. + */ + class ScalarColumnConverter implements ColumnConverter { + + private final Consumer<Object> valueConverter; + + public ScalarColumnConverter(Consumer<Object> valueConverter) { + this.valueConverter = valueConverter; + } + + public static ScalarColumnConverter init(ScalarWriter writer) { Review comment: Very nice! Clean and simple; much simpler than having a class per type. If we get a chance to update the Drill book, we'll point to this as an example of how to do conversion simply. ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services
