streaming-sql-engine 0.1.23__tar.gz → 0.1.24__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {streaming_sql_engine-0.1.23/streaming_sql_engine.egg-info → streaming_sql_engine-0.1.24}/PKG-INFO +160 -170
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/README.md +159 -169
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/engine.py +2 -2
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/executor.py +2 -2
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/pyproject.toml +2 -2
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/setup.py +1 -1
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24/streaming_sql_engine.egg-info}/PKG-INFO +160 -170
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/streaming_sql_engine.egg-info/SOURCES.txt +2 -1
- streaming_sql_engine-0.1.24/tests/test_readme_cases.py +923 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/DEPLOYMENT.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/MANIFEST.in +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/QUICK_DEPLOY.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/QUICK_FIX.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/RELEASE_READINESS_1.0.0.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/__init__.py +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/debug_tests.py +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/APACHE_DRILL_COMPARISON.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/API_JOIN_OPERATIONS.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/ARCHITECTURAL_RECOMMENDATION.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/ARCHITECTURE_DECISION.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/ARCHITECTURE_SYNCED.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/BEST_USE_CASES.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/BETTER_FILTER_APPROACH.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/CARTESIAN_PRODUCTS_CAUSES.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/CHANGES_SUMMARY.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/COMPREHENSIVE_ARTICLE.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/COMPREHENSIVE_DOCUMENTATION.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/DEVELOPER_GUIDE.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/DUCKDB_COMPARISON.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/ENGINE_OPTIONS_REFERENCE.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/FINAL_IMPLEMENTATION_RECOMMENDATIONS.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/FINAL_RECOMMENDATION.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/FIRST_MATCH_ONLY_WARNINGS.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/HANDLING_DUPLICATES_WITHOUT_CARTESIAN.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/HOW_PROTOCOL_DETECTION_WORKS.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/HOW_TO_ADD_TO_PROJECT.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/INSTALLATION.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/JSONL_EXECUTOR_ANALYSIS.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/JSONL_EXECUTOR_REMOVED.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/LIBRARY_DOCUMENTATION.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/MEDIUM_ARTICLE.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/MEDIUM_ARTICLE_SIMPLIFIED.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/MIGRATION_GUIDE.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/MMAP_WITHOUT_POLARS_SLOW.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/MOST_STABLE_AND_PERFORMANT.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/MULTI_SOURCE_EXAMPLE_README.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/MYSQL_USAGE.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/OPTIMIZATIONS_BREAKDOWN.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/OPTIMIZATIONS_NOT_DATABASE_ONLY.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/OPTIMIZATIONS_VS_POLARS.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/OPTIMIZER_AUTOMATED.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/PERFORMANCE.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/PERFORMANCE_COMPARISON.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/POLARS_AND_MMAP_GUIDE.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/POLARS_VS_POLARS_MMAP.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/PROTOCOL_AND_OPTIMIZATIONS_EXPLAINED.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/PROTOCOL_EXPLANATION.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/PUBLISHING.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/PYPI_CHECKLIST.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/QUICK_PUBLISH.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/QUICK_START.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/SIMPLE_PROTOCOL_GUIDE.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/SIMPLE_SOURCE_FUNCTIONS.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/SOURCE_COMBINATIONS_GUIDE.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/TECHNICAL_DOCUMENTATION.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/USER_GUIDE.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/WHAT_IS_WHERE_TO_PARAMS.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/WHEN_POLARS_IS_USED.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/WHERE_POLARS_IS_USED.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/WHY_API_CONVERTER_NEEDED.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/WHY_MANUAL_PARSING.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/WHY_ORIGINAL_IS_FASTER.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/WHY_PROTOCOL_IN_SOURCES.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/documentation/XML_MONGO_USE_CASE.md +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/evaluator.py +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/mmap_index.py +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/operators.py +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/operators_mmap.py +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/operators_polars.py +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/optimizer.py +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/parser.py +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/planner.py +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/polars_expression_translator.py +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/polars_operators.py +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/pre_release_test.py +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/protocol_helpers.py +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/quick_test.py +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/requirements.txt +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/setup.cfg +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/streaming_sql_engine.egg-info/dependency_links.txt +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/streaming_sql_engine.egg-info/requires.txt +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/streaming_sql_engine.egg-info/top_level.txt +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/test_full_pipeline.py +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/test_polars_fixes.py +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/test_polars_schema_fix.py +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/test_where_debug.py +0 -0
- {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.24}/tests/test_engine_options.py +0 -0
{streaming_sql_engine-0.1.23/streaming_sql_engine.egg-info → streaming_sql_engine-0.1.24}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: streaming-sql-engine
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.24
|
|
4
4
|
Summary: A lightweight SQL execution engine for streaming row-by-row queries with joins across multiple data sources
|
|
5
5
|
Home-page: https://github.com/Ierofantis/streaming-sql-engine/tree/master
|
|
6
6
|
Author: Theodore Pantazopoulo
|
|
@@ -46,11 +46,9 @@ Dynamic: requires-python
|
|
|
46
46
|
|
|
47
47
|
# Join Data from Anywhere: The Streaming SQL Engine That Bridges Databases, APIs, and Files
|
|
48
48
|
|
|
49
|
-
## How I Built a Python Library That Lets You Join MySQL, PostgreSQL, MongoDB, REST APIs, and Files in a Single SQL Query
|
|
50
|
-
|
|
51
49
|
---
|
|
52
50
|
|
|
53
|
-
|
|
51
|
+
Have you ever needed to join data from a MySQL database with a PostgreSQL database, a MongoDB collection, and a REST API — all in one query? Traditional databases can't do this. That's why I built the Streaming SQL Engine.\_
|
|
54
52
|
|
|
55
53
|
---
|
|
56
54
|
|
|
@@ -215,74 +213,35 @@ The engine follows a **pipeline architecture** inspired by database query execut
|
|
|
215
213
|
|
|
216
214
|
The engine uses recursive AST traversal to evaluate expressions:
|
|
217
215
|
|
|
218
|
-
```python
|
|
219
|
-
def evaluate_expression(expr, row):
|
|
220
|
-
"""Recursively evaluate SQL expression against row data"""
|
|
221
|
-
|
|
222
|
-
if isinstance(expr, exp.Column):
|
|
223
|
-
# Column reference: lookup value in row
|
|
224
|
-
return row[expr.sql()]
|
|
225
|
-
|
|
226
|
-
elif isinstance(expr, exp.Literal):
|
|
227
|
-
# Literal value: return as-is
|
|
228
|
-
return expr.this
|
|
229
|
-
|
|
230
|
-
elif isinstance(expr, exp.EQ):
|
|
231
|
-
# Equality: evaluate left and right, compare
|
|
232
|
-
left = evaluate_expression(expr.this, row)
|
|
233
|
-
right = evaluate_expression(expr.expression, row)
|
|
234
|
-
return left == right
|
|
235
|
-
|
|
236
|
-
elif isinstance(expr, exp.GT):
|
|
237
|
-
# Greater than: evaluate and compare
|
|
238
|
-
left = evaluate_expression(expr.this, row)
|
|
239
|
-
right = evaluate_expression(expr.expression, row)
|
|
240
|
-
return left > right
|
|
241
|
-
|
|
242
|
-
# ... handle other operators (AND, OR, NOT, etc.)
|
|
243
|
-
```
|
|
244
|
-
|
|
245
216
|
**Why recursive:** SQL expressions are trees. Recursive evaluation naturally handles nested expressions like `(a > 10 AND b < 20) OR c = 5`.
|
|
246
217
|
|
|
247
218
|
### Join Algorithm Selection
|
|
248
219
|
|
|
249
220
|
**How the engine chooses join algorithms:**
|
|
250
221
|
|
|
222
|
+
The engine follows this priority order when selecting a join algorithm:
|
|
223
|
+
|
|
251
224
|
1. **Check if both sides are sorted** (`ordered_by` metadata)
|
|
252
225
|
|
|
253
|
-
- If yes
|
|
254
|
-
-
|
|
226
|
+
- If yes, use `MergeJoinIterator` (most memory-efficient for sorted data)
|
|
227
|
+
- Only used when `use_polars=False`
|
|
255
228
|
|
|
256
229
|
2. **Check if right side is a file** (`filename` metadata)
|
|
257
230
|
|
|
258
|
-
- If yes
|
|
231
|
+
- If yes, use `MmapLookupJoinIterator` (memory-mapped, 90-99% memory reduction)
|
|
232
|
+
- Only used when `use_polars=False`
|
|
259
233
|
|
|
260
234
|
3. **Check if Polars is available** (`use_polars` flag)
|
|
261
|
-
- If yes → Use PolarsLookupJoinIterator (vectorized)
|
|
262
|
-
|
|
263
|
-
**Logic:**
|
|
264
235
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
right_metadata, use_polars):
|
|
268
|
-
# Check for merge join (both sides sorted)
|
|
269
|
-
if left_metadata.get('ordered_by') == left_key and \
|
|
270
|
-
right_metadata.get('ordered_by') == right_key:
|
|
271
|
-
return MergeJoinIterator(left_iterator, right_source_fn, left_key, right_key)
|
|
236
|
+
- If yes, use `PolarsLookupJoinIterator` (vectorized, SIMD-accelerated)
|
|
237
|
+
- Used when `use_polars=True` is explicitly set
|
|
272
238
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
return MmapLookupJoinIterator(left_iterator, right_source_fn,
|
|
276
|
-
right_metadata['filename'], left_key, right_key)
|
|
239
|
+
4. **Default fallback**
|
|
240
|
+
- Use `LookupJoinIterator` (Python hash-based, most compatible)
|
|
277
241
|
|
|
278
|
-
|
|
279
|
-
if use_polars and POLARS_AVAILABLE:
|
|
280
|
-
return PolarsLookupJoinIterator(left_iterator, right_source_fn,
|
|
281
|
-
left_key, right_key)
|
|
242
|
+
**Logic:**
|
|
282
243
|
|
|
283
|
-
|
|
284
|
-
return LookupJoinIterator(left_iterator, right_source_fn, left_key, right_key)
|
|
285
|
-
```
|
|
244
|
+
**Note:** When `use_polars=False` (default), Merge Join and MMAP Join are checked first before falling back to Python Lookup Join. When `use_polars=True` is explicitly set, the engine prioritizes Polars over MMAP and Merge Join.
|
|
286
245
|
|
|
287
246
|
### Protocol-Based Optimization
|
|
288
247
|
|
|
@@ -385,27 +344,7 @@ with open('large_file.jsonl', 'rb') as f:
|
|
|
385
344
|
|
|
386
345
|
**3. First Match Only Optimization**
|
|
387
346
|
|
|
388
|
-
For joins where only the first match matters (prevents Cartesian products)
|
|
389
|
-
|
|
390
|
-
```python
|
|
391
|
-
class LookupJoinIterator:
|
|
392
|
-
def __init__(self, ..., first_match_only=False):
|
|
393
|
-
self.first_match_only = first_match_only
|
|
394
|
-
|
|
395
|
-
def _build_index(self):
|
|
396
|
-
self.index = {}
|
|
397
|
-
for right_row in self.right_source_fn():
|
|
398
|
-
key = right_row[self.right_key]
|
|
399
|
-
if self.first_match_only:
|
|
400
|
-
# Only keep first match per key
|
|
401
|
-
if key not in self.index:
|
|
402
|
-
self.index[key] = right_row
|
|
403
|
-
else:
|
|
404
|
-
# Keep all matches
|
|
405
|
-
if key not in self.index:
|
|
406
|
-
self.index[key] = []
|
|
407
|
-
self.index[key].append(right_row)
|
|
408
|
-
```
|
|
347
|
+
For joins where only the first match matters (prevents Cartesian products).
|
|
409
348
|
|
|
410
349
|
**Why useful:** Prevents Cartesian products when right side has duplicate keys. Significantly reduces output size and processing time.
|
|
411
350
|
|
|
@@ -501,20 +440,20 @@ The engine processes data **row-by-row**, never loading entire tables into memor
|
|
|
501
440
|
|
|
502
441
|
```
|
|
503
442
|
SQL Query
|
|
504
|
-
|
|
505
|
-
Parser
|
|
506
|
-
|
|
507
|
-
Planner
|
|
508
|
-
|
|
509
|
-
Executor
|
|
510
|
-
|
|
443
|
+
|
|
|
444
|
+
Parser -> AST
|
|
445
|
+
|
|
|
446
|
+
Planner -> Logical Plan
|
|
447
|
+
|
|
|
448
|
+
Executor -> Iterator Pipeline
|
|
449
|
+
|
|
|
511
450
|
Results (Generator)
|
|
512
451
|
```
|
|
513
452
|
|
|
514
453
|
**Iterator Pipeline:**
|
|
515
454
|
|
|
516
455
|
```
|
|
517
|
-
ScanIterator
|
|
456
|
+
ScanIterator -> FilterIterator -> JoinIterators -> ProjectIterator -> Results
|
|
518
457
|
```
|
|
519
458
|
|
|
520
459
|
Each iterator processes rows incrementally, enabling true streaming execution. This means:
|
|
@@ -648,12 +587,13 @@ def source(dynamic_where=None):
|
|
|
648
587
|
10-200x faster processing for large datasets using SIMD-accelerated operations:
|
|
649
588
|
|
|
650
589
|
```python
|
|
651
|
-
engine = Engine(
|
|
590
|
+
engine = Engine() # use_polars=False (default)
|
|
652
591
|
|
|
653
|
-
# Automatically uses Polars for:
|
|
654
|
-
# - Vectorized
|
|
655
|
-
# - Vectorized
|
|
656
|
-
# -
|
|
592
|
+
# Automatically uses Polars when available for:
|
|
593
|
+
# - Vectorized joins (PolarsLookupJoinIterator) - when right side >= 10K rows
|
|
594
|
+
# - Vectorized filtering (PolarsBatchFilterIterator) - when expression is translatable
|
|
595
|
+
# - Vectorized projections (PolarsBatchProjectIterator) - batch column selection
|
|
596
|
+
# Falls back to Python iterators if Polars fails or isn't available
|
|
657
597
|
```
|
|
658
598
|
|
|
659
599
|
### 4. Memory-Mapped Joins
|
|
@@ -1146,11 +1086,11 @@ for row in engine.query(query):
|
|
|
1146
1086
|
|
|
1147
1087
|
**Why This Configuration is Best to Start:**
|
|
1148
1088
|
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1089
|
+
- **Most Stable**: Handles mixed data types gracefully
|
|
1090
|
+
- **No Schema Errors**: No type inference issues
|
|
1091
|
+
- **Works Everywhere**: No external dependencies required
|
|
1092
|
+
- **Reliable**: Battle-tested Python code
|
|
1093
|
+
- **Fast for Small-Medium Data**: 0.72s for 10K rows
|
|
1154
1094
|
|
|
1155
1095
|
**Use this when:**
|
|
1156
1096
|
|
|
@@ -1162,7 +1102,7 @@ for row in engine.query(query):
|
|
|
1162
1102
|
|
|
1163
1103
|
---
|
|
1164
1104
|
|
|
1165
|
-
##
|
|
1105
|
+
## Experimenting with Options
|
|
1166
1106
|
|
|
1167
1107
|
Once you're comfortable with the basics, you can experiment with different options to optimize for your specific use case.
|
|
1168
1108
|
|
|
@@ -1182,10 +1122,10 @@ STREAMING SQL ENGINE - DEBUG MODE
|
|
|
1182
1122
|
============================================================
|
|
1183
1123
|
|
|
1184
1124
|
[1/3] PARSING SQL QUERY...
|
|
1185
|
-
|
|
1125
|
+
SQL parsed successfully
|
|
1186
1126
|
|
|
1187
1127
|
[2/3] BUILDING LOGICAL PLAN...
|
|
1188
|
-
|
|
1128
|
+
Logical plan built
|
|
1189
1129
|
|
|
1190
1130
|
[3/3] EXECUTING QUERY...
|
|
1191
1131
|
Using LOOKUP JOIN (building index...)
|
|
@@ -1203,15 +1143,15 @@ engine = Engine(use_polars=True) # Enable Polars for speed
|
|
|
1203
1143
|
|
|
1204
1144
|
**Benefits:**
|
|
1205
1145
|
|
|
1206
|
-
-
|
|
1207
|
-
-
|
|
1208
|
-
-
|
|
1146
|
+
- Faster for large datasets (vectorized operations)
|
|
1147
|
+
- SIMD acceleration
|
|
1148
|
+
- Better for consistent schemas
|
|
1209
1149
|
|
|
1210
1150
|
**Trade-offs:**
|
|
1211
1151
|
|
|
1212
|
-
-
|
|
1213
|
-
-
|
|
1214
|
-
-
|
|
1152
|
+
- Requires data normalization (consistent types)
|
|
1153
|
+
- Can fail on mixed types
|
|
1154
|
+
- Requires Polars dependency
|
|
1215
1155
|
|
|
1216
1156
|
**Example:**
|
|
1217
1157
|
|
|
@@ -1243,14 +1183,14 @@ engine.register("products", source, filename="products.jsonl") # MMAP enabled
|
|
|
1243
1183
|
|
|
1244
1184
|
**Benefits:**
|
|
1245
1185
|
|
|
1246
|
-
-
|
|
1247
|
-
-
|
|
1248
|
-
-
|
|
1186
|
+
- 90-99% memory reduction
|
|
1187
|
+
- Works with files larger than RAM
|
|
1188
|
+
- OS-managed memory mapping
|
|
1249
1189
|
|
|
1250
1190
|
**Trade-offs:**
|
|
1251
1191
|
|
|
1252
|
-
-
|
|
1253
|
-
-
|
|
1192
|
+
- Requires file-based sources
|
|
1193
|
+
- Slower for small files (overhead)
|
|
1254
1194
|
|
|
1255
1195
|
**Example:**
|
|
1256
1196
|
|
|
@@ -1279,14 +1219,14 @@ engine.register("products", source, ordered_by="id") # Merge join enabled
|
|
|
1279
1219
|
|
|
1280
1220
|
**Benefits:**
|
|
1281
1221
|
|
|
1282
|
-
-
|
|
1283
|
-
-
|
|
1284
|
-
-
|
|
1222
|
+
- Lowest memory usage (no index needed)
|
|
1223
|
+
- Fast for sorted data
|
|
1224
|
+
- Streaming algorithm
|
|
1285
1225
|
|
|
1286
1226
|
**Trade-offs:**
|
|
1287
1227
|
|
|
1288
|
-
-
|
|
1289
|
-
-
|
|
1228
|
+
- Requires pre-sorted data
|
|
1229
|
+
- Both tables must be sorted
|
|
1290
1230
|
|
|
1291
1231
|
**Example:**
|
|
1292
1232
|
|
|
@@ -1315,33 +1255,38 @@ engine.register("orders", sorted_orders, ordered_by="user_id")
|
|
|
1315
1255
|
|
|
1316
1256
|
---
|
|
1317
1257
|
|
|
1318
|
-
##
|
|
1258
|
+
## Advanced: Mixing Options
|
|
1259
|
+
|
|
1260
|
+
### Mix 1: MMAP with Polars Index Building (Best for Large Files)
|
|
1319
1261
|
|
|
1320
|
-
|
|
1262
|
+
**Important Note:** When `use_polars=False` (default), the engine uses **MMAP Join** or **Merge Join** when available. When `use_polars=True` is explicitly set, the engine uses **Polars Join** (not MMAP Join).
|
|
1321
1263
|
|
|
1322
|
-
**
|
|
1264
|
+
However, **MMAP can use Polars internally** for faster index building even when `use_polars=False`:
|
|
1323
1265
|
|
|
1324
1266
|
```python
|
|
1325
|
-
engine = Engine(use_polars=
|
|
1267
|
+
engine = Engine(use_polars=False) # MMAP Join will be used
|
|
1326
1268
|
engine.register("products", source, filename="products.jsonl") # MMAP for memory
|
|
1269
|
+
# MMAP will use Polars internally for index building if available
|
|
1327
1270
|
```
|
|
1328
1271
|
|
|
1329
1272
|
**What You Get:**
|
|
1330
1273
|
|
|
1331
|
-
-
|
|
1332
|
-
-
|
|
1333
|
-
-
|
|
1274
|
+
- Low memory (MMAP 90-99% reduction)
|
|
1275
|
+
- Fast index building (if Polars is installed, used internally)
|
|
1276
|
+
- Best balance for large files with memory constraints
|
|
1334
1277
|
|
|
1335
1278
|
**Performance:**
|
|
1336
1279
|
|
|
1337
|
-
- Time: 8-15s for 500MB files
|
|
1280
|
+
- Time: 8-15s for 500MB files (with Polars for index building)
|
|
1338
1281
|
- Memory: 0.01 MB (vs 500MB+ without MMAP)
|
|
1339
1282
|
|
|
1340
1283
|
**When to Use:**
|
|
1341
1284
|
|
|
1342
1285
|
- Large files (> 100MB)
|
|
1343
|
-
- Consistent data types
|
|
1344
1286
|
- Memory-constrained systems
|
|
1287
|
+
- When you want MMAP Join (not Polars Join)
|
|
1288
|
+
|
|
1289
|
+
**Note:** If you set `use_polars=True`, the engine will use **Polars Join** instead of MMAP Join, prioritizing speed over memory efficiency.
|
|
1345
1290
|
|
|
1346
1291
|
---
|
|
1347
1292
|
|
|
@@ -1367,9 +1312,9 @@ engine.register("products", optimized_source)
|
|
|
1367
1312
|
|
|
1368
1313
|
**What You Get:**
|
|
1369
1314
|
|
|
1370
|
-
-
|
|
1371
|
-
-
|
|
1372
|
-
-
|
|
1315
|
+
- Reduced I/O (only reads needed columns)
|
|
1316
|
+
- Faster queries (less data to process)
|
|
1317
|
+
- Lower memory usage
|
|
1373
1318
|
|
|
1374
1319
|
---
|
|
1375
1320
|
|
|
@@ -1394,9 +1339,9 @@ engine.register("products", optimized_source)
|
|
|
1394
1339
|
|
|
1395
1340
|
**What You Get:**
|
|
1396
1341
|
|
|
1397
|
-
-
|
|
1398
|
-
-
|
|
1399
|
-
-
|
|
1342
|
+
- Early filtering (reduces data volume)
|
|
1343
|
+
- Faster execution (less data to process)
|
|
1344
|
+
- Lower memory usage
|
|
1400
1345
|
|
|
1401
1346
|
---
|
|
1402
1347
|
|
|
@@ -1426,57 +1371,69 @@ engine.register("products", ultimate_source, filename="products.jsonl")
|
|
|
1426
1371
|
|
|
1427
1372
|
**What You Get:**
|
|
1428
1373
|
|
|
1429
|
-
-
|
|
1430
|
-
-
|
|
1431
|
-
-
|
|
1432
|
-
|
|
1374
|
+
- Polars Join (speed) - when `use_polars=True`
|
|
1375
|
+
- Column Pruning (I/O)
|
|
1376
|
+
- Filter Pushdown (early filtering)
|
|
1377
|
+
|
|
1378
|
+
**Best for:** Very large datasets (> 1M rows) when speed is priority
|
|
1433
1379
|
|
|
1434
|
-
**
|
|
1380
|
+
**Note:** This uses Polars Join, not MMAP Join. For memory-constrained scenarios, use `use_polars=False` with `filename` parameter instead.
|
|
1435
1381
|
|
|
1436
1382
|
---
|
|
1437
1383
|
|
|
1438
|
-
##
|
|
1384
|
+
## Performance Guide
|
|
1439
1385
|
|
|
1440
1386
|
### By Dataset Size
|
|
1441
1387
|
|
|
1442
|
-
| Size | Configuration
|
|
1443
|
-
| ----------------- |
|
|
1444
|
-
| **< 10K rows** | `use_polars=False` (default)
|
|
1445
|
-
| **10K-100K rows** | `use_polars=False` (default)
|
|
1446
|
-
| **100K-1M rows** | `use_polars=True`
|
|
1447
|
-
| **> 1M rows** | All optimizations
|
|
1388
|
+
| Size | Configuration | Why |
|
|
1389
|
+
| ----------------- | ------------------------------- | ----------------------------------------- |
|
|
1390
|
+
| **< 10K rows** | `use_polars=False` (default) | Fastest, most stable |
|
|
1391
|
+
| **10K-100K rows** | `use_polars=False` (default) | Still fastest, handles mixed types |
|
|
1392
|
+
| **100K-1M rows** | `use_polars=True` OR `filename` | Polars Join (speed) OR MMAP Join (memory) |
|
|
1393
|
+
| **> 1M rows** | All optimizations | Maximum performance |
|
|
1448
1394
|
|
|
1449
1395
|
### By Priority
|
|
1450
1396
|
|
|
1451
|
-
**Priority: Stability**
|
|
1397
|
+
**Priority: Stability** - Use default (`use_polars=False`)
|
|
1452
1398
|
|
|
1453
1399
|
```python
|
|
1454
1400
|
engine = Engine() # Most stable
|
|
1455
1401
|
```
|
|
1456
1402
|
|
|
1457
|
-
**Priority: Speed**
|
|
1403
|
+
**Priority: Speed** - Use Polars
|
|
1458
1404
|
|
|
1459
1405
|
```python
|
|
1460
1406
|
engine = Engine(use_polars=True) # Fastest for large datasets
|
|
1461
1407
|
```
|
|
1462
1408
|
|
|
1463
|
-
**Priority: Memory**
|
|
1409
|
+
**Priority: Memory** - Use MMAP
|
|
1464
1410
|
|
|
1465
1411
|
```python
|
|
1466
1412
|
engine = Engine()
|
|
1467
1413
|
engine.register("table", source, filename="data.jsonl") # Lowest memory
|
|
1468
1414
|
```
|
|
1469
1415
|
|
|
1470
|
-
**Priority: Both**
|
|
1416
|
+
**Priority: Both** - Choose based on priority:
|
|
1417
|
+
|
|
1418
|
+
**If speed is more important:**
|
|
1471
1419
|
|
|
1472
1420
|
```python
|
|
1473
|
-
engine = Engine(use_polars=True)
|
|
1474
|
-
engine.register("table", source
|
|
1421
|
+
engine = Engine(use_polars=True) # Uses Polars Join (fastest)
|
|
1422
|
+
engine.register("table", source) # No filename - Polars Join
|
|
1475
1423
|
```
|
|
1476
1424
|
|
|
1425
|
+
**If memory is more important:**
|
|
1426
|
+
|
|
1427
|
+
```python
|
|
1428
|
+
engine = Engine(use_polars=False) # Uses MMAP Join (lowest memory)
|
|
1429
|
+
engine.register("table", source, filename="data.jsonl") # MMAP Join
|
|
1430
|
+
```
|
|
1431
|
+
|
|
1432
|
+
**Note:** Polars Join and MMAP Join are mutually exclusive - the engine chooses one based on `use_polars` flag. MMAP Join can use Polars internally for index building, but the join algorithm itself is MMAP.
|
|
1433
|
+
|
|
1477
1434
|
---
|
|
1478
1435
|
|
|
1479
|
-
##
|
|
1436
|
+
## Learning Path
|
|
1480
1437
|
|
|
1481
1438
|
### Level 1: Beginner (Start Here)
|
|
1482
1439
|
|
|
@@ -1516,8 +1473,8 @@ engine = Engine(use_polars=True)
|
|
|
1516
1473
|
### Level 3: Advanced
|
|
1517
1474
|
|
|
1518
1475
|
```python
|
|
1519
|
-
# Use MMAP for large files
|
|
1520
|
-
engine = Engine(use_polars=
|
|
1476
|
+
# Use MMAP for large files (requires use_polars=False)
|
|
1477
|
+
engine = Engine(use_polars=False) # MMAP Join requires use_polars=False
|
|
1521
1478
|
engine.register("table", source, filename="data.jsonl")
|
|
1522
1479
|
|
|
1523
1480
|
# Use Merge Join for sorted data
|
|
@@ -1553,7 +1510,7 @@ engine.register("table", optimized_source, filename="data.jsonl")
|
|
|
1553
1510
|
|
|
1554
1511
|
---
|
|
1555
1512
|
|
|
1556
|
-
##
|
|
1513
|
+
## Common Pitfalls
|
|
1557
1514
|
|
|
1558
1515
|
### Pitfall 1: Using Polars Without Normalization
|
|
1559
1516
|
|
|
@@ -1613,17 +1570,13 @@ engine.register("table", source) # Faster for < 100MB
|
|
|
1613
1570
|
|
|
1614
1571
|
---
|
|
1615
1572
|
|
|
1616
|
-
##
|
|
1617
|
-
|
|
1618
|
-
**Just starting?** → Use default (`Engine()`)
|
|
1573
|
+
## Quick Decision Guide
|
|
1619
1574
|
|
|
1620
|
-
**
|
|
1621
|
-
|
|
1622
|
-
**Memory constrained?**
|
|
1623
|
-
|
|
1624
|
-
**
|
|
1625
|
-
|
|
1626
|
-
**Want maximum performance?** → Combine all: `use_polars=True` + `filename` + protocols
|
|
1575
|
+
- **Just starting?** Use default (`Engine()`)
|
|
1576
|
+
- **Have large datasets?** Use `use_polars=True`
|
|
1577
|
+
- **Memory constrained?** Use `filename` parameter (MMAP)
|
|
1578
|
+
- **Data is sorted?** Use `ordered_by` parameter (Merge Join)
|
|
1579
|
+
- **Want maximum performance?** Use `use_polars=True` + protocols (Polars Join) OR `use_polars=False` + `filename` (MMAP Join) + protocols
|
|
1627
1580
|
|
|
1628
1581
|
---
|
|
1629
1582
|
|
|
@@ -1668,6 +1621,7 @@ engine = Engine(use_polars=True) # Enable Polars
|
|
|
1668
1621
|
**If you have large files:**
|
|
1669
1622
|
|
|
1670
1623
|
```python
|
|
1624
|
+
engine = Engine(use_polars=False) # MMAP Join requires use_polars=False
|
|
1671
1625
|
engine.register("table", source, filename="data.jsonl") # Enable MMAP
|
|
1672
1626
|
```
|
|
1673
1627
|
|
|
@@ -1679,15 +1633,28 @@ engine.register("table", source, ordered_by="key") # Enable Merge Join
|
|
|
1679
1633
|
|
|
1680
1634
|
### Step 4: Combine Optimizations
|
|
1681
1635
|
|
|
1636
|
+
**For Speed Priority (Polars Join):**
|
|
1637
|
+
|
|
1682
1638
|
```python
|
|
1683
|
-
|
|
1684
|
-
engine = Engine(use_polars=True)
|
|
1639
|
+
engine = Engine(use_polars=True) # Uses Polars Join
|
|
1685
1640
|
|
|
1686
1641
|
def optimized_source(dynamic_where=None, dynamic_columns=None):
|
|
1687
1642
|
# Supports all optimizations
|
|
1688
1643
|
pass
|
|
1689
1644
|
|
|
1690
|
-
engine.register("table", optimized_source
|
|
1645
|
+
engine.register("table", optimized_source) # No filename - Polars Join
|
|
1646
|
+
```
|
|
1647
|
+
|
|
1648
|
+
**For Memory Priority (MMAP Join):**
|
|
1649
|
+
|
|
1650
|
+
```python
|
|
1651
|
+
engine = Engine(use_polars=False) # Uses MMAP Join
|
|
1652
|
+
|
|
1653
|
+
def optimized_source(dynamic_where=None, dynamic_columns=None):
|
|
1654
|
+
# Supports all optimizations
|
|
1655
|
+
pass
|
|
1656
|
+
|
|
1657
|
+
engine.register("table", optimized_source, filename="data.jsonl") # MMAP Join
|
|
1691
1658
|
```
|
|
1692
1659
|
|
|
1693
1660
|
---
|
|
@@ -1719,21 +1686,44 @@ engine.register("table2", source2)
|
|
|
1719
1686
|
|
|
1720
1687
|
**Best Mix for Large Files:**
|
|
1721
1688
|
|
|
1689
|
+
**Option 1: Speed Priority (Polars Join)**
|
|
1690
|
+
|
|
1722
1691
|
```python
|
|
1723
|
-
engine = Engine(use_polars=True) #
|
|
1724
|
-
engine.register("table", source
|
|
1692
|
+
engine = Engine(use_polars=True) # Uses Polars Join (fastest)
|
|
1693
|
+
engine.register("table", source) # No filename needed
|
|
1694
|
+
```
|
|
1695
|
+
|
|
1696
|
+
**Option 2: Memory Priority (MMAP Join)**
|
|
1697
|
+
|
|
1698
|
+
```python
|
|
1699
|
+
engine = Engine(use_polars=False) # Uses MMAP Join (lowest memory)
|
|
1700
|
+
engine.register("table", source, filename="data.jsonl") # MMAP enabled
|
|
1725
1701
|
```
|
|
1726
1702
|
|
|
1727
1703
|
**Best Mix for Maximum Performance:**
|
|
1728
1704
|
|
|
1705
|
+
**Option 1: Speed Priority (Polars Join + Protocols)**
|
|
1706
|
+
|
|
1729
1707
|
```python
|
|
1730
|
-
engine = Engine(use_polars=True)
|
|
1708
|
+
engine = Engine(use_polars=True) # Uses Polars Join
|
|
1731
1709
|
|
|
1732
1710
|
def source(dynamic_where=None, dynamic_columns=None):
|
|
1733
|
-
# All optimizations
|
|
1711
|
+
# All optimizations (filter pushdown + column pruning)
|
|
1734
1712
|
pass
|
|
1735
1713
|
|
|
1736
|
-
engine.register("table", source
|
|
1714
|
+
engine.register("table", source) # No filename - Polars Join
|
|
1715
|
+
```
|
|
1716
|
+
|
|
1717
|
+
**Option 2: Memory Priority (MMAP Join + Protocols)**
|
|
1718
|
+
|
|
1719
|
+
```python
|
|
1720
|
+
engine = Engine(use_polars=False) # Uses MMAP Join
|
|
1721
|
+
|
|
1722
|
+
def source(dynamic_where=None, dynamic_columns=None):
|
|
1723
|
+
# All optimizations (filter pushdown + column pruning)
|
|
1724
|
+
pass
|
|
1725
|
+
|
|
1726
|
+
engine.register("table", source, filename="data.jsonl") # MMAP Join
|
|
1737
1727
|
```
|
|
1738
1728
|
|
|
1739
1729
|
---
|
|
@@ -1742,8 +1732,8 @@ engine.register("table", source, filename="data.jsonl")
|
|
|
1742
1732
|
|
|
1743
1733
|
1. **Start Simple**: Use default configuration (`Engine()`) - it's the most stable
|
|
1744
1734
|
2. **Experiment Gradually**: Add options one at a time to understand their impact
|
|
1745
|
-
3. **Mix Wisely**:
|
|
1746
|
-
4. **Know When to Use Each**: Small files
|
|
1735
|
+
3. **Mix Wisely**: Choose Polars Join (speed) OR MMAP Join (memory) based on priority
|
|
1736
|
+
4. **Know When to Use Each**: Small files: default, Large files: Polars Join (speed) OR MMAP Join (memory)
|
|
1747
1737
|
|
|
1748
1738
|
---
|
|
1749
1739
|
|