jtuglu1 commented on code in PR #18568:
URL: https://github.com/apache/druid/pull/18568#discussion_r2395978203
##########
processing/src/main/java/org/apache/druid/query/scan/ScanQueryQueryToolChest.java:
##########
@@ -191,6 +198,76 @@ public Sequence<Object[]> resultsAsArrays(final ScanQuery
query, final Sequence<
);
}
+ @Override
+ public CacheStrategy<ScanResultValue, ScanResultValue, ScanQuery>
getCacheStrategy(
+ final ScanQuery query,
+ @Nullable final ObjectMapper objectMapper
+ )
+ {
+ return new CacheStrategy<>()
+ {
+ @Override
+ public boolean isCacheable(ScanQuery query, boolean willMergeRunners,
boolean segmentLevel)
+ {
+ // Currently, there is no bijective mapping from ScanResultValue to
Result<BySegmentResultValueClass<ScanResultValue>>.
+ // This means queries will fail if:
+ // - A query is issued with bySegment:true
+ // - Segment-level cache is enabled on the broker (in which case it
sends bySegment queries to data nodes).
+ return !query.context().isBySegment() && (!segmentLevel ||
willMergeRunners);
+ }
+
+ @Override
+ public byte[] computeCacheKey(ScanQuery query)
+ {
+ CacheKeyBuilder builder = new CacheKeyBuilder(SCAN_QUERY)
+ .appendByte(CACHE_STRATEGY_VERSION)
+ .appendCacheable(query.getDataSource())
+ .appendCacheable(query.getVirtualColumns())
+ .appendString(query.getResultFormat().toString())
+ .appendLong(query.getScanRowsOffset())
+ .appendLong(query.getScanRowsLimit())
+ .appendCacheable(query.getFilter())
+ .appendStrings(query.getColumns() != null ? query.getColumns() :
List.of())
+ .appendString(query.getTimeOrder().toString());
+
+ List<OrderBy> orderBys = query.getOrderBys();
+ if (orderBys != null) {
+ for (OrderBy orderBy : orderBys) {
+ builder.appendString(orderBy.getColumnName())
+ .appendString(orderBy.getOrder().toString());
+ }
+ }
+
+ return builder.build();
+ }
+
+ @Override
+ public byte[] computeResultLevelCacheKey(ScanQuery query)
+ {
+ // Use the same key as segment-level cache no result-level
transformations like aggregations
+ return computeCacheKey(query);
+ }
+
+ @Override
+ public TypeReference<ScanResultValue> getCacheObjectClazz()
+ {
+ return TYPE_REFERENCE;
+ }
+
+ @Override
+ public Function<ScanResultValue, ScanResultValue>
prepareForCache(boolean isResultLevelCache)
Review Comment:
Because of perSegment query type. See the explanation in the PR description.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]