Java Code Examples for org.apache.kylin.rest.response.SQLResponse

The following examples show how to use org.apache.kylin.rest.response.SQLResponse. These examples are extracted from open source projects. 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 Project: Kylin   Source File: QueryServiceTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testBasics() throws JobException, IOException, SQLException {
    Assert.assertNotNull(queryService.getConfig());
    Assert.assertNotNull(queryService.getKylinConfig());
    Assert.assertNotNull(queryService.getMetadataManager());
    Assert.assertNotNull(queryService.getOLAPDataSource(ProjectInstance.DEFAULT_PROJECT_NAME));

    //        Assert.assertTrue(queryService.getQueries("ADMIN").size() == 0);
    //
    //        queryService.saveQuery("test", "test", "select * from test_table", "test");
    //        Assert.assertTrue(queryService.getQueries("ADMIN").size() == 1);
    //
    //        queryService.removeQuery(queryService.getQueries("ADMIN").get(0).getProperty("id"));
    //        Assert.assertTrue(queryService.getQueries("ADMIN").size() == 0);

    SQLRequest request = new SQLRequest();
    request.setSql("select * from test_table");
    request.setAcceptPartial(true);
    SQLResponse response = new SQLResponse();
    response.setHitCache(true);
    queryService.logQuery(request, response, new Date(), new Date());
}
 
Example 2
Source Project: kylin-on-parquet-v2   Source File: QueryServiceTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testBasics() throws JobException, IOException, SQLException {
    Assert.assertNotNull(queryService.getConfig());
    Assert.assertNotNull(queryService.getConfig());
    Assert.assertNotNull(queryService.getDataModelManager());
    Assert.assertNotNull(QueryConnection.getConnection(ProjectInstance.DEFAULT_PROJECT_NAME));

    //        Assert.assertTrue(queryService.getQueries("ADMIN").size() == 0);
    //
    //        queryService.saveQuery("test", "test", "select * from test_table", "test");
    //        Assert.assertTrue(queryService.getQueries("ADMIN").size() == 1);
    //
    //        queryService.removeQuery(queryService.getQueries("ADMIN").get(0).getProperty("id"));
    //        Assert.assertTrue(queryService.getQueries("ADMIN").size() == 0);

    SQLRequest request = new SQLRequest();
    request.setSql("select * from test_table");
    request.setAcceptPartial(true);
    QueryContext queryContext = QueryContextFacade.current();
    SQLResponse response = new SQLResponse();
    response.setHitExceptionCache(true);
    queryService.logQuery(queryContext.getQueryId(), request, response);
}
 
Example 3
Source Project: kylin-on-parquet-v2   Source File: QueryServiceTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTableToWith() {
    String create_table1 = " create table tableId as select * from some_table1;";
    String create_table2 = "CREATE TABLE tableId2 AS select * FROM some_table2;";
    String select_table = "select * from tableId join tableId2 on tableId.a = tableId2.b;";

    KylinConfig config = KylinConfig.getInstanceFromEnv();
    config.setProperty("kylin.query.convert-create-table-to-with", "true");
    try (SetAndUnsetThreadLocalConfig autoUnset = KylinConfig.setAndUnsetThreadLocalConfig(config)) {

        SQLRequest request = new SQLRequest();
        request.setProject("default");
        request.setSql(create_table1);
        queryService.doQueryWithCache(request);

        request.setSql(create_table2);
        queryService.doQueryWithCache(request);

        request.setSql(select_table);
        SQLResponse response = queryService.doQueryWithCache(request, true);

        Assert.assertEquals(
                "WITH tableId as (select * from some_table1) , tableId2 AS (select * FROM some_table2) select * from tableId join tableId2 on tableId.a = tableId2.b;",
                response.getExceptionMessage());
    }
}
 
Example 4
Source Project: kylin-on-parquet-v2   Source File: QueryMetrics2Facade.java    License: 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 5
Source Project: kylin-on-parquet-v2   Source File: QueryMetrics2Facade.java    License: Apache License 2.0 6 votes vote down vote up
private static void update(String name, SQLResponse sqlResponse) {
    try {
        incrQueryCount(name, sqlResponse);
        incrCacheHitCount(name, sqlResponse);
        if (!sqlResponse.getIsException()) {
            metrics.updateTimer(MetricsNameBuilder.buildMetricName(name, MetricsConstant.QUERY_DURATION),
                    sqlResponse.getDuration(), TimeUnit.MILLISECONDS);
            metrics.updateHistogram(MetricsNameBuilder.buildMetricName(name, MetricsConstant.QUERY_RESULT_ROWCOUNT),
                    sqlResponse.getResults().size());
            metrics.updateHistogram(MetricsNameBuilder.buildMetricName(name, MetricsConstant.QUERY_SCAN_ROWCOUNT),
                    sqlResponse.getTotalScanCount());
        }
    } catch (Exception e) {
        logger.error(e.getMessage());
    }

}
 
Example 6
Source Project: kylin-on-parquet-v2   Source File: DashboardController.java    License: Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/metric/query", method = RequestMethod.GET)
@ResponseBody
public MetricsResponse getQueryMetrics(@RequestParam(value = "projectName", required = false) String projectName,
        @RequestParam(value = "cubeName", required = false) String cubeName,
        @RequestParam(value = "startTime") String startTime, @RequestParam(value = "endTime") String endTime) {
    checkAuthorization(projectName);
    MetricsResponse queryMetrics = new MetricsResponse();
    PrepareSqlRequest sqlRequest = dashboardService.getQueryMetricsSQLRequest(startTime, endTime, projectName,
            cubeName);
    SQLResponse sqlResponse = queryService.doQueryWithCache(sqlRequest);
    if (!sqlResponse.getIsException()) {
        queryMetrics.increase("queryCount",
                dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(0)));
        queryMetrics.increase("avgQueryLatency",
                dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(1)));
        queryMetrics.increase("maxQueryLatency",
                dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(2)));
        queryMetrics.increase("minQueryLatency",
                dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(3)));
    }
    return queryMetrics;
}
 
Example 7
Source Project: kylin-on-parquet-v2   Source File: DashboardController.java    License: Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/metric/job", method = RequestMethod.GET)
@ResponseBody
public MetricsResponse getJobMetrics(@RequestParam(value = "projectName", required = false) String projectName,
        @RequestParam(value = "cubeName", required = false) String cubeName,
        @RequestParam(value = "startTime") String startTime, @RequestParam(value = "endTime") String endTime) {
    checkAuthorization(projectName);
    MetricsResponse jobMetrics = new MetricsResponse();
    PrepareSqlRequest sqlRequest = dashboardService.getJobMetricsSQLRequest(startTime, endTime, projectName,
            cubeName);
    SQLResponse sqlResponse = queryService.doQueryWithCache(sqlRequest);
    if (!sqlResponse.getIsException()) {
        jobMetrics.increase("jobCount", dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(0)));
        jobMetrics.increase("avgJobBuildTime",
                dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(1)));
        jobMetrics.increase("maxJobBuildTime",
                dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(2)));
        jobMetrics.increase("minJobBuildTime",
                dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(3)));
    }
    return jobMetrics;
}
 
Example 8
Source Project: kylin-on-parquet-v2   Source File: QueryService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param correctedSql
 * @param sqlRequest
 * @return
 * @throws Exception
 */
private SQLResponse executeRequest(String correctedSql, SQLRequest sqlRequest, Connection conn) throws Exception {
    Statement stat = null;
    ResultSet resultSet = null;
    boolean isPushDown = false;

    Pair<List<List<String>>, List<SelectedColumnMeta>> r = null;
    try {
        stat = conn.createStatement();
        processStatementAttr(stat, sqlRequest);
        resultSet = stat.executeQuery(correctedSql);

        r = createResponseFromResultSet(resultSet);

    } catch (SQLException sqlException) {
        r = pushDownQuery(sqlRequest, correctedSql, conn, sqlException);
        if (r == null)
            throw sqlException;

        isPushDown = true;
    } finally {
        close(resultSet, stat, null); //conn is passed in, not my duty to close
    }

    return buildSqlResponse(sqlRequest.getProject(), isPushDown, r.getFirst(), r.getSecond());
}
 
Example 9
@Override
public String calculateSignature(KylinConfig config, SQLResponse sqlResponse, ProjectInstance project) {
    Set<String> realizations = getRealizations(config, sqlResponse.getCube(), project);
    if (realizations == null) {
        return null;
    }
    Set<RealizationSignature> signatureSet = Sets.newTreeSet();
    for (String realization : realizations) {
        RealizationSignature realizationSignature = getRealizationSignature(config, realization);
        if (realizationSignature != null) {
            signatureSet.add(realizationSignature);
        }
    }
    if (signatureSet.isEmpty()) {
        return null;
    }
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] signature = md.digest(signatureSet.toString().getBytes("UTF-8"));
        return new String(Base64.encodeBase64(signature), "UTF-8");
    } catch (Exception e) {
        logger.warn("Failed to calculate signature due to " + e);
        return null;
    }
}
 
Example 10
Source Project: kylin   Source File: QueryServiceTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testBasics() throws JobException, IOException, SQLException {
    Assert.assertNotNull(queryService.getConfig());
    Assert.assertNotNull(queryService.getConfig());
    Assert.assertNotNull(queryService.getDataModelManager());
    Assert.assertNotNull(QueryConnection.getConnection(ProjectInstance.DEFAULT_PROJECT_NAME));

    //        Assert.assertTrue(queryService.getQueries("ADMIN").size() == 0);
    //
    //        queryService.saveQuery("test", "test", "select * from test_table", "test");
    //        Assert.assertTrue(queryService.getQueries("ADMIN").size() == 1);
    //
    //        queryService.removeQuery(queryService.getQueries("ADMIN").get(0).getProperty("id"));
    //        Assert.assertTrue(queryService.getQueries("ADMIN").size() == 0);

    SQLRequest request = new SQLRequest();
    request.setSql("select * from test_table");
    request.setAcceptPartial(true);
    QueryContext queryContext = QueryContextFacade.current();
    SQLResponse response = new SQLResponse();
    response.setHitExceptionCache(true);
    queryService.logQuery(queryContext.getQueryId(), request, response);
}
 
Example 11
Source Project: kylin   Source File: QueryServiceTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTableToWith() {
    String create_table1 = " create table tableId as select * from some_table1;";
    String create_table2 = "CREATE TABLE tableId2 AS select * FROM some_table2;";
    String select_table = "select * from tableId join tableId2 on tableId.a = tableId2.b;";

    KylinConfig config = KylinConfig.getInstanceFromEnv();
    config.setProperty("kylin.query.convert-create-table-to-with", "true");
    try (SetAndUnsetThreadLocalConfig autoUnset = KylinConfig.setAndUnsetThreadLocalConfig(config)) {

        SQLRequest request = new SQLRequest();
        request.setProject("default");
        request.setSql(create_table1);
        queryService.doQueryWithCache(request);

        request.setSql(create_table2);
        queryService.doQueryWithCache(request);

        request.setSql(select_table);
        SQLResponse response = queryService.doQueryWithCache(request, true);

        Assert.assertEquals(
                "WITH tableId as (select * from some_table1) , tableId2 AS (select * FROM some_table2) select * from tableId join tableId2 on tableId.a = tableId2.b;",
                response.getExceptionMessage());
    }
}
 
Example 12
Source Project: kylin   Source File: QueryMetrics2Facade.java    License: 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 13
Source Project: kylin   Source File: QueryMetrics2Facade.java    License: Apache License 2.0 6 votes vote down vote up
private static void update(String name, SQLResponse sqlResponse) {
    try {
        incrQueryCount(name, sqlResponse);
        incrCacheHitCount(name, sqlResponse);
        if (!sqlResponse.getIsException()) {
            metrics.updateTimer(MetricsNameBuilder.buildMetricName(name, MetricsConstant.QUERY_DURATION),
                    sqlResponse.getDuration(), TimeUnit.MILLISECONDS);
            metrics.updateHistogram(MetricsNameBuilder.buildMetricName(name, MetricsConstant.QUERY_RESULT_ROWCOUNT),
                    sqlResponse.getResults().size());
            metrics.updateHistogram(MetricsNameBuilder.buildMetricName(name, MetricsConstant.QUERY_SCAN_ROWCOUNT),
                    sqlResponse.getTotalScanCount());
        }
    } catch (Exception e) {
        logger.error(e.getMessage());
    }

}
 
Example 14
Source Project: kylin   Source File: DashboardController.java    License: Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/metric/query", method = RequestMethod.GET)
@ResponseBody
public MetricsResponse getQueryMetrics(@RequestParam(value = "projectName", required = false) String projectName,
        @RequestParam(value = "cubeName", required = false) String cubeName,
        @RequestParam(value = "startTime") String startTime, @RequestParam(value = "endTime") String endTime) {
    checkAuthorization(projectName);
    MetricsResponse queryMetrics = new MetricsResponse();
    PrepareSqlRequest sqlRequest = dashboardService.getQueryMetricsSQLRequest(startTime, endTime, projectName,
            cubeName);
    SQLResponse sqlResponse = queryService.doQueryWithCache(sqlRequest);
    if (!sqlResponse.getIsException()) {
        queryMetrics.increase("queryCount",
                dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(0)));
        queryMetrics.increase("avgQueryLatency",
                dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(1)));
        queryMetrics.increase("maxQueryLatency",
                dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(2)));
        queryMetrics.increase("minQueryLatency",
                dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(3)));
    }
    return queryMetrics;
}
 
Example 15
Source Project: kylin   Source File: DashboardController.java    License: Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/metric/job", method = RequestMethod.GET)
@ResponseBody
public MetricsResponse getJobMetrics(@RequestParam(value = "projectName", required = false) String projectName,
        @RequestParam(value = "cubeName", required = false) String cubeName,
        @RequestParam(value = "startTime") String startTime, @RequestParam(value = "endTime") String endTime) {
    checkAuthorization(projectName);
    MetricsResponse jobMetrics = new MetricsResponse();
    PrepareSqlRequest sqlRequest = dashboardService.getJobMetricsSQLRequest(startTime, endTime, projectName,
            cubeName);
    SQLResponse sqlResponse = queryService.doQueryWithCache(sqlRequest);
    if (!sqlResponse.getIsException()) {
        jobMetrics.increase("jobCount", dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(0)));
        jobMetrics.increase("avgJobBuildTime",
                dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(1)));
        jobMetrics.increase("maxJobBuildTime",
                dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(2)));
        jobMetrics.increase("minJobBuildTime",
                dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(3)));
    }
    return jobMetrics;
}
 
Example 16
Source Project: Kylin   Source File: QueryService.java    License: Apache License 2.0 6 votes vote down vote up
protected SQLResponse executeQuery(String sql, SQLRequest sqlRequest) throws Exception {
    sql = sql.trim().replace(";", "");

    int limit = sqlRequest.getLimit();
    if (limit > 0 && !sql.toLowerCase().contains("limit")) {
        sql += (" LIMIT " + limit);
    }

    int offset = sqlRequest.getOffset();
    if (offset > 0 && !sql.toLowerCase().contains("offset")) {
        sql += (" OFFSET " + offset);
    }

    // add extra parameters into olap context, like acceptPartial
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put(OLAPContext.PRM_ACCEPT_PARTIAL_RESULT, String.valueOf(sqlRequest.isAcceptPartial()));
    OLAPContext.setParameters(parameters);

    return execute(sql, sqlRequest);
}
 
Example 17
Source Project: kylin   Source File: QueryService.java    License: Apache License 2.0 6 votes vote down vote up
public SQLResponse update(SQLRequest sqlRequest) throws Exception {
    // non select operations, only supported when enable pushdown
    logger.debug("Query pushdown enabled, redirect the non-select query to pushdown engine.");
    Connection conn = null;
    try {
        conn = QueryConnection.getConnection(sqlRequest.getProject());
        Pair<List<List<String>>, List<SelectedColumnMeta>> r = PushDownUtil.tryPushDownNonSelectQuery(
                sqlRequest.getProject(), sqlRequest.getSql(), conn.getSchema(), BackdoorToggles.getPrepareOnly());

        List<SelectedColumnMeta> columnMetas = Lists.newArrayList();
        columnMetas.add(new SelectedColumnMeta(false, false, false, false, 1, false, Integer.MAX_VALUE, "c0", "c0",
                null, null, null, Integer.MAX_VALUE, 128, 1, "char", false, false, false));

        return buildSqlResponse(sqlRequest.getProject(), true, r.getFirst(), columnMetas);

    } catch (Exception e) {
        logger.info("pushdown engine failed to finish current non-select query");
        throw e;
    } finally {
        close(null, null, conn);
    }
}
 
Example 18
Source Project: kylin   Source File: RealizationSetCalculator.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String calculateSignature(KylinConfig config, SQLResponse sqlResponse, ProjectInstance project) {
    Set<String> realizations = getRealizations(config, sqlResponse.getCube(), project);
    if (realizations == null) {
        return null;
    }
    Set<RealizationSignature> signatureSet = Sets.newTreeSet();
    for (String realization : realizations) {
        RealizationSignature realizationSignature = getRealizationSignature(config, realization);
        if (realizationSignature != null) {
            signatureSet.add(realizationSignature);
        }
    }
    if (signatureSet.isEmpty()) {
        return null;
    }
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] signature = md.digest(signatureSet.toString().getBytes("UTF-8"));
        return new String(Base64.encodeBase64(signature), "UTF-8");
    } catch (Exception e) {
        logger.warn("Failed to calculate signature due to " + e);
        return null;
    }
}
 
Example 19
Source Project: Kylin   Source File: QueryController.java    License: Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/query", method = RequestMethod.POST)
@ResponseBody
@Timed(name = "query")
public SQLResponse query(@RequestBody SQLRequest sqlRequest) {
    long startTimestamp = System.currentTimeMillis();

    SQLResponse response = doQuery(sqlRequest);
    response.setDuration(System.currentTimeMillis() - startTimestamp);

    queryService.logQuery(sqlRequest, response, new Date(startTimestamp), new Date(System.currentTimeMillis()));

    return response;
}
 
Example 20
Source Project: kylin-on-parquet-v2   Source File: QueryControllerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = Exception.class)
public void testQueryException() throws Exception {
    PrepareSqlRequest sqlRequest = new PrepareSqlRequest();
    sqlRequest.setSql("select * from not_exist_table");
    sqlRequest.setProject("default");
    SQLResponse response1 = queryController.query(sqlRequest);
    Assert.assertEquals(false, response1.getIsException());

    SQLResponse response2 = queryController.query(sqlRequest);
    Assert.assertEquals(false, response2.getIsException());
}
 
Example 21
Source Project: kylin-on-parquet-v2   Source File: QueryMetricsFacade.java    License: 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 22
Source Project: kylin-on-parquet-v2   Source File: QueryMetricsFacade.java    License: Apache License 2.0 5 votes vote down vote up
private static void update(QueryMetrics queryMetrics, SQLResponse sqlResponse) {
    try {
        incrQueryCount(queryMetrics, sqlResponse);
        incrCacheHitCount(queryMetrics, sqlResponse);

        if (!sqlResponse.getIsException()) {
            queryMetrics.addQueryLatency(sqlResponse.getDuration());
            queryMetrics.addScanRowCount(sqlResponse.getTotalScanCount());
            queryMetrics.addResultRowCount(sqlResponse.getResults().size());
        }
    } catch (Exception e) {
        logger.error(e.getMessage());
    }

}
 
Example 23
Source Project: kylin-on-parquet-v2   Source File: QueryMetricsFacade.java    License: Apache License 2.0 5 votes vote down vote up
private static void incrQueryCount(QueryMetrics queryMetrics, SQLResponse sqlResponse) {
    if (!sqlResponse.isHitExceptionCache() && !sqlResponse.getIsException()) {
        queryMetrics.incrQuerySuccessCount();
    } else {
        queryMetrics.incrQueryFailCount();
    }
    queryMetrics.incrQueryCount();
}
 
Example 24
Source Project: kylin-on-parquet-v2   Source File: QueryMetrics2Facade.java    License: Apache License 2.0 5 votes vote down vote up
private static void incrQueryCount(String name, SQLResponse sqlResponse) {
    if (!sqlResponse.isHitExceptionCache() && !sqlResponse.getIsException()) {
        metrics.incrementCounter(MetricsNameBuilder.buildMetricName(name, MetricsConstant.QUERY_SUCCESS_COUNT));
    } else {
        metrics.incrementCounter(MetricsNameBuilder.buildMetricName(name, MetricsConstant.QUERY_FAIL_COUNT));
    }
    metrics.incrementCounter(MetricsNameBuilder.buildMetricName(name, MetricsConstant.QUERY_COUNT));
}
 
Example 25
Source Project: kylin-on-parquet-v2   Source File: QueryController.java    License: Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/query/prestate", method = RequestMethod.POST, produces = "application/json")
@ResponseBody
public SQLResponse prepareQuery(@RequestBody PrepareSqlRequest sqlRequest) {
    Map<String, String> newToggles = Maps.newHashMap();
    if (sqlRequest.getBackdoorToggles() != null)
        newToggles.putAll(sqlRequest.getBackdoorToggles());
    newToggles.put(BackdoorToggles.DEBUG_TOGGLE_PREPARE_ONLY, "true");
    sqlRequest.setBackdoorToggles(newToggles);

    return queryService.doQueryWithCache(sqlRequest);
}
 
Example 26
Source Project: kylin-on-parquet-v2   Source File: QueryService.java    License: Apache License 2.0 5 votes vote down vote up
public SQLResponse query(SQLRequest sqlRequest, String queryId) throws Exception {
    SQLResponse ret = null;
    try {
        final String user = SecurityContextHolder.getContext().getAuthentication().getName();
        badQueryDetector.queryStart(Thread.currentThread(), sqlRequest, user, queryId);

        ret = queryWithSqlMassage(sqlRequest);
        return ret;

    } finally {
        String badReason = (ret != null && ret.isPushDown()) ? BadQueryEntry.ADJ_PUSHDOWN : null;
        badQueryDetector.queryEnd(Thread.currentThread(), badReason);
        Thread.interrupted(); //reset if interrupted
    }
}
 
Example 27
Source Project: kylin-on-parquet-v2   Source File: QueryService.java    License: Apache License 2.0 5 votes vote down vote up
private SQLResponse executePrepareRequest(String correctedSql, PrepareSqlRequest sqlRequest,
        PreparedContext preparedContext) throws Exception {
    ResultSet resultSet = null;
    boolean isPushDown = false;

    Pair<List<List<String>>, List<SelectedColumnMeta>> r = null;
    Connection conn = preparedContext.conn;
    try {
        PreparedStatement preparedStatement = preparedContext.preparedStatement;
        processStatementAttr(preparedStatement, sqlRequest);
        for (int i = 0; i < sqlRequest.getParams().length; i++) {
            setParam(preparedStatement, i + 1, (sqlRequest.getParams()[i]));
        }
        resultSet = preparedStatement.executeQuery();
        r = createResponseFromResultSet(resultSet);
    } catch (SQLException sqlException) {
        r = pushDownQuery(sqlRequest, correctedSql, conn, sqlException);
        if (r == null)
            throw sqlException;

        isPushDown = true;
    } finally {
        DBUtils.closeQuietly(resultSet);
    }

    return buildSqlResponse(sqlRequest.getProject(), isPushDown, r.getFirst(), r.getSecond());
}
 
Example 28
Source Project: kylin-on-parquet-v2   Source File: DashboardService.java    License: Apache License 2.0 5 votes vote down vote up
public MetricsResponse transformChartData(SQLResponse sqlResponse) {
    if (!sqlResponse.getIsException()) {
        MetricsResponse metrics = new MetricsResponse();
        List<List<String>> results = sqlResponse.getResults();
        for (List<String> result : results) {
            String dimension = result.get(0);
            if (dimension != null && !dimension.isEmpty()) {
                String metric = result.get(1);
                metrics.increase(dimension, getMetricValue(metric));
            }
        }
        return metrics;
    }
    return null;
}
 
Example 29
Source Project: kylin-on-parquet-v2   Source File: TableauInterceptor.java    License: Apache License 2.0 5 votes vote down vote up
public static SQLResponse tableauIntercept(String sql) {

        String[] tokens = sql.split("[\r\n\t \\(\\)]");
        for (int i = 0; i < tableauTestQueries.length; ++i) {
            if (isTokenWiseEqual(tokens, tableauTestQueriesInToken.get(i))) {
                logger.info("Hit fake response " + i);
                return fakeResponses[i];
            }
        }

        return null;
    }
 
Example 30
public static boolean checkSignature(KylinConfig config, SQLResponse sqlResponse, String projectName) {
    String old = sqlResponse.getSignature();
    if (old == null) {
        return false;
    }
    String latest = createSignature(config, sqlResponse, projectName);
    return old.equals(latest);
}