1

I am using databrick pyspark for coding wondering how could I pass the variable value to the name of the table which I want to save in the Azure

I am able to use this if that is the fix table name

result.write.format("parquet").mode("overwrite").saveAsTable("result0911")

but I hope to do this

Having a variable: time = datetime.today() the value of that is "2019-09-11 12:10:48.969602"

I want to first format the "time" to "20190911121048" which is good for the name of a table (I need the time also, because people may save the records more than once per day)

then use that value "20190911121048" table name which I want to save the table name should be "result_20190911121048"

any suggestion? Thank you the following does not work

result.write.format("parquet").mode("overwrite").saveAsTable("result_%s time")
2
  • I am able to use {t=time.strftime("%Y%m%d%H%M")} to reformat the time but still not abke to put the value of t in the name. Commented Sep 11, 2019 at 12:49
  • 2
    Make the variable of table name and then use str.format Commented Sep 11, 2019 at 12:59

2 Answers 2

2

Say you have 2 variables having values

time = "20190911121048"
table_name = 'result'

Then you can make table name as :

final_table_name = '{}_{}'.format(table_name, time)

result.write.format("parquet").mode("overwrite").saveAsTable(final_table_name)
Sign up to request clarification or add additional context in comments.

1 Comment

@CloverCeline please let me know if this is what you were looking for and please accept the answer
1

Thank you for the input. I am able to use this:

time = datetime.today()
t=time.strftime("%Y%m%d%H%M")
result_name ="recommendation_%s" % (t)
final_recon.write.format("parquet").mode("overwrite").saveAsTable(result_name)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.