Write DataFrame from Azure Databricks notebook to Azure DataLake Gen2 Tables - azure

I've created a DataFrame which I would like to write / export next to my Azure DataLake Gen2 in Tables (need to create new Table for this).
In the future I will also need to update this Azure DL Gen2 Table with new DataFrames.
In Azure Databricks I've created a connection Azure Databricks -> Azure DataLake to see my my files:
Appreciate help how to write it in spark / pyspark.
Thank you!

I would suggest instead of writing data in parquet format, go for Delta format which internally uses Parquet format but provide other features like ACID transaction.The syntax would be
df.write.format("delta").save(path)

Related

Hive and ADLS GEN2 integration

I am working on POC of Hive and Adls Gen2 integration.Requirement is if we submit a job we need to store the data in ADLS GEN2 location. So we need to create an External table on the top ADLS location.
Please share me any leads or pseudo code of it. I explored a lot but did not get any concrete solution yet.

Does Azure Databricks use Query Acceleration in Azure Data Lake Storage?

Does Azure Databricks use the query acceleration functions in Azure Data Lake Storage gen2? In documentation we can see that spark can benefit from this functionality.
I'm wondering if, in the case where I only use the delta format, I'm profiting from this functionality and whether to include it in the pricing in Azure Calculator under the Storage Account section?
From the docs
Query acceleration supports CSV and JSON formatted data as input to each request.
So it doesn't work with Parquet or Delta - because it is fundamentally a row based accelerator, and Parquet is a columnar format.

Azure Data Factory: Ingest - from Delta table to Postgres

I am currently creating an ingest pipeline to copy data from a delta table to a postgres table. When selecting the sink, I am asked to enable staging.
Direct copying data from Azure Databricks Delta Lake is only supported when sink dataset is DelimitedText, Parquet or Avro with Azure Blob Storage linked service or Azure Data Lake Storage Gen2, for other dataset or linked service, please enable staging
This will turn my pipeline into a 2 step process where my delta table data is copied to a staging location and then from there it is inserted into postgres. How can I take the delta table data and directly load it directly into postgres using an ingest pipeline in ADF without staging? Is this possible?
As suggested by #Karthikeyan Rasipalay Durairaj in comments, you can directly copy data from databricks to postgresql
To copy data from Azure databricks to postgresql use below code -
df.write().option('driver', 'org.postgresql.Driver').jdbc(url_connect, table, mode, properties)
Staged copy from delta lake
When your sink data store or format does not match the direct copy criteria, It enables the built-in staged copy using an interim Azure storage instance. The staged copy feature also provides you better throughput. The service exports data from Azure Databricks Delta Lake into staging storage, then copies the data to sink, and finally cleans up your temporary data from the staging storage.
Direct copy from delta lake
If your sink data store and format meet the criteria described below, you can use the Copy activity to directly copy from Azure Databricks Delta table to sink.
• The sink linked service is Azure Blob storage or Azure Data Lake Storage Gen2. The account credential should be pre-configured in Azure Databricks cluster configuration.
• The sink data format is of Parquet, delimited text, or Avro with the following configurations, and points to a folder instead of file.
• In the Copy activity source, additionalColumns is not specified.
• If copying data to delimited text, in copy activity sink, fileExtension need to be ".csv".
Refer this documentation

Ezport data from azure synapse sql

We have azure synapse with external data source as azure dala lake gen2.
We need to export T-SQL query results as csv file on a weekly schedule from Azure synapse to any blob storage or FTP. I could not find documents related to export from synapse. Please guide me through this - I've been stuck here for a long time.
Per this answer, I think the answer is:
Make a Dataflow where
the source is the Synapse db and you pass the query you want
the sink is a csv in ADLS gen2
Make an ADF pipeline with a weekly schedule trigger that calls your Dataflow

Is possible to read an Azure Databricks table from Azure Data Factory?

I have a table into an Azure Databricks Cluster, i would like to replicate this data into an Azure SQL Database, to let another users analyze this data from Metabase.
Is it possible to acess databricks tables through Azure Data factory?
No, unfortunately not. Databricks tables are typically temporary and last as long as your job/session is running. See here.
You would need to persist your databricks table to some storage in order to access it. Change your databricks job to dump the table to Blob storage as it's final action. In the next step of your data factory job, you can then read the dumped data from the storage account and process further.
Another option may be databricks delta although I have not tried this yet...
If you register the table in the Databricks hive metastore then ADF could read from it using the ODBC source in ADF. Though this would require an IR.
Alternatively you could write the table to external storage such as blob or lake. ADF can then read that file and push it to your sql database.

Resources