minor, remove unused hard-code BI transform code (#1889)
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/bf887a7a Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/bf887a7a Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/bf887a7a Branch: refs/heads/2.1.x Commit: bf887a7a8fea0a5a0791e85c6c998df221889863 Parents: 02868ad Author: Jiatao Tao <245915...@qq.com> Authored: Wed Aug 9 00:59:17 2017 -0500 Committer: GitHub <nore...@github.com> Committed: Wed Aug 9 00:59:17 2017 -0500 ---------------------------------------------------------------------- .../org/apache/kylin/common/util/ClassUtil.java | 1 - .../query/util/CognosParenthesesEscape.java | 106 -------- .../query/util/ConvertToComputedColumn.java | 248 ------------------- .../org/apache/kylin/query/util/QueryUtil.java | 2 +- .../query/util/CognosParenthesesEscapeTest.java | 89 ------- .../query/util/ConvertToComputedColumnTest.java | 124 ---------- .../src/test/resources/query/cognos/query01.sql | 28 --- .../resources/query/cognos/query01.sql.expected | 28 --- .../src/test/resources/query/cognos/query02.sql | 27 -- .../resources/query/cognos/query02.sql.expected | 27 -- .../src/test/resources/query/cognos/query03.sql | 29 --- .../resources/query/cognos/query03.sql.expected | 29 --- 12 files changed, 1 insertion(+), 737 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/bf887a7a/core-common/src/main/java/org/apache/kylin/common/util/ClassUtil.java ---------------------------------------------------------------------- diff --git a/core-common/src/main/java/org/apache/kylin/common/util/ClassUtil.java b/core-common/src/main/java/org/apache/kylin/common/util/ClassUtil.java index 0eb1af5..79de357 100644 --- a/core-common/src/main/java/org/apache/kylin/common/util/ClassUtil.java +++ b/core-common/src/main/java/org/apache/kylin/common/util/ClassUtil.java @@ -66,7 +66,6 @@ public class ClassUtil { classRenameMap.put("org.apache.kylin.job.cube.UpdateCubeInfoAfterBuildStep", "org.apache.kylin.engine.mr.steps.UpdateCubeInfoAfterBuildStep"); classRenameMap.put("org.apache.kylin.job.cube.UpdateCubeInfoAfterMergeStep", "org.apache.kylin.engine.mr.steps.UpdateCubeInfoAfterMergeStep"); classRenameMap.put("org.apache.kylin.rest.util.KeywordDefaultDirtyHack", "org.apache.kylin.query.util.KeywordDefaultDirtyHack"); - classRenameMap.put("org.apache.kylin.rest.util.CognosParenthesesEscape", "org.apache.kylin.query.util.CognosParenthesesEscape"); } @SuppressWarnings("unchecked") http://git-wip-us.apache.org/repos/asf/kylin/blob/bf887a7a/query/src/main/java/org/apache/kylin/query/util/CognosParenthesesEscape.java ---------------------------------------------------------------------- diff --git a/query/src/main/java/org/apache/kylin/query/util/CognosParenthesesEscape.java b/query/src/main/java/org/apache/kylin/query/util/CognosParenthesesEscape.java deleted file mode 100644 index 8c6d82d..0000000 --- a/query/src/main/java/org/apache/kylin/query/util/CognosParenthesesEscape.java +++ /dev/null @@ -1,106 +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.query.util; - -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Stack; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import com.google.common.collect.Lists; - -public class CognosParenthesesEscape implements QueryUtil.IQueryTransformer { - private static final Pattern FROM_PATTERN = Pattern.compile("\\s+from\\s+(\\s*\\(\\s*)+(?!\\s*select\\s)", Pattern.CASE_INSENSITIVE); - - @Override - public String transform(String sql, String project) { - if (sql == null || sql.isEmpty()) { - return sql; - } - - Map<Integer, Integer> parenthesesPairs = findParenthesesPairs(sql); - if (parenthesesPairs.isEmpty()) { - // parentheses not found - return sql; - } - - List<Integer> parentheses = Lists.newArrayList(); - StringBuilder result = new StringBuilder(sql); - - Matcher m; - while (true) { - m = FROM_PATTERN.matcher(sql); - if (!m.find()) { - break; - } - - int i = m.end() - 1; - while (i > m.start()) { - if (sql.charAt(i) == '(') { - parentheses.add(i); - } - i--; - } - - if (m.end() < sql.length()) { - sql = sql.substring(m.end()); - } else { - break; - } - } - - Collections.sort(parentheses); - for (int i = 0; i < parentheses.size(); i++) { - result.deleteCharAt(parentheses.get(i) - i); - result.deleteCharAt(parenthesesPairs.get(parentheses.get(i)) - i - 1); - } - return result.toString(); - } - - private Map<Integer, Integer> findParenthesesPairs(String sql) { - Map<Integer, Integer> result = new HashMap<>(); - if (sql.length() > 1) { - Stack<Integer> lStack = new Stack<>(); - boolean inStrVal = false; - for (int i = 0; i < sql.length(); i++) { - switch (sql.charAt(i)) { - case '(': - if (!inStrVal) { - lStack.push(i); - } - break; - case ')': - if (!inStrVal && !lStack.empty()) { - result.put(lStack.pop(), i); - } - break; - case '\'': - inStrVal = !inStrVal; - break; - default: - break; - } - } - } - return result; - } -} http://git-wip-us.apache.org/repos/asf/kylin/blob/bf887a7a/query/src/main/java/org/apache/kylin/query/util/ConvertToComputedColumn.java ---------------------------------------------------------------------- diff --git a/query/src/main/java/org/apache/kylin/query/util/ConvertToComputedColumn.java b/query/src/main/java/org/apache/kylin/query/util/ConvertToComputedColumn.java deleted file mode 100644 index ad42b96..0000000 --- a/query/src/main/java/org/apache/kylin/query/util/ConvertToComputedColumn.java +++ /dev/null @@ -1,248 +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.query.util; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -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.SqlLiteral; -import org.apache.calcite.sql.SqlNode; -import org.apache.calcite.sql.SqlNodeList; -import org.apache.calcite.sql.parser.SqlParseException; -import org.apache.calcite.sql.util.SqlVisitor; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang3.tuple.Pair; -import org.apache.kylin.common.KylinConfig; -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.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.Functions; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSortedMap; -import com.google.common.collect.Ordering; - -public class ConvertToComputedColumn implements QueryUtil.IQueryTransformer { - private static final Logger logger = LoggerFactory.getLogger(ConvertToComputedColumn.class); - - @Override - public String transform(String sql, String project) { - if (project == null) { - return sql; - } - ImmutableSortedMap<String, String> computedColumns = getSortedComputedColumnWithProject(project); - String s = replaceComputedColumn(sql, computedColumns); - if (!StringUtils.equals(sql, s)) { - logger.debug("sql changed"); - } - return s; - } - - static String replaceComputedColumn(String inputSql, ImmutableSortedMap<String, String> computedColumn) { - if (inputSql == null) { - return ""; - } - - if (computedColumn == null || computedColumn.isEmpty()) { - return inputSql; - } - String result = inputSql; - List<Pair<String, String>> toBeReplacedExp = new ArrayList<>(); //{"alias":"expression"}, like {"t1":"t1.a+t1.b+t1.c"} - - for (String ccExp : computedColumn.keySet()) { - List<SqlNode> matchedNodes = new ArrayList<>(); - try { - matchedNodes = getMatchedNodes(inputSql, computedColumn.get(ccExp)); - } catch (SqlParseException e) { - logger.error("Convert to computedColumn Fail,parse sql fail ", e); - return inputSql; - } - for (SqlNode node : matchedNodes) { - Pair<Integer, Integer> startEndPos = CalciteParser.getReplacePos(node, inputSql); - int start = startEndPos.getLeft(); - int end = startEndPos.getRight(); - //add table alias like t1.column,if exists alias - String alias = getTableAlias(node); - toBeReplacedExp.add(Pair.of(alias, inputSql.substring(start, end))); - } - logger.debug("Computed column: " + ccExp + "'s matched list:" + toBeReplacedExp); - //replace user's input sql - for (Pair<String, String> toBeReplaced : toBeReplacedExp) { - result = result.replace(toBeReplaced.getRight(), toBeReplaced.getLeft() + ccExp); - } - } - return result; - } - - //Return matched node's position and its alias(if exists).If can not find matches, return an empty capacity list - private static List<SqlNode> getMatchedNodes(String inputSql, String ccExp) throws SqlParseException { - if (ccExp == null || ccExp.equals("")) { - return new ArrayList<>(); - } - ArrayList<SqlNode> toBeReplacedNodes = new ArrayList<>(); - SqlNode ccNode = CalciteParser.getExpNode(ccExp); - List<SqlNode> inputNodes = getInputTreeNodes(inputSql); - - // find whether user input sql's tree node equals computed columns's define expression - for (SqlNode inputNode : inputNodes) { - if (CalciteParser.isNodeEqual(inputNode, ccNode)) { - toBeReplacedNodes.add(inputNode); - } - } - return toBeReplacedNodes; - } - - private static List<SqlNode> getInputTreeNodes(String inputSql) throws SqlParseException { - SqlTreeVisitor stv = new SqlTreeVisitor(); - CalciteParser.parse(inputSql).accept(stv); - return stv.getSqlNodes(); - } - - private static String getTableAlias(SqlNode node) { - if (node instanceof SqlCall) { - SqlCall call = (SqlCall) node; - return getTableAlias(call.getOperandList()); - } - if (node instanceof SqlIdentifier) { - StringBuilder alias = new StringBuilder(""); - ImmutableList<String> names = ((SqlIdentifier) node).names; - if (names.size() >= 2) { - for (int i = 0; i < names.size() - 1; i++) { - alias.append(names.get(i)).append("."); - } - } - return alias.toString(); - } - if (node instanceof SqlNodeList) { - return ""; - } - if (node instanceof SqlLiteral) { - return ""; - } - return ""; - } - - private static String getTableAlias(List<SqlNode> operands) { - for (SqlNode operand : operands) { - return getTableAlias(operand); - } - return ""; - } - - private ImmutableSortedMap<String, String> getSortedComputedColumnWithProject(String project) { - - Map<String, String> computedColumns = new HashMap<>(); - - MetadataManager metadataManager = MetadataManager.getInstance(KylinConfig.getInstanceFromEnv()); - List<DataModelDesc> dataModelDescs = metadataManager.getModels(project); - for (DataModelDesc dataModelDesc : dataModelDescs) { - for (ComputedColumnDesc computedColumnDesc : dataModelDesc.getComputedColumnDescs()) { - computedColumns.put(computedColumnDesc.getColumnName(), computedColumnDesc.getExpression()); - } - } - - return getMapSortedByValue(computedColumns); - } - - static ImmutableSortedMap<String, String> getMapSortedByValue(Map<String, String> computedColumns) { - if (computedColumns == null || computedColumns.isEmpty()) { - return null; - } - - Ordering<String> ordering = Ordering.from(new Comparator<String>() { - @Override - public int compare(String o1, String o2) { - return Integer.compare(o1.replaceAll("\\s*", "").length(), o2.replaceAll("\\s*", "").length()); - } - }).reverse().nullsLast().onResultOf(Functions.forMap(computedColumns, null)).compound(Ordering.natural()); - return ImmutableSortedMap.copyOf(computedColumns, ordering); - } - -} - -class SqlTreeVisitor implements SqlVisitor<SqlNode> { - private List<SqlNode> sqlNodes; - - SqlTreeVisitor() { - this.sqlNodes = new ArrayList<>(); - } - - List<SqlNode> getSqlNodes() { - return sqlNodes; - } - - @Override - public SqlNode visit(SqlNodeList nodeList) { - sqlNodes.add(nodeList); - for (int i = 0; i < nodeList.size(); i++) { - SqlNode node = nodeList.get(i); - node.accept(this); - } - return null; - } - - @Override - public SqlNode visit(SqlLiteral literal) { - sqlNodes.add(literal); - return null; - } - - @Override - public SqlNode visit(SqlCall call) { - sqlNodes.add(call); - for (SqlNode operand : call.getOperandList()) { - if (operand != null) { - operand.accept(this); - } - } - return null; - } - - @Override - public SqlNode visit(SqlIdentifier id) { - sqlNodes.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; - } -} http://git-wip-us.apache.org/repos/asf/kylin/blob/bf887a7a/query/src/main/java/org/apache/kylin/query/util/QueryUtil.java ---------------------------------------------------------------------- diff --git a/query/src/main/java/org/apache/kylin/query/util/QueryUtil.java b/query/src/main/java/org/apache/kylin/query/util/QueryUtil.java index eff9f6d..29e2c26 100644 --- a/query/src/main/java/org/apache/kylin/query/util/QueryUtil.java +++ b/query/src/main/java/org/apache/kylin/query/util/QueryUtil.java @@ -76,7 +76,7 @@ public class QueryUtil { IQueryTransformer t = (IQueryTransformer) ClassUtil.newInstance(clz); transformers.add(t); } catch (Exception e) { - logger.error("Failed to init query transformer", e); + throw new RuntimeException("Failed to init query transformer", e); } } queryTransformers = transformers; http://git-wip-us.apache.org/repos/asf/kylin/blob/bf887a7a/query/src/test/java/org/apache/kylin/query/util/CognosParenthesesEscapeTest.java ---------------------------------------------------------------------- diff --git a/query/src/test/java/org/apache/kylin/query/util/CognosParenthesesEscapeTest.java b/query/src/test/java/org/apache/kylin/query/util/CognosParenthesesEscapeTest.java deleted file mode 100644 index 7825dbd..0000000 --- a/query/src/test/java/org/apache/kylin/query/util/CognosParenthesesEscapeTest.java +++ /dev/null @@ -1,89 +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.query.util; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.Collection; - -import org.apache.commons.io.FileUtils; -import org.junit.Assert; -import org.junit.Test; - -public class CognosParenthesesEscapeTest { - - @Test - public void basicTest() { - CognosParenthesesEscape escape = new CognosParenthesesEscape(); - String data = " from ((a left outer join b on a.x1 = b.y1 and a.x2=b.y2 and a.x3= b.y3) inner join c as cc on a.x1=cc.z1 ) join d dd on a.x1=d.w1 and a.x2 =d.w2 "; - String expected = " from a left outer join b on a.x1 = b.y1 and a.x2=b.y2 and a.x3= b.y3 inner join c as cc on a.x1=cc.z1 join d dd on a.x1=d.w1 and a.x2 =d.w2 "; - String transformed = escape.transform(data, null); - Assert.assertEquals(expected, transformed); - } - - @Test - public void advanced1Test() throws IOException { - CognosParenthesesEscape escape = new CognosParenthesesEscape(); - String query = FileUtils.readFileToString(new File("src/test/resources/query/cognos/query01.sql"), - Charset.defaultCharset()); - String expected = FileUtils.readFileToString(new File("src/test/resources/query/cognos/query01.sql.expected"), - Charset.defaultCharset()); - String transformed = escape.transform(query, null); - //System.out.println(transformed); - Assert.assertEquals(expected, transformed); - } - - @Test - public void advanced2Test() throws IOException { - CognosParenthesesEscape escape = new CognosParenthesesEscape(); - String query = FileUtils.readFileToString(new File("src/test/resources/query/cognos/query02.sql"), - Charset.defaultCharset()); - String expected = FileUtils.readFileToString(new File("src/test/resources/query/cognos/query02.sql.expected"), - Charset.defaultCharset()); - String transformed = escape.transform(query, null); - //System.out.println(transformed); - Assert.assertEquals(expected, transformed); - } - - @Test - public void advanced3Test() throws IOException { - CognosParenthesesEscape escape = new CognosParenthesesEscape(); - String query = FileUtils.readFileToString(new File("src/test/resources/query/cognos/query03.sql"), - Charset.defaultCharset()); - String expected = FileUtils.readFileToString(new File("src/test/resources/query/cognos/query03.sql.expected"), - Charset.defaultCharset()); - String transformed = escape.transform(query, null); - //System.out.println(transformed); - Assert.assertEquals(expected, transformed); - } - - @Test - public void proguardTest() throws IOException { - CognosParenthesesEscape escape = new CognosParenthesesEscape(); - Collection<File> files = FileUtils.listFiles(new File("../kylin-it/src/test/resources"), new String[] { "sql" }, - true); - for (File f : files) { - System.out.println("checking " + f.getAbsolutePath()); - String query = FileUtils.readFileToString(f, Charset.defaultCharset()); - String transformed = escape.transform(query, null); - Assert.assertEquals(query, transformed); - } - } -} http://git-wip-us.apache.org/repos/asf/kylin/blob/bf887a7a/query/src/test/java/org/apache/kylin/query/util/ConvertToComputedColumnTest.java ---------------------------------------------------------------------- diff --git a/query/src/test/java/org/apache/kylin/query/util/ConvertToComputedColumnTest.java b/query/src/test/java/org/apache/kylin/query/util/ConvertToComputedColumnTest.java deleted file mode 100644 index d9910fe..0000000 --- a/query/src/test/java/org/apache/kylin/query/util/ConvertToComputedColumnTest.java +++ /dev/null @@ -1,124 +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.query.util; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.calcite.sql.parser.SqlParseException; -import org.junit.Assert; -import org.junit.Test; - -import com.google.common.collect.ImmutableSortedMap; - -public class ConvertToComputedColumnTest { - - @Test - public void testErrorCase() { - //computed column is null or empty - String sql = "select a from t"; - Map<String, String> map = new HashMap<>(); - ImmutableSortedMap<String, String> computedColumns = ConvertToComputedColumn.getMapSortedByValue(map); - Assert.assertEquals("select a from t", ConvertToComputedColumn.replaceComputedColumn(sql, null)); - Assert.assertEquals("select a from t", ConvertToComputedColumn.replaceComputedColumn(sql, computedColumns)); - - //input is null or empty or parse error - String sql1 = ""; - String sql2 = "select sum(a from t"; - Map<String, String> map2 = new HashMap<>(); - map2.put("cc", "a + b"); - ImmutableSortedMap<String, String> computedColumns2 = ConvertToComputedColumn.getMapSortedByValue(map2); - Assert.assertEquals("", ConvertToComputedColumn.replaceComputedColumn(null, computedColumns2)); - Assert.assertEquals("", ConvertToComputedColumn.replaceComputedColumn(sql1, computedColumns2)); - Assert.assertEquals("select sum(a from t", - ConvertToComputedColumn.replaceComputedColumn(sql2, computedColumns2)); - } - - @Test - public void testReplaceComputedColumn() throws SqlParseException { - String sql0 = "select (\"DB\".\"t1\" . \"a\" + DB.t1.b + DB.t1.c) as c, substring(substring(lstg_format_name,1,3),1,3) as d from table1 as t1 group by t1.a+ t1.b + t1.c having t1.a+t1.b+t1.c > 100 order by t1.a +t1.b +t1.c"; - String sql1 = "select sum(sum(a)) from t"; - String sql2 = "select t1.a + t1.b as aa, t2.c + t2.d as bb from table1 t1,table2 t2 where t1.a + t1.b > t2.c + t2.d order by t1.a + t1.b"; - String sql3 = "select substring(substring(lstg_format_name,1,3),1,3) from a"; - - String expr0 = "a + b + c"; - String expr1 = "sum(a)"; - String expr2 = "a + b"; - String expr3 = "c + d"; - String expr = "substring(substring(lstg_format_name,1,3),1,3)"; - - Map<String, String> map = new HashMap<>(); - map.put("cc0", expr0); - map.put("cc1", expr1); - map.put("cc2", expr2); - map.put("cc3", expr3); - map.put("cc", expr); - - ImmutableSortedMap<String, String> computedColumns = ConvertToComputedColumn.getMapSortedByValue(map); - Assert.assertEquals( - "select (DB.t1.cc0) as c, cc as d from table1 as t1 group by T1.cc0 having T1.cc0 > 100 order by T1.cc0", - ConvertToComputedColumn.replaceComputedColumn(sql0, computedColumns)); - Assert.assertEquals("select sum(cc1) from t", - ConvertToComputedColumn.replaceComputedColumn(sql1, computedColumns)); - Assert.assertEquals( - "select T1.cc2 as aa, T2.cc3 as bb from table1 t1,table2 t2 where T1.cc2 > T2.cc3 order by T1.cc2", - ConvertToComputedColumn.replaceComputedColumn(sql2, computedColumns)); - Assert.assertEquals("select cc from a", ConvertToComputedColumn.replaceComputedColumn(sql3, computedColumns)); - - } - - @Test - public void testTwoCCHasSameSubExp() { - String sql0 = "select a + b + c from t order by a + b"; - - String expr0 = "a + b"; - String expr1 = "a + b + c"; - - Map<String, String> map = new HashMap<>(); - map.put("cc1", expr0); - map.put("cc0", expr1); - ImmutableSortedMap<String, String> computedColumns = ConvertToComputedColumn.getMapSortedByValue(map); - Assert.assertEquals("select cc0 from t order by cc1", - ConvertToComputedColumn.replaceComputedColumn(sql0, computedColumns)); - - //é²æ¢æ·»å ç顺åºé æå½±å - String expr11 = "a + b + c"; - String expr00 = "a + b"; - - Map<String, String> map2 = new HashMap<>(); - map2.put("cc0", expr11); - map2.put("cc1", expr00); - ImmutableSortedMap<String, String> computedColumns1 = ConvertToComputedColumn.getMapSortedByValue(map2); - Assert.assertEquals("select cc0 from t order by cc1", - ConvertToComputedColumn.replaceComputedColumn(sql0, computedColumns1)); - - } - - @Test - public void testCCWithBrackets() { - String sql0 = "select ( a + b) + (c+d \t\n) from t"; - String expr1 = "a + b + (c + d)"; - - Map<String, String> map = new HashMap<>(); - map.put("cc0", expr1); - ImmutableSortedMap<String, String> computedColumns = ConvertToComputedColumn.getMapSortedByValue(map); - Assert.assertEquals("select cc0 from t", - ConvertToComputedColumn.replaceComputedColumn(sql0, computedColumns)); - } -} http://git-wip-us.apache.org/repos/asf/kylin/blob/bf887a7a/query/src/test/resources/query/cognos/query01.sql ---------------------------------------------------------------------- diff --git a/query/src/test/resources/query/cognos/query01.sql b/query/src/test/resources/query/cognos/query01.sql deleted file mode 100644 index a76b4e1..0000000 --- a/query/src/test/resources/query/cognos/query01.sql +++ /dev/null @@ -1,28 +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. --- - -SELECT "TABLE1"."DIM1_1" "DIM1_1" - ,"TABLE2"."DIM2_1" "DIM2_1" - ,SUM("FACT"."M1") "M1" - ,SUM("FACT"."M2") "M2" - FROM ("COGNOS"."FACT" "FACT" LEFT OUTER JOIN "COGNOS"."TABLE1" - "TABLE1" ON "FACT"."FK_1" = "TABLE1"."PK_1") - LEFT OUTER JOIN "COGNOS"."TABLE2" "TABLE2" - ON "FACT"."FK_2" = "TABLE2"."PK_2" - GROUP BY "TABLE2"."DIM2_1" - ,"TABLE1"."DIM1_1"; http://git-wip-us.apache.org/repos/asf/kylin/blob/bf887a7a/query/src/test/resources/query/cognos/query01.sql.expected ---------------------------------------------------------------------- diff --git a/query/src/test/resources/query/cognos/query01.sql.expected b/query/src/test/resources/query/cognos/query01.sql.expected deleted file mode 100644 index c8005fc..0000000 --- a/query/src/test/resources/query/cognos/query01.sql.expected +++ /dev/null @@ -1,28 +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. --- - -SELECT "TABLE1"."DIM1_1" "DIM1_1" - ,"TABLE2"."DIM2_1" "DIM2_1" - ,SUM("FACT"."M1") "M1" - ,SUM("FACT"."M2") "M2" - FROM "COGNOS"."FACT" "FACT" LEFT OUTER JOIN "COGNOS"."TABLE1" - "TABLE1" ON "FACT"."FK_1" = "TABLE1"."PK_1" - LEFT OUTER JOIN "COGNOS"."TABLE2" "TABLE2" - ON "FACT"."FK_2" = "TABLE2"."PK_2" - GROUP BY "TABLE2"."DIM2_1" - ,"TABLE1"."DIM1_1"; http://git-wip-us.apache.org/repos/asf/kylin/blob/bf887a7a/query/src/test/resources/query/cognos/query02.sql ---------------------------------------------------------------------- diff --git a/query/src/test/resources/query/cognos/query02.sql b/query/src/test/resources/query/cognos/query02.sql deleted file mode 100644 index 935251d..0000000 --- a/query/src/test/resources/query/cognos/query02.sql +++ /dev/null @@ -1,27 +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. --- - -SELECT "X1"."DIM1_1" "DIM1_1" - ,"TABLE2"."DIM2_1" "DIM2_1" - ,SUM("FACT"."M1") "M1" - ,SUM("FACT"."M2") "M2" - FROM ("COGNOS"."FACT" "FACT" LEFT OUTER JOIN (SELECT "DIM1_1", "PK_1" FROM COGNOS"."TABLE1" WHERE DIM1_1 = '1') "X1" ON "FACT"."FK_1" = "X1"."PK_1") - LEFT OUTER JOIN "COGNOS"."TABLE2" "TABLE2" - ON "FACT"."FK_2" = "TABLE2"."PK_2" - GROUP BY "TABLE2"."DIM2_1" - ,"X1"."DIM1_1"; http://git-wip-us.apache.org/repos/asf/kylin/blob/bf887a7a/query/src/test/resources/query/cognos/query02.sql.expected ---------------------------------------------------------------------- diff --git a/query/src/test/resources/query/cognos/query02.sql.expected b/query/src/test/resources/query/cognos/query02.sql.expected deleted file mode 100644 index 4d4f016..0000000 --- a/query/src/test/resources/query/cognos/query02.sql.expected +++ /dev/null @@ -1,27 +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. --- - -SELECT "X1"."DIM1_1" "DIM1_1" - ,"TABLE2"."DIM2_1" "DIM2_1" - ,SUM("FACT"."M1") "M1" - ,SUM("FACT"."M2") "M2" - FROM "COGNOS"."FACT" "FACT" LEFT OUTER JOIN (SELECT "DIM1_1", "PK_1" FROM COGNOS"."TABLE1" WHERE DIM1_1 = '1') "X1" ON "FACT"."FK_1" = "X1"."PK_1" - LEFT OUTER JOIN "COGNOS"."TABLE2" "TABLE2" - ON "FACT"."FK_2" = "TABLE2"."PK_2" - GROUP BY "TABLE2"."DIM2_1" - ,"X1"."DIM1_1"; http://git-wip-us.apache.org/repos/asf/kylin/blob/bf887a7a/query/src/test/resources/query/cognos/query03.sql ---------------------------------------------------------------------- diff --git a/query/src/test/resources/query/cognos/query03.sql b/query/src/test/resources/query/cognos/query03.sql deleted file mode 100644 index bfa483f..0000000 --- a/query/src/test/resources/query/cognos/query03.sql +++ /dev/null @@ -1,29 +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. --- - -SELECT "X1"."DIM1_1" "DIM1_1" - ,"TABLE2"."DIM2_1" "DIM2_1" - ,SUM("FACT"."M1") "M1" - ,SUM("FACT"."M2") "M2" - FROM - ( ( - SELECT "F1" FROM "T1") X0 LEFT OUTER JOIN (SELECT "DIM1_1", "PK_1" FROM COGNOS"."TABLE1" WHERE DIM1_1 = '1') "X1" ON "FACT"."FK_1" = "X1"."PK_1") - LEFT OUTER JOIN "COGNOS"."TABLE2" "TABLE2" - ON "FACT"."FK_2" = "TABLE2"."PK_2" - GROUP BY "TABLE2"."DIM2_1" - ,"X1"."DIM1_1"; http://git-wip-us.apache.org/repos/asf/kylin/blob/bf887a7a/query/src/test/resources/query/cognos/query03.sql.expected ---------------------------------------------------------------------- diff --git a/query/src/test/resources/query/cognos/query03.sql.expected b/query/src/test/resources/query/cognos/query03.sql.expected deleted file mode 100644 index 20215a9..0000000 --- a/query/src/test/resources/query/cognos/query03.sql.expected +++ /dev/null @@ -1,29 +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. --- - -SELECT "X1"."DIM1_1" "DIM1_1" - ,"TABLE2"."DIM2_1" "DIM2_1" - ,SUM("FACT"."M1") "M1" - ,SUM("FACT"."M2") "M2" - FROM - ( - SELECT "F1" FROM "T1") X0 LEFT OUTER JOIN (SELECT "DIM1_1", "PK_1" FROM COGNOS"."TABLE1" WHERE DIM1_1 = '1') "X1" ON "FACT"."FK_1" = "X1"."PK_1" - LEFT OUTER JOIN "COGNOS"."TABLE2" "TABLE2" - ON "FACT"."FK_2" = "TABLE2"."PK_2" - GROUP BY "TABLE2"."DIM2_1" - ,"X1"."DIM1_1";