streaming-sql-engine 0.1.26__tar.gz → 0.1.27__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.26/streaming_sql_engine.egg-info → streaming_sql_engine-0.1.27}/PKG-INFO +1 -1
  2. streaming_sql_engine-0.1.27/benchmark_all_configurations.py +414 -0
  3. streaming_sql_engine-0.1.27/benchmark_all_configurations_1k.py +489 -0
  4. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/operators_polars.py +162 -74
  5. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/optimizer.py +1 -1
  6. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/polars_operators.py +9 -1
  7. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/pyproject.toml +1 -1
  8. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/setup.py +1 -1
  9. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27/streaming_sql_engine.egg-info}/PKG-INFO +1 -1
  10. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/streaming_sql_engine.egg-info/SOURCES.txt +4 -0
  11. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/DEPLOYMENT.md +0 -0
  12. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/MANIFEST.in +0 -0
  13. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/QUICK_DEPLOY.md +0 -0
  14. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/QUICK_FIX.md +0 -0
  15. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/README.md +0 -0
  16. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/__init__.py +0 -0
  17. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/APACHE_DRILL_COMPARISON.md +0 -0
  18. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/API_JOIN_OPERATIONS.md +0 -0
  19. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/ARCHITECTURAL_RECOMMENDATION.md +0 -0
  20. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/ARCHITECTURE_DECISION.md +0 -0
  21. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/ARCHITECTURE_SYNCED.md +0 -0
  22. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/BEST_USE_CASES.md +0 -0
  23. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/BETTER_FILTER_APPROACH.md +0 -0
  24. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/CARTESIAN_PRODUCTS_CAUSES.md +0 -0
  25. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/CHANGES_SUMMARY.md +0 -0
  26. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/COMPREHENSIVE_ARTICLE.md +0 -0
  27. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/COMPREHENSIVE_DOCUMENTATION.md +0 -0
  28. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/COMPREHENSIVE_GUIDE.md +0 -0
  29. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/DEVELOPER_GUIDE.md +0 -0
  30. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/DUCKDB_COMPARISON.md +0 -0
  31. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/ENGINE_OPTIONS_REFERENCE.md +0 -0
  32. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/FINAL_IMPLEMENTATION_RECOMMENDATIONS.md +0 -0
  33. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/FINAL_RECOMMENDATION.md +0 -0
  34. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/FIRST_MATCH_ONLY_WARNINGS.md +0 -0
  35. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/HANDLING_DUPLICATES_WITHOUT_CARTESIAN.md +0 -0
  36. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/HOW_PROTOCOL_DETECTION_WORKS.md +0 -0
  37. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/HOW_TO_ADD_TO_PROJECT.md +0 -0
  38. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/INSTALLATION.md +0 -0
  39. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/JSONL_EXECUTOR_ANALYSIS.md +0 -0
  40. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/JSONL_EXECUTOR_REMOVED.md +0 -0
  41. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/LIBRARY_DOCUMENTATION.md +0 -0
  42. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/MEDIUM_ARTICLE.md +0 -0
  43. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/MEDIUM_ARTICLE_SIMPLIFIED.md +0 -0
  44. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/MIGRATION_GUIDE.md +0 -0
  45. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/MMAP_WITHOUT_POLARS_SLOW.md +0 -0
  46. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/MOST_STABLE_AND_PERFORMANT.md +0 -0
  47. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/MULTI_SOURCE_EXAMPLE_README.md +0 -0
  48. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/MYSQL_USAGE.md +0 -0
  49. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/OPTIMIZATIONS_BREAKDOWN.md +0 -0
  50. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/OPTIMIZATIONS_NOT_DATABASE_ONLY.md +0 -0
  51. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/OPTIMIZATIONS_VS_POLARS.md +0 -0
  52. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/OPTIMIZER_AUTOMATED.md +0 -0
  53. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/PERFORMANCE.md +0 -0
  54. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/PERFORMANCE_COMPARISON.md +0 -0
  55. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/POLARS_AND_MMAP_GUIDE.md +0 -0
  56. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/POLARS_VS_POLARS_MMAP.md +0 -0
  57. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/PROTOCOL_AND_OPTIMIZATIONS_EXPLAINED.md +0 -0
  58. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/PROTOCOL_EXPLANATION.md +0 -0
  59. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/PUBLISHING.md +0 -0
  60. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/PYPI_CHECKLIST.md +0 -0
  61. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/QUICK_PUBLISH.md +0 -0
  62. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/QUICK_START.md +0 -0
  63. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/SIMPLE_PROTOCOL_GUIDE.md +0 -0
  64. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/SIMPLE_SOURCE_FUNCTIONS.md +0 -0
  65. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/SOURCE_COMBINATIONS_GUIDE.md +0 -0
  66. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/TECHNICAL_DOCUMENTATION.md +0 -0
  67. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/USER_GUIDE.md +0 -0
  68. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/WHAT_IS_WHERE_TO_PARAMS.md +0 -0
  69. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/WHEN_POLARS_IS_USED.md +0 -0
  70. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/WHERE_POLARS_IS_USED.md +0 -0
  71. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/WHY_API_CONVERTER_NEEDED.md +0 -0
  72. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/WHY_MANUAL_PARSING.md +0 -0
  73. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/WHY_ORIGINAL_IS_FASTER.md +0 -0
  74. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/WHY_PROTOCOL_IN_SOURCES.md +0 -0
  75. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/documentation/XML_MONGO_USE_CASE.md +0 -0
  76. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/engine.py +0 -0
  77. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/evaluator.py +0 -0
  78. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/executor.py +0 -0
  79. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/mmap_index.py +0 -0
  80. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/operators.py +0 -0
  81. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/operators_mmap.py +0 -0
  82. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/optimized_export.py +0 -0
  83. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/parser.py +0 -0
  84. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/planner.py +0 -0
  85. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/polars_expression_translator.py +0 -0
  86. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/pre_release_test.py +0 -0
  87. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/protocol_helpers.py +0 -0
  88. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/quick_test.py +0 -0
  89. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/requirements.txt +0 -0
  90. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/setup.cfg +0 -0
  91. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/streaming_sql_engine.egg-info/dependency_links.txt +0 -0
  92. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/streaming_sql_engine.egg-info/requires.txt +0 -0
  93. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/streaming_sql_engine.egg-info/top_level.txt +0 -0
  94. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_engine_options.py +0 -0
  95. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_full_pipeline.py +0 -0
  96. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_merge_buffer.py +0 -0
  97. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_merge_join_debug.py +0 -0
  98. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_merge_join_detailed_debug.py +0 -0
  99. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_merge_join_direct.py +0 -0
  100. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_merge_join_issue.py +0 -0
  101. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_merge_join_simple.py +0 -0
  102. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_merge_join_with_user_data.py +0 -0
  103. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_mmap_debug.py +0 -0
  104. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_mmap_direct.py +0 -0
  105. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_mmap_get_matches.py +0 -0
  106. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_mmap_get_matches_direct.py +0 -0
  107. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_mmap_get_rows_variants.py +0 -0
  108. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_mmap_index.py +0 -0
  109. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_mmap_index_lookup.py +0 -0
  110. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_mmap_join_benchmark_match.py +0 -0
  111. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_mmap_join_debug.py +0 -0
  112. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_mmap_join_simple.py +0 -0
  113. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_mmap_join_simple_fixed.py +0 -0
  114. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_mmap_join_trace.py +0 -0
  115. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_mmap_key_extraction.py +0 -0
  116. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_mmap_required_columns.py +0 -0
  117. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_mmap_simple_query.py +0 -0
  118. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_polars_fixes.py +0 -0
  119. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_polars_schema_fix.py +0 -0
  120. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_readme_cases.py +0 -0
  121. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_required_columns_analysis.py +0 -0
  122. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_where_clause_1k.py +0 -0
  123. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_where_debug.py +0 -0
  124. {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.27}/tests/test_where_pushdown.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: streaming-sql-engine
3
- Version: 0.1.26
3
+ Version: 0.1.27
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
@@ -0,0 +1,414 @@
1
+ """
2
+ Comprehensive benchmark comparing all engine configurations with RAM and CPU measurements.
3
+
4
+ Tests:
5
+ 1. Merge Join (sorted data, use_polars=False, ordered_by)
6
+ 2. Lookup Join (default Python join)
7
+ 3. Polars Join (use_polars=True)
8
+ 4. MMAP Join (filename metadata, use_polars=False)
9
+ 5. Polars + Column Pruning (use_polars=True, dynamic_columns protocol)
10
+ 6. Polars + Filter Pushdown (use_polars=True, dynamic_where protocol)
11
+ 7. All Optimizations Combined (Polars + Column Pruning + Filter Pushdown + first_match_only)
12
+ """
13
+
14
+ import json
15
+ import time
16
+ import psutil
17
+ import os
18
+ from streaming_sql_engine import Engine
19
+
20
+
21
+ def load_jsonl_file(filename, dynamic_where=None, dynamic_columns=None):
22
+ """
23
+ Load JSONL file with optional column pruning and filter pushdown.
24
+
25
+ Args:
26
+ dynamic_where: SQL WHERE clause string (for filter pushdown)
27
+ dynamic_columns: List of column names to read (for column pruning)
28
+ """
29
+ with open(filename, "r", encoding="utf-8") as f:
30
+ for line in f:
31
+ if line.strip():
32
+ row = json.loads(line)
33
+
34
+ # Apply filter pushdown if WHERE clause provided
35
+ if dynamic_where:
36
+ # Handle table-prefixed and non-prefixed, quoted and unquoted values
37
+ # Examples: "products.checked = 1", "checked = '1'", "checked=1", etc.
38
+ # Normalize the WHERE clause for easier matching
39
+ where_lower = dynamic_where.lower().replace(" ", "")
40
+
41
+ # Check for checked=1 patterns (with various formats)
42
+ if ("checked=1" in where_lower or "checked='1'" in where_lower or
43
+ "checked=\"1\"" in where_lower or ".checked=1" in where_lower or
44
+ ".checked='1'" in where_lower or ".checked=\"1\"" in where_lower):
45
+ if row.get("checked") != 1:
46
+ continue
47
+ # Check for checked=0 patterns
48
+ elif ("checked=0" in where_lower or "checked='0'" in where_lower or
49
+ "checked=\"0\"" in where_lower or ".checked=0" in where_lower or
50
+ ".checked='0'" in where_lower or ".checked=\"0\"" in where_lower):
51
+ if row.get("checked") != 0:
52
+ continue
53
+
54
+ # Apply column pruning if columns specified
55
+ if dynamic_columns:
56
+ pruned_row = {k: v for k, v in row.items() if k in dynamic_columns}
57
+ yield pruned_row
58
+ else:
59
+ yield row
60
+
61
+
62
+ def get_memory_usage():
63
+ """Get current memory usage in MB."""
64
+ process = psutil.Process(os.getpid())
65
+ return process.memory_info().rss / (1024 * 1024) # Convert to MB
66
+
67
+
68
+ def get_cpu_percent():
69
+ """Get current CPU usage percentage."""
70
+ return psutil.cpu_percent(interval=0.1)
71
+
72
+
73
+ def run_benchmark(name, engine_config, source_config, query, products_file, images_file):
74
+ """
75
+ Run a benchmark with specific configuration.
76
+
77
+ Returns:
78
+ dict with results: rows, time_seconds, peak_memory_mb, avg_cpu_percent
79
+ """
80
+ print(f"\n{'='*70}")
81
+ print(f"CONFIGURATION: {name}")
82
+ print(f"{'='*70}")
83
+ print(f"Engine config: {engine_config}")
84
+ print(f"Source config: {source_config}")
85
+ print()
86
+
87
+ # Initialize engine
88
+ engine = Engine(**engine_config)
89
+
90
+ # Register sources
91
+ products_source_fn = source_config.get("products_fn", lambda: load_jsonl_file(products_file))
92
+ images_source_fn = source_config.get("images_fn", lambda: load_jsonl_file(images_file))
93
+
94
+ engine.register(
95
+ "products",
96
+ products_source_fn,
97
+ **source_config.get("products_metadata", {})
98
+ )
99
+
100
+ engine.register(
101
+ "images",
102
+ images_source_fn,
103
+ **source_config.get("images_metadata", {})
104
+ )
105
+
106
+ # Measure baseline memory
107
+ baseline_memory = get_memory_usage()
108
+
109
+ # Start CPU monitoring
110
+ cpu_samples = []
111
+
112
+ # Execute query and measure
113
+ start_time = time.time()
114
+ peak_memory = baseline_memory
115
+ row_count = 0
116
+
117
+ # Prepare output file name
118
+ safe_name = name.lower().replace(" ", "_").replace(".", "").replace("(", "").replace(")", "").replace("+", "_")
119
+ output_file = f"results_{safe_name}.jsonl"
120
+ output_rows = []
121
+
122
+ try:
123
+ for row in engine.query(query):
124
+ row_count += 1
125
+ output_rows.append(row) # Store for export
126
+
127
+ # Monitor memory
128
+ current_memory = get_memory_usage()
129
+ if current_memory > peak_memory:
130
+ peak_memory = current_memory
131
+
132
+ # Sample CPU every 1000 rows
133
+ if row_count % 1000 == 0:
134
+ cpu_samples.append(get_cpu_percent())
135
+
136
+ # Limit output for very large result sets
137
+ if row_count >= 1000000: # Cap at 1M rows for testing
138
+ print(f" [INFO] Capped at 1M rows for performance testing")
139
+ break
140
+
141
+ elapsed_time = time.time() - start_time
142
+
143
+ # Calculate average CPU
144
+ avg_cpu = sum(cpu_samples) / len(cpu_samples) if cpu_samples else 0
145
+
146
+ # Memory overhead
147
+ memory_overhead = peak_memory - baseline_memory
148
+
149
+ # Export results to JSONL file
150
+ export_start = time.time()
151
+ with open(output_file, "w", encoding="utf-8") as f:
152
+ for row in output_rows:
153
+ f.write(json.dumps(row, ensure_ascii=False) + "\n")
154
+ export_time = time.time() - export_start
155
+
156
+ import os
157
+ file_size_mb = os.path.getsize(output_file) / (1024 * 1024)
158
+
159
+ results = {
160
+ "name": name,
161
+ "rows": row_count,
162
+ "time_seconds": elapsed_time,
163
+ "peak_memory_mb": peak_memory,
164
+ "baseline_memory_mb": baseline_memory,
165
+ "memory_overhead_mb": memory_overhead,
166
+ "avg_cpu_percent": avg_cpu,
167
+ "rows_per_second": row_count / elapsed_time if elapsed_time > 0 else 0,
168
+ "output_file": output_file,
169
+ "output_file_size_mb": file_size_mb
170
+ }
171
+
172
+ print(f" Results:")
173
+ print(f" Rows processed: {row_count:,}")
174
+ print(f" Time: {elapsed_time:.2f} seconds")
175
+ print(f" Speed: {results['rows_per_second']:,.0f} rows/second")
176
+ print(f" Peak memory: {peak_memory:.2f} MB")
177
+ print(f" Memory overhead: {memory_overhead:.2f} MB")
178
+ print(f" Avg CPU: {avg_cpu:.1f}%")
179
+ print(f" Exported to: {output_file} ({file_size_mb:.2f} MB)")
180
+
181
+ return results
182
+
183
+ except Exception as e:
184
+ print(f" [ERROR] {e}")
185
+ import traceback
186
+ traceback.print_exc()
187
+ return {
188
+ "name": name,
189
+ "error": str(e),
190
+ "rows": 0,
191
+ "time_seconds": 0,
192
+ "peak_memory_mb": 0,
193
+ "memory_overhead_mb": 0,
194
+ "avg_cpu_percent": 0,
195
+ "rows_per_second": 0,
196
+ "output_file": None,
197
+ "output_file_size_mb": 0
198
+ }
199
+
200
+
201
+ def main():
202
+ products_file = "products_3_1k.jsonl"
203
+ images_file = "images_3_1k.jsonl"
204
+
205
+ # Check if files exist
206
+ if not os.path.exists(products_file):
207
+ print(f"[ERROR] File not found: {products_file}")
208
+ print("Run: python generate_test_data_100k.py")
209
+ return
210
+
211
+ if not os.path.exists(images_file):
212
+ print(f"[ERROR] File not found: {images_file}")
213
+ print("Run: python generate_test_data_100k.py")
214
+ return
215
+
216
+ # Query to test
217
+ query = """
218
+ SELECT
219
+ products.product_id,
220
+ products.product_sku,
221
+ products.title,
222
+ images.image,
223
+ images.image_type
224
+ FROM products
225
+ LEFT JOIN images ON products.product_id = images.product_id
226
+ WHERE products.checked = 1
227
+ """
228
+
229
+ print("=" * 70)
230
+ print("COMPREHENSIVE BENCHMARK: All Engine Configurations")
231
+ print("=" * 70)
232
+ print()
233
+ print(f"Data files:")
234
+ print(f" Products: {products_file}")
235
+ print(f" Images: {images_file}")
236
+ print()
237
+ print(f"Query:")
238
+ print(query)
239
+ print()
240
+
241
+ # Define all configurations to test
242
+ configurations = [
243
+ {
244
+ "name": "1. Merge Join (Sorted Data)",
245
+ "engine_config": {
246
+ "debug": False,
247
+ "use_polars": False,
248
+ "first_match_only": False
249
+ },
250
+ "source_config": {
251
+ "products_fn": lambda: load_jsonl_file(products_file),
252
+ "images_fn": lambda: load_jsonl_file(images_file),
253
+ "products_metadata": {"ordered_by": "product_id"},
254
+ "images_metadata": {"ordered_by": "product_id"}
255
+ }
256
+ },
257
+ {
258
+ "name": "2. Lookup Join (Default Python)",
259
+ "engine_config": {
260
+ "debug": False,
261
+ "use_polars": False,
262
+ "first_match_only": False
263
+ },
264
+ "source_config": {
265
+ "products_fn": lambda: load_jsonl_file(products_file),
266
+ "images_fn": lambda: load_jsonl_file(images_file),
267
+ "products_metadata": {},
268
+ "images_metadata": {}
269
+ }
270
+ },
271
+ {
272
+ "name": "3. Polars Join",
273
+ "engine_config": {
274
+ "debug": False,
275
+ "use_polars": True,
276
+ "first_match_only": False
277
+ },
278
+ "source_config": {
279
+ "products_fn": lambda: load_jsonl_file(products_file),
280
+ "images_fn": lambda: load_jsonl_file(images_file),
281
+ "products_metadata": {},
282
+ "images_metadata": {}
283
+ }
284
+ },
285
+ {
286
+ "name": "4. MMAP Join",
287
+ "engine_config": {
288
+ "debug": False,
289
+ "use_polars": False,
290
+ "first_match_only": False
291
+ },
292
+ "source_config": {
293
+ "products_fn": lambda: load_jsonl_file(products_file),
294
+ "images_fn": lambda: load_jsonl_file(images_file),
295
+ "products_metadata": {"filename": products_file},
296
+ "images_metadata": {"filename": images_file}
297
+ }
298
+ },
299
+ {
300
+ "name": "5. Polars + Column Pruning",
301
+ "engine_config": {
302
+ "debug": False,
303
+ "use_polars": True,
304
+ "first_match_only": False
305
+ },
306
+ "source_config": {
307
+ "products_fn": lambda dynamic_where=None, dynamic_columns=None: load_jsonl_file(
308
+ products_file, dynamic_where=dynamic_where, dynamic_columns=dynamic_columns
309
+ ),
310
+ "images_fn": lambda dynamic_where=None, dynamic_columns=None: load_jsonl_file(
311
+ images_file, dynamic_where=dynamic_where, dynamic_columns=dynamic_columns
312
+ ),
313
+ "products_metadata": {},
314
+ "images_metadata": {}
315
+ }
316
+ },
317
+ {
318
+ "name": "6. Polars + Filter Pushdown",
319
+ "engine_config": {
320
+ "debug": False,
321
+ "use_polars": True,
322
+ "first_match_only": False
323
+ },
324
+ "source_config": {
325
+ "products_fn": lambda dynamic_where=None, dynamic_columns=None: load_jsonl_file(
326
+ products_file, dynamic_where=dynamic_where, dynamic_columns=dynamic_columns
327
+ ),
328
+ "images_fn": lambda dynamic_where=None, dynamic_columns=None: load_jsonl_file(
329
+ images_file, dynamic_where=dynamic_where, dynamic_columns=dynamic_columns
330
+ ),
331
+ "products_metadata": {},
332
+ "images_metadata": {}
333
+ }
334
+ },
335
+ {
336
+ "name": "7. All Optimizations Combined",
337
+ "engine_config": {
338
+ "debug": False,
339
+ "use_polars": True,
340
+ "first_match_only": True
341
+ },
342
+ "source_config": {
343
+ "products_fn": lambda dynamic_where=None, dynamic_columns=None: load_jsonl_file(
344
+ products_file, dynamic_where=dynamic_where, dynamic_columns=dynamic_columns
345
+ ),
346
+ "images_fn": lambda dynamic_where=None, dynamic_columns=None: load_jsonl_file(
347
+ images_file, dynamic_where=dynamic_where, dynamic_columns=dynamic_columns
348
+ ),
349
+ "products_metadata": {},
350
+ "images_metadata": {}
351
+ }
352
+ },
353
+ ]
354
+
355
+ # Run all benchmarks
356
+ all_results = []
357
+ for config in configurations:
358
+ result = run_benchmark(
359
+ config["name"],
360
+ config["engine_config"],
361
+ config["source_config"],
362
+ query,
363
+ products_file,
364
+ images_file
365
+ )
366
+ all_results.append(result)
367
+
368
+ # Small delay between tests
369
+ time.sleep(1)
370
+
371
+ # Print summary
372
+ print()
373
+ print("=" * 70)
374
+ print("BENCHMARK SUMMARY")
375
+ print("=" * 70)
376
+ print()
377
+ print(f"{'Configuration':<40} {'Rows':>12} {'Time (s)':>10} {'Memory (MB)':>12} {'CPU %':>8} {'Rows/s':>12} {'Output File':<30}")
378
+ print("-" * 130)
379
+
380
+ for result in all_results:
381
+ if "error" in result:
382
+ print(f"{result['name']:<40} {'ERROR':>12} {'':>30}")
383
+ else:
384
+ output_info = f"{result.get('output_file', 'N/A')} ({result.get('output_file_size_mb', 0):.2f} MB)" if result.get('output_file') else "N/A"
385
+ print(f"{result['name']:<40} {result['rows']:>12,} {result['time_seconds']:>10.2f} "
386
+ f"{result['memory_overhead_mb']:>12.2f} {result['avg_cpu_percent']:>8.1f} "
387
+ f"{result['rows_per_second']:>12,.0f} {output_info:<30}")
388
+
389
+ print()
390
+ print("=" * 70)
391
+ print("RECOMMENDATIONS")
392
+ print("=" * 70)
393
+ print()
394
+
395
+ # Find best configuration for each metric
396
+ valid_results = [r for r in all_results if "error" not in r]
397
+
398
+ if valid_results:
399
+ fastest = min(valid_results, key=lambda x: x["time_seconds"])
400
+ lowest_memory = min(valid_results, key=lambda x: x["memory_overhead_mb"])
401
+ highest_throughput = max(valid_results, key=lambda x: x["rows_per_second"])
402
+
403
+ print(f"Fastest: {fastest['name']} ({fastest['time_seconds']:.2f}s)")
404
+ print(f"Lowest Memory: {lowest_memory['name']} ({lowest_memory['memory_overhead_mb']:.2f} MB)")
405
+ print(f"Highest Throughput: {highest_throughput['name']} ({highest_throughput['rows_per_second']:,.0f} rows/s)")
406
+ print()
407
+ print("For 100K+ records:")
408
+ print(" - Use Merge Join if data is sorted (fastest + lowest memory)")
409
+ print(" - Use MMAP Join if data is not sorted (low memory)")
410
+ print(" - Use Polars + optimizations for best throughput")
411
+
412
+
413
+ if __name__ == "__main__":
414
+ main()