Skip to content

Commit 818287a

Browse files
committed
fix readme
1 parent ad6245f commit 818287a

File tree

9 files changed

+840
-818
lines changed

9 files changed

+840
-818
lines changed

LICENSE

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,17 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
77
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
88

99
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.

README.md

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
[![PyPI](https://img.shields.io/pypi/v/funsql-python.svg)](https://pypi.org/project/funsql-python/)
44
[![Changelog](https://img.shields.io/github/v/release/ananis25/funsql-python?include_prereleases&label=changelog)](https://github.com/ananis25/funsql-python/releases)
5-
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/ananis25/funsql-python/blob/main/LICENSE)
5+
[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/ananis25/funsql-python/blob/main/LICENSE)
66

77
`funsql` is a python library to write SQL queries in a way that is more composable.
88

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.
1010

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.
12-
1. [Why FunSQL?](https://mechanicalrabbit.github.io/FunSQL.jl/stable/guide/#Why-FunSQL?)
13-
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.
1412

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.
1614

17-
### Table of Contents
15+
<br/>
16+
17+
## Contents
1818

1919
- [Example](#example)
2020
- [Usage](#usage)
@@ -43,13 +43,15 @@ _When was the last time each person born between 1930 and 1940 and living in Ill
4343
<details open><summary>Python Code</summary>
4444

4545
```python
46+
# define the source tables
4647
location = SQLTable(S.location, [S.location_id, S.city, S.state])
4748
person = SQLTable(S.person, [S.person_id, S.year_of_birth, S.location_id])
4849
visit_occurence = SQLTable(
4950
S.visit_occurence,
5051
[S.visit_occurence_id, S.person_id, S.visit_start_date, S.visit_end_date],
5152
)
5253

54+
# construct queries incrementally
5355
people_in_grp = From(person) >> Where(Fun("between", Get.year_of_birth, 1930, 1940))
5456
people_in_il = people_in_grp >> Join(
5557
From(location) >> Where(Fun("=", Get.state, "IL")) >> As(S.loc),
@@ -98,7 +100,6 @@ LEFT JOIN (
98100
```
99101
</details>
100102

101-
<br>
102103
<br>
103104

104105
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:
112113

113114
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.
114115

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!
116117

117118
<br>
118119

@@ -143,17 +144,10 @@ def get_stats(col):
143144

144145
## Usage
145146

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).
151148

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.
153150

154-
The [funsql-examples](https://github.com/ananis25/funsql-examples/) repository has more examples of queries/projects written using FunSQL.
155-
156-
<br>
157151

158152
## Concept
159153

@@ -174,7 +168,6 @@ Note that we join the person records with the visits records already grouped by
174168

175169
The `docs` directory has more notes on how the compiler works, and the debugging output for some sample queries.
176170

177-
<br>
178171

179172
## More notes
180173

@@ -253,7 +246,6 @@ The FunSQL python library doesn't have any dependencies. Install this library us
253246

254247
$ pip install funsql-python
255248

256-
<br>
257249

258250
## Development
259251

docs/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Contents
2+
3+
* `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.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)