Skip to content
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

Fix: check for slashless metadata paths #968

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1583,4 +1583,13 @@ public void testFileIOWrapper() {
handler.handleTask(taskEntity, realmContext);
Assertions.assertThat(measured.getNumDeletedFiles()).as("A table was deleted").isGreaterThan(0);
}

@Test
public void testRegisterTableWithSlashlessMetadataLocation() {
BasePolarisCatalog catalog = catalog();
Assertions.assertThatThrownBy(
() -> catalog.registerTable(TABLE, "metadata_location_without_slashes"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Invalid metadata file location");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,18 @@ public Table registerTable(TableIdentifier identifier, String metadataFileLocati
metadataFileLocation != null && !metadataFileLocation.isEmpty(),
"Cannot register an empty metadata file location as a table");

int lastSlashIndex = metadataFileLocation.lastIndexOf("/");
Preconditions.checkArgument(
lastSlashIndex != -1,
"Invalid metadata file location: %s, must be a full path to a file",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The presence of a slash does not mean the path is full, e.g. ../relative

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but this indicates the absence of a slash, which means the path is not full.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but it is kind of misleading to check for condition X and then print an error message saying condition (X + Y) is not met.

How about...

Invalid metadata file location; metadata file location should be absolute and must contain `/`: %s

Copy link
Contributor

@eric-maynard eric-maynard Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, I don't think making this check for an absolute path is strictly a blocker here; we can file an issue to track that if need be. But let's please try to swiftly get rid of the 500

metadataFileLocation);

// Throw an exception if this table already exists in the catalog.
if (tableExists(identifier)) {
throw new AlreadyExistsException("Table already exists: %s", identifier);
}

String locationDir = metadataFileLocation.substring(0, metadataFileLocation.lastIndexOf("/"));
String locationDir = metadataFileLocation.substring(0, lastSlashIndex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if metadataFileLocation is s3://my-bucket?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there is no .metadata.json in the file name, that would fail the file name format checks in https://github.com/apache/iceberg/blob/main/core/src/main/java/org/apache/iceberg/TableMetadataParser.java#L68 when we try to read the metadata file, giving a 400.


TableOperations ops = newTableOps(identifier);

Expand Down