Skip to content

Conversation

@nastra
Copy link
Contributor

@nastra nastra commented Jan 29, 2024

This adds support for the below ALTER cases as defined in https://spark.apache.org/docs/latest/sql-ref-syntax-ddl-alter-view.html:

  • ALTER VIEW <viewName> SET TBLPROPERTIES (...)
  • ALTER VIEW <viewName> UNSET TBLPROPERTIES (...)

verifyColumnCount(ident, columnAliases, query)
SchemaUtils.checkColumnNameDuplication(query.schema.fieldNames, SQLConf.get.resolver)

case UnsetViewProperties(ResolvedV2View(catalog, ident), propertyKeys, ifExists) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Check rules are intended to ensure that SQL is correct and valid, not to check the execution. If you have this check here, it would fail when you run EXPLAIN ALTER VIEW ... because this is doing execution work (checking for the property) in the planner. Another way to think about this is that this isn't an analysis failure, it is a runtime failure due to data. The SQL is perfectly valid.

This should either be done in AlterV2ViewExec or not at all. I would lean toward not doing this check at all. Shouldn't this be idempotent? Is there value in failing to remove a property if it isn't there? I don't see value so I'd ignore this and let the catalog throw an exception if it chooses to.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, I missed the ifExists part. looks like this behavior is required by Spark.

In that case, this should be moved to the Exec plan.

if (null != asViewCatalog) {
try {
org.apache.iceberg.view.View view = asViewCatalog.loadView(buildIdentifier(ident));
UpdateViewProperties updateViewProperties = view.updateProperties();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also reject reserved properties? I don't think that you should be able to set format-version, location, or provider.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a miss on my end. For some reason reason I manually checked provider / location (which Spark would prevent from being set/unset) and assumed Spark would do this for all reserved properties.

I've added some tests and fixed this. Note that I'm rejecting both setting/removing reserved properties as it seems a bit confusing from a user's perspective if Spark rejects setting/removing certain properties but we only reject setting those.
It also appears that the behavior for tables is slightly different, where we're only rejecting setting reserved table properties, but we're not rejecting the removal of reserved table properties.

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.

Mostly looks good. Just two major things:

  1. Checking if a property to unset exists should be done in the exec node
  2. Iceberg should fail if the caller attempts to set reserved properties

@nastra nastra force-pushed the spark-view-alter-properties-support branch 2 times, most recently from 06461fe to 54a6abe Compare January 31, 2024 10:25
.hasMessageContaining(
"The feature is not supported: location is a reserved table property");

sql("ALTER VIEW %s UNSET TBLPROPERTIES ('format-version')", viewName);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rdblue it feels like maybe we should also prevent removing reserverd properties to be more explicit (even though they would be set by default when the view is loaded)? But I also see that we don't do this when removing reserved properties from a table

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree. You should not be able to unset these properties.

@nastra nastra force-pushed the spark-view-alter-properties-support branch 2 times, most recently from a2e312a to 32bc1d3 Compare January 31, 2024 10:44
@nastra nastra requested a review from rdblue January 31, 2024 10:52
@nastra nastra force-pushed the spark-view-alter-properties-support branch from 32bc1d3 to 646a645 Compare January 31, 2024 11:52
() -> sql("ALTER VIEW %s SET TBLPROPERTIES ('location' = 'random_location')", viewName))
.isInstanceOf(AnalysisException.class)
.hasMessageContaining(
"The feature is not supported: location is a reserved table property");
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Just because Spark has a bad error message doesn't mean Iceberg should. We could make this conform to our standard, which is more clear: "Cannot set reserved property: location"

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see this is coming from Spark. I think the other messages (that we generate) could also improve.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah we don't have much control over the error msg coming from Spark unfortunately

@apache apache deleted a comment from nastra Jan 31, 2024
() -> sql("ALTER VIEW %s SET TBLPROPERTIES ('format-version' = '99')", viewName))
.isInstanceOf(UnsupportedOperationException.class)
.hasMessageContaining(
"Cannot specify 'format-version' because it's a reserved view property");
Copy link
Contributor

Choose a reason for hiding this comment

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

How about Cannot set reserved property: %s? That's more direct and also uses the same verb that the caller used, "set".


assertThatThrownBy(() -> sql("ALTER VIEW %s UNSET TBLPROPERTIES ('unknown-key')", viewName))
.isInstanceOf(AnalysisException.class)
.hasMessageContaining("Attempted to unset non-existing property 'unknown-key'");
Copy link
Contributor

Choose a reason for hiding this comment

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

If this isn't Spark, we should fix the message: Cannot remove property that is not set: %s

assertThatThrownBy(() -> sql("ALTER VIEW %s UNSET TBLPROPERTIES ('format-version')", viewName))
.isInstanceOf(UnsupportedOperationException.class)
.hasMessageContaining(
"Cannot specify 'format-version' because it's a reserved view property");
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, it would be nice to improve the error message.

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.

Looks great! I have some minor style comments mostly about error messages.

This adds support for the below `ALTER` cases as defined in https://spark.apache.org/docs/latest/sql-ref-syntax-ddl-alter-view.html:
* `ALTER VIEW <viewName> SET TBLPROPERTIES (...)`
* `ALTER VIEW <viewName> UNSET TBLPROPERTIES (...)`
@nastra nastra force-pushed the spark-view-alter-properties-support branch from 646a645 to 9e3eb5a Compare February 1, 2024 07:32
@nastra
Copy link
Contributor Author

nastra commented Feb 1, 2024

Thanks for the review @rdblue, I've updated the error msgs and also renamed the internal property to spark.query-column-names

@nastra nastra merged commit 9c8e9ba into apache:main Feb 1, 2024
@nastra nastra deleted the spark-view-alter-properties-support branch February 1, 2024 08:20
devangjhabakh pushed a commit to cdouglas/iceberg that referenced this pull request Apr 22, 2024
This adds support for the below `ALTER` cases as defined in https://spark.apache.org/docs/latest/sql-ref-syntax-ddl-alter-view.html:
* `ALTER VIEW <viewName> SET TBLPROPERTIES (...)`
* `ALTER VIEW <viewName> UNSET TBLPROPERTIES (...)`
@nastra nastra self-assigned this Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants