@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)); 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()); }
public void logQuery(final SQLRequest request, final SQLResponse response, final Date startTime, final Date endTime) { final String user = SecurityContextHolder.getContext().getAuthentication().getName(); final Set<String> realizationNames = new HashSet<String>(); final Set<Long> cuboidIds = new HashSet<Long>(); long totalScanCount = 0; float duration = (endTime.getTime() - startTime.getTime()) / (float) 1000; if (!response.isHitCache() && null != OLAPContext.getThreadLocalContexts()) { for (OLAPContext ctx : OLAPContext.getThreadLocalContexts()) { Cuboid cuboid = ctx.storageContext.getCuboid(); if (cuboid != null) { cuboidIds.add(cuboid.getId()); } if (ctx.realization != null) { String realizationName = ctx.realization.getName(); realizationNames.add(realizationName); } totalScanCount += ctx.storageContext.getTotalScanCount(); } } int resultRowCount = 0; if (!response.getIsException() && response.getResults() != null) { resultRowCount = response.getResults().size(); } QueryMetrics.getInstance().increase("duration", duration); QueryMetrics.getInstance().increase("totalScanCount", (float) totalScanCount); QueryMetrics.getInstance().increase("count", (float) 1); String newLine = System.getProperty("line.separator"); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(newLine); stringBuilder.append("==========================[QUERY]===============================").append(newLine); stringBuilder.append("SQL: ").append(request.getSql()).append(newLine); stringBuilder.append("User: ").append(user).append(newLine); stringBuilder.append("Success: ").append((null == response.getExceptionMessage())).append(newLine); stringBuilder.append("Duration: ").append(duration).append(newLine); stringBuilder.append("Project: ").append(request.getProject()).append(newLine); stringBuilder.append("Realization Names: ").append(realizationNames).append(newLine); stringBuilder.append("Cuboid Ids: ").append(cuboidIds).append(newLine); stringBuilder.append("Total scan count: ").append(totalScanCount).append(newLine); stringBuilder.append("Result row count: ").append(resultRowCount).append(newLine); stringBuilder.append("Accept Partial: ").append(request.isAcceptPartial()).append(newLine); stringBuilder.append("Is Partial Result: ").append(response.isPartial()).append(newLine); stringBuilder.append("Hit Cache: ").append(response.isHitCache()).append(newLine); stringBuilder.append("Message: ").append(response.getExceptionMessage()).append(newLine); stringBuilder.append("==========================[QUERY]===============================").append(newLine); logger.info(stringBuilder.toString()); }
QueryService extends BasicService { public void logQuery(final SQLRequest request, final SQLResponse response, final Date startTime, final Date endTime) { final String user = SecurityContextHolder.getContext().getAuthentication().getName(); final Set<String> realizationNames = new HashSet<String>(); final Set<Long> cuboidIds = new HashSet<Long>(); long totalScanCount = 0; float duration = (endTime.getTime() - startTime.getTime()) / (float) 1000; if (!response.isHitCache() && null != OLAPContext.getThreadLocalContexts()) { for (OLAPContext ctx : OLAPContext.getThreadLocalContexts()) { Cuboid cuboid = ctx.storageContext.getCuboid(); if (cuboid != null) { cuboidIds.add(cuboid.getId()); } if (ctx.realization != null) { String realizationName = ctx.realization.getName(); realizationNames.add(realizationName); } totalScanCount += ctx.storageContext.getTotalScanCount(); } } int resultRowCount = 0; if (!response.getIsException() && response.getResults() != null) { resultRowCount = response.getResults().size(); } QueryMetrics.getInstance().increase("duration", duration); QueryMetrics.getInstance().increase("totalScanCount", (float) totalScanCount); QueryMetrics.getInstance().increase("count", (float) 1); String newLine = System.getProperty("line.separator"); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(newLine); stringBuilder.append("==========================[QUERY]===============================").append(newLine); stringBuilder.append("SQL: ").append(request.getSql()).append(newLine); stringBuilder.append("User: ").append(user).append(newLine); stringBuilder.append("Success: ").append((null == response.getExceptionMessage())).append(newLine); stringBuilder.append("Duration: ").append(duration).append(newLine); stringBuilder.append("Project: ").append(request.getProject()).append(newLine); stringBuilder.append("Realization Names: ").append(realizationNames).append(newLine); stringBuilder.append("Cuboid Ids: ").append(cuboidIds).append(newLine); stringBuilder.append("Total scan count: ").append(totalScanCount).append(newLine); stringBuilder.append("Result row count: ").append(resultRowCount).append(newLine); stringBuilder.append("Accept Partial: ").append(request.isAcceptPartial()).append(newLine); stringBuilder.append("Is Partial Result: ").append(response.isPartial()).append(newLine); stringBuilder.append("Hit Cache: ").append(response.isHitCache()).append(newLine); stringBuilder.append("Message: ").append(response.getExceptionMessage()).append(newLine); stringBuilder.append("==========================[QUERY]===============================").append(newLine); logger.info(stringBuilder.toString()); } }
QueryService extends BasicService { public void logQuery(final SQLRequest request, final SQLResponse response, final Date startTime, final Date endTime) { final String user = SecurityContextHolder.getContext().getAuthentication().getName(); final Set<String> realizationNames = new HashSet<String>(); final Set<Long> cuboidIds = new HashSet<Long>(); long totalScanCount = 0; float duration = (endTime.getTime() - startTime.getTime()) / (float) 1000; if (!response.isHitCache() && null != OLAPContext.getThreadLocalContexts()) { for (OLAPContext ctx : OLAPContext.getThreadLocalContexts()) { Cuboid cuboid = ctx.storageContext.getCuboid(); if (cuboid != null) { cuboidIds.add(cuboid.getId()); } if (ctx.realization != null) { String realizationName = ctx.realization.getName(); realizationNames.add(realizationName); } totalScanCount += ctx.storageContext.getTotalScanCount(); } } int resultRowCount = 0; if (!response.getIsException() && response.getResults() != null) { resultRowCount = response.getResults().size(); } QueryMetrics.getInstance().increase("duration", duration); QueryMetrics.getInstance().increase("totalScanCount", (float) totalScanCount); QueryMetrics.getInstance().increase("count", (float) 1); String newLine = System.getProperty("line.separator"); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(newLine); stringBuilder.append("==========================[QUERY]===============================").append(newLine); stringBuilder.append("SQL: ").append(request.getSql()).append(newLine); stringBuilder.append("User: ").append(user).append(newLine); stringBuilder.append("Success: ").append((null == response.getExceptionMessage())).append(newLine); stringBuilder.append("Duration: ").append(duration).append(newLine); stringBuilder.append("Project: ").append(request.getProject()).append(newLine); stringBuilder.append("Realization Names: ").append(realizationNames).append(newLine); stringBuilder.append("Cuboid Ids: ").append(cuboidIds).append(newLine); stringBuilder.append("Total scan count: ").append(totalScanCount).append(newLine); stringBuilder.append("Result row count: ").append(resultRowCount).append(newLine); stringBuilder.append("Accept Partial: ").append(request.isAcceptPartial()).append(newLine); stringBuilder.append("Is Partial Result: ").append(response.isPartial()).append(newLine); stringBuilder.append("Hit Cache: ").append(response.isHitCache()).append(newLine); stringBuilder.append("Message: ").append(response.getExceptionMessage()).append(newLine); stringBuilder.append("==========================[QUERY]===============================").append(newLine); logger.info(stringBuilder.toString()); } QueryService(); }
QueryService extends BasicService { public void logQuery(final SQLRequest request, final SQLResponse response, final Date startTime, final Date endTime) { final String user = SecurityContextHolder.getContext().getAuthentication().getName(); final Set<String> realizationNames = new HashSet<String>(); final Set<Long> cuboidIds = new HashSet<Long>(); long totalScanCount = 0; float duration = (endTime.getTime() - startTime.getTime()) / (float) 1000; if (!response.isHitCache() && null != OLAPContext.getThreadLocalContexts()) { for (OLAPContext ctx : OLAPContext.getThreadLocalContexts()) { Cuboid cuboid = ctx.storageContext.getCuboid(); if (cuboid != null) { cuboidIds.add(cuboid.getId()); } if (ctx.realization != null) { String realizationName = ctx.realization.getName(); realizationNames.add(realizationName); } totalScanCount += ctx.storageContext.getTotalScanCount(); } } int resultRowCount = 0; if (!response.getIsException() && response.getResults() != null) { resultRowCount = response.getResults().size(); } QueryMetrics.getInstance().increase("duration", duration); QueryMetrics.getInstance().increase("totalScanCount", (float) totalScanCount); QueryMetrics.getInstance().increase("count", (float) 1); String newLine = System.getProperty("line.separator"); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(newLine); stringBuilder.append("==========================[QUERY]===============================").append(newLine); stringBuilder.append("SQL: ").append(request.getSql()).append(newLine); stringBuilder.append("User: ").append(user).append(newLine); stringBuilder.append("Success: ").append((null == response.getExceptionMessage())).append(newLine); stringBuilder.append("Duration: ").append(duration).append(newLine); stringBuilder.append("Project: ").append(request.getProject()).append(newLine); stringBuilder.append("Realization Names: ").append(realizationNames).append(newLine); stringBuilder.append("Cuboid Ids: ").append(cuboidIds).append(newLine); stringBuilder.append("Total scan count: ").append(totalScanCount).append(newLine); stringBuilder.append("Result row count: ").append(resultRowCount).append(newLine); stringBuilder.append("Accept Partial: ").append(request.isAcceptPartial()).append(newLine); stringBuilder.append("Is Partial Result: ").append(response.isPartial()).append(newLine); stringBuilder.append("Hit Cache: ").append(response.isHitCache()).append(newLine); stringBuilder.append("Message: ").append(response.getExceptionMessage()).append(newLine); stringBuilder.append("==========================[QUERY]===============================").append(newLine); logger.info(stringBuilder.toString()); } QueryService(); List<TableMeta> getMetadata(String project); SQLResponse query(SQLRequest sqlRequest); void saveQuery(final String creator, final Query query); void removeQuery(final String creator, final String id); List<Query> getQueries(final String creator); void logQuery(final SQLRequest request, final SQLResponse response, final Date startTime, final Date endTime); @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'MANAGEMENT')" + " or hasPermission(#cube, 'OPERATION') or hasPermission(#cube, 'READ')") void checkAuthorization(CubeInstance cube); }
QueryService extends BasicService { public void logQuery(final SQLRequest request, final SQLResponse response, final Date startTime, final Date endTime) { final String user = SecurityContextHolder.getContext().getAuthentication().getName(); final Set<String> realizationNames = new HashSet<String>(); final Set<Long> cuboidIds = new HashSet<Long>(); long totalScanCount = 0; float duration = (endTime.getTime() - startTime.getTime()) / (float) 1000; if (!response.isHitCache() && null != OLAPContext.getThreadLocalContexts()) { for (OLAPContext ctx : OLAPContext.getThreadLocalContexts()) { Cuboid cuboid = ctx.storageContext.getCuboid(); if (cuboid != null) { cuboidIds.add(cuboid.getId()); } if (ctx.realization != null) { String realizationName = ctx.realization.getName(); realizationNames.add(realizationName); } totalScanCount += ctx.storageContext.getTotalScanCount(); } } int resultRowCount = 0; if (!response.getIsException() && response.getResults() != null) { resultRowCount = response.getResults().size(); } QueryMetrics.getInstance().increase("duration", duration); QueryMetrics.getInstance().increase("totalScanCount", (float) totalScanCount); QueryMetrics.getInstance().increase("count", (float) 1); String newLine = System.getProperty("line.separator"); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(newLine); stringBuilder.append("==========================[QUERY]===============================").append(newLine); stringBuilder.append("SQL: ").append(request.getSql()).append(newLine); stringBuilder.append("User: ").append(user).append(newLine); stringBuilder.append("Success: ").append((null == response.getExceptionMessage())).append(newLine); stringBuilder.append("Duration: ").append(duration).append(newLine); stringBuilder.append("Project: ").append(request.getProject()).append(newLine); stringBuilder.append("Realization Names: ").append(realizationNames).append(newLine); stringBuilder.append("Cuboid Ids: ").append(cuboidIds).append(newLine); stringBuilder.append("Total scan count: ").append(totalScanCount).append(newLine); stringBuilder.append("Result row count: ").append(resultRowCount).append(newLine); stringBuilder.append("Accept Partial: ").append(request.isAcceptPartial()).append(newLine); stringBuilder.append("Is Partial Result: ").append(response.isPartial()).append(newLine); stringBuilder.append("Hit Cache: ").append(response.isHitCache()).append(newLine); stringBuilder.append("Message: ").append(response.getExceptionMessage()).append(newLine); stringBuilder.append("==========================[QUERY]===============================").append(newLine); logger.info(stringBuilder.toString()); } QueryService(); List<TableMeta> getMetadata(String project); SQLResponse query(SQLRequest sqlRequest); void saveQuery(final String creator, final Query query); void removeQuery(final String creator, final String id); List<Query> getQueries(final String creator); void logQuery(final SQLRequest request, final SQLResponse response, final Date startTime, final Date endTime); @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'MANAGEMENT')" + " or hasPermission(#cube, 'OPERATION') or hasPermission(#cube, 'READ')") void checkAuthorization(CubeInstance cube); static final String USER_QUERY_FAMILY; }