Skip to content

Commit

Permalink
minor, add project filter to saved query
Browse files Browse the repository at this point in the history
  • Loading branch information
lidongsjtu authored and chenzhx committed Jan 6, 2018
1 parent f86d067 commit 2ba22a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.supercsv.io.CsvListWriter;
import org.supercsv.io.ICsvListWriter;
Expand Down Expand Up @@ -114,9 +115,9 @@ public void removeQuery(@PathVariable String id) throws IOException {

@RequestMapping(value = "/saved_queries", method = RequestMethod.GET, produces = { "application/json" })
@ResponseBody
public List<Query> getQueries() throws IOException {
public List<Query> getQueries(@RequestParam(value = "project", required = false) String project) throws IOException {
String creator = SecurityContextHolder.getContext().getAuthentication().getName();
return queryService.getQueries(creator);
return queryService.getQueries(creator, project);
}

@RequestMapping(value = "/query/format/{format}", method = RequestMethod.GET, produces = { "application/json" })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,20 @@ public void removeQuery(final String creator, final String id) throws IOExceptio
}

public List<Query> getQueries(final String creator) throws IOException {
return getQueries(creator, null);
}

public List<Query> getQueries(final String creator, final String project) throws IOException {
if (null == creator) {
return null;
}
List<Query> queries = new ArrayList<Query>();
List<Query> queries = new ArrayList<>();
QueryRecord record = queryStore.getResource(getQueryKeyById(creator), QueryRecord.class,
QueryRecordSerializer.getInstance());
if (record != null) {
for (Query query : record.getQueries()) {
queries.add(query);
if (project == null || query.getProject().equals(project))
queries.add(query);
}
}
return queries;
Expand Down Expand Up @@ -414,7 +419,7 @@ public SQLResponse doQueryWithCache(SQLRequest sqlRequest, boolean isQueryInspec

try (SetThreadName ignored = new SetThreadName("Query %s", queryContext.getQueryId())) {
long startTime = System.currentTimeMillis();

SQLResponse sqlResponse = null;
String sql = sqlRequest.getSql();
String project = sqlRequest.getProject();
Expand All @@ -433,16 +438,16 @@ public SQLResponse doQueryWithCache(SQLRequest sqlRequest, boolean isQueryInspec
if (sqlResponse == null && isQueryInspect) {
sqlResponse = new SQLResponse(null, null, 0, false, sqlRequest.getSql());
}

if (sqlResponse == null && isCreateTempStatement) {
sqlResponse = new SQLResponse(null, null, 0, false, null);
}

if (sqlResponse == null && isQueryCacheEnabled) {
sqlResponse = searchQueryInCache(sqlRequest);
Trace.addTimelineAnnotation("query cache searched");
}

// real execution if required
if (sqlResponse == null) {
try (QueryRequestLimits limit = new QueryRequestLimits(sqlRequest.getProject())) {
Expand Down Expand Up @@ -481,7 +486,7 @@ public SQLResponse doQueryWithCache(SQLRequest sqlRequest, boolean isQueryInspec
private SQLResponse queryAndUpdateCache(SQLRequest sqlRequest, long startTime, boolean queryCacheEnabled) {
KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
Message msg = MsgPicker.getMsg();

SQLResponse sqlResponse = null;
try {
final boolean isSelect = QueryUtil.isSelectStatement(sqlRequest.getSql());
Expand Down Expand Up @@ -543,8 +548,7 @@ && checkCondition(sqlResponse.getResults().size() < kylinConfig.getLargeQueryThr
}

private boolean isQueryCacheEnabled(KylinConfig kylinConfig) {
return checkCondition(kylinConfig.isQueryCacheEnabled(),
"query cache disabled in KylinConfig") && //
return checkCondition(kylinConfig.isQueryCacheEnabled(), "query cache disabled in KylinConfig") && //
checkCondition(!BackdoorToggles.getDisableCache(), "query cache disabled in BackdoorToggles");
}

Expand Down

0 comments on commit 2ba22a9

Please sign in to comment.