Commit 5331862
authored
Expose ProllyTree SQL API to Python and Add Chronological LangGraph TA-RAG Example (#87)
* Expose ProllyTree SQL API to Python
Summary
This PR adds complete SQL functionality to the ProllyTree Python bindings, allowing users to
execute SQL queries on the versioned key-value store through a new ProllySQLStore class.
Changes
Core Implementation
- Added ProllySQLStore Python class (src/python.rs)
- Full SQL query execution via GlueSQL
- Multiple output formats: dict, tuples, JSON, CSV
- Helper methods for common operations (create_table, insert, select)
- Transaction support with commit functionality
Python Module Updates
- Updated python/prollytree/__init__.py
- Conditionally exports ProllySQLStore when SQL feature is available
- Graceful fallback when SQL support is not compiled
Build System Enhancements
- Enhanced python/build_python.sh
- Added --with-sql flag to build with SQL support
- Added --all-features flag for complete feature set
- Added --help documentation
- Automatic SQL functionality testing when built with SQL feature
- Updated pyproject.toml
- Added SQL feature to default maturin build configuration
- Allows override via command-line flags
Storage Layer
- Added current_commit() method (src/git/versioned_store.rs)
- Enables retrieving the current HEAD commit ID
- Required for SQL commit operations
Documentation & Examples
- Created comprehensive SQL example (python/examples/sql_example.py)
- Demonstrates table creation, data insertion, and querying
- Shows all output formats (dict, tuples, JSON, CSV)
- Examples of JOINs, GROUP BY, subqueries
- UPDATE and DELETE operations
- Added SQL test suite (python/tests/test_sql.py)
- Tests for all SQL operations
- Output format validation
- Complex query testing
- Static method testing
API Usage
from prollytree import ProllySQLStore
# Initialize store (requires git repository)
store = ProllySQLStore(path)
# Create table
store.create_table("users", [("id", "INTEGER"), ("name", "TEXT")])
# Insert data
store.insert("users", [[1, "Alice"], [2, "Bob"]])
# Query with different formats
results = store.execute("SELECT * FROM users") # Returns list of dicts
labels, rows = store.execute("SELECT * FROM users", format="tuples")
json_str = store.execute("SELECT * FROM users", format="json")
csv_str = store.execute("SELECT * FROM users", format="csv")
# Helper methods
store.select("users", columns=["name"], where_clause="id > 1")
# Execute multiple queries
store.execute_many([query1, query2, query3])
# Commit changes
store.commit("Added user data")
Building with SQL Support
# Build with SQL support
./python/build_python.sh --with-sql
# Build and install
./python/build_python.sh --with-sql --install
# Run example
python3 python/examples/sql_example.py
Testing
- ✅ All SQL operations tested and working
- ✅ Example script runs successfully
- ✅ Multiple output formats validated
- ✅ Complex queries (JOIN, GROUP BY) functional
Breaking Changes
None - SQL support is optional and doesn't affect existing functionality.
Notes
- SQL functionality requires git repository initialization
- Based on GlueSQL, some SQL features may have limitations (e.g., no DISTINCT support)
- Performance is optimized for versioned operations rather than pure SQL speed
* add sql example to run script
* rename langgraph example
* add langgraph_chronological.py
* add loop
* add more profiles to the example
* remove unused codes
* improve run_example.sh1 parent fea792b commit 5331862
10 files changed
Lines changed: 2394 additions & 17 deletions
File tree
- python
- examples
- prollytree
- tests
- src
- git
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
16 | 24 | | |
17 | 25 | | |
18 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
19 | 48 | | |
20 | 49 | | |
21 | 50 | | |
| |||
27 | 56 | | |
28 | 57 | | |
29 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
30 | 83 | | |
31 | | - | |
32 | | - | |
| 84 | + | |
| 85 | + | |
33 | 86 | | |
34 | 87 | | |
35 | 88 | | |
| |||
54 | 107 | | |
55 | 108 | | |
56 | 109 | | |
57 | | - | |
| 110 | + | |
58 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
59 | 141 | | |
60 | 142 | | |
61 | 143 | | |
62 | 144 | | |
| 145 | + | |
| 146 | + | |
63 | 147 | | |
64 | 148 | | |
65 | 149 | | |
66 | 150 | | |
67 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
68 | 155 | | |
69 | 156 | | |
70 | 157 | | |
| |||
0 commit comments