-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7566cb3
commit 86e1285
Showing
31 changed files
with
886 additions
and
338 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
123 changes: 123 additions & 0 deletions
123
fluss-client/src/main/java/com/alibaba/fluss/client/lookup/FlussLookuper.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,123 @@ | ||
/* | ||
* Copyright (c) 2024 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed 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 com.alibaba.fluss.client.lookup; | ||
|
||
import com.alibaba.fluss.annotation.PublicEvolving; | ||
import com.alibaba.fluss.client.lakehouse.LakeTableBucketAssigner; | ||
import com.alibaba.fluss.client.metadata.MetadataUpdater; | ||
import com.alibaba.fluss.client.table.getter.PartitionGetter; | ||
import com.alibaba.fluss.metadata.TableBucket; | ||
import com.alibaba.fluss.metadata.TableInfo; | ||
import com.alibaba.fluss.row.InternalRow; | ||
import com.alibaba.fluss.row.encode.KeyEncoder; | ||
import com.alibaba.fluss.row.encode.ValueDecoder; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import static com.alibaba.fluss.client.utils.ClientUtils.getBucketId; | ||
import static com.alibaba.fluss.client.utils.ClientUtils.getPartitionId; | ||
|
||
/** | ||
* The default impl of {@link Lookuper}. | ||
* | ||
* @since 0.6 | ||
*/ | ||
@PublicEvolving | ||
public class FlussLookuper implements Lookuper { | ||
|
||
private final TableInfo tableInfo; | ||
|
||
private final MetadataUpdater metadataUpdater; | ||
|
||
private final LookupClient lookupClient; | ||
|
||
private final KeyEncoder primaryKeyEncoder; | ||
|
||
/** Extract bucket key from lookup key row. */ | ||
private final KeyEncoder bucketKeyEncoder; | ||
|
||
private final boolean isDataLakeEnable; | ||
|
||
private final int numBuckets; | ||
|
||
private final LakeTableBucketAssigner lakeTableBucketAssigner; | ||
|
||
/** a getter to extract partition from lookup key row, null when it's not a partitioned. */ | ||
private @Nullable final PartitionGetter partitionGetter; | ||
|
||
/** Decode the lookup bytes to result row. */ | ||
private final ValueDecoder kvValueDecoder; | ||
|
||
public FlussLookuper( | ||
TableInfo tableInfo, | ||
int numBuckets, | ||
MetadataUpdater metadataUpdater, | ||
LookupClient lookupClient, | ||
KeyEncoder primaryKeyEncoder, | ||
KeyEncoder bucketKeyEncoder, | ||
LakeTableBucketAssigner lakeTableBucketAssigner, | ||
@Nullable PartitionGetter partitionGetter, | ||
ValueDecoder kvValueDecoder) { | ||
this.tableInfo = tableInfo; | ||
this.numBuckets = numBuckets; | ||
this.metadataUpdater = metadataUpdater; | ||
this.lookupClient = lookupClient; | ||
this.primaryKeyEncoder = primaryKeyEncoder; | ||
this.bucketKeyEncoder = bucketKeyEncoder; | ||
this.isDataLakeEnable = tableInfo.getTableDescriptor().isDataLakeEnabled(); | ||
this.lakeTableBucketAssigner = lakeTableBucketAssigner; | ||
this.partitionGetter = partitionGetter; | ||
this.kvValueDecoder = kvValueDecoder; | ||
} | ||
|
||
@Override | ||
public CompletableFuture<LookupResult> lookup(InternalRow lookupKey) { | ||
// encoding the key row using a compacted way consisted with how the key is encoded when put | ||
// a row | ||
byte[] pkBytes = primaryKeyEncoder.encode(lookupKey); | ||
byte[] bkBytes = bucketKeyEncoder.encode(lookupKey); | ||
Long partitionId = | ||
partitionGetter == null | ||
? null | ||
: getPartitionId( | ||
lookupKey, | ||
partitionGetter, | ||
tableInfo.getTablePath(), | ||
metadataUpdater); | ||
int bucketId = | ||
getBucketId( | ||
bkBytes, | ||
lookupKey, | ||
lakeTableBucketAssigner, | ||
isDataLakeEnable, | ||
numBuckets, | ||
metadataUpdater); | ||
TableBucket tableBucket = new TableBucket(tableInfo.getTableId(), partitionId, bucketId); | ||
return lookupClient | ||
.lookup(tableBucket, pkBytes) | ||
.thenApply( | ||
valueBytes -> { | ||
InternalRow row = | ||
valueBytes == null | ||
? null | ||
: kvValueDecoder.decodeValue(valueBytes).row; | ||
return new LookupResult(row); | ||
}); | ||
} | ||
} |
123 changes: 123 additions & 0 deletions
123
fluss-client/src/main/java/com/alibaba/fluss/client/lookup/FlussPrefixLookuper.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,123 @@ | ||
/* | ||
* Copyright (c) 2024 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed 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 com.alibaba.fluss.client.lookup; | ||
|
||
import com.alibaba.fluss.annotation.PublicEvolving; | ||
import com.alibaba.fluss.client.lakehouse.LakeTableBucketAssigner; | ||
import com.alibaba.fluss.client.metadata.MetadataUpdater; | ||
import com.alibaba.fluss.client.table.getter.PartitionGetter; | ||
import com.alibaba.fluss.metadata.TableBucket; | ||
import com.alibaba.fluss.metadata.TableInfo; | ||
import com.alibaba.fluss.row.InternalRow; | ||
import com.alibaba.fluss.row.encode.KeyEncoder; | ||
import com.alibaba.fluss.row.encode.ValueDecoder; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import static com.alibaba.fluss.client.utils.ClientUtils.getBucketId; | ||
import static com.alibaba.fluss.client.utils.ClientUtils.getPartitionId; | ||
|
||
/** | ||
* The default impl of {@link PrefixLookuper}. | ||
* | ||
* @since 0.6 | ||
*/ | ||
@PublicEvolving | ||
public class FlussPrefixLookuper implements PrefixLookuper { | ||
|
||
private final TableInfo tableInfo; | ||
|
||
private final MetadataUpdater metadataUpdater; | ||
|
||
private final LookupClient lookupClient; | ||
|
||
/** Extract bucket key from prefix lookup key row. */ | ||
private final KeyEncoder bucketKeyEncoder; | ||
|
||
private final boolean isDataLakeEnable; | ||
|
||
private final int numBuckets; | ||
|
||
private final LakeTableBucketAssigner lakeTableBucketAssigner; | ||
|
||
/** | ||
* a getter to extract partition from prefix lookup key row, null when it's not a partitioned. | ||
*/ | ||
private @Nullable final PartitionGetter partitionGetter; | ||
|
||
/** Decode the lookup bytes to result row. */ | ||
private final ValueDecoder kvValueDecoder; | ||
|
||
public FlussPrefixLookuper( | ||
TableInfo tableInfo, | ||
int numBuckets, | ||
MetadataUpdater metadataUpdater, | ||
LookupClient lookupClient, | ||
KeyEncoder bucketKeyEncoder, | ||
LakeTableBucketAssigner lakeTableBucketAssigner, | ||
@Nullable PartitionGetter partitionGetter, | ||
ValueDecoder kvValueDecoder) { | ||
this.tableInfo = tableInfo; | ||
this.numBuckets = numBuckets; | ||
this.metadataUpdater = metadataUpdater; | ||
this.lookupClient = lookupClient; | ||
this.isDataLakeEnable = tableInfo.getTableDescriptor().isDataLakeEnabled(); | ||
this.lakeTableBucketAssigner = lakeTableBucketAssigner; | ||
this.bucketKeyEncoder = bucketKeyEncoder; | ||
this.partitionGetter = partitionGetter; | ||
this.kvValueDecoder = kvValueDecoder; | ||
} | ||
|
||
@Override | ||
public CompletableFuture<PrefixLookupResult> prefixLookup(InternalRow prefixKey) { | ||
byte[] prefixKeyBytes = bucketKeyEncoder.encode(prefixKey); | ||
int bucketId = | ||
getBucketId( | ||
prefixKeyBytes, | ||
prefixKey, | ||
lakeTableBucketAssigner, | ||
isDataLakeEnable, | ||
numBuckets, | ||
metadataUpdater); | ||
|
||
Long partitionId = null; | ||
if (partitionGetter != null) { | ||
partitionId = | ||
getPartitionId( | ||
prefixKey, partitionGetter, tableInfo.getTablePath(), metadataUpdater); | ||
} | ||
|
||
TableBucket tableBucket = new TableBucket(tableInfo.getTableId(), partitionId, bucketId); | ||
return lookupClient | ||
.prefixLookup(tableBucket, prefixKeyBytes) | ||
.thenApply( | ||
result -> { | ||
List<InternalRow> rowList = new ArrayList<>(); | ||
for (byte[] valueBytes : result) { | ||
rowList.add( | ||
valueBytes == null | ||
? null | ||
: kvValueDecoder.decodeValue(valueBytes).row); | ||
} | ||
return new PrefixLookupResult(rowList); | ||
}); | ||
} | ||
} |
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.