Skip to content

Comments

[SPARK-30019][SQL] Add the owner property to v2 table#27249

Closed
yaooqinn wants to merge 17 commits intoapache:masterfrom
yaooqinn:SPARK-30019
Closed

[SPARK-30019][SQL] Add the owner property to v2 table#27249
yaooqinn wants to merge 17 commits intoapache:masterfrom
yaooqinn:SPARK-30019

Conversation

@yaooqinn
Copy link
Member

@yaooqinn yaooqinn commented Jan 17, 2020

What changes were proposed in this pull request?

Add owner property to v2 table, it is reversed by TableCatalog, indicates the table's owner.

Why are the changes needed?

enhance ownership management of catalog API

Does this PR introduce any user-facing change?

yes, add 1 reserved property - owner , and it is not allowed to use in OPTIONS/TBLPROPERTIES anymore, only if legacy on

How was this patch tested?

add uts

@yaooqinn yaooqinn requested a review from cloud-fan January 17, 2020 05:39
@SparkQA
Copy link

SparkQA commented Jan 17, 2020

Test build #116892 has finished for PR 27249 at commit 30b91f5.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jan 17, 2020

Test build #116898 has finished for PR 27249 at commit 0467b1e.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jan 17, 2020

Test build #116914 has finished for PR 27249 at commit 4577e93.

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

@SparkQA
Copy link

SparkQA commented Jan 17, 2020

Test build #116929 has finished for PR 27249 at commit 0b50979.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

shall we also print owner name/type in DESC TABLE like DESC NAMESPACE?

@yaooqinn
Copy link
Member Author

shall we also print owner name/type in DESC TABLE like DESC NAMESPACE?

The DescribeTableExec will show all reserved properties separately

TableCatalog.RESERVED_PROPERTIES.asScala.toList.foreach(propKey => {
if (table.properties.containsKey(propKey)) {
rows += toCatalystRow(propKey.capitalize, table.properties.get(propKey), "")
}
})

@cloud-fan
Copy link
Contributor

I mean, we should follow DESC NAMESPACE to implement it, e.g. display Owner Name: abc which looks nicer. Anyway we can do it in a followup.

@cloud-fan
Copy link
Contributor

LGTM

@SparkQA
Copy link

SparkQA commented Jan 17, 2020

Test build #116940 has finished for PR 27249 at commit 0fc2692.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jan 17, 2020

Test build #116959 has finished for PR 27249 at commit 8e4f747.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jan 17, 2020

Test build #116958 has finished for PR 27249 at commit f5512fb.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@yaooqinn
Copy link
Member Author

retest this please

@SparkQA
Copy link

SparkQA commented Jan 19, 2020

Test build #116986 has finished for PR 27249 at commit 8e4f747.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jan 19, 2020

Test build #116991 has finished for PR 27249 at commit e618825.

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

@yaooqinn
Copy link
Member Author

retest this please

@SparkQA
Copy link

SparkQA commented Jan 19, 2020

Test build #116996 has finished for PR 27249 at commit e618825.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jan 19, 2020

Test build #116999 has finished for PR 27249 at commit 46ae85b.

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

owner
</td>
<td>
no
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 reserved for both table and namespace, or do I miss something?

Copy link
Contributor

Choose a reason for hiding this comment

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

nvm, we can update when revert ALTER NAMESPACE SET OWNER.

case (PROP_LOCATION, _) => false
case (PROP_OWNER, _) if !legacyOn =>
throw new ParseException(s"$PROP_OWNER is a reserved table property , please use" +
" ALTER TABLE ... SET OWNER ... to specify it.", ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

it can't be changed after table is created.

import org.apache.spark.sql.catalyst.plans.DescribeTableSchema
import org.apache.spark.sql.catalyst.plans.logical._
import org.apache.spark.sql.catalyst.util.{escapeSingleQuotedString, quoteIdentifier, CaseInsensitiveMap}
import org.apache.spark.sql.connector.catalog.TableCatalog
Copy link
Contributor

Choose a reason for hiding this comment

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

unnecessary change


import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.catalyst.catalog.CatalogTable
import org.apache.spark.sql.connector.catalog.TableCatalog
Copy link
Contributor

Choose a reason for hiding this comment

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

unnecessary

import org.apache.spark.sql.catalyst.expressions.Expression
import org.apache.spark.sql.catalyst.parser.{CatalystSqlParser, ParseException}
import org.apache.spark.sql.connector.catalog.SupportsNamespaces._
import org.apache.spark.sql.connector.catalog.TableCatalog
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@cloud-fan
Copy link
Contributor

can we add some tests to make sure CREATE/ALTER TABLE fails if setting owner property?

Also let's update the PR title. Now we are just adding an owner property to v2 table.

@yaooqinn
Copy link
Member Author

yaooqinn commented Jan 20, 2020

can we add some tests to make sure CREATE/ALTER TABLE fails if setting owner property?

test("create/replace/alter table - reserved properties") {
import TableCatalog._
withSQLConf((SQLConf.LEGACY_PROPERTY_NON_RESERVED.key, "false")) {
RESERVED_PROPERTIES.asScala.filterNot(_ == PROP_COMMENT).foreach { key =>
Seq("OPTIONS", "TBLPROPERTIES").foreach { clause =>
Seq("CREATE", "REPLACE").foreach { action =>
val e = intercept[ParseException] {
sql(s"$action TABLE testcat.reservedTest (key int) USING foo $clause ('$key'='bar')")
}
assert(e.getMessage.contains(s"$key is a reserved table property"))
}
}
val e1 = intercept[ParseException] {
sql(s"ALTER TABLE testcat.reservedTest SET TBLPROPERTIES ('$key'='bar')")
}
assert(e1.getMessage.contains(s"$key is a reserved table property"))
val e2 = intercept[ParseException] {
sql(s"ALTER TABLE testcat.reservedTest UNSET TBLPROPERTIES ('$key')")
}
assert(e2.getMessage.contains(s"$key is a reserved table property"))
}
}
withSQLConf((SQLConf.LEGACY_PROPERTY_NON_RESERVED.key, "true")) {
RESERVED_PROPERTIES.asScala.filterNot(_ == PROP_COMMENT).foreach { key =>
Seq("OPTIONS", "TBLPROPERTIES").foreach { clause =>
withTable("testcat.reservedTest") {
Seq("CREATE", "REPLACE").foreach { action =>
sql(s"$action TABLE testcat.reservedTest (key int) USING foo $clause ('$key'='bar')")
val tableCatalog = catalog("testcat").asTableCatalog
val identifier = Identifier.of(Array(), "reservedTest")
val originValue = tableCatalog.loadTable(identifier).properties().get(key)
assert(originValue != "bar", "reserved properties should not have side effects")
sql(s"ALTER TABLE testcat.reservedTest SET TBLPROPERTIES ('$key'='newValue')")
assert(tableCatalog.loadTable(identifier).properties().get(key) == originValue,
"reserved properties should not have side effects")
sql(s"ALTER TABLE testcat.reservedTest UNSET TBLPROPERTIES ('$key')")
assert(tableCatalog.loadTable(identifier).properties().get(key) == originValue,
"reserved properties should not have side effects")
}
}
}
}
}
}

We have a general test for reserved ones

Also let's update the PR title. Now we are just adding an owner property to v2 table.

OK

@yaooqinn yaooqinn changed the title [SPARK-30019][SQL] Add ALTER TABLE SET OWNER syntax [SPARK-30019][SQL] Add the owner property to v2 table Jan 20, 2020
@SparkQA
Copy link

SparkQA commented Jan 20, 2020

Test build #117109 has finished for PR 27249 at commit 8e70ec1.

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

@SparkQA
Copy link

SparkQA commented Jan 20, 2020

Test build #117106 has finished for PR 27249 at commit ce352a9.

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

} else {
catalog.getTableMetadata(tableIdent).properties
}
props -- TableCatalog.RESERVED_PROPERTIES.asScala
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need this change?

assert(sql(s"DESCRIBE TABLE EXTENDED spark_30019").where("col_name='Owner'")
.collect().head.getString(1) === Utils.getCurrentUserName())
val e2 = intercept[ParseException](
sql(s"CREATE TABLE spark_30019_2 WITH TBLPROPERTIES('owner'='spark_30019')"))
Copy link
Contributor

@cloud-fan cloud-fan Jan 20, 2020

Choose a reason for hiding this comment

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

do we need it? I think we already have CREATE/REPLACE/ALTER TABLE tests for reserved properties.

Copy link
Member Author

Choose a reason for hiding this comment

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

you mean this whole test or this line?

@cloud-fan
Copy link
Contributor

LGTM except a few minor comments

@SparkQA
Copy link

SparkQA commented Jan 20, 2020

Test build #117100 has finished for PR 27249 at commit 9bb78eb.

  • This patch fails from timeout after a configured wait of 400m.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jan 20, 2020

Test build #117120 has finished for PR 27249 at commit 97f07b8.

  • This patch passes all tests.
  • This patch does not merge cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jan 20, 2020

Test build #117127 has finished for PR 27249 at commit 6b48061.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class UnresolvedTableWithViewExists(view: ResolvedView) extends LeafNode
  • case class ResolvedView(identifier: Identifier, isTempView: Boolean) extends LeafNode
  • abstract class AlterTable extends Command
  • case class AlterTableAddColumns(
  • case class AlterTableAlterColumn(
  • case class AlterTableRenameColumn(
  • case class AlterTableDropColumns(
  • case class AlterTableSetProperties(
  • case class AlterTableUnsetProperties(
  • case class AlterTableSetLocation(

@cloud-fan
Copy link
Contributor

thanks, merging to master!

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.

4 participants