本文整理汇总了Java中org.apache.kylin.rest.response.SQLResponse类的典型用法代码示例。如果您正苦于以下问题:Java SQLResponse类的具体用法?Java SQLResponse怎么用?Java SQLResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SQLResponse类属于org.apache.kylin.rest.response包,在下文中一共展示了SQLResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBasics
import org.apache.kylin.rest.response.SQLResponse; //导入依赖的package包/类
@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);
SQLResponse response = new SQLResponse();
response.setHitExceptionCache(true);
queryService.logQuery(request, response);
}
示例2: testCreateTableToWith
import org.apache.kylin.rest.response.SQLResponse; //导入依赖的package包/类
@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");
KylinConfig.setKylinConfigThreadLocal(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());
}
示例3: updateMetrics
import org.apache.kylin.rest.response.SQLResponse; //导入依赖的package包/类
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);
}
示例4: update
import org.apache.kylin.rest.response.SQLResponse; //导入依赖的package包/类
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());
}
}
示例5: getQueryMetrics
import org.apache.kylin.rest.response.SQLResponse; //导入依赖的package包/类
@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();
SQLRequest sqlRequest = new SQLRequest();
sqlRequest.setProject(MetricsManager.SYSTEM_PROJECT);
String sql = dashboardService.getQueryMetricsSQL(startTime, endTime, projectName, cubeName);
sqlRequest.setSql(sql);
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;
}
示例6: getJobMetrics
import org.apache.kylin.rest.response.SQLResponse; //导入依赖的package包/类
@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();
SQLRequest sqlRequest = new SQLRequest();
sqlRequest.setProject(MetricsManager.SYSTEM_PROJECT);
String sql = dashboardService.getJobMetricsSQL(startTime, endTime, projectName, cubeName);
sqlRequest.setSql(sql);
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;
}
示例7: update
import org.apache.kylin.rest.response.SQLResponse; //导入依赖的package包/类
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(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);
}
}
示例8: buildSqlResponse
import org.apache.kylin.rest.response.SQLResponse; //导入依赖的package包/类
private SQLResponse buildSqlResponse(Boolean isPushDown, List<List<String>> results,
List<SelectedColumnMeta> columnMetas) {
boolean isPartialResult = false;
StringBuilder cubeSb = new StringBuilder();
StringBuilder logSb = new StringBuilder("Processed rows for each storageContext: ");
if (OLAPContext.getThreadLocalContexts() != null) { // contexts can be null in case of 'explain plan for'
for (OLAPContext ctx : OLAPContext.getThreadLocalContexts()) {
if (ctx.realization != null) {
isPartialResult |= ctx.storageContext.isPartialResultReturned();
if (cubeSb.length() > 0) {
cubeSb.append(",");
}
cubeSb.append(ctx.realization.getCanonicalName());
logSb.append(ctx.storageContext.getProcessedRowCount()).append(" ");
}
}
}
logger.info(logSb.toString());
SQLResponse response = new SQLResponse(columnMetas, results, cubeSb.toString(), 0, false, null, isPartialResult,
isPushDown);
response.setTotalScanCount(QueryContext.current().getScannedRows());
response.setTotalScanBytes(QueryContext.current().getScannedBytes());
return response;
}
示例9: prepareQuery
import org.apache.kylin.rest.response.SQLResponse; //导入依赖的package包/类
@RequestMapping(value = "/query/prestate", method = RequestMethod.POST, produces = "application/json")
@ResponseBody
@Timed(name = "query")
public SQLResponse prepareQuery(@RequestBody PrepareSqlRequest 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()));
if (response.getIsException()) {
String errorMsg = response.getExceptionMessage();
throw new InternalErrorException(QueryUtil.makeErrorMsgUserFriendly(errorMsg));
}
return response;
}
示例10: executeQuery
import org.apache.kylin.rest.response.SQLResponse; //导入依赖的package包/类
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);
}
示例11: tableauIntercept
import org.apache.kylin.rest.response.SQLResponse; //导入依赖的package包/类
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))) {
printInfo("Hit fake response " + i);
return fakeResponses[i];
}
}
// if(sql.trim().endsWith("LIMIT 1"))
// {
// //queries end with LIMIT 1 is test queries sent by Tableau
// return temp;
// }
return null;
}
示例12: testBasics
import org.apache.kylin.rest.response.SQLResponse; //导入依赖的package包/类
@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());
}
示例13: testQueryException
import org.apache.kylin.rest.response.SQLResponse; //导入依赖的package包/类
@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());
}
示例14: updateMetricsToLocal
import org.apache.kylin.rest.response.SQLResponse; //导入依赖的package包/类
private static void updateMetricsToLocal(SQLRequest sqlRequest, SQLResponse sqlResponse) {
if (!enabled)
return;
String projectName = sqlRequest.getProject();
String cubeName = sqlResponse.getCube();
update(getQueryMetrics("Server_Total"), sqlResponse);
update(getQueryMetrics(projectName), sqlResponse);
String cubeMetricName = projectName + ",sub=" + cubeName;
update(getQueryMetrics(cubeMetricName), sqlResponse);
}
示例15: update
import org.apache.kylin.rest.response.SQLResponse; //导入依赖的package包/类
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());
}
}