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 2017/08/01 02:33:55 UTC
[01/15] kylin git commit: minor, refine CreateFlatHiveTableStep
Repository: kylin
Updated Branches:
refs/heads/2.1.x ea4edd6a7 -> 91c08e8a8
minor, refine CreateFlatHiveTableStep
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/afd7e55c
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/afd7e55c
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/afd7e55c
Branch: refs/heads/2.1.x
Commit: afd7e55c5686325cbf3218ac3a0222e082838db6
Parents: e2bd2eb
Author: Cheng Wang <ch...@kyligence.io>
Authored: Tue Jul 25 18:25:21 2017 +0800
Committer: Cheng Wang <ch...@kyligence.io>
Committed: Tue Jul 25 18:33:07 2017 +0800
----------------------------------------------------------------------
.../java/org/apache/kylin/source/hive/CreateFlatHiveTableStep.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/afd7e55c/source-hive/src/main/java/org/apache/kylin/source/hive/CreateFlatHiveTableStep.java
----------------------------------------------------------------------
diff --git a/source-hive/src/main/java/org/apache/kylin/source/hive/CreateFlatHiveTableStep.java b/source-hive/src/main/java/org/apache/kylin/source/hive/CreateFlatHiveTableStep.java
index f28f3c7..dc85c52 100644
--- a/source-hive/src/main/java/org/apache/kylin/source/hive/CreateFlatHiveTableStep.java
+++ b/source-hive/src/main/java/org/apache/kylin/source/hive/CreateFlatHiveTableStep.java
@@ -38,7 +38,7 @@ import org.slf4j.LoggerFactory;
public class CreateFlatHiveTableStep extends AbstractExecutable {
private static final Logger logger = LoggerFactory.getLogger(CreateFlatHiveTableStep.class);
- private final PatternedLogger stepLogger = new PatternedLogger(logger);
+ protected final PatternedLogger stepLogger = new PatternedLogger(logger);
protected void createFlatHiveTable(KylinConfig config) throws IOException {
final HiveCmdBuilder hiveCmdBuilder = new HiveCmdBuilder();
[13/15] kylin git commit: minor,
fix the order of the parameters passing into the "doPushDownQuery()"
in KylinTestBase
Posted by li...@apache.org.
minor, fix the order of the parameters passing into the "doPushDownQuery()" in KylinTestBase
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/7369ee36
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/7369ee36
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/7369ee36
Branch: refs/heads/2.1.x
Commit: 7369ee36e094a2bf6dec9f0c95a9263c026c33c5
Parents: e21e86e
Author: Jiatao Tao <24...@qq.com>
Authored: Mon Jul 31 06:36:14 2017 -0500
Committer: GitHub <no...@github.com>
Committed: Mon Jul 31 06:36:14 2017 -0500
----------------------------------------------------------------------
kylin-it/src/test/java/org/apache/kylin/query/KylinTestBase.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/7369ee36/kylin-it/src/test/java/org/apache/kylin/query/KylinTestBase.java
----------------------------------------------------------------------
diff --git a/kylin-it/src/test/java/org/apache/kylin/query/KylinTestBase.java b/kylin-it/src/test/java/org/apache/kylin/query/KylinTestBase.java
index 0c6feb3..413177e 100644
--- a/kylin-it/src/test/java/org/apache/kylin/query/KylinTestBase.java
+++ b/kylin-it/src/test/java/org/apache/kylin/query/KylinTestBase.java
@@ -263,8 +263,8 @@ public class KylinTestBase {
} catch (SQLException sqlException) {
List<List<String>> results = Lists.newArrayList();
List<SelectedColumnMeta> columnMetas = Lists.newArrayList();
- boolean b = PushDownUtil.doPushDownQuery(ProjectInstance.DEFAULT_PROJECT_NAME, "DEFAULT", sql, results, columnMetas,
- sqlException);
+ boolean b = PushDownUtil.doPushDownQuery(ProjectInstance.DEFAULT_PROJECT_NAME, sql, "DEFAULT", results,
+ columnMetas, sqlException);
if (!b) {
throw sqlException;
}
[07/15] kylin git commit: Revert "#1276 loose global dict column
limit"
Posted by li...@apache.org.
Revert "#1276 loose global dict column limit"
This reverts commit e6f58d1b8129d3ff024e6cfc1462dccbb65a27d8.
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/625e706b
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/625e706b
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/625e706b
Branch: refs/heads/2.1.x
Commit: 625e706b73da56d5f4d303fad1d4c17fd769b96f
Parents: 68f2fc0
Author: Roger Shi <ro...@hotmail.com>
Authored: Fri Jul 28 13:39:09 2017 +0800
Committer: Roger Shi <ro...@hotmail.com>
Committed: Fri Jul 28 15:19:10 2017 +0800
----------------------------------------------------------------------
.../kylin/cube/model/validation/rule/DictionaryRule.java | 7 +++++++
.../cube/model/validation/rule/DictionaryRuleTest.java | 10 ++++++++--
2 files changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/625e706b/core-cube/src/main/java/org/apache/kylin/cube/model/validation/rule/DictionaryRule.java
----------------------------------------------------------------------
diff --git a/core-cube/src/main/java/org/apache/kylin/cube/model/validation/rule/DictionaryRule.java b/core-cube/src/main/java/org/apache/kylin/cube/model/validation/rule/DictionaryRule.java
index 548586f..8da3ca0 100644
--- a/core-cube/src/main/java/org/apache/kylin/cube/model/validation/rule/DictionaryRule.java
+++ b/core-cube/src/main/java/org/apache/kylin/cube/model/validation/rule/DictionaryRule.java
@@ -29,6 +29,7 @@ import org.apache.kylin.cube.model.DictionaryDesc;
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.dict.GlobalDictionaryBuilder;
import org.apache.kylin.metadata.model.TblColRef;
/**
@@ -45,6 +46,7 @@ public class DictionaryRule implements IValidatorRule<CubeDesc> {
static final String ERROR_REUSE_BUILDER_BOTH_SET = "REUSE and BUILDER both set on dictionary for column: ";
static final String ERROR_REUSE_BUILDER_BOTH_EMPTY = "REUSE and BUILDER both empty on dictionary for column: ";
static final String ERROR_TRANSITIVE_REUSE = "Transitive REUSE is not allowed for dictionary: ";
+ static final String ERROR_GLOBAL_DICTIONNARY_ONLY_MEASURE = "Global dictionary couldn't be used for dimension column: ";
@Override
public void validate(CubeDesc cubeDesc, ValidateContext context) {
@@ -80,6 +82,11 @@ public class DictionaryRule implements IValidatorRule<CubeDesc> {
return;
}
+ if (StringUtils.isNotEmpty(builderClass) && builderClass.equalsIgnoreCase(GlobalDictionaryBuilder.class.getName()) && dimensionColumns.contains(dictCol)) {
+ context.addResult(ResultLevel.ERROR, ERROR_GLOBAL_DICTIONNARY_ONLY_MEASURE + dictCol);
+ return;
+ }
+
if (reuseCol != null) {
reuseDictionaries.add(dictDesc);
} else {
http://git-wip-us.apache.org/repos/asf/kylin/blob/625e706b/core-cube/src/test/java/org/apache/kylin/cube/model/validation/rule/DictionaryRuleTest.java
----------------------------------------------------------------------
diff --git a/core-cube/src/test/java/org/apache/kylin/cube/model/validation/rule/DictionaryRuleTest.java b/core-cube/src/test/java/org/apache/kylin/cube/model/validation/rule/DictionaryRuleTest.java
index 0f11f4b..0dd9b76 100644
--- a/core-cube/src/test/java/org/apache/kylin/cube/model/validation/rule/DictionaryRuleTest.java
+++ b/core-cube/src/test/java/org/apache/kylin/cube/model/validation/rule/DictionaryRuleTest.java
@@ -19,6 +19,7 @@
package org.apache.kylin.cube.model.validation.rule;
import static org.apache.kylin.cube.model.validation.rule.DictionaryRule.ERROR_DUPLICATE_DICTIONARY_COLUMN;
+import static org.apache.kylin.cube.model.validation.rule.DictionaryRule.ERROR_GLOBAL_DICTIONNARY_ONLY_MEASURE;
import static org.apache.kylin.cube.model.validation.rule.DictionaryRule.ERROR_REUSE_BUILDER_BOTH_EMPTY;
import static org.apache.kylin.cube.model.validation.rule.DictionaryRule.ERROR_REUSE_BUILDER_BOTH_SET;
import static org.apache.kylin.cube.model.validation.rule.DictionaryRule.ERROR_TRANSITIVE_REUSE;
@@ -29,6 +30,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
+import com.google.common.collect.Lists;
import org.apache.kylin.common.KylinConfig;
import org.apache.kylin.common.util.JsonUtil;
import org.apache.kylin.common.util.LocalFileMetadataTestCase;
@@ -40,8 +42,6 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import com.google.common.collect.Lists;
-
public class DictionaryRuleTest extends LocalFileMetadataTestCase {
private static KylinConfig config;
@@ -96,6 +96,12 @@ public class DictionaryRuleTest extends LocalFileMetadataTestCase {
}
@Test
+ public void testBadDesc5() throws IOException {
+ testDictionaryDesc(ERROR_GLOBAL_DICTIONNARY_ONLY_MEASURE,
+ DictionaryDesc.create("CATEG_LVL2_NAME", null, GlobalDictionaryBuilder.class.getName()));
+ }
+
+ @Test
public void testGoodDesc2() throws IOException {
testDictionaryDesc(null, DictionaryDesc.create("SELLER_ID", null, GlobalDictionaryBuilder.class.getName()));
}
[10/15] kylin git commit: update shade plugin version and correct
shade name for storage-parquet-protocol
Posted by li...@apache.org.
update shade plugin version and correct shade name for storage-parquet-protocol
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/b9627213
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/b9627213
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/b9627213
Branch: refs/heads/2.1.x
Commit: b9627213d06586940b6b4fb4f4024cfc99a16ef9
Parents: f03b81e
Author: Hongbin Ma <ma...@apache.org>
Authored: Fri Jul 28 17:45:47 2017 +0800
Committer: Hongbin Ma <ma...@apache.org>
Committed: Mon Jul 31 15:21:24 2017 +0800
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/b9627213/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 7181309..b6f891d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -940,7 +940,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
- <version>2.4.3</version>
+ <version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
[15/15] kylin git commit: Merge commit
'ea4edd6a76bb0cb176dbc8e35851c783d7210d04' into kap-2.4.x
Posted by li...@apache.org.
Merge commit 'ea4edd6a76bb0cb176dbc8e35851c783d7210d04' into kap-2.4.x
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/91c08e8a
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/91c08e8a
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/91c08e8a
Branch: refs/heads/2.1.x
Commit: 91c08e8a8336284c6ed92f03e17c5eed9f2fe8d0
Parents: e164b4a ea4edd6
Author: Hongbin Ma <ma...@apache.org>
Authored: Tue Aug 1 10:32:25 2017 +0800
Committer: Hongbin Ma <ma...@apache.org>
Committed: Tue Aug 1 10:32:25 2017 +0800
----------------------------------------------------------------------
.../apache/kylin/metadata/model/TableDesc.java | 3 ---
.../kylin/engine/mr/common/HadoopCmdOutput.java | 17 +++++++++--------
.../org/apache/kylin/query/util/PushDownUtil.java | 2 +-
webapp/app/js/controllers/cubeMeasures.js | 18 +++++++++++-------
webapp/app/partials/cubeDesigner/measures.html | 5 ++---
webapp/app/partials/cubes/cube_detail.html | 4 ++--
6 files changed, 25 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/91c08e8a/core-metadata/src/main/java/org/apache/kylin/metadata/model/TableDesc.java
----------------------------------------------------------------------
diff --cc core-metadata/src/main/java/org/apache/kylin/metadata/model/TableDesc.java
index a2a2c24,d3543dd..989f47b
--- a/core-metadata/src/main/java/org/apache/kylin/metadata/model/TableDesc.java
+++ b/core-metadata/src/main/java/org/apache/kylin/metadata/model/TableDesc.java
@@@ -63,18 -63,18 +63,15 @@@ public class TableDesc extends RootPers
public TableDesc(TableDesc other) {
this.uuid = other.uuid;
this.lastModified = other.lastModified;
-
-
this.name = other.name;
this.sourceType = other.sourceType;
this.tableType = other.tableType;
this.dataGen = other.dataGen;
-
-
this.columns = new ColumnDesc[other.columns.length];
for (int i = 0; i < other.columns.length; i++) {
this.columns[i] = new ColumnDesc(other.columns[i]);
this.columns[i].init(this);
}
-
-
this.database.setName(other.getDatabase());
this.identity = other.identity;
}
http://git-wip-us.apache.org/repos/asf/kylin/blob/91c08e8a/query/src/main/java/org/apache/kylin/query/util/PushDownUtil.java
----------------------------------------------------------------------
diff --cc query/src/main/java/org/apache/kylin/query/util/PushDownUtil.java
index f496626,0000000..3edd899
mode 100644,000000..100644
--- a/query/src/main/java/org/apache/kylin/query/util/PushDownUtil.java
+++ b/query/src/main/java/org/apache/kylin/query/util/PushDownUtil.java
@@@ -1,294 -1,0 +1,294 @@@
+/*
+ * 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.query.util;
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.calcite.sql.SqlBasicCall;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlDataTypeSpec;
+import org.apache.calcite.sql.SqlDynamicParam;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlIntervalQualifier;
+import org.apache.calcite.sql.SqlJoin;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlNodeList;
+import org.apache.calcite.sql.util.SqlVisitor;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.text.StrBuilder;
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.commons.lang3.tuple.Triple;
+import org.apache.kylin.common.KylinConfig;
+import org.apache.kylin.common.util.ClassUtil;
+import org.apache.kylin.metadata.MetadataManager;
+import org.apache.kylin.metadata.model.ComputedColumnDesc;
+import org.apache.kylin.metadata.model.DataModelDesc;
+import org.apache.kylin.metadata.model.tool.CalciteParser;
+import org.apache.kylin.metadata.querymeta.SelectedColumnMeta;
+import org.apache.kylin.query.routing.NoRealizationFoundException;
+import org.apache.kylin.source.adhocquery.IPushDownConverter;
+import org.apache.kylin.source.adhocquery.IPushDownRunner;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+
+public class PushDownUtil {
+ private static final Logger logger = LoggerFactory.getLogger(PushDownUtil.class);
+
+ public static boolean doPushDownQuery(String project, String sql, String schema, List<List<String>> results,
+ List<SelectedColumnMeta> columnMetas, SQLException sqlException) throws Exception {
+
+ KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
+ if (!kylinConfig.isPushDownEnabled()) {
+ return false;
+ }
+
+ Throwable rootCause = ExceptionUtils.getRootCause(sqlException);
+ boolean isExpectedCause = rootCause != null && (rootCause.getClass().equals(NoRealizationFoundException.class));
+
+ if (isExpectedCause) {
+ logger.info("Query failed to utilize pre-calculation, routing to other engines", sqlException);
+ IPushDownRunner runner = (IPushDownRunner) ClassUtil.newInstance(kylinConfig.getPushDownRunnerClassName());
+ IPushDownConverter converter = (IPushDownConverter) ClassUtil
+ .newInstance(kylinConfig.getPushDownConverterClassName());
+
+ runner.init(kylinConfig);
+
+ logger.debug("Query pushdown runner {}", runner);
+
+ String expandCC = restoreComputedColumnToExpr(sql, project);
+ if (!StringUtils.equals(expandCC, sql)) {
+ logger.info("computed column in sql is expanded to: " + expandCC);
+ }
+ if (schema != null && !schema.equals("DEFAULT")) {
+ expandCC = schemaCompletion(expandCC, schema);
+ }
+ String adhocSql = converter.convert(expandCC);
+ if (!adhocSql.equals(expandCC)) {
+ logger.info("the query is converted to {} according to kylin.query.pushdown.converter-class-name",
+ adhocSql);
+ }
+
+ runner.executeQuery(adhocSql, results, columnMetas);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ static String schemaCompletion(String inputSql, String schema) {
+ if (inputSql == null || inputSql.equals("")) {
+ return "";
+ }
+ SqlNode fromNode = CalciteParser.getFromNode(inputSql);
+
+ // get all table node that don't have schema by visitor pattern
+ FromTablesVisitor ftv = new FromTablesVisitor();
+ fromNode.accept(ftv);
+ List<SqlNode> tablesWithoutSchema = ftv.getTablesWithoutSchema();
+
+ List<Pair<Integer, Integer>> tablesPos = new ArrayList<>();
+ for (SqlNode tables : tablesWithoutSchema) {
+ tablesPos.add(CalciteParser.getReplacePos(tables, inputSql));
+ }
+
+ // make the behind position in the front of the list, so that the front position will not be affected when replaced
+ Collections.sort(tablesPos);
+ Collections.reverse(tablesPos);
+
+ StrBuilder afterConvert = new StrBuilder(inputSql);
+ for (Pair<Integer, Integer> pos : tablesPos) {
+ String tableWithSchema = schema + "." + inputSql.substring(pos.getLeft(), pos.getRight());
+ afterConvert.replace(pos.getLeft(), pos.getRight(), tableWithSchema);
+ }
+ return afterConvert.toString();
+ }
+
+ private final static Pattern identifierInSqlPattern = Pattern.compile(
+ //find pattern like "table"."column" or "column"
+ "((?<![\\p{L}_0-9\\.\\\"])(\\\"[\\p{L}_0-9]+\\\"\\.)?(\\\"[\\p{L}_0-9]+\\\")(?![\\p{L}_0-9\\.\\\"]))" + "|"
+ //find pattern like table.column or column
+ + "((?<![\\p{L}_0-9\\.\\\"])([\\p{L}_0-9]+\\.)?([\\p{L}_0-9]+)(?![\\p{L}_0-9\\.\\\"]))");
+
+ private final static Pattern identifierInExprPattern = Pattern.compile(
+ // a.b.c
+ "((?<![\\p{L}_0-9\\.\\\"])([\\p{L}_0-9]+\\.)([\\p{L}_0-9]+\\.)([\\p{L}_0-9]+)(?![\\p{L}_0-9\\.\\\"]))");
+
+ private final static Pattern endWithAsPattern = Pattern.compile("\\s+as\\s+$", Pattern.CASE_INSENSITIVE);
+
+ public static String restoreComputedColumnToExpr(String beforeSql, String project) {
+ final MetadataManager metadataManager = MetadataManager.getInstance(KylinConfig.getInstanceFromEnv());
+ List<DataModelDesc> dataModelDescs = metadataManager.getModels(project);
+
+ String afterSql = beforeSql;
+ for (DataModelDesc dataModelDesc : dataModelDescs) {
+ for (ComputedColumnDesc computedColumnDesc : dataModelDesc.getComputedColumnDescs()) {
+ afterSql = restoreComputedColumnToExpr(afterSql, computedColumnDesc);
+ }
+ }
+ return afterSql;
+ }
+
+ static String restoreComputedColumnToExpr(String sql, ComputedColumnDesc computedColumnDesc) {
+
+ String ccName = computedColumnDesc.getColumnName();
+ List<Triple<Integer, Integer, String>> replacements = Lists.newArrayList();
+ Matcher matcher = identifierInSqlPattern.matcher(sql);
+
+ while (matcher.find()) {
+ if (matcher.group(1) != null) { //with quote case: "TABLE"."COLUMN"
+
+ String quotedColumnName = matcher.group(3);
+ Preconditions.checkNotNull(quotedColumnName);
+ String columnName = StringUtils.strip(quotedColumnName, "\"");
+ if (!columnName.equalsIgnoreCase(ccName)) {
+ continue;
+ }
+
+ if (matcher.group(2) != null) { // table name exist
+ String quotedTableAlias = StringUtils.strip(matcher.group(2), ".");
+ String tableAlias = StringUtils.strip(quotedTableAlias, "\"");
+ replacements.add(Triple.of(matcher.start(1), matcher.end(1),
+ replaceIdentifierInExpr(computedColumnDesc.getExpression(), tableAlias, true)));
+ } else { //only column
+ if (endWithAsPattern.matcher(sql.substring(0, matcher.start(1))).find()) {
+ //select DEAL_AMOUNT as "deal_amount" case
+ continue;
+ }
+ replacements.add(Triple.of(matcher.start(1), matcher.end(1),
+ replaceIdentifierInExpr(computedColumnDesc.getExpression(), null, true)));
+ }
+ } else if (matcher.group(4) != null) { //without quote case: table.column or simply column
+ String columnName = matcher.group(6);
+ Preconditions.checkNotNull(columnName);
+ if (!columnName.equalsIgnoreCase(ccName)) {
+ continue;
+ }
+
+ if (matcher.group(5) != null) { //table name exist
+ String tableAlias = StringUtils.strip(matcher.group(5), ".");
+ replacements.add(Triple.of(matcher.start(4), matcher.end(4),
+ replaceIdentifierInExpr(computedColumnDesc.getExpression(), tableAlias, false)));
+
+ } else { //only column
+ if (endWithAsPattern.matcher(sql.substring(0, matcher.start(4))).find()) {
+ //select DEAL_AMOUNT as deal_amount case
+ continue;
+ }
+ replacements.add(Triple.of(matcher.start(4), matcher.end(4),
+ replaceIdentifierInExpr(computedColumnDesc.getExpression(), null, false)));
+ }
+ }
+ }
+
+ Collections.reverse(replacements);
+ for (Triple<Integer, Integer, String> triple : replacements) {
+ sql = sql.substring(0, triple.getLeft()) + "(" + triple.getRight() + ")"
+ + sql.substring(triple.getMiddle());
+ }
+ return sql;
+ }
+
+ static String replaceIdentifierInExpr(String expr, String tableAlias, boolean quoted) {
+ if (tableAlias == null) {
+ return expr;
+ }
+
+ return CalciteParser.insertAliasInExpr(expr, tableAlias);
+ }
+}
+
+/**
+ * Created by jiatao.tao
+ * Get all the tables from "FROM" clause that without schema
+ */
+class FromTablesVisitor implements SqlVisitor<SqlNode> {
+ private List<SqlNode> tables;
+
+ FromTablesVisitor() {
+ this.tables = new ArrayList<>();
+ }
+
+ List<SqlNode> getTablesWithoutSchema() {
+ return tables;
+ }
+
+ @Override
+ public SqlNode visit(SqlNodeList nodeList) {
+ return null;
+ }
+
+ @Override
+ public SqlNode visit(SqlLiteral literal) {
+ return null;
+ }
+
+ @Override
+ public SqlNode visit(SqlCall call) {
+ if (call instanceof SqlBasicCall) {
+ SqlBasicCall node = (SqlBasicCall) call;
+ node.getOperands()[0].accept(this);
+ return null;
+ }
+ if (call instanceof SqlJoin) {
+ SqlJoin node = (SqlJoin) call;
+ node.getLeft().accept(this);
+ node.getRight().accept(this);
+ return null;
+ }
+ for (SqlNode operand : call.getOperandList()) {
+ if (operand != null) {
+ operand.accept(this);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public SqlNode visit(SqlIdentifier id) {
+ if (id.names.size() == 1) {
+ tables.add(id);
+ }
+ return null;
+ }
+
+ @Override
+ public SqlNode visit(SqlDataTypeSpec type) {
+ return null;
+ }
+
+ @Override
+ public SqlNode visit(SqlDynamicParam param) {
+ return null;
+ }
+
+ @Override
+ public SqlNode visit(SqlIntervalQualifier intervalQualifier) {
+ return null;
+ }
- }
++}
[06/15] kylin git commit: #1710 fix UT
Posted by li...@apache.org.
#1710 fix UT
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/68f2fc06
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/68f2fc06
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/68f2fc06
Branch: refs/heads/2.1.x
Commit: 68f2fc0618184f48fd0eb14525cc5b63ee0d911d
Parents: fb39c9d
Author: Hongbin Ma <ma...@apache.org>
Authored: Thu Jul 27 18:42:01 2017 +0800
Committer: Hongbin Ma <ma...@apache.org>
Committed: Thu Jul 27 18:47:06 2017 +0800
----------------------------------------------------------------------
.../test/java/org/apache/kylin/rest/service/ModelServiceTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/68f2fc06/server/src/test/java/org/apache/kylin/rest/service/ModelServiceTest.java
----------------------------------------------------------------------
diff --git a/server/src/test/java/org/apache/kylin/rest/service/ModelServiceTest.java b/server/src/test/java/org/apache/kylin/rest/service/ModelServiceTest.java
index b8633fb..756454a 100644
--- a/server/src/test/java/org/apache/kylin/rest/service/ModelServiceTest.java
+++ b/server/src/test/java/org/apache/kylin/rest/service/ModelServiceTest.java
@@ -81,7 +81,7 @@ public class ModelServiceTest extends ServiceTestBase {
@Test
public void testFailureModelUpdateDueToComputedColumnConflict() throws IOException, JobException, NoSuchFieldException, IllegalAccessException {
expectedEx.expect(IllegalArgumentException.class);
- expectedEx.expectMessage("Computed column named DEFAULT.TEST_KYLIN_FACT.DEAL_AMOUNT is defined differently in model ci_inner_join_model");
+ expectedEx.expectMessage("Column name for computed column DEFAULT.TEST_KYLIN_FACT.DEAL_AMOUNT is already used in model ci_inner_join_model, you should apply the same expression ' PRICE * ITEM_COUNT ' here, or use a different column name.");
List<DataModelDesc> dataModelDescs = modelService.listAllModels("ci_left_join_model", "default", true);
Assert.assertTrue(dataModelDescs.size() == 1);
[04/15] kylin git commit: #1710 refine Computed Column duplicate
check logic and error message
Posted by li...@apache.org.
#1710 refine Computed Column duplicate check logic and error message
* #1710 refine Computed Column duplicate check logic and error message
* Minor revision for error message expression
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/9cd49dcc
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/9cd49dcc
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/9cd49dcc
Branch: refs/heads/2.1.x
Commit: 9cd49dcca47e3fc4b807f867a846e0848643519e
Parents: e2a0f48
Author: Hongbin Ma <ma...@kyligence.io>
Authored: Thu Jul 27 10:38:44 2017 +0800
Committer: Hongbin Ma <ma...@apache.org>
Committed: Thu Jul 27 10:40:53 2017 +0800
----------------------------------------------------------------------
.../apache/kylin/metadata/model/DataModelDesc.java | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/9cd49dcc/core-metadata/src/main/java/org/apache/kylin/metadata/model/DataModelDesc.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/main/java/org/apache/kylin/metadata/model/DataModelDesc.java b/core-metadata/src/main/java/org/apache/kylin/metadata/model/DataModelDesc.java
index bc35e2a..dc2f301 100644
--- a/core-metadata/src/main/java/org/apache/kylin/metadata/model/DataModelDesc.java
+++ b/core-metadata/src/main/java/org/apache/kylin/metadata/model/DataModelDesc.java
@@ -495,17 +495,17 @@ public class DataModelDesc extends RootPersistentEntity {
DataModelDesc dataModelDesc = pair.getSecond();
ComputedColumnDesc cc = pair.getFirst();
- if (StringUtils.equals(cc.getFullName(), newCCName) && !(cc.equals(newCC))) {
- throw new IllegalArgumentException(
- String.format("Computed column named %s is defined differently in model %s", newCCName,
- dataModelDesc.getName()));
+ if (StringUtils.equalsIgnoreCase(cc.getFullName(), newCCName) && !(cc.equals(newCC))) {
+ throw new IllegalArgumentException(String.format(
+ "Column name for computed column %s is already used in model %s, you should apply the same expression ' %s ' here, or use a different column name.",
+ newCCName, dataModelDesc.getName(), cc.getExpression()));
}
if (isTwoCCDefinitionEquals(cc.getExpression(), newCC.getExpression())
- && !StringUtils.equals(cc.getColumnName(), newCCColumnName)) {
+ && !StringUtils.equalsIgnoreCase(cc.getColumnName(), newCCColumnName)) {
throw new IllegalArgumentException(String.format(
- "Duplicate expression of %s with computed column %s in model %s, keep same computed column name could suppress this",
- newCCColumnName, cc.getColumnName(), dataModelDesc.getName()));
+ "Expression for computed column %s is already used in model %s, you should use the same column name with ' %s ' .",
+ newCCName, dataModelDesc.getName(), cc.getColumnName()));
}
}
existingCCs.add(Pair.newPair(newCC, this));
[03/15] kylin git commit: #918 provided API to get license and upload
license
Posted by li...@apache.org.
#918 provided API to get license and upload license
#918 add license
#918 remove check license
#918
non-sec
non-sec
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/e2a0f488
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/e2a0f488
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/e2a0f488
Branch: refs/heads/2.1.x
Commit: e2a0f4882b756600ebbed0d9185337c9c549f99b
Parents: 016a57a
Author: Hongbin Ma <ma...@apache.org>
Authored: Thu Jul 20 17:45:27 2017 +0800
Committer: Hongbin Ma <ma...@apache.org>
Committed: Wed Jul 26 12:41:31 2017 +0800
----------------------------------------------------------------------
pom.xml | 6 ++++++
1 file changed, 6 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/e2a0f488/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index b4dd685..7181309 100644
--- a/pom.xml
+++ b/pom.xml
@@ -79,6 +79,7 @@
<commons-cli.version>1.2</commons-cli.version>
<commons-lang.version>2.6</commons-lang.version>
<commons-io.version>2.4</commons-io.version>
+ <commons-upload.version>1.3.1</commons-upload.version>
<commons-math3.version>3.1.1</commons-math3.version>
<commons-collections.version>3.2.2</commons-collections.version>
@@ -472,6 +473,11 @@
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>commons-fileupload</groupId>
+ <artifactId>commons-fileupload</artifactId>
+ <version>${commons-upload.version}</version>
+ </dependency>
+ <dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>${commons-collections.version}</version>
[08/15] kylin git commit: KYLIN-2758 Complete input SQL's default
database name when the query is entering query pushdown engine
Posted by li...@apache.org.
KYLIN-2758 Complete input SQL's default database name when the query is entering query pushdown engine
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/bc347b7b
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/bc347b7b
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/bc347b7b
Branch: refs/heads/2.1.x
Commit: bc347b7b213e881b689a813f220390716e9b04b6
Parents: 625e706
Author: Jiatao Tao <24...@qq.com>
Authored: Fri Jul 28 03:29:54 2017 -0500
Committer: GitHub <no...@github.com>
Committed: Fri Jul 28 03:29:54 2017 -0500
----------------------------------------------------------------------
.../metadata/model/tool/CalciteParser.java | 13 +
.../org/apache/kylin/query/KylinTestBase.java | 4 +-
query/pom.xml | 7 +
.../apache/kylin/query/util/PushDownUtil.java | 294 +++++++++++++++++++
.../kylin/query/util/PushDownUtilTest.java | 163 ++++++++++
.../apache/kylin/rest/service/QueryService.java | 4 +-
.../apache/kylin/rest/util/PushDownUtil.java | 180 ------------
.../kylin/rest/util/PushDownUtilTest.java | 94 ------
8 files changed, 481 insertions(+), 278 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/bc347b7b/core-metadata/src/main/java/org/apache/kylin/metadata/model/tool/CalciteParser.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/main/java/org/apache/kylin/metadata/model/tool/CalciteParser.java b/core-metadata/src/main/java/org/apache/kylin/metadata/model/tool/CalciteParser.java
index 5352708..a48abae 100644
--- a/core-metadata/src/main/java/org/apache/kylin/metadata/model/tool/CalciteParser.java
+++ b/core-metadata/src/main/java/org/apache/kylin/metadata/model/tool/CalciteParser.java
@@ -68,6 +68,19 @@ public class CalciteParser {
}
+ public static SqlNode getFromNode(String sql) {
+ //When the sql have limit clause, calcite will parse it as a SqlOrder Object.
+ sql = sql.split("LIMIT")[0];
+ SqlNode fromNode = null;
+ try {
+ fromNode = ((SqlSelect) (CalciteParser.parse(sql))).getFrom();
+ } catch (SqlParseException e) {
+ throw new RuntimeException("Failed to parse expression \'" + sql
+ + "\', please make sure the expression is valid");
+ }
+ return fromNode;
+ }
+
public static boolean isNodeEqual(SqlNode node0, SqlNode node1) {
if (node0 == null) {
return node1 == null;
http://git-wip-us.apache.org/repos/asf/kylin/blob/bc347b7b/kylin-it/src/test/java/org/apache/kylin/query/KylinTestBase.java
----------------------------------------------------------------------
diff --git a/kylin-it/src/test/java/org/apache/kylin/query/KylinTestBase.java b/kylin-it/src/test/java/org/apache/kylin/query/KylinTestBase.java
index e1d4a44..0c6feb3 100644
--- a/kylin-it/src/test/java/org/apache/kylin/query/KylinTestBase.java
+++ b/kylin-it/src/test/java/org/apache/kylin/query/KylinTestBase.java
@@ -51,7 +51,7 @@ import org.apache.kylin.metadata.project.ProjectInstance;
import org.apache.kylin.metadata.querymeta.SelectedColumnMeta;
import org.apache.kylin.query.relnode.OLAPContext;
import org.apache.kylin.query.routing.rules.RemoveBlackoutRealizationsRule;
-import org.apache.kylin.rest.util.PushDownUtil;
+import org.apache.kylin.query.util.PushDownUtil;
import org.dbunit.DatabaseUnitException;
import org.dbunit.database.DatabaseConfig;
import org.dbunit.database.DatabaseConnection;
@@ -263,7 +263,7 @@ public class KylinTestBase {
} catch (SQLException sqlException) {
List<List<String>> results = Lists.newArrayList();
List<SelectedColumnMeta> columnMetas = Lists.newArrayList();
- boolean b = PushDownUtil.doPushDownQuery(ProjectInstance.DEFAULT_PROJECT_NAME, sql, results, columnMetas,
+ boolean b = PushDownUtil.doPushDownQuery(ProjectInstance.DEFAULT_PROJECT_NAME, "DEFAULT", sql, results, columnMetas,
sqlException);
if (!b) {
throw sqlException;
http://git-wip-us.apache.org/repos/asf/kylin/blob/bc347b7b/query/pom.xml
----------------------------------------------------------------------
diff --git a/query/pom.xml b/query/pom.xml
index 941eb8a..24c63f9 100644
--- a/query/pom.xml
+++ b/query/pom.xml
@@ -70,5 +70,12 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ <!--MRUnit relies on older version of mockito, so cannot manage it globally-->
+ <version>${mockito.version}</version>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/kylin/blob/bc347b7b/query/src/main/java/org/apache/kylin/query/util/PushDownUtil.java
----------------------------------------------------------------------
diff --git a/query/src/main/java/org/apache/kylin/query/util/PushDownUtil.java b/query/src/main/java/org/apache/kylin/query/util/PushDownUtil.java
new file mode 100644
index 0000000..f496626
--- /dev/null
+++ b/query/src/main/java/org/apache/kylin/query/util/PushDownUtil.java
@@ -0,0 +1,294 @@
+/*
+ * 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.query.util;
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.calcite.sql.SqlBasicCall;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlDataTypeSpec;
+import org.apache.calcite.sql.SqlDynamicParam;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlIntervalQualifier;
+import org.apache.calcite.sql.SqlJoin;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlNodeList;
+import org.apache.calcite.sql.util.SqlVisitor;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.text.StrBuilder;
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.commons.lang3.tuple.Triple;
+import org.apache.kylin.common.KylinConfig;
+import org.apache.kylin.common.util.ClassUtil;
+import org.apache.kylin.metadata.MetadataManager;
+import org.apache.kylin.metadata.model.ComputedColumnDesc;
+import org.apache.kylin.metadata.model.DataModelDesc;
+import org.apache.kylin.metadata.model.tool.CalciteParser;
+import org.apache.kylin.metadata.querymeta.SelectedColumnMeta;
+import org.apache.kylin.query.routing.NoRealizationFoundException;
+import org.apache.kylin.source.adhocquery.IPushDownConverter;
+import org.apache.kylin.source.adhocquery.IPushDownRunner;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+
+public class PushDownUtil {
+ private static final Logger logger = LoggerFactory.getLogger(PushDownUtil.class);
+
+ public static boolean doPushDownQuery(String project, String sql, String schema, List<List<String>> results,
+ List<SelectedColumnMeta> columnMetas, SQLException sqlException) throws Exception {
+
+ KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
+ if (!kylinConfig.isPushDownEnabled()) {
+ return false;
+ }
+
+ Throwable rootCause = ExceptionUtils.getRootCause(sqlException);
+ boolean isExpectedCause = rootCause != null && (rootCause.getClass().equals(NoRealizationFoundException.class));
+
+ if (isExpectedCause) {
+ logger.info("Query failed to utilize pre-calculation, routing to other engines", sqlException);
+ IPushDownRunner runner = (IPushDownRunner) ClassUtil.newInstance(kylinConfig.getPushDownRunnerClassName());
+ IPushDownConverter converter = (IPushDownConverter) ClassUtil
+ .newInstance(kylinConfig.getPushDownConverterClassName());
+
+ runner.init(kylinConfig);
+
+ logger.debug("Query pushdown runner {}", runner);
+
+ String expandCC = restoreComputedColumnToExpr(sql, project);
+ if (!StringUtils.equals(expandCC, sql)) {
+ logger.info("computed column in sql is expanded to: " + expandCC);
+ }
+ if (schema != null && !schema.equals("DEFAULT")) {
+ expandCC = schemaCompletion(expandCC, schema);
+ }
+ String adhocSql = converter.convert(expandCC);
+ if (!adhocSql.equals(expandCC)) {
+ logger.info("the query is converted to {} according to kylin.query.pushdown.converter-class-name",
+ adhocSql);
+ }
+
+ runner.executeQuery(adhocSql, results, columnMetas);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ static String schemaCompletion(String inputSql, String schema) {
+ if (inputSql == null || inputSql.equals("")) {
+ return "";
+ }
+ SqlNode fromNode = CalciteParser.getFromNode(inputSql);
+
+ // get all table node that don't have schema by visitor pattern
+ FromTablesVisitor ftv = new FromTablesVisitor();
+ fromNode.accept(ftv);
+ List<SqlNode> tablesWithoutSchema = ftv.getTablesWithoutSchema();
+
+ List<Pair<Integer, Integer>> tablesPos = new ArrayList<>();
+ for (SqlNode tables : tablesWithoutSchema) {
+ tablesPos.add(CalciteParser.getReplacePos(tables, inputSql));
+ }
+
+ // make the behind position in the front of the list, so that the front position will not be affected when replaced
+ Collections.sort(tablesPos);
+ Collections.reverse(tablesPos);
+
+ StrBuilder afterConvert = new StrBuilder(inputSql);
+ for (Pair<Integer, Integer> pos : tablesPos) {
+ String tableWithSchema = schema + "." + inputSql.substring(pos.getLeft(), pos.getRight());
+ afterConvert.replace(pos.getLeft(), pos.getRight(), tableWithSchema);
+ }
+ return afterConvert.toString();
+ }
+
+ private final static Pattern identifierInSqlPattern = Pattern.compile(
+ //find pattern like "table"."column" or "column"
+ "((?<![\\p{L}_0-9\\.\\\"])(\\\"[\\p{L}_0-9]+\\\"\\.)?(\\\"[\\p{L}_0-9]+\\\")(?![\\p{L}_0-9\\.\\\"]))" + "|"
+ //find pattern like table.column or column
+ + "((?<![\\p{L}_0-9\\.\\\"])([\\p{L}_0-9]+\\.)?([\\p{L}_0-9]+)(?![\\p{L}_0-9\\.\\\"]))");
+
+ private final static Pattern identifierInExprPattern = Pattern.compile(
+ // a.b.c
+ "((?<![\\p{L}_0-9\\.\\\"])([\\p{L}_0-9]+\\.)([\\p{L}_0-9]+\\.)([\\p{L}_0-9]+)(?![\\p{L}_0-9\\.\\\"]))");
+
+ private final static Pattern endWithAsPattern = Pattern.compile("\\s+as\\s+$", Pattern.CASE_INSENSITIVE);
+
+ public static String restoreComputedColumnToExpr(String beforeSql, String project) {
+ final MetadataManager metadataManager = MetadataManager.getInstance(KylinConfig.getInstanceFromEnv());
+ List<DataModelDesc> dataModelDescs = metadataManager.getModels(project);
+
+ String afterSql = beforeSql;
+ for (DataModelDesc dataModelDesc : dataModelDescs) {
+ for (ComputedColumnDesc computedColumnDesc : dataModelDesc.getComputedColumnDescs()) {
+ afterSql = restoreComputedColumnToExpr(afterSql, computedColumnDesc);
+ }
+ }
+ return afterSql;
+ }
+
+ static String restoreComputedColumnToExpr(String sql, ComputedColumnDesc computedColumnDesc) {
+
+ String ccName = computedColumnDesc.getColumnName();
+ List<Triple<Integer, Integer, String>> replacements = Lists.newArrayList();
+ Matcher matcher = identifierInSqlPattern.matcher(sql);
+
+ while (matcher.find()) {
+ if (matcher.group(1) != null) { //with quote case: "TABLE"."COLUMN"
+
+ String quotedColumnName = matcher.group(3);
+ Preconditions.checkNotNull(quotedColumnName);
+ String columnName = StringUtils.strip(quotedColumnName, "\"");
+ if (!columnName.equalsIgnoreCase(ccName)) {
+ continue;
+ }
+
+ if (matcher.group(2) != null) { // table name exist
+ String quotedTableAlias = StringUtils.strip(matcher.group(2), ".");
+ String tableAlias = StringUtils.strip(quotedTableAlias, "\"");
+ replacements.add(Triple.of(matcher.start(1), matcher.end(1),
+ replaceIdentifierInExpr(computedColumnDesc.getExpression(), tableAlias, true)));
+ } else { //only column
+ if (endWithAsPattern.matcher(sql.substring(0, matcher.start(1))).find()) {
+ //select DEAL_AMOUNT as "deal_amount" case
+ continue;
+ }
+ replacements.add(Triple.of(matcher.start(1), matcher.end(1),
+ replaceIdentifierInExpr(computedColumnDesc.getExpression(), null, true)));
+ }
+ } else if (matcher.group(4) != null) { //without quote case: table.column or simply column
+ String columnName = matcher.group(6);
+ Preconditions.checkNotNull(columnName);
+ if (!columnName.equalsIgnoreCase(ccName)) {
+ continue;
+ }
+
+ if (matcher.group(5) != null) { //table name exist
+ String tableAlias = StringUtils.strip(matcher.group(5), ".");
+ replacements.add(Triple.of(matcher.start(4), matcher.end(4),
+ replaceIdentifierInExpr(computedColumnDesc.getExpression(), tableAlias, false)));
+
+ } else { //only column
+ if (endWithAsPattern.matcher(sql.substring(0, matcher.start(4))).find()) {
+ //select DEAL_AMOUNT as deal_amount case
+ continue;
+ }
+ replacements.add(Triple.of(matcher.start(4), matcher.end(4),
+ replaceIdentifierInExpr(computedColumnDesc.getExpression(), null, false)));
+ }
+ }
+ }
+
+ Collections.reverse(replacements);
+ for (Triple<Integer, Integer, String> triple : replacements) {
+ sql = sql.substring(0, triple.getLeft()) + "(" + triple.getRight() + ")"
+ + sql.substring(triple.getMiddle());
+ }
+ return sql;
+ }
+
+ static String replaceIdentifierInExpr(String expr, String tableAlias, boolean quoted) {
+ if (tableAlias == null) {
+ return expr;
+ }
+
+ return CalciteParser.insertAliasInExpr(expr, tableAlias);
+ }
+}
+
+/**
+ * Created by jiatao.tao
+ * Get all the tables from "FROM" clause that without schema
+ */
+class FromTablesVisitor implements SqlVisitor<SqlNode> {
+ private List<SqlNode> tables;
+
+ FromTablesVisitor() {
+ this.tables = new ArrayList<>();
+ }
+
+ List<SqlNode> getTablesWithoutSchema() {
+ return tables;
+ }
+
+ @Override
+ public SqlNode visit(SqlNodeList nodeList) {
+ return null;
+ }
+
+ @Override
+ public SqlNode visit(SqlLiteral literal) {
+ return null;
+ }
+
+ @Override
+ public SqlNode visit(SqlCall call) {
+ if (call instanceof SqlBasicCall) {
+ SqlBasicCall node = (SqlBasicCall) call;
+ node.getOperands()[0].accept(this);
+ return null;
+ }
+ if (call instanceof SqlJoin) {
+ SqlJoin node = (SqlJoin) call;
+ node.getLeft().accept(this);
+ node.getRight().accept(this);
+ return null;
+ }
+ for (SqlNode operand : call.getOperandList()) {
+ if (operand != null) {
+ operand.accept(this);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public SqlNode visit(SqlIdentifier id) {
+ if (id.names.size() == 1) {
+ tables.add(id);
+ }
+ return null;
+ }
+
+ @Override
+ public SqlNode visit(SqlDataTypeSpec type) {
+ return null;
+ }
+
+ @Override
+ public SqlNode visit(SqlDynamicParam param) {
+ return null;
+ }
+
+ @Override
+ public SqlNode visit(SqlIntervalQualifier intervalQualifier) {
+ return null;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/kylin/blob/bc347b7b/query/src/test/java/org/apache/kylin/query/util/PushDownUtilTest.java
----------------------------------------------------------------------
diff --git a/query/src/test/java/org/apache/kylin/query/util/PushDownUtilTest.java b/query/src/test/java/org/apache/kylin/query/util/PushDownUtilTest.java
new file mode 100644
index 0000000..e2ccd9e
--- /dev/null
+++ b/query/src/test/java/org/apache/kylin/query/util/PushDownUtilTest.java
@@ -0,0 +1,163 @@
+/*
+ * 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.query.util;
+
+import org.apache.kylin.metadata.model.ComputedColumnDesc;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class PushDownUtilTest {
+ @Test
+ public void testSchemaCompletion() {
+ String sql1 = "SELECT a \n"+
+ "FROM a.KYLIN_SALES as KYLIN_SALES\n" +
+ "INNER JOIN \"A\".KYLIN_ACCOUNT as BUYER_ACCOUNT\n" +
+ "ON KYLIN_SALES.BUYER_ID = BUYER_ACCOUNT.ACCOUNT_ID\n" +
+ "INNER JOIN \"KYLIN_COUNTRY\" as BUYER_COUNTRY\n" +
+ "ON BUYER_ACCOUNT.ACCOUNT_COUNTRY = BUYER_COUNTRY.COUNTRY";
+ String sql2 = "select * from DB2.t,DB2.tt,ttt";
+
+ String sql3 = "SELECT t1.week_beg_dt, t1.sum_price, t2.cnt\n" +
+ "FROM (\n" +
+ " select test_cal_dt.week_beg_dt, sum(price) as sum_price\n" +
+ " from DB1.\"test_kylin_fact\"\n" +
+ " inner JOIN test_cal_dt as test_cal_dt\n" +
+ " ON test_kylin_fact.cal_dt = test_cal_dt.cal_dt\n" +
+ " inner JOIN test_category_groupings\n" +
+ " ON test_kylin_fact.leaf_categ_id = test_category_groupings.leaf_categ_id AND test_kylin_fact.lstg_site_id = test_category_groupings.site_id\n" +
+ " inner JOIN test_sites as test_sites\n" +
+ " ON test_kylin_fact.lstg_site_id = test_sites.site_id\n" +
+ " group by test_cal_dt.week_beg_dt\n" +
+ ") t1\n" +
+ "inner join (\n" +
+ " select test_cal_dt.week_beg_dt, count(*) as cnt\n" +
+ " from DB1.test_kylin_fact\n" +
+ " inner JOIN test_cal_dt as test_cal_dt\n" +
+ " ON test_kylin_fact.cal_dt = test_cal_dt.cal_dt\n" +
+ " inner JOIN test_category_groupings\n" +
+ " ON test_kylin_fact.leaf_categ_id = test_category_groupings.leaf_categ_id AND test_kylin_fact.lstg_site_id = test_category_groupings.site_id\n" +
+ " inner JOIN test_sites as test_sites\n" +
+ " ON test_kylin_fact.lstg_site_id = test_sites.site_id\n" +
+ " group by test_cal_dt.week_beg_dt\n" +
+ ") t2\n" +
+ "on t1.week_beg_dt=t2.week_beg_dt";
+
+ String exceptSQL1 = "SELECT a \n" +
+ "FROM a.KYLIN_SALES as KYLIN_SALES\n" +
+ "INNER JOIN \"A\".KYLIN_ACCOUNT as BUYER_ACCOUNT\n" +
+ "ON KYLIN_SALES.BUYER_ID = BUYER_ACCOUNT.ACCOUNT_ID\n" +
+ "INNER JOIN EDW.\"KYLIN_COUNTRY\" as BUYER_COUNTRY\n" +
+ "ON BUYER_ACCOUNT.ACCOUNT_COUNTRY = BUYER_COUNTRY.COUNTRY";
+
+ String exceptSQL2 = "select * from DB2.t,DB2.tt,EDW.ttt";
+
+ String exceptSQL3 = "SELECT t1.week_beg_dt, t1.sum_price, t2.cnt\n" +
+ "FROM (\n" +
+ " select test_cal_dt.week_beg_dt, sum(price) as sum_price\n" +
+ " from DB1.\"test_kylin_fact\"\n" +
+ " inner JOIN EDW.test_cal_dt as test_cal_dt\n" +
+ " ON test_kylin_fact.cal_dt = test_cal_dt.cal_dt\n" +
+ " inner JOIN EDW.test_category_groupings\n" +
+ " ON test_kylin_fact.leaf_categ_id = test_category_groupings.leaf_categ_id AND test_kylin_fact.lstg_site_id = test_category_groupings.site_id\n" +
+ " inner JOIN EDW.test_sites as test_sites\n" +
+ " ON test_kylin_fact.lstg_site_id = test_sites.site_id\n" +
+ " group by test_cal_dt.week_beg_dt\n" +
+ ") t1\n" +
+ "inner join (\n" +
+ " select test_cal_dt.week_beg_dt, count(*) as cnt\n" +
+ " from DB1.test_kylin_fact\n" +
+ " inner JOIN EDW.test_cal_dt as test_cal_dt\n" +
+ " ON test_kylin_fact.cal_dt = test_cal_dt.cal_dt\n" +
+ " inner JOIN EDW.test_category_groupings\n" +
+ " ON test_kylin_fact.leaf_categ_id = test_category_groupings.leaf_categ_id AND test_kylin_fact.lstg_site_id = test_category_groupings.site_id\n" +
+ " inner JOIN EDW.test_sites as test_sites\n" +
+ " ON test_kylin_fact.lstg_site_id = test_sites.site_id\n" +
+ " group by test_cal_dt.week_beg_dt\n" +
+ ") t2\n" +
+ "on t1.week_beg_dt=t2.week_beg_dt";
+ Assert.assertEquals(exceptSQL1, PushDownUtil.schemaCompletion(sql1, "EDW"));
+ Assert.assertEquals(exceptSQL2, PushDownUtil.schemaCompletion(sql2, "EDW"));
+ Assert.assertEquals(exceptSQL3, PushDownUtil.schemaCompletion(sql3, "EDW"));
+ }
+
+ @Test
+ public void testReplaceIdentifierInExpr() {
+ {
+ String ret = PushDownUtil.replaceIdentifierInExpr("x * y", null, false);
+ Assert.assertEquals("x * y", ret);
+ }
+ {
+ String ret = PushDownUtil.replaceIdentifierInExpr("x_3 * y_3", "b_2", false);
+ Assert.assertEquals("b_2.x_3 * b_2.y_3", ret);
+ }
+ {
+ String ret = PushDownUtil.replaceIdentifierInExpr("substr(x,1,3)>y", "c", true);
+ Assert.assertEquals("substr(c.x,1,3)>c.y", ret);
+ }
+ {
+ String ret = PushDownUtil.replaceIdentifierInExpr("strcmp(substr(x,1,3),y)", "c", true);
+ Assert.assertEquals("strcmp(substr(c.x,1,3),c.y)", ret);
+ }
+ {
+ String ret = PushDownUtil.replaceIdentifierInExpr("strcmp(substr(x,1,3),y)", null, true);
+ Assert.assertEquals("strcmp(substr(x,1,3),y)", ret);
+ }
+ {
+ String ret = PushDownUtil.replaceIdentifierInExpr("strcmp(substr(x,1,3),y)", null, false);
+ Assert.assertEquals("strcmp(substr(x,1,3),y)", ret);
+ }
+ }
+
+ @Test
+ public void testRestoreComputedColumnToExpr() {
+
+ ComputedColumnDesc computedColumnDesc = Mockito.mock(ComputedColumnDesc.class);
+ Mockito.when(computedColumnDesc.getColumnName()).thenReturn("DEAL_AMOUNT");
+ Mockito.when(computedColumnDesc.getExpression()).thenReturn("price * number");
+ {
+ String ret = PushDownUtil.restoreComputedColumnToExpr(
+ "select DEAL_AMOUNT from DB.TABLE group by date order by DEAL_AMOUNT", computedColumnDesc);
+ Assert.assertEquals("select (price * number) from DB.TABLE group by date order by (price * number)", ret);
+ }
+ {
+ String ret = PushDownUtil.restoreComputedColumnToExpr(
+ "select DEAL_AMOUNT as DEAL_AMOUNT from DB.TABLE group by date order by DEAL_AMOUNT",
+ computedColumnDesc);
+ Assert.assertEquals(
+ "select (price * number) as DEAL_AMOUNT from DB.TABLE group by date order by (price * number)",
+ ret);
+ }
+ {
+ String ret = PushDownUtil.restoreComputedColumnToExpr(
+ "select \"DEAL_AMOUNT\" AS deal_amount from DB.TABLE group by date order by DEAL_AMOUNT",
+ computedColumnDesc);
+ Assert.assertEquals(
+ "select (price * number) AS deal_amount from DB.TABLE group by date order by (price * number)",
+ ret);
+ }
+ {
+ String ret = PushDownUtil.restoreComputedColumnToExpr(
+ "select x.DEAL_AMOUNT AS deal_amount from DB.TABLE x group by date order by x.DEAL_AMOUNT",
+ computedColumnDesc);
+ Assert.assertEquals(
+ "select (x.price * x.number) AS deal_amount from DB.TABLE x group by date order by (x.price * x.number)",
+ ret);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/kylin/blob/bc347b7b/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java
----------------------------------------------------------------------
diff --git a/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java b/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java
index 1c55f6b..ab47caa 100644
--- a/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java
+++ b/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java
@@ -94,7 +94,7 @@ import org.apache.kylin.rest.request.PrepareSqlRequest;
import org.apache.kylin.rest.request.SQLRequest;
import org.apache.kylin.rest.response.SQLResponse;
import org.apache.kylin.rest.util.AclUtil;
-import org.apache.kylin.rest.util.PushDownUtil;
+import org.apache.kylin.query.util.PushDownUtil;
import org.apache.kylin.rest.util.TableauInterceptor;
import org.apache.kylin.storage.hybrid.HybridInstance;
import org.slf4j.Logger;
@@ -791,7 +791,7 @@ public class QueryService extends BasicService {
results.add(oneRow);
}
} catch (SQLException sqlException) {
- isPushDown = PushDownUtil.doPushDownQuery(sqlRequest.getProject(), correctedSql, results, columnMetas,
+ isPushDown = PushDownUtil.doPushDownQuery(sqlRequest.getProject(), correctedSql, conn.getSchema(), results, columnMetas,
sqlException);
if (!isPushDown) {
throw sqlException;
http://git-wip-us.apache.org/repos/asf/kylin/blob/bc347b7b/server-base/src/main/java/org/apache/kylin/rest/util/PushDownUtil.java
----------------------------------------------------------------------
diff --git a/server-base/src/main/java/org/apache/kylin/rest/util/PushDownUtil.java b/server-base/src/main/java/org/apache/kylin/rest/util/PushDownUtil.java
deleted file mode 100644
index c21d5c2..0000000
--- a/server-base/src/main/java/org/apache/kylin/rest/util/PushDownUtil.java
+++ /dev/null
@@ -1,180 +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.rest.util;
-
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang3.exception.ExceptionUtils;
-import org.apache.commons.lang3.tuple.Triple;
-import org.apache.kylin.common.KylinConfig;
-import org.apache.kylin.common.util.ClassUtil;
-import org.apache.kylin.metadata.MetadataManager;
-import org.apache.kylin.metadata.model.ComputedColumnDesc;
-import org.apache.kylin.metadata.model.DataModelDesc;
-import org.apache.kylin.metadata.model.tool.CalciteParser;
-import org.apache.kylin.metadata.querymeta.SelectedColumnMeta;
-import org.apache.kylin.query.routing.NoRealizationFoundException;
-import org.apache.kylin.source.adhocquery.IPushDownConverter;
-import org.apache.kylin.source.adhocquery.IPushDownRunner;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-
-public class PushDownUtil {
- private static final Logger logger = LoggerFactory.getLogger(PushDownUtil.class);
-
- public static boolean doPushDownQuery(String project, String sql, List<List<String>> results,
- List<SelectedColumnMeta> columnMetas, SQLException sqlException) throws Exception {
-
- KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
- if (!kylinConfig.isPushDownEnabled()) {
- return false;
- }
-
- Throwable rootCause = ExceptionUtils.getRootCause(sqlException);
- boolean isExpectedCause = rootCause != null && (rootCause.getClass().equals(NoRealizationFoundException.class));
-
- if (isExpectedCause) {
- logger.info("Query failed to utilize pre-calculation, routing to other engines", sqlException);
- IPushDownRunner runner = (IPushDownRunner) ClassUtil.newInstance(kylinConfig.getPushDownRunnerClassName());
- IPushDownConverter converter = (IPushDownConverter) ClassUtil
- .newInstance(kylinConfig.getPushDownConverterClassName());
-
- runner.init(kylinConfig);
-
- logger.debug("Query pushdown runner {}", runner);
-
- String expandCC = restoreComputedColumnToExpr(sql, project);
- if (!StringUtils.equals(expandCC, sql)) {
- logger.info("computed column in sql is expanded to: " + expandCC);
- }
- String adhocSql = converter.convert(expandCC);
- if (!adhocSql.equals(expandCC)) {
- logger.info("the query is converted to {} according to kylin.query.pushdown.converter-class-name",
- adhocSql);
- }
-
- runner.executeQuery(adhocSql, results, columnMetas);
-
- return true;
- } else {
- return false;
- }
- }
-
- private final static Pattern identifierInSqlPattern = Pattern.compile(
- //find pattern like "table"."column" or "column"
- "((?<![\\p{L}_0-9\\.\\\"])(\\\"[\\p{L}_0-9]+\\\"\\.)?(\\\"[\\p{L}_0-9]+\\\")(?![\\p{L}_0-9\\.\\\"]))" + "|"
- //find pattern like table.column or column
- + "((?<![\\p{L}_0-9\\.\\\"])([\\p{L}_0-9]+\\.)?([\\p{L}_0-9]+)(?![\\p{L}_0-9\\.\\\"]))");
-
- private final static Pattern identifierInExprPattern = Pattern.compile(
- // a.b.c
- "((?<![\\p{L}_0-9\\.\\\"])([\\p{L}_0-9]+\\.)([\\p{L}_0-9]+\\.)([\\p{L}_0-9]+)(?![\\p{L}_0-9\\.\\\"]))");
-
- private final static Pattern endWithAsPattern = Pattern.compile("\\s+as\\s+$", Pattern.CASE_INSENSITIVE);
-
- public static String restoreComputedColumnToExpr(String beforeSql, String project) {
- final MetadataManager metadataManager = MetadataManager.getInstance(KylinConfig.getInstanceFromEnv());
- List<DataModelDesc> dataModelDescs = metadataManager.getModels(project);
-
- String afterSql = beforeSql;
- for (DataModelDesc dataModelDesc : dataModelDescs) {
- for (ComputedColumnDesc computedColumnDesc : dataModelDesc.getComputedColumnDescs()) {
- afterSql = restoreComputedColumnToExpr(afterSql, computedColumnDesc);
- }
- }
- return afterSql;
- }
-
- static String restoreComputedColumnToExpr(String sql, ComputedColumnDesc computedColumnDesc) {
-
- String ccName = computedColumnDesc.getColumnName();
- List<Triple<Integer, Integer, String>> replacements = Lists.newArrayList();
- Matcher matcher = identifierInSqlPattern.matcher(sql);
-
- while (matcher.find()) {
- if (matcher.group(1) != null) { //with quote case: "TABLE"."COLUMN"
-
- String quotedColumnName = matcher.group(3);
- Preconditions.checkNotNull(quotedColumnName);
- String columnName = StringUtils.strip(quotedColumnName, "\"");
- if (!columnName.equalsIgnoreCase(ccName)) {
- continue;
- }
-
- if (matcher.group(2) != null) { // table name exist
- String quotedTableAlias = StringUtils.strip(matcher.group(2), ".");
- String tableAlias = StringUtils.strip(quotedTableAlias, "\"");
- replacements.add(Triple.of(matcher.start(1), matcher.end(1),
- replaceIdentifierInExpr(computedColumnDesc.getExpression(), tableAlias, true)));
- } else { //only column
- if (endWithAsPattern.matcher(sql.substring(0, matcher.start(1))).find()) {
- //select DEAL_AMOUNT as "deal_amount" case
- continue;
- }
- replacements.add(Triple.of(matcher.start(1), matcher.end(1),
- replaceIdentifierInExpr(computedColumnDesc.getExpression(), null, true)));
- }
- } else if (matcher.group(4) != null) { //without quote case: table.column or simply column
- String columnName = matcher.group(6);
- Preconditions.checkNotNull(columnName);
- if (!columnName.equalsIgnoreCase(ccName)) {
- continue;
- }
-
- if (matcher.group(5) != null) { //table name exist
- String tableAlias = StringUtils.strip(matcher.group(5), ".");
- replacements.add(Triple.of(matcher.start(4), matcher.end(4),
- replaceIdentifierInExpr(computedColumnDesc.getExpression(), tableAlias, false)));
-
- } else { //only column
- if (endWithAsPattern.matcher(sql.substring(0, matcher.start(4))).find()) {
- //select DEAL_AMOUNT as deal_amount case
- continue;
- }
- replacements.add(Triple.of(matcher.start(4), matcher.end(4),
- replaceIdentifierInExpr(computedColumnDesc.getExpression(), null, false)));
- }
- }
- }
-
- Collections.reverse(replacements);
- for (Triple<Integer, Integer, String> triple : replacements) {
- sql = sql.substring(0, triple.getLeft()) + "(" + triple.getRight() + ")"
- + sql.substring(triple.getMiddle());
- }
- return sql;
- }
-
- static String replaceIdentifierInExpr(String expr, String tableAlias, boolean quoted) {
- if (tableAlias == null) {
- return expr;
- }
-
- return CalciteParser.insertAliasInExpr(expr, tableAlias);
- }
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/bc347b7b/server-base/src/test/java/org/apache/kylin/rest/util/PushDownUtilTest.java
----------------------------------------------------------------------
diff --git a/server-base/src/test/java/org/apache/kylin/rest/util/PushDownUtilTest.java b/server-base/src/test/java/org/apache/kylin/rest/util/PushDownUtilTest.java
deleted file mode 100644
index 5302a70..0000000
--- a/server-base/src/test/java/org/apache/kylin/rest/util/PushDownUtilTest.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.rest.util;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import org.apache.kylin.metadata.model.ComputedColumnDesc;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class PushDownUtilTest {
-
- @Test
- public void testReplaceIdentifierInExpr() {
- {
- String ret = PushDownUtil.replaceIdentifierInExpr("x * y", null, false);
- Assert.assertEquals("x * y", ret);
- }
- {
- String ret = PushDownUtil.replaceIdentifierInExpr("x_3 * y_3", "b_2", false);
- Assert.assertEquals("b_2.x_3 * b_2.y_3", ret);
- }
- {
- String ret = PushDownUtil.replaceIdentifierInExpr("substr(x,1,3)>y", "c", true);
- Assert.assertEquals("substr(c.x,1,3)>c.y", ret);
- }
- {
- String ret = PushDownUtil.replaceIdentifierInExpr("strcmp(substr(x,1,3),y)", "c", true);
- Assert.assertEquals("strcmp(substr(c.x,1,3),c.y)", ret);
- }
- {
- String ret = PushDownUtil.replaceIdentifierInExpr("strcmp(substr(x,1,3),y)", null, true);
- Assert.assertEquals("strcmp(substr(x,1,3),y)", ret);
- }
- {
- String ret = PushDownUtil.replaceIdentifierInExpr("strcmp(substr(x,1,3),y)", null, false);
- Assert.assertEquals("strcmp(substr(x,1,3),y)", ret);
- }
- }
-
- @Test
- public void testRestoreComputedColumnToExpr() {
-
- ComputedColumnDesc computedColumnDesc = mock(ComputedColumnDesc.class);
- when(computedColumnDesc.getColumnName()).thenReturn("DEAL_AMOUNT");
- when(computedColumnDesc.getExpression()).thenReturn("price * number");
-
- {
- String ret = PushDownUtil.restoreComputedColumnToExpr(
- "select DEAL_AMOUNT from DB.TABLE group by date order by DEAL_AMOUNT", computedColumnDesc);
- Assert.assertEquals("select (price * number) from DB.TABLE group by date order by (price * number)", ret);
- }
- {
- String ret = PushDownUtil.restoreComputedColumnToExpr(
- "select DEAL_AMOUNT as DEAL_AMOUNT from DB.TABLE group by date order by DEAL_AMOUNT",
- computedColumnDesc);
- Assert.assertEquals(
- "select (price * number) as DEAL_AMOUNT from DB.TABLE group by date order by (price * number)",
- ret);
- }
- {
- String ret = PushDownUtil.restoreComputedColumnToExpr(
- "select \"DEAL_AMOUNT\" AS deal_amount from DB.TABLE group by date order by DEAL_AMOUNT",
- computedColumnDesc);
- Assert.assertEquals(
- "select (price * number) AS deal_amount from DB.TABLE group by date order by (price * number)",
- ret);
- }
- {
- String ret = PushDownUtil.restoreComputedColumnToExpr(
- "select x.DEAL_AMOUNT AS deal_amount from DB.TABLE x group by date order by x.DEAL_AMOUNT",
- computedColumnDesc);
- Assert.assertEquals(
- "select (x.price * x.number) AS deal_amount from DB.TABLE x group by date order by (x.price * x.number)",
- ret);
- }
- }
-}
[05/15] kylin git commit: minor, fix error message
Posted by li...@apache.org.
minor, fix error message
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/fb39c9d9
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/fb39c9d9
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/fb39c9d9
Branch: refs/heads/2.1.x
Commit: fb39c9d92059a387d683faada68872d5a5764ff0
Parents: 9cd49dc
Author: Roger Shi <ro...@hotmail.com>
Authored: Thu Jul 27 13:12:44 2017 +0800
Committer: Roger Shi <ro...@hotmail.com>
Committed: Thu Jul 27 13:16:42 2017 +0800
----------------------------------------------------------------------
.../src/main/java/org/apache/kylin/metadata/model/Segments.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/fb39c9d9/core-metadata/src/main/java/org/apache/kylin/metadata/model/Segments.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/main/java/org/apache/kylin/metadata/model/Segments.java b/core-metadata/src/main/java/org/apache/kylin/metadata/model/Segments.java
index 9d22dc6..73a385c 100644
--- a/core-metadata/src/main/java/org/apache/kylin/metadata/model/Segments.java
+++ b/core-metadata/src/main/java/org/apache/kylin/metadata/model/Segments.java
@@ -144,7 +144,7 @@ public class Segments<T extends ISegment> extends ArrayList<T> implements Serial
if (sourceOffsetContains(mergedSegment, seg)) {
// make sure no holes
if (result.size() > 0 && result.getLast().getSourceOffsetEnd() != seg.getSourceOffsetStart())
- throw new IllegalStateException("Merging segments must not have holes between " + result.getLast() + " and " + seg);
+ throw new IllegalStateException("Merging segments must not have gaps between " + result.getLast() + " and " + seg);
result.add(seg);
}
[09/15] kylin git commit: KYLIN-2748 fix: modify default permsize to
256m , improve query performance
Posted by li...@apache.org.
KYLIN-2748 fix: modify default permsize to 256m ,improve query performance
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/f03b81eb
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/f03b81eb
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/f03b81eb
Branch: refs/heads/2.1.x
Commit: f03b81ebd1834e717395defe1c6dee9540f9a3fb
Parents: bc347b7
Author: yiming.xu <10...@qq.com>
Authored: Wed Jul 26 18:41:02 2017 +0800
Committer: YIMINGXU <10...@qq.com>
Committed: Mon Jul 31 02:14:38 2017 -0500
----------------------------------------------------------------------
build/conf/setenv.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/f03b81eb/build/conf/setenv.sh
----------------------------------------------------------------------
diff --git a/build/conf/setenv.sh b/build/conf/setenv.sh
index 0e9b185..5fcff3e 100755
--- a/build/conf/setenv.sh
+++ b/build/conf/setenv.sh
@@ -22,7 +22,7 @@
# (if your're deploying KYLIN on a powerful server and want to replace the default conservative settings)
# uncomment following to for it to take effect
export KYLIN_JVM_SETTINGS="-Xms1024M -Xmx4096M -Xss1024K -XX:MaxPermSize=128M -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:$KYLIN_HOME/logs/kylin.gc.$$ -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=64M"
-# export KYLIN_JVM_SETTINGS="-Xms16g -Xmx16g -XX:MaxPermSize=512m -XX:NewSize=3g -XX:MaxNewSize=3g -XX:SurvivorRatio=4 -XX:+CMSClassUnloadingEnabled -XX:+CMSParallelRemarkEnabled -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:CMSInitiatingOccupancyFraction=70 -XX:+UseCMSInitiatingOccupancyOnly -XX:+DisableExplicitGC -XX:+HeapDumpOnOutOfMemoryError"
+# export KYLIN_JVM_SETTINGS="-Xms16g -Xmx16g -XX:MaxPermSize=256m -XX:NewSize=3g -XX:MaxNewSize=3g -XX:SurvivorRatio=4 -XX:+CMSClassUnloadingEnabled -XX:+CMSParallelRemarkEnabled -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:CMSInitiatingOccupancyFraction=70 -XX:+UseCMSInitiatingOccupancyOnly -XX:+DisableExplicitGC -XX:+HeapDumpOnOutOfMemoryError -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:$KYLIN_HOME/logs/kylin.gc.$$ -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=64M"
# uncomment following to for it to take effect(the values need adjusting to fit your env)
# export KYLIN_DEBUG_SETTINGS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
[02/15] kylin git commit: #1693 fix error message (#1700)
Posted by li...@apache.org.
#1693 fix error message (#1700)
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/016a57af
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/016a57af
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/016a57af
Branch: refs/heads/2.1.x
Commit: 016a57afa1cae3ad3578863129cc11041e7bb6b9
Parents: afd7e55
Author: Roger Shi <ro...@gmail.com>
Authored: Tue Jul 25 18:45:10 2017 +0800
Committer: Roger Shi <ro...@hotmail.com>
Committed: Tue Jul 25 18:45:50 2017 +0800
----------------------------------------------------------------------
server-base/src/main/java/org/apache/kylin/rest/msg/CnMessage.java | 2 +-
server-base/src/main/java/org/apache/kylin/rest/msg/Message.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/016a57af/server-base/src/main/java/org/apache/kylin/rest/msg/CnMessage.java
----------------------------------------------------------------------
diff --git a/server-base/src/main/java/org/apache/kylin/rest/msg/CnMessage.java b/server-base/src/main/java/org/apache/kylin/rest/msg/CnMessage.java
index e086b68..ece4b83 100644
--- a/server-base/src/main/java/org/apache/kylin/rest/msg/CnMessage.java
+++ b/server-base/src/main/java/org/apache/kylin/rest/msg/CnMessage.java
@@ -229,7 +229,7 @@ public class CnMessage extends Message {
// Acl
public String getUSER_NOT_EXIST() {
- return "用户 '%s' 不存在, 请确认用户是否曾经登陆";
+ return "用户 '%s' 不存在, 请确认用户是否存在。";
}
// Project
http://git-wip-us.apache.org/repos/asf/kylin/blob/016a57af/server-base/src/main/java/org/apache/kylin/rest/msg/Message.java
----------------------------------------------------------------------
diff --git a/server-base/src/main/java/org/apache/kylin/rest/msg/Message.java b/server-base/src/main/java/org/apache/kylin/rest/msg/Message.java
index f48a217..8137c34 100644
--- a/server-base/src/main/java/org/apache/kylin/rest/msg/Message.java
+++ b/server-base/src/main/java/org/apache/kylin/rest/msg/Message.java
@@ -229,7 +229,7 @@ public class Message {
// Acl
public String getUSER_NOT_EXIST() {
- return "User '%s' does not exist. Please make sure the user has logged in before";
+ return "User '%s' does not exist. Please make sure the user exists.";
}
// Project
[14/15] kylin git commit: minor, handle cube desc being bad json cases
Posted by li...@apache.org.
minor, handle cube desc being bad json cases
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/e164b4a3
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/e164b4a3
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/e164b4a3
Branch: refs/heads/2.1.x
Commit: e164b4a3fac379e71b8effaa8922d95a2dca05d8
Parents: 7369ee3
Author: Hongbin Ma <ma...@apache.org>
Authored: Mon Jul 31 21:57:59 2017 +0800
Committer: Hongbin Ma <ma...@apache.org>
Committed: Mon Jul 31 22:00:50 2017 +0800
----------------------------------------------------------------------
.../main/java/org/apache/kylin/cube/CubeDescManager.java | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/e164b4a3/core-cube/src/main/java/org/apache/kylin/cube/CubeDescManager.java
----------------------------------------------------------------------
diff --git a/core-cube/src/main/java/org/apache/kylin/cube/CubeDescManager.java b/core-cube/src/main/java/org/apache/kylin/cube/CubeDescManager.java
index 2d44454..6635366 100644
--- a/core-cube/src/main/java/org/apache/kylin/cube/CubeDescManager.java
+++ b/core-cube/src/main/java/org/apache/kylin/cube/CubeDescManager.java
@@ -316,7 +316,13 @@ public class CubeDescManager {
List<String> paths = store.collectResourceRecursively(ResourceStore.CUBE_DESC_RESOURCE_ROOT,
MetadataConstants.FILE_SURFIX);
for (String path : paths) {
- CubeDesc desc = loadCubeDesc(path, true);
+ CubeDesc desc = null;
+ try {
+ desc = loadCubeDesc(path, true);
+ } catch (Exception e) {
+ logger.error("Error during load cube desc, skipping " + path, e);
+ continue;
+ }
if (!path.equals(desc.getResourcePath())) {
logger.error(
@@ -350,7 +356,7 @@ public class CubeDescManager {
throw new IllegalArgumentException("CubeDesc '" + name + "' does not exist.");
if (desc.isDraft())
throw new IllegalArgumentException("CubeDesc '" + desc.getName() + "' must not be a draft");
-
+
try {
desc.init(config);
} catch (Exception e) {
[12/15] kylin git commit: KYLIN-2762 Make the jar under
KYLIN_HOME/tool in front of the CLASSPATH
Posted by li...@apache.org.
KYLIN-2762 Make the jar under KYLIN_HOME/tool in front of the CLASSPATH
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/e21e86e4
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/e21e86e4
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/e21e86e4
Branch: refs/heads/2.1.x
Commit: e21e86e4738f9f463d2b38d5577d3bd6caa05b86
Parents: 3e777c0
Author: tttMelody <24...@qq.com>
Authored: Mon Jul 31 17:30:40 2017 +0800
Committer: YIMINGXU <10...@qq.com>
Committed: Mon Jul 31 04:53:32 2017 -0500
----------------------------------------------------------------------
build/bin/kylin.sh | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/e21e86e4/build/bin/kylin.sh
----------------------------------------------------------------------
diff --git a/build/bin/kylin.sh b/build/bin/kylin.sh
index 08c9075..bf1c862 100755
--- a/build/bin/kylin.sh
+++ b/build/bin/kylin.sh
@@ -199,10 +199,10 @@ then
then source ${dir}/setenv-tool.sh
fi
- hbase_original=${HBASE_CLASSPATH}
- export HBASE_CLASSPATH=${hbase_original}:${KYLIN_HOME}/tool/*
+ hbase_pre_original=${HBASE_CLASSPATH_PREFIX}
+ export HBASE_CLASSPATH_PREFIX=${KYLIN_HOME}/tool/*:${HBASE_CLASSPATH_PREFIX}
exec hbase ${KYLIN_EXTRA_START_OPTS} -Dkylin.hive.dependency=${hive_dependency} -Dkylin.hbase.dependency=${hbase_dependency} -Dlog4j.configuration=file:${KYLIN_HOME}/conf/kylin-tools-log4j.properties "$@"
- export HBASE_CLASSPATH=${hbase_original}
+ export HBASE_CLASSPATH_PREFIX=${hbase_pre_original}
else
quit "Usage: 'kylin.sh [-v] start' or 'kylin.sh [-v] stop'"
fi
[11/15] kylin git commit: #1736 should check if computed column name
duplicates with normal column name
Posted by li...@apache.org.
#1736 should check if computed column name duplicates with normal column name
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/3e777c0f
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/3e777c0f
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/3e777c0f
Branch: refs/heads/2.1.x
Commit: 3e777c0fd4d5d047467a69a1e48406b4808f5aa6
Parents: b962721
Author: Hongbin Ma <ma...@apache.org>
Authored: Mon Jul 31 16:38:13 2017 +0800
Committer: Hongbin Ma <ma...@apache.org>
Committed: Mon Jul 31 17:23:47 2017 +0800
----------------------------------------------------------------------
.../metadata/model/ComputedColumnDesc.java | 4 ++++
.../apache/kylin/metadata/model/TableDesc.java | 23 +++++++++++++++-----
.../kylin/rest/service/ModelServiceTest.java | 20 +++++++++++++++++
3 files changed, 41 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/3e777c0f/core-metadata/src/main/java/org/apache/kylin/metadata/model/ComputedColumnDesc.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/main/java/org/apache/kylin/metadata/model/ComputedColumnDesc.java b/core-metadata/src/main/java/org/apache/kylin/metadata/model/ComputedColumnDesc.java
index ab7e074..10a7dd3 100644
--- a/core-metadata/src/main/java/org/apache/kylin/metadata/model/ComputedColumnDesc.java
+++ b/core-metadata/src/main/java/org/apache/kylin/metadata/model/ComputedColumnDesc.java
@@ -44,6 +44,10 @@ public class ComputedColumnDesc implements Serializable {
Preconditions.checkNotNull(expression, "expression is null");
Preconditions.checkNotNull(datatype, "datatype is null");
+ Preconditions.checkState(tableIdentity.equals(tableIdentity.trim()), "tableIdentity of ComputedColumnDesc has heading/tailing whitespace");
+ Preconditions.checkState(columnName.equals(columnName.trim()), "columnName of ComputedColumnDesc has heading/tailing whitespace");
+ Preconditions.checkState(datatype.equals(datatype.trim()), "datatype of ComputedColumnDesc has heading/tailing whitespace");
+
tableIdentity = tableIdentity.toUpperCase();
columnName = columnName.toUpperCase();
http://git-wip-us.apache.org/repos/asf/kylin/blob/3e777c0f/core-metadata/src/main/java/org/apache/kylin/metadata/model/TableDesc.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/main/java/org/apache/kylin/metadata/model/TableDesc.java b/core-metadata/src/main/java/org/apache/kylin/metadata/model/TableDesc.java
index d3543dd..a2a2c24 100644
--- a/core-metadata/src/main/java/org/apache/kylin/metadata/model/TableDesc.java
+++ b/core-metadata/src/main/java/org/apache/kylin/metadata/model/TableDesc.java
@@ -63,18 +63,18 @@ public class TableDesc extends RootPersistentEntity implements ISourceAware {
public TableDesc(TableDesc other) {
this.uuid = other.uuid;
this.lastModified = other.lastModified;
-
+
this.name = other.name;
this.sourceType = other.sourceType;
this.tableType = other.tableType;
this.dataGen = other.dataGen;
-
+
this.columns = new ColumnDesc[other.columns.length];
for (int i = 0; i < other.columns.length; i++) {
this.columns[i] = new ColumnDesc(other.columns[i]);
this.columns[i].init(this);
}
-
+
this.database.setName(other.getDatabase());
this.identity = other.identity;
}
@@ -89,6 +89,15 @@ public class TableDesc extends RootPersistentEntity implements ISourceAware {
ret.columns = new ColumnDesc[computedColumns.length + origin.length];
for (int i = 0; i < origin.length; i++) {
ret.columns[i] = origin[i];
+
+ //check name conflict
+ for (int j = 0; j < computedColumns.length; j++) {
+ if (origin[i].getName().equalsIgnoreCase(computedColumns[j].getName())) {
+ throw new IllegalArgumentException(String.format(
+ "There is already a column named %s on table %s, please change your computed column name",
+ new Object[] { computedColumns[j].getName(), this.getIdentity() }));
+ }
+ }
}
for (int i = 0; i < computedColumns.length; i++) {
computedColumns[i].init(ret);
@@ -186,9 +195,9 @@ public class TableDesc extends RootPersistentEntity implements ISourceAware {
if (columns == null) {
return -1;
}
-
+
int max = -1;
-
+
for (ColumnDesc col : columns) {
int idx = col.getZeroBasedIndex();
max = Math.max(max, idx);
@@ -270,7 +279,9 @@ public class TableDesc extends RootPersistentEntity implements ISourceAware {
@Override
public String toString() {
- return "TableDesc{" + "name='" + name + '\'' + ", columns=" + Arrays.toString(columns) + ", sourceType=" + sourceType + ", tableType='" + tableType + '\'' + ", database=" + database + ", identity='" + getIdentity() + '\'' + '}';
+ return "TableDesc{" + "name='" + name + '\'' + ", columns=" + Arrays.toString(columns) + ", sourceType="
+ + sourceType + ", tableType='" + tableType + '\'' + ", database=" + database + ", identity='"
+ + getIdentity() + '\'' + '}';
}
/** create a mockup table for unit test */
http://git-wip-us.apache.org/repos/asf/kylin/blob/3e777c0f/server/src/test/java/org/apache/kylin/rest/service/ModelServiceTest.java
----------------------------------------------------------------------
diff --git a/server/src/test/java/org/apache/kylin/rest/service/ModelServiceTest.java b/server/src/test/java/org/apache/kylin/rest/service/ModelServiceTest.java
index 756454a..78b1979 100644
--- a/server/src/test/java/org/apache/kylin/rest/service/ModelServiceTest.java
+++ b/server/src/test/java/org/apache/kylin/rest/service/ModelServiceTest.java
@@ -96,4 +96,24 @@ public class ModelServiceTest extends ServiceTestBase {
field.set(deserialize.getComputedColumnDescs().get(0), "another expression");
DataModelDesc dataModelDesc = modelService.updateModelAndDesc(deserialize);
}
+
+
+ @Test
+ public void testFailureModelUpdateDueToComputedColumnConflict2() throws IOException, JobException, NoSuchFieldException, IllegalAccessException {
+ expectedEx.expect(IllegalArgumentException.class);
+ expectedEx.expectMessage("There is already a column named cal_dt on table DEFAULT.TEST_KYLIN_FACT, please change your computed column name");
+
+ List<DataModelDesc> dataModelDescs = modelService.listAllModels("ci_left_join_model", "default", true);
+ Assert.assertTrue(dataModelDescs.size() == 1);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ MetadataManager.MODELDESC_SERIALIZER.serialize(dataModelDescs.get(0), new DataOutputStream(baos));
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ DataModelDesc deserialize = MetadataManager.MODELDESC_SERIALIZER.deserialize(new DataInputStream(bais));
+
+ Field field = ComputedColumnDesc.class.getDeclaredField("columnName");
+ field.setAccessible(true);
+ field.set(deserialize.getComputedColumnDescs().get(0), "cal_dt");
+ DataModelDesc dataModelDesc = modelService.updateModelAndDesc(deserialize);
+ }
}