From b807924f4abb7f5901ab4fe007c07daa959bde05 Mon Sep 17 00:00:00 2001 From: Chen Luwei Date: Wed, 13 Jan 2016 14:10:05 +0800 Subject: [PATCH 1/3] add cat in ResourceTool --- .../kylin/common/persistence/ResourceTool.java | 29 ++++++++++ .../storage/hbase/steps/ResourceStoreTest.java | 63 ++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 storage-hbase/src/test/java/org/apache/kylin/storage/hbase/steps/ResourceStoreTest.java diff --git a/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceTool.java b/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceTool.java index c3038dd..23c0bac 100644 --- a/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceTool.java +++ b/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceTool.java @@ -19,6 +19,9 @@ package org.apache.kylin.common.persistence; import java.io.IOException; +import java.io.InputStream; +import java.io.BufferedReader; +import java.io.InputStreamReader; import java.util.ArrayList; import org.apache.kylin.common.KylinConfig; @@ -60,11 +63,37 @@ public class ResourceTool { case "remove": remove(KylinConfig.getInstanceFromEnv(), args[1]); break; + case "cat": + cat(KylinConfig.getInstanceFromEnv(), args[1]); + break; default: System.out.println("Unknown cmd: " + cmd); } } + public static void cat(KylinConfig config, String path) throws IOException { + ResourceStore store = ResourceStore.getStore(config); + InputStream is = store.getResource(path).inputStream; + BufferedReader br = null; + String line; + try { + br = new BufferedReader(new InputStreamReader(is)); + while ((line = br.readLine()) != null) { + System.out.println(line); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + public static void list(KylinConfig config, String path) throws IOException { ResourceStore store = ResourceStore.getStore(config); ArrayList result = store.listResources(path); diff --git a/storage-hbase/src/test/java/org/apache/kylin/storage/hbase/steps/ResourceStoreTest.java b/storage-hbase/src/test/java/org/apache/kylin/storage/hbase/steps/ResourceStoreTest.java new file mode 100644 index 0000000..020394b --- /dev/null +++ b/storage-hbase/src/test/java/org/apache/kylin/storage/hbase/steps/ResourceStoreTest.java @@ -0,0 +1,63 @@ +/* + * 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.kylin.storage.hbase.steps; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.kylin.common.KylinConfig; +import org.apache.kylin.common.persistence.ResourceTool; +import org.apache.kylin.common.util.ClassUtil; + +import java.io.File; + +/** + * This is a helper class for developer to directly manipulate the metadata store in sandbox + * This is designed to run in IDE(i.e. not on sandbox hadoop CLI) + * + * For production metadata store manipulation refer to bin/metastore.sh in binary package + * It is desinged to run in hadoop CLI, both in sandbox or in real hadoop environment + */ +public class ResourceStoreTest { + + private static final Log logger = LogFactory.getLog(ResourceStoreTest.class); + + public static void main(String[] args) throws Exception { + logger.info("Adding to classpath: " + new File(HBaseMetadataTestCase.SANDBOX_TEST_DATA).getAbsolutePath()); + ClassUtil.addClasspath(new File(HBaseMetadataTestCase.SANDBOX_TEST_DATA).getAbsolutePath()); + System.setProperty(KylinConfig.KYLIN_CONF, "../examples/test_case_data/sandbox"); + if (System.getProperty("hdp.version") == null) { + throw new RuntimeException("No hdp.version set; Please set hdp.version in your jvm option, for example: -Dhdp.version=2.2.4.2-2"); + } + + if (args.length < 2) { + printUsage(); + return; + } + + if ("cat".equalsIgnoreCase(args[0])) { + ResourceTool.main(new String[] { "cat", args[1] }); + } else { + printUsage(); + } + } + + private static void printUsage() { + logger.info("Usage: ResourceStoreTest cat file"); + } +} -- 2.3.2 (Apple Git-55) From 5250f9499ac0f17d700332daed08a5e74f6729d8 Mon Sep 17 00:00:00 2001 From: Chen Luwei Date: Tue, 26 Jan 2016 11:03:44 +0800 Subject: [PATCH 2/3] KYLIN-242 add validation when init cube desc --- .../java/org/apache/kylin/cube/model/CubeDesc.java | 161 +++++++++++++++++-- .../java/org/apache/kylin/cube/CubeDescTest.java | 172 ++++++++++++++++++++- 2 files changed, 315 insertions(+), 18 deletions(-) diff --git a/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java b/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java index 2c1e623..8578be8 100644 --- a/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java +++ b/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java @@ -20,21 +20,13 @@ package org.apache.kylin.cube.model; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.Set; import javax.annotation.Nullable; import org.apache.commons.codec.binary.Base64; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.apache.kylin.common.KylinConfig; @@ -43,6 +35,9 @@ import org.apache.kylin.common.persistence.RootPersistentEntity; import org.apache.kylin.common.util.Array; import org.apache.kylin.common.util.CaseInsensitiveStringMap; import org.apache.kylin.common.util.JsonUtil; +import org.apache.kylin.cube.model.validation.IValidatorRule; +import org.apache.kylin.cube.model.validation.ResultLevel; +import org.apache.kylin.cube.model.validation.ValidateContext; import org.apache.kylin.measure.MeasureType; import org.apache.kylin.metadata.MetadataConstants; import org.apache.kylin.metadata.MetadataManager; @@ -64,12 +59,15 @@ import com.google.common.base.Function; import com.google.common.collect.Collections2; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** */ @SuppressWarnings("serial") @JsonAutoDetect(fieldVisibility = Visibility.NONE, getterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE) public class CubeDesc extends RootPersistentEntity { + private static final Logger logger = LoggerFactory.getLogger(CubeDesc.class); public enum DeriveType { LOOKUP, PK_FK @@ -446,6 +444,9 @@ public class CubeDesc extends RootPersistentEntity { this.addError("The cubeDesc '" + this.getName() + "' doesn't have data model specified."); } + // check if aggregation group is valid + validate(this); + this.model = MetadataManager.getInstance(config).getDataModelDesc(this.modelName); if (this.model == null) { @@ -477,6 +478,146 @@ public class CubeDesc extends RootPersistentEntity { } } + public void validate(CubeDesc cube) { + inner(cube); + } + + private void inner(CubeDesc cube) { + int maxSize = getMaxAgrGroupSize(); + int index = 0; + + for (AggregationGroup agg : cube.getAggregationGroups()) { + if (agg.getIncludes() == null) { + logger.error("Aggregation group " + index + " includes field not set"); + throw new IllegalStateException("Aggregation group " + index + " includes field not set"); + } + + if (agg.getSelectRule() == null) { + logger.error("Aggregation group " + index + " includes field not set"); + throw new IllegalStateException("Aggregation group " + index + " select rule field not set"); + } + + Set includeDims = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); + getDims(includeDims, agg.getIncludes()); + + Set mandatoryDims = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); + getDims(mandatoryDims, agg.getSelectRule().mandatory_dims); + + ArrayList> hierarchyDimsList = new ArrayList (); + Set hierarchyDims = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); + getDims(hierarchyDimsList, hierarchyDims, agg.getSelectRule().hierarchy_dims); + + ArrayList> jointDimsList = new ArrayList (); + Set jointDims = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); + getDims(jointDimsList, jointDims, agg.getSelectRule().joint_dims); + + if (!includeDims.containsAll(mandatoryDims) || !containsAll(includeDims, hierarchyDimsList) || !containsAll(includeDims, jointDimsList)) { + logger.error("Aggregation group " + index + " Include dims not containing all the used dims"); + throw new IllegalStateException("Aggregation group " + index + " Include dims not containing all the used dims"); + } + + Set normalDims = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); + normalDims.addAll(includeDims); + normalDims.removeAll(mandatoryDims); + normalDims.removeAll(hierarchyDims); + normalDims.removeAll(jointDims); + + int normalDimSize = normalDims.size(); + int hierarchyDimSize = hierarchyDimsList.size(); + int jointDimSize = jointDimsList.size(); + + if (normalDimSize + hierarchyDimSize + jointDimSize > maxSize) { + logger.error("Aggregation group " + index + " has too many dimensions"); + throw new IllegalStateException("Aggregation group " + index + " has too many dimensions"); + } + + if (CollectionUtils.containsAny(mandatoryDims, hierarchyDims)) { + logger.warn("Aggregation group " + index + " mandatory dims overlap with hierarchy dims"); + } + if (CollectionUtils.containsAny(mandatoryDims, jointDims)) { + logger.warn("Aggregation group " + index + " mandatory dims overlap with joint dims"); + } + if (CollectionUtils.containsAny(hierarchyDims, jointDims)) { + logger.error("Aggregation group " + index + " hierarchy dims overlap with joint dims"); + throw new IllegalStateException("Aggregation group " + index + " hierarchy dims overlap with joint dims"); + } + if (hasSingle(hierarchyDimsList)) { + logger.error("Aggregation group " + index + " require at least 2 dims in a hierarchy"); + throw new IllegalStateException("Aggregation group " + index + " require at least 2 dims in a hierarchy"); + } + if (hasSingle(jointDimsList)) { + logger.error("Aggregation group " + index + " require at least 2 dims in a joint"); + throw new IllegalStateException("Aggregation group " + index + " require at least 2 dims in a joint"); + } + if (hasOverlap(hierarchyDimsList, hierarchyDims)) { + logger.error("Aggregation group " + index + " a dim exist in more than one hierarchy"); + throw new IllegalStateException("Aggregation group " + index + " a dim exist in more than one hierarchy"); + } + if (hasOverlap(jointDimsList, jointDims)) { + logger.error("Aggregation group " + index + " a dim exist in more than one joint"); + throw new IllegalStateException("Aggregation group " + index + " a dim exist in more than one joint"); + } + + index++; + } + } + + private void getDims (Set dims, String [] stringSet) { + if (stringSet != null) { + for (String str : stringSet) { + dims.add(str); + } + } + } + + private void getDims (ArrayList> dimsList, Set dims, String [][] stringSets) { + Set temp = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); + if (stringSets != null) { + for (String[] ss : stringSets) { + temp.clear(); + for (String s : ss) { + temp.add(s); + dims.add(s); + } + dimsList.add(temp); + } + } + } + + private boolean containsAll(Set includeDims, ArrayList> dimsList) { + boolean b = true; + for (Set dims : dimsList) { + if (!includeDims.containsAll(dims)) + b = false; + } + return b; + } + + private boolean hasSingle (ArrayList> dimsList) { + boolean hasSingle = false; + for (Set dims : dimsList) { + if (dims.size() < 2) + hasSingle = true; + } + return hasSingle; + } + + private boolean hasOverlap (ArrayList> dimsList, Set Dims) { + boolean hasOverlap = false; + int dimSize = 0; + for (Set dims : dimsList) { + dimSize += dims.size(); + } + if (dimSize != Dims.size()) + hasOverlap = true; + return hasOverlap; + } + + protected int getMaxAgrGroupSize() { + String size = KylinConfig.getInstanceFromEnv().getOptional(IValidatorRule.KEY_MAX_AGR_GROUP_SIZE, String.valueOf(IValidatorRule.DEFAULT_MAX_AGR_GROUP_SIZE)); + return Integer.parseInt(size); + } + private void initDimensionColumns() { for (DimensionDesc dim : dimensions) { JoinDesc join = dim.getJoin(); diff --git a/core-cube/src/test/java/org/apache/kylin/cube/CubeDescTest.java b/core-cube/src/test/java/org/apache/kylin/cube/CubeDescTest.java index 13fcd4a..3bc6690 100644 --- a/core-cube/src/test/java/org/apache/kylin/cube/CubeDescTest.java +++ b/core-cube/src/test/java/org/apache/kylin/cube/CubeDescTest.java @@ -18,24 +18,28 @@ package org.apache.kylin.cube; -import java.util.HashMap; -import java.util.Map; - +import com.google.common.collect.Maps; import org.apache.kylin.common.util.JsonUtil; import org.apache.kylin.common.util.LocalFileMetadataTestCase; import org.apache.kylin.cube.model.CubeDesc; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.apache.kylin.cube.model.SelectRule; +import org.apache.kylin.metadata.MetadataManager; +import org.junit.*; +import org.junit.rules.ExpectedException; -import com.google.common.collect.Maps; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; /** * @author yangli9 */ public class CubeDescTest extends LocalFileMetadataTestCase { + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before public void setUp() throws Exception { this.createTestMetadata(); @@ -47,6 +51,158 @@ public class CubeDescTest extends LocalFileMetadataTestCase { } @Test + public void testGoodInit() throws Exception { + CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("test_kylin_cube_with_slr_desc"); + cubeDesc.init(getTestConfig(), MetadataManager.getInstance(getTestConfig()).getAllTablesMap()); + } + + @Test + public void testBadInit1() throws Exception { + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Aggregation group 0 includes field not set"); + + CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("test_kylin_cube_with_slr_desc"); + String[] temp = null; + cubeDesc.getAggregationGroups().get(0).setIncludes(temp); + + cubeDesc.init(getTestConfig(), MetadataManager.getInstance(getTestConfig()).getAllTablesMap()); + } + + @Test + public void testBadInit2() throws Exception { + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Aggregation group 0 select rule field not set"); + + CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("test_kylin_cube_with_slr_desc"); + SelectRule temp = null; + cubeDesc.getAggregationGroups().get(0).setSelectRule(temp); + + cubeDesc.init(getTestConfig(), MetadataManager.getInstance(getTestConfig()).getAllTablesMap()); + } + + @Test + public void testBadInit3() throws Exception { + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Aggregation group 0 Include dims not containing all the used dims"); + + CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("test_kylin_cube_with_slr_desc"); + String[] temp = Arrays.asList(cubeDesc.getAggregationGroups().get(0).getIncludes()).subList(0, 3).toArray(new String[3]); + cubeDesc.getAggregationGroups().get(0).setIncludes(temp); + + cubeDesc.init(getTestConfig(), MetadataManager.getInstance(getTestConfig()).getAllTablesMap()); + } + + @Test + public void testBadInit4() throws Exception { + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Aggregation group 0 has too many dimensions"); + + CubeDesc desc = new CubeDesc() { + @Override + protected int getMaxAgrGroupSize() { + return 3; + } + }; + CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("test_kylin_cube_with_slr_desc"); + desc.validate(cubeDesc); + } + + @Test + public void testBadInit5() throws Exception { + CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("test_kylin_cube_with_slr_desc"); + cubeDesc.getAggregationGroups().get(0).getSelectRule().mandatory_dims = new String[] { + "seller_id", "META_CATEG_NAME"}; + + cubeDesc.init(getTestConfig(), MetadataManager.getInstance(getTestConfig()).getAllTablesMap()); + } + + @Test + public void testBadInit6() throws Exception { + CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("test_kylin_cube_with_slr_desc"); + cubeDesc.getAggregationGroups().get(0).getSelectRule().mandatory_dims = new String[] { + "seller_id", "lstg_format_name"}; + + cubeDesc.init(getTestConfig(), MetadataManager.getInstance(getTestConfig()).getAllTablesMap()); + } + + @Test + public void testBadInit7() throws Exception { + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Aggregation group 0 require at least 2 dims in a joint"); + + CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("test_kylin_cube_with_slr_desc"); + cubeDesc.getAggregationGroups().get(0).getSelectRule().joint_dims = new String[][] { + new String[] { "lstg_format_name" } }; + + cubeDesc.init(getTestConfig(), MetadataManager.getInstance(getTestConfig()).getAllTablesMap()); + } + + @Test + public void testBadInit8() throws Exception { + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Aggregation group 0 hierarchy dims overlap with joint dims"); + + CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("test_kylin_cube_with_slr_desc"); + cubeDesc.getAggregationGroups().get(0).getSelectRule().joint_dims = new String[][] { + new String[] { "META_CATEG_NAME", "CATEG_LVL2_NAME" } }; + + cubeDesc.init(getTestConfig(), MetadataManager.getInstance(getTestConfig()).getAllTablesMap()); + } + + @Test + public void testBadInit9() throws Exception { + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Aggregation group 0 hierarchy dims overlap with joint dims"); + + CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("test_kylin_cube_with_slr_desc"); + cubeDesc.getAggregationGroups().get(0).getSelectRule().hierarchy_dims = new String[][] { + new String[] { "META_CATEG_NAME", "CATEG_LVL2_NAME", "CATEG_LVL3_NAME" }, + new String[] { "lstg_format_name", "lstg_site_id" } }; + cubeDesc.getAggregationGroups().get(0).getSelectRule().joint_dims = new String[][] { + new String[] { "META_CATEG_NAME", "lstg_format_name" } }; + + cubeDesc.init(getTestConfig(), MetadataManager.getInstance(getTestConfig()).getAllTablesMap()); + } + + @Test + public void testBadInit10() throws Exception { + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Aggregation group 0 a dim exist in more than one joint"); + + CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("test_kylin_cube_with_slr_desc"); + cubeDesc.getAggregationGroups().get(0).getSelectRule().joint_dims = new String[][] { + new String[] { "lstg_format_name", "lstg_site_id", "slr_segment_cd" }, + new String[] { "lstg_format_name", "lstg_site_id", "leaf_categ_id"} }; + + cubeDesc.init(getTestConfig(), MetadataManager.getInstance(getTestConfig()).getAllTablesMap()); + } + + @Test + public void testBadInit11() throws Exception { + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Aggregation group 0 require at least 2 dims in a hierarchy"); + + CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("test_kylin_cube_with_slr_desc"); + cubeDesc.getAggregationGroups().get(0).getSelectRule().hierarchy_dims = new String[][] { + new String[] { "META_CATEG_NAME" } }; + + cubeDesc.init(getTestConfig(), MetadataManager.getInstance(getTestConfig()).getAllTablesMap()); + } + + @Test + public void testBadInit12() throws Exception { + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Aggregation group 0 a dim exist in more than one hierarchy"); + + CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("test_kylin_cube_with_slr_desc"); + cubeDesc.getAggregationGroups().get(0).getSelectRule().hierarchy_dims = new String[][] { + new String[] { "META_CATEG_NAME", "CATEG_LVL2_NAME", "CATEG_LVL3_NAME" }, + new String[] { "META_CATEG_NAME", "CATEG_LVL2_NAME" } }; + + cubeDesc.init(getTestConfig(), MetadataManager.getInstance(getTestConfig()).getAllTablesMap()); + } + + @Test public void testSerialize() throws Exception { CubeDesc desc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("test_kylin_cube_with_slr_desc"); String str = JsonUtil.writeValueAsIndentString(desc); -- 2.3.2 (Apple Git-55) From a9f1af2e25c69b38247e868bd863360a0585a377 Mon Sep 17 00:00:00 2001 From: Chen Luwei Date: Thu, 28 Jan 2016 18:27:15 +0800 Subject: [PATCH 3/3] delete resourceStoreTest --- .../storage/hbase/steps/ResourceStoreTest.java | 63 ---------------------- 1 file changed, 63 deletions(-) delete mode 100644 storage-hbase/src/test/java/org/apache/kylin/storage/hbase/steps/ResourceStoreTest.java diff --git a/storage-hbase/src/test/java/org/apache/kylin/storage/hbase/steps/ResourceStoreTest.java b/storage-hbase/src/test/java/org/apache/kylin/storage/hbase/steps/ResourceStoreTest.java deleted file mode 100644 index 020394b..0000000 --- a/storage-hbase/src/test/java/org/apache/kylin/storage/hbase/steps/ResourceStoreTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.kylin.storage.hbase.steps; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.kylin.common.KylinConfig; -import org.apache.kylin.common.persistence.ResourceTool; -import org.apache.kylin.common.util.ClassUtil; - -import java.io.File; - -/** - * This is a helper class for developer to directly manipulate the metadata store in sandbox - * This is designed to run in IDE(i.e. not on sandbox hadoop CLI) - * - * For production metadata store manipulation refer to bin/metastore.sh in binary package - * It is desinged to run in hadoop CLI, both in sandbox or in real hadoop environment - */ -public class ResourceStoreTest { - - private static final Log logger = LogFactory.getLog(ResourceStoreTest.class); - - public static void main(String[] args) throws Exception { - logger.info("Adding to classpath: " + new File(HBaseMetadataTestCase.SANDBOX_TEST_DATA).getAbsolutePath()); - ClassUtil.addClasspath(new File(HBaseMetadataTestCase.SANDBOX_TEST_DATA).getAbsolutePath()); - System.setProperty(KylinConfig.KYLIN_CONF, "../examples/test_case_data/sandbox"); - if (System.getProperty("hdp.version") == null) { - throw new RuntimeException("No hdp.version set; Please set hdp.version in your jvm option, for example: -Dhdp.version=2.2.4.2-2"); - } - - if (args.length < 2) { - printUsage(); - return; - } - - if ("cat".equalsIgnoreCase(args[0])) { - ResourceTool.main(new String[] { "cat", args[1] }); - } else { - printUsage(); - } - } - - private static void printUsage() { - logger.info("Usage: ResourceStoreTest cat file"); - } -} -- 2.3.2 (Apple Git-55)