Skip to content

Commit

Permalink
[Bug] Fix the incorrect lookup join result when lookup from level0 (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
Aitozi authored Feb 27, 2024
1 parent ece4f84 commit f6c8c46
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ public static <T> T lookup(
BiFunctionWithIOE<InternalRow, SortedRun, T> lookup,
BiFunctionWithIOE<InternalRow, TreeSet<DataFileMeta>, T> level0Lookup)
throws IOException {
if (startLevel == 0) {
return level0Lookup.apply(key, levels.level0());
}

T result = null;
for (int i = startLevel; i < levels.numberOfLevels(); i++) {
SortedRun level = levels.runOfLevel(i);
result = lookup.apply(key, level);
if (i == 0) {
result = level0Lookup.apply(key, levels.level0());
} else {
SortedRun level = levels.runOfLevel(i);
result = lookup.apply(key, level);
}
if (result != null) {
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,41 @@ public void testLookupEmptyLevel() throws IOException {
assertThat(kv).isNotNull();
}

@Test
public void testLookupLevel0() throws Exception {
Levels levels =
new Levels(
comparator,
Arrays.asList(
newFile(0, kv(1, 0)),
newFile(1, kv(1, 11), kv(3, 33), kv(5, 5)),
newFile(2, kv(2, 22), kv(5, 55))),
3);
LookupLevels lookupLevels = createLookupLevels(levels, MemorySize.ofMebiBytes(10));

KeyValue kv = lookupLevels.lookup(row(1), 0);
assertThat(kv).isNotNull();
assertThat(kv.sequenceNumber()).isEqualTo(UNKNOWN_SEQUENCE);
assertThat(kv.level()).isEqualTo(0);
assertThat(kv.value().getInt(1)).isEqualTo(0);

levels =
new Levels(
comparator,
Arrays.asList(
newFile(1, kv(1, 11), kv(3, 33), kv(5, 5)),
newFile(2, kv(2, 22), kv(5, 55))),
3);
lookupLevels = createLookupLevels(levels, MemorySize.ofMebiBytes(10));

// not in level 0
kv = lookupLevels.lookup(row(1), 0);
assertThat(kv).isNotNull();
assertThat(kv.sequenceNumber()).isEqualTo(UNKNOWN_SEQUENCE);
assertThat(kv.level()).isEqualTo(1);
assertThat(kv.value().getInt(1)).isEqualTo(11);
}

private LookupLevels createLookupLevels(Levels levels, MemorySize maxDiskSize) {
return new LookupLevels(
levels,
Expand Down

0 comments on commit f6c8c46

Please sign in to comment.