streaming-sql-engine 0.1.23__tar.gz → 0.1.26__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.
Files changed (124) hide show
  1. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/DEPLOYMENT.md +11 -0
  2. {streaming_sql_engine-0.1.23/streaming_sql_engine.egg-info → streaming_sql_engine-0.1.26}/PKG-INFO +160 -170
  3. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/QUICK_DEPLOY.md +11 -0
  4. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/QUICK_FIX.md +11 -0
  5. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/README.md +159 -169
  6. streaming_sql_engine-0.1.26/documentation/COMPREHENSIVE_GUIDE.md +1891 -0
  7. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/HOW_PROTOCOL_DETECTION_WORKS.md +11 -0
  8. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/MMAP_WITHOUT_POLARS_SLOW.md +11 -0
  9. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/MOST_STABLE_AND_PERFORMANT.md +11 -0
  10. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/OPTIMIZER_AUTOMATED.md +11 -0
  11. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/POLARS_VS_POLARS_MMAP.md +11 -0
  12. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/SIMPLE_PROTOCOL_GUIDE.md +11 -0
  13. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/SIMPLE_SOURCE_FUNCTIONS.md +11 -0
  14. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/WHAT_IS_WHERE_TO_PARAMS.md +11 -0
  15. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/WHY_API_CONVERTER_NEEDED.md +11 -0
  16. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/WHY_MANUAL_PARSING.md +11 -0
  17. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/WHY_PROTOCOL_IN_SOURCES.md +11 -0
  18. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/engine.py +2 -2
  19. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/executor.py +2 -2
  20. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/mmap_index.py +391 -386
  21. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/operators.py +538 -532
  22. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/operators_mmap.py +332 -269
  23. streaming_sql_engine-0.1.26/optimized_export.py +350 -0
  24. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/pyproject.toml +2 -2
  25. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/setup.py +1 -1
  26. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26/streaming_sql_engine.egg-info}/PKG-INFO +160 -170
  27. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/streaming_sql_engine.egg-info/SOURCES.txt +34 -13
  28. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/tests/test_engine_options.py +646 -638
  29. streaming_sql_engine-0.1.26/tests/test_merge_buffer.py +82 -0
  30. streaming_sql_engine-0.1.26/tests/test_merge_join_debug.py +68 -0
  31. streaming_sql_engine-0.1.26/tests/test_merge_join_detailed_debug.py +240 -0
  32. streaming_sql_engine-0.1.26/tests/test_merge_join_direct.py +116 -0
  33. streaming_sql_engine-0.1.26/tests/test_merge_join_issue.py +52 -0
  34. streaming_sql_engine-0.1.26/tests/test_merge_join_simple.py +116 -0
  35. streaming_sql_engine-0.1.26/tests/test_merge_join_with_user_data.py +139 -0
  36. streaming_sql_engine-0.1.26/tests/test_mmap_debug.py +60 -0
  37. streaming_sql_engine-0.1.26/tests/test_mmap_direct.py +60 -0
  38. streaming_sql_engine-0.1.26/tests/test_mmap_get_matches.py +75 -0
  39. streaming_sql_engine-0.1.26/tests/test_mmap_get_matches_direct.py +44 -0
  40. streaming_sql_engine-0.1.26/tests/test_mmap_get_rows_variants.py +31 -0
  41. streaming_sql_engine-0.1.26/tests/test_mmap_index.py +30 -0
  42. streaming_sql_engine-0.1.26/tests/test_mmap_index_lookup.py +36 -0
  43. streaming_sql_engine-0.1.26/tests/test_mmap_join_benchmark_match.py +175 -0
  44. streaming_sql_engine-0.1.26/tests/test_mmap_join_debug.py +324 -0
  45. streaming_sql_engine-0.1.26/tests/test_mmap_join_simple.py +132 -0
  46. streaming_sql_engine-0.1.26/tests/test_mmap_join_simple_fixed.py +174 -0
  47. streaming_sql_engine-0.1.26/tests/test_mmap_join_trace.py +89 -0
  48. streaming_sql_engine-0.1.26/tests/test_mmap_key_extraction.py +92 -0
  49. streaming_sql_engine-0.1.26/tests/test_mmap_required_columns.py +39 -0
  50. streaming_sql_engine-0.1.26/tests/test_mmap_simple_query.py +65 -0
  51. streaming_sql_engine-0.1.26/tests/test_readme_cases.py +931 -0
  52. streaming_sql_engine-0.1.26/tests/test_required_columns_analysis.py +37 -0
  53. streaming_sql_engine-0.1.26/tests/test_where_clause_1k.py +94 -0
  54. streaming_sql_engine-0.1.26/tests/test_where_pushdown.py +81 -0
  55. streaming_sql_engine-0.1.23/RELEASE_READINESS_1.0.0.md +0 -172
  56. streaming_sql_engine-0.1.23/debug_tests.py +0 -47
  57. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/MANIFEST.in +0 -0
  58. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/__init__.py +0 -0
  59. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/APACHE_DRILL_COMPARISON.md +0 -0
  60. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/API_JOIN_OPERATIONS.md +0 -0
  61. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/ARCHITECTURAL_RECOMMENDATION.md +0 -0
  62. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/ARCHITECTURE_DECISION.md +0 -0
  63. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/ARCHITECTURE_SYNCED.md +0 -0
  64. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/BEST_USE_CASES.md +0 -0
  65. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/BETTER_FILTER_APPROACH.md +0 -0
  66. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/CARTESIAN_PRODUCTS_CAUSES.md +0 -0
  67. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/CHANGES_SUMMARY.md +0 -0
  68. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/COMPREHENSIVE_ARTICLE.md +0 -0
  69. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/COMPREHENSIVE_DOCUMENTATION.md +0 -0
  70. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/DEVELOPER_GUIDE.md +0 -0
  71. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/DUCKDB_COMPARISON.md +0 -0
  72. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/ENGINE_OPTIONS_REFERENCE.md +0 -0
  73. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/FINAL_IMPLEMENTATION_RECOMMENDATIONS.md +0 -0
  74. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/FINAL_RECOMMENDATION.md +0 -0
  75. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/FIRST_MATCH_ONLY_WARNINGS.md +0 -0
  76. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/HANDLING_DUPLICATES_WITHOUT_CARTESIAN.md +0 -0
  77. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/HOW_TO_ADD_TO_PROJECT.md +0 -0
  78. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/INSTALLATION.md +0 -0
  79. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/JSONL_EXECUTOR_ANALYSIS.md +0 -0
  80. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/JSONL_EXECUTOR_REMOVED.md +0 -0
  81. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/LIBRARY_DOCUMENTATION.md +0 -0
  82. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/MEDIUM_ARTICLE.md +0 -0
  83. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/MEDIUM_ARTICLE_SIMPLIFIED.md +0 -0
  84. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/MIGRATION_GUIDE.md +0 -0
  85. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/MULTI_SOURCE_EXAMPLE_README.md +0 -0
  86. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/MYSQL_USAGE.md +0 -0
  87. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/OPTIMIZATIONS_BREAKDOWN.md +0 -0
  88. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/OPTIMIZATIONS_NOT_DATABASE_ONLY.md +0 -0
  89. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/OPTIMIZATIONS_VS_POLARS.md +0 -0
  90. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/PERFORMANCE.md +0 -0
  91. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/PERFORMANCE_COMPARISON.md +0 -0
  92. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/POLARS_AND_MMAP_GUIDE.md +0 -0
  93. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/PROTOCOL_AND_OPTIMIZATIONS_EXPLAINED.md +0 -0
  94. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/PROTOCOL_EXPLANATION.md +0 -0
  95. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/PUBLISHING.md +0 -0
  96. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/PYPI_CHECKLIST.md +0 -0
  97. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/QUICK_PUBLISH.md +0 -0
  98. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/QUICK_START.md +0 -0
  99. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/SOURCE_COMBINATIONS_GUIDE.md +0 -0
  100. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/TECHNICAL_DOCUMENTATION.md +0 -0
  101. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/USER_GUIDE.md +0 -0
  102. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/WHEN_POLARS_IS_USED.md +0 -0
  103. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/WHERE_POLARS_IS_USED.md +0 -0
  104. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/WHY_ORIGINAL_IS_FASTER.md +0 -0
  105. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/documentation/XML_MONGO_USE_CASE.md +0 -0
  106. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/evaluator.py +0 -0
  107. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/operators_polars.py +0 -0
  108. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/optimizer.py +0 -0
  109. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/parser.py +0 -0
  110. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/planner.py +0 -0
  111. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/polars_expression_translator.py +0 -0
  112. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/polars_operators.py +0 -0
  113. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/pre_release_test.py +0 -0
  114. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/protocol_helpers.py +0 -0
  115. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/quick_test.py +0 -0
  116. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/requirements.txt +0 -0
  117. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/setup.cfg +0 -0
  118. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/streaming_sql_engine.egg-info/dependency_links.txt +0 -0
  119. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/streaming_sql_engine.egg-info/requires.txt +0 -0
  120. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26}/streaming_sql_engine.egg-info/top_level.txt +0 -0
  121. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26/tests}/test_full_pipeline.py +0 -0
  122. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26/tests}/test_polars_fixes.py +0 -0
  123. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26/tests}/test_polars_schema_fix.py +0 -0
  124. {streaming_sql_engine-0.1.23 → streaming_sql_engine-0.1.26/tests}/test_where_debug.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: streaming-sql-engine
3
- Version: 0.1.23
3
+ Version: 0.1.26
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
- _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._
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 → Use MergeJoinIterator
254
- - If no → Use LookupJoinIterator
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 → Use MmapLookupJoinIterator (memory-mapped)
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
- ```python
266
- def _build_join_iterator(left_iterator, right_source_fn, left_key, right_key,
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
- # Check for mmap join (file-based)
274
- if right_metadata.get('filename') and MMAP_AVAILABLE:
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
- # Check for Polars join (vectorized)
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
- # Default: standard lookup join
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 → AST
506
- ↓
507
- Planner → Logical Plan
508
- ↓
509
- Executor → Iterator Pipeline
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 → FilterIterator → JoinIterators → ProjectIterator → Results
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(use_polars=True) # Enabled by default
590
+ engine = Engine() # use_polars=False (default)
652
591
 
653
- # Automatically uses Polars for:
654
- # - Vectorized filtering
655
- # - Vectorized projections
656
- # - Batch processing
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
- ✅ **Most Stable**: Handles mixed data types gracefully
1150
- ✅ **No Schema Errors**: No type inference issues
1151
- ✅ **Works Everywhere**: No external dependencies required
1152
- ✅ **Reliable**: Battle-tested Python code
1153
- ✅ **Fast for Small-Medium Data**: 0.72s for 10K rows
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
- ## 🚀 Experimenting with Options
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
- ✓ SQL parsed successfully
1125
+ SQL parsed successfully
1186
1126
 
1187
1127
  [2/3] BUILDING LOGICAL PLAN...
1188
- ✓ Logical plan built
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
- - ⚡ Faster for large datasets (vectorized operations)
1207
- - 🎯 SIMD acceleration
1208
- - 📊 Better for consistent schemas
1146
+ - Faster for large datasets (vectorized operations)
1147
+ - SIMD acceleration
1148
+ - Better for consistent schemas
1209
1149
 
1210
1150
  **Trade-offs:**
1211
1151
 
1212
- - ⚠️ Requires data normalization (consistent types)
1213
- - ⚠️ Can fail on mixed types
1214
- - ⚠️ Requires Polars dependency
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
- - 💾 90-99% memory reduction
1247
- - 📁 Works with files larger than RAM
1248
- - 🔄 OS-managed memory mapping
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
- - ⚠️ Requires file-based sources
1253
- - ⚠️ Slower for small files (overhead)
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
- - 💾 Lowest memory usage (no index needed)
1283
- - ⚡ Fast for sorted data
1284
- - 🔄 Streaming algorithm
1222
+ - Lowest memory usage (no index needed)
1223
+ - Fast for sorted data
1224
+ - Streaming algorithm
1285
1225
 
1286
1226
  **Trade-offs:**
1287
1227
 
1288
- - ⚠️ Requires pre-sorted data
1289
- - ⚠️ Both tables must be sorted
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
- ## 🔬 Advanced: Mixing Options
1258
+ ## Advanced: Mixing Options
1259
+
1260
+ ### Mix 1: MMAP with Polars Index Building (Best for Large Files)
1319
1261
 
1320
- ### Mix 1: Polars + MMAP (Best for Large Files)
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
- **The Ultimate Configuration** for large files with consistent types:
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=True) # Polars for speed
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
- - ⚡ Fast (Polars vectorized operations)
1332
- - 💾 Low memory (MMAP 90-99% reduction)
1333
- - 🎯 Best balance for large datasets
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
- - 📉 Reduced I/O (only reads needed columns)
1371
- - ⚡ Faster queries (less data to process)
1372
- - 💾 Lower memory usage
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
- - 🎯 Early filtering (reduces data volume)
1398
- - ⚡ Faster execution (less data to process)
1399
- - 📉 Lower memory usage
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
- - ⚡ Polars (speed)
1430
- - 💾 MMAP (memory)
1431
- - 📉 Column Pruning (I/O)
1432
- - 🎯 Filter Pushdown (early filtering)
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
- **Best for:** Very large datasets (> 1M rows)
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
- ## 📊 Performance Guide
1384
+ ## Performance Guide
1439
1385
 
1440
1386
  ### By Dataset Size
1441
1387
 
1442
- | Size | Configuration | Why |
1443
- | ----------------- | ------------------------------ | ---------------------------------- |
1444
- | **< 10K rows** | `use_polars=False` (default) | Fastest, most stable |
1445
- | **10K-100K rows** | `use_polars=False` (default) | Still fastest, handles mixed types |
1446
- | **100K-1M rows** | `use_polars=True` + `filename` | Polars + MMAP for best balance |
1447
- | **> 1M rows** | All optimizations | Maximum performance |
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** → Use default (`use_polars=False`)
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** → Use Polars
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** → Use MMAP
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** → Use Polars + MMAP
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, filename="data.jsonl") # Fast + Low memory
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
- ## 🎓 Learning Path
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=True)
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
- ## ⚠️ Common Pitfalls
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
- ## 🎯 Quick Decision Guide
1617
-
1618
- **Just starting?** → Use default (`Engine()`)
1573
+ ## Quick Decision Guide
1619
1574
 
1620
- **Have large datasets?** → Use `use_polars=True`
1621
-
1622
- **Memory constrained?** → Use `filename` parameter (MMAP)
1623
-
1624
- **Data is sorted?** → Use `ordered_by` parameter (Merge Join)
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
- # Ultimate configuration for large files
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, filename="data.jsonl")
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) # Speed
1724
- engine.register("table", source, filename="data.jsonl") # Memory
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, filename="data.jsonl")
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**: Combine options (Polars + MMAP) for best results
1746
- 4. **Know When to Use Each**: Small files → default, Large files → Polars + MMAP
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
 
@@ -54,3 +54,14 @@ python3 -c "import streaming_sql_engine; print(streaming_sql_engine.__file__)"
54
54
 
55
55
 
56
56
 
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+