Skip to content

Commit

Permalink
[BugFix] Fix getRemoteFiles error for paimon system table.
Browse files Browse the repository at this point in the history
Signed-off-by: Jiao Mingye <mxdzs0612@gmail.com>
  • Loading branch information
mxdzs0612 committed Feb 24, 2025
1 parent 2bad402 commit f2d3aa7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,13 @@ public List<RemoteFileInfo> getRemoteFiles(Table table, GetRemoteFilesParams par
RemoteFileInfo remoteFileInfo = new RemoteFileInfo();
PaimonTable paimonTable = (PaimonTable) table;
long latestSnapshotId = -1L;
if (paimonTable.getNativeTable().latestSnapshotId().isPresent()) {
latestSnapshotId = paimonTable.getNativeTable().latestSnapshotId().getAsLong();
try {
if (paimonTable.getNativeTable().latestSnapshotId().isPresent()) {
latestSnapshotId = paimonTable.getNativeTable().latestSnapshotId().getAsLong();
}
} catch (Exception e) {
// System table does not have snapshotId, ignore it.
LOG.warn("Cannot get snapshot because {}", e.getMessage());
}
PredicateSearchKey filter = PredicateSearchKey.of(paimonTable.getCatalogDBName(),
paimonTable.getCatalogTableName(), latestSnapshotId, params.getPredicate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.apache.paimon.types.IntType;
import org.apache.paimon.types.RowType;
import org.apache.paimon.types.TimestampType;
import org.apache.paimon.types.VarCharType;
import org.apache.paimon.utils.SerializationUtils;
import org.assertj.core.api.Assertions;
import org.junit.Assert;
Expand Down Expand Up @@ -195,6 +196,35 @@ public void testGetTableDoesNotExist() throws Exception {
Assert.assertNull(metadata.getTable("nonexistentDb", "nonexistentTbl"));
}

@Test
public void testGetSystemTable(@Mocked FileStoreTable paimonSystemTable,
@Mocked ReadBuilder readBuilder) throws Exception {
List<DataField> fields = new ArrayList<>();
fields.add(new DataField(0, "file_name", new VarCharType(true, 1073741824)));
fields.add(new DataField(1, "file_size", new BigIntType(false)));
fields.add(new DataField(2, "num_added_files", new BigIntType(false)));
fields.add(new DataField(3, "num_deleted_files", new BigIntType(false)));
fields.add(new DataField(4, "schema_id", new BigIntType(false)));
fields.add(new DataField(5, "min_partition_stats", new VarCharType(true, 1073741824)));
fields.add(new DataField(6, "max_partition_stats", new VarCharType(true, 1073741824)));
new Expectations() {
{
paimonNativeCatalog.getTable((Identifier) any);
result = paimonSystemTable;
paimonSystemTable.newReadBuilder();
result = readBuilder;
readBuilder.withFilter((List<Predicate>) any).withProjection((int[]) any).newScan().plan().splits();
result = splits;
}
};
PaimonTable paimonTable = (PaimonTable) metadata.getTable("db1", "tbl1$manifests");
List<String> requiredNames = Lists.newArrayList("file_name", "file_size");
List<RemoteFileInfo> result =
metadata.getRemoteFiles(paimonTable, GetRemoteFilesParams.newBuilder().setFieldNames(requiredNames).build());
Assert.assertEquals(1, result.size());
}


@Test
public void testListPartitionNames(@Mocked FileStoreTable mockPaimonTable,
@Mocked PartitionsTable mockPartitionTable,
Expand Down

0 comments on commit f2d3aa7

Please sign in to comment.