You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@polaris.apache.org by "jbonofre (via GitHub)" <gi...@apache.org> on 2026/10/30 08:08:01 UTC
[PR] Add a simple directory scan service [polaris]
jbonofre opened a new pull request, #5929:
URL: https://github.com/apache/polaris/pull/5929
This is the third of three PRs split from #4613:
1. #5927: OpenAPI specification and documentation
2. #5928: Directory entity, REST endpoints and `DirectoryScanService` SPI
3. **This PR**: simple directory scan service
It is stacked on #5928: until the previous PRs are merged, this PR also shows their commits. Only the last commit (`Add a simple directory scan service to populate the directory inventory table`) belongs to this PR.
### Changes
`DefaultDirectoryScanService` (the default `DirectoryScanService` bean) now uses a simple scanner, `DirectoryScanner`, to populate the directory inventory table on `POST /polaris/v1/{prefix}/namespaces/{namespace}/directories/{directory}/scan`:
- Lists the objects under `base_location` (with read/list credentials scoped to that location), applies the include/exclude filters, and replaces the table content with a Parquet data file in a single overwrite commit. A failed scan leaves the table unchanged. If the commit state is unknown, the new data file is kept, as the commit may have landed.
- Fills `file_uri`, `content_type` (guessed from the file name), `size` and `last_modified`. The other columns are left empty.
- Requires a `FileIO` that supports listing a prefix.
- Still disabled by default (`ENABLE_DIRECTORY_SCAN`): the scan is synchronous and keeps the listing in memory, so it is not suited to large directories yet.
- Runs on demand only: `scan-schedule` stays informational, so periodic scans are left to the caller or an external scheduler.
- An extension can still replace it with its own `DirectoryScanService` bean (for example to compute checksums or update the table incrementally).
Dependencies: adds `iceberg-data`, `iceberg-parquet` and `parquet-hadoop` (same Parquet version as the one already on the runtime classpath) to the runtime service, with the matching `LICENSE` entries. The Spark plugin and Spark tests exclude the server's Parquet, so it does not override the Parquet version provided by Spark.
### Tests
- `DirectoryScannerTest`: scanner behavior on an in-memory file system (filters, rescan, recorded metadata, wrapped `FileIO`, missing prefix operations support, unknown commit state).
- `DirectoryServiceIntegrationTest`: the end-to-end test now scans the directory between create and drop.
- Also tested manually on S3. Not tested on GCS or Azure yet.
### Notes for reviewers
- The scan endpoint emits no Polaris events yet.
## Checklist
- [X] π‘οΈ Don't disclose security issues! (contact security@apache.org)
- [X] π Clearly explained why the changes are needed, or linked related issues: Related to #4613
- [X] π§ͺ Added/updated tests with good coverage, or manually tested (and explained how)
- [X] π‘ Added comments for complex logic
- [X] π§Ύ Updated `CHANGELOG.md` (if needed)
- [X] π Updated documentation in `site/content/in-dev/unreleased` (if needed)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add a simple directory scan service [polaris]
Posted by "orca-review-bot (via GitHub)" <gi...@apache.org>.
orca-review-bot commented on code in PR #5929:
URL: https://github.com/apache/polaris/pull/5929#discussion_r4427587754
##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/directory/DirectoryScanner.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.polaris.service.catalog.directory;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.net.URLConnection;
+import java.time.Instant;
+import java.time.OffsetDateTime;
+import java.time.ZoneOffset;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import java.util.regex.Pattern;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.OverwriteFiles;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.data.GenericRecord;
+import org.apache.iceberg.data.Record;
+import org.apache.iceberg.data.parquet.GenericParquetWriter;
+import org.apache.iceberg.exceptions.CommitStateUnknownException;
+import org.apache.iceberg.expressions.Expressions;
+import org.apache.iceberg.io.DataWriter;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.FileInfo;
+import org.apache.iceberg.io.OutputFile;
+import org.apache.iceberg.io.SupportsPrefixOperations;
+import org.apache.iceberg.parquet.Parquet;
+import org.apache.polaris.core.storage.StorageLocation;
+import org.apache.polaris.service.catalog.io.ExceptionMappingFileIO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Lists the objects under a directory base location and replaces the content of the directory
+ * inventory table (see {@link DirectoryCatalogHandler#DIRECTORY_TABLE_SCHEMA}) with them, in a
+ * single commit.
+ */
+final class DirectoryScanner {
+ private static final Logger LOGGER = LoggerFactory.getLogger(DirectoryScanner.class);
+
+ private DirectoryScanner() {}
+
+ /**
+ * @param sourceIO the {@link FileIO} used to list the objects, it must support prefix operations
+ * @return the number of objects recorded in the table
+ */
+ static long scan(
+ Table table,
+ FileIO sourceIO,
+ String baseLocation,
+ List<String> include,
+ List<String> exclude) {
+ // The FileIO factory wraps the FileIO, and the wrapper does not expose the prefix operations
+ FileIO io = sourceIO instanceof ExceptionMappingFileIO w ? w.getInnerIo() : sourceIO;
Review Comment:
This reaches past the wrapper through `getInnerIo()`, which is `@VisibleForTesting`. Listing errors then skip the UnknownHost mapping the wrapper is there for. `ExceptionMappingFileIO.wrap` already keeps `SupportsBulkOperations` with a subclass. Can we do the same for `SupportsPrefixOperations` and drop the unwrap here?
<sub>π€ AI-generated review comment β agents make mistakes, so please verify before acting on it.</sub>
##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/directory/DirectoryScanner.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.polaris.service.catalog.directory;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.net.URLConnection;
+import java.time.Instant;
+import java.time.OffsetDateTime;
+import java.time.ZoneOffset;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import java.util.regex.Pattern;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.OverwriteFiles;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.data.GenericRecord;
+import org.apache.iceberg.data.Record;
+import org.apache.iceberg.data.parquet.GenericParquetWriter;
+import org.apache.iceberg.exceptions.CommitStateUnknownException;
+import org.apache.iceberg.expressions.Expressions;
+import org.apache.iceberg.io.DataWriter;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.FileInfo;
+import org.apache.iceberg.io.OutputFile;
+import org.apache.iceberg.io.SupportsPrefixOperations;
+import org.apache.iceberg.parquet.Parquet;
+import org.apache.polaris.core.storage.StorageLocation;
+import org.apache.polaris.service.catalog.io.ExceptionMappingFileIO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Lists the objects under a directory base location and replaces the content of the directory
+ * inventory table (see {@link DirectoryCatalogHandler#DIRECTORY_TABLE_SCHEMA}) with them, in a
+ * single commit.
+ */
+final class DirectoryScanner {
+ private static final Logger LOGGER = LoggerFactory.getLogger(DirectoryScanner.class);
+
+ private DirectoryScanner() {}
+
+ /**
+ * @param sourceIO the {@link FileIO} used to list the objects, it must support prefix operations
+ * @return the number of objects recorded in the table
+ */
+ static long scan(
+ Table table,
+ FileIO sourceIO,
+ String baseLocation,
+ List<String> include,
+ List<String> exclude) {
+ // The FileIO factory wraps the FileIO, and the wrapper does not expose the prefix operations
+ FileIO io = sourceIO instanceof ExceptionMappingFileIO w ? w.getInnerIo() : sourceIO;
+ if (!(io instanceof SupportsPrefixOperations prefixIO)) {
+ throw new UnsupportedOperationException(
+ "Scanning is not supported for location " + baseLocation);
+ }
+ List<Pattern> includePatterns = compile(include);
+ List<Pattern> excludePatterns = compile(exclude);
+
+ List<Record> records = new ArrayList<>();
Review Comment:
Every matching object becomes a `Record` in this list before anything gets written, so heap use grows with the size of the prefix. Fine while the flag is off, but the first big bucket someone points this at could OOM the server. Can we open the `DataWriter` up front and write records as we list?
<sub>π€ AI-generated review comment β agents make mistakes, so please verify before acting on it.</sub>
##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/directory/DirectoryScanner.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.polaris.service.catalog.directory;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.net.URLConnection;
+import java.time.Instant;
+import java.time.OffsetDateTime;
+import java.time.ZoneOffset;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import java.util.regex.Pattern;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.OverwriteFiles;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.data.GenericRecord;
+import org.apache.iceberg.data.Record;
+import org.apache.iceberg.data.parquet.GenericParquetWriter;
+import org.apache.iceberg.exceptions.CommitStateUnknownException;
+import org.apache.iceberg.expressions.Expressions;
+import org.apache.iceberg.io.DataWriter;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.FileInfo;
+import org.apache.iceberg.io.OutputFile;
+import org.apache.iceberg.io.SupportsPrefixOperations;
+import org.apache.iceberg.parquet.Parquet;
+import org.apache.polaris.core.storage.StorageLocation;
+import org.apache.polaris.service.catalog.io.ExceptionMappingFileIO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Lists the objects under a directory base location and replaces the content of the directory
+ * inventory table (see {@link DirectoryCatalogHandler#DIRECTORY_TABLE_SCHEMA}) with them, in a
+ * single commit.
+ */
+final class DirectoryScanner {
+ private static final Logger LOGGER = LoggerFactory.getLogger(DirectoryScanner.class);
+
+ private DirectoryScanner() {}
+
+ /**
+ * @param sourceIO the {@link FileIO} used to list the objects, it must support prefix operations
+ * @return the number of objects recorded in the table
+ */
+ static long scan(
+ Table table,
+ FileIO sourceIO,
+ String baseLocation,
+ List<String> include,
+ List<String> exclude) {
+ // The FileIO factory wraps the FileIO, and the wrapper does not expose the prefix operations
+ FileIO io = sourceIO instanceof ExceptionMappingFileIO w ? w.getInnerIo() : sourceIO;
+ if (!(io instanceof SupportsPrefixOperations prefixIO)) {
+ throw new UnsupportedOperationException(
+ "Scanning is not supported for location " + baseLocation);
+ }
+ List<Pattern> includePatterns = compile(include);
+ List<Pattern> excludePatterns = compile(exclude);
+
+ List<Record> records = new ArrayList<>();
+ String inventoryLocation = StorageLocation.ensureTrailingSlash(table.location());
+ for (FileInfo file : prefixIO.listPrefix(baseLocation)) {
+ String uri = file.location();
+ // The inventory table may live under the base location: do not index its own files
+ if (uri.startsWith(inventoryLocation)) {
Review Comment:
This is a plain string prefix check against `table.location()`. If `listPrefix` returns a different form (s3a vs s3, an extra slash), the inventory would start indexing its own files. Did you check that the forms match on S3? Not sure about GCS/ADLS either.
<sub>π€ AI-generated review comment β agents make mistakes, so please verify before acting on it.</sub>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add a simple directory scan service [polaris]
Posted by "adutra (via GitHub) via issues" <is...@polaris.apache.org>.
adutra commented on PR #5929:
URL: https://github.com/apache/polaris/pull/5929#issuecomment-6943661750
Heads-up: #5967 has been merged, so `CHANGELOG.md` is no longer edited directly. Changelog entries now go in a fragment file under `changelog.d/`, which avoids merge conflicts on `CHANGELOG.md`. See [changelog.d/README.md](https://github.com/apache/polaris/blob/main/changelog.d/README.md) for the format.
Could you rebase onto `main`, revert your changes to `CHANGELOG.md`, and add a fragment file instead if your change needs a changelog entry? A fragment is only needed for things worth calling out in release notes, such as breaking changes, metastore schema changes, or changes that require manual steps during an upgrade. Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add a simple directory scan service [polaris]
Posted by "ArnabKarmakar1108 (via GitHub) via issues" <is...@polaris.apache.org>.
ArnabKarmakar1108 commented on code in PR #5929:
URL: https://github.com/apache/polaris/pull/5929#discussion_r4432255323
##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/directory/DirectoryScanner.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.polaris.service.catalog.directory;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.net.URLConnection;
+import java.time.Instant;
+import java.time.OffsetDateTime;
+import java.time.ZoneOffset;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import java.util.regex.Pattern;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.OverwriteFiles;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.data.GenericRecord;
+import org.apache.iceberg.data.Record;
+import org.apache.iceberg.data.parquet.GenericParquetWriter;
+import org.apache.iceberg.exceptions.CommitStateUnknownException;
+import org.apache.iceberg.expressions.Expressions;
+import org.apache.iceberg.io.DataWriter;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.FileInfo;
+import org.apache.iceberg.io.OutputFile;
+import org.apache.iceberg.io.SupportsPrefixOperations;
+import org.apache.iceberg.parquet.Parquet;
+import org.apache.polaris.core.storage.StorageLocation;
+import org.apache.polaris.service.catalog.io.ExceptionMappingFileIO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Lists the objects under a directory base location and replaces the content of the directory
+ * inventory table (see {@link DirectoryCatalogHandler#DIRECTORY_TABLE_SCHEMA}) with them, in a
+ * single commit.
+ */
+final class DirectoryScanner {
+ private static final Logger LOGGER = LoggerFactory.getLogger(DirectoryScanner.class);
+
+ private DirectoryScanner() {}
+
+ /**
+ * @param sourceIO the {@link FileIO} used to list the objects, it must support prefix operations
+ * @return the number of objects recorded in the table
+ */
+ static long scan(
+ Table table,
+ FileIO sourceIO,
+ String baseLocation,
+ List<String> include,
+ List<String> exclude) {
+ // The FileIO factory wraps the FileIO, and the wrapper does not expose the prefix operations
+ FileIO io = sourceIO instanceof ExceptionMappingFileIO w ? w.getInnerIo() : sourceIO;
+ if (!(io instanceof SupportsPrefixOperations prefixIO)) {
+ throw new UnsupportedOperationException(
+ "Scanning is not supported for location " + baseLocation);
+ }
+ List<Pattern> includePatterns = compile(include);
+ List<Pattern> excludePatterns = compile(exclude);
+
+ List<Record> records = new ArrayList<>();
+ String inventoryLocation = StorageLocation.ensureTrailingSlash(table.location());
+ for (FileInfo file : prefixIO.listPrefix(baseLocation)) {
+ String uri = file.location();
+ // The inventory table may live under the base location: do not index its own files
+ if (uri.startsWith(inventoryLocation)) {
+ continue;
+ }
+ if (matches(uri, includePatterns, excludePatterns)) {
+ Record record = GenericRecord.create(table.schema());
+ record.setField("file_uri", uri);
+ record.setField("content_type", URLConnection.guessContentTypeFromName(uri));
+ record.setField("size", file.size());
+ record.setField(
+ "last_modified",
+ OffsetDateTime.ofInstant(Instant.ofEpochMilli(file.createdAtMillis()), ZoneOffset.UTC));
+ records.add(record);
+ }
+ }
+
+ OverwriteFiles overwrite = table.newOverwrite().overwriteByRowFilter(Expressions.alwaysTrue());
+ String dataFileLocation = null;
+ try {
+ if (!records.isEmpty()) {
+ dataFileLocation = table.locationProvider().newDataLocation(UUID.randomUUID() + ".parquet");
+ overwrite.addFile(write(table, dataFileLocation, records));
Review Comment:
Not sure but is this thread safe? Should we serialize on directory/inventory id?
##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/directory/DirectoryScanner.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.polaris.service.catalog.directory;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.net.URLConnection;
+import java.time.Instant;
+import java.time.OffsetDateTime;
+import java.time.ZoneOffset;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import java.util.regex.Pattern;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.OverwriteFiles;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.data.GenericRecord;
+import org.apache.iceberg.data.Record;
+import org.apache.iceberg.data.parquet.GenericParquetWriter;
+import org.apache.iceberg.exceptions.CommitStateUnknownException;
+import org.apache.iceberg.expressions.Expressions;
+import org.apache.iceberg.io.DataWriter;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.FileInfo;
+import org.apache.iceberg.io.OutputFile;
+import org.apache.iceberg.io.SupportsPrefixOperations;
+import org.apache.iceberg.parquet.Parquet;
+import org.apache.polaris.core.storage.StorageLocation;
+import org.apache.polaris.service.catalog.io.ExceptionMappingFileIO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Lists the objects under a directory base location and replaces the content of the directory
+ * inventory table (see {@link DirectoryCatalogHandler#DIRECTORY_TABLE_SCHEMA}) with them, in a
+ * single commit.
+ */
+final class DirectoryScanner {
+ private static final Logger LOGGER = LoggerFactory.getLogger(DirectoryScanner.class);
+
+ private DirectoryScanner() {}
+
+ /**
+ * @param sourceIO the {@link FileIO} used to list the objects, it must support prefix operations
+ * @return the number of objects recorded in the table
+ */
+ static long scan(
+ Table table,
+ FileIO sourceIO,
+ String baseLocation,
+ List<String> include,
+ List<String> exclude) {
+ // The FileIO factory wraps the FileIO, and the wrapper does not expose the prefix operations
+ FileIO io = sourceIO instanceof ExceptionMappingFileIO w ? w.getInnerIo() : sourceIO;
+ if (!(io instanceof SupportsPrefixOperations prefixIO)) {
+ throw new UnsupportedOperationException(
+ "Scanning is not supported for location " + baseLocation);
+ }
+ List<Pattern> includePatterns = compile(include);
+ List<Pattern> excludePatterns = compile(exclude);
Review Comment:
patterns are Pattern.compileβd on every scan and matched with .find(). Complex regexes can cause heavy backtracking on long URIs during UPDATE_TABLE-authorized scan. Should we consider timeouts, or pattern complexity limit?
##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/directory/DirectoryScanner.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.polaris.service.catalog.directory;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.net.URLConnection;
+import java.time.Instant;
+import java.time.OffsetDateTime;
+import java.time.ZoneOffset;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import java.util.regex.Pattern;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.OverwriteFiles;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.data.GenericRecord;
+import org.apache.iceberg.data.Record;
+import org.apache.iceberg.data.parquet.GenericParquetWriter;
+import org.apache.iceberg.exceptions.CommitStateUnknownException;
+import org.apache.iceberg.expressions.Expressions;
+import org.apache.iceberg.io.DataWriter;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.FileInfo;
+import org.apache.iceberg.io.OutputFile;
+import org.apache.iceberg.io.SupportsPrefixOperations;
+import org.apache.iceberg.parquet.Parquet;
+import org.apache.polaris.core.storage.StorageLocation;
+import org.apache.polaris.service.catalog.io.ExceptionMappingFileIO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Lists the objects under a directory base location and replaces the content of the directory
+ * inventory table (see {@link DirectoryCatalogHandler#DIRECTORY_TABLE_SCHEMA}) with them, in a
+ * single commit.
+ */
+final class DirectoryScanner {
+ private static final Logger LOGGER = LoggerFactory.getLogger(DirectoryScanner.class);
+
+ private DirectoryScanner() {}
+
+ /**
+ * @param sourceIO the {@link FileIO} used to list the objects, it must support prefix operations
+ * @return the number of objects recorded in the table
+ */
+ static long scan(
+ Table table,
+ FileIO sourceIO,
+ String baseLocation,
+ List<String> include,
+ List<String> exclude) {
+ // The FileIO factory wraps the FileIO, and the wrapper does not expose the prefix operations
Review Comment:
Prefix support is detected only after unwrapping ExceptionMappingFileIO something like:
WasbTranslatingFileIO -> ExceptionMappingFileIO -> real FileIO (can list)
Production Azure setups use WasbTranslatingFileIOFactory, which returns WasbTranslatingFileIO outside ExceptionMappingFileIO. I think we should either unwrap the full factory wrapper chain (like ExceptionMappingFileIO.getInnerIo()), or delegate listPrefix from WasbTranslatingFileIO to the inner IO.
##########
integration-tests/src/main/java/org/apache/polaris/service/it/test/PolarisDirectoryServiceIntegrationTest.java:
##########
@@ -0,0 +1,236 @@
+/*
+ * 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.polaris.service.it.test;
+
+import static org.apache.polaris.service.it.env.PolarisClient.polarisClient;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import jakarta.ws.rs.core.Response;
+import java.io.IOException;
+import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.rest.RESTCatalog;
+import org.apache.iceberg.types.Types;
+import org.apache.polaris.core.admin.model.Catalog;
+import org.apache.polaris.core.admin.model.CatalogGrant;
+import org.apache.polaris.core.admin.model.CatalogPrivilege;
+import org.apache.polaris.core.admin.model.CatalogProperties;
+import org.apache.polaris.core.admin.model.FileStorageConfigInfo;
+import org.apache.polaris.core.admin.model.GrantResource;
+import org.apache.polaris.core.admin.model.PolarisCatalog;
+import org.apache.polaris.core.admin.model.PrincipalWithCredentials;
+import org.apache.polaris.core.admin.model.StorageConfigInfo;
+import org.apache.polaris.service.it.env.ClientCredentials;
+import org.apache.polaris.service.it.env.DirectoryApi;
+import org.apache.polaris.service.it.env.IcebergHelper;
+import org.apache.polaris.service.it.env.IntegrationTestsHelper;
+import org.apache.polaris.service.it.env.ManagementApi;
+import org.apache.polaris.service.it.env.PolarisApiEndpoints;
+import org.apache.polaris.service.it.env.PolarisClient;
+import org.apache.polaris.service.it.ext.PolarisIntegrationTestExtension;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * End-to-end test of the directories REST API on a file based catalog: the whole create, scan, load
+ * and drop flow goes through the REST layer, including authorization and location validation.
+ */
+@ExtendWith(PolarisIntegrationTestExtension.class)
+public class PolarisDirectoryServiceIntegrationTest {
+
+ private static final String CATALOG_ROLE = "directory_catalog_role";
+ private static final Namespace NS = Namespace.of("ns");
+ private static final TableIdentifier IMAGES = TableIdentifier.of(NS, "images");
+ private static final TableIdentifier IMAGES_INVENTORY =
+ TableIdentifier.of(NS, "images__inventory");
+
+ private static PolarisApiEndpoints endpoints;
+ private static PolarisClient client;
+ private static ManagementApi managementApi;
+ private static String adminToken;
+ private static URI rootUri;
+
+ private RESTCatalog restCatalog;
+ private DirectoryApi directoryApi;
+ private String catalogName;
+ private URI catalogBaseLocation;
+
+ @BeforeAll
+ public static void setup(
+ PolarisApiEndpoints apiEndpoints, ClientCredentials credentials, @TempDir Path tempDir) {
+ endpoints = apiEndpoints;
+ client = polarisClient(endpoints);
+ adminToken = client.obtainToken(credentials);
+ managementApi = client.managementApi(adminToken);
+ rootUri = IntegrationTestsHelper.getTemporaryDirectory(tempDir);
+ }
+
+ @AfterAll
+ public static void close() throws Exception {
+ client.close();
+ }
+
+ @BeforeEach
+ public void before() {
+ String principalRoleName = "directory-admin-" + UUID.randomUUID();
+ PrincipalWithCredentials principal =
+ managementApi.createPrincipalWithRole(
+ "directory-user-" + UUID.randomUUID(), principalRoleName);
+
+ catalogName = client.newEntityName("directory");
+ catalogBaseLocation = rootUri.resolve(catalogName + "/");
+ Catalog catalog =
+ PolarisCatalog.builder()
+ .setType(Catalog.TypeEnum.INTERNAL)
+ .setName(catalogName)
+ .setProperties(
+ CatalogProperties.builder(catalogBaseLocation.toString())
+ // directories are rooted outside the namespace location
+ .putAll(Map.of("polaris.config.allow.unstructured.table.location", "true"))
+ .build())
+ .setStorageConfigInfo(
+ new FileStorageConfigInfo(
+ StorageConfigInfo.StorageTypeEnum.FILE,
+ List.of(catalogBaseLocation.toString()),
+ null))
+ .build();
+ managementApi.createCatalog(principalRoleName, catalog);
+
+ managementApi.createCatalogRole(catalogName, CATALOG_ROLE);
+ managementApi.addGrant(
+ catalogName,
+ CATALOG_ROLE,
+ new CatalogGrant(CatalogPrivilege.CATALOG_MANAGE_CONTENT, GrantResource.TypeEnum.CATALOG));
+ managementApi.grantCatalogRoleToPrincipalRole(
+ principalRoleName, catalogName, managementApi.getCatalogRole(catalogName, CATALOG_ROLE));
+
+ String principalToken = client.obtainToken(principal);
+ restCatalog = IcebergHelper.restCatalog(endpoints, catalogName, Map.of(), principalToken);
+ directoryApi = client.directoryApi(principalToken);
+ restCatalog.createNamespace(NS);
+ }
+
+ @AfterEach
+ public void cleanUp() throws IOException {
+ try {
+ if (restCatalog != null) {
+ restCatalog.close();
+ }
+ } finally {
+ client.cleanUp(adminToken);
+ }
+ }
+
+ @Test
+ public void testCreateScanLoadAndDrop() throws IOException {
+ URI baseLocation = catalogBaseLocation.resolve("images/");
+ Path baseDir = Path.of(baseLocation);
+ Files.createDirectories(baseDir);
+ Files.writeString(baseDir.resolve("a.jpg"), "a");
+ Files.writeString(baseDir.resolve("b.png"), "bb");
+
+ directoryApi.createDirectory(catalogName, IMAGES, baseLocation.toString(), Map.of());
+
+ assertThat(directoryApi.listDirectories(catalogName, NS)).containsExactly(IMAGES);
+ assertThat(directoryApi.getDirectory(catalogName, IMAGES).getBaseLocation())
+ .isEqualTo(baseLocation.toString());
+ // The inventory table cannot share the name of the directory
+ assertThat(restCatalog.tableExists(IMAGES_INVENTORY)).isTrue();
+
+ assertThat(directoryApi.scanDirectory(catalogName, IMAGES)).isEqualTo(2L);
+ assertThat(restCatalog.loadTable(IMAGES_INVENTORY).currentSnapshot()).isNotNull();
Review Comment:
Can we also assert file_uri values, filter behavior? It'd be helpful in preventing regressions to pass.
##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/directory/DirectoryScanner.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.polaris.service.catalog.directory;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.net.URLConnection;
+import java.time.Instant;
+import java.time.OffsetDateTime;
+import java.time.ZoneOffset;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import java.util.regex.Pattern;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.OverwriteFiles;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.data.GenericRecord;
+import org.apache.iceberg.data.Record;
+import org.apache.iceberg.data.parquet.GenericParquetWriter;
+import org.apache.iceberg.exceptions.CommitStateUnknownException;
+import org.apache.iceberg.expressions.Expressions;
+import org.apache.iceberg.io.DataWriter;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.FileInfo;
+import org.apache.iceberg.io.OutputFile;
+import org.apache.iceberg.io.SupportsPrefixOperations;
+import org.apache.iceberg.parquet.Parquet;
+import org.apache.polaris.core.storage.StorageLocation;
+import org.apache.polaris.service.catalog.io.ExceptionMappingFileIO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Lists the objects under a directory base location and replaces the content of the directory
+ * inventory table (see {@link DirectoryCatalogHandler#DIRECTORY_TABLE_SCHEMA}) with them, in a
+ * single commit.
+ */
+final class DirectoryScanner {
+ private static final Logger LOGGER = LoggerFactory.getLogger(DirectoryScanner.class);
+
+ private DirectoryScanner() {}
+
+ /**
+ * @param sourceIO the {@link FileIO} used to list the objects, it must support prefix operations
+ * @return the number of objects recorded in the table
+ */
+ static long scan(
+ Table table,
+ FileIO sourceIO,
+ String baseLocation,
+ List<String> include,
+ List<String> exclude) {
+ // The FileIO factory wraps the FileIO, and the wrapper does not expose the prefix operations
+ FileIO io = sourceIO instanceof ExceptionMappingFileIO w ? w.getInnerIo() : sourceIO;
+ if (!(io instanceof SupportsPrefixOperations prefixIO)) {
+ throw new UnsupportedOperationException(
+ "Scanning is not supported for location " + baseLocation);
+ }
+ List<Pattern> includePatterns = compile(include);
+ List<Pattern> excludePatterns = compile(exclude);
+
+ List<Record> records = new ArrayList<>();
+ String inventoryLocation = StorageLocation.ensureTrailingSlash(table.location());
+ for (FileInfo file : prefixIO.listPrefix(baseLocation)) {
Review Comment:
We are not considering any trailing slashes in `listPrefix(baseLocation)` but object stores and FileIO implementations often treat s3://b/p and s3://b/p/ differently. The tests are always using a trailing slash.
##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/directory/DirectoryScanner.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.polaris.service.catalog.directory;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.net.URLConnection;
+import java.time.Instant;
+import java.time.OffsetDateTime;
+import java.time.ZoneOffset;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import java.util.regex.Pattern;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.OverwriteFiles;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.data.GenericRecord;
+import org.apache.iceberg.data.Record;
+import org.apache.iceberg.data.parquet.GenericParquetWriter;
+import org.apache.iceberg.exceptions.CommitStateUnknownException;
+import org.apache.iceberg.expressions.Expressions;
+import org.apache.iceberg.io.DataWriter;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.FileInfo;
+import org.apache.iceberg.io.OutputFile;
+import org.apache.iceberg.io.SupportsPrefixOperations;
+import org.apache.iceberg.parquet.Parquet;
+import org.apache.polaris.core.storage.StorageLocation;
+import org.apache.polaris.service.catalog.io.ExceptionMappingFileIO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Lists the objects under a directory base location and replaces the content of the directory
+ * inventory table (see {@link DirectoryCatalogHandler#DIRECTORY_TABLE_SCHEMA}) with them, in a
+ * single commit.
+ */
+final class DirectoryScanner {
+ private static final Logger LOGGER = LoggerFactory.getLogger(DirectoryScanner.class);
+
+ private DirectoryScanner() {}
+
+ /**
+ * @param sourceIO the {@link FileIO} used to list the objects, it must support prefix operations
+ * @return the number of objects recorded in the table
+ */
+ static long scan(
+ Table table,
+ FileIO sourceIO,
+ String baseLocation,
+ List<String> include,
+ List<String> exclude) {
+ // The FileIO factory wraps the FileIO, and the wrapper does not expose the prefix operations
+ FileIO io = sourceIO instanceof ExceptionMappingFileIO w ? w.getInnerIo() : sourceIO;
+ if (!(io instanceof SupportsPrefixOperations prefixIO)) {
+ throw new UnsupportedOperationException(
+ "Scanning is not supported for location " + baseLocation);
+ }
+ List<Pattern> includePatterns = compile(include);
+ List<Pattern> excludePatterns = compile(exclude);
+
+ List<Record> records = new ArrayList<>();
+ String inventoryLocation = StorageLocation.ensureTrailingSlash(table.location());
+ for (FileInfo file : prefixIO.listPrefix(baseLocation)) {
+ String uri = file.location();
+ // The inventory table may live under the base location: do not index its own files
+ if (uri.startsWith(inventoryLocation)) {
+ continue;
+ }
+ if (matches(uri, includePatterns, excludePatterns)) {
+ Record record = GenericRecord.create(table.schema());
+ record.setField("file_uri", uri);
+ record.setField("content_type", URLConnection.guessContentTypeFromName(uri));
Review Comment:
`URLConnection.guessContentTypeFromName(uri)` can often return null right? Some rows are going to have null content_type.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add a simple directory scan service [polaris]
Posted by "ArnabKarmakar1108 (via GitHub) via issues" <is...@polaris.apache.org>.
ArnabKarmakar1108 commented on code in PR #5929:
URL: https://github.com/apache/polaris/pull/5929#discussion_r4432288453
##########
integration-tests/src/main/java/org/apache/polaris/service/it/test/PolarisDirectoryServiceIntegrationTest.java:
##########
@@ -0,0 +1,236 @@
+/*
+ * 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.polaris.service.it.test;
+
+import static org.apache.polaris.service.it.env.PolarisClient.polarisClient;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import jakarta.ws.rs.core.Response;
+import java.io.IOException;
+import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.rest.RESTCatalog;
+import org.apache.iceberg.types.Types;
+import org.apache.polaris.core.admin.model.Catalog;
+import org.apache.polaris.core.admin.model.CatalogGrant;
+import org.apache.polaris.core.admin.model.CatalogPrivilege;
+import org.apache.polaris.core.admin.model.CatalogProperties;
+import org.apache.polaris.core.admin.model.FileStorageConfigInfo;
+import org.apache.polaris.core.admin.model.GrantResource;
+import org.apache.polaris.core.admin.model.PolarisCatalog;
+import org.apache.polaris.core.admin.model.PrincipalWithCredentials;
+import org.apache.polaris.core.admin.model.StorageConfigInfo;
+import org.apache.polaris.service.it.env.ClientCredentials;
+import org.apache.polaris.service.it.env.DirectoryApi;
+import org.apache.polaris.service.it.env.IcebergHelper;
+import org.apache.polaris.service.it.env.IntegrationTestsHelper;
+import org.apache.polaris.service.it.env.ManagementApi;
+import org.apache.polaris.service.it.env.PolarisApiEndpoints;
+import org.apache.polaris.service.it.env.PolarisClient;
+import org.apache.polaris.service.it.ext.PolarisIntegrationTestExtension;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * End-to-end test of the directories REST API on a file based catalog: the whole create, scan, load
+ * and drop flow goes through the REST layer, including authorization and location validation.
+ */
+@ExtendWith(PolarisIntegrationTestExtension.class)
+public class PolarisDirectoryServiceIntegrationTest {
+
+ private static final String CATALOG_ROLE = "directory_catalog_role";
+ private static final Namespace NS = Namespace.of("ns");
+ private static final TableIdentifier IMAGES = TableIdentifier.of(NS, "images");
+ private static final TableIdentifier IMAGES_INVENTORY =
+ TableIdentifier.of(NS, "images__inventory");
+
+ private static PolarisApiEndpoints endpoints;
+ private static PolarisClient client;
+ private static ManagementApi managementApi;
+ private static String adminToken;
+ private static URI rootUri;
+
+ private RESTCatalog restCatalog;
+ private DirectoryApi directoryApi;
+ private String catalogName;
+ private URI catalogBaseLocation;
+
+ @BeforeAll
+ public static void setup(
+ PolarisApiEndpoints apiEndpoints, ClientCredentials credentials, @TempDir Path tempDir) {
+ endpoints = apiEndpoints;
+ client = polarisClient(endpoints);
+ adminToken = client.obtainToken(credentials);
+ managementApi = client.managementApi(adminToken);
+ rootUri = IntegrationTestsHelper.getTemporaryDirectory(tempDir);
+ }
+
+ @AfterAll
+ public static void close() throws Exception {
+ client.close();
+ }
+
+ @BeforeEach
+ public void before() {
+ String principalRoleName = "directory-admin-" + UUID.randomUUID();
+ PrincipalWithCredentials principal =
+ managementApi.createPrincipalWithRole(
+ "directory-user-" + UUID.randomUUID(), principalRoleName);
+
+ catalogName = client.newEntityName("directory");
+ catalogBaseLocation = rootUri.resolve(catalogName + "/");
+ Catalog catalog =
+ PolarisCatalog.builder()
+ .setType(Catalog.TypeEnum.INTERNAL)
+ .setName(catalogName)
+ .setProperties(
+ CatalogProperties.builder(catalogBaseLocation.toString())
+ // directories are rooted outside the namespace location
+ .putAll(Map.of("polaris.config.allow.unstructured.table.location", "true"))
+ .build())
+ .setStorageConfigInfo(
+ new FileStorageConfigInfo(
+ StorageConfigInfo.StorageTypeEnum.FILE,
+ List.of(catalogBaseLocation.toString()),
+ null))
+ .build();
+ managementApi.createCatalog(principalRoleName, catalog);
+
+ managementApi.createCatalogRole(catalogName, CATALOG_ROLE);
+ managementApi.addGrant(
+ catalogName,
+ CATALOG_ROLE,
+ new CatalogGrant(CatalogPrivilege.CATALOG_MANAGE_CONTENT, GrantResource.TypeEnum.CATALOG));
+ managementApi.grantCatalogRoleToPrincipalRole(
+ principalRoleName, catalogName, managementApi.getCatalogRole(catalogName, CATALOG_ROLE));
+
+ String principalToken = client.obtainToken(principal);
+ restCatalog = IcebergHelper.restCatalog(endpoints, catalogName, Map.of(), principalToken);
+ directoryApi = client.directoryApi(principalToken);
+ restCatalog.createNamespace(NS);
+ }
+
+ @AfterEach
+ public void cleanUp() throws IOException {
+ try {
+ if (restCatalog != null) {
+ restCatalog.close();
+ }
+ } finally {
+ client.cleanUp(adminToken);
+ }
+ }
+
+ @Test
+ public void testCreateScanLoadAndDrop() throws IOException {
+ URI baseLocation = catalogBaseLocation.resolve("images/");
+ Path baseDir = Path.of(baseLocation);
+ Files.createDirectories(baseDir);
+ Files.writeString(baseDir.resolve("a.jpg"), "a");
+ Files.writeString(baseDir.resolve("b.png"), "bb");
+
+ directoryApi.createDirectory(catalogName, IMAGES, baseLocation.toString(), Map.of());
+
+ assertThat(directoryApi.listDirectories(catalogName, NS)).containsExactly(IMAGES);
+ assertThat(directoryApi.getDirectory(catalogName, IMAGES).getBaseLocation())
+ .isEqualTo(baseLocation.toString());
+ // The inventory table cannot share the name of the directory
+ assertThat(restCatalog.tableExists(IMAGES_INVENTORY)).isTrue();
+
+ assertThat(directoryApi.scanDirectory(catalogName, IMAGES)).isEqualTo(2L);
+ assertThat(restCatalog.loadTable(IMAGES_INVENTORY).currentSnapshot()).isNotNull();
Review Comment:
Can we also assert file_uri values, filter behavior? It'd be helpful in preventing regressions from passing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org