-
Notifications
You must be signed in to change notification settings - Fork 177
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
base: main
Are you sure you want to change the base?
Fix: check for slashless metadata paths #968
Conversation
8461a5d
to
edb49b3
Compare
int lastSlashIndex = metadataFileLocation.lastIndexOf("/"); | ||
Preconditions.checkArgument( | ||
lastSlashIndex != -1, | ||
"Invalid metadata file location: %s, must be a full path to a file", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
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 anRange [0, -1) out of bounds
error when callingsubstring()
.