4949import java .util .Set ;
5050
5151import static org .apache .paimon .table .BucketMode .POSTPONE_BUCKET ;
52+ import static org .apache .paimon .utils .Preconditions .checkArgument ;
5253
5354/** Lookup table for primary key which supports to read the LSM tree directly. */
5455public class PrimaryKeyPartialLookupTable implements LookupTable {
@@ -209,7 +210,8 @@ static class LocalQueryExecutor implements QueryExecutor {
209210 private final StreamTableScan scan ;
210211 private final String tableName ;
211212
212- private final Map <BinaryRow , Integer > totalBuckets ;
213+ private final Integer defaultNumBuckets ;
214+ private final Map <BinaryRow , Integer > numBuckets ;
213215
214216 private LocalQueryExecutor (
215217 FileStoreTable table ,
@@ -238,13 +240,14 @@ private LocalQueryExecutor(
238240 .newStreamScan ();
239241
240242 this .tableName = table .name ();
241- this .totalBuckets = new HashMap <>();
243+ this .defaultNumBuckets = table .bucketSpec ().getNumBuckets ();
244+ this .numBuckets = new HashMap <>();
242245 }
243246
244247 @ Override
245248 @ Nullable
246249 public Integer numBuckets (BinaryRow partition ) {
247- return totalBuckets .get (partition );
250+ return numBuckets .get (partition );
248251 }
249252
250253 @ Override
@@ -264,18 +267,30 @@ public void refresh() {
264267 }
265268
266269 for (Split split : splits ) {
267- DataSplit dataSplit = (DataSplit ) split ;
268- BinaryRow partition = dataSplit .partition ();
269- int bucket = dataSplit .bucket ();
270- List <DataFileMeta > before = dataSplit .beforeFiles ();
271- List <DataFileMeta > after = dataSplit .dataFiles ();
272-
273- tableQuery .refreshFiles (partition , bucket , before , after );
274- totalBuckets .put (partition , dataSplit .totalBuckets ());
270+ refreshSplit ((DataSplit ) split );
275271 }
276272 }
277273 }
278274
275+ @ VisibleForTesting
276+ void refreshSplit (DataSplit split ) {
277+ BinaryRow partition = split .partition ();
278+ int bucket = split .bucket ();
279+ List <DataFileMeta > before = split .beforeFiles ();
280+ List <DataFileMeta > after = split .dataFiles ();
281+
282+ tableQuery .refreshFiles (partition , bucket , before , after );
283+ Integer totalBuckets = split .totalBuckets ();
284+ if (totalBuckets == null ) {
285+ // Just for compatibility with older versions
286+ checkArgument (
287+ defaultNumBuckets > 0 ,
288+ "This is a bug, old version table numBuckets should be greater than 0." );
289+ totalBuckets = defaultNumBuckets ;
290+ }
291+ numBuckets .put (partition , totalBuckets );
292+ }
293+
279294 @ Override
280295 public void close () throws IOException {
281296 tableQuery .close ();
0 commit comments