Skip to content

Conversation

@planga82
Copy link
Contributor

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.

@planga82
Copy link
Contributor Author

cc: @cloud-fan @rdblue @viirya @imback82

@viirya
Copy link
Member

viirya commented Oct 19, 2019

ok to test

@SparkQA
Copy link

SparkQA commented Oct 19, 2019

Test build #112320 has finished for PR 26176 at commit 4bd0c5a.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class ShowTablePropertiesStatement(

@SparkQA
Copy link

SparkQA commented Oct 20, 2019

Test build #112335 has finished for PR 26176 at commit 4bc65b1.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@planga82 planga82 force-pushed the feature/SPARK-29519_SHOW_TBLPROPERTIES_datasourceV2 branch from 4bc65b1 to f651227 Compare October 20, 2019 07:18
@SparkQA
Copy link

SparkQA commented Oct 20, 2019

Test build #112338 has finished for PR 26176 at commit f651227.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

override def visitShowTblProperties(
ctx: ShowTblPropertiesContext): LogicalPlan = withOrigin(ctx) {
ShowTablePropertiesStatement(
visitMultipartIdentifier(ctx.multipartIdentifier()),
Copy link
Contributor

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.

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 have seen the other pull requests as example. If we have to change it, it's not a problem.

Copy link
Contributor

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"))
Copy link
Contributor

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.

@planga82 planga82 force-pushed the feature/SPARK-29519_SHOW_TBLPROPERTIES_datasourceV2 branch from f651227 to fb93e0f Compare November 6, 2019 05:51
@planga82
Copy link
Contributor Author

planga82 commented Nov 6, 2019

V2 command implemented

/**
* The logical plan of the SHOW TBLPROPERTIES command that works for v2 catalogs.
*/
case class ShowTblproperties(
Copy link
Contributor

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)
Copy link
Contributor

@cloud-fan cloud-fan Nov 6, 2019

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.

Copy link
Contributor Author

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!!

@SparkQA
Copy link

SparkQA commented Nov 6, 2019

Test build #113301 has finished for PR 26176 at commit fb93e0f.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class ShowTablePropertiesStatement(
  • case class ShowTblproperties(
  • case class ShowTblpropertiesExec(

@SparkQA
Copy link

SparkQA commented Nov 7, 2019

Test build #113400 has finished for PR 26176 at commit 706a555.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class ShowTableProperties(

ShowCurrentNamespace(catalogManager)

case ShowTablePropertiesStatement(
nameParts @ NonSessionCatalog(catalog, tableName), propertyKey) =>
Copy link
Contributor

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')")
Copy link
Contributor

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?

Copy link
Contributor Author

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)

Copy link
Contributor

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')];
Copy link
Contributor

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
}
}

Copy link
Contributor

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())

Copy link
Contributor

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(
Copy link
Contributor

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")
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes done

@SparkQA
Copy link

SparkQA commented Nov 8, 2019

Test build #113466 has finished for PR 26176 at commit 93ec3f8.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Nov 8, 2019

Test build #113471 has finished for PR 26176 at commit e5e44c1.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Copy link
Contributor

@imback82 imback82 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @planga82!

@planga82
Copy link
Contributor Author

planga82 commented Nov 9, 2019

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
@planga82 planga82 force-pushed the feature/SPARK-29519_SHOW_TBLPROPERTIES_datasourceV2 branch from e5e44c1 to 863ed90 Compare November 10, 2019 18:55
@planga82
Copy link
Contributor Author

Conflict resolved

@SparkQA
Copy link

SparkQA commented Nov 10, 2019

Test build #113547 has finished for PR 26176 at commit 863ed90.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class ShowTablePropertiesStatement(
  • case class ShowTableProperties(
  • case class ShowTablePropertiesExec(

CatalogV2Util.loadRelation(u.catalog, u.tableName)
.map(rel => show.copy(table = rel))
.getOrElse(u)

Copy link
Contributor

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 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

good catch!

Copy link
Contributor Author

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) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: 4 space indentation

@SparkQA
Copy link

SparkQA commented Nov 11, 2019

Test build #113599 has finished for PR 26176 at commit 846e21a.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

thanks, merging to master!

@cloud-fan cloud-fan closed this in 37e387a Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants