![JAR search and dependency download from the Maven repository](/logo.png)
org.dinky.shaded.paimon.crosspartition.BucketAssigner Maven / Gradle / Ivy
The newest version!
/*
* 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.dinky.shaded.paimon.crosspartition;
import org.dinky.shaded.paimon.data.BinaryRow;
import org.dinky.shaded.paimon.utils.Filter;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
/** Bucket Assigner to assign bucket in a partition. */
public class BucketAssigner {
private final Map> stats = new HashMap<>();
public void bootstrapBucket(BinaryRow part, int bucket) {
TreeMap bucketMap = bucketMap(part);
Integer count = bucketMap.get(bucket);
if (count == null) {
count = 0;
}
bucketMap.put(bucket, count + 1);
}
public int assignBucket(BinaryRow part, Filter filter, int maxCount) {
TreeMap bucketMap = bucketMap(part);
for (Map.Entry entry : bucketMap.entrySet()) {
int bucket = entry.getKey();
int count = entry.getValue();
if (filter.test(bucket) && count < maxCount) {
bucketMap.put(bucket, count + 1);
return bucket;
}
}
for (int i = 0; ; i++) {
if (filter.test(i) && !bucketMap.containsKey(i)) {
bucketMap.put(i, 1);
return i;
}
}
}
public void decrement(BinaryRow part, int bucket) {
bucketMap(part).compute(bucket, (k, v) -> v == null ? 0 : v - 1);
}
private TreeMap bucketMap(BinaryRow part) {
TreeMap map = stats.get(part);
if (map == null) {
map = new TreeMap<>();
stats.put(part.copy(), map);
}
return map;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy