autumnust commented on a change in pull request #2566: [GOBBLIN-695] Adding utility functions to generate Avro/ORC binary using json URL: https://github.com/apache/incubator-gobblin/pull/2566#discussion_r263173107
########## File path: gobblin-binary-management/src/main/java/org/apache/gobblin/binary_creation/OrcTestTools.java ########## @@ -0,0 +1,408 @@ +/* + * 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.gobblin.binary_creation; + +import com.google.common.collect.AbstractIterator; +import java.io.DataInput; +import java.io.DataOutput; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; +import java.util.TreeMap; +import javax.annotation.Nullable; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.experimental.Delegate; +import lombok.extern.slf4j.Slf4j; +import org.apache.avro.Schema; +import org.apache.avro.generic.GenericDatumReader; +import org.apache.avro.generic.GenericRecord; +import org.apache.avro.io.Decoder; +import org.apache.avro.io.DecoderFactory; +import org.apache.gobblin.util.FileListUtils; +import org.apache.gobblin.util.PathUtils; +import org.apache.gobblin.util.filters.HiddenFilter; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.PathFilter; +import org.apache.hadoop.hive.ql.io.orc.OrcFile; +import org.apache.hadoop.hive.ql.io.orc.OrcStruct; +import org.apache.hadoop.hive.ql.io.orc.Reader; +import org.apache.hadoop.hive.ql.io.orc.RecordReader; +import org.apache.hadoop.hive.ql.io.orc.Writer; +import org.apache.hadoop.hive.serde2.SerDeException; +import org.apache.hadoop.hive.serde2.avro.AvroGenericRecordWritable; +import org.apache.hadoop.hive.serde2.avro.AvroObjectInspectorGenerator; +import org.apache.hadoop.hive.serde2.avro.AvroSerDe; +import org.apache.hadoop.hive.serde2.avro.AvroSerdeUtils; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo; +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils; +import org.apache.hadoop.io.DoubleWritable; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.LongWritable; +import org.apache.hadoop.io.ShortWritable; +import org.apache.hadoop.io.Text; +import org.apache.hadoop.io.Writable; + +import static org.apache.gobblin.binary_creation.AvroTestTools.*; + + +// A class that examines ORC-Format file in Purger Integration test. +@Slf4j +public class OrcTestTools extends DataTestTools<OrcTestTools.OrcRowIterator, TypeInfo> { + + /** + * + * @param expected + * @param observed + * @param allowDifferentOrder ORC tools will not use this parameter currently. + * @param blacklistRecordFields ORC tools will not use this parameter currently. + * @return If two sets of files are identical. + * Note that there might be an ordering issue in this comparison method. When one is drafting an ORC integration + * test, try to name all json files differently. + */ + @Override + public boolean checkSameFilesAndRecords(TreeMap<String, OrcRowIterator> expected, + TreeMap<String, OrcRowIterator> observed, boolean allowDifferentOrder, Collection<String> blacklistRecordFields, + boolean allowDifferentSchema) { + Iterator<String> keys1 = expected.navigableKeySet().iterator(); + Iterator<String> keys2 = observed.navigableKeySet().iterator(); + + return compareIterators(keys1, keys2, (key1, key2) -> { + // ORC file doesn't have extension by Linkedin's convention. + if (!removeExtension(key1).equals(key2)) { + log.error(String.format("Mismatched files: %s and %s", key1, key2)); + return false; + } + + OrcRowIterator it1 = expected.get(key1); + OrcRowIterator it2 = observed.get(key2); + + if (!it1.getTypeInfo().equals(it2.getTypeInfo())) { Review comment: `allowDifferentOrder` is allowing different record order in record iterator. `allowDifferentSchema` is allowing different schema in record comparison. This is useful in some Avro cases that two records are the same in terms of contents, but could have different doc in schema for example. They are not in Orc now. `allowDifferentOrder` makes sense to be added in Orc, but `allowDifferentSchema`, maybe not. ---------------------------------------------------------------- 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
