commit ecfd55b35e12891f88d475ded91dc705248b8435 Author: Daniel Dai Date: Tue Jun 5 15:49:34 2018 -0700 testcase for HIVE-19810 diff --git a/ql/src/test/org/apache/hadoop/hive/ql/exec/AutoShippingStorageHandlerForTesting.java b/ql/src/test/org/apache/hadoop/hive/ql/exec/AutoShippingStorageHandlerForTesting.java new file mode 100644 index 0000000..0e75f83 --- /dev/null +++ b/ql/src/test/org/apache/hadoop/hive/ql/exec/AutoShippingStorageHandlerForTesting.java @@ -0,0 +1,73 @@ +/* + * 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.hadoop.hive.ql.exec; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hive.ql.metadata.DefaultStorageHandler; +import org.apache.hadoop.hive.ql.plan.TableDesc; +import org.apache.hadoop.mapred.FileSplit; +import org.apache.hadoop.mapred.InputFormat; +import org.apache.hadoop.mapred.InputSplit; +import org.apache.hadoop.mapred.JobConf; +import org.apache.hadoop.mapred.OutputFormat; +import org.apache.hadoop.mapred.RecordReader; +import org.apache.hadoop.mapred.Reporter; +import org.apache.hadoop.mapred.SequenceFileInputFormat; +import org.apache.hadoop.mapred.SequenceFileOutputFormat; +import org.apache.hadoop.mapred.SequenceFileRecordReader; + +import java.io.IOException; + +public class AutoShippingStorageHandlerForTesting extends DefaultStorageHandler { + static class AutoShippingInputFormat extends SequenceFileInputFormat { + static class AutoShippingRecordReader extends SequenceFileRecordReader { + public AutoShippingRecordReader(Configuration conf, FileSplit split) throws IOException { + super(conf, split); + } + } + @Override + public RecordReader getRecordReader(InputSplit split, JobConf job, Reporter reporter) throws IOException { + try { + Class.forName("org.apache.hadoop.hive.udf.example.GenericUDFExampleAdd"); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + return new AutoShippingInputFormat.AutoShippingRecordReader(job, (FileSplit)split); + } + } + + @Override + public Class getInputFormatClass() { + return AutoShippingInputFormat.class; + } + + @Override + public Class getOutputFormatClass() { + return SequenceFileOutputFormat.class; + } + + @Override + public void configureJobConf(TableDesc tableDesc, JobConf jobConf) { + jobConf.set("mapreduce.output.fileoutputformat.outputdir", + (String)tableDesc.getProperties().get("location")); + String pathToJar = System.getProperties().get("maven.local.repository") + + "/org/apache/hive/hive-it-test-serde/" + System.getProperties().get("hive.version") + + "/hive-it-test-serde-" + System.getProperties().get("hive.version") + ".jar"; + jobConf.set("tmpjars", pathToJar); + } +} diff --git a/ql/src/test/queries/clientpositive/storagehandler_autoship.q b/ql/src/test/queries/clientpositive/storagehandler_autoship.q new file mode 100644 index 0000000..4ca6f63 --- /dev/null +++ b/ql/src/test/queries/clientpositive/storagehandler_autoship.q @@ -0,0 +1,16 @@ +set tez.am.container.reuse.enabled=false; +set hive.fetch.task.conversion=none; +set hive.query.results.cache.enabled=false; +set tez.am.task.max.failed.attempts=1; + +create external table src2 (key int, value string) stored as sequencefile location 'hdfs:///tmp/src2'; +insert into src2 values (1, 'hello'); + +drop table src2; +create external table src2 (key int, value string) stored by 'org.apache.hadoop.hive.ql.exec.AutoShippingStorageHandlerForTesting' location 'hdfs:///tmp/src2'; + +select * from src2; + +!sleep 11; + +select * from src2;