-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add caching support to join queries (#10366)
* Proposed changes for making joins cacheable * Add unit tests * Fix tests * simplify logic * Pull empty byte array logic out of CachingQueryRunner * remove useless null check * Minor refactor * Fix tests * Fix segment caching on Broker * Move join cache key computation in Broker Move join cache key computation in Broker from ResultLevelCachingQueryRunner to CachingClusteredClient * Fix compilation * Review comments * Add more tests * Fix inspection errors * Pushed condition analysis to JoinableFactory * review comments * Disable join caching for broker and add prefix key to BroadcastSegmentIndexedTable * Remove commented lines * Fix populateCache * Disable caching for selective datasources Refactored the code so that we can decide at the data source level, whether to enable cache for broker or data nodes
- Loading branch information
1 parent
4c78b51
commit 4d2a92f
Showing
58 changed files
with
1,684 additions
and
495 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
processing/src/main/java/org/apache/druid/segment/join/JoinPrefixUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.druid.segment.join; | ||
|
||
import org.apache.druid.java.util.common.IAE; | ||
import org.apache.druid.segment.column.ColumnHolder; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
/** | ||
* Utility class for working with prefixes in join operations | ||
*/ | ||
public class JoinPrefixUtils | ||
{ | ||
private static final Comparator<String> DESCENDING_LENGTH_STRING_COMPARATOR = (s1, s2) -> | ||
Integer.compare(s2.length(), s1.length()); | ||
|
||
/** | ||
* Checks that "prefix" is a valid prefix for a join clause (see {@link JoinableClause#getPrefix()}) and, if so, | ||
* returns it. Otherwise, throws an exception. | ||
*/ | ||
public static String validatePrefix(@Nullable final String prefix) | ||
{ | ||
if (prefix == null || prefix.isEmpty()) { | ||
throw new IAE("Join clause cannot have null or empty prefix"); | ||
} else if (isPrefixedBy(ColumnHolder.TIME_COLUMN_NAME, prefix) || ColumnHolder.TIME_COLUMN_NAME.equals(prefix)) { | ||
throw new IAE( | ||
"Join clause cannot have prefix[%s], since it would shadow %s", | ||
prefix, | ||
ColumnHolder.TIME_COLUMN_NAME | ||
); | ||
} else { | ||
return prefix; | ||
} | ||
} | ||
|
||
public static boolean isPrefixedBy(final String columnName, final String prefix) | ||
{ | ||
return columnName.length() > prefix.length() && columnName.startsWith(prefix); | ||
} | ||
|
||
/** | ||
* Check if any prefixes in the provided list duplicate or shadow each other. | ||
* | ||
* @param prefixes A mutable list containing the prefixes to check. This list will be sorted by descending | ||
* string length. | ||
*/ | ||
public static void checkPrefixesForDuplicatesAndShadowing( | ||
final List<String> prefixes | ||
) | ||
{ | ||
// this is a naive approach that assumes we'll typically handle only a small number of prefixes | ||
prefixes.sort(DESCENDING_LENGTH_STRING_COMPARATOR); | ||
for (int i = 0; i < prefixes.size(); i++) { | ||
String prefix = prefixes.get(i); | ||
for (int k = i + 1; k < prefixes.size(); k++) { | ||
String otherPrefix = prefixes.get(k); | ||
if (prefix.equals(otherPrefix)) { | ||
throw new IAE("Detected duplicate prefix in join clauses: [%s]", prefix); | ||
} | ||
if (isPrefixedBy(prefix, otherPrefix)) { | ||
throw new IAE("Detected conflicting prefixes in join clauses: [%s, %s]", prefix, otherPrefix); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.