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 2015/06/30 14:37:04 UTC
[7/8] incubator-kylin git commit: KYLIN-780 JDBC query pass
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/776a3a24/jdbc/src/test/java/org/apache/kylin/jdbc2/DummyJdbcFactory.java
----------------------------------------------------------------------
diff --git a/jdbc/src/test/java/org/apache/kylin/jdbc2/DummyJdbcFactory.java b/jdbc/src/test/java/org/apache/kylin/jdbc2/DummyJdbcFactory.java
new file mode 100644
index 0000000..775cb73
--- /dev/null
+++ b/jdbc/src/test/java/org/apache/kylin/jdbc2/DummyJdbcFactory.java
@@ -0,0 +1,35 @@
+/*
+ * 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.jdbc2;
+
+/**
+ */
+public class DummyJdbcFactory extends KylinJdbcFactory {
+
+ public DummyJdbcFactory() {
+ super(4, 1);
+ }
+
+ @Override
+ public IRemoteClient newRemoteClient(KylinConnection conn) {
+ return new DummyClient(conn);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/776a3a24/query/src/main/java/org/apache/kylin/query/QueryCli.java
----------------------------------------------------------------------
diff --git a/query/src/main/java/org/apache/kylin/query/QueryCli.java b/query/src/main/java/org/apache/kylin/query/QueryCli.java
index fe02b2f..898cb22 100644
--- a/query/src/main/java/org/apache/kylin/query/QueryCli.java
+++ b/query/src/main/java/org/apache/kylin/query/QueryCli.java
@@ -25,13 +25,13 @@ import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
+import org.apache.calcite.jdbc.Driver;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
-
import org.apache.kylin.common.KylinConfig;
import org.apache.kylin.query.schema.OLAPSchemaFactory;
@@ -54,7 +54,7 @@ public class QueryCli {
KylinConfig config = KylinConfig.createInstanceFromUri(commandLine.getOptionValue(OPTION_METADATA.getOpt()));
String sql = commandLine.getOptionValue(OPTION_SQL.getOpt());
- Class.forName("net.hydromatic.optiq.jdbc.Driver");
+ Class.forName(Driver.class.getName());
File olapTmp = OLAPSchemaFactory.createTempOLAPJson(null, config);
Connection conn = null;
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/776a3a24/server/src/main/java/org/apache/kylin/rest/controller/QueryController.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/kylin/rest/controller/QueryController.java b/server/src/main/java/org/apache/kylin/rest/controller/QueryController.java
index 53795ec..1eea415 100644
--- a/server/src/main/java/org/apache/kylin/rest/controller/QueryController.java
+++ b/server/src/main/java/org/apache/kylin/rest/controller/QueryController.java
@@ -36,7 +36,6 @@ import org.apache.kylin.common.KylinConfig;
import org.apache.kylin.common.debug.BackdoorToggles;
import org.apache.kylin.cube.CubeInstance;
import org.apache.kylin.rest.constant.Constant;
-import org.apache.kylin.rest.exception.ForbiddenException;
import org.apache.kylin.rest.exception.InternalErrorException;
import org.apache.kylin.rest.model.Query;
import org.apache.kylin.rest.model.SelectedColumnMeta;
@@ -208,20 +207,24 @@ public class QueryController extends BasicController {
}
checkQueryAuth(sqlResponse);
-
- return sqlResponse;
- } catch (AccessDeniedException ade) {
- // Access exception is bind with each user, it will not be cached
- logger.error("Exception when execute sql", ade);
- throw new ForbiddenException(ade.getLocalizedMessage());
+
} catch (Throwable e) { // calcite may throw AssertError
- SQLResponse exceptionRes = new SQLResponse(null, null, 0, true, e.getMessage());
- Cache exceptionCache = cacheManager.getCache(EXCEPTION_QUERY_CACHE);
- exceptionCache.put(new Element(sqlRequest, exceptionRes));
-
logger.error("Exception when execute sql", e);
- throw new InternalErrorException(QueryUtil.makeErrorMsgUserFriendly(e.getLocalizedMessage()));
+ String errMsg = QueryUtil.makeErrorMsgUserFriendly(e);
+
+ sqlResponse = new SQLResponse(null, null, 0, true, errMsg);
+
+ // Access exception is bind with each user, it will not be cached
+ if ((e instanceof AccessDeniedException) == false) {
+ Cache exceptionCache = cacheManager.getCache(EXCEPTION_QUERY_CACHE);
+ exceptionCache.put(new Element(sqlRequest, sqlResponse));
+ }
}
+
+ if (sqlResponse.getIsException())
+ throw new InternalErrorException(sqlResponse.getExceptionMessage());
+ else
+ return sqlResponse;
}
private SQLResponse searchQueryInCache(SQLRequest sqlRequest) {
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/776a3a24/server/src/main/java/org/apache/kylin/rest/service/BasicService.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/kylin/rest/service/BasicService.java b/server/src/main/java/org/apache/kylin/rest/service/BasicService.java
index f248e95..764dd7b 100644
--- a/server/src/main/java/org/apache/kylin/rest/service/BasicService.java
+++ b/server/src/main/java/org/apache/kylin/rest/service/BasicService.java
@@ -43,6 +43,7 @@ import org.apache.kylin.query.enumerator.OLAPQuery;
import org.apache.kylin.query.relnode.OLAPContext;
import org.apache.kylin.query.schema.OLAPSchemaFactory;
import org.apache.kylin.rest.controller.QueryController;
+import org.apache.calcite.jdbc.Driver;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -114,7 +115,7 @@ public abstract class BasicService {
Properties props = new Properties();
props.setProperty(OLAPQuery.PROP_SCAN_THRESHOLD, String.valueOf(KylinConfig.getInstanceFromEnv().getScanThreshold()));
ds.setConnectionProperties(props);
- ds.setDriverClassName("net.hydromatic.optiq.jdbc.Driver");
+ ds.setDriverClassName(Driver.class.getName());
ds.setUrl("jdbc:calcite:model=" + modelJson.getAbsolutePath());
ret = olapDataSources.putIfAbsent(project, ds);
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/776a3a24/server/src/main/java/org/apache/kylin/rest/util/QueryUtil.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/kylin/rest/util/QueryUtil.java b/server/src/main/java/org/apache/kylin/rest/util/QueryUtil.java
index dd3ffa9..994fe03 100644
--- a/server/src/main/java/org/apache/kylin/rest/util/QueryUtil.java
+++ b/server/src/main/java/org/apache/kylin/rest/util/QueryUtil.java
@@ -149,12 +149,22 @@ public class QueryUtil {
return null;
}
- /**
- * adjust error message order
- *
- * @param errorMsg
- * @return
- */
+ public static String makeErrorMsgUserFriendly(Throwable e) {
+ String msg = e.getMessage();
+
+ // pick ParseException error message if possible
+ Throwable cause = e;
+ while (cause != null) {
+ if (cause.getClass().getName().contains("ParseException")) {
+ msg = cause.getMessage();
+ break;
+ }
+ cause = cause.getCause();
+ }
+
+ return makeErrorMsgUserFriendly(msg);
+ }
+
public static String makeErrorMsgUserFriendly(String errorMsg) {
try {
// make one line