-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add inline code examples for the S3 datasource (#29)
- Loading branch information
1 parent
c5f9257
commit 2d98dee
Showing
3 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
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
13 changes: 13 additions & 0 deletions
13
hexa/plugins/connector_s3/templates/connector_s3/partials/datasource_demo.py
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,13 @@ | ||
# Reading and writing to S3 using Pandas | ||
import pandas as pd | ||
|
||
df = pd.read_csv("s3://{{datasource.s3_name}}/path-in-bucket/example.csv") | ||
df.to_csv("s3://{{datasource.s3_name}}/other-path-in-bucket/result.csv") | ||
|
||
|
||
# Using S3FS to work directly with S3 resources | ||
import s3fs, json | ||
|
||
fs = s3fs.S3FileSystem() | ||
with fs.open("s3://{{datasource.s3_name}}/path-in-bucket/example.json", "rb") as f: | ||
print(len(json.load(f))) |
15 changes: 15 additions & 0 deletions
15
hexa/plugins/connector_s3/templates/connector_s3/partials/datasource_demo.r
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,15 @@ | ||
library(aws.s3) | ||
|
||
# Read CSV file | ||
df <- s3read_using( | ||
FUN = read.csv, | ||
object = 's3://{{ datasource.s3_name}}/path-in-bucket/example.csv' | ||
) | ||
|
||
# Write CSV file | ||
df.out <- head(df) | ||
s3write_using( | ||
x = df, | ||
FUN = write.csv, | ||
object = 's3://{{ datasource.s3_name}}/path-in-bucket/some-output.csv' | ||
) |