@@ -100,18 +100,19 @@ public List<InterpreterCompletion> completion(String buf, int cursor) {
100100 }
101101
102102 public HttpResponse prepareRequest (String sql ) throws IOException {
103- String kylinProject = getProject (KYLIN_QUERY_PROJECT );
103+ String kylinProject = getProject (sql );
104+ String kylinSql = getSQL (sql );
104105
105106 logger .info ("project:" + kylinProject );
106- logger .info ("sql:" + sql );
107+ logger .info ("sql:" + kylinSql );
107108 logger .info ("acceptPartial:" + getProperty (KYLIN_QUERY_ACCEPT_PARTIAL ));
108109 logger .info ("limit:" + getProperty (KYLIN_QUERY_LIMIT ));
109110 logger .info ("offset:" + getProperty (KYLIN_QUERY_OFFSET ));
110111 byte [] encodeBytes = Base64 .encodeBase64 (new String (getProperty (KYLIN_USERNAME )
111112 + ":" + getProperty (KYLIN_PASSWORD )).getBytes ("UTF-8" ));
112113
113114 String postContent = new String ("{\" project\" :" + "\" " + kylinProject + "\" "
114- + "," + "\" sql\" :" + "\" " + sql + "\" "
115+ + "," + "\" sql\" :" + "\" " + kylinSql + "\" "
115116 + "," + "\" acceptPartial\" :" + "\" " + getProperty (KYLIN_QUERY_ACCEPT_PARTIAL ) + "\" "
116117 + "," + "\" offset\" :" + "\" " + getProperty (KYLIN_QUERY_OFFSET ) + "\" "
117118 + "," + "\" limit\" :" + "\" " + getProperty (KYLIN_QUERY_LIMIT ) + "\" " + "}" );
@@ -132,13 +133,13 @@ public HttpResponse prepareRequest(String sql) throws IOException {
132133 }
133134
134135 public String getProject (String cmd ) {
135- boolean firstLineIndex = cmd .startsWith ("(" );
136+ boolean isFirstLineProject = cmd .startsWith ("(" );
136137
137- if (firstLineIndex ) {
138- int configStartIndex = cmd .indexOf ("(" );
139- int configLastIndex = cmd .indexOf (")" );
140- if (configStartIndex != -1 && configLastIndex != -1 ) {
141- return cmd .substring (configStartIndex + 1 , configLastIndex );
138+ if (isFirstLineProject ) {
139+ int projectStartIndex = cmd .indexOf ("(" );
140+ int projectEndIndex = cmd .indexOf (")" );
141+ if (projectStartIndex != -1 && projectEndIndex != -1 ) {
142+ return cmd .substring (projectStartIndex + 1 , projectEndIndex );
142143 } else {
143144 return getProperty (KYLIN_QUERY_PROJECT );
144145 }
@@ -147,6 +148,22 @@ public String getProject(String cmd) {
147148 }
148149 }
149150
151+ public String getSQL (String cmd ) {
152+ boolean isFirstLineProject = cmd .startsWith ("(" );
153+
154+ if (isFirstLineProject ) {
155+ int projectStartIndex = cmd .indexOf ("(" );
156+ int projectEndIndex = cmd .indexOf (")" );
157+ if (projectStartIndex != -1 && projectEndIndex != -1 ) {
158+ return cmd .substring (projectEndIndex + 1 );
159+ } else {
160+ return cmd ;
161+ }
162+ } else {
163+ return cmd ;
164+ }
165+ }
166+
150167 private InterpreterResult executeQuery (String sql ) throws IOException {
151168
152169 HttpResponse response = prepareRequest (sql );
0 commit comments