#Get all objects from the metastore for databases
from pyspark.sql.functions import col,lit, concat
objects = spark.sql("SHOW TABLES FROM %s" % databases[0])
for db in databases[1:]:
tables = spark.sql("SHOW TABLES FROM %s" % db)
objects = objects.union(tables)
objects_w_grant = objects.withColumn("ownerGrant", concat(lit("ALTER TABLE "), col("database"), lit("."), col("tableName"), lit(" OWNER TO `"), lit(new_owner), lit("`;") ))
display(objects_w_grant.select("ownerGrant"))
#Copy the following `GRANT` statements and issue in a new Cmd prefixed by `%sql`
This notebook allows you to quickly set the owner for objects that already exist in your metastore.
Attach to a cluster enabled with table access control.
There are 2 common patterns:
new_owner
Cmd 2 to that user or group.