minor, refactor ITKylinQueryTest, move select * queries to sql files
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/7ce3a153 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/7ce3a153 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/7ce3a153 Branch: refs/heads/master-hbase0.98 Commit: 7ce3a153cdb63b874e68b29518cd6bb0836a9d57 Parents: 36f716f Author: Li Yang <liy...@apache.org> Authored: Tue Feb 21 17:29:13 2017 +0800 Committer: Li Yang <liy...@apache.org> Committed: Tue Feb 21 17:29:13 2017 +0800 ---------------------------------------------------------------------- .../apache/kylin/query/ITKylinQueryTest.java | 9 +--- .../org/apache/kylin/query/KylinTestBase.java | 43 +++++++++++++++----- .../resources/query/sql_verifyCount/query01.sql | 19 +++++++++ .../query/sql_verifyCount/query01.sql.expected | 2 + .../resources/query/sql_verifyCount/query03.sql | 22 ++++++++++ .../query/sql_verifyCount/query03.sql.expected | 2 + .../query/sql_verifyCount/query04.sql.expected | 1 + 7 files changed, 79 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/7ce3a153/kylin-it/src/test/java/org/apache/kylin/query/ITKylinQueryTest.java ---------------------------------------------------------------------- diff --git a/kylin-it/src/test/java/org/apache/kylin/query/ITKylinQueryTest.java b/kylin-it/src/test/java/org/apache/kylin/query/ITKylinQueryTest.java index d30371a..842ce40 100644 --- a/kylin-it/src/test/java/org/apache/kylin/query/ITKylinQueryTest.java +++ b/kylin-it/src/test/java/org/apache/kylin/query/ITKylinQueryTest.java @@ -210,7 +210,7 @@ public class ITKylinQueryTest extends KylinTestBase { @Test public void testVerifyCountQuery() throws Exception { - verifyResultRowCount(getQueryFolderPrefix() + "src/test/resources/query/sql_verifyCount"); + verifyResultRowColCount(getQueryFolderPrefix() + "src/test/resources/query/sql_verifyCount"); } @Test @@ -393,13 +393,6 @@ public class ITKylinQueryTest extends KylinTestBase { } @Test - public void testSelectStarColumnCount() throws Exception { - execAndCompColumnCount("select * from test_kylin_fact limit 10", 11); - execAndCompColumnCount("select * from test_kylin_fact", 11); - execAndCompColumnCount("select * from test_kylin_fact left join edw.test_cal_dt on test_kylin_fact.cal_dt = edw.test_cal_dt.CAL_DT limit 10", 13); - } - - @Test public void testPercentileQuery() throws Exception { batchExecuteQuery(getQueryFolderPrefix() + "src/test/resources/query/sql_percentile"); } http://git-wip-us.apache.org/repos/asf/kylin/blob/7ce3a153/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 d83ad75..402aaa0 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 @@ -46,6 +46,7 @@ import java.util.logging.LogManager; import org.apache.commons.lang3.StringUtils; import org.apache.kylin.common.KylinConfig; import org.apache.kylin.common.util.HBaseMetadataTestCase; +import org.apache.kylin.common.util.Pair; import org.apache.kylin.metadata.project.ProjectInstance; import org.apache.kylin.query.relnode.OLAPContext; import org.apache.kylin.query.routing.rules.RemoveBlackoutRealizationsRule; @@ -233,7 +234,7 @@ public class KylinTestBase { for (int i = 0; i < columnNames.length; i++) { columnNames[i] = queryTable.getTableMetaData().getColumns()[i].getColumnName(); } - + queryTable = new SortedTable(queryTable, columnNames); } if (PRINT_RESULT) @@ -337,7 +338,7 @@ public class KylinTestBase { } } - protected void verifyResultRowCount(String queryFolder) throws Exception { + protected void verifyResultRowColCount(String queryFolder) throws Exception { printInfo("---------- verify result count in folder: " + queryFolder); List<File> sqlFiles = getFilesFromFolder(new File(queryFolder), ".sql"); @@ -346,7 +347,9 @@ public class KylinTestBase { String sql = getTextFromFile(sqlFile); File expectResultFile = new File(sqlFile.getParent(), sqlFile.getName() + ".expected"); - int expectRowCount = Integer.parseInt(Files.readFirstLine(expectResultFile, Charset.defaultCharset())); + Pair<Integer, Integer> pair = getExpectedRowAndCol(expectResultFile); + int expectRowCount = pair.getFirst(); + int expectColCount = pair.getSecond(); // execute Kylin printInfo("Query Result from Kylin - " + queryName + " (" + queryFolder + ")"); @@ -354,11 +357,29 @@ public class KylinTestBase { ITable kylinTable = executeQuery(kylinConn, queryName, sql, false); // compare the result - Assert.assertEquals(queryName, expectRowCount, kylinTable.getRowCount()); - // assertTableEquals(expectRowCount, kylinTable.getRowCount()); + if (expectRowCount >= 0) + Assert.assertEquals(queryName, expectRowCount, kylinTable.getRowCount()); + + if (expectColCount >= 0) + Assert.assertEquals(queryName, expectColCount, kylinTable.getTableMetaData().getColumns().length); } } + private Pair<Integer, Integer> getExpectedRowAndCol(File expectResultFile) throws IOException { + List<String> lines = Files.readLines(expectResultFile, Charset.forName("UTF-8")); + int row = -1; + int col = -1; + try { + row = Integer.parseInt(lines.get(0).trim()); + } catch (Exception ex) { + } + try { + col = Integer.parseInt(lines.get(1).trim()); + } catch (Exception ex) { + } + return Pair.newPair(row, col); + } + protected void verifyResultContent(String queryFolder) throws Exception { printInfo("---------- verify result content in folder: " + queryFolder); @@ -370,7 +391,7 @@ public class KylinTestBase { File expectResultFile = new File(sqlFile.getParent(), sqlFile.getName() + ".expected.xml"); IDataSet expect = new FlatXmlDataSetBuilder().build(expectResultFile); // Get expected table named "expect". FIXME Only support default table name - ITable expectTable = expect.getTable("expect"); + ITable expectTable = expect.getTable("expect"); // execute Kylin printInfo("Query Result from Kylin - " + queryName + " (" + queryFolder + ")"); @@ -421,13 +442,13 @@ public class KylinTestBase { protected void execAndCompColumnCount(String input, int expectedColumnCount) throws Exception { printInfo("---------- test column count: " + input); Set<String> sqlSet = ImmutableSet.of(input); - + for (String sql : sqlSet) { // execute Kylin printInfo("Query Result from Kylin - " + sql); IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection); ITable kylinTable = executeQuery(kylinConn, sql, sql, false); - + try { // compare the result Assert.assertEquals(expectedColumnCount, kylinTable.getTableMetaData().getColumns().length); @@ -437,7 +458,7 @@ public class KylinTestBase { } } } - + protected void execLimitAndValidate(String queryFolder) throws Exception { printInfo("---------- test folder: " + new File(queryFolder).getAbsolutePath()); @@ -543,13 +564,13 @@ public class KylinTestBase { assertTableEquals(h2Table, kylinTable); } } - + protected void assertTableEquals(ITable h2Table, ITable kylinTable) throws DatabaseUnitException { HackedDbUnitAssert dbUnit = new HackedDbUnitAssert(); dbUnit.hackIgnoreIntBigIntMismatch(); dbUnit.assertEquals(h2Table, kylinTable); } - + protected void assertTableContains(ITable h2Table, ITable kylinTable) throws DatabaseUnitException { HackedDbUnitAssert dbUnit = new HackedDbUnitAssert(); dbUnit.hackIgnoreIntBigIntMismatch(); http://git-wip-us.apache.org/repos/asf/kylin/blob/7ce3a153/kylin-it/src/test/resources/query/sql_verifyCount/query01.sql ---------------------------------------------------------------------- diff --git a/kylin-it/src/test/resources/query/sql_verifyCount/query01.sql b/kylin-it/src/test/resources/query/sql_verifyCount/query01.sql new file mode 100644 index 0000000..ae25894 --- /dev/null +++ b/kylin-it/src/test/resources/query/sql_verifyCount/query01.sql @@ -0,0 +1,19 @@ +-- +-- 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 * from test_kylin_fact http://git-wip-us.apache.org/repos/asf/kylin/blob/7ce3a153/kylin-it/src/test/resources/query/sql_verifyCount/query01.sql.expected ---------------------------------------------------------------------- diff --git a/kylin-it/src/test/resources/query/sql_verifyCount/query01.sql.expected b/kylin-it/src/test/resources/query/sql_verifyCount/query01.sql.expected new file mode 100644 index 0000000..86242f2 --- /dev/null +++ b/kylin-it/src/test/resources/query/sql_verifyCount/query01.sql.expected @@ -0,0 +1,2 @@ +* +11 http://git-wip-us.apache.org/repos/asf/kylin/blob/7ce3a153/kylin-it/src/test/resources/query/sql_verifyCount/query03.sql ---------------------------------------------------------------------- diff --git a/kylin-it/src/test/resources/query/sql_verifyCount/query03.sql b/kylin-it/src/test/resources/query/sql_verifyCount/query03.sql new file mode 100644 index 0000000..93ef871 --- /dev/null +++ b/kylin-it/src/test/resources/query/sql_verifyCount/query03.sql @@ -0,0 +1,22 @@ +-- +-- 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 * +from +test_kylin_fact left join edw.test_cal_dt on test_kylin_fact.cal_dt = edw.test_cal_dt.CAL_DT +limit 10 http://git-wip-us.apache.org/repos/asf/kylin/blob/7ce3a153/kylin-it/src/test/resources/query/sql_verifyCount/query03.sql.expected ---------------------------------------------------------------------- diff --git a/kylin-it/src/test/resources/query/sql_verifyCount/query03.sql.expected b/kylin-it/src/test/resources/query/sql_verifyCount/query03.sql.expected new file mode 100644 index 0000000..093e327 --- /dev/null +++ b/kylin-it/src/test/resources/query/sql_verifyCount/query03.sql.expected @@ -0,0 +1,2 @@ +10 +13 http://git-wip-us.apache.org/repos/asf/kylin/blob/7ce3a153/kylin-it/src/test/resources/query/sql_verifyCount/query04.sql.expected ---------------------------------------------------------------------- diff --git a/kylin-it/src/test/resources/query/sql_verifyCount/query04.sql.expected b/kylin-it/src/test/resources/query/sql_verifyCount/query04.sql.expected index 29d6383..71011db 100644 --- a/kylin-it/src/test/resources/query/sql_verifyCount/query04.sql.expected +++ b/kylin-it/src/test/resources/query/sql_verifyCount/query04.sql.expected @@ -1 +1,2 @@ 100 +11