streaming-sql-engine 0.1.26__tar.gz → 0.1.28__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.26/streaming_sql_engine.egg-info → streaming_sql_engine-0.1.28}/PKG-INFO +1 -1
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/__init__.py +1 -1
- streaming_sql_engine-0.1.28/benchmark_all_configurations.py +619 -0
- streaming_sql_engine-0.1.28/benchmark_all_configurations_1k.py +489 -0
- streaming_sql_engine-0.1.28/debug_where.py +48 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/evaluator.py +14 -1
- streaming_sql_engine-0.1.28/executor.py +558 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/operators.py +55 -7
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/operators_polars.py +213 -94
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/optimizer.py +1 -1
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/polars_expression_translator.py +21 -3
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/polars_operators.py +9 -1
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/pyproject.toml +1 -1
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/setup.py +1 -1
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28/streaming_sql_engine.egg-info}/PKG-INFO +1 -1
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/streaming_sql_engine.egg-info/SOURCES.txt +18 -0
- streaming_sql_engine-0.1.28/test_evaluator_direct.py +64 -0
- streaming_sql_engine-0.1.28/test_lookup_join_where.py +225 -0
- streaming_sql_engine-0.1.28/test_polars_where.py +86 -0
- streaming_sql_engine-0.1.28/test_where_debug_simple.py +87 -0
- streaming_sql_engine-0.1.28/test_where_fix.py +67 -0
- streaming_sql_engine-0.1.28/test_where_string.py +107 -0
- streaming_sql_engine-0.1.26/planner.py +0 -252
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/DEPLOYMENT.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/MANIFEST.in +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/QUICK_DEPLOY.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/QUICK_FIX.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/README.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/APACHE_DRILL_COMPARISON.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/API_JOIN_OPERATIONS.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/ARCHITECTURAL_RECOMMENDATION.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/ARCHITECTURE_DECISION.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/ARCHITECTURE_SYNCED.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/BEST_USE_CASES.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/BETTER_FILTER_APPROACH.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/CARTESIAN_PRODUCTS_CAUSES.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/CHANGES_SUMMARY.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/COMPREHENSIVE_ARTICLE.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/COMPREHENSIVE_DOCUMENTATION.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/COMPREHENSIVE_GUIDE.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/DEVELOPER_GUIDE.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/DUCKDB_COMPARISON.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/ENGINE_OPTIONS_REFERENCE.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/FINAL_IMPLEMENTATION_RECOMMENDATIONS.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/FINAL_RECOMMENDATION.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/FIRST_MATCH_ONLY_WARNINGS.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/HANDLING_DUPLICATES_WITHOUT_CARTESIAN.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/HOW_PROTOCOL_DETECTION_WORKS.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/HOW_TO_ADD_TO_PROJECT.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/INSTALLATION.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/JSONL_EXECUTOR_ANALYSIS.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/JSONL_EXECUTOR_REMOVED.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/LIBRARY_DOCUMENTATION.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/MEDIUM_ARTICLE.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/MEDIUM_ARTICLE_SIMPLIFIED.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/MIGRATION_GUIDE.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/MMAP_WITHOUT_POLARS_SLOW.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/MOST_STABLE_AND_PERFORMANT.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/MULTI_SOURCE_EXAMPLE_README.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/MYSQL_USAGE.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/OPTIMIZATIONS_BREAKDOWN.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/OPTIMIZATIONS_NOT_DATABASE_ONLY.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/OPTIMIZATIONS_VS_POLARS.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/OPTIMIZER_AUTOMATED.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/PERFORMANCE.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/PERFORMANCE_COMPARISON.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/POLARS_AND_MMAP_GUIDE.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/POLARS_VS_POLARS_MMAP.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/PROTOCOL_AND_OPTIMIZATIONS_EXPLAINED.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/PROTOCOL_EXPLANATION.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/PUBLISHING.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/PYPI_CHECKLIST.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/QUICK_PUBLISH.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/QUICK_START.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/SIMPLE_PROTOCOL_GUIDE.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/SIMPLE_SOURCE_FUNCTIONS.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/SOURCE_COMBINATIONS_GUIDE.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/TECHNICAL_DOCUMENTATION.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/USER_GUIDE.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/WHAT_IS_WHERE_TO_PARAMS.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/WHEN_POLARS_IS_USED.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/WHERE_POLARS_IS_USED.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/WHY_API_CONVERTER_NEEDED.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/WHY_MANUAL_PARSING.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/WHY_ORIGINAL_IS_FASTER.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/WHY_PROTOCOL_IN_SOURCES.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/documentation/XML_MONGO_USE_CASE.md +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/engine.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/mmap_index.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/operators_mmap.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/optimized_export.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/parser.py +0 -0
- /streaming_sql_engine-0.1.26/executor.py → /streaming_sql_engine-0.1.28/planner.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/pre_release_test.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/protocol_helpers.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/quick_test.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/requirements.txt +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/setup.cfg +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/streaming_sql_engine.egg-info/dependency_links.txt +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/streaming_sql_engine.egg-info/requires.txt +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/streaming_sql_engine.egg-info/top_level.txt +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_engine_options.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_full_pipeline.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_merge_buffer.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_merge_join_debug.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_merge_join_detailed_debug.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_merge_join_direct.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_merge_join_issue.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_merge_join_simple.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_merge_join_with_user_data.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_mmap_debug.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_mmap_direct.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_mmap_get_matches.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_mmap_get_matches_direct.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_mmap_get_rows_variants.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_mmap_index.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_mmap_index_lookup.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_mmap_join_benchmark_match.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_mmap_join_debug.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_mmap_join_simple.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_mmap_join_simple_fixed.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_mmap_join_trace.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_mmap_key_extraction.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_mmap_required_columns.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_mmap_simple_query.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_polars_fixes.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_polars_schema_fix.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_readme_cases.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_required_columns_analysis.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_where_clause_1k.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_where_debug.py +0 -0
- {streaming_sql_engine-0.1.26 → streaming_sql_engine-0.1.28}/tests/test_where_pushdown.py +0 -0
{streaming_sql_engine-0.1.26/streaming_sql_engine.egg-info → streaming_sql_engine-0.1.28}/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.28
|
|
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,619 @@
|
|
|
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 analyze_results(output_file, expected_products_checked_1):
|
|
74
|
+
"""Analyze results for inconsistencies."""
|
|
75
|
+
issues = []
|
|
76
|
+
|
|
77
|
+
if not os.path.exists(output_file):
|
|
78
|
+
return {
|
|
79
|
+
"total_rows": 0,
|
|
80
|
+
"unique_products": 0,
|
|
81
|
+
"products_with_images": 0,
|
|
82
|
+
"products_without_images": 0,
|
|
83
|
+
"issues": [f"Output file not found: {output_file}"]
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
rows = []
|
|
87
|
+
with open(output_file, "r", encoding="utf-8") as f:
|
|
88
|
+
for line in f:
|
|
89
|
+
if line.strip():
|
|
90
|
+
rows.append(json.loads(line))
|
|
91
|
+
|
|
92
|
+
total_rows = len(rows)
|
|
93
|
+
|
|
94
|
+
# Check row count consistency
|
|
95
|
+
if total_rows == 0:
|
|
96
|
+
issues.append("[ERROR] No rows returned")
|
|
97
|
+
|
|
98
|
+
# Check for missing images (should have images for products with checked=1)
|
|
99
|
+
products_with_images = set()
|
|
100
|
+
products_without_images = set()
|
|
101
|
+
|
|
102
|
+
for row in rows:
|
|
103
|
+
product_id = row.get("product_id")
|
|
104
|
+
image = row.get("image")
|
|
105
|
+
|
|
106
|
+
if image is None:
|
|
107
|
+
products_without_images.add(product_id)
|
|
108
|
+
else:
|
|
109
|
+
products_with_images.add(product_id)
|
|
110
|
+
|
|
111
|
+
# Check for duplicate product_ids (should have multiple rows per product if multiple images)
|
|
112
|
+
product_counts = {}
|
|
113
|
+
for row in rows:
|
|
114
|
+
pid = row.get("product_id")
|
|
115
|
+
product_counts[pid] = product_counts.get(pid, 0) + 1
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
"total_rows": total_rows,
|
|
119
|
+
"unique_products": len(product_counts),
|
|
120
|
+
"products_with_images": len(products_with_images),
|
|
121
|
+
"products_without_images": len(products_without_images),
|
|
122
|
+
"issues": issues
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def compare_results(all_results):
|
|
127
|
+
"""Compare results across all configurations to ensure consistency."""
|
|
128
|
+
valid_results = [r for r in all_results if "error" not in r and r.get("rows", 0) > 0]
|
|
129
|
+
|
|
130
|
+
if len(valid_results) < 2:
|
|
131
|
+
return {"consistent": True, "issues": []}
|
|
132
|
+
|
|
133
|
+
# Get row counts
|
|
134
|
+
row_counts = [r["rows"] for r in valid_results]
|
|
135
|
+
unique_products = [r.get("analysis", {}).get("unique_products", 0) for r in valid_results]
|
|
136
|
+
|
|
137
|
+
issues = []
|
|
138
|
+
|
|
139
|
+
# Group configurations by expected behavior
|
|
140
|
+
# IMPORTANT: "Filter pushdown" and "column pruning" are performance optimizations.
|
|
141
|
+
# They should NOT change the final output row count for the same SQL query.
|
|
142
|
+
#
|
|
143
|
+
# Configs 1-4: No pushdown/pruning protocol (WHERE applied after join in engine)
|
|
144
|
+
# Configs 5-6: Pushdown/pruning protocol enabled (WHERE can be applied while scanning)
|
|
145
|
+
# Config 7: first_match_only changes semantics (may reduce duplicate joined rows)
|
|
146
|
+
|
|
147
|
+
baseline_configs = [r for r in valid_results if "Merge Join" in r['name'] or "Lookup Join" in r['name'] or "Polars Join" in r['name'] or "MMAP Join" in r['name']]
|
|
148
|
+
optimized_configs = [r for r in valid_results if "Column Pruning" in r['name'] or "Filter Pushdown" in r['name']]
|
|
149
|
+
first_match_configs = [r for r in valid_results if "All Optimizations" in r['name']]
|
|
150
|
+
|
|
151
|
+
# Check consistency within baseline configs (should all return same)
|
|
152
|
+
if len(baseline_configs) > 1:
|
|
153
|
+
baseline_row_counts = [r["rows"] for r in baseline_configs]
|
|
154
|
+
if len(set(baseline_row_counts)) > 1:
|
|
155
|
+
issues.append(f"[WARNING] Baseline configs row count mismatch: {dict(zip([r['name'] for r in baseline_configs], baseline_row_counts))}")
|
|
156
|
+
|
|
157
|
+
# Check consistency within optimized configs (should all return same)
|
|
158
|
+
if len(optimized_configs) > 1:
|
|
159
|
+
optimized_row_counts = [r["rows"] for r in optimized_configs]
|
|
160
|
+
if len(set(optimized_row_counts)) > 1:
|
|
161
|
+
issues.append(f"[WARNING] Optimized configs row count mismatch: {dict(zip([r['name'] for r in optimized_configs], optimized_row_counts))}")
|
|
162
|
+
|
|
163
|
+
# Check that first_match configs return fewer rows than optimized (due to first_match_only)
|
|
164
|
+
if optimized_configs and first_match_configs:
|
|
165
|
+
optimized_avg = sum(r["rows"] for r in optimized_configs) / len(optimized_configs)
|
|
166
|
+
first_match_avg = sum(r["rows"] for r in first_match_configs) / len(first_match_configs)
|
|
167
|
+
if first_match_avg >= optimized_avg:
|
|
168
|
+
issues.append(f"[WARNING] First match configs should return fewer rows, but got {first_match_avg:.0f} vs optimized {optimized_avg:.0f}")
|
|
169
|
+
|
|
170
|
+
# Compare actual data content (sample first 100 rows from each)
|
|
171
|
+
if len(valid_results) > 1:
|
|
172
|
+
sample_data = {}
|
|
173
|
+
for result in valid_results:
|
|
174
|
+
if result.get("output_file") and os.path.exists(result["output_file"]):
|
|
175
|
+
samples = []
|
|
176
|
+
with open(result["output_file"], "r", encoding="utf-8") as f:
|
|
177
|
+
for i, line in enumerate(f):
|
|
178
|
+
if i >= 100:
|
|
179
|
+
break
|
|
180
|
+
if line.strip():
|
|
181
|
+
samples.append(json.loads(line))
|
|
182
|
+
sample_data[result["name"]] = samples
|
|
183
|
+
|
|
184
|
+
# Compare samples
|
|
185
|
+
if len(sample_data) > 1:
|
|
186
|
+
first_config = list(sample_data.keys())[0]
|
|
187
|
+
first_samples = sample_data[first_config]
|
|
188
|
+
|
|
189
|
+
for config_name, samples in list(sample_data.items())[1:]:
|
|
190
|
+
if len(samples) != len(first_samples):
|
|
191
|
+
issues.append(f"[WARNING] Sample size mismatch: {first_config} has {len(first_samples)} rows, {config_name} has {len(samples)} rows")
|
|
192
|
+
else:
|
|
193
|
+
# Compare product_ids
|
|
194
|
+
first_pids = sorted([r.get("product_id") for r in first_samples])
|
|
195
|
+
other_pids = sorted([r.get("product_id") for r in samples])
|
|
196
|
+
if first_pids != other_pids:
|
|
197
|
+
issues.append(f"[WARNING] Product ID mismatch between {first_config} and {config_name}")
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
"consistent": len(issues) == 0,
|
|
201
|
+
"issues": issues,
|
|
202
|
+
"row_counts": dict(zip([r['name'] for r in valid_results], row_counts)),
|
|
203
|
+
"unique_products": dict(zip([r['name'] for r in valid_results], unique_products))
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def run_benchmark(name, engine_config, source_config, query, products_file, images_file):
|
|
208
|
+
"""
|
|
209
|
+
Run a benchmark with specific configuration.
|
|
210
|
+
|
|
211
|
+
Returns:
|
|
212
|
+
dict with results: rows, time_seconds, peak_memory_mb, avg_cpu_percent
|
|
213
|
+
"""
|
|
214
|
+
print(f"\n{'='*70}")
|
|
215
|
+
print(f"CONFIGURATION: {name}")
|
|
216
|
+
print(f"{'='*70}")
|
|
217
|
+
print(f"Engine config: {engine_config}")
|
|
218
|
+
print(f"Source config: {source_config}")
|
|
219
|
+
print()
|
|
220
|
+
|
|
221
|
+
# Initialize engine
|
|
222
|
+
engine = Engine(**engine_config)
|
|
223
|
+
|
|
224
|
+
# Register sources
|
|
225
|
+
products_source_fn = source_config.get("products_fn", lambda: load_jsonl_file(products_file))
|
|
226
|
+
images_source_fn = source_config.get("images_fn", lambda: load_jsonl_file(images_file))
|
|
227
|
+
|
|
228
|
+
engine.register(
|
|
229
|
+
"products",
|
|
230
|
+
products_source_fn,
|
|
231
|
+
**source_config.get("products_metadata", {})
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
engine.register(
|
|
235
|
+
"images",
|
|
236
|
+
images_source_fn,
|
|
237
|
+
**source_config.get("images_metadata", {})
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
# Measure baseline memory
|
|
241
|
+
baseline_memory = get_memory_usage()
|
|
242
|
+
|
|
243
|
+
# Start CPU monitoring
|
|
244
|
+
cpu_samples = []
|
|
245
|
+
|
|
246
|
+
# Execute query and measure
|
|
247
|
+
start_time = time.time()
|
|
248
|
+
peak_memory = baseline_memory
|
|
249
|
+
row_count = 0
|
|
250
|
+
|
|
251
|
+
# Prepare output file name
|
|
252
|
+
safe_name = name.lower().replace(" ", "_").replace(".", "").replace("(", "").replace(")", "").replace("+", "_")
|
|
253
|
+
output_file = f"results_{safe_name}.jsonl"
|
|
254
|
+
output_rows = []
|
|
255
|
+
|
|
256
|
+
try:
|
|
257
|
+
for row in engine.query(query):
|
|
258
|
+
row_count += 1
|
|
259
|
+
output_rows.append(row) # Store for export
|
|
260
|
+
|
|
261
|
+
# Monitor memory
|
|
262
|
+
current_memory = get_memory_usage()
|
|
263
|
+
if current_memory > peak_memory:
|
|
264
|
+
peak_memory = current_memory
|
|
265
|
+
|
|
266
|
+
# Sample CPU every 1000 rows
|
|
267
|
+
if row_count % 1000 == 0:
|
|
268
|
+
cpu_samples.append(get_cpu_percent())
|
|
269
|
+
|
|
270
|
+
# Limit output for very large result sets
|
|
271
|
+
if row_count >= 1000000: # Cap at 1M rows for testing
|
|
272
|
+
print(f" [INFO] Capped at 1M rows for performance testing")
|
|
273
|
+
break
|
|
274
|
+
|
|
275
|
+
elapsed_time = time.time() - start_time
|
|
276
|
+
|
|
277
|
+
# Calculate average CPU
|
|
278
|
+
avg_cpu = sum(cpu_samples) / len(cpu_samples) if cpu_samples else 0
|
|
279
|
+
|
|
280
|
+
# Memory overhead
|
|
281
|
+
memory_overhead = peak_memory - baseline_memory
|
|
282
|
+
|
|
283
|
+
# Export results to JSONL file
|
|
284
|
+
export_start = time.time()
|
|
285
|
+
with open(output_file, "w", encoding="utf-8") as f:
|
|
286
|
+
for row in output_rows:
|
|
287
|
+
f.write(json.dumps(row, ensure_ascii=False) + "\n")
|
|
288
|
+
export_time = time.time() - export_start
|
|
289
|
+
|
|
290
|
+
file_size_mb = os.path.getsize(output_file) / (1024 * 1024)
|
|
291
|
+
|
|
292
|
+
# Analyze results (calculate expected_products_checked_1 from products_file)
|
|
293
|
+
expected_products_checked_1 = sum(
|
|
294
|
+
1 for line in open(products_file)
|
|
295
|
+
if line.strip() and json.loads(line).get("checked") == 1
|
|
296
|
+
)
|
|
297
|
+
analysis = analyze_results(output_file, expected_products_checked_1)
|
|
298
|
+
|
|
299
|
+
results = {
|
|
300
|
+
"name": name,
|
|
301
|
+
"rows": row_count,
|
|
302
|
+
"time_seconds": elapsed_time,
|
|
303
|
+
"peak_memory_mb": peak_memory,
|
|
304
|
+
"baseline_memory_mb": baseline_memory,
|
|
305
|
+
"memory_overhead_mb": memory_overhead,
|
|
306
|
+
"avg_cpu_percent": avg_cpu,
|
|
307
|
+
"rows_per_second": row_count / elapsed_time if elapsed_time > 0 else 0,
|
|
308
|
+
"output_file": output_file,
|
|
309
|
+
"output_file_size_mb": file_size_mb,
|
|
310
|
+
"analysis": analysis
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
print(f" Results:")
|
|
314
|
+
print(f" Rows processed: {row_count:,}")
|
|
315
|
+
print(f" Unique products: {analysis['unique_products']}")
|
|
316
|
+
print(f" Products with images: {analysis['products_with_images']}")
|
|
317
|
+
print(f" Products without images: {analysis['products_without_images']}")
|
|
318
|
+
print(f" Time: {elapsed_time:.2f} seconds")
|
|
319
|
+
print(f" Speed: {results['rows_per_second']:,.0f} rows/second")
|
|
320
|
+
print(f" Peak memory: {peak_memory:.2f} MB")
|
|
321
|
+
print(f" Memory overhead: {memory_overhead:.2f} MB")
|
|
322
|
+
print(f" Avg CPU: {avg_cpu:.1f}%")
|
|
323
|
+
print(f" Exported to: {output_file} ({file_size_mb:.2f} MB)")
|
|
324
|
+
|
|
325
|
+
if analysis['issues']:
|
|
326
|
+
print(f" [WARNING] Issues found:")
|
|
327
|
+
for issue in analysis['issues']:
|
|
328
|
+
print(f" {issue}")
|
|
329
|
+
|
|
330
|
+
return results
|
|
331
|
+
|
|
332
|
+
except Exception as e:
|
|
333
|
+
print(f" [ERROR] {e}")
|
|
334
|
+
import traceback
|
|
335
|
+
traceback.print_exc()
|
|
336
|
+
return {
|
|
337
|
+
"name": name,
|
|
338
|
+
"error": str(e),
|
|
339
|
+
"rows": 0,
|
|
340
|
+
"time_seconds": 0,
|
|
341
|
+
"peak_memory_mb": 0,
|
|
342
|
+
"memory_overhead_mb": 0,
|
|
343
|
+
"avg_cpu_percent": 0,
|
|
344
|
+
"rows_per_second": 0,
|
|
345
|
+
"output_file": None,
|
|
346
|
+
"output_file_size_mb": 0,
|
|
347
|
+
"analysis": {"issues": [f"Error: {str(e)}"]}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
def main():
|
|
352
|
+
products_file = "products_3_1k.jsonl"
|
|
353
|
+
images_file = "images_3_1k.jsonl"
|
|
354
|
+
|
|
355
|
+
# Check if files exist
|
|
356
|
+
if not os.path.exists(products_file):
|
|
357
|
+
print(f"[ERROR] File not found: {products_file}")
|
|
358
|
+
print("Run: python generate_test_data_100k.py")
|
|
359
|
+
return
|
|
360
|
+
|
|
361
|
+
if not os.path.exists(images_file):
|
|
362
|
+
print(f"[ERROR] File not found: {images_file}")
|
|
363
|
+
print("Run: python generate_test_data_100k.py")
|
|
364
|
+
return
|
|
365
|
+
|
|
366
|
+
# Calculate expected values
|
|
367
|
+
products_checked_1 = sum(
|
|
368
|
+
1 for line in open(products_file)
|
|
369
|
+
if line.strip() and json.loads(line).get("checked") == 1
|
|
370
|
+
)
|
|
371
|
+
|
|
372
|
+
# Build images index
|
|
373
|
+
images_by_product = {}
|
|
374
|
+
for line in open(images_file):
|
|
375
|
+
if line.strip():
|
|
376
|
+
img = json.loads(line)
|
|
377
|
+
pid = img.get("product_id")
|
|
378
|
+
if pid not in images_by_product:
|
|
379
|
+
images_by_product[pid] = []
|
|
380
|
+
images_by_product[pid].append(img)
|
|
381
|
+
|
|
382
|
+
expected_rows = sum(
|
|
383
|
+
len(images_by_product.get(json.loads(line).get("product_id"), []))
|
|
384
|
+
for line in open(products_file)
|
|
385
|
+
if line.strip() and json.loads(line).get("checked") == 1
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
# Query to test
|
|
389
|
+
query = """
|
|
390
|
+
SELECT
|
|
391
|
+
products.product_id,
|
|
392
|
+
products.product_sku,
|
|
393
|
+
products.title,
|
|
394
|
+
images.image,
|
|
395
|
+
images.image_type
|
|
396
|
+
FROM products
|
|
397
|
+
LEFT JOIN images ON products.product_id = images.product_id
|
|
398
|
+
WHERE products.checked = 1
|
|
399
|
+
"""
|
|
400
|
+
|
|
401
|
+
print("=" * 70)
|
|
402
|
+
print("COMPREHENSIVE BENCHMARK: All Engine Configurations")
|
|
403
|
+
print("=" * 70)
|
|
404
|
+
print()
|
|
405
|
+
print(f"Data files:")
|
|
406
|
+
print(f" Products: {products_file}")
|
|
407
|
+
print(f" Images: {images_file}")
|
|
408
|
+
print()
|
|
409
|
+
print(f"Expected:")
|
|
410
|
+
print(f" Products with checked=1: {products_checked_1}")
|
|
411
|
+
print(f" Expected joined rows: ~{expected_rows}")
|
|
412
|
+
print()
|
|
413
|
+
print(f"Query:")
|
|
414
|
+
print(query)
|
|
415
|
+
print()
|
|
416
|
+
|
|
417
|
+
# Define all configurations to test
|
|
418
|
+
configurations = [
|
|
419
|
+
{
|
|
420
|
+
"name": "1. Merge Join (Sorted Data)",
|
|
421
|
+
"engine_config": {
|
|
422
|
+
"debug": False,
|
|
423
|
+
"use_polars": False,
|
|
424
|
+
"first_match_only": False
|
|
425
|
+
},
|
|
426
|
+
"source_config": {
|
|
427
|
+
"products_fn": lambda: load_jsonl_file(products_file),
|
|
428
|
+
"images_fn": lambda: load_jsonl_file(images_file),
|
|
429
|
+
"products_metadata": {"ordered_by": "product_id"},
|
|
430
|
+
"images_metadata": {"ordered_by": "product_id"}
|
|
431
|
+
}
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
"name": "2. Lookup Join (Default Python)",
|
|
435
|
+
"engine_config": {
|
|
436
|
+
"debug": False,
|
|
437
|
+
"use_polars": False,
|
|
438
|
+
"first_match_only": False
|
|
439
|
+
},
|
|
440
|
+
"source_config": {
|
|
441
|
+
"products_fn": lambda: load_jsonl_file(products_file),
|
|
442
|
+
"images_fn": lambda: load_jsonl_file(images_file),
|
|
443
|
+
"products_metadata": {},
|
|
444
|
+
"images_metadata": {}
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
"name": "3. Polars Join",
|
|
449
|
+
"engine_config": {
|
|
450
|
+
"debug": False,
|
|
451
|
+
"use_polars": True,
|
|
452
|
+
"first_match_only": False
|
|
453
|
+
},
|
|
454
|
+
"source_config": {
|
|
455
|
+
"products_fn": lambda: load_jsonl_file(products_file),
|
|
456
|
+
"images_fn": lambda: load_jsonl_file(images_file),
|
|
457
|
+
"products_metadata": {},
|
|
458
|
+
"images_metadata": {}
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
"name": "4. MMAP Join",
|
|
463
|
+
"engine_config": {
|
|
464
|
+
"debug": False,
|
|
465
|
+
"use_polars": False,
|
|
466
|
+
"first_match_only": False
|
|
467
|
+
},
|
|
468
|
+
"source_config": {
|
|
469
|
+
"products_fn": lambda: load_jsonl_file(products_file),
|
|
470
|
+
"images_fn": lambda: load_jsonl_file(images_file),
|
|
471
|
+
"products_metadata": {"filename": products_file},
|
|
472
|
+
"images_metadata": {"filename": images_file}
|
|
473
|
+
}
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
"name": "5. Polars + Column Pruning",
|
|
477
|
+
"engine_config": {
|
|
478
|
+
"debug": False,
|
|
479
|
+
"use_polars": True,
|
|
480
|
+
"first_match_only": False
|
|
481
|
+
},
|
|
482
|
+
"source_config": {
|
|
483
|
+
"products_fn": lambda dynamic_where=None, dynamic_columns=None: load_jsonl_file(
|
|
484
|
+
products_file, dynamic_where=dynamic_where, dynamic_columns=dynamic_columns
|
|
485
|
+
),
|
|
486
|
+
"images_fn": lambda dynamic_where=None, dynamic_columns=None: load_jsonl_file(
|
|
487
|
+
images_file, dynamic_where=dynamic_where, dynamic_columns=dynamic_columns
|
|
488
|
+
),
|
|
489
|
+
"products_metadata": {},
|
|
490
|
+
"images_metadata": {}
|
|
491
|
+
}
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
"name": "6. Polars + Filter Pushdown",
|
|
495
|
+
"engine_config": {
|
|
496
|
+
"debug": False,
|
|
497
|
+
"use_polars": True,
|
|
498
|
+
"first_match_only": False
|
|
499
|
+
},
|
|
500
|
+
"source_config": {
|
|
501
|
+
"products_fn": lambda dynamic_where=None, dynamic_columns=None: load_jsonl_file(
|
|
502
|
+
products_file, dynamic_where=dynamic_where, dynamic_columns=dynamic_columns
|
|
503
|
+
),
|
|
504
|
+
"images_fn": lambda dynamic_where=None, dynamic_columns=None: load_jsonl_file(
|
|
505
|
+
images_file, dynamic_where=dynamic_where, dynamic_columns=dynamic_columns
|
|
506
|
+
),
|
|
507
|
+
"products_metadata": {},
|
|
508
|
+
"images_metadata": {}
|
|
509
|
+
}
|
|
510
|
+
},
|
|
511
|
+
{
|
|
512
|
+
"name": "7. All Optimizations Combined",
|
|
513
|
+
"engine_config": {
|
|
514
|
+
"debug": False,
|
|
515
|
+
"use_polars": True,
|
|
516
|
+
"first_match_only": True
|
|
517
|
+
},
|
|
518
|
+
"source_config": {
|
|
519
|
+
"products_fn": lambda dynamic_where=None, dynamic_columns=None: load_jsonl_file(
|
|
520
|
+
products_file, dynamic_where=dynamic_where, dynamic_columns=dynamic_columns
|
|
521
|
+
),
|
|
522
|
+
"images_fn": lambda dynamic_where=None, dynamic_columns=None: load_jsonl_file(
|
|
523
|
+
images_file, dynamic_where=dynamic_where, dynamic_columns=dynamic_columns
|
|
524
|
+
),
|
|
525
|
+
"products_metadata": {},
|
|
526
|
+
"images_metadata": {}
|
|
527
|
+
}
|
|
528
|
+
},
|
|
529
|
+
]
|
|
530
|
+
|
|
531
|
+
# Run all benchmarks
|
|
532
|
+
all_results = []
|
|
533
|
+
for config in configurations:
|
|
534
|
+
result = run_benchmark(
|
|
535
|
+
config["name"],
|
|
536
|
+
config["engine_config"],
|
|
537
|
+
config["source_config"],
|
|
538
|
+
query,
|
|
539
|
+
products_file,
|
|
540
|
+
images_file
|
|
541
|
+
)
|
|
542
|
+
all_results.append(result)
|
|
543
|
+
|
|
544
|
+
# Small delay between tests
|
|
545
|
+
time.sleep(1)
|
|
546
|
+
|
|
547
|
+
# Print summary
|
|
548
|
+
print()
|
|
549
|
+
print("=" * 70)
|
|
550
|
+
print("BENCHMARK SUMMARY")
|
|
551
|
+
print("=" * 70)
|
|
552
|
+
print()
|
|
553
|
+
print(f"{'Configuration':<40} {'Rows':>12} {'Time (s)':>10} {'Memory (MB)':>12} {'CPU %':>8} {'Rows/s':>12} {'Output File':<30}")
|
|
554
|
+
print("-" * 130)
|
|
555
|
+
|
|
556
|
+
for result in all_results:
|
|
557
|
+
if "error" in result:
|
|
558
|
+
print(f"{result['name']:<40} {'ERROR':>12} {'':>30}")
|
|
559
|
+
else:
|
|
560
|
+
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"
|
|
561
|
+
print(f"{result['name']:<40} {result['rows']:>12,} {result['time_seconds']:>10.2f} "
|
|
562
|
+
f"{result['memory_overhead_mb']:>12.2f} {result['avg_cpu_percent']:>8.1f} "
|
|
563
|
+
f"{result['rows_per_second']:>12,.0f} {output_info:<30}")
|
|
564
|
+
|
|
565
|
+
print()
|
|
566
|
+
print("=" * 70)
|
|
567
|
+
print("RESULT VALIDATION")
|
|
568
|
+
print("=" * 70)
|
|
569
|
+
print()
|
|
570
|
+
|
|
571
|
+
# Compare results across configurations
|
|
572
|
+
comparison = compare_results(all_results)
|
|
573
|
+
|
|
574
|
+
if comparison["consistent"]:
|
|
575
|
+
print("[OK] All configurations returned consistent results!")
|
|
576
|
+
print(f" Row counts: {comparison['row_counts']}")
|
|
577
|
+
print(f" Unique products: {comparison['unique_products']}")
|
|
578
|
+
else:
|
|
579
|
+
print("[WARNING] Some inconsistencies found between configurations:")
|
|
580
|
+
for issue in comparison["issues"]:
|
|
581
|
+
print(f" {issue}")
|
|
582
|
+
print()
|
|
583
|
+
print(" Row counts by configuration:")
|
|
584
|
+
for name, count in comparison['row_counts'].items():
|
|
585
|
+
print(f" {name}: {count:,}")
|
|
586
|
+
|
|
587
|
+
# Explain expected differences
|
|
588
|
+
print()
|
|
589
|
+
print(" Expected differences:")
|
|
590
|
+
print(" - Configs 1-4: No filter pushdown to source; WHERE is evaluated in-engine after join")
|
|
591
|
+
print(" - Configs 5-6: Filter pushdown/column pruning enabled; WHERE may be applied while scanning (same final rows, less work)")
|
|
592
|
+
print(" - Config 7: first_match_only enabled; may return fewer rows (1 match per product)")
|
|
593
|
+
|
|
594
|
+
print()
|
|
595
|
+
print("=" * 70)
|
|
596
|
+
print("RECOMMENDATIONS")
|
|
597
|
+
print("=" * 70)
|
|
598
|
+
print()
|
|
599
|
+
|
|
600
|
+
# Find best configuration for each metric
|
|
601
|
+
valid_results = [r for r in all_results if "error" not in r]
|
|
602
|
+
|
|
603
|
+
if valid_results:
|
|
604
|
+
fastest = min(valid_results, key=lambda x: x["time_seconds"])
|
|
605
|
+
lowest_memory = min(valid_results, key=lambda x: x["memory_overhead_mb"])
|
|
606
|
+
highest_throughput = max(valid_results, key=lambda x: x["rows_per_second"])
|
|
607
|
+
|
|
608
|
+
print(f"Fastest: {fastest['name']} ({fastest['time_seconds']:.2f}s)")
|
|
609
|
+
print(f"Lowest Memory: {lowest_memory['name']} ({lowest_memory['memory_overhead_mb']:.2f} MB)")
|
|
610
|
+
print(f"Highest Throughput: {highest_throughput['name']} ({highest_throughput['rows_per_second']:,.0f} rows/s)")
|
|
611
|
+
print()
|
|
612
|
+
print("For 100K+ records:")
|
|
613
|
+
print(" - Use Merge Join if data is sorted (fastest + lowest memory)")
|
|
614
|
+
print(" - Use MMAP Join if data is not sorted (low memory)")
|
|
615
|
+
print(" - Use Polars + optimizations for best throughput")
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
if __name__ == "__main__":
|
|
619
|
+
main()
|