flyql 0.0.31__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 (104) hide show
  1. flyql-0.0.31/LICENSE +21 -0
  2. flyql-0.0.31/Makefile +23 -0
  3. flyql-0.0.31/PKG-INFO +26 -0
  4. flyql-0.0.31/e2e/conftest.py +48 -0
  5. flyql-0.0.31/e2e/test_clickhouse_e2e.py +347 -0
  6. flyql-0.0.31/e2e/test_matcher_e2e.py +86 -0
  7. flyql-0.0.31/e2e/test_postgresql_e2e.py +371 -0
  8. flyql-0.0.31/e2e/test_starrocks_e2e.py +445 -0
  9. flyql-0.0.31/flyql/__init__.py +39 -0
  10. flyql-0.0.31/flyql/columns/__init__.py +79 -0
  11. flyql-0.0.31/flyql/columns/char.py +93 -0
  12. flyql-0.0.31/flyql/columns/column.py +48 -0
  13. flyql-0.0.31/flyql/columns/constants.py +28 -0
  14. flyql-0.0.31/flyql/columns/exceptions.py +11 -0
  15. flyql-0.0.31/flyql/columns/parser.py +518 -0
  16. flyql-0.0.31/flyql/columns/state.py +22 -0
  17. flyql-0.0.31/flyql/columns/validator.py +163 -0
  18. flyql-0.0.31/flyql/core/__init__.py +28 -0
  19. flyql-0.0.31/flyql/core/char.py +82 -0
  20. flyql-0.0.31/flyql/core/column.py +49 -0
  21. flyql-0.0.31/flyql/core/constants.py +85 -0
  22. flyql-0.0.31/flyql/core/exceptions.py +16 -0
  23. flyql-0.0.31/flyql/core/expression.py +76 -0
  24. flyql-0.0.31/flyql/core/key.py +355 -0
  25. flyql-0.0.31/flyql/core/parser.py +1613 -0
  26. flyql-0.0.31/flyql/core/range.py +22 -0
  27. flyql-0.0.31/flyql/core/state.py +28 -0
  28. flyql-0.0.31/flyql/core/tree.py +43 -0
  29. flyql-0.0.31/flyql/core/validator.py +293 -0
  30. flyql-0.0.31/flyql/generators/README.md +2 -0
  31. flyql-0.0.31/flyql/generators/__init__.py +7 -0
  32. flyql-0.0.31/flyql/generators/clickhouse/__init__.py +4 -0
  33. flyql-0.0.31/flyql/generators/clickhouse/column.py +138 -0
  34. flyql-0.0.31/flyql/generators/clickhouse/constants.py +146 -0
  35. flyql-0.0.31/flyql/generators/clickhouse/generator.py +958 -0
  36. flyql-0.0.31/flyql/generators/clickhouse/helpers.py +86 -0
  37. flyql-0.0.31/flyql/generators/postgresql/__init__.py +4 -0
  38. flyql-0.0.31/flyql/generators/postgresql/column.py +90 -0
  39. flyql-0.0.31/flyql/generators/postgresql/constants.py +65 -0
  40. flyql-0.0.31/flyql/generators/postgresql/generator.py +954 -0
  41. flyql-0.0.31/flyql/generators/postgresql/helpers.py +76 -0
  42. flyql-0.0.31/flyql/generators/starrocks/__init__.py +4 -0
  43. flyql-0.0.31/flyql/generators/starrocks/column.py +112 -0
  44. flyql-0.0.31/flyql/generators/starrocks/constants.py +39 -0
  45. flyql-0.0.31/flyql/generators/starrocks/generator.py +1039 -0
  46. flyql-0.0.31/flyql/generators/starrocks/helpers.py +86 -0
  47. flyql-0.0.31/flyql/generators/transformer_helpers.py +76 -0
  48. flyql-0.0.31/flyql/matcher/__init__.py +7 -0
  49. flyql-0.0.31/flyql/matcher/evaluator.py +284 -0
  50. flyql-0.0.31/flyql/matcher/key.py +14 -0
  51. flyql-0.0.31/flyql/matcher/record.py +63 -0
  52. flyql-0.0.31/flyql/transformers/__init__.py +14 -0
  53. flyql-0.0.31/flyql/transformers/base.py +42 -0
  54. flyql-0.0.31/flyql/transformers/builtins.py +112 -0
  55. flyql-0.0.31/flyql/transformers/registry.py +34 -0
  56. flyql-0.0.31/flyql/types.py +12 -0
  57. flyql-0.0.31/flyql.egg-info/PKG-INFO +26 -0
  58. flyql-0.0.31/flyql.egg-info/SOURCES.txt +102 -0
  59. flyql-0.0.31/flyql.egg-info/dependency_links.txt +1 -0
  60. flyql-0.0.31/flyql.egg-info/requires.txt +1 -0
  61. flyql-0.0.31/flyql.egg-info/top_level.txt +4 -0
  62. flyql-0.0.31/pyproject.toml +104 -0
  63. flyql-0.0.31/setup.cfg +4 -0
  64. flyql-0.0.31/snippets/getting_started_columns.py +15 -0
  65. flyql-0.0.31/snippets/getting_started_generate_clickhouse.py +13 -0
  66. flyql-0.0.31/snippets/getting_started_match.py +14 -0
  67. flyql-0.0.31/snippets/getting_started_parse.py +4 -0
  68. flyql-0.0.31/snippets/getting_started_transformers.py +11 -0
  69. flyql-0.0.31/tests/__init__.py +0 -0
  70. flyql-0.0.31/tests/columns/__init__.py +0 -0
  71. flyql-0.0.31/tests/columns/helpers.py +48 -0
  72. flyql-0.0.31/tests/columns/test_parser.py +95 -0
  73. flyql-0.0.31/tests/columns/test_validator.py +109 -0
  74. flyql-0.0.31/tests/core/__init__.py +0 -0
  75. flyql-0.0.31/tests/core/helpers.py +231 -0
  76. flyql-0.0.31/tests/core/test_key.py +328 -0
  77. flyql-0.0.31/tests/core/test_parser.py +127 -0
  78. flyql-0.0.31/tests/core/test_parser_params.py +90 -0
  79. flyql-0.0.31/tests/core/test_positions.py +82 -0
  80. flyql-0.0.31/tests/core/test_typed_chars.py +200 -0
  81. flyql-0.0.31/tests/core/test_validator.py +296 -0
  82. flyql-0.0.31/tests/core/tests_char.py +109 -0
  83. flyql-0.0.31/tests/core/tests_expression.py +94 -0
  84. flyql-0.0.31/tests/core/tests_tree.py +100 -0
  85. flyql-0.0.31/tests/generators/clickhouse/test_column.py +149 -0
  86. flyql-0.0.31/tests/generators/clickhouse/test_generator.py +50 -0
  87. flyql-0.0.31/tests/generators/clickhouse/test_helpers.py +68 -0
  88. flyql-0.0.31/tests/generators/clickhouse/test_shared_data.py +607 -0
  89. flyql-0.0.31/tests/generators/postgresql/__init__.py +0 -0
  90. flyql-0.0.31/tests/generators/postgresql/test_shared_data.py +573 -0
  91. flyql-0.0.31/tests/generators/starrocks/test_starrocks_column.py +98 -0
  92. flyql-0.0.31/tests/generators/starrocks/test_starrocks_generator.py +60 -0
  93. flyql-0.0.31/tests/generators/starrocks/test_starrocks_helpers.py +73 -0
  94. flyql-0.0.31/tests/generators/starrocks/test_starrocks_shared_data.py +653 -0
  95. flyql-0.0.31/tests/matcher/__init__.py +0 -0
  96. flyql-0.0.31/tests/matcher/tests_matcher.py +219 -0
  97. flyql-0.0.31/tests/test_doc_snippets.py +42 -0
  98. flyql-0.0.31/tests/test_package_exports.py +107 -0
  99. flyql-0.0.31/tests/test_types.py +50 -0
  100. flyql-0.0.31/tests/transformers/__init__.py +0 -0
  101. flyql-0.0.31/tests/transformers/test_base.py +70 -0
  102. flyql-0.0.31/tests/transformers/test_builtins.py +135 -0
  103. flyql-0.0.31/tests/transformers/test_custom_registration.py +143 -0
  104. flyql-0.0.31/tests/transformers/test_registry.py +93 -0
flyql-0.0.31/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Ilia (HumanUser) Khomutov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
flyql-0.0.31/Makefile ADDED
@@ -0,0 +1,23 @@
1
+ all: test
2
+ install:
3
+ pip install -e .
4
+ pip install pytest black==26.3.1 mypy
5
+ fmt:
6
+ black .
7
+ fmt-test:
8
+ black --check .
9
+ pytest:
10
+ pytest
11
+ type-test:
12
+ mypy flyql/
13
+ lint:
14
+ pylint flyql/
15
+ test: fmt-test pytest type-test
16
+ coverage:
17
+ pytest --cov=flyql --cov-report=html --cov-report=term-missing
18
+ cleanup:
19
+ find . -name __pycache__ -type d -exec rm -rf {} +
20
+ rm -rf flyql.egg-info/
21
+ rm -rf build/
22
+ rm -rf htmlcov/
23
+ rm -rf .coverage
flyql-0.0.31/PKG-INFO ADDED
@@ -0,0 +1,26 @@
1
+ Metadata-Version: 2.4
2
+ Name: flyql
3
+ Version: 0.0.31
4
+ Summary: A lightweight, injection-proof query language for multi-dialect SQL generation
5
+ Author: Ilia (HumanUser) Khomutov
6
+ License: MIT License
7
+ Project-URL: Homepage, https://flyql.dev
8
+ Project-URL: Repository, https://github.com/iamtelescope/flyql.git
9
+ Project-URL: Issues, https://github.com/iamtelescope/flyql/issues
10
+ Project-URL: Documentation, https://docs.flyql.dev
11
+ Keywords: query,parser,ast,sql,clickhouse,filter
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: License :: OSI Approved :: MIT License
19
+ Classifier: Operating System :: OS Independent
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Topic :: Database
22
+ Classifier: Topic :: Text Processing :: Linguistic
23
+ Requires-Python: >=3.10
24
+ License-File: LICENSE
25
+ Requires-Dist: google-re2>=1.1
26
+ Dynamic: license-file
@@ -0,0 +1,48 @@
1
+ import json
2
+ import os
3
+ from pathlib import Path
4
+ from typing import Any
5
+
6
+
7
+ def pytest_sessionfinish(session: Any, exitstatus: int) -> None:
8
+ """Write JSON report if E2E_REPORT_JSON is set."""
9
+ report_path = os.environ.get("E2E_REPORT_JSON", "")
10
+ if not report_path:
11
+ return
12
+
13
+ all_results: list[dict[str, Any]] = []
14
+
15
+ try:
16
+ from test_clickhouse_e2e import _results as ch_results
17
+
18
+ all_results.extend(ch_results)
19
+ except ImportError:
20
+ pass
21
+
22
+ try:
23
+ from test_starrocks_e2e import _results as sr_results
24
+
25
+ all_results.extend(sr_results)
26
+ except ImportError:
27
+ pass
28
+
29
+ try:
30
+ from test_postgresql_e2e import _results as pg_results
31
+
32
+ all_results.extend(pg_results)
33
+ except ImportError:
34
+ pass
35
+
36
+ try:
37
+ from test_matcher_e2e import _results as matcher_results
38
+
39
+ all_results.extend(matcher_results)
40
+ except ImportError:
41
+ pass
42
+
43
+ if all_results:
44
+ report = {"language": "python", "results": all_results}
45
+ try:
46
+ Path(report_path).write_text(json.dumps(report, indent=2))
47
+ except OSError as e:
48
+ print(f"warn: could not write e2e report {report_path}: {e}")
@@ -0,0 +1,347 @@
1
+ """ClickHouse E2E tests for Python FlyQL generator.
2
+
3
+ Connects to a real ClickHouse instance, generates SQL from FlyQL queries
4
+ using the Python generator, executes the SQL, and validates returned IDs
5
+ match expected results from the shared test cases.
6
+
7
+ Outputs a JSON report compatible with the e2e runner when E2E_REPORT_JSON is set.
8
+ """
9
+
10
+ import json
11
+ import os
12
+ import sys
13
+ from pathlib import Path
14
+ from typing import Any
15
+
16
+ import pytest
17
+
18
+ # Add python/ to path so we can import flyql
19
+ sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
20
+
21
+ from flyql.core.parser import parse # noqa: E402
22
+ from flyql.generators.clickhouse.column import Column # noqa: E402
23
+ from flyql.generators.clickhouse.generator import (
24
+ to_sql_where,
25
+ to_sql_select,
26
+ ) # noqa: E402
27
+
28
+ REPO_ROOT = Path(__file__).resolve().parent.parent.parent
29
+ TEST_DATA_DIR = REPO_ROOT / "tests-data" / "e2e"
30
+
31
+ CH_HOST = os.environ.get("CLICKHOUSE_HOST", "localhost")
32
+ CH_HTTP_PORT = os.environ.get("CLICKHOUSE_HTTP_PORT", "18123")
33
+ CH_USER = os.environ.get("CLICKHOUSE_USER", "flyql")
34
+ CH_PASS = os.environ.get("CLICKHOUSE_PASSWORD", "flyql")
35
+
36
+ _results: list[dict[str, Any]] = []
37
+
38
+
39
+ def ch_query(sql: str) -> list[dict[str, Any]]:
40
+ """Execute a query against ClickHouse via HTTP interface."""
41
+ import urllib.request
42
+ import urllib.parse
43
+
44
+ params = urllib.parse.urlencode(
45
+ {
46
+ "user": CH_USER,
47
+ "password": CH_PASS,
48
+ "default_format": "JSONEachRow",
49
+ }
50
+ )
51
+ url = f"http://{CH_HOST}:{CH_HTTP_PORT}/?{params}"
52
+
53
+ req = urllib.request.Request(url, data=sql.encode("utf-8"), method="POST")
54
+ try:
55
+ with urllib.request.urlopen(req, timeout=10) as resp:
56
+ text = resp.read().decode("utf-8").strip()
57
+ except Exception as e:
58
+ raise RuntimeError(f"ClickHouse error: {e}") from e
59
+
60
+ if not text:
61
+ return []
62
+ return [json.loads(line) for line in text.split("\n")]
63
+
64
+
65
+ def load_json(path: Path) -> Any:
66
+ return json.loads(path.read_text())
67
+
68
+
69
+ def build_columns() -> dict[str, Column]:
70
+ col_data = load_json(TEST_DATA_DIR / "clickhouse" / "columns.json")
71
+ columns: dict[str, Column] = {}
72
+ for key, col in col_data["columns"].items():
73
+ columns[key] = Column(
74
+ name=col["name"],
75
+ jsonstring=col["jsonstring"],
76
+ _type=col["type"],
77
+ values=col.get("values"),
78
+ )
79
+ return columns
80
+
81
+
82
+ def build_join_columns() -> dict[str, Column]:
83
+ col_data = load_json(TEST_DATA_DIR / "clickhouse" / "join_columns.json")
84
+ columns: dict[str, Column] = {}
85
+ for key, col in col_data["columns"].items():
86
+ c = Column(
87
+ name=col["name"],
88
+ jsonstring=col.get("jsonstring", False),
89
+ _type=col["type"],
90
+ values=col.get("values"),
91
+ )
92
+ if col.get("raw_identifier"):
93
+ c.with_raw_identifier(col["raw_identifier"])
94
+ columns[key] = c
95
+ return columns
96
+
97
+
98
+ def load_test_cases() -> list[dict[str, Any]]:
99
+ data = load_json(TEST_DATA_DIR / "test_cases.json")
100
+ return [tc for tc in data["tests"] if "clickhouse" in tc["databases"]]
101
+
102
+
103
+ def load_join_test_cases() -> list[dict[str, Any]]:
104
+ data = load_json(TEST_DATA_DIR / "join_test_cases.json")
105
+ return [tc for tc in data["tests"] if "clickhouse" in tc["databases"]]
106
+
107
+
108
+ @pytest.fixture(scope="module")
109
+ def ch_available() -> bool:
110
+ try:
111
+ rows = ch_query("SELECT 1 AS ok")
112
+ return len(rows) > 0 and rows[0]["ok"] == 1
113
+ except Exception:
114
+ return False
115
+
116
+
117
+ @pytest.fixture(scope="module")
118
+ def columns() -> dict[str, Column]:
119
+ return build_columns()
120
+
121
+
122
+ def ids_match(expected: list[int], got: list[int]) -> bool:
123
+ return sorted(expected) == sorted(got)
124
+
125
+
126
+ @pytest.mark.parametrize(
127
+ "name,flyql,expected_ids",
128
+ [(tc["name"], tc["flyql"], tc["expected_ids"]) for tc in load_test_cases()],
129
+ ids=[tc["name"] for tc in load_test_cases()],
130
+ )
131
+ def test_clickhouse_where(
132
+ ch_available: bool,
133
+ columns: dict[str, Column],
134
+ name: str,
135
+ flyql: str,
136
+ expected_ids: list[int],
137
+ ) -> None:
138
+ result: dict[str, Any] = {
139
+ "kind": "where",
140
+ "database": "clickhouse",
141
+ "name": name,
142
+ "flyql": flyql,
143
+ "sql": "",
144
+ "expected_ids": expected_ids,
145
+ "returned_ids": [],
146
+ "passed": False,
147
+ "error": "",
148
+ }
149
+
150
+ if not ch_available:
151
+ result["error"] = "ClickHouse not available"
152
+ _results.append(result)
153
+ pytest.skip("ClickHouse not available")
154
+ return
155
+
156
+ try:
157
+ parsed = parse(flyql)
158
+ sql_where = to_sql_where(parsed.current_node, columns)
159
+ result["sql"] = sql_where
160
+
161
+ query = f"SELECT id FROM flyql_e2e_test WHERE {sql_where} ORDER BY id"
162
+ rows = ch_query(query)
163
+ returned_ids = [r["id"] for r in rows]
164
+ result["returned_ids"] = returned_ids
165
+ result["passed"] = ids_match(expected_ids, returned_ids)
166
+
167
+ _results.append(result)
168
+ assert result["passed"], f"expected {expected_ids}, got {returned_ids}"
169
+ except Exception as e:
170
+ result["error"] = str(e)
171
+ _results.append(result)
172
+ raise
173
+
174
+
175
+ def load_select_test_cases() -> list[dict[str, Any]]:
176
+ data = load_json(TEST_DATA_DIR / "clickhouse" / "select_test_cases.json")
177
+ return data["tests"]
178
+
179
+
180
+ def load_join_select_test_cases() -> list[dict[str, Any]]:
181
+ data = load_json(TEST_DATA_DIR / "clickhouse" / "join_select_test_cases.json")
182
+ return data["tests"]
183
+
184
+
185
+ @pytest.mark.parametrize(
186
+ "name,select_columns,expected_rows",
187
+ [
188
+ (tc["name"], tc["select_columns"], tc["expected_rows"])
189
+ for tc in load_select_test_cases()
190
+ ],
191
+ ids=[tc["name"] for tc in load_select_test_cases()],
192
+ )
193
+ def test_clickhouse_select(
194
+ ch_available: bool,
195
+ columns: dict[str, Column],
196
+ name: str,
197
+ select_columns: str,
198
+ expected_rows: list[list[str]],
199
+ ) -> None:
200
+ result: dict[str, Any] = {
201
+ "kind": "select",
202
+ "database": "clickhouse",
203
+ "name": name,
204
+ "select_columns": select_columns,
205
+ "sql": "",
206
+ "expected_rows": expected_rows,
207
+ "returned_rows": [],
208
+ "passed": False,
209
+ "error": "",
210
+ }
211
+
212
+ if not ch_available:
213
+ result["error"] = "ClickHouse not available"
214
+ _results.append(result)
215
+ pytest.skip("ClickHouse not available")
216
+ return
217
+
218
+ try:
219
+ select_result = to_sql_select(select_columns, columns)
220
+ result["sql"] = select_result.sql
221
+
222
+ query = f"SELECT {select_result.sql} FROM flyql_e2e_test ORDER BY id"
223
+ rows = ch_query(query)
224
+ returned_rows = [
225
+ [str(v) if v is not None else "null" for v in row.values()] for row in rows
226
+ ]
227
+ result["returned_rows"] = returned_rows
228
+ result["passed"] = returned_rows == expected_rows
229
+
230
+ _results.append(result)
231
+ assert result["passed"], f"expected {expected_rows}, got {returned_rows}"
232
+ except Exception as e:
233
+ result["error"] = str(e)
234
+ _results.append(result)
235
+ raise
236
+
237
+
238
+ @pytest.fixture(scope="module")
239
+ def join_columns() -> dict[str, Column]:
240
+ return build_join_columns()
241
+
242
+
243
+ @pytest.mark.parametrize(
244
+ "name,flyql,expected_ids",
245
+ [(tc["name"], tc["flyql"], tc["expected_ids"]) for tc in load_join_test_cases()],
246
+ ids=[tc["name"] for tc in load_join_test_cases()],
247
+ )
248
+ def test_clickhouse_join(
249
+ ch_available: bool,
250
+ join_columns: dict[str, Column],
251
+ name: str,
252
+ flyql: str,
253
+ expected_ids: list[int],
254
+ ) -> None:
255
+ result: dict[str, Any] = {
256
+ "kind": "where",
257
+ "database": "clickhouse",
258
+ "name": name,
259
+ "flyql": flyql,
260
+ "sql": "",
261
+ "expected_ids": expected_ids,
262
+ "returned_ids": [],
263
+ "passed": False,
264
+ "error": "",
265
+ }
266
+
267
+ if not ch_available:
268
+ result["error"] = "ClickHouse not available"
269
+ _results.append(result)
270
+ pytest.skip("ClickHouse not available")
271
+ return
272
+
273
+ try:
274
+ parsed = parse(flyql)
275
+ sql_where = to_sql_where(parsed.current_node, join_columns)
276
+ result["sql"] = sql_where
277
+
278
+ query = f"SELECT t.id FROM flyql_e2e_test t INNER JOIN flyql_e2e_related r ON t.id = r.test_id WHERE {sql_where} ORDER BY t.id"
279
+ rows = ch_query(query)
280
+ returned_ids = [r["id"] for r in rows]
281
+ result["returned_ids"] = returned_ids
282
+ result["passed"] = ids_match(expected_ids, returned_ids)
283
+
284
+ _results.append(result)
285
+ assert result["passed"], f"expected {expected_ids}, got {returned_ids}"
286
+ except Exception as e:
287
+ result["error"] = str(e)
288
+ _results.append(result)
289
+ raise
290
+
291
+
292
+ @pytest.fixture(scope="module")
293
+ def join_select_columns() -> dict[str, Column]:
294
+ return build_join_columns()
295
+
296
+
297
+ @pytest.mark.parametrize(
298
+ "name,select_columns,expected_rows",
299
+ [
300
+ (tc["name"], tc["select_columns"], tc["expected_rows"])
301
+ for tc in load_join_select_test_cases()
302
+ ],
303
+ ids=[tc["name"] for tc in load_join_select_test_cases()],
304
+ )
305
+ def test_clickhouse_join_select(
306
+ ch_available: bool,
307
+ join_select_columns: dict[str, Column],
308
+ name: str,
309
+ select_columns: str,
310
+ expected_rows: list[list[str]],
311
+ ) -> None:
312
+ result: dict[str, Any] = {
313
+ "kind": "select",
314
+ "database": "clickhouse",
315
+ "name": name,
316
+ "select_columns": select_columns,
317
+ "sql": "",
318
+ "expected_rows": expected_rows,
319
+ "returned_rows": [],
320
+ "passed": False,
321
+ "error": "",
322
+ }
323
+
324
+ if not ch_available:
325
+ result["error"] = "ClickHouse not available"
326
+ _results.append(result)
327
+ pytest.skip("ClickHouse not available")
328
+ return
329
+
330
+ try:
331
+ select_result = to_sql_select(select_columns, join_select_columns)
332
+ result["sql"] = select_result.sql
333
+
334
+ query = f"SELECT {select_result.sql} FROM flyql_e2e_test t INNER JOIN flyql_e2e_related r ON t.id = r.test_id ORDER BY t.id"
335
+ rows = ch_query(query)
336
+ returned_rows = [
337
+ [str(v) if v is not None else "null" for v in row.values()] for row in rows
338
+ ]
339
+ result["returned_rows"] = returned_rows
340
+ result["passed"] = returned_rows == expected_rows
341
+
342
+ _results.append(result)
343
+ assert result["passed"], f"expected {expected_rows}, got {returned_rows}"
344
+ except Exception as e:
345
+ result["error"] = str(e)
346
+ _results.append(result)
347
+ raise
@@ -0,0 +1,86 @@
1
+ """Matcher E2E tests for Python FlyQL — in-memory evaluation parity with database results."""
2
+
3
+ import json
4
+ import sys
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+ import pytest
9
+
10
+ sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
11
+
12
+ from flyql.matcher.evaluator import Evaluator # noqa: E402
13
+ from flyql.matcher.record import Record # noqa: E402
14
+ from flyql.core.parser import parse # noqa: E402
15
+
16
+ REPO_ROOT = Path(__file__).resolve().parent.parent.parent
17
+ TEST_DATA_DIR = REPO_ROOT / "tests-data" / "e2e"
18
+
19
+ _results: list[dict[str, Any]] = []
20
+
21
+
22
+ def load_json(path: Path) -> Any:
23
+ return json.loads(path.read_text())
24
+
25
+
26
+ ROWS = load_json(TEST_DATA_DIR / "rows.json")["rows"]
27
+
28
+
29
+ def load_test_cases() -> list[dict[str, Any]]:
30
+ data = load_json(TEST_DATA_DIR / "test_cases.json")
31
+ return [
32
+ tc
33
+ for tc in data["tests"]
34
+ if not any(
35
+ x in tc["flyql"]
36
+ for x in [
37
+ "tags.",
38
+ "metadata.",
39
+ "meta_json.",
40
+ "hello*'",
41
+ "'*@",
42
+ "created_at<=",
43
+ ]
44
+ )
45
+ ]
46
+
47
+
48
+ def match_row(query: str, data: dict[str, Any]) -> bool:
49
+ result = parse(query)
50
+ evaluator = Evaluator()
51
+ record = Record(data)
52
+ return evaluator.evaluate(result.current_node, record)
53
+
54
+
55
+ def ids_match(expected: list[int], got: list[int]) -> bool:
56
+ return sorted(expected) == sorted(got)
57
+
58
+
59
+ @pytest.mark.parametrize(
60
+ "name,flyql,expected_ids",
61
+ [(tc["name"], tc["flyql"], tc["expected_ids"]) for tc in load_test_cases()],
62
+ ids=[tc["name"] for tc in load_test_cases()],
63
+ )
64
+ def test_matcher_where(name: str, flyql: str, expected_ids: list[int]) -> None:
65
+ result: dict[str, Any] = {
66
+ "kind": "where",
67
+ "database": "matcher",
68
+ "name": name,
69
+ "flyql": flyql,
70
+ "sql": "(in-memory)",
71
+ "expected_ids": expected_ids,
72
+ "returned_ids": [],
73
+ "passed": False,
74
+ "error": "",
75
+ }
76
+
77
+ try:
78
+ matched_ids = [row["id"] for row in ROWS if match_row(flyql, row)]
79
+ result["returned_ids"] = matched_ids
80
+ result["passed"] = ids_match(expected_ids, matched_ids)
81
+ _results.append(result)
82
+ assert result["passed"], f"expected {expected_ids}, got {matched_ids}"
83
+ except Exception as e:
84
+ result["error"] = str(e)
85
+ _results.append(result)
86
+ raise