You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2016/11/08 16:15:41 UTC

[03/18] kylin git commit: Add UDF version() to get kylin version, Add UT

Add UDF version() to get kylin version, Add UT

Signed-off-by: Hongbin Ma <ma...@apache.org>

Update kylin properties's UDF setting

Signed-off-by: Hongbin Ma <ma...@apache.org>

Add IT cases of version() and query output check.

Signed-off-by: Hongbin Ma <ma...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/637581fb
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/637581fb
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/637581fb

Branch: refs/heads/KYLIN-2006
Commit: 637581fb7f9b1ae1a3abde93795755aaceea4ecf
Parents: 408f9d4
Author: Yifan Zhang <ev...@gmail.com>
Authored: Tue Oct 18 16:12:07 2016 +0800
Committer: Hongbin Ma <ma...@apache.org>
Committed: Tue Nov 8 14:50:15 2016 +0800

----------------------------------------------------------------------
 build/conf/kylin.properties                     |  2 ++
 .../test_case_data/sandbox/kylin.properties     |  1 +
 .../apache/kylin/query/ITKylinQueryTest.java    | 28 +++++++++++++++++++-
 .../org/apache/kylin/query/KylinTestBase.java   | 25 +++++++++++++++++
 .../query/sql_verifyContent/query01.sql         | 21 +++++++++++++++
 .../sql_verifyContent/query01.sql.expected.xml  |  4 +++
 .../org/apache/kylin/query/udf/VersionUDF.java  | 27 +++++++++++++++++++
 .../apache/kylin/query/udf/VersionUDFTest.java  | 15 +++++++++++
 8 files changed, 122 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/637581fb/build/conf/kylin.properties
----------------------------------------------------------------------
diff --git a/build/conf/kylin.properties b/build/conf/kylin.properties
index 91aa5b8..e935ebf 100644
--- a/build/conf/kylin.properties
+++ b/build/conf/kylin.properties
@@ -135,6 +135,8 @@ kylin.table.snapshot.max_mb=300
 
 kylin.query.scan.threshold=10000000
 
+kylin.query.udf.version=org.apache.kylin.query.udf.VersionUDF
+
 # 3G
 kylin.query.mem.budget=3221225472
 

http://git-wip-us.apache.org/repos/asf/kylin/blob/637581fb/examples/test_case_data/sandbox/kylin.properties
----------------------------------------------------------------------
diff --git a/examples/test_case_data/sandbox/kylin.properties b/examples/test_case_data/sandbox/kylin.properties
index 43b0855..0efd5c9 100644
--- a/examples/test_case_data/sandbox/kylin.properties
+++ b/examples/test_case_data/sandbox/kylin.properties
@@ -104,6 +104,7 @@ kylin.hbase.region.count.max=5
 kylin.hbase.hfile.size.gb=2
 
 kylin.query.udf.massin=org.apache.kylin.query.udf.MassInUDF
+kylin.query.udf.version=org.apache.kylin.query.udf.VersionUDF
 
 kylin.job.controller.lock=org.apache.kylin.job.lock.MockJobLock
 

http://git-wip-us.apache.org/repos/asf/kylin/blob/637581fb/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 520c5e6..9c1b640 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
@@ -27,6 +27,7 @@ import java.util.Map;
 
 import org.apache.commons.lang3.StringUtils;
 import org.apache.kylin.common.KylinConfig;
+import org.apache.kylin.common.KylinVersion;
 import org.apache.kylin.common.debug.BackdoorToggles;
 import org.apache.kylin.gridtable.GTScanSelfTerminatedException;
 import org.apache.kylin.gridtable.StorageSideBehavior;
@@ -36,7 +37,9 @@ import org.apache.kylin.query.routing.rules.RemoveBlackoutRealizationsRule;
 import org.apache.kylin.storage.hbase.HBaseStorage;
 import org.dbunit.database.DatabaseConnection;
 import org.dbunit.database.IDatabaseConnection;
+import org.dbunit.dataset.ITable;
 import org.junit.AfterClass;
+import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Rule;
@@ -199,11 +202,16 @@ public class ITKylinQueryTest extends KylinTestBase {
     }
 
     @Test
-    public void testVerifyQuery() throws Exception {
+    public void testVerifyCountQuery() throws Exception {
         verifyResultRowCount(getQueryFolderPrefix() + "src/test/resources/query/sql_verifyCount");
     }
 
     @Test
+    public void testVerifyContentQuery() throws Exception {
+        verifyResultContent(getQueryFolderPrefix() + "src/test/resources/query/sql_verifyContent");
+    }
+
+    @Test
     public void testOrderByQuery() throws Exception {
         execAndCompQuery(getQueryFolderPrefix() + "src/test/resources/query/sql_orderby", null, true);
         // FIXME
@@ -364,4 +372,22 @@ public class ITKylinQueryTest extends KylinTestBase {
         this.batchExecuteQuery(getQueryFolderPrefix() + "src/test/resources/query/sql_window");
     }
 
+    @Test
+    public void testVersionQuery() throws Exception {
+        String expectVersion = KylinVersion.getCurrentVersion().toString();
+        printInfo("---------- verify expect version: " + expectVersion);
+
+        String queryName = "QueryKylinVersion";
+        String sql = "SELECT VERSION() AS version";
+
+        // execute Kylin
+        printInfo("Query Result from Kylin - " + queryName);
+        IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
+        ITable kylinTable = executeQuery(kylinConn, queryName, sql, false);
+        String queriedVersion = String.valueOf(kylinTable.getValue(0, "version"));
+        
+
+        // compare the result
+        Assert.assertEquals(expectVersion, queriedVersion);
+    }
 }

http://git-wip-us.apache.org/repos/asf/kylin/blob/637581fb/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 57c4f4d..52461c4 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
@@ -58,10 +58,12 @@ import org.dbunit.database.DatabaseConfig;
 import org.dbunit.database.DatabaseConnection;
 import org.dbunit.database.IDatabaseConnection;
 import org.dbunit.dataset.DataSetException;
+import org.dbunit.dataset.IDataSet;
 import org.dbunit.dataset.ITable;
 import org.dbunit.dataset.SortedTable;
 import org.dbunit.dataset.datatype.DataType;
 import org.dbunit.dataset.datatype.DataTypeException;
+import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
 import org.dbunit.ext.h2.H2Connection;
 import org.dbunit.ext.h2.H2DataTypeFactory;
 import org.junit.Assert;
@@ -360,6 +362,29 @@ public class KylinTestBase {
         }
     }
 
+    protected void verifyResultContent(String queryFolder) throws Exception {
+        printInfo("---------- verify result content in folder: " + queryFolder);
+
+        List<File> sqlFiles = getFilesFromFolder(new File(queryFolder), ".sql");
+        for (File sqlFile : sqlFiles) {
+            String queryName = StringUtils.split(sqlFile.getName(), '.')[0];
+            String sql = getTextFromFile(sqlFile);
+
+            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");   
+
+            // execute Kylin
+            printInfo("Query Result from Kylin - " + queryName + "  (" + queryFolder + ")");
+            IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
+            ITable kylinTable = executeQuery(kylinConn, queryName, sql, false);
+
+            // compare the result
+            Assertion.assertEquals(expectTable, kylinTable);
+        }
+    }
+
     protected void execAndCompResultSize(String queryFolder, String[] exclusiveQuerys, boolean needSort) throws Exception {
         printInfo("---------- test folder: " + queryFolder);
         Set<String> exclusiveSet = buildExclusiveSet(exclusiveQuerys);

http://git-wip-us.apache.org/repos/asf/kylin/blob/637581fb/kylin-it/src/test/resources/query/sql_verifyContent/query01.sql
----------------------------------------------------------------------
diff --git a/kylin-it/src/test/resources/query/sql_verifyContent/query01.sql b/kylin-it/src/test/resources/query/sql_verifyContent/query01.sql
new file mode 100644
index 0000000..ffec3bf
--- /dev/null
+++ b/kylin-it/src/test/resources/query/sql_verifyContent/query01.sql
@@ -0,0 +1,21 @@
+--
+-- 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.
+--
+
+-- This is a sample case
+
+SELECT 'Hello world' AS message
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/kylin/blob/637581fb/kylin-it/src/test/resources/query/sql_verifyContent/query01.sql.expected.xml
----------------------------------------------------------------------
diff --git a/kylin-it/src/test/resources/query/sql_verifyContent/query01.sql.expected.xml b/kylin-it/src/test/resources/query/sql_verifyContent/query01.sql.expected.xml
new file mode 100644
index 0000000..d858aa9
--- /dev/null
+++ b/kylin-it/src/test/resources/query/sql_verifyContent/query01.sql.expected.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<dataset>
+  <expect message="Hello world" />
+</dataset>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/kylin/blob/637581fb/query/src/main/java/org/apache/kylin/query/udf/VersionUDF.java
----------------------------------------------------------------------
diff --git a/query/src/main/java/org/apache/kylin/query/udf/VersionUDF.java b/query/src/main/java/org/apache/kylin/query/udf/VersionUDF.java
new file mode 100644
index 0000000..cbd0f22
--- /dev/null
+++ b/query/src/main/java/org/apache/kylin/query/udf/VersionUDF.java
@@ -0,0 +1,27 @@
+/*
+ * 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.udf;
+
+import org.apache.kylin.common.KylinVersion;
+
+public class VersionUDF {
+    public String eval() {
+        return KylinVersion.getCurrentVersion().toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/kylin/blob/637581fb/query/src/test/java/org/apache/kylin/query/udf/VersionUDFTest.java
----------------------------------------------------------------------
diff --git a/query/src/test/java/org/apache/kylin/query/udf/VersionUDFTest.java b/query/src/test/java/org/apache/kylin/query/udf/VersionUDFTest.java
new file mode 100644
index 0000000..98cced4
--- /dev/null
+++ b/query/src/test/java/org/apache/kylin/query/udf/VersionUDFTest.java
@@ -0,0 +1,15 @@
+package org.apache.kylin.query.udf;
+
+import static org.junit.Assert.assertTrue;
+
+import org.apache.kylin.common.KylinVersion;
+import org.junit.Test;
+
+public class VersionUDFTest {
+    @Test
+    public void testVersionUDF() {
+        String currentVer = KylinVersion.getCurrentVersion().toString();
+        String udfVer = new VersionUDF().eval();
+        assertTrue(currentVer.equals(udfVer));
+    }
+}