Repository: tajo Updated Branches: refs/heads/hbase_storage 03c3ea290 -> 69373878b
http://git-wip-us.apache.org/repos/asf/tajo/blob/69373878/tajo-storage/src/test/java/org/apache/tajo/storage/hbase/TestColumnMapping.java ---------------------------------------------------------------------- diff --git a/tajo-storage/src/test/java/org/apache/tajo/storage/hbase/TestColumnMapping.java b/tajo-storage/src/test/java/org/apache/tajo/storage/hbase/TestColumnMapping.java new file mode 100644 index 0000000..39d28b3 --- /dev/null +++ b/tajo-storage/src/test/java/org/apache/tajo/storage/hbase/TestColumnMapping.java @@ -0,0 +1,95 @@ +/** + * 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.tajo.storage.hbase; + +import org.apache.tajo.catalog.Schema; +import org.apache.tajo.catalog.TableMeta; +import org.apache.tajo.catalog.proto.CatalogProtos.StoreType; +import org.apache.tajo.common.TajoDataTypes.Type; +import org.apache.tajo.util.KeyValueSet; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class TestColumnMapping { + @Test + public void testColumnKeyValueMapping() throws Exception { + KeyValueSet keyValueSet = new KeyValueSet(); + keyValueSet.set(HBaseStorageConstants.META_TABLE_KEY, "test"); + keyValueSet.set(HBaseStorageConstants.META_COLUMNS_KEY, ":key,col2:key:,col2:value:#b,col3:"); + + Schema schema = new Schema(); + schema.addColumn("c1", Type.TEXT); + schema.addColumn("c2", Type.TEXT); + schema.addColumn("c3", Type.TEXT); + schema.addColumn("c4", Type.TEXT); + + TableMeta tableMeta = new TableMeta(StoreType.HBASE, keyValueSet); + + ColumnMapping columnMapping = new ColumnMapping(schema, tableMeta); + + List<String> cfNames = columnMapping.getColumnFamilyNames(); + assertEquals(2, cfNames.size()); + assertEquals("col2", cfNames.get(0)); + assertEquals("col3", cfNames.get(1)); + + for (int i = 0; i < columnMapping.getIsBinaryColumns().length; i++) { + if (i == 2) { + assertTrue(columnMapping.getIsBinaryColumns()[i]); + } else { + assertFalse(columnMapping.getIsBinaryColumns()[i]); + } + } + + for (int i = 0; i < columnMapping.getIsRowKeyMappings().length; i++) { + if (i == 0) { + assertTrue(columnMapping.getIsRowKeyMappings()[i]); + } else { + assertFalse(columnMapping.getIsRowKeyMappings()[i]); + } + } + + String[] expectedColumnNames = { null, null, null, null}; + for (int i = 0; i < schema.size(); i++) { + String columnName = columnMapping.getMappingColumns()[i][1] == null ? null : + new String(columnMapping.getMappingColumns()[i][1]); + assertEquals(expectedColumnNames[i], columnName); + } + + for (int i = 0; i < schema.size(); i++) { + if (i == 1) { + assertTrue(columnMapping.getIsColumnKeys()[i]); + } else { + assertFalse(columnMapping.getIsColumnKeys()[i]); + } + } + + for (int i = 0; i < schema.size(); i++) { + if (i == 2) { + assertTrue(columnMapping.getIsColumnValues()[i]); + } else { + assertFalse(columnMapping.getIsColumnValues()[i]); + } + } + } +} http://git-wip-us.apache.org/repos/asf/tajo/blob/69373878/tajo-storage/src/test/java/org/apache/tajo/storage/hbase/TestHBaseStorageManager.java ---------------------------------------------------------------------- diff --git a/tajo-storage/src/test/java/org/apache/tajo/storage/hbase/TestHBaseStorageManager.java b/tajo-storage/src/test/java/org/apache/tajo/storage/hbase/TestHBaseStorageManager.java new file mode 100644 index 0000000..1fc4065 --- /dev/null +++ b/tajo-storage/src/test/java/org/apache/tajo/storage/hbase/TestHBaseStorageManager.java @@ -0,0 +1,109 @@ +/** + * 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.tajo.storage.hbase; + +import org.apache.tajo.catalog.Column; +import org.apache.tajo.catalog.proto.CatalogProtos.StoreType; +import org.apache.tajo.common.TajoDataTypes.Type; +import org.apache.tajo.conf.TajoConf; +import org.apache.tajo.datum.Datum; +import org.apache.tajo.datum.TextDatum; +import org.apache.tajo.plan.expr.*; +import org.apache.tajo.plan.logical.ScanNode; +import org.apache.tajo.storage.StorageManager; +import org.apache.tajo.util.Pair; +import org.junit.Test; + +import java.util.List; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class TestHBaseStorageManager { + @Test + public void testGetIndexPredications() throws Exception { + Column rowkeyColumn = new Column("rk", Type.TEXT); + // where rk >= '020' and rk <= '055' + ScanNode scanNode = new ScanNode(1); + EvalNode evalNode1 = new BinaryEval(EvalType.GEQ, new FieldEval(rowkeyColumn), new ConstEval(new TextDatum("020"))); + EvalNode evalNode2 = new BinaryEval(EvalType.LEQ, new FieldEval(rowkeyColumn), new ConstEval(new TextDatum("055"))); + EvalNode evalNodeA = new BinaryEval(EvalType.AND, evalNode1, evalNode2); + scanNode.setQual(evalNodeA); + + HBaseStorageManager storageManager = + (HBaseStorageManager) StorageManager.getStorageManager(new TajoConf(), StoreType.HBASE); + List<Set<EvalNode>> indexEvals = storageManager.findIndexablePredicateSet(scanNode, new Column[]{rowkeyColumn}); + assertNotNull(indexEvals); + assertEquals(1, indexEvals.size()); + Pair<Datum, Datum> indexPredicateValue = storageManager.getIndexablePredicateValue(null, indexEvals.get(0)); + assertEquals("020", indexPredicateValue.getFirst().asChars()); + assertEquals("055", indexPredicateValue.getSecond().asChars()); + + // where (rk >= '020' and rk <= '055') or rk = '075' + EvalNode evalNode3 = new BinaryEval(EvalType.EQUAL, new FieldEval(rowkeyColumn),new ConstEval(new TextDatum("075"))); + EvalNode evalNodeB = new BinaryEval(EvalType.OR, evalNodeA, evalNode3); + scanNode.setQual(evalNodeB); + indexEvals = storageManager.findIndexablePredicateSet(scanNode, new Column[]{rowkeyColumn}); + assertEquals(2, indexEvals.size()); + indexPredicateValue = storageManager.getIndexablePredicateValue(null, indexEvals.get(0)); + assertEquals("020", indexPredicateValue.getFirst().asChars()); + assertEquals("055", indexPredicateValue.getSecond().asChars()); + + indexPredicateValue = storageManager.getIndexablePredicateValue(null, indexEvals.get(1)); + assertEquals("075", indexPredicateValue.getFirst().asChars()); + assertEquals("075", indexPredicateValue.getSecond().asChars()); + + // where (rk >= '020' and rk <= '055') or (rk >= '072' and rk <= '078') + EvalNode evalNode4 = new BinaryEval(EvalType.GEQ, new FieldEval(rowkeyColumn), new ConstEval(new TextDatum("072"))); + EvalNode evalNode5 = new BinaryEval(EvalType.LEQ, new FieldEval(rowkeyColumn), new ConstEval(new TextDatum("078"))); + EvalNode evalNodeC = new BinaryEval(EvalType.AND, evalNode4, evalNode5); + EvalNode evalNodeD = new BinaryEval(EvalType.OR, evalNodeA, evalNodeC); + scanNode.setQual(evalNodeD); + indexEvals = storageManager.findIndexablePredicateSet(scanNode, new Column[]{rowkeyColumn}); + assertEquals(2, indexEvals.size()); + + indexPredicateValue = storageManager.getIndexablePredicateValue(null, indexEvals.get(0)); + assertEquals("020", indexPredicateValue.getFirst().asChars()); + assertEquals("055", indexPredicateValue.getSecond().asChars()); + + indexPredicateValue = storageManager.getIndexablePredicateValue(null, indexEvals.get(1)); + assertEquals("072", indexPredicateValue.getFirst().asChars()); + assertEquals("078", indexPredicateValue.getSecond().asChars()); + + // where (rk >= '020' and rk <= '055') or (rk >= '072' and rk <= '078' and rk >= '073') + evalNode4 = new BinaryEval(EvalType.GEQ, new FieldEval(rowkeyColumn), new ConstEval(new TextDatum("072"))); + evalNode5 = new BinaryEval(EvalType.LEQ, new FieldEval(rowkeyColumn), new ConstEval(new TextDatum("078"))); + evalNodeC = new BinaryEval(EvalType.AND, evalNode4, evalNode5); + EvalNode evalNode6 = new BinaryEval(EvalType.GEQ, new FieldEval(rowkeyColumn), new ConstEval(new TextDatum("073"))); + evalNodeD = new BinaryEval(EvalType.AND, evalNodeC, evalNode6); + EvalNode evalNodeE = new BinaryEval(EvalType.OR, evalNodeA, evalNodeD); + scanNode.setQual(evalNodeE); + indexEvals = storageManager.findIndexablePredicateSet(scanNode, new Column[]{rowkeyColumn}); + assertEquals(2, indexEvals.size()); + + indexPredicateValue = storageManager.getIndexablePredicateValue(null, indexEvals.get(0)); + assertEquals("020", indexPredicateValue.getFirst().asChars()); + assertEquals("055", indexPredicateValue.getSecond().asChars()); + + indexPredicateValue = storageManager.getIndexablePredicateValue(null, indexEvals.get(1)); + assertEquals("073", indexPredicateValue.getFirst().asChars()); + assertEquals("078", indexPredicateValue.getSecond().asChars()); + } +}
