ilooner commented on a change in pull request #1606: Drill 6845: Semi-Hash-Join to skip incoming build duplicates, automatically stop skipping if too few URL: https://github.com/apache/drill/pull/1606#discussion_r247010925
########## File path: exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/HashJoinSpillControlImpl.java ########## @@ -0,0 +1,52 @@ +/* + * 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.drill.exec.physical.impl.join; + + import org.apache.drill.exec.memory.BufferAllocator; + import org.apache.drill.exec.record.RecordBatchSizer; + import org.apache.drill.exec.record.VectorContainer; + +/** + * This class is currently used only for Semi-Hash-Join that avoids duplicates by the use of a hash table + * The method {@link HashJoinMemoryCalculator.HashJoinSpillControl#shouldSpill(VectorContainer)} returns true if the memory available now to the allocator if not enough + * to hold (a multiple of, for safety) a new allocated batch + */ +public class HashJoinSpillControlImpl implements HashJoinMemoryCalculator.HashJoinSpillControl { + private BufferAllocator allocator; + private int recordsPerBatch; + private int minBatchesInAvailableMemory; + + HashJoinSpillControlImpl(BufferAllocator allocator, int recordsPerBatch, int minBatchesInAvailableMemory) { + this.allocator = allocator; + this.recordsPerBatch = recordsPerBatch; + this.minBatchesInAvailableMemory = minBatchesInAvailableMemory; + } + + @Override + public boolean shouldSpill(VectorContainer currentVectorContainer) { + assert currentVectorContainer.hasRecordCount(); Review comment: Boaz I still think we need to address the other two cases. - **"Reserving space for the incoming probe batch: Not needed - The incoming size is not charged to the Hash-Join's available memory"** This statement is not completely accurate. If the HashJoin operator has **not spilled** then this is correct. The upstream operator owns the probe batch and we don't need to account for it. But if we are processing a **spilled partition** the probe batch is read from the SpilledRecord batch and the HashJoin operator owns the memory for the probe batch. In the code snippet I proposed we would account for the probe batch in this case. - **"Reserving room for the partial batches of each partition: This in a way is covered by this code, which is called prior to allocating these batches."** I don't see how it's accounted for with the rest of the code. You are using a heuristic to save room for 3 partition batches and it is tunable by the user. This approach is problematic since it will not be sufficient if there are a large number of partitions (16 or 32). So the user will have to change the **minBatchesInAvailableMemory** setting to tune the operator for their data and the number of partitions. If we can easily account for this explicitly and automatically for the user, why not do it? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
