You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2016/02/11 13:50:15 UTC
[36/51] [partial] kylin git commit: KYLIN-1416 keep only website in
document branch
http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/main/java/org/apache/kylin/cube/model/validation/rule/AggregationGroupSizeRule.java
----------------------------------------------------------------------
diff --git a/cube/src/main/java/org/apache/kylin/cube/model/validation/rule/AggregationGroupSizeRule.java b/cube/src/main/java/org/apache/kylin/cube/model/validation/rule/AggregationGroupSizeRule.java
deleted file mode 100644
index 23f24e0..0000000
--- a/cube/src/main/java/org/apache/kylin/cube/model/validation/rule/AggregationGroupSizeRule.java
+++ /dev/null
@@ -1,66 +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.cube.model.validation.rule;
-
-import org.apache.kylin.common.KylinConfig;
-import org.apache.kylin.cube.model.CubeDesc;
-import org.apache.kylin.cube.model.validation.IValidatorRule;
-import org.apache.kylin.cube.model.validation.ResultLevel;
-import org.apache.kylin.cube.model.validation.ValidateContext;
-
-/**
- * Rule to validate: 1. The aggregationGroup size must be less than 20
- *
- * @author jianliu
- *
- */
-public class AggregationGroupSizeRule implements IValidatorRule<CubeDesc> {
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.kylin.metadata.validation.IValidatorRule#validate(java.lang.Object
- * , org.apache.kylin.metadata.validation.ValidateContext)
- */
- @Override
- public void validate(CubeDesc cube, ValidateContext context) {
- innerValidateMaxSize(cube, context);
- }
-
- /**
- * @param cube
- * @param context
- */
- private void innerValidateMaxSize(CubeDesc cube, ValidateContext context) {
- int maxSize = getMaxAgrGroupSize();
- String[][] groups = cube.getRowkey().getAggregationGroups();
- for (int i = 0; i < groups.length; i++) {
- String[] group = groups[i];
- if (group.length >= maxSize) {
- context.addResult(ResultLevel.ERROR, "Length of the number " + i + " aggregation group's length should be less than " + maxSize);
- }
- }
- }
-
- protected int getMaxAgrGroupSize() {
- String size = KylinConfig.getInstanceFromEnv().getProperty(KEY_MAX_AGR_GROUP_SIZE, String.valueOf(DEFAULT_MAX_AGR_GROUP_SIZE));
- return Integer.parseInt(size);
- }
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/main/java/org/apache/kylin/cube/model/validation/rule/FunctionRule.java
----------------------------------------------------------------------
diff --git a/cube/src/main/java/org/apache/kylin/cube/model/validation/rule/FunctionRule.java b/cube/src/main/java/org/apache/kylin/cube/model/validation/rule/FunctionRule.java
deleted file mode 100644
index d7d9f13..0000000
--- a/cube/src/main/java/org/apache/kylin/cube/model/validation/rule/FunctionRule.java
+++ /dev/null
@@ -1,159 +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.cube.model.validation.rule;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.kylin.cube.model.CubeDesc;
-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.metadata.MetadataManager;
-import org.apache.kylin.metadata.model.ColumnDesc;
-import org.apache.kylin.metadata.model.FunctionDesc;
-import org.apache.kylin.metadata.model.MeasureDesc;
-import org.apache.kylin.metadata.model.ParameterDesc;
-import org.apache.kylin.metadata.model.TableDesc;
-
-/**
- * Validate function parameter. Ticket:
- * https://github.scm.corp.ebay.com/Kylin/Kylin/issues/268
- * <p/>
- * if type is column, check values are valid fact table columns if type is
- * constant, the value only can be numberic
- * <p/>
- * the return type only can be int/bigint/long/double/decimal
- *
- * @author jianliu
- */
-public class FunctionRule implements IValidatorRule<CubeDesc> {
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.kylin.metadata.validation.IValidatorRule#validate(java.lang.Object
- * , org.apache.kylin.metadata.validation.ValidateContext)
- */
- @Override
- public void validate(CubeDesc cube, ValidateContext context) {
- List<MeasureDesc> measures = cube.getMeasures();
-
- List<FunctionDesc> countFuncs = new ArrayList<FunctionDesc>();
-
- Iterator<MeasureDesc> it = measures.iterator();
- while (it.hasNext()) {
- MeasureDesc measure = it.next();
- FunctionDesc func = measure.getFunction();
- ParameterDesc parameter = func.getParameter();
- if (parameter == null) {
- context.addResult(ResultLevel.ERROR, "Must define parameter for function " + func.getExpression() + " in " + measure.getName());
- return;
- }
-
- String type = func.getParameter().getType();
- String value = func.getParameter().getValue();
- if (StringUtils.isEmpty(type)) {
- context.addResult(ResultLevel.ERROR, "Must define type for parameter type " + func.getExpression() + " in " + measure.getName());
- return;
- }
- if (StringUtils.isEmpty(value)) {
- context.addResult(ResultLevel.ERROR, "Must define type for parameter value " + func.getExpression() + " in " + measure.getName());
- return;
- }
- if (StringUtils.isEmpty(func.getReturnType())) {
- context.addResult(ResultLevel.ERROR, "Must define return type for function " + func.getExpression() + " in " + measure.getName());
- return;
- }
-
- if (StringUtils.equalsIgnoreCase(FunctionDesc.PARAMETER_TYPE_COLUMN, type)) {
- validateColumnParameter(context, cube, value);
- } else if (StringUtils.equals(FunctionDesc.PARAMTER_TYPE_CONSTANT, type)) {
- validateCostantParameter(context, cube, value);
- }
- try {
- func.getMeasureType().validate(func);
- } catch (IllegalArgumentException ex) {
- context.addResult(ResultLevel.ERROR, ex.getMessage());
- }
-
- if (func.isCount())
- countFuncs.add(func);
- }
-
- if (countFuncs.size() != 1) {
- context.addResult(ResultLevel.ERROR, "Must define one and only one count(1) function, but there are " + countFuncs.size() + " -- " + countFuncs);
- }
- }
-
- /**
- * @param context
- * @param cube
- * @param value
- */
- private void validateCostantParameter(ValidateContext context, CubeDesc cube, String value) {
- try {
- Integer.parseInt(value);
- } catch (Exception e) {
- context.addResult(ResultLevel.ERROR, "Parameter value must be number, but it is " + value);
- }
- }
-
- /**
- * @param context
- * @param cube
- * @param value
- */
- private void validateColumnParameter(ValidateContext context, CubeDesc cube, String value) {
- String factTable = cube.getFactTable();
- if (StringUtils.isEmpty(factTable)) {
- context.addResult(ResultLevel.ERROR, "Fact table can not be null.");
- return;
- }
- TableDesc table = MetadataManager.getInstance(cube.getConfig()).getTableDesc(factTable);
- if (table == null) {
- context.addResult(ResultLevel.ERROR, "Fact table can not be found: " + cube);
- return;
- }
- // Prepare column set
- Set<String> set = new HashSet<String>();
- ColumnDesc[] cdesc = table.getColumns();
- for (int i = 0; i < cdesc.length; i++) {
- ColumnDesc columnDesc = cdesc[i];
- set.add(columnDesc.getName());
- }
-
- String[] items = value.split(",");
- for (int i = 0; i < items.length; i++) {
- String item = items[i].trim();
- if (StringUtils.isEmpty(item)) {
- continue;
- }
- if (!set.contains(item)) {
- context.addResult(ResultLevel.ERROR, "Column [" + item + "] does not exist in factable table" + factTable);
- }
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/main/java/org/apache/kylin/cube/model/validation/rule/IKylinValidationConstants.java
----------------------------------------------------------------------
diff --git a/cube/src/main/java/org/apache/kylin/cube/model/validation/rule/IKylinValidationConstants.java b/cube/src/main/java/org/apache/kylin/cube/model/validation/rule/IKylinValidationConstants.java
deleted file mode 100644
index 95e92ad..0000000
--- a/cube/src/main/java/org/apache/kylin/cube/model/validation/rule/IKylinValidationConstants.java
+++ /dev/null
@@ -1,33 +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.cube.model.validation.rule;
-
-import org.apache.kylin.metadata.MetadataConstants;
-
-/**
- * @author jianliu
- *
- */
-public interface IKylinValidationConstants extends MetadataConstants {
-
- public static final int DEFAULT_MAX_AGR_GROUP_SIZE = 20;
- public static final String KEY_MAX_AGR_GROUP_SIZE = "rule_max.arggregation.group.size";
- public static final String KEY_IGNORE_UNKNOWN_FUNC = "rule_ignore_unknown_func";
-
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/main/java/org/apache/kylin/cube/model/validation/rule/MandatoryColumnRule.java
----------------------------------------------------------------------
diff --git a/cube/src/main/java/org/apache/kylin/cube/model/validation/rule/MandatoryColumnRule.java b/cube/src/main/java/org/apache/kylin/cube/model/validation/rule/MandatoryColumnRule.java
deleted file mode 100644
index b0e6847..0000000
--- a/cube/src/main/java/org/apache/kylin/cube/model/validation/rule/MandatoryColumnRule.java
+++ /dev/null
@@ -1,75 +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.cube.model.validation.rule;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.kylin.cube.model.CubeDesc;
-import org.apache.kylin.cube.model.RowKeyColDesc;
-import org.apache.kylin.cube.model.validation.IValidatorRule;
-import org.apache.kylin.cube.model.validation.ResultLevel;
-import org.apache.kylin.cube.model.validation.ValidateContext;
-
-/**
- * Validate that mandatory column must NOT appear in aggregation group.
- *
- * @author jianliu
- *
- */
-public class MandatoryColumnRule implements IValidatorRule<CubeDesc> {
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.kylin.metadata.validation.IValidatorRule#validate(java.lang.Object
- * , org.apache.kylin.metadata.validation.ValidateContext)
- */
- @Override
- public void validate(CubeDesc cube, ValidateContext context) {
- Set<String> mands = new HashSet<String>();
- RowKeyColDesc[] cols = cube.getRowkey().getRowKeyColumns();
- if (cols == null || cols.length == 0) {
- return;
- }
- for (int i = 0; i < cols.length; i++) {
- RowKeyColDesc rowKeyColDesc = cols[i];
- if (rowKeyColDesc.isMandatory()) {
- mands.add(rowKeyColDesc.getColumn());
- }
- }
- if (mands.isEmpty()) {
- return;
- }
- String[][] groups = cube.getRowkey().getAggregationGroups();
- for (int i = 0; i < groups.length; i++) {
- String[] group = groups[i];
- for (int j = 0; j < group.length; j++) {
- String col = group[j];
- if (mands.contains(col)) {
- context.addResult(ResultLevel.ERROR, "mandatory column " + col + " must not be in aggregation group [" + ArrayUtils.toString(group) + "]");
- }
- }
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/main/java/org/apache/kylin/cube/model/validation/rule/RowKeyAttrRule.java
----------------------------------------------------------------------
diff --git a/cube/src/main/java/org/apache/kylin/cube/model/validation/rule/RowKeyAttrRule.java b/cube/src/main/java/org/apache/kylin/cube/model/validation/rule/RowKeyAttrRule.java
deleted file mode 100644
index 9b8575f..0000000
--- a/cube/src/main/java/org/apache/kylin/cube/model/validation/rule/RowKeyAttrRule.java
+++ /dev/null
@@ -1,74 +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.cube.model.validation.rule;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.kylin.cube.model.CubeDesc;
-import org.apache.kylin.cube.model.RowKeyColDesc;
-import org.apache.kylin.cube.model.RowKeyDesc;
-import org.apache.kylin.cube.model.validation.IValidatorRule;
-import org.apache.kylin.cube.model.validation.ResultLevel;
-import org.apache.kylin.cube.model.validation.ValidateContext;
-
-/**
- * Validate that only one of "length" and "dictionary" appears on rowkey_column
- *
- * @author jianliu
- *
- */
-public class RowKeyAttrRule implements IValidatorRule<CubeDesc> {
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.kylin.metadata.validation.IValidatorRule#validate(java.lang.Object
- * , org.apache.kylin.metadata.validation.ValidateContext)
- */
- @Override
- public void validate(CubeDesc cube, ValidateContext context) {
- RowKeyDesc row = cube.getRowkey();
- if (row == null) {
- context.addResult(ResultLevel.ERROR, "Rowkey does not exist");
- return;
- }
-
- RowKeyColDesc[] rcd = row.getRowKeyColumns();
- if (rcd == null) {
- context.addResult(ResultLevel.ERROR, "Rowkey columns do not exist");
- return;
- }
- if (rcd.length == 0) {
- context.addResult(ResultLevel.ERROR, "Rowkey columns is empty");
- return;
- }
-
- for (int i = 0; i < rcd.length; i++) {
- RowKeyColDesc rd = rcd[i];
- if (rd.getLength() != 0 && (!StringUtils.isEmpty(rd.getDictionary()) && !rd.getDictionary().equals("false"))) {
- context.addResult(ResultLevel.ERROR, "Rowkey column " + rd.getColumn() + " must not have both 'length' and 'dictionary' attribute");
- }
- if (rd.getLength() == 0 && (StringUtils.isEmpty(rd.getDictionary()) || rd.getDictionary().equals("false"))) {
- context.addResult(ResultLevel.ERROR, "Rowkey column " + rd.getColumn() + " must not have both 'length' and 'dictionary' empty");
- }
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/test/java/org/apache/kylin/cube/AggregationGroupSizeRuleTest.java
----------------------------------------------------------------------
diff --git a/cube/src/test/java/org/apache/kylin/cube/AggregationGroupSizeRuleTest.java b/cube/src/test/java/org/apache/kylin/cube/AggregationGroupSizeRuleTest.java
deleted file mode 100644
index 4a5278e..0000000
--- a/cube/src/test/java/org/apache/kylin/cube/AggregationGroupSizeRuleTest.java
+++ /dev/null
@@ -1,101 +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.cube;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.kylin.common.util.JsonUtil;
-import org.apache.kylin.cube.model.CubeDesc;
-import org.apache.kylin.cube.model.validation.IValidatorRule;
-import org.apache.kylin.cube.model.validation.ValidateContext;
-import org.apache.kylin.cube.model.validation.rule.AggregationGroupSizeRule;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * @author jianliu
- *
- */
-public class AggregationGroupSizeRuleTest {
-
- private CubeDesc cube;
- private ValidateContext vContext = new ValidateContext();
-
- /**
- * @throws java.lang.Exception
- */
- @Before
- public void setUp() throws Exception {
- CubeDesc desc2 = JsonUtil.readValue(getClass().getClassLoader().getResourceAsStream("data/TEST2_desc.json"), CubeDesc.class);
- this.cube = desc2;
-
- }
-
- @Test
- public void testOneMandatoryColumn() {
- IValidatorRule<CubeDesc> rule = new AggregationGroupSizeRule() {
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.kylin.metadata.validation.rule.AggregationGroupSizeRule
- * #getMaxAgrGroupSize()
- */
- @Override
- protected int getMaxAgrGroupSize() {
- return 3;
- }
- };
- rule.validate(cube, vContext);
- vContext.print(System.out);
- assertEquals("Failed to validate aggragation group error", vContext.getResults().length, 2);
- assertTrue("Failed to validate aggragation group error", vContext.getResults()[0].getMessage().startsWith("Length of the number"));
- assertTrue("Failed to validate aggragation group error", vContext.getResults()[1].getMessage().startsWith("Length of the number"));
- // assertTrue("Failed to validate aggragation group error",
- // vContext.getResults()[2].getMessage()
- // .startsWith("Hierachy column"));
- }
-
- @Test
- public void testAggColumnSize() {
- AggregationGroupSizeRule rule = new AggregationGroupSizeRule() {
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.kylin.metadata.validation.rule.AggregationGroupSizeRule
- * #getMaxAgrGroupSize()
- */
- @Override
- protected int getMaxAgrGroupSize() {
- return 20;
- }
- };
- rule.validate(cube, vContext);
- vContext.print(System.out);
- assertEquals("Failed to validate aggragation group error", vContext.getResults().length, 0);
- // assertTrue("Failed to validate aggragation group error",
- // vContext.getResults()[0].getMessage()
- // .startsWith("Aggregation group"));
- // assertTrue("Failed to validate aggragation group error",
- // vContext.getResults()[0].getMessage()
- // .startsWith("Hierachy column"));
- }
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/test/java/org/apache/kylin/cube/CubeDescTest.java
----------------------------------------------------------------------
diff --git a/cube/src/test/java/org/apache/kylin/cube/CubeDescTest.java b/cube/src/test/java/org/apache/kylin/cube/CubeDescTest.java
deleted file mode 100644
index c0b6210..0000000
--- a/cube/src/test/java/org/apache/kylin/cube/CubeDescTest.java
+++ /dev/null
@@ -1,81 +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.cube;
-
-import java.util.HashMap;
-import java.util.Map;
-
-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 com.google.common.collect.Maps;
-
-/**
- * @author yangli9
- */
-public class CubeDescTest extends LocalFileMetadataTestCase {
-
- @Before
- public void setUp() throws Exception {
- this.createTestMetadata();
- }
-
- @After
- public void after() throws Exception {
- this.cleanupTestMetadata();
- }
-
- @Test
- public void testSerialize() throws Exception {
- CubeDesc desc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("test_kylin_cube_with_slr_desc");
- String str = JsonUtil.writeValueAsIndentString(desc);
- System.out.println(str);
- @SuppressWarnings("unused")
- CubeDesc desc2 = JsonUtil.readValue(str, CubeDesc.class);
- }
-
- @Test
- public void testGetCubeDesc() throws Exception {
- CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("test_kylin_cube_with_slr_desc");
- Assert.assertNotNull(cubeDesc);
- }
-
- @Test
- public void testSerializeMap() throws Exception {
- Map<String, String> map = Maps.newHashMap();
-
- map.put("key1", "value1");
- map.put("key2", "value2");
-
- String mapStr = JsonUtil.writeValueAsString(map);
-
- System.out.println(mapStr);
-
- Map<?, ?> map2 = JsonUtil.readValue(mapStr, HashMap.class);
-
- Assert.assertEquals(map, map2);
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/test/java/org/apache/kylin/cube/CubeManagerCacheTest.java
----------------------------------------------------------------------
diff --git a/cube/src/test/java/org/apache/kylin/cube/CubeManagerCacheTest.java b/cube/src/test/java/org/apache/kylin/cube/CubeManagerCacheTest.java
deleted file mode 100644
index 9796fb2..0000000
--- a/cube/src/test/java/org/apache/kylin/cube/CubeManagerCacheTest.java
+++ /dev/null
@@ -1,77 +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.cube;
-
-import static org.junit.Assert.assertEquals;
-
-import org.apache.kylin.common.persistence.ResourceStore;
-import org.apache.kylin.common.util.LocalFileMetadataTestCase;
-import org.apache.kylin.cube.model.CubeDesc;
-import org.apache.kylin.metadata.MetadataManager;
-import org.apache.kylin.metadata.project.ProjectManager;
-import org.apache.kylin.metadata.realization.RealizationStatusEnum;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * @author yangli9
- *
- */
-public class CubeManagerCacheTest extends LocalFileMetadataTestCase {
-
- private CubeManager cubeManager;
-
- @Before
- public void setUp() throws Exception {
- this.createTestMetadata();
- MetadataManager.clearCache();
- CubeManager.clearCache();
- ProjectManager.clearCache();
- cubeManager = CubeManager.getInstance(getTestConfig());
- }
-
- @After
- public void after() throws Exception {
- this.cleanupTestMetadata();
- }
-
- @Test
- public void testReloadCache() throws Exception {
- ResourceStore store = getStore();
-
- // clean legacy in case last run failed
- store.deleteResource("/cube/a_whole_new_cube.json");
- CubeDescManager cubeDescMgr = getCubeDescManager();
- CubeDesc desc = cubeDescMgr.getCubeDesc("test_kylin_cube_with_slr_desc");
- cubeManager.createCube("a_whole_new_cube", "default", desc, null);
-
- CubeInstance createdCube = cubeManager.getCube("a_whole_new_cube");
- assertEquals(0, createdCube.getSegments().size());
- assertEquals(RealizationStatusEnum.DISABLED, createdCube.getStatus());
- createdCube.setStatus(RealizationStatusEnum.DESCBROKEN);
-
- cubeManager.updateCube(createdCube);
- assertEquals(RealizationStatusEnum.DESCBROKEN, cubeManager.getCube("a_whole_new_cube").getStatus());
- }
-
- public CubeDescManager getCubeDescManager() {
- return CubeDescManager.getInstance(getTestConfig());
- }
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/test/java/org/apache/kylin/cube/CubeManagerTest.java
----------------------------------------------------------------------
diff --git a/cube/src/test/java/org/apache/kylin/cube/CubeManagerTest.java b/cube/src/test/java/org/apache/kylin/cube/CubeManagerTest.java
deleted file mode 100644
index 63ee2cc..0000000
--- a/cube/src/test/java/org/apache/kylin/cube/CubeManagerTest.java
+++ /dev/null
@@ -1,90 +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.cube;
-
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.kylin.common.KylinConfig;
-import org.apache.kylin.common.persistence.ResourceStore;
-import org.apache.kylin.common.util.JsonUtil;
-import org.apache.kylin.common.util.LocalFileMetadataTestCase;
-import org.apache.kylin.cube.model.CubeDesc;
-import org.apache.kylin.metadata.project.ProjectInstance;
-import org.apache.kylin.metadata.project.ProjectManager;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * @author yangli9
- */
-public class CubeManagerTest extends LocalFileMetadataTestCase {
-
- @Before
- public void setUp() throws Exception {
- this.createTestMetadata();
- }
-
- @After
- public void after() throws Exception {
- this.cleanupTestMetadata();
- }
-
- @Test
- public void testBasics() throws Exception {
- CubeInstance cube = CubeManager.getInstance(getTestConfig()).getCube("test_kylin_cube_without_slr_ready");
- CubeDesc desc = cube.getDescriptor();
- System.out.println(JsonUtil.writeValueAsIndentString(desc));
-
- String signature = desc.calculateSignature();
- desc.getModel().getPartitionDesc().setPartitionDateColumn("test_column");
- assertTrue(!signature.equals(desc.calculateSignature()));
- }
-
- @Test
- public void testCreateAndDrop() throws Exception {
-
- KylinConfig config = getTestConfig();
- CubeManager cubeMgr = CubeManager.getInstance(config);
- ProjectManager prjMgr = ProjectManager.getInstance(config);
- ResourceStore store = getStore();
-
- // clean legacy in case last run failed
- store.deleteResource("/cube/a_whole_new_cube.json");
-
- CubeDescManager cubeDescMgr = getCubeDescManager();
- CubeDesc desc = cubeDescMgr.getCubeDesc("test_kylin_cube_with_slr_desc");
- CubeInstance createdCube = cubeMgr.createCube("a_whole_new_cube", ProjectInstance.DEFAULT_PROJECT_NAME, desc, null);
- assertTrue(createdCube == cubeMgr.getCube("a_whole_new_cube"));
-
- assertTrue(prjMgr.listAllRealizations(ProjectInstance.DEFAULT_PROJECT_NAME).contains(createdCube));
-
- CubeInstance droppedCube = CubeManager.getInstance(getTestConfig()).dropCube("a_whole_new_cube", true);
- assertTrue(createdCube == droppedCube);
-
- assertTrue(!prjMgr.listAllRealizations(ProjectInstance.DEFAULT_PROJECT_NAME).contains(droppedCube));
-
- assertNull(CubeManager.getInstance(getTestConfig()).getCube("a_whole_new_cube"));
- }
-
- public CubeDescManager getCubeDescManager() {
- return CubeDescManager.getInstance(getTestConfig());
- }
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/test/java/org/apache/kylin/cube/CubeSegmentsTest.java
----------------------------------------------------------------------
diff --git a/cube/src/test/java/org/apache/kylin/cube/CubeSegmentsTest.java b/cube/src/test/java/org/apache/kylin/cube/CubeSegmentsTest.java
deleted file mode 100644
index 99e5003..0000000
--- a/cube/src/test/java/org/apache/kylin/cube/CubeSegmentsTest.java
+++ /dev/null
@@ -1,170 +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.cube;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.io.IOException;
-
-import org.apache.kylin.common.util.LocalFileMetadataTestCase;
-import org.apache.kylin.common.util.Pair;
-import org.apache.kylin.metadata.model.SegmentStatusEnum;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public class CubeSegmentsTest extends LocalFileMetadataTestCase {
-
- @Before
- public void setUp() throws Exception {
- this.createTestMetadata();
- }
-
- @After
- public void after() throws Exception {
- this.cleanupTestMetadata();
- }
-
- @Test(expected = IllegalStateException.class)
- public void testAppendNonPartitioned() throws IOException {
- CubeManager mgr = mgr();
- CubeInstance cube = mgr.getCube("test_kylin_cube_without_slr_empty");
-
- // first append, creates a new & single segment
- CubeSegment seg = mgr.appendSegments(cube, 0);
- assertEquals(0, seg.getDateRangeStart());
- assertEquals(Long.MAX_VALUE, seg.getDateRangeEnd());
- assertEquals(1, cube.getSegments().size());
-
- // second append, throw IllegalStateException because the first segment is not built
- CubeSegment seg2 = mgr.appendSegments(cube, 0);
- discard(seg2);
- }
-
- @Test(expected = IllegalStateException.class)
- public void testAppendNonPartitioned2() throws IOException {
- CubeManager mgr = mgr();
- CubeInstance cube = mgr.getCube("test_kylin_cube_without_slr_ready");
-
- // assert one ready segment
- assertEquals(1, cube.getSegments().size());
- CubeSegment seg = cube.getSegment(SegmentStatusEnum.READY).get(0);
- assertEquals(SegmentStatusEnum.READY, seg.getStatus());
-
- // append again, for non-partitioned cube, it becomes a full refresh
- CubeSegment seg2 = mgr.appendSegments(cube, 0);
- assertEquals(0, seg2.getDateRangeStart());
- assertEquals(Long.MAX_VALUE, seg2.getDateRangeEnd());
- assertEquals(2, cube.getSegments().size());
-
- // non-partitioned cannot merge, throw exception
- mgr.mergeSegments(cube, 0, Long.MAX_VALUE, false);
- }
-
- @Test
- public void testPartitioned() throws IOException {
- CubeManager mgr = mgr();
- CubeInstance cube = mgr.getCube("test_kylin_cube_with_slr_left_join_empty");
-
- // no segment at first
- assertEquals(0, cube.getSegments().size());
-
- // append first
- CubeSegment seg1 = mgr.appendSegments(cube, 1000);
- seg1.setStatus(SegmentStatusEnum.READY);
-
- // append second
- CubeSegment seg2 = mgr.appendSegments(cube, 2000);
-
- assertEquals(2, cube.getSegments().size());
- assertEquals(1000, seg2.getDateRangeStart());
- assertEquals(2000, seg2.getDateRangeEnd());
- assertEquals(SegmentStatusEnum.NEW, seg2.getStatus());
- seg2.setStatus(SegmentStatusEnum.READY);
-
- // merge first and second
- CubeSegment merge = mgr.mergeSegments(cube, 0, 2000, true);
-
- assertEquals(3, cube.getSegments().size());
- assertEquals(0, merge.getDateRangeStart());
- assertEquals(2000, merge.getDateRangeEnd());
- assertEquals(SegmentStatusEnum.NEW, merge.getStatus());
-
- // segments are strictly ordered
- assertEquals(seg1, cube.getSegments().get(0));
- assertEquals(merge, cube.getSegments().get(1));
- assertEquals(seg2, cube.getSegments().get(2));
-
- // drop the merge
- cube.getSegments().remove(merge);
-
- // try merge at start/end at middle of segments
- CubeSegment merge2 = mgr.mergeSegments(cube, 500, 1500, true);
- assertEquals(3, cube.getSegments().size());
- assertEquals(0, merge2.getDateRangeStart());
- assertEquals(2000, merge2.getDateRangeEnd());
- }
-
- @Test
- public void testSpecialAppendAndMerge() throws IOException {
- CubeManager mgr = mgr();
- CubeInstance cube = mgr.getCube("test_kylin_cube_without_slr_left_join_empty");
-
- // no segment at first
- assertEquals(0, cube.getSegments().size());
-
- try {
- mgr.appendAndMergeSegments(cube, 1000);
- fail();
- } catch (IllegalStateException ex) {
- // expected, append and merge requires at least one segment
- }
-
- // append first
- CubeSegment seg1 = mgr.appendSegments(cube, 1000);
- seg1.setStatus(SegmentStatusEnum.READY);
-
- // append second and merge with first
- Pair<CubeSegment, CubeSegment> appendAndMergeSegments = mgr.appendAndMergeSegments(cube, 2000);
- CubeSegment seg2 = appendAndMergeSegments.getFirst();
- CubeSegment merge = appendAndMergeSegments.getSecond();
-
- assertEquals(3, cube.getSegments().size());
- assertEquals(0, seg1.getDateRangeStart());
- assertEquals(1000, seg1.getDateRangeEnd());
- assertEquals(1000, seg2.getDateRangeStart());
- assertEquals(2000, seg2.getDateRangeEnd());
- assertEquals(0, merge.getDateRangeStart());
- assertEquals(2000, merge.getDateRangeEnd());
-
- // segments are strictly ordered
- assertEquals(seg1, cube.getSegments().get(0));
- assertEquals(merge, cube.getSegments().get(1));
- assertEquals(seg2, cube.getSegments().get(2));
- }
-
- private void discard(Object o) {
- // throw away input parameter
- }
-
- private CubeManager mgr() {
- return CubeManager.getInstance(getTestConfig());
- }
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/test/java/org/apache/kylin/cube/DictionaryManagerTest.java
----------------------------------------------------------------------
diff --git a/cube/src/test/java/org/apache/kylin/cube/DictionaryManagerTest.java b/cube/src/test/java/org/apache/kylin/cube/DictionaryManagerTest.java
deleted file mode 100644
index f093032..0000000
--- a/cube/src/test/java/org/apache/kylin/cube/DictionaryManagerTest.java
+++ /dev/null
@@ -1,85 +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.cube;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.HashSet;
-
-import org.apache.kylin.common.util.JsonUtil;
-import org.apache.kylin.common.util.LocalFileMetadataTestCase;
-import org.apache.kylin.cube.model.CubeDesc;
-import org.apache.kylin.common.util.Dictionary;
-import org.apache.kylin.dict.DictionaryInfo;
-import org.apache.kylin.dict.DictionaryManager;
-import org.apache.kylin.metadata.model.TblColRef;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-
-public class DictionaryManagerTest extends LocalFileMetadataTestCase {
-
- DictionaryManager dictMgr;
-
- @Before
- public void setup() throws Exception {
- createTestMetadata();
- dictMgr = DictionaryManager.getInstance(getTestConfig());
- }
-
- @After
- public void after() throws Exception {
- cleanupTestMetadata();
- }
-
- @Test
- @Ignore("hive not ready")
- public void basic() throws Exception {
- CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("test_kylin_cube_without_slr_desc");
- TblColRef col = cubeDesc.findColumnRef("DEFAULT.TEST_CATEGORY_GROUPINGS", "META_CATEG_NAME");
-
- DictionaryInfo info1 = dictMgr.buildDictionary(cubeDesc.getModel(), cubeDesc.getRowkey().getDictionary(col), col, null);
- System.out.println(JsonUtil.writeValueAsIndentString(info1));
-
- DictionaryInfo info2 = dictMgr.buildDictionary(cubeDesc.getModel(), cubeDesc.getRowkey().getDictionary(col), col, null);
- System.out.println(JsonUtil.writeValueAsIndentString(info2));
-
- assertTrue(info1.getUuid() == info2.getUuid());
-
- assertTrue(info1 == dictMgr.getDictionaryInfo(info1.getResourcePath()));
- assertTrue(info2 == dictMgr.getDictionaryInfo(info2.getResourcePath()));
-
- assertTrue(info1.getDictionaryObject() == info2.getDictionaryObject());
-
- touchDictValues(info1);
- }
-
- @SuppressWarnings("unchecked")
- private void touchDictValues(DictionaryInfo info1) {
- Dictionary<String> dict = (Dictionary<String>) info1.getDictionaryObject();
-
- HashSet<String> set = new HashSet<String>();
- for (int i = 0, n = info1.getCardinality(); i < n; i++) {
- set.add(dict.getValueFromId(i));
- }
- assertEquals(info1.getCardinality(), set.size());
- }
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/test/java/org/apache/kylin/cube/MandatoryColumnRuleTest.java
----------------------------------------------------------------------
diff --git a/cube/src/test/java/org/apache/kylin/cube/MandatoryColumnRuleTest.java b/cube/src/test/java/org/apache/kylin/cube/MandatoryColumnRuleTest.java
deleted file mode 100644
index a85522c..0000000
--- a/cube/src/test/java/org/apache/kylin/cube/MandatoryColumnRuleTest.java
+++ /dev/null
@@ -1,57 +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.cube;
-
-import static org.junit.Assert.assertTrue;
-
-import org.apache.kylin.common.util.JsonUtil;
-import org.apache.kylin.cube.model.CubeDesc;
-import org.apache.kylin.cube.model.validation.IValidatorRule;
-import org.apache.kylin.cube.model.validation.ValidateContext;
-import org.apache.kylin.cube.model.validation.rule.MandatoryColumnRule;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * @author jianliu
- *
- */
-public class MandatoryColumnRuleTest {
-
- private CubeDesc cube;
- private ValidateContext vContext = new ValidateContext();
-
- /**
- * @throws java.lang.Exception
- */
- @Before
- public void setUp() throws Exception {
- CubeDesc desc2 = JsonUtil.readValue(getClass().getClassLoader().getResourceAsStream("data/TEST1_desc.json"), CubeDesc.class);
- this.cube = desc2;
-
- }
-
- @Test
- public void testOneMandatoryColumn() {
- IValidatorRule<CubeDesc> rule = new MandatoryColumnRule();
- rule.validate(cube, vContext);
- assertTrue("Failed to validate mandatory error", vContext.getResults().length == 1);
- assertTrue("Failed to validate mandatory error", vContext.getResults()[0].getMessage().startsWith("mandatory column"));
- }
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/test/java/org/apache/kylin/cube/RowKeyAttrRuleTest.java
----------------------------------------------------------------------
diff --git a/cube/src/test/java/org/apache/kylin/cube/RowKeyAttrRuleTest.java b/cube/src/test/java/org/apache/kylin/cube/RowKeyAttrRuleTest.java
deleted file mode 100644
index f1445ba..0000000
--- a/cube/src/test/java/org/apache/kylin/cube/RowKeyAttrRuleTest.java
+++ /dev/null
@@ -1,58 +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.cube;
-
-import static org.junit.Assert.assertTrue;
-
-import org.apache.kylin.common.util.JsonUtil;
-import org.apache.kylin.cube.model.CubeDesc;
-import org.apache.kylin.cube.model.validation.IValidatorRule;
-import org.apache.kylin.cube.model.validation.ValidateContext;
-import org.apache.kylin.cube.model.validation.rule.RowKeyAttrRule;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * @author jianliu
- *
- */
-public class RowKeyAttrRuleTest {
-
- private CubeDesc cube;
- private ValidateContext vContext = new ValidateContext();
-
- /**
- * @throws java.lang.Exception
- */
- @Before
- public void setUp() throws Exception {
- CubeDesc desc2 = JsonUtil.readValue(getClass().getClassLoader().getResourceAsStream("data/TEST3_desc.json"), CubeDesc.class);
- this.cube = desc2;
-
- }
-
- @Test
- public void testOneMandatoryColumn() {
- IValidatorRule<CubeDesc> rule = new RowKeyAttrRule();
- rule.validate(cube, vContext);
- vContext.print(System.out);
- assertTrue("Failed to validate rowkey", vContext.getResults().length == 1);
- assertTrue("Failed to validate mandatory error", vContext.getResults()[0].getMessage().startsWith("Rowkey column"));
- }
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/test/java/org/apache/kylin/cube/common/BytesSplitterTest.java
----------------------------------------------------------------------
diff --git a/cube/src/test/java/org/apache/kylin/cube/common/BytesSplitterTest.java b/cube/src/test/java/org/apache/kylin/cube/common/BytesSplitterTest.java
deleted file mode 100644
index 3954ee7..0000000
--- a/cube/src/test/java/org/apache/kylin/cube/common/BytesSplitterTest.java
+++ /dev/null
@@ -1,54 +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.cube.common;
-
-import static org.junit.Assert.assertEquals;
-
-import org.apache.kylin.common.util.BytesSplitter;
-import org.junit.Test;
-
-/**
- * @author George Song (ysong1)
- *
- */
-public class BytesSplitterTest {
-
- @Test
- public void test() {
- BytesSplitter bytesSplitter = new BytesSplitter(10, 15);
- byte[] input = "2013-02-17Collectibles".getBytes();
- bytesSplitter.split(input, input.length, (byte) 127);
-
- assertEquals(2, bytesSplitter.getBufferSize());
- assertEquals("2013-02-17", new String(bytesSplitter.getSplitBuffers()[0].value, 0, bytesSplitter.getSplitBuffers()[0].length));
- assertEquals("Collectibles", new String(bytesSplitter.getSplitBuffers()[1].value, 0, bytesSplitter.getSplitBuffers()[1].length));
- }
-
- @Test
- public void testNullValue() {
- BytesSplitter bytesSplitter = new BytesSplitter(10, 15);
- byte[] input = "2013-02-17Collectibles".getBytes();
- bytesSplitter.split(input, input.length, (byte) 127);
-
- assertEquals(3, bytesSplitter.getBufferSize());
- assertEquals("2013-02-17", new String(bytesSplitter.getSplitBuffers()[0].value, 0, bytesSplitter.getSplitBuffers()[0].length));
- assertEquals("", new String(bytesSplitter.getSplitBuffers()[1].value, 0, bytesSplitter.getSplitBuffers()[1].length));
- assertEquals("Collectibles", new String(bytesSplitter.getSplitBuffers()[2].value, 0, bytesSplitter.getSplitBuffers()[2].length));
- }
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/test/java/org/apache/kylin/cube/common/RowKeySplitterTest.java
----------------------------------------------------------------------
diff --git a/cube/src/test/java/org/apache/kylin/cube/common/RowKeySplitterTest.java b/cube/src/test/java/org/apache/kylin/cube/common/RowKeySplitterTest.java
deleted file mode 100644
index 3615f5c..0000000
--- a/cube/src/test/java/org/apache/kylin/cube/common/RowKeySplitterTest.java
+++ /dev/null
@@ -1,71 +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.cube.common;
-
-import static org.junit.Assert.assertEquals;
-
-import org.apache.kylin.common.util.LocalFileMetadataTestCase;
-import org.apache.kylin.cube.CubeInstance;
-import org.apache.kylin.cube.CubeManager;
-import org.apache.kylin.metadata.MetadataManager;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * @author George Song (ysong1)
- *
- */
-public class RowKeySplitterTest extends LocalFileMetadataTestCase {
-
- @Before
- public void setUp() throws Exception {
- this.createTestMetadata();
- MetadataManager.clearCache();
- }
-
- @After
- public void after() throws Exception {
- this.cleanupTestMetadata();
- }
-
- @Test
- public void testWithSlr() throws Exception {
- CubeInstance cube = CubeManager.getInstance(getTestConfig()).getCube("TEST_KYLIN_CUBE_WITH_SLR_READY");
-
- RowKeySplitter rowKeySplitter = new RowKeySplitter(cube.getFirstSegment(), 10, 20);
- // base cuboid rowkey
- byte[] input = { 0, 0, 0, 0, 0, 0, 1, -1, 49, 48, 48, 48, 48, 48, 48, 48, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 11, 54, -105, 55, 13, 71, 114, 65, 66, 73, 78, 9, 9, 9, 9, 9, 9, 9, 9, 0, 10, 0 };
- rowKeySplitter.split(input, input.length);
-
- assertEquals(10, rowKeySplitter.getBufferSize());
- }
-
- @Test
- public void testWithoutSlr() throws Exception {
- CubeInstance cube = CubeManager.getInstance(getTestConfig()).getCube("TEST_KYLIN_CUBE_WITHOUT_SLR_READY");
-
- RowKeySplitter rowKeySplitter = new RowKeySplitter(cube.getFirstSegment(), 10, 20);
- // base cuboid rowkey
- byte[] input = { 0, 0, 0, 0, 0, 0, 0, -1, 11, 55, -13, 13, 22, 34, 121, 70, 80, 45, 71, 84, 67, 9, 9, 9, 9, 9, 9, 0, 10, 5 };
- rowKeySplitter.split(input, input.length);
-
- assertEquals(9, rowKeySplitter.getBufferSize());
- }
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/test/java/org/apache/kylin/cube/cuboid/CombinationTest.java
----------------------------------------------------------------------
diff --git a/cube/src/test/java/org/apache/kylin/cube/cuboid/CombinationTest.java b/cube/src/test/java/org/apache/kylin/cube/cuboid/CombinationTest.java
deleted file mode 100644
index 4c43a46..0000000
--- a/cube/src/test/java/org/apache/kylin/cube/cuboid/CombinationTest.java
+++ /dev/null
@@ -1,94 +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.cube.cuboid;
-
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-/**
- * @author xjiang
- *
- */
-public class CombinationTest {
-
- public int findSmallerSibling(long valueBits, long valueMask) {
- if ((valueBits | valueMask) != valueMask) {
- throw new IllegalArgumentException("Dismatch " + Long.toBinaryString(valueBits) + " from " + Long.toBinaryString(valueMask));
- }
-
- int n = Long.bitCount(valueMask);
- int k = Long.bitCount(valueBits);
- long[] bitMasks = new long[n];
- long leftBits = valueMask;
- for (int i = 0; i < n; i++) {
- long lowestBit = Long.lowestOneBit(leftBits);
- bitMasks[i] = lowestBit;
- leftBits &= ~lowestBit;
- }
- return combination(valueBits, bitMasks, 0, 0L, k);
- }
-
- private int combination(long valueBits, long[] bitMasks, int offset, long prefix, int k) {
- if (k == 0) {
- if (prefix < valueBits) {
- System.out.println(Long.toBinaryString(prefix));
- return 1;
- } else {
- return 0;
- }
- } else {
- int count = 0;
- for (int i = offset; i < bitMasks.length; i++) {
- long newPrefix = prefix | bitMasks[i];
- if (newPrefix < valueBits) {
- count += combination(valueBits, bitMasks, i + 1, newPrefix, k - 1);
- }
- }
- return count;
- }
- }
-
- private long calculateCombination(int n, int k) {
- if (n < k) {
- throw new IllegalArgumentException("N < K");
- }
- long res = 1;
- for (int i = n - k + 1; i <= n; i++) {
- res *= i;
- }
- for (int i = 1; i <= k; i++) {
- res /= i;
- }
- return res;
- }
-
- @Test
- public void testComb3() {
- long valueBits = 1 << 4 | 1 << 6 | 1 << 8;
- System.out.println("value = " + Long.toBinaryString(valueBits) + ", count = " + Long.bitCount(valueBits));
- long valueMask = (long) Math.pow(2, 10) - 1;
- System.out.println("mask = " + Long.toBinaryString(valueMask) + ", count = " + Long.bitCount(valueMask));
- System.out.println("************");
- int count = findSmallerSibling(valueBits, valueMask);
- System.out.println("smaller sibling count = " + count);
- int cnk = (int) calculateCombination(Long.bitCount(valueMask), Long.bitCount(valueBits));
- assertTrue(cnk > count);
- }
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/test/java/org/apache/kylin/cube/cuboid/CuboidSchedulerTest.java
----------------------------------------------------------------------
diff --git a/cube/src/test/java/org/apache/kylin/cube/cuboid/CuboidSchedulerTest.java b/cube/src/test/java/org/apache/kylin/cube/cuboid/CuboidSchedulerTest.java
deleted file mode 100644
index 52e34ec..0000000
--- a/cube/src/test/java/org/apache/kylin/cube/cuboid/CuboidSchedulerTest.java
+++ /dev/null
@@ -1,285 +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.cube.cuboid;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-
-import org.apache.kylin.common.util.LocalFileMetadataTestCase;
-import org.apache.kylin.cube.CubeDescManager;
-import org.apache.kylin.cube.model.CubeDesc;
-import org.apache.kylin.metadata.MetadataManager;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * @author George Song (ysong1)
- *
- */
-public class CuboidSchedulerTest extends LocalFileMetadataTestCase {
- @Before
- public void setUp() throws Exception {
- this.createTestMetadata();
- MetadataManager.clearCache();
- }
-
- @After
- public void after() throws Exception {
- this.cleanupTestMetadata();
- }
-
- static long toLong(String bin) {
- return Long.parseLong(bin, 2);
- }
-
- static String toString(long l) {
- return Long.toBinaryString(l);
- }
-
- static String toString(Collection<Long> cuboids) {
- StringBuilder buf = new StringBuilder();
- buf.append("[");
- for (Long l : cuboids) {
- if (buf.length() > 1)
- buf.append(",");
- buf.append(l).append("(").append(Long.toBinaryString(l)).append(")");
- }
- buf.append("]");
- return buf.toString();
- }
-
- private CubeDesc getTestKylinCubeWithoutSeller() {
- return getCubeDescManager().getCubeDesc("test_kylin_cube_without_slr_desc");
- }
-
- private CubeDesc getTestKylinCubeWithSeller() {
- return getCubeDescManager().getCubeDesc("test_kylin_cube_with_slr_desc");
- }
-
- private CubeDesc getTestKylinCubeWithoutSellerLeftJoin() {
- return getCubeDescManager().getCubeDesc("test_kylin_cube_without_slr_left_join_desc");
- }
-
- @Test
- public void testFindSmallerSibling1() {
- CubeDesc cube = getTestKylinCubeWithoutSeller();
- CuboidScheduler scheduler = new CuboidScheduler(cube);
-
- Collection<Long> siblings;
-
- siblings = scheduler.findSmallerSibling(255);
- assertEquals("[]", siblings.toString());
-
- siblings = scheduler.findSmallerSibling(133);
- assertEquals("[131]", siblings.toString());
-
- siblings = scheduler.findSmallerSibling(127);
- assertEquals("[]", siblings.toString());
-
- siblings = scheduler.findSmallerSibling(134);
- assertEquals("[131, 133]", sortToString(siblings));
-
- siblings = scheduler.findSmallerSibling(130);
- assertEquals("[129]", siblings.toString());
-
- siblings = scheduler.findSmallerSibling(5);
- assertEquals("[]", siblings.toString());
-
- siblings = scheduler.findSmallerSibling(135);
- assertEquals("[]", siblings.toString());
- }
-
- private void testSpanningAndGetParent(CuboidScheduler scheduler, CubeDesc cube, long[] cuboidIds) {
- for (long cuboidId : cuboidIds) {
- Collection<Long> spannings = scheduler.getSpanningCuboid(cuboidId);
- System.out.println("Spanning result for " + cuboidId + "(" + Long.toBinaryString(cuboidId) + "): " + toString(spannings));
-
- for (long child : spannings) {
- assertTrue(Cuboid.isValid(cube, child));
- }
- }
- }
-
- @Test
- public void testFindSmallerSibling2() {
- CubeDesc cube = getTestKylinCubeWithSeller();
- CuboidScheduler scheduler = new CuboidScheduler(cube);
-
- Collection<Long> siblings;
-
- siblings = scheduler.findSmallerSibling(511);
- assertEquals("[]", siblings.toString());
-
- siblings = scheduler.findSmallerSibling(toLong("110111111"));
- assertEquals("[383]", siblings.toString());
-
- siblings = scheduler.findSmallerSibling(toLong("101110111"));
- assertEquals("[319]", siblings.toString());
-
- siblings = scheduler.findSmallerSibling(toLong("111111000"));
- assertEquals("[]", siblings.toString());
-
- siblings = scheduler.findSmallerSibling(toLong("111111000"));
- assertEquals("[]", siblings.toString());
-
- siblings = scheduler.findSmallerSibling(toLong("110000000"));
- assertEquals("[288, 320]", sortToString(siblings));
- }
-
- @Test
- public void testGetSpanningCuboid2() {
- CubeDesc cube = getTestKylinCubeWithSeller();
- CuboidScheduler scheduler = new CuboidScheduler(cube);
-
- // generate 8d
- System.out.println("Spanning for 8D Cuboids");
- testSpanningAndGetParent(scheduler, cube, new long[] { 511 });
- // generate 7d
- System.out.println("Spanning for 7D Cuboids");
- testSpanningAndGetParent(scheduler, cube, new long[] { 504, 447, 503, 383 });
- // generate 6d
- System.out.println("Spanning for 6D Cuboids");
- testSpanningAndGetParent(scheduler, cube, new long[] { 440, 496, 376, 439, 487, 319, 375 });
- // generate 5d
- System.out.println("Spanning for 5D Cuboids");
- testSpanningAndGetParent(scheduler, cube, new long[] { 432, 480, 312, 368, 423, 455, 311, 359 });
- // generate 4d
- System.out.println("Spanning for 4D Cuboids");
- testSpanningAndGetParent(scheduler, cube, new long[] { 416, 448, 304, 352, 391, 295, 327 });
- // generate 3d
- System.out.println("Spanning for 3D Cuboids");
- testSpanningAndGetParent(scheduler, cube, new long[] { 384, 288, 320, 263 });
- // generate 2d
- // generate 1d
- // generate 0d
- }
-
- @Test
- public void testGetSpanningCuboid1() {
- CubeDesc cube = getTestKylinCubeWithoutSeller();
- CuboidScheduler scheduler = new CuboidScheduler(cube);
-
- long quiz = toLong("01100111");
- testSpanningAndGetParent(scheduler, cube, new long[] { quiz });
-
- // generate 7d
- System.out.println("Spanning for 7D Cuboids");
- testSpanningAndGetParent(scheduler, cube, new long[] { 255 });
- // generate 6d
- System.out.println("Spanning for 6D Cuboids");
- testSpanningAndGetParent(scheduler, cube, new long[] { 135, 251, 253, 254 });
- // generate 5d
- System.out.println("Spanning for 5D Cuboids");
- testSpanningAndGetParent(scheduler, cube, new long[] { 131, 133, 134, 249, 250, 252 });
- // generate 4d
- System.out.println("Spanning for 4D Cuboids");
- testSpanningAndGetParent(scheduler, cube, new long[] { 129, 130, 132, 248 });
- // generate 3d
- System.out.println("Spanning for 3D Cuboids");
- testSpanningAndGetParent(scheduler, cube, new long[] { 184, 240 });
- // generate 2d
- System.out.println("Spanning for 2D Cuboids");
- testSpanningAndGetParent(scheduler, cube, new long[] { 176, 224 });
- // generate 1d
- System.out.println("Spanning for 1D Cuboids");
- testSpanningAndGetParent(scheduler, cube, new long[] { 160, 192 });
- // generate 0d
- }
-
- @Test
- public void testGetSpanningCuboid() {
- CubeDesc cube = getTestKylinCubeWithoutSeller();
- CuboidScheduler scheduler = new CuboidScheduler(cube);
-
- Collection<Long> spnanningCuboids = scheduler.getSpanningCuboid(248);
-
- assertEquals("[]", spnanningCuboids.toString());
- }
-
- @Test
- public void testGetCardinality() {
- CubeDesc cube = getTestKylinCubeWithSeller();
- CuboidScheduler scheduler = new CuboidScheduler(cube);
-
- assertEquals(0, scheduler.getCardinality(0));
- assertEquals(7, scheduler.getCardinality(127));
- assertEquals(1, scheduler.getCardinality(1));
- assertEquals(1, scheduler.getCardinality(8));
- assertEquals(6, scheduler.getCardinality(126));
- }
-
- @Test
- public void testCuboidGeneration1() {
- CubeDesc cube = getTestKylinCubeWithoutSeller();
- CuboidCLI.simulateCuboidGeneration(cube);
- }
-
- @Test
- public void testCuboidGeneration2() {
- CubeDesc cube = getTestKylinCubeWithSeller();
- CuboidCLI.simulateCuboidGeneration(cube);
- }
-
- @Test
- public void testCuboidGeneration3() {
- CubeDesc cube = getTestKylinCubeWithoutSellerLeftJoin();
- CuboidCLI.simulateCuboidGeneration(cube);
- }
-
- @Test
- public void testCuboidCounts1() {
- CubeDesc cube = getTestKylinCubeWithoutSeller();
- int[] counts = CuboidCLI.calculateAllLevelCount(cube);
- printCount(counts);
- assertArrayEquals(new int[] { 1, 4, 6, 6, 4, 4, 2, 0 }, counts);
- }
-
- @Test
- public void testCuboidCounts2() {
- CubeDesc cube = getTestKylinCubeWithSeller();
- CuboidCLI.calculateAllLevelCount(cube);
- int[] counts = CuboidCLI.calculateAllLevelCount(cube);
- printCount(counts);
- assertArrayEquals(new int[] { 1, 4, 7, 8, 7, 4 }, counts);
- }
-
- private String sortToString(Collection<Long> longs) {
- ArrayList<Long> copy = new ArrayList<Long>(longs);
- Collections.sort(copy);
- return copy.toString();
- }
-
- public CubeDescManager getCubeDescManager() {
- return CubeDescManager.getInstance(getTestConfig());
- }
-
- private void printCount(int[] counts) {
- int sum = 0;
- for (int c : counts)
- sum += c;
- System.out.println(sum + " = " + Arrays.toString(counts));
- }
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/test/java/org/apache/kylin/cube/cuboid/CuboidTest.java
----------------------------------------------------------------------
diff --git a/cube/src/test/java/org/apache/kylin/cube/cuboid/CuboidTest.java b/cube/src/test/java/org/apache/kylin/cube/cuboid/CuboidTest.java
deleted file mode 100644
index 7109414..0000000
--- a/cube/src/test/java/org/apache/kylin/cube/cuboid/CuboidTest.java
+++ /dev/null
@@ -1,184 +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.cube.cuboid;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import org.apache.kylin.common.util.LocalFileMetadataTestCase;
-import org.apache.kylin.cube.CubeDescManager;
-import org.apache.kylin.cube.model.CubeDesc;
-import org.apache.kylin.metadata.MetadataManager;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * @author yangli9
- */
-public class CuboidTest extends LocalFileMetadataTestCase {
-
- private long toLong(String bin) {
- return Long.parseLong(bin, 2);
- }
-
- public CubeDescManager getCubeDescManager() {
- return CubeDescManager.getInstance(getTestConfig());
- }
-
- private CubeDesc getTestKylinCubeII() {
- return getCubeDescManager().getCubeDesc("test_kylin_ii");
- }
-
- private CubeDesc getTestKylinCubeWithoutSeller() {
- return getCubeDescManager().getCubeDesc("test_kylin_cube_without_slr_desc");
- }
-
- private CubeDesc getTestKylinCubeWithSeller() {
- return getCubeDescManager().getCubeDesc("test_kylin_cube_with_slr_desc");
- }
-
- @Before
- public void setUp() throws Exception {
- this.createTestMetadata();
- MetadataManager.clearCache();
- }
-
- @After
- public void after() throws Exception {
- this.cleanupTestMetadata();
- }
-
- @Test
- public void testIsValid() {
-
- CubeDesc cube = getTestKylinCubeWithSeller();
-
- // base
- assertEquals(false, Cuboid.isValid(cube, 0));
- assertEquals(true, Cuboid.isValid(cube, toLong("111111111")));
-
- // mandatory column
- assertEquals(false, Cuboid.isValid(cube, toLong("011111110")));
- assertEquals(false, Cuboid.isValid(cube, toLong("100000000")));
-
- // zero tail
- assertEquals(true, Cuboid.isValid(cube, toLong("111111000")));
-
- // aggregation group & zero tail
- assertEquals(true, Cuboid.isValid(cube, toLong("110000111")));
- assertEquals(true, Cuboid.isValid(cube, toLong("110111000")));
- assertEquals(true, Cuboid.isValid(cube, toLong("111110111")));
- assertEquals(false, Cuboid.isValid(cube, toLong("111110001")));
- assertEquals(false, Cuboid.isValid(cube, toLong("111110100")));
- assertEquals(false, Cuboid.isValid(cube, toLong("110000100")));
- }
-
- @Test
- public void testCuboid1() {
- CubeDesc cube = getTestKylinCubeWithoutSeller();
- Cuboid cuboid;
-
- cuboid = Cuboid.findById(cube, 0);
- assertEquals(toLong("10000001"), cuboid.getId());
-
- cuboid = Cuboid.findById(cube, 1);
- assertEquals(toLong("10000001"), cuboid.getId());
-
- cuboid = Cuboid.findById(cube, toLong("00000010"));
- assertEquals(toLong("10000010"), cuboid.getId());
-
- cuboid = Cuboid.findById(cube, toLong("00100000"));
- assertEquals(toLong("10100000"), cuboid.getId());
-
- cuboid = Cuboid.findById(cube, toLong("01001000"));
- assertEquals(toLong("11111000"), cuboid.getId());
-
- cuboid = Cuboid.findById(cube, toLong("01000111"));
- assertEquals(toLong("11111111"), cuboid.getId());
-
- cuboid = Cuboid.findById(cube, toLong("11111111"));
- assertEquals(toLong("11111111"), cuboid.getId());
- }
-
- @Test
- public void testIsValid2() {
- CubeDesc cube = getTestKylinCubeWithoutSeller();
- try {
- assertEquals(false, Cuboid.isValid(cube, toLong("111111111")));
- fail();
- } catch (IllegalArgumentException ex) {
- // expected
- }
-
- // base
- assertEquals(false, Cuboid.isValid(cube, 0));
- assertEquals(true, Cuboid.isValid(cube, toLong("11111111")));
-
- // aggregation group & zero tail
- assertEquals(true, Cuboid.isValid(cube, toLong("10000111")));
- assertEquals(false, Cuboid.isValid(cube, toLong("10001111")));
- assertEquals(false, Cuboid.isValid(cube, toLong("11001111")));
- assertEquals(true, Cuboid.isValid(cube, toLong("10000001")));
- assertEquals(true, Cuboid.isValid(cube, toLong("10000101")));
-
- // hierarchy
- assertEquals(true, Cuboid.isValid(cube, toLong("10100000")));
- assertEquals(true, Cuboid.isValid(cube, toLong("10110000")));
- assertEquals(true, Cuboid.isValid(cube, toLong("10111000")));
- assertEquals(false, Cuboid.isValid(cube, toLong("10001000")));
- assertEquals(false, Cuboid.isValid(cube, toLong("10011000")));
- }
-
- @Test
- public void testCuboid2() {
- CubeDesc cube = getTestKylinCubeWithSeller();
- Cuboid cuboid;
-
- cuboid = Cuboid.findById(cube, 0);
- assertEquals(toLong("100111000"), cuboid.getId());
-
- cuboid = Cuboid.findById(cube, 1);
- assertEquals(toLong("100000111"), cuboid.getId());
-
- cuboid = Cuboid.findById(cube, toLong("010"));
- assertEquals(toLong("100000111"), cuboid.getId());
-
- cuboid = Cuboid.findById(cube, toLong("0100000"));
- assertEquals(toLong("100100000"), cuboid.getId());
-
- cuboid = Cuboid.findById(cube, toLong("1001000"));
- assertEquals(toLong("101111000"), cuboid.getId());
-
- cuboid = Cuboid.findById(cube, toLong("1000111"));
- assertEquals(toLong("101000111"), cuboid.getId());
-
- cuboid = Cuboid.findById(cube, toLong("111111111"));
- assertEquals(toLong("111111111"), cuboid.getId());
- }
-
- public void testII() {
- CubeDesc cube = getTestKylinCubeII();
- assertEquals(toLong("111111111"), Cuboid.getBaseCuboidId(cube));
- assertEquals(true, Cuboid.isValid(cube, toLong("111111111")));
- assertEquals(false, Cuboid.isValid(cube, toLong("111111011")));
- assertEquals(false, Cuboid.isValid(cube, toLong("101011011")));
- assertEquals(false, Cuboid.isValid(cube, toLong("000000000")));
- }
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/6b6aa313/cube/src/test/java/org/apache/kylin/cube/kv/RowKeyDecoderTest.java
----------------------------------------------------------------------
diff --git a/cube/src/test/java/org/apache/kylin/cube/kv/RowKeyDecoderTest.java b/cube/src/test/java/org/apache/kylin/cube/kv/RowKeyDecoderTest.java
deleted file mode 100644
index 51743c0..0000000
--- a/cube/src/test/java/org/apache/kylin/cube/kv/RowKeyDecoderTest.java
+++ /dev/null
@@ -1,117 +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.cube.kv;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.IOException;
-import java.util.List;
-
-import org.apache.kylin.common.util.Bytes;
-import org.apache.kylin.common.util.LocalFileMetadataTestCase;
-import org.apache.kylin.cube.CubeInstance;
-import org.apache.kylin.cube.CubeManager;
-import org.apache.kylin.cube.cuboid.Cuboid;
-import org.apache.kylin.cube.model.CubeDesc;
-import org.apache.kylin.metadata.MetadataManager;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * @author George Song (ysong1)
- *
- */
-public class RowKeyDecoderTest extends LocalFileMetadataTestCase {
-
- @Before
- public void setUp() throws Exception {
- this.createTestMetadata();
- MetadataManager.clearCache();
- }
-
- @After
- public void after() throws Exception {
- this.cleanupTestMetadata();
- }
-
- @Test
- public void testDecodeWithoutSlr() throws Exception {
- CubeInstance cube = CubeManager.getInstance(getTestConfig()).getCube("TEST_KYLIN_CUBE_WITHOUT_SLR_READY");
-
- RowKeyDecoder rowKeyDecoder = new RowKeyDecoder(cube.getFirstSegment());
-
- byte[] key = { 0, 0, 0, 0, 0, 0, 0, -1, 11, 55, -13, 13, 22, 34, 121, 70, 80, 45, 71, 84, 67, 9, 9, 9, 9, 9, 9, 0, 10, 5 };
-
- rowKeyDecoder.decode(key);
- List<String> names = rowKeyDecoder.getNames(null);
- List<String> values = rowKeyDecoder.getValues();
-
- assertEquals("[CAL_DT, LEAF_CATEG_ID, META_CATEG_NAME, CATEG_LVL2_NAME, CATEG_LVL3_NAME, LSTG_FORMAT_NAME, LSTG_SITE_ID, SLR_SEGMENT_CD]", names.toString());
- assertEquals("[2012-12-15, 11848, Health & Beauty, Fragrances, Women, FP-GTC, 0, 15]", values.toString());
-
- }
-
- @Test
- public void testDecodeWithSlr() throws Exception {
- CubeInstance cube = CubeManager.getInstance(getTestConfig()).getCube("TEST_KYLIN_CUBE_WITH_SLR_READY");
-
- RowKeyDecoder rowKeyDecoder = new RowKeyDecoder(cube.getFirstSegment());
-
- byte[] key = { 0, 0, 0, 0, 0, 0, 1, -1, 49, 48, 48, 48, 48, 48, 48, 48, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 11, 54, -105, 55, 13, 71, 114, 65, 66, 73, 78, 9, 9, 9, 9, 9, 9, 9, 9, 0, 10, 0 };
-
- rowKeyDecoder.decode(key);
- List<String> names = rowKeyDecoder.getNames(null);
- List<String> values = rowKeyDecoder.getValues();
-
- assertEquals("[SELLER_ID, CAL_DT, LEAF_CATEG_ID, META_CATEG_NAME, CATEG_LVL2_NAME, CATEG_LVL3_NAME, LSTG_FORMAT_NAME, LSTG_SITE_ID, SLR_SEGMENT_CD]", names.toString());
- assertEquals("[10000000, 2012-01-02, 20213, Collectibles, Postcards, US StateCities & Towns, ABIN, 0, -99]", values.toString());
-
- }
-
- @Test
- public void testEncodeAndDecodeWithUtf8() throws IOException {
- CubeInstance cube = CubeManager.getInstance(getTestConfig()).getCube("TEST_KYLIN_CUBE_WITHOUT_SLR_READY");
- CubeDesc cubeDesc = cube.getDescriptor();
-
- byte[][] data = new byte[8][];
- data[0] = Bytes.toBytes("2012-12-15");
- data[1] = Bytes.toBytes("11848");
- data[2] = Bytes.toBytes("Health & Beauty");
- data[3] = Bytes.toBytes("Fragrances");
- data[4] = Bytes.toBytes("Women");
- data[5] = Bytes.toBytes("刊登格式测试");// UTF-8
- data[6] = Bytes.toBytes("0");
- data[7] = Bytes.toBytes("15");
-
- long baseCuboidId = Cuboid.getBaseCuboidId(cubeDesc);
- Cuboid baseCuboid = Cuboid.findById(cubeDesc, baseCuboidId);
- AbstractRowKeyEncoder rowKeyEncoder = AbstractRowKeyEncoder.createInstance(cube.getFirstSegment(), baseCuboid);
-
- byte[] encodedKey = rowKeyEncoder.encode(data);
- assertEquals(30, encodedKey.length);
-
- RowKeyDecoder rowKeyDecoder = new RowKeyDecoder(cube.getFirstSegment());
- rowKeyDecoder.decode(encodedKey);
- List<String> names = rowKeyDecoder.getNames(null);
- List<String> values = rowKeyDecoder.getValues();
- assertEquals("[CAL_DT, LEAF_CATEG_ID, META_CATEG_NAME, CATEG_LVL2_NAME, CATEG_LVL3_NAME, LSTG_FORMAT_NAME, LSTG_SITE_ID, SLR_SEGMENT_CD]", names.toString());
- assertEquals("[2012-12-15, 11848, Health & Beauty, Fragrances, Women, 刊登格式, 0, 15]", values.toString());
- }
-}