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: LICENSE
+14Lines changed: 14 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -7,3 +7,17 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
7
7
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
8
9
9
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
+
11
+
12
+
The python package is a derivative of the original Juia package whose license is reproduced below.
13
+
14
+
15
+
The FunSQL.jl package is licensed under the MIT "Expat" License:
16
+
17
+
Copyright (c) 2021: Clark C. Evans and Kyrylo Simonov.
18
+
19
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
20
+
21
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
22
+
23
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
`funsql` is a python library to write SQL queries in a way that is more composable.
8
8
9
-
This implementation closely follows the original Julia library [FunSQL.jl](https://github.com/MechanicalRabbit/FunSQL.jl/). Thanks to the original authors, Clark Evans and Kyrylo Simonov, who have been refining the idea for some time; you should check their previous work [here](https://querycombinators.org/).
9
+
SQL is tricky to write in a modular fashion since it is a DSL with its own grammar. The straightforward way to compose SQL query fragments then must rely on string interpolation/concatenation, extended with a templating language like Jinja. FunSQL exposes the full expressive power of SQL by implementing the SQL verbs _(FROM, WHERE, GROUP BY, ...)_ as regular python objects with compositional semantics. This approach is particularly useful for building applications that programmatically construct SQL queries.
10
10
11
-
The original project does a very good job of motivating the library. The python port retains a similar API, so there is little point repeating it.
2. A [presentation](https://www.youtube.com/watch?v=rGWwmuvRUYk) from JuliaCon
11
+
This implementation closely follows the original Julia library [FunSQL.jl](https://github.com/MechanicalRabbit/FunSQL.jl/). Thanks to the original authors, Clark Evans and Kyrylo Simonov, who have been refining the idea for some time; you should check their previous work [here](https://querycombinators.org/). Here is a [presentation](https://www.youtube.com/watch?v=rGWwmuvRUYk) talking about `FunSQL.jl` from Juliacon.
14
12
15
-
Below are some notes about how to use the python library, and my understanding of how FunSQL works.
13
+
Please continue below for notes on how to use the python library, and how FunSQL works.
16
14
17
-
### Table of Contents
15
+
<br/>
16
+
17
+
## Contents
18
18
19
19
-[Example](#example)
20
20
-[Usage](#usage)
@@ -43,13 +43,15 @@ _When was the last time each person born between 1930 and 1940 and living in Ill
FunSQL models the SQL semantics as a set of operations on tabular data. SQL clauses like `FROM`, `WHERE`, and `JOIN` are represented using instances of `From`, `Where`, and `Join` classes, and they are applied in sequence by connecting them with the `>>` operator. Note the absence of a FunSQL counterpart to nested `SELECT` clauses; when necessary, FunSQL automatically adds nested subqueries and
@@ -112,7 +113,7 @@ Scalar expressions are represented using:
112
113
113
114
FunSQL queries and their intermediate components are first-class python objects. So, they can be constructed independently, passed around as values, and freely composed together.
114
115
115
-
You'd also note writing expressions isn't particularly convenient; `Fun("between", Get.year_of_birth, 1930, 1940)` is too verbose for a data manipulation DSL. While part of the reason is, operator overloading might surface bugs I haven't thought through, it also illustrates the usefulness of FunSQL being just a python library; you can build your own abstractions.
116
+
You'd also note writing expressions isn't particularly convenient; `Fun("between", Get.year_of_birth, 1930, 1940)` is too verbose for a data manipulation DSL. While part of the reason is, operator overloading might surface bugs I haven't thought through, it also illustrates the usefulness of FunSQL being just a python library; you can build your own abstractions!
116
117
117
118
<br>
118
119
@@ -143,17 +144,10 @@ def get_stats(col):
143
144
144
145
## Usage
145
146
146
-
The `docs` directory has examples on how to use the library.
147
-
148
-
*`usage-guide.ipynb` - Introduces the verbs available in FunSQL, and how to assmeble queries using them.
149
-
150
-
*`using-nodes.ipynb` - This is the user facing API, and adds more detail about each FunSQL node.
147
+
To get started, please go through the [user guide](https://nbviewer.ipython.org/github/ananis25/funsql-python/blob/main/docs/usage-guide.ipynb). The FunSQL equivalents for the available SQL expressions are documented [here](https://nbviewer.ipython.org/github/ananis25/funsql-python/blob/main/docs/tests/using-nodes.ipynb).
151
148
152
-
*`using-clauses.ipynb` - FunSQL compiles the tree of SQL nodes to something close to the lexical structure of SQL, called clause objects. These directly translate to SQL text, only abstracting over spaces and dialect specific punctuation. When projects like [Substrait](https://substrait.io/) are further along, might be a good idea to use that as a backend instead.
149
+
The [funsql-examples](https://github.com/ananis25/funsql-examples/) repository adds examples of queries/projects written using FunSQL.
153
150
154
-
The [funsql-examples](https://github.com/ananis25/funsql-examples/) repository has more examples of queries/projects written using FunSQL.
155
-
156
-
<br>
157
151
158
152
## Concept
159
153
@@ -174,7 +168,6 @@ Note that we join the person records with the visits records already grouped by
174
168
175
169
The `docs` directory has more notes on how the compiler works, and the debugging output for some sample queries.
176
170
177
-
<br>
178
171
179
172
## More notes
180
173
@@ -253,7 +246,6 @@ The FunSQL python library doesn't have any dependencies. Install this library us
*`usage-guide.ipynb` - Introduces the verbs available in FunSQL, and how to assmeble queries using them.
4
+
5
+
*`compiler-internals.md` - Scattered notes on how the FunSQL compiler works.
6
+
7
+
### Tests
8
+
9
+
These notebooks document the full FunSQL API.
10
+
11
+
*`tests/using-nodes.ipynb` - This is the user facing API, and adds more detail about each FunSQL node.
12
+
13
+
*`tests/using-clauses.ipynb` - FunSQL compiles the tree of SQL nodes to something close to the lexical structure of SQL, called clause objects. These directly translate to SQL text, only abstracting over spaces and dialect specific punctuation. When projects like [Substrait](https://substrait.io/) are further along, might be a good idea to use that as a backend instead.
14
+
15
+
### Debugging
16
+
17
+
This directory stores the compiler output at different stages for some typical queries.
0 commit comments