0
votes

I am trying to access a hive table specifying database qualifier using spark sql. I am using sparksession as it is spark 2.0 or above. For example, I am trying to add a partition to an existing table. The query is

sparksession.sql("ALTER TABLE $databasename.$tablename ADD PARTITION (...) LOCATION ...")

It doesn't throw any error but not even creating any partition. Is it the case that I can't specify databaseName in spark sql?

1
Can you please share the code and spark Logs? - Anupam Alok
It's a very big code. Inside that I am implementing a method. Can't share the whole code, basically the code is creating a query which looks like : ALTER TABLE databaseName.tableName ADD PARTITION (partitioncolumns = 'value') LOCATION 'some s3 location' - Pooja Agrawal
Can you see the spark logs when it is executing this sql? - Anupam Alok
It runs perfectly when I don't specify database name, i.e. while it uses the default database. - Pooja Agrawal
Yeah, sparks logs says retries for twice or thrice and then it just stops without throwing an error. I am runnig the spark code on EMR - Pooja Agrawal

1 Answers

1
votes
use Database

Command is supported in Latest Spark version you can use

sparksession.sql("use $databasename");
sparksession.sql("ALTER TABLE $tablename ADD PARTITION (...) LOCATION ...");

Try using the above code this can solve you problem.