|
| 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 | + |
| 19 | +package org.apache.orc.util; |
| 20 | + |
| 21 | +import java.util.Arrays; |
| 22 | + |
| 23 | +import org.apache.orc.OrcUtils; |
| 24 | +import org.apache.orc.TypeDescription; |
| 25 | + |
| 26 | +import org.junit.Assert; |
| 27 | +import org.junit.Test; |
| 28 | + |
| 29 | +/** |
| 30 | + * Tests for OrcUtils. |
| 31 | + */ |
| 32 | +public class TestOrcUtils { |
| 33 | + |
| 34 | + @Test |
| 35 | + public void testBloomFilterIncludeColumns() { |
| 36 | + TypeDescription schema = TypeDescription.createStruct() |
| 37 | + .addField("msisdn", TypeDescription.createString()) |
| 38 | + .addField("imsi", TypeDescription.createVarchar()) |
| 39 | + .addField("imei", TypeDescription.createInt()); |
| 40 | + |
| 41 | + boolean[] includeColumns = new boolean[3+1]; |
| 42 | + includeColumns[1] = true; |
| 43 | + includeColumns[3] = true; |
| 44 | + |
| 45 | + Assert.assertTrue(Arrays.equals(includeColumns, |
| 46 | + OrcUtils.includeColumns("msisdn, imei", schema))); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void testBloomFilterIncludeColumns_ACID() { |
| 51 | + TypeDescription rowSchema = TypeDescription.createStruct() |
| 52 | + .addField("msisdn", TypeDescription.createString()) |
| 53 | + .addField("imei", TypeDescription.createInt()); |
| 54 | + |
| 55 | + TypeDescription schema = TypeDescription.createStruct() |
| 56 | + .addField("operation", TypeDescription.createString()) |
| 57 | + .addField("originalTransaction", TypeDescription.createInt()) |
| 58 | + .addField("bucket", TypeDescription.createInt()) |
| 59 | + .addField("rowId", TypeDescription.createInt()) |
| 60 | + .addField("currentTransaction", TypeDescription.createInt()) |
| 61 | + .addField("row", rowSchema); |
| 62 | + |
| 63 | + boolean[] includeColumns = new boolean[8+1]; |
| 64 | + includeColumns[7] = true; |
| 65 | + |
| 66 | + Assert.assertTrue(Arrays.equals(includeColumns, |
| 67 | + OrcUtils.includeColumns("msisdn", schema))); |
| 68 | + } |
| 69 | + |
| 70 | + @Test |
| 71 | + public void testBloomFilterIncludeColumns_Nested() { |
| 72 | + TypeDescription rowSchema = TypeDescription.createStruct() |
| 73 | + .addField("msisdn", TypeDescription.createString()) |
| 74 | + .addField("imei", TypeDescription.createInt()); |
| 75 | + |
| 76 | + TypeDescription schema = TypeDescription.createStruct() |
| 77 | + .addField("row", rowSchema); |
| 78 | + |
| 79 | + boolean[] includeColumns = new boolean[3+1]; |
| 80 | + includeColumns[2] = true; |
| 81 | + |
| 82 | + Assert.assertTrue(Arrays.equals(includeColumns, |
| 83 | + OrcUtils.includeColumns("row.msisdn", schema))); |
| 84 | + } |
| 85 | + |
| 86 | + @Test |
| 87 | + public void testBloomFilterIncludeColumns_NonExisting() { |
| 88 | + TypeDescription rowSchema = TypeDescription.createStruct() |
| 89 | + .addField("msisdn", TypeDescription.createString()) |
| 90 | + .addField("imei", TypeDescription.createInt()); |
| 91 | + |
| 92 | + TypeDescription schema = TypeDescription.createStruct() |
| 93 | + .addField("row", rowSchema); |
| 94 | + |
| 95 | + boolean[] includeColumns = new boolean[3+1]; |
| 96 | + |
| 97 | + Assert.assertTrue(Arrays.equals(includeColumns, |
| 98 | + OrcUtils.includeColumns("msisdn, row.msisdn2", schema))); |
| 99 | + } |
| 100 | +} |
0 commit comments