-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-29519][SQL] SHOW TBLPROPERTIES should do multi-catalog resolution. #26176
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
[SPARK-29519][SQL] SHOW TBLPROPERTIES should do multi-catalog resolution. #26176
Conversation
|
ok to test |
|
Test build #112320 has finished for PR 26176 at commit
|
|
Test build #112335 has finished for PR 26176 at commit
|
4bc65b1 to
f651227
Compare
|
Test build #112338 has finished for PR 26176 at commit
|
| override def visitShowTblProperties( | ||
| ctx: ShowTblPropertiesContext): LogicalPlan = withOrigin(ctx) { | ||
| ShowTablePropertiesStatement( | ||
| visitMultipartIdentifier(ctx.multipartIdentifier()), |
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.
ctx.table since the alias is available? I am not sure what the preferred way is, and for commands like ALTER TABLE, we haven't used the alias table in SqlBase.g4. @cloud-fan can confirm.
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.
I have seen the other pull requests as example. If we have to change it, it's not a problem.
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.
It's not a big deal. We can either remove the table alias, or use ctx.table here.
| val e1 = intercept[AnalysisException] { | ||
| sql(s"SHOW TBLPROPERTIES $t") | ||
| } | ||
| assert(e1.message.contains("SHOW TBLPROPERTIES is only supported with v1 tables")) |
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.
I think we can implement SHOW TBLPROPERTIES with v2 APIs. You can refer to #26166 about how to implement a v2 command.
f651227 to
fb93e0f
Compare
|
V2 command implemented |
| /** | ||
| * The logical plan of the SHOW TBLPROPERTIES command that works for v2 catalogs. | ||
| */ | ||
| case class ShowTblproperties( |
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.
let's use the full name: ShowTableProperties
| ShowCurrentNamespace(catalogManager) | ||
|
|
||
| case ShowTablePropertiesStatement(NonSessionCatalog(catalog, tableName), propertyKey) => | ||
| ShowTblproperties(catalog.asTableCatalog, tableName.asIdentifier, propertyKey) |
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 logical plan should take a NamedRelation, and here we can just pass in a UnresolvedV2Relation.
You can take a look at how DescribeTableStatement is handled in this 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.
Ok, I see, the Analizer resolve tables in V2 catalog, thanks!!
|
Test build #113301 has finished for PR 26176 at commit
|
|
Test build #113400 has finished for PR 26176 at commit
|
| ShowCurrentNamespace(catalogManager) | ||
|
|
||
| case ShowTablePropertiesStatement( | ||
| nameParts @ NonSessionCatalog(catalog, tableName), propertyKey) => |
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.
nit: 4 space indentation before nameParts @
| spark.sql(s"CREATE TABLE $t (id bigint, data string) USING $provider " + | ||
| s"TBLPROPERTIES ('owner'='$owner', 'status'='$status')") | ||
|
|
||
| val tbl1 = sql(s"SHOW TBLPROPERTIES $t ('status')") |
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.
can we also test if the key not found?
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.
Ok
| nameParts @ NonSessionCatalog(catalog, tableName), propertyKey) => | ||
| val r = UnresolvedV2Relation(nameParts, catalog.asTableCatalog, tableName.asIdentifier) | ||
| ShowTableProperties(r, propertyKey) | ||
|
|
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.
nit: remove extra empty line.
| * corresponding values are returned. | ||
| * The syntax of using this command in SQL is: | ||
| * {{{ | ||
| * SHOW TBLPROPERTIES table_name[('propertyKey')]; |
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.
nit: table_name -> multi_part_name
| encoder.toRow(new GenericRowWithSchema(Array(k, properties(k)), schema)).copy()).toSeq | ||
| } | ||
| } | ||
|
|
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.
nit: remove empty line
|
|
||
| assert(tbl1.schema === schema) | ||
| assert(expected === tbl1.collect()) | ||
|
|
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.
nit: remove empty line
| /** | ||
| * Physical plan node for showing tblproperties. | ||
| */ | ||
| case class ShowTblpropertiesExec( |
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.
ShowTablePropertiesExec to match with the statement, etc. Same applies to other places below.
| spark.sql(s"CREATE TABLE $t (id bigint, data string) USING $provider " + | ||
| s"TBLPROPERTIES ('owner'='$owner', 'status'='$status')") | ||
|
|
||
| val tbl1 = sql(s"SHOW TBLPROPERTIES $t") |
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.
Why 1? How about just properties?
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.
Changes done
|
Test build #113466 has finished for PR 26176 at commit
|
|
Test build #113471 has finished for PR 26176 at commit
|
imback82
left a comment
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.
LGTM. Thanks @planga82!
|
Thanks for your comments!! |
[SPARK-29519] Fix tests [SPARK-29519] Resolve catalog in Analizer [SPARK-29519] Fix pull request comments [SPARK-29519] Fix pull request comments
e5e44c1 to
863ed90
Compare
|
Conflict resolved |
|
Test build #113547 has finished for PR 26176 at commit
|
| CatalogV2Util.loadRelation(u.catalog, u.tableName) | ||
| .map(rel => show.copy(table = rel)) | ||
| .getOrElse(u) | ||
|
|
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.
Why is it '.getOrElse(u)' instead of '.getOrElse(show)' here ?
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.
good catch!
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.
oh, yes good catch!!
| ShowCurrentNamespace(catalogManager) | ||
|
|
||
| case ShowTablePropertiesStatement( | ||
| nameParts @ NonSessionCatalog(catalog, tableName), propertyKey) => |
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.
nit: 4 space indentation
|
Test build #113599 has finished for PR 26176 at commit
|
|
thanks, merging to master! |
What changes were proposed in this pull request?
Add ShowTablePropertiesStatement and make SHOW TBLPROPERTIES go through the same catalog/table resolution framework of v2 commands.
Why are the changes needed?
It's important to make all the commands have the same table resolution behavior, to avoid confusing end-users. e.g.
USE my_catalog
DESC t // success and describe the table t from my_catalog
SHOW TBLPROPERTIES t // report table not found as there is no table t in the session catalog
Does this PR introduce any user-facing change?
yes. When running SHOW TBLPROPERTIES Spark fails the command if the current catalog is set to a v2 catalog, or the table name specified a v2 catalog.
How was this patch tested?
Unit tests.