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

Conversation

RichardLiu2001
Copy link

@RichardLiu2001 RichardLiu2001 commented Feb 8, 2025

Polaris currently returns a 500 error for the registerTable catalog API if the provided metadata file path does not contain any slashes.

  • lastIndexOf("/") will return -1, causing an Range [0, -1) out of bounds error when calling substring().
  • This change handles this case & returns a 400 instead.

@RichardLiu2001 RichardLiu2001 force-pushed the check-slashless-metadata-paths branch from 8461a5d to edb49b3 Compare February 8, 2025 01:11
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

// 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.

@RichardLiu2001 RichardLiu2001 marked this pull request as ready for review February 10, 2025 19:16
@RichardLiu2001 RichardLiu2001 changed the title add check for slashless metadata paths Fix: check for slashless metadata paths Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants