-
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 sampling factor for DeterminePartitionsJob (#13840)
There are two type of DeterminePartitionsJob: - When the input data is not assume grouped, there may be duplicate rows. In this case, two MR jobs are launched. The first one do group job to remove duplicate rows. And a second one to perform global sorting to find lower and upper bound for target segments. - When the input data is assume grouped, we only need to launch the global sorting MR job to find lower and upper bound for segments. Sampling strategy: - If the input data is assume grouped, sample by random at the mapper side of the global sort mr job. - If the input data is not assume grouped, sample at the mapper of the group job. Use hash on time and all dimensions and mod by sampling factor to sample, don't use random method because there may be duplicate rows.
- Loading branch information
Showing
14 changed files
with
258 additions
and
27 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
70 changes: 70 additions & 0 deletions
70
indexing-hadoop/src/main/java/org/apache/druid/indexer/DeterminePartitionsJobSampler.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,70 @@ | ||
/* | ||
* 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.indexer; | ||
|
||
import com.google.common.hash.HashFunction; | ||
import com.google.common.hash.Hashing; | ||
|
||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
public class DeterminePartitionsJobSampler | ||
{ | ||
private static final HashFunction HASH_FUNCTION = Hashing.murmur3_32(); | ||
|
||
private final int samplingFactor; | ||
|
||
private final int sampledTargetPartitionSize; | ||
|
||
private final int sampledMaxRowsPerSegment; | ||
|
||
public DeterminePartitionsJobSampler(int samplingFactor, int targetPartitionSize, int maxRowsPerSegment) | ||
{ | ||
this.samplingFactor = Math.max(samplingFactor, 1); | ||
this.sampledTargetPartitionSize = targetPartitionSize / this.samplingFactor; | ||
this.sampledMaxRowsPerSegment = maxRowsPerSegment / this.samplingFactor; | ||
} | ||
|
||
/** | ||
* If input rows is duplicate, we can use hash and mod to do sample. As we hash on whole group key, | ||
* there will not likely data skew if the hash function is balanced enough. | ||
*/ | ||
boolean shouldEmitRow(byte[] groupKeyBytes) | ||
{ | ||
return samplingFactor == 1 || HASH_FUNCTION.hashBytes(groupKeyBytes).asInt() % samplingFactor == 0; | ||
} | ||
|
||
/** | ||
* If input rows is not duplicate, we can sample at random. | ||
*/ | ||
boolean shouldEmitRow() | ||
{ | ||
return samplingFactor == 1 || ThreadLocalRandom.current().nextInt(samplingFactor) == 0; | ||
} | ||
|
||
public int getSampledTargetPartitionSize() | ||
{ | ||
return sampledTargetPartitionSize; | ||
} | ||
|
||
public int getSampledMaxRowsPerSegment() | ||
{ | ||
return sampledMaxRowsPerSegment; | ||
} | ||
} |
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
Oops, something went wrong.