Skip to content

Commit

Permalink
Update docs for append & merge operator changes (#474)
Browse files Browse the repository at this point in the history
- Update the docs REFERENCE.md and TUTORIAL.md to make sure the examples
- Run the example DAG successfully from tutorial.
  • Loading branch information
sunank200 authored Jun 20, 2022
1 parent 514d80b commit 8f0529d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
23 changes: 10 additions & 13 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,9 @@ The `aql.append` function merges tables assuming that there are no conflicts. Yo

```python
foo = aql.append(
append_table=Table("some_table", "snowflake_default"),
main_table=Table("main_table", "snowflake_default"),
source_table=Table("some_table", "snowflake_default"),
target_table=Table("target_table", "snowflake_default"),
columns=["Bedrooms", "Bathrooms"],
casted_columns={"Age": "INTEGER"},
)
```

Expand All @@ -354,22 +353,20 @@ Postgres:
```python
a = aql.merge(
target_table=Table("target_table", "postgres_default"),
merge_table=Table("merge_table", "postgres_default"),
merge_keys=["list", "sell"],
target_columns=["list", "sell", "taxes"],
merge_columns=["list", "sell", "age"],
conflict_strategy="update",
source_table=Table("source_table", "postgres_default"),
target_conflict_columns=["list", "sell"],
columns={"list": "list", "sell": "sell", "age": "taxes"},
if_conflicts="update",
)
```
Snowflake:
```python
a = aql.merge(
target_table=Table("target_table", "snowflake_default"),
merge_table=Table("merge_table", "snowflake_default"),
merge_keys={"list": "list", "sell": "sell"},
target_columns=["list", "sell"],
merge_columns=["list", "sell"],
conflict_strategy="ignore",
source_table=Table("source_table", "snowflake_default"),
target_conflict_columns={"list": "list", "sell": "sell"},
columns=["list", "sell"],
if_conflicts="ignore",
)
```

Expand Down
26 changes: 12 additions & 14 deletions TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +155,22 @@ We'll create some auxiliary tables in Snowflake and populate with a small amount

```sql
CREATE OR REPLACE TABLE customers_table (customer_id CHAR(10), customer_name VARCHAR(100), type VARCHAR(10) )
CREATE OR REPLACE TABLE customers_table (customer_id CHAR(10), customer_name VARCHAR(100), type VARCHAR(10) );
INSERT INTO customers_table (CUSTOMER_ID, CUSTOMER_NAME,TYPE) VALUES ('CUST1','NAME1','TYPE1'),('CUST2','NAME2','TYPE1'),('CUST3','NAME3','TYPE2')
INSERT INTO customers_table (CUSTOMER_ID, CUSTOMER_NAME,TYPE) VALUES ('CUST1','NAME1','TYPE1'),('CUST2','NAME2','TYPE1'),('CUST3','NAME3','TYPE2');
```

* Create and populate a reporting table into which we'll merge our transformed data:
```sql
CREATE OR REPLACE TABLE reporting_table (
CUSTOMER_ID CHAR(10), CUSTOMER_NAME VARCHAR(100), ORDER_ID CHAR(10), PURCHASE_DATE DATE, AMOUNT FLOAT, TYPE CHAR(10));
CUSTOMER_ID CHAR(30), CUSTOMER_NAME VARCHAR(100), ORDER_ID CHAR(10), PURCHASE_DATE DATE, AMOUNT FLOAT, TYPE CHAR(10));
INSERT INTO reporting_table (CUSTOMER_ID, CUSTOMER_NAME, ORDER_ID, PURCHASE_DATE, AMOUNT, TYPE) VALUES
('INCORRECT_CUSTOMER_ID','INCORRECT_CUSTOMER_NAME','ORDER2','2/2/2022',200,'TYPE1'),
('CUST3','NAME3','ORDER3','3/3/2023',300,'TYPE2'),
('CUST4','NAME4','ORDER4','4/4/2022',400,'TYPE2')
('CUST4','NAME4','ORDER4','4/4/2022',400,'TYPE2');
```
***
# Simple ETL workflow
Expand Down Expand Up @@ -252,11 +252,10 @@ with dag:
name=SNOWFLAKE_REPORTING,
conn_id=SNOWFLAKE_CONN_ID,
),
merge_table=joined_data,
merge_columns=["customer_id", "customer_name"],
target_columns=["customer_id", "customer_name"],
merge_keys={"order_id": "order_id"},
conflict_strategy="update",
source_table=joined_data,
target_conflict_columns=["order_id"],
columns=["customer_id", "customer_name"],
if_conflicts="update",
)
purchase_dates = transform_dataframe(reporting_table)
Expand Down Expand Up @@ -330,11 +329,10 @@ reporting_table = aql.merge(
name=SNOWFLAKE_REPORTING,
conn_id=SNOWFLAKE_CONN_ID,
),
merge_table=joined_data,
merge_columns=["customer_id", "customer_name"],
target_columns=["customer_id", "customer_name"],
merge_keys={"order_id": "order_id"},
conflict_strategy="update",
source_table=joined_data,
target_conflict_columns=["order_id"],
columns=["customer_id", "customer_name"],
if_conflicts="update",
)
```

Expand Down

0 comments on commit 8f0529d

Please sign in to comment.