Reputation: 107
1.How to create the database using varible in pyspark.Assume we have variable with database name .using that variable how to create the database in the pyspark.
Var a="databasename"
create database a
can you please it is possible to use the variable?
Upvotes: 1
Views: 3616
Reputation: 87204
Just use spark.sql to execute corresponding CREATE DATABASE command:
db_name = "some_name"
spark.sql(f"CREATE DATABASE IF NOT EXISTS {db_name}")
Upvotes: 2