r''' Run a SQL query on Pathway Live Data Framework tables. Args: query: the SQL query to execute. kwargs: the association name: table used for the execution of the SQL query. \ Each name:table pair links a Pathway Live Data Framework table to a table name used i
(query: str, **kwargs: table.Table)
| 5 | |
| 6 | @check_arg_types |
| 7 | def sql(query: str, **kwargs: table.Table) -> table.Table: |
| 8 | r''' |
| 9 | Run a SQL query on Pathway Live Data Framework tables. |
| 10 | |
| 11 | Args: |
| 12 | query: the SQL query to execute. |
| 13 | kwargs: the association name: table used for the execution of the SQL query. \ |
| 14 | Each name:table pair links a Pathway Live Data Framework table to a table name used in the SQL query. |
| 15 | |
| 16 | Example: |
| 17 | |
| 18 | >>> import pathway as pw |
| 19 | >>> t = pw.debug.table_from_markdown( |
| 20 | ... """ |
| 21 | ... A | B |
| 22 | ... 1 | 2 |
| 23 | ... 4 | 3 |
| 24 | ... 4 | 7 |
| 25 | ... """ |
| 26 | ... ) |
| 27 | >>> ret = pw.sql("SELECT * FROM tab WHERE A<B", tab=t) |
| 28 | >>> pw.debug.compute_and_print(ret, include_id=False) |
| 29 | A | B |
| 30 | 1 | 2 |
| 31 | 4 | 7 |
| 32 | |
| 33 | Supported SQL keywords and operations: |
| 34 | SELECT, WHERE, boolean expressions, arithmetic operations, \ |
| 35 | GROUP BY, HAVING, AS (alias), UNION, INTERSECTION, JOIN, and WITH. |
| 36 | |
| 37 | Table and column names are case-sensitive. |
| 38 | |
| 39 | Specificities of the Pathway Live Data Framework: |
| 40 | - `id` is a reserved key word for columns, every Pathway Live Data Framework table has a special column \ |
| 41 | `id`. This column is not captured by `*` expressions in SQL. |
| 42 | - Order of columns might not be preserved with respect to SELECT query. |
| 43 | - Pathway Live Data Framework reducers (pw.count, pw.sum, etc.) aggregate over None values, while SQL \ |
| 44 | aggregation functions (COUNT, SUM, etc.) skip NULL values. |
| 45 | - UNION requires matching column names. |
| 46 | - INTERSECT requires matching column names. |
| 47 | |
| 48 | Limited support: |
| 49 | - Subqueries are supported but fragile -- they depend on a set of query rewriting routines \ |
| 50 | from the `sqlglot <https://github.com/tobymao/sqlglot>`_ library. |
| 51 | - Additionally, using the `id` column in subqueries is fragile. |
| 52 | - LIKE, ANY, ALL, EXISTS are not supported, or only supported in a very weak state. |
| 53 | |
| 54 | Unsupported operations: |
| 55 | - ordering operations: ORDER BY, LIMIT, SELECT TOP |
| 56 | - INSERT INTO (Pathway Live Data Framework tables are immutable) |
| 57 | - The Pathway Live Data Framework does not support anonymous columns: they might work but |
| 58 | we do not guarantee their behavior. |
| 59 | - INTERSECT does not support INTERSECT ALL. |
| 60 | - COALESCE, IFNULL are not supported. |
| 61 | - FULL JOIN and NATURAL JOIN are not supported. |
| 62 | - CAST is not supported |
| 63 | |
| 64 | ''' |
nothing calls this directly
no test coverage detected