|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | +package org.apache.hadoop.hive.llap.io.encoded; |
| 19 | + |
| 20 | +import static org.junit.Assert.assertEquals; |
| 21 | +import static org.junit.Assert.assertFalse; |
| 22 | +import static org.junit.Assert.assertNotNull; |
| 23 | + |
| 24 | +import java.io.IOException; |
| 25 | +import java.nio.charset.StandardCharsets; |
| 26 | +import java.nio.file.Files; |
| 27 | +import java.util.Arrays; |
| 28 | +import java.util.LinkedHashMap; |
| 29 | +import java.util.Properties; |
| 30 | + |
| 31 | +import org.apache.hadoop.fs.Path; |
| 32 | +import org.apache.hadoop.hive.conf.HiveConf; |
| 33 | +import org.apache.hadoop.hive.conf.HiveConf.ConfVars; |
| 34 | +import org.apache.hadoop.hive.llap.io.api.LlapProxy; |
| 35 | +import org.apache.hadoop.hive.ql.exec.Utilities; |
| 36 | +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; |
| 37 | +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; |
| 38 | +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; |
| 39 | +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatchCtx; |
| 40 | +import org.apache.hadoop.hive.ql.io.orc.OrcFile; |
| 41 | +import org.apache.hadoop.hive.ql.io.orc.OrcInputFormat; |
| 42 | +import org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat; |
| 43 | +import org.apache.hadoop.hive.ql.io.IOConstants; |
| 44 | +import org.apache.hadoop.hive.ql.plan.MapWork; |
| 45 | +import org.apache.hadoop.hive.ql.plan.PartitionDesc; |
| 46 | +import org.apache.hadoop.hive.ql.plan.TableDesc; |
| 47 | +import org.apache.hadoop.hive.serde2.ColumnProjectionUtils; |
| 48 | +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo; |
| 49 | +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory; |
| 50 | + |
| 51 | +import static org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.META_TABLE_NAME; |
| 52 | + |
| 53 | +import org.apache.hadoop.io.NullWritable; |
| 54 | +import org.apache.hadoop.mapred.JobConf; |
| 55 | +import org.apache.hadoop.mapred.RecordReader; |
| 56 | +import org.apache.hadoop.mapred.Reporter; |
| 57 | +import org.apache.orc.TypeDescription; |
| 58 | +import org.apache.orc.Writer; |
| 59 | +import org.junit.AfterClass; |
| 60 | +import org.junit.BeforeClass; |
| 61 | +import org.junit.Test; |
| 62 | + |
| 63 | +public class TestOrcEncodedDataReaderIOCacheDisabled { |
| 64 | + |
| 65 | + private static final TypeDescription ORC_SCHEMA = TypeDescription.fromString("struct<id:bigint,value:string>"); |
| 66 | + private static final int ROW_COUNT = 3; |
| 67 | + private static final long[] EXPECTED_IDS = {1L, 2L, 3L}; |
| 68 | + private static final String[] EXPECTED_VALUES = {"one", "two", "three"}; |
| 69 | + |
| 70 | + private static HiveConf daemonConf; |
| 71 | + private static Path orcFile; |
| 72 | + |
| 73 | + @BeforeClass |
| 74 | + public static void setUpClass() throws Exception { |
| 75 | + daemonConf = new HiveConf(); |
| 76 | + HiveConf.setVar(daemonConf, ConfVars.LLAP_IO_MEMORY_MODE, "none"); |
| 77 | + |
| 78 | + Path tmpDir = new Path(Files.createTempDirectory("llap-orc-no-io-cache").toString()); |
| 79 | + orcFile = new Path(tmpDir, "data.orc"); |
| 80 | + writeOrcFile(orcFile, daemonConf); |
| 81 | + |
| 82 | + LlapProxy.setDaemon(true); |
| 83 | + LlapProxy.initializeLlapIo(daemonConf); |
| 84 | + assertFalse(LlapProxy.getIo().usingLowLevelCache()); |
| 85 | + } |
| 86 | + |
| 87 | + @AfterClass |
| 88 | + public static void tearDownClass() { |
| 89 | + LlapProxy.close(); |
| 90 | + } |
| 91 | + |
| 92 | + @Test |
| 93 | + public void testVectorizedOrcEncodedReadWithIoCacheDisabled() throws Exception { |
| 94 | + JobConf job = buildJobConf(orcFile); |
| 95 | + long fileLen = orcFile.getFileSystem(job).getFileStatus(orcFile).getLen(); |
| 96 | + |
| 97 | + RecordReader<NullWritable, VectorizedRowBatch> reader = LlapProxy.getIo().llapVectorizedOrcReaderForPath( |
| 98 | + null, orcFile, null, Arrays.asList(0, 1), job, 0, fileLen, Reporter.NULL); |
| 99 | + assertNotNull("LLAP should handle this ORC read", reader); |
| 100 | + |
| 101 | + try { |
| 102 | + VectorizedRowBatch batch = reader.createValue(); |
| 103 | + int rowsRead = 0; |
| 104 | + while (reader.next(NullWritable.get(), batch)) { |
| 105 | + LongColumnVector idCol = (LongColumnVector) batch.cols[0]; |
| 106 | + BytesColumnVector valueCol = (BytesColumnVector) batch.cols[1]; |
| 107 | + for (int i = 0; i < batch.size; i++) { |
| 108 | + assertEquals("id at row " + rowsRead, EXPECTED_IDS[rowsRead], idCol.vector[i]); |
| 109 | + assertEquals("value at row " + rowsRead, EXPECTED_VALUES[rowsRead], valueCol.toString(i)); |
| 110 | + rowsRead++; |
| 111 | + } |
| 112 | + } |
| 113 | + assertEquals(ROW_COUNT, rowsRead); |
| 114 | + } finally { |
| 115 | + reader.close(); |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + private static void writeOrcFile(Path path, HiveConf conf) throws IOException { |
| 120 | + try (Writer writer = OrcFile.createWriter(path, OrcFile.writerOptions(conf).setSchema(ORC_SCHEMA))) { |
| 121 | + VectorizedRowBatch batch = ORC_SCHEMA.createRowBatch(); |
| 122 | + LongColumnVector idCol = (LongColumnVector) batch.cols[0]; |
| 123 | + BytesColumnVector valueCol = (BytesColumnVector) batch.cols[1]; |
| 124 | + batch.size = ROW_COUNT; |
| 125 | + for (int i = 0; i < ROW_COUNT; i++) { |
| 126 | + idCol.vector[i] = EXPECTED_IDS[i]; |
| 127 | + valueCol.setVal(i, EXPECTED_VALUES[i].getBytes(StandardCharsets.UTF_8)); |
| 128 | + } |
| 129 | + writer.addRowBatch(batch); |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + private static JobConf buildJobConf(Path orcPath) { |
| 134 | + JobConf job = new JobConf(daemonConf); |
| 135 | + HiveConf.setBoolVar(job, ConfVars.HIVE_VECTORIZATION_ENABLED, true); |
| 136 | + HiveConf.setVar(job, ConfVars.PLAN, "//tmp"); |
| 137 | + job.set(IOConstants.COLUMNS, "id,value"); |
| 138 | + job.set(IOConstants.COLUMNS_TYPES, "bigint,string"); |
| 139 | + job.set(ColumnProjectionUtils.ORC_SCHEMA_STRING, ORC_SCHEMA.toString()); |
| 140 | + |
| 141 | + Properties tblProps = new Properties(); |
| 142 | + tblProps.setProperty(META_TABLE_NAME, "default.test_orc"); |
| 143 | + TableDesc tableDesc = new TableDesc(OrcInputFormat.class, OrcOutputFormat.class, tblProps); |
| 144 | + |
| 145 | + MapWork mapWork = new MapWork(); |
| 146 | + mapWork.setVectorMode(true); |
| 147 | + mapWork.setVectorizedRowBatchCtx(new VectorizedRowBatchCtx( |
| 148 | + new String[] {"id", "value"}, |
| 149 | + new TypeInfo[] {TypeInfoFactory.longTypeInfo, TypeInfoFactory.stringTypeInfo}, |
| 150 | + null, null, 0, 0, null, new String[0], null)); |
| 151 | + LinkedHashMap<Path, PartitionDesc> partMap = new LinkedHashMap<>(); |
| 152 | + partMap.put(orcPath.getParent(), new PartitionDesc(tableDesc, new LinkedHashMap<>())); |
| 153 | + mapWork.setPathToPartitionInfo(partMap); |
| 154 | + Utilities.setMapWork(job, mapWork); |
| 155 | + return job; |
| 156 | + } |
| 157 | +} |
0 commit comments