0

Can someone let me know what asterics ** achieves when writing to Cosmos DB from Databrick.

# Write configuration
writeConfig = {
    "Endpoint": "https://doctorwho.documents.azure.com:443/",
    "Masterkey": "YOUR-KEY-HERE",
    "Database": "DepartureDelays",
    "Collection": "flights_fromsea",
    "Upsert": "true"
}

# Write to Cosmos DB from the flights DataFrame
flights.write.format("com.microsoft.azure.cosmosdb.spark").options(
    **writeConfig).save()

Thanks

Carltonp
  • 1,166
  • 5
  • 19
  • 39
  • Does this answer your question? [What does \*\* (double star/asterisk) and \* (star/asterisk) do for parameters?](https://stackoverflow.com/questions/36901/what-does-double-star-asterisk-and-star-asterisk-do-for-parameters) – blackbishop Feb 17 '20 at 21:24
  • hi blackbishop, it doesn't help in this context – Carltonp Feb 17 '20 at 22:42

1 Answers1

2

This is simply to allow you to pass multiple arguments directly using a list, tuple or a dictionary in your case.

So rather than you say:

flights.write.format("com.microsoft.azure.cosmosdb.spark")\
             .option("Endpoint", "https://doctorwho.documents.azure.com:443/")\
             .option("Upsert", "true")\
             .option("Masterkey", "YOUR-KEY-HERE")\
             ...etc 

You simply have all your arguments in a dictionary and then pass it like the following

flights.write.format("com.microsoft.azure.cosmosdb.spark").options(
    **yourdict).save()
BICube
  • 4,451
  • 1
  • 23
  • 44
  • I'm a little confused by your answer. Are you saying that options.(**yourdict) is equivalent to ```flights.write.format("com.microsoft.azure.cosmosdb.spark")\ .option("Endpoint": "https://doctorwho.documents.azure.com:443/")\ .option("Upsert": "true")\ .option("Masterkey": "YOUR-KEY-HERE")\ ...etc ``` – Carltonp Feb 17 '20 at 22:35
  • @Carltonp, Yes, in databricks, you either pass your options one by one as key/value using .option(key,value).option(key,value).option(key,value) ..etc or you put your arguments into a dictionary and then pass them using .options(**yourdict). Is that still confusing? – BICube Feb 17 '20 at 23:23
  • perfect. Thank you very much – Carltonp Feb 18 '20 at 13:19