-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new post / 2024-05-05-convert-json-to-parquet-and-send-to-azure-blob-…
…storage.md
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...posts/2024/2024-05-05-convert-json-to-parquet-and-send-to-azure-blob-storage.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
authors: | ||
- copdips | ||
categories: | ||
- python | ||
- file | ||
- spark | ||
comments: true | ||
date: | ||
created: 2024-05-05 | ||
--- | ||
|
||
# Convert json to parquet and send to Azure Blob Storage | ||
|
||
```python title="with pyarrow only without pandas" | ||
# pip install adlfs pyarrow | ||
# https://arrow.apache.org/docs/python/parquet.html#reading-from-cloud-storage | ||
|
||
from os import environ | ||
|
||
import pyarrow as pa | ||
import pyarrow.parquet as pq | ||
from adlfs import AzureBlobFileSystem | ||
|
||
|
||
json_file = "aaa.json" | ||
blob_connection_string = environ["AZURE_BLOB_CONNECTION_STRING"] | ||
blob_container_name = "bbb" | ||
|
||
table = pa.Table.from_json(source_file) | ||
|
||
abfs = AzureBlobFileSystem(connection_string=blob_connection_string) | ||
|
||
pq.write_table( | ||
table, | ||
f"{blob_container_name}/another_folder/output.parquet", | ||
filesystem=abfs | ||
) | ||
``` |