Java Code Examples for org.apache.kylin.rest.request.SQLRequest#getProject()

The following examples show how to use org.apache.kylin.rest.request.SQLRequest#getProject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueryMetrics2Facade.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
public static void updateMetrics(SQLRequest sqlRequest, SQLResponse sqlResponse) {
    if (!enabled) {
        return;
    }
    if (metrics == null) {
        metrics = MetricsFactory.getInstance();
    }
    String projectName = sqlRequest.getProject();
    String cube = sqlResponse.getCube();
    if (cube == null) {
        return;
    }
    String cubeName = cube.replace("=", "->");

    //        update(getQueryMetrics("Server_Total"), sqlResponse);
    update(buildCubeMetricPrefix(TOTAL), sqlResponse);
    update(buildCubeMetricPrefix(projectName), sqlResponse);
    String cubeMetricName = buildCubeMetricPrefix(projectName, cubeName);
    update(cubeMetricName, sqlResponse);
}
 
Example 2
Source File: QueryMetrics2Facade.java    From kylin with Apache License 2.0 6 votes vote down vote up
public static void updateMetrics(SQLRequest sqlRequest, SQLResponse sqlResponse) {
    if (!enabled) {
        return;
    }
    if (metrics == null) {
        metrics = MetricsFactory.getInstance();
    }
    String projectName = sqlRequest.getProject();
    String cube = sqlResponse.getCube();
    if (cube == null) {
        return;
    }
    String cubeName = cube.replace("=", "->");

    //        update(getQueryMetrics("Server_Total"), sqlResponse);
    update(buildCubeMetricPrefix(TOTAL), sqlResponse);
    update(buildCubeMetricPrefix(projectName), sqlResponse);
    String cubeMetricName = buildCubeMetricPrefix(projectName, cubeName);
    update(cubeMetricName, sqlResponse);
}
 
Example 3
Source File: QueryMetricsFacade.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private static void updateMetricsToLocal(SQLRequest sqlRequest, SQLResponse sqlResponse) {
    if (!enabled)
        return;

    String projectName = sqlRequest.getProject();
    update(getQueryMetrics("Server_Total"), sqlResponse);
    update(getQueryMetrics(projectName), sqlResponse);

    String cube = sqlResponse.getCube();
    String cubeName = cube.replace("=", "->");
    String cubeMetricName = projectName + ",sub=" + cubeName;
    update(getQueryMetrics(cubeMetricName), sqlResponse);
}
 
Example 4
Source File: QueryMetricsFacade.java    From kylin with Apache License 2.0 5 votes vote down vote up
private static void updateMetricsToLocal(SQLRequest sqlRequest, SQLResponse sqlResponse) {
    if (!enabled)
        return;

    String projectName = sqlRequest.getProject();
    update(getQueryMetrics("Server_Total"), sqlResponse);
    update(getQueryMetrics(projectName), sqlResponse);

    String cube = sqlResponse.getCube();
    String cubeName = cube.replace("=", "->");
    String cubeMetricName = projectName + ",sub=" + cubeName;
    update(getQueryMetrics(cubeMetricName), sqlResponse);
}
 
Example 5
Source File: QueryController.java    From Kylin with Apache License 2.0 4 votes vote down vote up
private SQLResponse doQuery(SQLRequest sqlRequest) {
    String sql = sqlRequest.getSql();
    String project = sqlRequest.getProject();
    logger.info("Using project: " + project);
    logger.info("The original query:  " + sql);

    String serverMode = KylinConfig.getInstanceFromEnv().getServerMode();
    if (!(Constant.SERVER_MODE_QUERY.equals(serverMode.toLowerCase()) || Constant.SERVER_MODE_ALL.equals(serverMode.toLowerCase()))) {
        throw new InternalErrorException("Query is not allowed in " + serverMode + " mode.");
    }

    if (sql.toLowerCase().contains("select") == false) {
        logger.debug("Directly return expection as not supported");
        throw new InternalErrorException(QueryUtil.makeErrorMsgUserFriendly("Not Supported SQL."));
    }

    SQLResponse sqlResponse = searchQueryInCache(sqlRequest);
    try {
        if (null == sqlResponse) {
            sqlResponse = queryService.query(sqlRequest);

            long durationThreshold = KylinConfig.getInstanceFromEnv().getQueryDurationCacheThreshold();
            long scancountThreshold = KylinConfig.getInstanceFromEnv().getQueryScanCountCacheThreshold();
            if (!sqlResponse.getIsException() && (sqlResponse.getDuration() > durationThreshold || sqlResponse.getTotalScanCount() > scancountThreshold)) {
                cacheManager.getCache(SUCCESS_QUERY_CACHE).put(new Element(sqlRequest, sqlResponse));
            }
        }

        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()));
    }
}