Repository navigation
Split EU trade SQL for more than 5 countries into several statements - #134
Merged
Merged
Conversation
The FactIQ API now accepts at most 5 Eurostat Comext country schemas in one SQL statement that reads data_points. comext_sql.py now prints one statement per group of at most 5 reporters when a request names more (or "all"), each with the schema to run it with, and a header that says to run them one after another and how to combine the results. Requests for 5 or fewer reporters print the same SQL as before. The SQL guide no longer says that a union over all 27 member schemas finishes inside the 30-second limit. It now states the 5-schema limit. Version 0.44.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
comext_sql.pynow splits a request for more than 5 EU reporter countries into several SQL statements of at most 5 countries each. The FactIQ API is being changed to refuse a single statement that reads trade data from more than 5 Eurostat Comext country schemas, because such statements did not finish inside the 30-second limit. Requests for 5 or fewer countries print exactly the same SQL as before.The problem: the generator and the guide led clients into time-outs
For a request such as
--reporters all, the generator printed oneUNION ALLstatement over all 27 country schemas. The SQL guide also said that such a union "completes well within the 30-second limit". That is not true: a read of trade data scans every row of each country's data after the start date, even for exact series ids, so the time grows with the number of countries and the date range. Statements over many countries ran past the limit.The fix: one statement per group of at most 5 countries
comext_sql.py total,productsandtrendprint one statement per group of at most 5 reporters when a request names more. The groups are as even as possible (27 countries give 6 statements of 5, 5, 5, 4, 4 and 4).products, each statement returns its top 50 codes so that the combined top list can be built from them. The header says that a code missing from some statements has a total that is a lower bound.Before and after, same request
Input:
comext_sql.py total --reporters de,fr,it,es,nl,pl --partner cn --flow imports --start 2025-01 --end 2025-12(theSELECTandWHERElines inside each branch are left out here; they did not change).Before: one statement over 6 schemas, which the API will refuse.
After: two statements of 3 schemas each.
Details
total,total --monthly,productsandtrend, including weight and supplementary metrics.tests/test_trade_scripts.py:--reporters allgives 6 statements of at most 5 schemas for each command, each with its own schema line and all 27 countries read once; splitproductsstatements return 50 rows each; the domestic-reporter note stays when the partner is itself a member (26 reporters, 6 statements). All 84 tests pass.🤖 Generated with Claude Code