Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.fluss.client.metadata.KvSnapshots;
import org.apache.fluss.client.metadata.LakeSnapshot;
import org.apache.fluss.client.metadata.RemoteLogManifestInfo;
import org.apache.fluss.client.utils.ClientUtils;
import org.apache.fluss.cluster.ServerNode;
import org.apache.fluss.cluster.rebalance.GoalType;
import org.apache.fluss.cluster.rebalance.RebalanceProgress;
Expand Down Expand Up @@ -72,8 +73,10 @@
import org.apache.fluss.metadata.TableInfo;
import org.apache.fluss.metadata.TablePath;
import org.apache.fluss.metadata.TableStats;
import org.apache.fluss.predicate.Predicate;
import org.apache.fluss.security.acl.AclBinding;
import org.apache.fluss.security.acl.AclBindingFilter;
import org.apache.fluss.utils.PartitionUtils;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -435,6 +438,39 @@ CompletableFuture<List<PartitionInfo>> listPartitionInfos(
CompletableFuture<List<PartitionInfo>> listPartitionInfos(
TablePath tablePath, PartitionSpec partialPartitionSpec);

/**
* Lists regular partitions that match a predicate asynchronously.
*
* <p>The predicate must use the field order and types of {@link
* PartitionUtils#partitionRowType(TableInfo)}.
*
* @param tablePath The path of the partitioned table.
* @param predicate The predicate on partition keys.
*/
default CompletableFuture<List<PartitionInfo>> listPartitionInfosByPredicate(
TablePath tablePath, Predicate predicate) {
return getTableInfo(tablePath)
.thenCompose(tableInfo -> listPartitionInfosByPredicate(tableInfo, predicate));
}

/**
* Lists regular partitions that match a predicate using already resolved table metadata.
*
* @param tableInfo Current metadata for the partitioned table.
* @param predicate The predicate on the partition row type of the table.
* @see #listPartitionInfosByPredicate(TablePath, Predicate)
*/
default CompletableFuture<List<PartitionInfo>> listPartitionInfosByPredicate(
TableInfo tableInfo, Predicate predicate) {
return listPartitionInfos(tableInfo.getTablePath())
.thenApply(
partitions ->
ClientUtils.filterPartitionInfos(
partitions,
PartitionUtils.partitionRowType(tableInfo),
predicate));
}

/**
* Create a new partition for a partitioned table.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.apache.fluss.exception.NotCoordinatorLeaderException;
import org.apache.fluss.exception.PartitionNotExistException;
import org.apache.fluss.exception.RetriableException;
import org.apache.fluss.exception.TableNotPartitionedException;
import org.apache.fluss.metadata.BucketInfo;
import org.apache.fluss.metadata.DatabaseChange;
import org.apache.fluss.metadata.DatabaseDescriptor;
Expand All @@ -59,6 +60,7 @@
import org.apache.fluss.metadata.TableInfo;
import org.apache.fluss.metadata.TablePath;
import org.apache.fluss.metadata.TableStats;
import org.apache.fluss.predicate.Predicate;
import org.apache.fluss.rpc.GatewayClientProxy;
import org.apache.fluss.rpc.RetryableGatewayClientProxy;
import org.apache.fluss.rpc.RpcClient;
Expand Down Expand Up @@ -117,7 +119,6 @@
import org.apache.fluss.rpc.messages.PbListOffsetsRespForBucket;
import org.apache.fluss.rpc.messages.PbListedGroup;
import org.apache.fluss.rpc.messages.PbPartitionInfo;
import org.apache.fluss.rpc.messages.PbTablePath;
import org.apache.fluss.rpc.messages.PbTableStatsRespForBucket;
import org.apache.fluss.rpc.messages.RebalanceRequest;
import org.apache.fluss.rpc.messages.RebalanceResponse;
Expand All @@ -126,9 +127,12 @@
import org.apache.fluss.rpc.messages.TableExistsRequest;
import org.apache.fluss.rpc.messages.TableExistsResponse;
import org.apache.fluss.rpc.protocol.ApiError;
import org.apache.fluss.rpc.util.PredicateMessageUtils;
import org.apache.fluss.security.acl.AclBinding;
import org.apache.fluss.security.acl.AclBindingFilter;
import org.apache.fluss.types.RowType;
import org.apache.fluss.utils.ExceptionUtils;
import org.apache.fluss.utils.PartitionUtils;
import org.apache.fluss.utils.concurrent.ExecutorThreadFactory;
import org.apache.fluss.utils.concurrent.FutureUtils;

Expand Down Expand Up @@ -501,22 +505,50 @@ public CompletableFuture<List<PartitionInfo>> listPartitionInfos(
return listPartitionInfos(tablePath, partitionSpec, false);
}

@Override
public CompletableFuture<List<PartitionInfo>> listPartitionInfosByPredicate(
TableInfo tableInfo, Predicate predicate) {
TablePath tablePath = tableInfo.getTablePath();
if (!tableInfo.isPartitioned()) {
return FutureUtils.completedExceptionally(
new TableNotPartitionedException(
"Table '" + tablePath + "' is not a partitioned table."));
}
RowType partitionRowType = PartitionUtils.partitionRowType(tableInfo);
ListPartitionInfosRequest request = createListPartitionInfosRequest(tablePath);
try {
request.setPartitionPredicate(
PredicateMessageUtils.toPbPredicate(predicate, partitionRowType));
} catch (IllegalArgumentException e) {
return FutureUtils.completedExceptionally(e);
}
return sendListPartitionInfosRequest(tablePath, false, request)
.thenApply(
// Older servers ignore the optional predicate and return all partitions.
partitions ->
ClientUtils.filterPartitionInfos(
partitions, partitionRowType, predicate));
}

private CompletableFuture<List<PartitionInfo>> listPartitionInfos(
TablePath tablePath,
@Nullable PartitionSpec partitionSpec,
boolean includeSystemPartitions) {
ListPartitionInfosRequest request = new ListPartitionInfosRequest();
request.setTablePath(
new PbTablePath()
.setDatabaseName(tablePath.getDatabaseName())
.setTableName(tablePath.getTableName()));
ListPartitionInfosRequest request = createListPartitionInfosRequest(tablePath);
if (partitionSpec != null) {
request.setPartialPartitionSpec(makePbPartitionSpec(partitionSpec));
}
if (includeSystemPartitions) {
request.setIncludeSystemPartitions(true);
}

return sendListPartitionInfosRequest(tablePath, includeSystemPartitions, request);
}

private CompletableFuture<List<PartitionInfo>> sendListPartitionInfosRequest(
TablePath tablePath,
boolean includeSystemPartitions,
ListPartitionInfosRequest request) {
return readOnlyGateway
.listPartitionInfos(request)
.thenCompose(
Expand Down Expand Up @@ -1462,4 +1494,12 @@ private static void validateRackRequest(List<String> racks, ServerTag serverTag)
"rack element must not be null, empty, or whitespace-only");
}
}

private static ListPartitionInfosRequest createListPartitionInfosRequest(TablePath tablePath) {
ListPartitionInfosRequest request = new ListPartitionInfosRequest();
request.setTablePath()
.setDatabaseName(tablePath.getDatabaseName())
.setTableName(tablePath.getTableName());
return request;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@

import org.apache.fluss.config.ConfigOptions;
import org.apache.fluss.exception.IllegalConfigurationException;
import org.apache.fluss.metadata.PartitionInfo;
import org.apache.fluss.metadata.TableInfo;
import org.apache.fluss.predicate.Predicate;
import org.apache.fluss.types.RowType;
import org.apache.fluss.utils.PartitionUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -29,6 +33,7 @@
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/** Utils for Fluss Client. */
public final class ClientUtils {
Expand All @@ -40,6 +45,21 @@ public final class ClientUtils {

private ClientUtils() {}

/** Filters regular partition metadata using the same typed values as server-side pruning. */
public static List<PartitionInfo> filterPartitionInfos(
List<PartitionInfo> partitions, RowType partitionRowType, Predicate predicate) {
return partitions.stream()
.filter(
partition ->
predicate.test(
PartitionUtils.toPartitionRow(
partition
.getResolvedPartitionSpec()
.getPartitionValues(),
partitionRowType)))
.collect(Collectors.toList());
}

// todo: may add DnsLookup
public static List<InetSocketAddress> parseAndValidateAddresses(List<String> urls) {
if (urls == null) {
Expand Down
Loading
Loading