You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by bz...@apache.org on 2016/12/14 03:57:17 UTC
zeppelin git commit: [ZEPPELIN-1512] Support Kylin project name in
interpreter runtime
Repository: zeppelin
Updated Branches:
refs/heads/master 641a641c3 -> 75441540f
[ZEPPELIN-1512] Support Kylin project name in interpreter runtime
### What is this PR for?
Currently, the parameter "project" is defined with "kylin.query.project" in properties. It's not convenience when query Kylin among different projects. May I propose introducing %kylin(project_name) at the interpreter runtime? If not set, the default project will work, otherwise, will use explicit project_name for the query request.
### What type of PR is it?
Improvement
### Todos
DONE
### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-1512
### How should this be tested?
%kylin select ...
%kylin(new_project) select ....
### Screenshots (if appropriate)
### Questions:
- Does the licenses files need update?
No.
- Is there breaking changes for older versions?
No.
- Does this needs documentation?
Will do later.
Author: Yiming Liu <li...@gmail.com>
Closes #1477 from yiming187/ZEPPELIN-1512 and squashes the following commits:
b58ee7f [Yiming Liu] [ZEPPELIN-1512] Support Kylin project name in interpreter runtime
Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/75441540
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/75441540
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/75441540
Branch: refs/heads/master
Commit: 75441540fde1565570828403171d530a2abc6e2a
Parents: 641a641
Author: Yiming Liu <li...@gmail.com>
Authored: Wed Nov 16 16:17:48 2016 +0800
Committer: Alexander Bezzubov <bz...@apache.org>
Committed: Wed Dec 14 12:57:12 2016 +0900
----------------------------------------------------------------------
docs/interpreter/kylin.md | 10 +++-----
.../apache/zeppelin/kylin/KylinInterpreter.java | 27 ++++++++++++++++----
.../src/main/resources/interpreter-setting.json | 14 +++++-----
kylin/src/test/java/KylinInterpreterTest.java | 27 ++++++++++++++++++--
4 files changed, 57 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/75441540/docs/interpreter/kylin.md
----------------------------------------------------------------------
diff --git a/docs/interpreter/kylin.md b/docs/interpreter/kylin.md
index 9497a62..e1d27d9 100644
--- a/docs/interpreter/kylin.md
+++ b/docs/interpreter/kylin.md
@@ -30,7 +30,6 @@ To get start with Apache Kylin, please see [Apache Kylin Quickstart](https://kyl
## Configuration
<table class="table-configuration">
-<table class="table-configuration">
<tr>
<th>Name</th>
<th>Default</th>
@@ -54,7 +53,7 @@ To get start with Apache Kylin, please see [Apache Kylin Quickstart](https://kyl
<tr>
<td>kylin.query.project</td>
<td>learn_kylin</td>
- <td>String, Project to perform query.</td>
+ <td>String, Project to perform query. Could update at notebook level</td>
</tr>
<tr>
<td>kylin.query.ispartial</td>
@@ -72,15 +71,12 @@ To get start with Apache Kylin, please see [Apache Kylin Quickstart](https://kyl
<td>int, Query offset <br/> If offset is set in sql, curIndex will be ignored.</td>
</tr>
</table>
-
-
-</table>
## Using the Apache Kylin Interpreter
-In a paragraph, use `%kylin` to select the **kylin** interpreter and then input sql.
+In a paragraph, use `%kylin(project_name)` to select the **kylin** interpreter, **project name** and then input **sql**. If no project name defined, will use the default project name from the above configuration.
```
-%kylin
+%kylin(learn_project)
select count(*) from kylin_sales group by part_dt
```
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/75441540/kylin/src/main/java/org/apache/zeppelin/kylin/KylinInterpreter.java
----------------------------------------------------------------------
diff --git a/kylin/src/main/java/org/apache/zeppelin/kylin/KylinInterpreter.java b/kylin/src/main/java/org/apache/zeppelin/kylin/KylinInterpreter.java
index 8523e49..5da5ebd 100755
--- a/kylin/src/main/java/org/apache/zeppelin/kylin/KylinInterpreter.java
+++ b/kylin/src/main/java/org/apache/zeppelin/kylin/KylinInterpreter.java
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package org.apache.zeppelin.kylin;
import org.apache.commons.codec.binary.Base64;
@@ -41,7 +40,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
- * Kylin interpreter for Zeppelin. (http://kylin.io)
+ * Kylin interpreter for Zeppelin. (http://kylin.apache.org)
*/
public class KylinInterpreter extends Interpreter {
Logger logger = LoggerFactory.getLogger(KylinInterpreter.class);
@@ -59,6 +58,7 @@ public class KylinInterpreter extends Interpreter {
public KylinInterpreter(Properties property) {
super(property);
}
+
@Override
public void open() {
@@ -100,8 +100,9 @@ public class KylinInterpreter extends Interpreter {
}
public HttpResponse prepareRequest(String sql) throws IOException {
- String KYLIN_PROJECT = getProperty(KYLIN_QUERY_PROJECT);
- logger.info("project:" + KYLIN_PROJECT);
+ String kylinProject = getProject(KYLIN_QUERY_PROJECT);
+
+ logger.info("project:" + kylinProject);
logger.info("sql:" + sql);
logger.info("acceptPartial:" + getProperty(KYLIN_QUERY_ACCEPT_PARTIAL));
logger.info("limit:" + getProperty(KYLIN_QUERY_LIMIT));
@@ -109,7 +110,7 @@ public class KylinInterpreter extends Interpreter {
byte[] encodeBytes = Base64.encodeBase64(new String(getProperty(KYLIN_USERNAME)
+ ":" + getProperty(KYLIN_PASSWORD)).getBytes("UTF-8"));
- String postContent = new String("{\"project\":" + "\"" + KYLIN_PROJECT + "\""
+ String postContent = new String("{\"project\":" + "\"" + kylinProject + "\""
+ "," + "\"sql\":" + "\"" + sql + "\""
+ "," + "\"acceptPartial\":" + "\"" + getProperty(KYLIN_QUERY_ACCEPT_PARTIAL) + "\""
+ "," + "\"offset\":" + "\"" + getProperty(KYLIN_QUERY_OFFSET) + "\""
@@ -130,6 +131,22 @@ public class KylinInterpreter extends Interpreter {
return httpClient.execute(postRequest);
}
+ public String getProject(String cmd) {
+ boolean firstLineIndex = cmd.startsWith("(");
+
+ if (firstLineIndex) {
+ int configStartIndex = cmd.indexOf("(");
+ int configLastIndex = cmd.indexOf(")");
+ if (configStartIndex != -1 && configLastIndex != -1) {
+ return cmd.substring(configStartIndex + 1, configLastIndex);
+ } else {
+ return getProperty(KYLIN_QUERY_PROJECT);
+ }
+ } else {
+ return getProperty(KYLIN_QUERY_PROJECT);
+ }
+ }
+
private InterpreterResult executeQuery(String sql) throws IOException {
HttpResponse response = prepareRequest(sql);
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/75441540/kylin/src/main/resources/interpreter-setting.json
----------------------------------------------------------------------
diff --git a/kylin/src/main/resources/interpreter-setting.json b/kylin/src/main/resources/interpreter-setting.json
index ca51b17..a8c0d32 100644
--- a/kylin/src/main/resources/interpreter-setting.json
+++ b/kylin/src/main/resources/interpreter-setting.json
@@ -14,37 +14,37 @@
"envName": null,
"propertyName": "kylin.api.user",
"defaultValue": "ADMIN",
- "description": "username for kylin user"
+ "description": "Kylin username"
},
"kylin.api.password": {
"envName": null,
"propertyName": "kylin.api.password",
"defaultValue": "KYLIN",
- "description": "password for kylin user"
+ "description": "Kylin password"
},
"kylin.query.project": {
"envName": null,
"propertyName": "kylin.query.project",
- "defaultValue": "default",
- "description": "kylin project name"
+ "defaultValue": "learn_kylin",
+ "description": "Default Kylin project name"
},
"kylin.query.offset": {
"envName": null,
"propertyName": "kylin.query.offset",
"defaultValue": "0",
- "description": "kylin query offset"
+ "description": "Kylin query offset"
},
"kylin.query.limit": {
"envName": null,
"propertyName": "kylin.query.limit",
"defaultValue": "5000",
- "description": "kylin query limit"
+ "description": "Kylin query limit"
},
"kylin.query.ispartial": {
"envName": null,
"propertyName": "kylin.query.ispartial",
"defaultValue": "true",
- "description": "The kylin query partial flag"
+ "description": "Kylin query partial flag, deprecated"
}
},
"editor": {
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/75441540/kylin/src/test/java/KylinInterpreterTest.java
----------------------------------------------------------------------
diff --git a/kylin/src/test/java/KylinInterpreterTest.java b/kylin/src/test/java/KylinInterpreterTest.java
index e608f77..e11076a 100755
--- a/kylin/src/test/java/KylinInterpreterTest.java
+++ b/kylin/src/test/java/KylinInterpreterTest.java
@@ -47,13 +47,36 @@ public class KylinInterpreterTest {
}
@Test
- public void test(){
- KylinInterpreter t = new MockKylinInterpreter(kylinProperties);
+ public void testWithDefault(){
+ KylinInterpreter t = new MockKylinInterpreter(getDefaultProperties());
InterpreterResult result = t.interpret(
"select a.date,sum(b.measure) as measure from kylin_fact_table a " +
"inner join kylin_lookup_table b on a.date=b.date group by a.date", null);
+ assertEquals("default", t.getProject("select a.date,sum(b.measure) as measure " +
+ "from kylin_fact_table a inner join kylin_lookup_table b on a.date=b.date group by a.date"));
assertEquals(InterpreterResult.Type.TABLE,result.message().get(0).getType());
}
+
+ @Test
+ public void testWithProject(){
+ KylinInterpreter t = new MockKylinInterpreter(getDefaultProperties());
+ assertEquals("project2", t.getProject("(project2)\n select a.date,sum(b.measure) as measure " +
+ "from kylin_fact_table a inner join kylin_lookup_table b on a.date=b.date group by a.date"));
+ assertEquals("", t.getProject("()\n select a.date,sum(b.measure) as measure " +
+ "from kylin_fact_table a inner join kylin_lookup_table b on a.date=b.date group by a.date"));
+ }
+
+ private Properties getDefaultProperties(){
+ Properties prop = new Properties();
+ prop.put("kylin.api.username", "ADMIN");
+ prop.put("kylin.api.password", "KYLIN");
+ prop.put("kylin.api.url", "http://<host>:<port>/kylin/api/query");
+ prop.put("kylin.query.project", "default");
+ prop.put("kylin.query.offset", "0");
+ prop.put("kylin.query.limit", "5000");
+ prop.put("kylin.query.ispartial", "true");
+ return prop;
+ }
}
class MockKylinInterpreter extends KylinInterpreter {