-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[fs] Optimize cloud file listing with per-page filtering and early termination in PinotFS #17847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
KKcorps
merged 2 commits into
apache:master
from
anshul98ks123:preview-pagination-list-metadata
Mar 13, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
273 changes: 273 additions & 0 deletions
273
...c/test/java/org/apache/pinot/plugin/filesystem/test/ADLSGen2PinotFSPaginatedListTest.java
This file contains hidden or 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,273 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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 org.apache.pinot.plugin.filesystem.test; | ||
|
|
||
| import com.azure.core.http.rest.PagedIterable; | ||
| import com.azure.storage.file.datalake.DataLakeFileSystemClient; | ||
| import com.azure.storage.file.datalake.models.DataLakeStorageException; | ||
| import com.azure.storage.file.datalake.models.PathItem; | ||
| import java.io.IOException; | ||
| import java.net.URI; | ||
| import java.time.OffsetDateTime; | ||
| import java.time.ZoneOffset; | ||
| import java.util.Arrays; | ||
| import java.util.Iterator; | ||
| import java.util.List; | ||
| import java.util.function.Predicate; | ||
| import org.apache.pinot.plugin.filesystem.ADLSGen2PinotFS; | ||
| import org.apache.pinot.spi.filesystem.FileMetadata; | ||
| import org.mockito.Mock; | ||
| import org.mockito.MockitoAnnotations; | ||
| import org.testng.annotations.AfterMethod; | ||
| import org.testng.annotations.BeforeMethod; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
| import static org.testng.Assert.assertEquals; | ||
| import static org.testng.Assert.assertFalse; | ||
| import static org.testng.Assert.assertTrue; | ||
|
|
||
|
|
||
| /** | ||
| * Unit tests for ADLSGen2PinotFS.listFilesWithMetadata(URI, boolean, Predicate, int) | ||
| * — the paginated listing with lazy PagedIterable iteration and early termination. | ||
| */ | ||
| public class ADLSGen2PinotFSPaginatedListTest { | ||
|
|
||
| private static final Predicate<String> ACCEPT_ALL = path -> true; | ||
| private static final OffsetDateTime MTIME = OffsetDateTime.of(2026, 1, 15, 10, 30, 0, 0, ZoneOffset.UTC); | ||
|
|
||
| @Mock | ||
| private DataLakeFileSystemClient _mockFileSystemClient; | ||
|
|
||
| @SuppressWarnings("rawtypes") | ||
| @Mock | ||
| private PagedIterable _mockPagedIterable; | ||
|
|
||
| private ADLSGen2PinotFS _adlsPinotFS; | ||
| private AutoCloseable _mocks; | ||
|
|
||
| @BeforeMethod | ||
| public void setUp() { | ||
| _mocks = MockitoAnnotations.openMocks(this); | ||
| _adlsPinotFS = new ADLSGen2PinotFS(_mockFileSystemClient); | ||
| } | ||
|
|
||
| @AfterMethod | ||
| public void tearDown() throws Exception { | ||
| _mocks.close(); | ||
| } | ||
|
|
||
| private static PathItem mockPathItem(final String name, final boolean isDirectory, | ||
| final long contentLength) { | ||
| final PathItem item = mock(PathItem.class); | ||
| when(item.getName()).thenReturn(name); | ||
| when(item.isDirectory()).thenReturn(isDirectory); | ||
| when(item.getContentLength()).thenReturn(contentLength); | ||
| when(item.getLastModified()).thenReturn(MTIME); | ||
| return item; | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private void setupIterator(final PathItem... items) { | ||
| when(_mockFileSystemClient.listPaths(any(), any())).thenReturn(_mockPagedIterable); | ||
| final Iterator<PathItem> iterator = Arrays.asList(items).iterator(); | ||
| when(_mockPagedIterable.iterator()).thenReturn(iterator); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAllMatch() throws IOException { | ||
| setupIterator( | ||
| mockPathItem("data/file1.parquet", false, 100), | ||
| mockPathItem("data/file2.parquet", false, 200), | ||
| mockPathItem("data/file3.parquet", false, 300) | ||
| ); | ||
|
|
||
| final List<FileMetadata> result = _adlsPinotFS.listFilesWithMetadata( | ||
| URI.create("abfss://container@account.dfs.core.windows.net/data/"), | ||
| true, ACCEPT_ALL, 10); | ||
|
|
||
| assertEquals(result.size(), 3); | ||
| assertEquals(result.get(0).getFilePath(), "/data/file1.parquet"); | ||
| assertEquals(result.get(1).getFilePath(), "/data/file2.parquet"); | ||
| assertEquals(result.get(2).getFilePath(), "/data/file3.parquet"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEarlyTermination() throws IOException { | ||
| // 5 items, maxResults=3 | ||
| setupIterator( | ||
| mockPathItem("data/f1.parquet", false, 100), | ||
| mockPathItem("data/f2.parquet", false, 200), | ||
| mockPathItem("data/f3.parquet", false, 300), | ||
| mockPathItem("data/f4.parquet", false, 400), | ||
| mockPathItem("data/f5.parquet", false, 500) | ||
| ); | ||
|
|
||
| final List<FileMetadata> result = _adlsPinotFS.listFilesWithMetadata( | ||
| URI.create("abfss://container@account.dfs.core.windows.net/data/"), | ||
| true, ACCEPT_ALL, 3); | ||
|
|
||
| assertEquals(result.size(), 3); | ||
| assertEquals(result.get(2).getFilePath(), "/data/f3.parquet"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMaxResultsOne() throws IOException { | ||
| setupIterator( | ||
| mockPathItem("data/f1.parquet", false, 100), | ||
| mockPathItem("data/f2.parquet", false, 200) | ||
| ); | ||
|
|
||
| final List<FileMetadata> result = _adlsPinotFS.listFilesWithMetadata( | ||
| URI.create("abfss://container@account.dfs.core.windows.net/data/"), | ||
| true, ACCEPT_ALL, 1); | ||
|
|
||
| assertEquals(result.size(), 1); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFilterPredicate() throws IOException { | ||
| setupIterator( | ||
| mockPathItem("data/file1.parquet", false, 100), | ||
| mockPathItem("data/file2.csv", false, 200), | ||
| mockPathItem("data/file3.parquet", false, 300), | ||
| mockPathItem("data/file4.json", false, 400) | ||
| ); | ||
|
|
||
| final List<FileMetadata> result = _adlsPinotFS.listFilesWithMetadata( | ||
| URI.create("abfss://container@account.dfs.core.windows.net/data/"), | ||
| true, path -> path.endsWith(".parquet"), 10); | ||
|
|
||
| assertEquals(result.size(), 2); | ||
| assertTrue(result.stream().allMatch(f -> f.getFilePath().endsWith(".parquet"))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDirectoriesSkipped() throws IOException { | ||
| setupIterator( | ||
| mockPathItem("data/subdir", true, 0), | ||
| mockPathItem("data/file1.parquet", false, 100), | ||
| mockPathItem("data/anotherdir", true, 0), | ||
| mockPathItem("data/file2.parquet", false, 200) | ||
| ); | ||
|
|
||
| final List<FileMetadata> result = _adlsPinotFS.listFilesWithMetadata( | ||
| URI.create("abfss://container@account.dfs.core.windows.net/data/"), | ||
| true, ACCEPT_ALL, 10); | ||
|
|
||
| assertEquals(result.size(), 2); | ||
| assertTrue(result.stream().noneMatch(FileMetadata::isDirectory)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFilterRejectsAll() throws IOException { | ||
| setupIterator( | ||
| mockPathItem("data/file1.parquet", false, 100), | ||
| mockPathItem("data/file2.parquet", false, 200) | ||
| ); | ||
|
|
||
| final List<FileMetadata> result = _adlsPinotFS.listFilesWithMetadata( | ||
| URI.create("abfss://container@account.dfs.core.windows.net/data/"), | ||
| true, path -> false, 10); | ||
|
|
||
| assertEquals(result.size(), 0); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEmptyListing() throws IOException { | ||
| setupIterator(); | ||
|
|
||
| final List<FileMetadata> result = _adlsPinotFS.listFilesWithMetadata( | ||
| URI.create("abfss://container@account.dfs.core.windows.net/data/"), | ||
| true, ACCEPT_ALL, 10); | ||
|
|
||
| assertEquals(result.size(), 0); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFileMetadataAttributes() throws IOException { | ||
| setupIterator( | ||
| mockPathItem("data/file.parquet", false, 4096) | ||
| ); | ||
|
|
||
| final List<FileMetadata> result = _adlsPinotFS.listFilesWithMetadata( | ||
| URI.create("abfss://container@account.dfs.core.windows.net/data/"), | ||
| true, ACCEPT_ALL, 10); | ||
|
|
||
| assertEquals(result.size(), 1); | ||
| final FileMetadata fm = result.get(0); | ||
| assertEquals(fm.getFilePath(), "/data/file.parquet"); | ||
| assertEquals(fm.getLength(), 4096L); | ||
| assertEquals(fm.getLastModifiedTime(), MTIME.toInstant().toEpochMilli()); | ||
| assertFalse(fm.isDirectory()); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| @Test(expectedExceptions = IOException.class) | ||
| public void testDataLakeExceptionWrappedAsIOException() throws IOException { | ||
| when(_mockFileSystemClient.listPaths(any(), any())) | ||
| .thenThrow(mock(DataLakeStorageException.class)); | ||
|
|
||
| _adlsPinotFS.listFilesWithMetadata( | ||
| URI.create("abfss://container@account.dfs.core.windows.net/data/"), | ||
| true, ACCEPT_ALL, 10); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMaxResultsZeroReturnsEmpty() throws IOException { | ||
| final List<FileMetadata> result = _adlsPinotFS.listFilesWithMetadata( | ||
| URI.create("abfss://container@account.dfs.core.windows.net/data/"), | ||
| true, ACCEPT_ALL, 0); | ||
|
|
||
| assertEquals(result.size(), 0); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMaxResultsNegativeReturnsEmpty() throws IOException { | ||
| final List<FileMetadata> result = _adlsPinotFS.listFilesWithMetadata( | ||
| URI.create("abfss://container@account.dfs.core.windows.net/data/"), | ||
| true, ACCEPT_ALL, -3); | ||
|
|
||
| assertEquals(result.size(), 0); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEarlyTerminationWithFilterAndDirectories() throws IOException { | ||
| // Mix of dirs, matching files, and non-matching files; maxResults=2 | ||
| setupIterator( | ||
| mockPathItem("data/dir1", true, 0), | ||
| mockPathItem("data/file1.csv", false, 100), | ||
| mockPathItem("data/file2.parquet", false, 200), | ||
| mockPathItem("data/dir2", true, 0), | ||
| mockPathItem("data/file3.parquet", false, 300), | ||
| mockPathItem("data/file4.parquet", false, 400) | ||
| ); | ||
|
|
||
| final List<FileMetadata> result = _adlsPinotFS.listFilesWithMetadata( | ||
| URI.create("abfss://container@account.dfs.core.windows.net/data/"), | ||
| true, path -> path.endsWith(".parquet"), 2); | ||
|
|
||
| assertEquals(result.size(), 2); | ||
| assertEquals(result.get(0).getFilePath(), "/data/file2.parquet"); | ||
| assertEquals(result.get(1).getFilePath(), "/data/file3.parquet"); | ||
| } | ||
| } |
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.