@@ -89,7 +89,9 @@ ctx.create_dataframe([[batch]]).show()
8989## Object Store
9090
9191DataFusion has support for multiple storage options in addition to local files.
92- The example below requires an appropriate S3 account with access credentials.
92+ The example below requires access to the S3 bucket. Set ` AWS_ACCESS_KEY_ID ` and
93+ ` AWS_SECRET_ACCESS_KEY ` in the environment before running it. For temporary
94+ credentials, also set ` AWS_SESSION_TOKEN ` .
9395
9496Supported Object Stores are
9597
@@ -100,16 +102,17 @@ Supported Object Stores are
100102- {py: class }` ~datafusion.object_store.MicrosoftAzure `
101103
102104``` python
105+ from datafusion import SessionContext
103106from datafusion.object_store import AmazonS3
104107
105108region = " us-east-1"
106109bucket_name = " yellow-trips"
107110
111+ ctx = SessionContext()
112+
108113s3 = AmazonS3(
109114 bucket_name = bucket_name,
110115 region = region,
111- access_key_id = os.getenv(" AWS_ACCESS_KEY_ID" ),
112- secret_access_key = os.getenv(" AWS_SECRET_ACCESS_KEY" ),
113116)
114117
115118path = f " s3:// { bucket_name} / "
@@ -120,6 +123,27 @@ ctx.register_parquet("trips", path)
120123ctx.table(" trips" ).show()
121124```
122125
126+ ### Query S3 data with SQL
127+
128+ To reach the same data from SQL, give the S3 path a table name with
129+ ` CREATE EXTERNAL TABLE ` . The registered object store carries the credentials and
130+ the region, so the statement itself needs only the location.
131+
132+ Register the store for the bucket as shown above, then use that same
133+ {py: class }` ~datafusion.context.SessionContext ` to create and query the table:
134+
135+ ``` python
136+ ctx.sql(
137+ f """
138+ CREATE EXTERNAL TABLE trips_sql
139+ STORED AS PARQUET
140+ LOCATION ' { path} '
141+ """
142+ ).collect()
143+
144+ ctx.sql(" SELECT count(passenger_count) FROM trips_sql" ).show()
145+ ```
146+
123147## Other DataFrame Libraries
124148
125149DataFusion can import DataFrames directly from other libraries, such as
0 commit comments