Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,19 @@ public List<InterpreterCompletion> completion(String buf, int cursor) {
}

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));
byte[] encodeBytes = Base64.encodeBase64(new String(getProperty(KYLIN_USERNAME)
+ ":" + 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) + "\"" + "}");
Expand All @@ -132,13 +133,13 @@ public HttpResponse prepareRequest(String sql) throws IOException {
}

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);
}
Expand All @@ -147,6 +148,22 @@ public String getProject(String cmd) {
}
}

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);
Expand Down
7 changes: 7 additions & 0 deletions kylin/src/test/java/KylinInterpreterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ public void testWithProject(){
"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(){
Expand Down