You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by mo...@apache.org on 2017/02/11 07:09:54 UTC
zeppelin git commit: [ZEPPELIN-2078] bug fix in get project name in
Kylin interpreter
Repository: zeppelin
Updated Branches:
refs/heads/master b579a6414 -> 12459bf51
[ZEPPELIN-2078] bug fix in get project name in Kylin interpreter
### What is this PR for?
https://github.com/apache/zeppelin/blob/master/kylin/src/main/java/org/apache/zeppelin/kylin/KylinInterpreter.java line 103, the getProject's input should be sql, not const string KYLIN_QUERY_PROJECT. Otherwise no project name could be retrieved. And also the SQL should exclude the project part.
public HttpResponse prepareRequest(String sql) throws IOException {
String kylinProject = getProject(KYLIN_QUERY_PROJECT);
### What type of PR is it?
[Bug Fix]
### Todos
* [ ] - Task
### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-2078
### How should this be tested?
Has unit test.
### Screenshots (if appropriate)
### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No
Author: Billy Liu <bi...@apache.org>
Closes #1986 from yiming187/ZEPPELIN-2078 and squashes the following commits:
1af8493 [Billy Liu] [ZEPPELIN-2078] bug fix in getProject in Kylin interpreter
Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/12459bf5
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/12459bf5
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/12459bf5
Branch: refs/heads/master
Commit: 12459bf517ff820400f9b3a28e47bc56288940b8
Parents: b579a64
Author: Billy Liu <bi...@apache.org>
Authored: Thu Feb 9 09:28:09 2017 +0800
Committer: Lee moon soo <mo...@apache.org>
Committed: Sat Feb 11 16:09:42 2017 +0900
----------------------------------------------------------------------
.../apache/zeppelin/kylin/KylinInterpreter.java | 35 +++++++++++++++-----
kylin/src/test/java/KylinInterpreterTest.java | 7 ++++
2 files changed, 33 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/12459bf5/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 5da5ebd..c831c24 100755
--- a/kylin/src/main/java/org/apache/zeppelin/kylin/KylinInterpreter.java
+++ b/kylin/src/main/java/org/apache/zeppelin/kylin/KylinInterpreter.java
@@ -100,10 +100,11 @@ public class KylinInterpreter extends Interpreter {
}
public HttpResponse prepareRequest(String sql) throws IOException {
- String kylinProject = getProject(KYLIN_QUERY_PROJECT);
+ String kylinProject = getProject(sql);
+ String kylinSql = getSQL(sql);
logger.info("project:" + kylinProject);
- logger.info("sql:" + sql);
+ logger.info("sql:" + kylinSql);
logger.info("acceptPartial:" + getProperty(KYLIN_QUERY_ACCEPT_PARTIAL));
logger.info("limit:" + getProperty(KYLIN_QUERY_LIMIT));
logger.info("offset:" + getProperty(KYLIN_QUERY_OFFSET));
@@ -111,7 +112,7 @@ public class KylinInterpreter extends Interpreter {
+ ":" + getProperty(KYLIN_PASSWORD)).getBytes("UTF-8"));
String postContent = new String("{\"project\":" + "\"" + kylinProject + "\""
- + "," + "\"sql\":" + "\"" + sql + "\""
+ + "," + "\"sql\":" + "\"" + kylinSql + "\""
+ "," + "\"acceptPartial\":" + "\"" + getProperty(KYLIN_QUERY_ACCEPT_PARTIAL) + "\""
+ "," + "\"offset\":" + "\"" + getProperty(KYLIN_QUERY_OFFSET) + "\""
+ "," + "\"limit\":" + "\"" + getProperty(KYLIN_QUERY_LIMIT) + "\"" + "}");
@@ -132,13 +133,13 @@ public class KylinInterpreter extends Interpreter {
}
public String getProject(String cmd) {
- boolean firstLineIndex = cmd.startsWith("(");
+ boolean isFirstLineProject = cmd.startsWith("(");
- if (firstLineIndex) {
- int configStartIndex = cmd.indexOf("(");
- int configLastIndex = cmd.indexOf(")");
- if (configStartIndex != -1 && configLastIndex != -1) {
- return cmd.substring(configStartIndex + 1, configLastIndex);
+ if (isFirstLineProject) {
+ int projectStartIndex = cmd.indexOf("(");
+ int projectEndIndex = cmd.indexOf(")");
+ if (projectStartIndex != -1 && projectEndIndex != -1) {
+ return cmd.substring(projectStartIndex + 1, projectEndIndex);
} else {
return getProperty(KYLIN_QUERY_PROJECT);
}
@@ -147,6 +148,22 @@ public class KylinInterpreter extends Interpreter {
}
}
+ public String getSQL(String cmd) {
+ boolean isFirstLineProject = cmd.startsWith("(");
+
+ if (isFirstLineProject) {
+ int projectStartIndex = cmd.indexOf("(");
+ int projectEndIndex = cmd.indexOf(")");
+ if (projectStartIndex != -1 && projectEndIndex != -1) {
+ return cmd.substring(projectEndIndex + 1);
+ } else {
+ return cmd;
+ }
+ } else {
+ return cmd;
+ }
+ }
+
private InterpreterResult executeQuery(String sql) throws IOException {
HttpResponse response = prepareRequest(sql);
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/12459bf5/kylin/src/test/java/KylinInterpreterTest.java
----------------------------------------------------------------------
diff --git a/kylin/src/test/java/KylinInterpreterTest.java b/kylin/src/test/java/KylinInterpreterTest.java
index e11076a..6cee13b 100755
--- a/kylin/src/test/java/KylinInterpreterTest.java
+++ b/kylin/src/test/java/KylinInterpreterTest.java
@@ -64,6 +64,13 @@ public class KylinInterpreterTest {
"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"));
+ assertEquals("\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", t.getSQL("(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("\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", t.getSQL("()\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(){