Skip to content

Commit 7f84c9e

Browse files
ywang103igorborgest
authored andcommitted
QuickSight general clean up.
1 parent 9d970c8 commit 7f84c9e

File tree

4 files changed

+1350
-8
lines changed

4 files changed

+1350
-8
lines changed

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,30 @@ df = wr.s3.read_parquet("s3://bucket/dataset/", dataset=True)
4444
df = wr.athena.read_sql_query("SELECT * FROM my_table", database="my_db")
4545

4646
# Getting Redshift connection (SQLAlchemy) from Glue Catalog Connections
47-
engine = wr.catalog.get_engine("my-redshift-connection")
48-
4947
# Retrieving the data from Amazon Redshift Spectrum
48+
engine = wr.catalog.get_engine("my-redshift-connection")
5049
df = wr.db.read_sql_query("SELECT * FROM external_schema.my_table", con=engine)
50+
51+
# Creating QuickSight Data Source and Dataset to reflect our new table
52+
wr.quicksight.create_athena_data_source("athena-source", allowed_to_manage=["username"])
53+
wr.quicksight.create_athena_dataset(
54+
name="my-dataset",
55+
database="my_db",
56+
table="my_table",
57+
data_source_name="athena-source",
58+
allowed_to_manage=["username"]
59+
)
60+
61+
# Getting MySQL connection (SQLAlchemy) from Glue Catalog Connections
62+
# Load the data into MySQL
63+
engine = wr.catalog.get_engine("my-mysql-connection")
64+
wr.db.to_sql(df, engine, schema="test", name="my_table")
65+
66+
# Getting PostgreSQL connection (SQLAlchemy) from Glue Catalog Connections
67+
# Load the data into PostgreSQL
68+
engine = wr.catalog.get_engine("my-postgresql-connection")
69+
wr.db.to_sql(df, engine, schema="test", name="my_table")
70+
5171
```
5272

5373
## [Read The Docs](https://aws-data-wrangler.readthedocs.io/)
@@ -80,13 +100,15 @@ df = wr.db.read_sql_query("SELECT * FROM external_schema.my_table", con=engine)
80100
- [015 - EMR](https://github.com/awslabs/aws-data-wrangler/blob/master/tutorials/015%20-%20EMR.ipynb)
81101
- [016 - EMR & Docker](https://github.com/awslabs/aws-data-wrangler/blob/master/tutorials/016%20-%20EMR%20%26%20Docker.ipynb)
82102
- [017 - Partition Projection](https://github.com/awslabs/aws-data-wrangler/blob/master/tutorials/017%20-%20Partition%20Projection.ipynb)
103+
- [018 - QuickSight](https://github.com/awslabs/aws-data-wrangler/blob/master/tutorials/018%20-%20QuickSight.ipynb)
83104
- [**API Reference**](https://aws-data-wrangler.readthedocs.io/en/latest/api.html)
84105
- [Amazon S3](https://aws-data-wrangler.readthedocs.io/en/latest/api.html#amazon-s3)
85106
- [AWS Glue Catalog](https://aws-data-wrangler.readthedocs.io/en/latest/api.html#aws-glue-catalog)
86107
- [Amazon Athena](https://aws-data-wrangler.readthedocs.io/en/latest/api.html#amazon-athena)
87108
- [Databases (Redshift, PostgreSQL, MySQL)](https://aws-data-wrangler.readthedocs.io/en/latest/api.html#databases-redshift-postgresql-mysql)
88109
- [EMR Cluster](https://aws-data-wrangler.readthedocs.io/en/latest/api.html#emr-cluster)
89110
- [CloudWatch Logs](https://aws-data-wrangler.readthedocs.io/en/latest/api.html#cloudwatch-logs)
111+
- [QuickSight](https://aws-data-wrangler.readthedocs.io/en/latest/api.html#quicksight)
90112
- [**License**](https://github.com/awslabs/aws-data-wrangler/blob/master/LICENSE)
91113
- [**Contributing**](https://github.com/awslabs/aws-data-wrangler/blob/master/CONTRIBUTING.md)
92114
- [**Legacy Docs** (pre-1.0.0)](https://aws-data-wrangler.readthedocs.io/en/legacy/)

awswrangler/quicksight/_create.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353

5454

5555
def _generate_principal(user_name: str, account_id: str, region: str) -> str:
56-
return f"arn:aws:quicksight:{region}:{account_id}:user/default/{user_name}"
56+
user_name = user_name if "/" in user_name else f"default/{user_name}"
57+
return f"arn:aws:quicksight:{region}:{account_id}:user/{user_name}"
5758

5859

5960
def _generate_permissions(
@@ -273,6 +274,8 @@ def create_athena_dataset(
273274
raise exceptions.InvalidArgument("You must pass a not None data_source_name or data_source_arn argument.")
274275
if ((database is None) and (table is None)) and (sql is None):
275276
raise exceptions.InvalidArgument("You must pass database/table OR sql argument.")
277+
if (database is not None) and (sql is not None):
278+
raise exceptions.InvalidArgument("If you provide sql argument, please include the database name inside the sql statement. Do NOT pass in with database argument.")
276279
session: boto3.Session = _utils.ensure_session(session=boto3_session)
277280
client: boto3.client = _utils.client(service_name="quicksight", session=session)
278281
if account_id is None:
@@ -363,8 +366,8 @@ def create_ingestion(
363366
364367
Returns
365368
-------
366-
Current status
367-
'INITIALIZED'|'QUEUED'|'RUNNING'|'FAILED'|'COMPLETED'|'CANCELLED'
369+
str
370+
Ingestion ID
368371
369372
Examples
370373
--------
@@ -384,4 +387,4 @@ def create_ingestion(
384387
response: Dict[str, Any] = client.create_ingestion(
385388
DataSetId=dataset_id, IngestionId=ingestion_id, AwsAccountId=account_id
386389
)
387-
return response["IngestionStatus"]
390+
return response["IngestionId"]

docs/source/index.rst

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,30 @@ Quick Start
2626
df = wr.athena.read_sql_query("SELECT * FROM my_table", database="my_db")
2727
2828
# Getting Redshift connection (SQLAlchemy) from Glue Catalog Connections
29-
engine = wr.catalog.get_engine("my-redshift-connection")
30-
3129
# Retrieving the data from Amazon Redshift Spectrum
30+
engine = wr.catalog.get_engine("my-redshift-connection")
3231
df = wr.db.read_sql_query("SELECT * FROM external_schema.my_table", con=engine)
3332
33+
# Creating QuickSight Data Source and Dataset to reflect our new table
34+
wr.quicksight.create_athena_data_source("athena-source", allowed_to_manage=["username"])
35+
wr.quicksight.create_athena_dataset(
36+
name="my-dataset",
37+
database="my_db",
38+
table="my_table",
39+
data_source_name="athena-source",
40+
allowed_to_manage=["username"]
41+
)
42+
43+
# Getting MySQL connection (SQLAlchemy) from Glue Catalog Connections
44+
# Load the data into MySQL
45+
engine = wr.catalog.get_engine("my-mysql-connection")
46+
wr.db.to_sql(df, engine, schema="test", name="my_table")
47+
48+
# Getting PostgreSQL connection (SQLAlchemy) from Glue Catalog Connections
49+
# Load the data into PostgreSQL
50+
engine = wr.catalog.get_engine("my-postgresql-connection")
51+
wr.db.to_sql(df, engine, schema="test", name="my_table")
52+
3453
Read The Docs
3554
-------------
3655

0 commit comments

Comments
 (0)