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

API, Core: Add sqlFor API to views to handle basic resolution of dialect #9247

Merged
merged 1 commit into from
Dec 15, 2023

Conversation

amogh-jahagirdar
Copy link
Contributor

@amogh-jahagirdar amogh-jahagirdar commented Dec 7, 2023

This change adds a ViewRepresentation sqlFor(String dialect) API which will resolve a representation based on the give dialect. The current implementation just aims for an exact search with a fallback to the first added representation in case an exact match does not exist. If no SQL dialect exists, null is returned.

The intention of this API is so that engine integrations don't have to implement this same logic. If an engine wants to use a different dialect than what this API returns then they can still implement that.

* @return the view representation for the given SQL dialect, or null if no representation could
* be resolved
*/
default ViewRepresentation sqlFor(String dialect) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's unfortunate, this API has to return a ViewRepresentation. It would have been better if it could have returned a SQLViewRepresentation specifically but since that's an implementation in core that's not possible. The issue is that now callers have to cast. But I guess they would've had to do that anyways?

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we just move SQLViewRepresentation into API? That would make sense to me.

return sqlViewRepresentation;
}

closest = sqlViewRepresentation;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use the first defined representation or the last? I'm inclined to use the first as the closest.

Copy link
Contributor Author

@amogh-jahagirdar amogh-jahagirdar Dec 14, 2023

Choose a reason for hiding this comment

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

I don't really have a preference as long as it's consistent (always first or always last or well defined based on some other heuristic).

What's the main benefit you see for using the first? Is it just that it's easier to see in the metadata?

For context, I chose the last just because the implementation is cleaner there (just need a single loop over the representations and tracking the closest is just a matter of updating a reference until either an exact match is found or the loop completes and we return the closest which would be null in case there's no SQL representation).

Copy link
Contributor

@rdblue rdblue left a comment

Choose a reason for hiding this comment

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

Overall this look great. I had some minor comments in the implementation and I think the only major change I'd make is to move SQLViewRepresentation into the API. The SQL representation is defined by the spec so it makes sense to have it there.

Copy link
Contributor

@rdblue rdblue left a comment

Choose a reason for hiding this comment

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

A couple minor points, but overall this looks good. Thanks for getting this done, @amogh-jahagirdar!

@amogh-jahagirdar
Copy link
Contributor Author

Thanks for the review @rdblue , merging!

@amogh-jahagirdar amogh-jahagirdar merged commit 8181f84 into apache:main Dec 15, 2023
for (ViewRepresentation representation : currentVersion().representations()) {
if (representation instanceof SQLViewRepresentation) {
SQLViewRepresentation sqlViewRepresentation = (SQLViewRepresentation) representation;
if (sqlViewRepresentation.dialect().equals(dialect)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious whether equalsIgnoreCase would make sense here?

Copy link
Contributor Author

@amogh-jahagirdar amogh-jahagirdar Dec 16, 2023

Choose a reason for hiding this comment

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

Ah this was equalsIgnoreCase before but when I refactored back into a loop, it mistakenly became equals. Let me fix this.

Copy link
Contributor Author

@amogh-jahagirdar amogh-jahagirdar Dec 16, 2023

Choose a reason for hiding this comment

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

But yes I think the API should be case insensitive (in practice it won't really matter I think because engines would just read and write the view through a constant but it's helpful from an API perspective if someone wants to create the view from say a Python script which doesn't necessarily know the exact constant). The API should still return the same representation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should add a test for this as well

lisirrx pushed a commit to lisirrx/iceberg that referenced this pull request Jan 4, 2024
geruh pushed a commit to geruh/iceberg that referenced this pull request Jan 26, 2024
devangjhabakh pushed a commit to cdouglas/iceberg that referenced this pull request Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants