You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/usage.md
+42-54Lines changed: 42 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -453,6 +453,7 @@ The `to_sql` API takes in PyDough code and transforms it into SQL query text wit
453
453
-`metadata`: the PyDough knowledge graph to use for the conversion (if omitted, `pydough.active_session.metadata` is used instead).
454
454
-`config`: the PyDough configuration settings to use for the conversion (if omitted, `pydough.active_session.config` is used instead).
455
455
-`database`: the database context to use for the conversion (if omitted, `pydough.active_session.database` is used instead). The database context matters because it controls which SQL dialect is used for the translation.
456
+
-`session`: a PyDough session object which, if provided, is used instead of `pydough.active_session` or the `metadata` / `config` / `database` arguments. Note: this argument cannot be used alongside those arguments.
456
457
457
458
Below is an example of using `pydough.to_sql` and the output (the SQL output may be outdated if PyDough's SQL conversion process has been updated):
See the [demo notebooks](../demos/README.md) for more instances of how to use the `to_sql` API.
@@ -506,6 +495,7 @@ The `to_df` API does all the same steps as the [`to_sql` API](#pydoughto_sql), b
506
495
-`metadata`: the PyDough knowledge graph to use for the conversion (if omitted, `pydough.active_session.metadata` is used instead).
507
496
-`config`: the PyDough configuration settings to use for the conversion (if omitted, `pydough.active_session.config` is used instead).
508
497
-`database`: the database context to use for the conversion (if omitted, `pydough.active_session.database` is used instead). The database context matters because it controls which SQL dialect is used for the translation.
498
+
-`session`: a PyDough session object which, if provided, is used instead of `pydough.active_session` or the `metadata` / `config` / `database` arguments. Note: this argument cannot be used alongside those arguments.
509
499
-`display_sql`: displays the sql before executing in a logger.
510
500
511
501
Below is an example of using `pydough.to_df` and the output, attached to a sqlite database containing data for the TPC-H schema:
@@ -644,41 +634,35 @@ The value of `sql` is the following SQL query text as a Python string:
@@ -716,27 +700,27 @@ The value of `sql` is the following SQL query text as a Python string:
716
700
```sql
717
701
WITH _s1 AS (
718
702
SELECT
719
-
COALESCE(SUM(o_totalprice), 0) AS total,
703
+
o_custkey,
720
704
COUNT(*) AS n_rows,
721
-
o_custkey
705
+
SUM(o_totalprice) AS sum_o_totalprice
722
706
FROMmain.orders
723
707
WHERE
724
-
o_orderdate <'1997-01-01'
725
-
AND o_orderdate >='1996-01-01'
708
+
o_orderdate <CAST('1997-01-01'ASDATE)
709
+
AND o_orderdate >=CAST('1996-01-01'ASDATE)
726
710
AND o_orderpriority ='1-URGENT'
727
711
AND o_totalprice >100000
728
712
GROUP BY
729
-
o_custkey
713
+
1
730
714
)
731
715
SELECT
732
716
customer.c_nameAS name,
733
717
_s1.n_rowsAS n_orders,
734
-
_s1.total
718
+
_s1.sum_o_totalpriceAStotal
735
719
FROMmain.customerAS customer
736
720
JOIN _s1 AS _s1
737
721
ON_s1.o_custkey=customer.c_custkey
738
722
ORDER BY
739
-
totalDESC
723
+
3DESC
740
724
```
741
725
742
726
<!-- TOC --><aname="exploration-apis"></a>
@@ -804,7 +788,9 @@ The `explain` API is a more generic explanation interface that can be called on
804
788
- A specific property within a specific collection within a metadata graph object (can be accessed as `graph["collection_name"]["property_name"]`)
805
789
- The PyDough code for a collection that could have `to_sql` or `to_df` called on it.
806
790
807
-
The `explain` API also has an optional `verbose` argument (default=False) that enables displaying additional information.
791
+
The `explain` API has the following optional arguments:
792
+
*`verbose` (default False): specifies whether to include a more detailed explanation, as opposed to a more compact summary.
793
+
*`session` (default None): if provided, specifies what configs etc. to use when explaining PyDough code objects (if not provided, uses `pydough.active_session`).
808
794
809
795
Below are examples of each of these behaviors, using a knowledge graph for the TPCH schema.
810
796
@@ -1022,7 +1008,9 @@ The `explain` API is limited in that it can only be called on complete PyDough c
1022
1008
1023
1009
To handle cases where you need to learn about a term within a collection, you can use the `explain_term` API. The first argument to `explain_term` is PyDough code for a collection, which can have `explain` called on it, and the second is PyDough code for a term that can be evaluated within the context of that collection (e.g. a scalar term of the collection, or one of its sub-collections).
1024
1010
1025
-
The `explain_term` API also has a `verbose` keyword argument (default False) to specify whether to include a more detailed explanation, as opposed to a more compact summary.
1011
+
The `explain_term` API has the following optional arguments:
1012
+
*`verbose` (default False): specifies whether to include a more detailed explanation, as opposed to a more compact summary.
1013
+
*`session` (default None): if provided, specifies what configs etc. to use when explaining certain terms (if not provided, uses `pydough.active_session`).
1026
1014
1027
1015
Below are examples of using `explain_term`, using a knowledge graph for the TPCH schema. For each of these examples, `european_countries` is the "context" collection, which could have `to_sql` or `to_df` called on it, and `term` is the term being explained with regards to `european_countries`.
0 commit comments