jihoonson commented on a change in pull request #10224:
URL: https://github.com/apache/druid/pull/10224#discussion_r470266457
##########
File path:
processing/src/main/java/org/apache/druid/segment/join/table/IndexedTableJoinable.java
##########
@@ -97,41 +103,49 @@ public JoinMatcher makeJoinMatcher(
if (filterColumnPosition < 0 || correlatedColumnPosition < 0) {
return Optional.empty();
}
+ Closer closer = Closer.create();
+ try {
+ Set<String> correlatedValues = new HashSet<>();
+ if (table.keyColumns().contains(searchColumnName)) {
+ IndexedTable.Index index = table.columnIndex(filterColumnPosition);
+ IndexedTable.Reader reader =
table.columnReader(correlatedColumnPosition);
+ closer.register(reader);
+ IntList rowIndex = index.find(searchColumnValue);
+ for (int i = 0; i < rowIndex.size(); i++) {
+ int rowNum = rowIndex.getInt(i);
+ String correlatedDimVal = Objects.toString(reader.read(rowNum),
null);
+ correlatedValues.add(correlatedDimVal);
- Set<String> correlatedValues = new HashSet<>();
- if (table.keyColumns().contains(searchColumnName)) {
- IndexedTable.Index index = table.columnIndex(filterColumnPosition);
- IndexedTable.Reader reader =
table.columnReader(correlatedColumnPosition);
- IntList rowIndex = index.find(searchColumnValue);
- for (int i = 0; i < rowIndex.size(); i++) {
- int rowNum = rowIndex.getInt(i);
- String correlatedDimVal = Objects.toString(reader.read(rowNum), null);
- correlatedValues.add(correlatedDimVal);
-
- if (correlatedValues.size() > maxCorrelationSetSize) {
+ if (correlatedValues.size() > maxCorrelationSetSize) {
+ return Optional.empty();
+ }
+ }
+ return Optional.of(correlatedValues);
+ } else {
+ if (!allowNonKeyColumnSearch) {
return Optional.empty();
}
- }
- return Optional.of(correlatedValues);
- } else {
- if (!allowNonKeyColumnSearch) {
- return Optional.empty();
- }
- IndexedTable.Reader dimNameReader =
table.columnReader(filterColumnPosition);
- IndexedTable.Reader correlatedColumnReader =
table.columnReader(correlatedColumnPosition);
- for (int i = 0; i < table.numRows(); i++) {
- String dimVal = Objects.toString(dimNameReader.read(i), null);
- if (searchColumnValue.equals(dimVal)) {
- String correlatedDimVal =
Objects.toString(correlatedColumnReader.read(i), null);
- correlatedValues.add(correlatedDimVal);
- if (correlatedValues.size() > maxCorrelationSetSize) {
- return Optional.empty();
+ IndexedTable.Reader dimNameReader =
table.columnReader(filterColumnPosition);
+ IndexedTable.Reader correlatedColumnReader =
table.columnReader(correlatedColumnPosition);
+ closer.register(dimNameReader);
+ closer.register(correlatedColumnReader);
+ for (int i = 0; i < table.numRows(); i++) {
+ String dimVal = Objects.toString(dimNameReader.read(i), null);
+ if (searchColumnValue.equals(dimVal)) {
+ String correlatedDimVal =
Objects.toString(correlatedColumnReader.read(i), null);
+ correlatedValues.add(correlatedDimVal);
+ if (correlatedValues.size() > maxCorrelationSetSize) {
+ return Optional.empty();
+ }
}
}
- }
- return Optional.of(correlatedValues);
+ return Optional.of(correlatedValues);
+ }
+ }
+ finally {
+ CloseQuietly.close(closer);
Review comment:
Can we use try-with-resources instead of `CloseQuiently`? It would be
more aligned with https://github.com/apache/druid/pull/10247 as well.
##########
File path:
server/src/main/java/org/apache/druid/segment/join/BroadcastTableJoinableFactory.java
##########
@@ -0,0 +1,79 @@
+/*
+ * 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 com.google.common.collect.Iterators;
+import com.google.inject.Inject;
+import org.apache.druid.java.util.common.ISE;
+import org.apache.druid.query.DataSource;
+import org.apache.druid.query.GlobalTableDataSource;
+import org.apache.druid.query.planning.DataSourceAnalysis;
+import org.apache.druid.segment.join.table.IndexedTableJoinable;
+import org.apache.druid.segment.join.table.ReferenceCountingIndexedTable;
+import org.apache.druid.server.SegmentManager;
+
+import java.util.Iterator;
+import java.util.Optional;
+
+public class BroadcastTableJoinableFactory implements JoinableFactory
+{
+ private final SegmentManager segmentManager;
+
+ @Inject
+ public BroadcastTableJoinableFactory(SegmentManager segmentManager)
+ {
+ this.segmentManager = segmentManager;
+ }
+
+ @Override
+ public boolean isDirectlyJoinable(DataSource dataSource)
+ {
+ GlobalTableDataSource broadcastDatasource = (GlobalTableDataSource)
dataSource;
+ return broadcastDatasource != null &&
segmentManager.hasIndexedTables(broadcastDatasource.getName());
+ }
+
+ @Override
+ public Optional<Joinable> build(
+ DataSource dataSource,
+ JoinConditionAnalysis condition
+ )
+ {
+ GlobalTableDataSource broadcastDatasource = (GlobalTableDataSource)
dataSource;
+ if (condition.canHashJoin()) {
+ DataSourceAnalysis analysis =
DataSourceAnalysis.forDataSource(broadcastDatasource);
+ return segmentManager.getIndexedTables(analysis).map(tables -> {
+ Iterator<ReferenceCountingIndexedTable> tableIterator =
tables.iterator();
+ if (!tableIterator.hasNext()) {
+ return null;
Review comment:
Should it return `Optional.empty()` instead?
##########
File path:
processing/src/main/java/org/apache/druid/segment/join/HashJoinEngine.java
##########
@@ -51,14 +52,16 @@ private HashJoinEngine()
* not be queryable through the returned Cursor. This happens even if the
right-hand joinable doesn't actually have a
* column with this name.
*/
- public static Cursor makeJoinCursor(final Cursor leftCursor, final
JoinableClause joinableClause)
+ public static Cursor makeJoinCursor(final Cursor leftCursor, final
JoinableClause joinableClause, boolean descending, final Closer closer)
Review comment:
super nit: would you add `final` for `descending` as well just to be
consistent?
##########
File path: server/src/main/java/org/apache/druid/server/SegmentManager.java
##########
@@ -258,6 +316,11 @@ public void dropSegment(final DataSegment segment)
log.info("Attempting to close segment %s", segment.getId());
oldQueryable.close();
+
+ final ReferenceCountingIndexedTable oldTable =
dataSourceState.tablesLookup.remove(segment.getId());
+ if (oldTable != null) {
+ oldTable.close();
Review comment:
Hmm, should we use `Closer` to close `oldTable` and `oldQueryable` so
that both can be closed even when any potential errors is thrown?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]