A time series data federated query method

By implementing a time-series data federated query method within the time-series database query engine, the problems of data migration, time-series capability degradation, and time semantic inconsistency in cross-data source queries are solved. This enables efficient and accurate unified queries without data migration, reducing maintenance costs and query complexity.

CN123178479APending Publication Date: 2026-11-27TAOS DATA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611603009.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-16
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

Existing technologies suffer from problems such as high data migration costs, outdated data, difficulty in completing cross-source processing in a single query, degradation of external data time-series capabilities, high cost of table-by-table registration and maintenance, and inconsistency in time semantics across precision and time zones in unified queries, resulting in low query efficiency and inaccurate results.

Method used

The time-series database query engine implements a time-series data federated query method. It identifies external path expressions through the parser, generates a plan tree, and uses the optimizer to perform federated pushdown. It maps external heterogeneous databases to a unified namespace and conceptual model, and uses a single SQL statement to query local and external data sources simultaneously, realizing time-series semantic adaptation and computation pushdown, cross-source alignment and result consolidation.

Benefits of technology

It enables unified querying of local and external data sources without migrating external data, maintaining the time series analysis capability without degradation, ensuring the correctness and efficiency of query results, reducing the cost and maintenance complexity of cross-source access, and solving the problem of inconsistent timestamp accuracy and time zone semantics across sources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123178479A_ABST
    Figure CN123178479A_ABST
Patent Text Reader

Abstract

The application discloses a kind of time series data federation query method, comprising: parser reads external metadata and external source capability image by identifying external path expression in the SQL statement to be executed from metadata cache, and completes legality verification;Logical planner generates plan tree containing external scanning node;Optimizer executes federation pushdown according to external source capability image, traverses plan tree from bottom to top, obtains pushable operator and non-pushable upper operator, and harvests pushable operator into remote sub-plan;When executing federation query, external connector traverses remote sub-plan, converts time series database specific time series window semantics into external library standard SQL equivalent expression containing pushable operator according to target database dialect, pushes to remote, and uniformly converts external result returned by remote into internal data block;Non-pushable upper operator reads data from the internal data block, and continues to calculate the data read locally.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to time-series database query processing technology, specifically to a time-series data federated query method implemented within a time-series database query engine for unified querying of local time-series data and external heterogeneous data sources. Background Technology

[0002] Time-series databases typically focus on efficient writing and querying of locally stored time-series data, with their query engines organized around local storage formats, local time-partitioned indexes, and local metadata. However, in real-world business scenarios, data is inherently distributed: time-series measurement data is stored in time-series databases (such as TDengine / InfluxDB), device dimension tables and business ledgers are stored in relational databases (such as MySQL / PostgreSQL), and historical data may be stored in yet another location. Performing a unified analysis across these data sources presents significant challenges with current technologies.

[0003] For this type of unified query requirement across data sources, existing approximate approaches mainly fall into the following categories:

[0004] 1) Data migration (ETL) solution: External data is periodically and synchronously copied to the time series database through the ETL pipeline, and then queried in a unified manner.

[0005] 2) Application layer multi-step query scheme: The application connects to each data source separately, performs multiple round trip queries, and then concatenates, associates, and aggregates the results at the application layer.

[0006] 3) Traditional federated / external table solution: External data is accessed by "CREATE FOREIGN TABLE" and each table is declared once. If the structure changes, each table needs to be declared again.

[0007] The above approximation scheme has at least the following shortcomings:

[0008] 1) High cost of data migration and outdated data: long ETL links, doubled storage, and long-term pipeline maintenance required; data becomes outdated with the synchronization cycle, and analysis results are not real-time;

[0009] 2) Difficulty in completing cross-source processing within a single query: Application-layer multi-step solutions cannot uniformly complete external source identification, calculation pushdown, cross-source alignment, and result aggregation within a single SQL query; multiple round trips also bring data consistency risks.

[0010] 3) Degradation of time-series capabilities of external data: The time-series semantics such as time windows, PARTITION BY TBNAME, and TAGS that are unique to time-series databases cannot be directly expressed on relational databases. External data becomes a "second-class citizen" and its capabilities are downgraded.

[0011] 4) High cost of table-by-table registration and maintenance: Traditional external table solutions register tables as the unit of registration. If the database table structure changes, each table needs to be re-declared, which is difficult to adapt to time-series external databases with a large number of tables and frequent structural changes.

[0012] 5) Lack of localized pushdown and reliable fallback: The capabilities of operators / functions in various external libraries vary greatly and evolve with version. Existing solutions either "aggressively push down" leading to semantic errors or query failures, or "pull everything back to local" resulting in performance loss. There is a lack of a unified mechanism that "precisely push down based on library capabilities, safely roll back in case of failure, and does not require maintaining capability definitions for each version."

[0013] 6) Inconsistent time semantics across precision and time zones: The timestamp precision (ms / µs / ns) of different data sources has different meanings from the time zone. Cross-source comparison, JOIN, and window alignment are prone to losing precision or causing time zone ambiguity. Summary of the Invention

[0014] The purpose of this invention is to provide a time-series data federated query method, which integrates external heterogeneous data sources as first-class query objects within the time-series database query engine. This enables a single SQL query to uniformly query local time-series data and external data sources, and completes time-series semantic adaptation, computation pushdown, cross-source alignment, and result consolidation during the execution phase, achieving "zero data migration, no degradation of time-series capabilities, and a bottom line of correctness".

[0015] This invention provides a time-series data federated query method for accessing heterogeneous external databases with different functions and models as query objects of a time-series database. It uses a single SQL statement to simultaneously query local time-series data and data from one or more external heterogeneous databases. The method includes: mapping the external heterogeneous databases as external sources to a unified namespace, so that a single SQL statement can unambiguously mix references to local tables and tables from any number of external sources; and mapping the data models of each heterogeneous database to a unified conceptual system of the time-series database. This unified conceptual system includes: database, ordinary table, super table, sub-table, tag column, data column, and timestamp primary key.

[0016] Methods for querying local time-series data and data from one or more external heterogeneous databases simultaneously using a single SQL statement include:

[0017] The parser identifies external path expressions in the SQL statement to be executed, reads external metadata and external source capability profiles from the metadata cache, and performs legality verification.

[0018] The logic planner generates a plan tree containing external scan nodes;

[0019] The optimizer performs federated pushdown based on the external source capability profile, traverses the plan tree from bottom to top, obtains pushdown operators and non-pushdown upper-level operators, and harvests the pushdown operators into the remote sub-plans.

[0020] When executing federated queries, the external connector traverses remote sub-plans, converts the time-series window semantics specific to the time-series database into equivalent expressions of the external library's standard SQL containing pushdown operators according to the target database dialect, and pushes them down to the remote end. It also converts the external results returned by the remote end into internal data blocks. Non-pushdown upper-level operators read data from the internal data blocks and perform further calculations on the read data locally.

[0021] Preferably, external heterogeneous databases are mapped to a unified namespace as external sources, including: all external objects are addressed using the path source.[db|schema.]table; MySQL / InfluxDB middleware without schema concept is mapped to database, and PostgreSQL middleware with schema concept is mapped to schema; and the external source name does not conflict with the local database name.

[0022] Preferably, converting the time-series window semantics specific to the time-series database into equivalent expressions in the standard SQL of the external library includes: converting the INTERVAL rolling window to GROUP BY time buckets according to the inherent precision of the target library; dividing COUNT_WINDOW into buckets by row number; grouping STATE_WINDOW by marking state change points with the window function LAG and accumulating the window numbers using SUM() OVER; grouping SESSION_WINDOW by marking window breaks based on whether adjacent time intervals exceed the gap; and converting PARTITION BY TBNAME to grouping by all Tag columns on an external source with super table alignment semantics. This allows the non-time-series database to perform time window, count window, status window, and session window aggregation and grouping by sub-tables locally. The window function-based rewriting is based on the premise that the target library supports window functions and common table expressions. If the target library does not meet the requirements or there is no equivalent expression, it degenerates into local calculation with correct results.

[0023] Preferably, the external library standard SQL equivalent expression pushdown includes: a time-series federated computation pushdown method that uses a whitelist capability matrix of clauses / operators / functions to perform layer-by-layer gating based on dialect bitmasks, and recursively determines whether an operator can be pushed down based on the mappability of the expression. It also involves bottom-up, continuously harvesting pushable operators from the external scan node along the plan tree into the remote sub-plan, stopping only when the first non-pushable operator is reached, and pushing down complex structures such as nested queries / multi-way JOIN / UNION across clauses. The pushable operators include condition operators, grouping operators, window operators, aggregation operators, sorting operators, projection operators, restriction operators, same-origin JOIN operators, and subquery operators.

[0024] Preferably, the pushdown operator is pushed down under the assumption that the external database supports it. When execution fails, it uses a three-level progressive rollback method: function / operator / type level, clause level, and only scan fallback level. The part that is not supported is pulled back to the local machine. After rollback, it automatically replans and retryes. If it still fails within the upper limit, it switches to baseline scan fallback.

[0025] Preferably, the time-series data federated query method of the present invention further includes an error-driven runtime pushdown capability self-learning method, specifically: remote errors are attributed according to deterministic classification, errors are explicitly written to the process-level capability negative table for cross-session effect, and fuzzy errors are only written to the session-level overlay table and discarded after the query ends. Invariants such as "no repeated entries in the retry chain, no deletion after appending, no automatic clearing of static default items, and capping of retry limit" are used to ensure stable convergence of capability profiles and prevent occasional failures from polluting long-term capability cache.

[0026] Preferably, the external data source access method is source-level registration; after executing CREATE EXTERNAL SOURCE to register the remote database instance, all databases, tables and fields under the instance are automatically made accessible, without needing to register external tables one by one; each external source namespace is independent and isolated from each other.

[0027] Preferably, external sources are used as the management unit, and metadata self-consistency is maintained through "automatic discovery + on-demand lazy loading + error-driven automatic synchronization of schema changes + automatic timed refresh + forced refresh". For structural changes that will trigger remote mismatch errors, the latest schema will be automatically retrieved and the cache updated by the remote error driver, and the query will be re-executed with the latest schema. For structural changes that do not trigger remote mismatch errors, the cache will be synchronized with the external source after a refresh cycle by the periodically executed automatic timed refresh, so that such queries will automatically obtain the latest columns.

[0028] Preferably, the method involves using virtual table column references to point to external paths, weaving local time-series measurement columns and external static ledger columns into a unified logical table at the column level based on timestamps, and validating the timestamp primary key of the referenced external table before table creation.

[0029] Preferably, the time-series data federated query method also includes a time semantic self-consistent method for time-series federated queries, specifically including: each timestamp column maintains its inherent precision from the data source and is transmitted independently column by column along the entire link; when comparing / joining / aligning across precisions, the coarser precision side is scaled to a finer precision before comparison; when the time zone type is included, UTC is directly taken; when the time zone type is not included, it is interpreted according to the client's time zone; and the timestamp is read using the binary protocol throughout the process, while ensuring that the pure local query behavior remains completely unchanged.

[0030] Preferably, federated JOIN performs a three-way flow scheduling; when two data tables belong to the same external source, the JOIN operator is pushed down to the remote end for execution; when joining cross-source data tables, the operators on both sides are pushed down to simplify the dataset first, and the join operation is executed locally. Before joining, the field types, time zones, and timestamp precision are aligned; ASOF-JOIN and Window-JOIN time-series-specific join operators are forced to run on the local engine.

[0031] The above technical solution mainly involves integrating heterogeneous external databases (such as relational databases like MySQL and PostgreSQL, and time-series databases like InfluxDB) as primary query objects for time-series databases, without migrating or copying external data. A single SQL statement can simultaneously query local time-series data and data from one or more external data sources. Based on this, this method focuses on addressing the following technical challenges specific to time-series federated queries:

[0032] • How to map heterogeneous external libraries (time-series and relational libraries, with and without schemas) with different functions and models to a unified namespace and conceptual model without conflict;

[0033] • How to ensure that the query semantics specific to time-series databases (time windows, super tables / label grouping, etc.) can still be correctly expressed and executed on non-time-series databases that do not have these semantics;

[0034] • How to maximize the pushdown of computation to external sources while ensuring correctness, given that external library operators / functions have varying capabilities and evolve with version, without needing to maintain capability definitions for each library and each version;

[0035] • How to ensure that the database / table / column structure of the external database and its changes are automatically visible and synchronized to queries even after canceling "register external tables table by table";

[0036] • How to weave local high-frequency time-series measurement data and external static ledger data into a unified logical table at the column level;

[0037] • How to resolve cross-source comparison, JOIN, and window alignment errors caused by inconsistencies in timestamp precision (ms / µs / ns) and timezone semantics across data sources.

[0038] The core innovations and technical effects of this invention

[0039] The heterogeneous data source unified mapping of this invention provides a foundation for "the same namespace and the same conceptual model," enabling all subsequent processing to be unaware of differences between libraries. On this basis, temporal semantics is transformed and pushed down according to local conditions, allowing non-temporal libraries to have temporal computing capabilities on-site. Capability matrix and whole tree push-down use external sources as computing power. The three-level rollback simplifies capability management from "version-by-version definition / probing" to "automatic convergence at runtime" while ensuring the bottom line of correctness. Error-driven learning makes it more and more accurate with use. Source-level management and automatic synchronization reduce the cost of cross-source access to "one-time registration, automatic visibility, and automatic synchronization."

[0040] Heterogeneous data sources are uniformly mapped to a single namespace and conceptual model without conflict.

[0041] Existing technical problems: To manage multiple heterogeneous external databases, including time-series databases, relational databases, and databases with and without schemas, within a single SQL statement, where the naming hierarchy (database / schema / table) and data models (with or without super tables, tags, timestamp primary keys) vary greatly; existing solutions either require users to be aware of the differences between the databases or make it difficult to unambiguously mix and reference local tables and multiple heterogeneous external sources under a unified namespace.

[0042] This invention unifies time-series databases / relational databases and heterogeneous external databases with / without schemas into a single namespace and conceptual model—using source.[db|schema.]table for unified addressing. It normalizes "with / without schema hierarchy" according to source type to the same addressing form and forces external source names to be different from local database names, ensuring that local databases and each external source occupy independent subspaces within the same namespace and do not conflict with each other. The data models of each database are uniformly mapped to the time-series database conceptual system (Database / regular table / super table / subtable / tag column / data column / timestamp primary key). Types that cannot be mapped will report errors during the parsing phase instead of silently degrading.

[0043] Technical effect: Regardless of whether the external database is time-series or relational, and whether it has a schema or not, after integration, all upper-level queries are unified as "a queryable table under the same namespace and the same conceptual model". A single SQL statement can unambiguously mix and reference local tables and tables from any number of heterogeneous external sources. Differences between databases are completely absorbed by the mapping layer and do not conflict with each other.

[0044] Enable non-time-series libraries to have time-series computation capabilities in-situ (time-series semantics are transformed and pushed down according to local conditions).

[0045] Existing technical issues: Non-time-series libraries such as MySQL and PostgreSQL lack time-series database-specific semantics such as time windows and grouping by super tables / labels. This makes it impossible to express or push down such time-series calculations on them, resulting in a degradation in the ability to analyze external time-series data, and the only option is to pull all the data back to the local machine for further calculations.

[0046] This invention achieves the following: Time-series specific semantics are rewritten into equivalent external library expressions and then pushed down; multiple types of time-series windows are uniformly rewritten into two paradigms of standard SQL: "time bucket aggregation" and "window function label grouping (gaps-and-islands) two-stage"—INTERVAL rolling window is converted to GROUP BY time bucket (MySQL FLOOR(UNIX_TIMESTAMP·scaling), PG / InfluxDB DATE_BIN); COUNT_WINDOW uses FLOOR((ROW_NUMBER() OVER(ORDER BY ts)-1) / N) row number for bucketing; STATE_WINDOW uses LAG to mark status change points and SUM() OVER to accumulate window numbers before grouping; SESSION_WINDOW changes the change point condition to "adjacent time interval exceeds gap"; PARTITION BY TBNAME in InfluxDB is converted to grouping by all Tag columns.

[0047] Technical effect: Enables non-time-series libraries that do not have time-series semantics to perform various time-series aggregations such as time windows, count windows, status windows, and session windows, as well as grouping by sub-tables, locally. Treats external sources as "computing power nodes with time-series analysis capabilities" without degrading the analysis capabilities of external time-series data. Sliding / overlapping windows, windows with fill, and EVENT_WINDOW, which cannot be safely modified, degrade to local computation, but the results are still correct.

[0048] Three-tier whitelist capability matrix + bottom-up whole-tree push

[0049] Existing technical issues: The capabilities of operators / functions in various external libraries vary greatly. Existing solutions either push down aggressively, leading to semantic errors or failures, or pull everything back to the local machine, resulting in performance loss. Furthermore, pushdown is usually limited to a single operator or clause, making it difficult to push down complex structures such as nested queries, multi-way JOINs, and UNIONs as a whole.

[0050] This invention uses a three-whitelist capability matrix of "clause / operator / function" for layer-by-layer gating and precise access based on dialect bitmasks; it uses bottom-up continuous harvesting to harvest the entire tree of pushdown operators into the remote terminal plan, and stops only when the first non-pushdown operator is reached, and can push down complex structures as a whole across clauses.

[0051] Technical benefits: External sources are repositioned as computing power rather than storage, and pushdown is organized based on the principle of minimizing data movement; hundreds of millions of rows of details can be compressed into a small number of results at the remote end before being sent back, significantly reducing the amount of data movement across the network; the whitelist system eliminates false pushes from the source.

[0052] Three-level progressive fallback substitution capability definition / detection, adaptive to any external library version.

[0053] Existing technical problems: Pushing computation down to external libraries with varying capabilities that evolve with version requires knowing which capabilities the library supports in that version; static definitions must be maintained version by version and are always outdated, while runtime detection is costly and its coverage is difficult to exhaustively cover.

[0054] This invention uses "correctness-first runtime three-level progressive rollback" as the core of capability management—it can assume that the external library supports all capabilities, pushback without conditions, and rollback step by step in the event of failure, from "function / operator / type level → clause level → only scan fallback", with automatic replanning and retrying. The actual capabilities of the external library are automatically determined by the execution results during runtime convergence.

[0055] Technical benefits: It can adapt to external libraries of any version and with any capability differences without the need to maintain a version-by-version capability list for any external library or probe logic. When an external library is upgraded, the system does not need to upgrade its version accordingly. Any pushdown failure is reduced to "slower" rather than "error" or "query interruption".

[0056] Error-driven runtime capabilities, self-learning, and anti-pollution mechanisms

[0057] Existing technical issues: The true capabilities of external sources are difficult to fully determine during compilation; if runtime errors are used to blindly adjust capability profiles, occasional timeout / network / rate limiting errors may be misjudged as capability deficiencies, polluting long-term capability caches.

[0058] This invention achieves the following: remote errors are attributed to deterministic hierarchical causes—explicit errors are persistently written to the process-level negative table for cross-session effects, while ambiguous errors are only written to the session-level overlay table and discarded after the query ends, never written to the persistent cache; and convergence stability is guaranteed by invariants such as "no repeated entries in the retry chain, no deletion after appending, no automatic clearing of static default items, and capping of the retry limit".

[0059] Technical effects: The system dynamically converges the true capabilities of each external source through runtime errors, becoming more accurate with use; at the same time, it eliminates the "false experience" problem caused by occasional failures polluting the capability cache.

[0060] Source-level management and its supporting mechanism of "automatic discovery + automatic synchronization of structural changes"

[0061] Existing technical problems: Traditional external table solutions use tables as the registration unit, requiring each table to be declared once and re-declared for each table if the structure changes; this makes them almost unusable in time-series scenarios with tens of thousands of tables / test points and frequent structural changes.

[0062] This invention uses "external sources" as the management unit, and the entire database / table / column becomes automatically visible after a single source-level registration; it is also equipped with "automatic discovery + lazy loading + error-driven automatic synchronization of schema changes + automatic timed refresh + forced refresh"—changes that will trigger remote mismatches are synchronized immediately by error-driven methods, while changes that do not trigger mismatches, such as SELECT *, are automatically synchronized after a period of timed refresh.

[0063] Technical benefits: Cross-source access is streamlined from "N tables, N declarations" to "one-time registration, visibility across the entire database"; after external database schema changes, the system automatically discovers and synchronizes, and queries automatically use the latest schema, requiring no manual maintenance throughout the process—source-level management is both low-cost and does not sacrifice correctness due to automatic synchronization.

[0064] Virtual table column-level cross-source data weaving and DDL pre-validation

[0065] Existing technical problems: The real-time measurement column and static ledger column of the same device are located in the time series database and the relational database respectively. Traditional solutions require manual JOIN statements and physical distribution awareness when querying; the misconfiguration of "inability to align timelines" often only becomes apparent during runtime.

[0066] This invention achieves the following: virtual table column references can point to external paths, and local time series measurement columns and external ledger columns are woven into a unified logical table at the column level according to timestamps, eliminating the need for manual JOIN queries; and the timestamp primary key of the referenced external table is validated before table creation, and an error is reported if there is no valid primary key.

[0067] Technical benefits: Column-level cross-source weaving models "real-time measurement + static ledger" into a unified logical table at once, eliminating the need for data migration and manual association; timestamp primary key constraints are validated in advance during the DDL period, errors are shifted to the left, and the table can be queried correctly as soon as it is built.

[0068] Cross-precision time alignment and time zone semantic consistency

[0069] Existing technical issues: The timestamp precision (ms / µs / ns) and time zone meanings differ between different data sources, making it easy to lose precision or introduce time zone ambiguity during cross-source comparisons, JOINs, and window alignment; this is a problem that traditional relational database federation does not need to solve, but must be addressed in time-series scenarios.

[0070] This invention achieves the following: each timestamp column maintains the inherent precision of its data source and is transmitted independently column by column along the entire link; when comparing / joining / aligning across precisions, the coarser precision side is scaled to a finer precision before comparison (low precision is padded with zeros for alignment); when the time zone type is included, UTC is directly retrieved, and when the time zone type is not included, it is interpreted according to the client's time zone; the timestamp is read using the binary protocol throughout, eliminating ambiguity in string parsing; and the behavior of pure local queries remains completely unchanged.

[0071] Technical benefits: Cross-source time comparison / JOIN / window alignment does not lose precision or time zone ambiguity, and enables time series-specific semantics such as time windows and PARTITION BY to be correctly expressed on external data.

[0072] JOIN is divided into three streams: "same origin / cross origin / time-series proprietary".

[0073] Existing technical issues: If federated JOINs do not distinguish between source and type, it is difficult to balance pushdown performance and temporal semantic correctness. Same-source JOINs can be pushed down as a whole, while temporal-specific JOINs (ASOF / Window) must be local to ensure semantics.

[0074] This invention implements the following: JOIN is divided into three streams: "same-source overall pushdown / cross-source pushdown on each side followed by local JOIN / time-series specific streams are all local"; before cross-source association, type / time zone / precision alignment is performed.

[0075] Technical benefits: Same-source JOIN reuses the external source join algorithm for local execution and maximizes pushdown; cross-source and time-specific JOINs are executed correctly locally, balancing performance and temporal semantics correctness. Attached Figure Description

[0076] Figure 1 This is a schematic diagram of a time-series data federated query method according to the present invention. Detailed Implementation

[0077] The "federated query" involved in this invention is fundamentally different from the federated / external table technology of traditional relational databases: this invention is aimed at time-series databases, and needs to fully support the semantics of time-series databases such as time windows, time-series functions, super tables / labels on external heterogeneous data, and needs to solve the problems of cross-precision time alignment and external library capabilities evolving with version unique to time-series scenarios - these are all problems that traditional relational database federated technology does not have or does not need to solve.

[0078] To address the aforementioned issues, this invention proposes a method for federated querying of time-series data. This method integrates external heterogeneous data sources as primary query objects in the time-series database. Within the query engine, it achieves unified querying of local and external data through a combination of "unified mapping of heterogeneous sources + localized maximum pushdown of time-series semantics + correctness-first multi-level rollback + runtime capability self-learning + automatic source-level discovery and synchronization".

[0079] The overall execution flow of this invention is as follows: The parser identifies the external path expression in the SQL, reads the external table metadata and external source capability profile from the metadata cache (Catalog), and completes the validity verification; the logical planner generates a plan tree containing external scan nodes; the optimizer performs federated pushdown based on the external source capability profile, harvesting pushdown-capable operators into a "remote sub-plan" from the bottom up; during the execution phase, the external connector traverses the remote sub-plans, generates remote SQL according to the target library dialect, and sends it down for execution, then uniformly converts the external results into internal data blocks (SSDataBlock); non-pushdown upper-level operators read data from this data block and continue calculation locally.

[0080] The access to external data is handled by two components: an external connector (responsible for connection management, external metadata acquisition, generating remote SQL according to dialects, and result transformation) and a federated scan operator (driving external data retrieval in the execution tree and presenting it as a regular table to upper-level operators). Local and external data are processed through the same query execution path, and upper-level aggregation / window / JOIN / sorting operators treat both types of data equally. Subsequent sections describe the specific innovative mechanisms of this method on top of this process.

[0081] External Source Management: Source-level registration, automatic discovery, and automatic synchronization of structural changes. This invention uses "external source" rather than "external table" as the basic management unit. This design is complementary to the "automatic discovery + automatic synchronization of structural changes" mechanism—the former establishes a low-cost access model, while the latter solves the metadata consistency problem that it inevitably brings.

[0082] Source-level registration ensures full database visibility. This invention uses `CREATE EXTERNAL SOURCE` to register an external source (including type, address, credentials, etc.) in a single step. After registration, the entire three-level structure of the database / table / column under that source becomes automatically visible, eliminating the need for separate declarations for any individual table. In time-series scenarios, the number of tables / test points in a single external database often reaches tens of thousands and continues to grow and change, making table-by-table registration almost unusable. Source-level registration reduces the cost of "N tables = N declarations, requiring table-by-table re-declaration every time the structure changes" to "one-time registration, full database visibility." Multiple external sources coexist in their own independent namespaces without conflict, and anomalies in one source do not affect other sources.

[0083] Automatic discovery + lazy loading + local caching. The structure under this invention is automatically visible, but the schema is only fetched on demand when a table is accessed for the first time, without preloading the full schema to avoid startup storms for large databases; discovery results are cached locally to avoid duplicate retrieval.

[0084] Automatic synchronization of structural changes (error-driven + timed refresh + forced refresh): After eliminating manual registration for each table, this invention automatically maintains the consistency between the obtained external table schema information and the external structure after changes through the following mechanism, requiring no manual maintenance by the user:

[0085] • Automatic synchronization of error-driven schema changes: When the structure of an external database table changes (adding / deleting columns, changing data types), queries that hit the outdated cache will trigger remote mismatch errors. The system automatically identifies this as a schema mismatch, automatically retrieves the latest schema for the table, updates the cache, and re-plans and executes the query with the latest schema. The closed loop of "detecting changes → updating the cache → completing the query with the latest schema" is automatically completed at runtime.

[0086] • Automatic timed refresh: The cache is automatically synchronized with the external source according to the refresh cycle, covering scenarios that will not trigger remote mismatch errors but still need to be aware of structural changes (such as SELECT * still returning the old column set without reporting an error after adding a column to the external table). After one refresh cycle, such queries can automatically retrieve the latest column.

[0087] • Forced refresh: Provides REFRESH for active convergence and also serves as an anomaly self-healing mechanism.

[0088] Therefore, source-level management is paired with automatic discovery / automatic synchronization: it is both low-cost (one-time registration, full database visibility) and does not sacrifice correctness (structural changes are automatically synchronized throughout the process, no manual maintenance required).

[0089] Heterogeneous data sources are uniformly mapped to a single namespace and conceptual model. This invention integrates heterogeneous external libraries with different functions and models—including time-series libraries (such as InfluxDB) and relational libraries (such as MySQL / PostgreSQL), including libraries with schema levels (PostgreSQL) and libraries without schema levels (MySQL / InfluxDB)—into the same namespace and conceptual model of the time-series database, without any conflicts between them.

[0090] Unified namespace (unified addressing, no conflicts): All external objects are addressed using a two- or three-segment path: source.[db|schema.]table; the semantics of the middle segment are fixed according to the external source type—MySQL / InfluxDB middle segments without schema concept are mapped to database, and PostgreSQL middle segments with schema concept are mapped to schema, thus unifying the structural differences of "with / without schema hierarchy" into the same addressing form. External source names are forced to be different from the local database name, ensuring that the local database and each external source occupy independent subspaces within the same namespace, without conflicts. A single SQL statement can unambiguously mix references to local tables and tables from any number of heterogeneous external sources.

[0091] Unified conceptual model (model standardization): The data models of external databases are mapped to a unified conceptual system of the time-series database (Database / Regular table / Super table / Sub-table / Tag column / Data column / Timestamp primary key): Time series database model

[0092] Specifically: InfluxDB's Measurement / Tag Set / Tag are naturally aligned with the supertable / subtable / tag of the time-series database, allowing time-series database-specific syntax such as PARTITION BY TBNAME and TAGS to be expressed equivalently on it; MySQL / PG does not have the concept of a supertable, and when referencing related pseudo-columns, it explicitly reports errors during the parsing phase without silent degradation. External column types are classified into four levels: "exact correspondence / degradable / structured / unmappable". Unmappable external proprietary types are intercepted and reported as errors during the parsing phase, ensuring that all column types involved in the executed query are mappable and the data is reliable.

[0093] Therefore, regardless of whether the external library is time-series or relational, has a schema or not, or how different the models are, after integration, it is unified into "a queryable table under the same namespace and the same conceptual model" for upper-level queries, and the differences are completely absorbed by this mapping layer.

[0094] Computational pushdown: Capability matrix + bottom-up whole-tree pushdown + location-specific temporal semantic transformation. Pushdown is the core of this invention's performance; its concept is to reposition external sources as "computing power" rather than "storage," allowing computation to be completed locally at the data's origin and minimizing cross-network data movement. This invention employs three mutually cooperating mechanisms for pushdown in temporal federation scenarios:

[0095] A three-layer whitelist capability matrix is ​​used. External pushdown capabilities are controlled layer by layer by an AND gate of three whitelist capability matrices: clauses, operators, and functions. A whitelist system is employed: if not declared as pushable, it is not pushable, preventing false pushes from the source. Each capability item encodes the capability of a particular dialect using a bitmask (e.g., one bit each for MySQL, PG, and InfluxDB), allowing precise access based on the target database. For example, FULL_OUTER_JOIN is not pushable for MySQL but is pushable for PG / InfluxDB; PARTITION_TBNAME can only be converted to a GROUP BY tag for InfluxDB. Before pushdown, a recursive check of the mappability of the expression within the operator is performed (checking node by node whether the function / operator is in the whitelist, whether the column reference is an external physical column, and whether the constant type is mappable); the operator is only pushed down if both the capability bit is allowed and the expression is fully mappable.

[0096] The process proceeds from bottom to top, continuously pushing down the entire tree. Starting from the external scanning node, it traverses the plan tree layer by layer, "harvesting" pushable operators into a distant sub-plan in sequence until the first non-pushable operator is encountered. The harvesting order is: WHERE condition → PARTITION BY → GROUP BY → INTERVAL → time bucket → aggregation → sorting → projection → LIMIT → same-origin JOIN → subquery. Pushdown can span a single clause—nested queries, multi-way JOINs, UNIONs, etc., can all be pushed down as a whole, not just limited to a single operator or clause.

[0097] Temporal semantics are adapted and pushed down to local conditions: enabling non-time-series databases to perform time-series calculations locally. Time-series databases provide various proprietary "time windows"—time windows divided by fixed duration, counting windows divided by a fixed number of rows, status windows divided by whether the values ​​of a certain status column are consecutively identical, and session windows divided by whether the time interval between adjacent data exceeds a threshold, etc. General-purpose databases like MySQL and PostgreSQL do not understand these window concepts. The key innovation of this invention lies in the insight that these time-series windows can essentially be reduced to two steps: "first determine which window each piece of data belongs to, and then aggregate the data within the same window into a row." These two steps can be expressed using standard SQL capabilities that general-purpose databases possess. Therefore, this invention rewrites the time-series semantics into standard SQL that the target database can understand and then pushes it down for execution, allowing general-purpose databases that originally lack time-series analysis capabilities to perform time-series window calculations locally within themselves, without having to pull all the massive amounts of raw data back to their local machine for calculation.

[0098] Specifically, based on the rules governing "how data is determined to belong to which window," different windows are rewritten into two types of standard SQL syntax:

[0099] Category 1: Directly calculate the window number based on a pattern (applicable to time windows and counting windows)

[0100] The boundaries of these two types of windows are regular and independent of the data content, so the window number to which each data point belongs can be directly calculated, and then the data can be grouped and aggregated according to the number:

[0101] • Time window: Divide the timestamp of each data point by the window duration and round down to determine its time period. This time period is then used as the basis for grouping. For example, dividing by 1 hour will group all data points falling within the same hour together.

[0102] • Counting window: First, assign a serial number to each data item in chronological order. Then, divide the serial number by the number of rows in the window and round down to determine which window it belongs to. For example, if there is one window for every 100 rows, then rows 1-100 belong to group 0, rows 101-200 belong to group 1, and so on.

[0103] The second type: First identify the "boundary line" of the window, and then assign data numbers accordingly (applicable to status windows and session windows).

[0104] The boundaries of these two types of windows are irregular and depend on the data itself, making it impossible to calculate the number directly. However, we can use the "view adjacent rows" capability supported by general databases (i.e., standard SQL window functions, which can retrieve the value of the previous row in the same sequence) to identify the window's boundary points, and then sum up the boundary points to obtain the window number.

[0105] • Status Window: Compare the status column values ​​of the current row with the previous row in chronological order. Wherever the value changes, it becomes the starting point of a new window. The "whether it is the starting point" flag is accumulated in chronological order to obtain the window number to which each data belongs. Consecutive data with the same status naturally get the same number and are grouped together.

[0106] • Session Window: The principle is exactly the same as the Status Window, except that the "boundary condition" is changed from "the status has changed" to "the time interval between the current row and the previous row exceeds the set interval threshold".

[0107] Equivalent expressions for supertable / label grouping: Time-series specific syntax such as "PARTITION BY TBNAME" only holds true in InfluxDB, where the data model is naturally aligned—the system reads all the label columns of the measurement and converts it to grouping by these label columns, which is equivalent. MySQL and PostgreSQL do not have a corresponding concept, and using this syntax will explicitly result in an error during the parsing phase.

[0108] The following example, "calculating average current by hour on MySQL," illustrates the effect of rewriting the time window—the top is the time-series window query written by the user, and the bottom is the standard SQL actually sent to MySQL for execution after rewriting by this invention:

[0109]

[0110] Let's take "splitting the status window by the status column" as an example to illustrate the second type of rewriting:

[0111]

[0112] In addition to the time-series-specific semantic conversions mentioned above, for operators that the target library already supports but with different syntax (e.g., some databases do not support FULL OUTER JOIN, which can be replaced by the union of left and right joins), this invention also rewrites them according to the dialects of each library and pushes them down as a completeness supplement to the pushdown capability—this part is a conventional equivalent rewriting.

[0113] Cross-source JOIN three-stream processing: When a single SQL statement crosses multiple sources, it is split into remote SQL statements representing the respective dialects of each source. After maximizing pushdown and weight reduction on each side, the data is merged and processed locally. The JOIN is divided into three streams based on "whether they are from the same source"—this is key to balancing pushdown performance and temporal semantic accuracy.

[0114] • **Single-source JOIN (two tables from the same external source)** → The entire process is pushed down, and the external source executes the join locally using its own join algorithm (Full Outer is rewritten in MySQL using LEFT ∪ RIGHT, and Semi / Anti is converted to EXISTS / NOTEXISTS).

[0115] • Cross-source JOIN / Local + External Mixed → Push-down filtering on each side + column pruning and postback, JOIN is executed locally; before association, type normalization + time zone alignment + precision alignment are performed;

[0116] •**ASOF / Window JOIN (Timing-Specific)** → Always executed locally, ensuring correct timing semantics.

[0117] Virtual Tables: Column-Level Cross-Source Data Weaving. A common scenario in time-series scenarios is that "real-time measurement columns for the same device are stored in a time-series database, while static ledger columns are stored in a relational database." This invention allows column references in virtual tables to point to external paths, thereby weaving these two types of columns into a unified logical table at the column level: time-series (current / voltage) columns come from the local time-series database, and ledger columns (responsible person / address) columns come from an external MySQL / PostgreSQL database. During queries, these columns are automatically merged by timestamp, presenting a single ordinary table without the need for manual JOIN statements or awareness of physical distribution.

[0118] To ensure timeline alignment, the referenced external table must have a timestamp primary key (for MySQL, this is the PK of DATETIME / TIMESTAMP or UNIQUE INDEX; for PG, it is the PK of TIMESTAMP / TIMESTAMPTZ). This constraint is validated before table creation (DDL): if there is no valid timestamp primary key, an error is reported, shifting the "timeline misalignment" error from runtime to table creation for interception.

[0119] A three-level rollback prioritizing correctness, coupled with runtime capability self-learning. This invention is based on a fundamental principle for reliability: any failed pushdown optimization should never return an error or uncertain result, only resulting in performance loss. Two complementary mechanisms are designed around this principle, enabling capability management to operate without relying on version-by-version complete capability definitions or runtime probing.

[0120] Three-level progressive rollback to replace capability definition / probing. To push computation down to external libraries with different capabilities, the conventional approach is either to predefine a complete capability list for each version of each library (which requires version-by-version maintenance and is always lagging behind the latest version of the external library), or to actively probe capabilities after connection (which incurs additional overhead and is difficult to exhaustively cover) - both of which are very costly.

[0121] This invention uses a three-level progressive rollback as the core of capability management: it can assume that the external library supports all capabilities, push down operators unconditionally (or with lenient defaults), and when the pushdown fails, it rolls back step by step according to "L3 function / operator / type level → L2 clause level → L1 baseline scan". At each level, only the truly erroneous part is pulled back to the local system, and the parts that can be pushed continue to be pushed. After the rollback, the system automatically replans and retryes. If it still fails within the retry limit, it switches to L1 baseline scan (which will always succeed). The actual capability boundary of the external library is automatically determined by the actual execution results at runtime, rather than by a pre-defined list. As a result, the system does not need to maintain a version-by-version capability list or probe logic, and can adapt to external libraries of any version and with any capability differences. Moreover, when the external library is upgraded, the system does not need to be upgraded accordingly.

[0122] Error-driven capability self-learning and prevention of "false experience" contamination: Under the above premise, how runtime errors are written back into the capability profile determines the accuracy of capability convergence. This invention handles errors according to their deterministic classification:

[0123] • Clearly identify errors (function does not exist / type mismatch / syntax not supported and located in clause / operator undefined): persistent write to the process-level capability negative table, effective across sessions, and the next planning will avoid this non-inferable item;

[0124] • Ambiguous errors (timeout / network rejection / rate limiting / uncategorized): Only write to the session-level overlay table and discard after the query ends, never write to the persistent cache—to prevent unreproducible occasional failures from being misjudged as "capability deficiency" and polluting the long-term capability profile.

[0125] Furthermore, several invariants are used to ensure convergence stability: the same negative item is not repeatedly entered into the table within the same retry chain (to avoid degenerate oscillations), the negative table is "appended but not deleted," static default items are not automatically cleared by error-driven logic, and the number of retries is capped. As a result, the system "understands the source better the more it is used," while preventing occasional failures from polluting the capability cache.

[0126] Embodiments of the present invention

[0127] 1) External Source Registration Syntax: External sources are registered once using CREATE EXTERNAL SOURCE. After registration, the databases / tables / columns under that source are automatically visible, without the need for table-by-table declaration. The complete syntax is as follows:

[0128]

[0129] Meaning of each field:

[0130] • source_name: External source name, globally unique, and not allowed to have the same name as a local library (to ensure no conflict in cross-source addressing).

[0131] •TYPE: External source type, which determines the connector implementation and path resolution rules;

[0132] •HOST / PORT / USER / PASSWORD: The connection address and access credentials for the external library;

[0133] •DATABASE: Default database name (optional). Because PostgreSQL connections are database-level bounds and database switching is not possible after connection, it must be explicitly specified during registration; MySQL / InfluxDB can be omitted, but the database name must be included in the query if omitted.

[0134] •SCHEMA: Default schema name (optional, primarily used in PostgreSQL);

[0135] •OPTIONS: A list of key-value pairs for extending connection parameters, used to pass optional configurations in addition to the base fields.

[0136] The accompanying management statements include: ALTER EXTERNAL SOURCE (modify connection configuration), SHOW EXTERNAL SOURCES (list registered sources), DESC (view the structure of a source or its sub-tables), REFRESH EXTERNAL SOURCE (force refresh metadata cache), and DROP EXTERNAL SOURCE (unregister a source). Registration and the above management operations only write metadata and do not immediately connect to the external database; the correctness of the connection parameters is only verified during the first actual query.

[0137] Registration example:

[0138]

[0139] External object path addressing: After registration, external tables are addressed using segmented paths of "source name + database / schema + table name", consistent with the local "database.table" addressing convention.

[0140] • source.table: Uses the default library / schema specified during registration;

[0141] • source.db.table: Explicitly specifies the database (MySQL / InfluxDB);

[0142] • source.schema.table: Explicitly specifies the schema (PostgreSQL).

[0143] You can also access the namespace of an external source by using `USE source` or `USE source.db`, ​​and then directly reference the tables under it using short table names, which is consistent with the experience of using short table names in the local database.

[0144] 2) Basic query syntax: External tables are used in the same way as local tables in queries—simply treat the external path as the table name in the FROM clause. The rest of the SQL syntax (projection, filtering, sorting, limiting, aggregation, grouping, windowing, JOIN, subqueries, etc.) is exactly the same as querying local tables, requiring no special syntax. For example:

[0145]

[0146] Therefore, users can query both local time-series data and external data sources simultaneously using the same SQL syntax and query entry point, without needing to be aware of the physical location of the data or differences between external databases. How the query is broken down, which calculations are pushed down to the external database, and which are completed locally are all automatically determined by the system and are transparent to the user. The following examples are based on this syntax.

[0147] Specific Example 1: Source-level registration and automatic synchronization of schema changes

[0148] Scenario: A MySQL database contains thousands of device measurement point tables. The table structure changes as business evolves. It needs to be integrated with a time-series database for unified querying, but we do not want to declare each table individually or maintain it manually after the structure changes.

[0149]

[0150] Execution Notes: The second query hit an outdated cache, triggering a remote column mismatch error. The system automatically identified this as a schema mismatch, automatically retrieved the latest schema to update the cache, and re-executed using the latest schema, correctly returning results containing the temperature column. For queries like SELECT * that do not trigger a mismatch, the system automatically refreshes and synchronizes the latest columns after a period. No manual refresh or redeclaration by the user is required throughout the entire process.

[0151] Specific Example 2: Overall Pushdown from a Single External Source

[0152] Scenario: Perform filtering, sorting, and restriction on an external table in MySQL.

[0153]

[0154] Execution Description: The optimizer harvests WHERE, column pruning, ORDER BY, and LIMIT operations from bottom to top, ensuring they are all within the MySQL capability matrix and the expressions are mappable, and then harvests them all into the remote sub-plan. The connector renders it as a single MySQL dialect SQL statement and sends it out. MySQL performs filtering / sorting / truncation remotely, returning only 1000 rows. In this example, all operators are pushed down, with no additional local computation.

[0155] Specific Example 3: Pushdown of Semantic Transformation of Time Series Window (INTERVAL → Time Bucket)

[0156] Scenario: Perform hourly rolling window aggregation specific to time-series databases on a MySQL external table without INTERVAL semantics.

[0157]

[0158] Execution Notes: After the optimizer confirms that the window is a sliding window, without fill, and AVG can be mapped, it converts the 1-hour window to a grouping expression FLOOR(UNIX_TIMESTAMP(ts)*1000000 / N_us)*N_us / 1000000 (or DATE_BIN for PG / InfluxDB) with MySQL microsecond precision. The window is then converted to an aggregation pushdown with this grouping key. MySQL performs bucket aggregation remotely and only returns one row per hour. If it is a sliding window / window with fill / time-series specific window, it cannot be converted; in this case, execution is performed locally, and the result is still correct.

[0159] Specific Example 4: Equivalent Representation of Supertable Semantics in InfluxDB (PARTITION BY TBNAME)

[0160] Scenario: InfluxDB's Measurement / Tag is naturally aligned with the time-series database's supertable / tag.

[0161]

[0162] Execution Notes: On MySQL / PG, using TBNAME results in an error during the resolution phase (there is no concept of a super table); On InfluxDB, the optimizer reads all Tag columns of the Measurement from the Catalog, converts PARTITION BYTBNAME to GROUP BY tag1, tag2, ..., and then merges and pushes it down with the time buckets converted by INTERVAL. The time-series-specific grouping semantics by sub-table are equivalently expressed in the external source without degradation of capabilities.

[0163] Specific Example 5: Virtual Table Column-Level Cross-Source Data Weaving

[0164] Scenario: The real-time current / voltage data of meter d1001 is stored in a local time-series database, while the ledger (responsible person / address) is stored in MySQL, and both are merged into a single logical table.

[0165]

[0166] Execution Instructions: During table creation, a pre-verification check is performed to ensure that the referenced external table `meter_asset` has a valid timestamp primary key; otherwise, an error is reported and table creation is rejected. During queries, local columns are read locally, and external columns are retrieved from MySQL via a federated scan. The two are automatically merged into a single regular table based on timestamps and returned. Users do not need to manually write JOIN statements or be aware of the physical origin of the columns.

[0167] Specific Example 6: Local and External JOIN Three-way Flow

[0168] Scenario: Local time-series super table meters is associated with a PostgreSQL device ledger.

[0169]

[0170] Execution Instructions: This example is a "local + external hybrid JOIN," following a three-way cross-source JOIN path: Locally, meters are read locally (including time range filtering); externally, device_info is pruned and filtered remotely at PG before being sent back; the JOIN is executed locally. Before the join, meter_id is type-normalized, and timezone and precision are aligned for ts. If both tables belong to the same external source, the entire table is pushed down and the JOIN is performed locally from the external source; if it is an ASOF / Window JOIN, it is always executed locally to ensure time-series semantics.

[0171] Specific Example 7: Three-stage progressive rollback after pushdown failure

[0172] Scenario: A query pushes down an aggregation in PostgreSQL that contains a function that does not exist in PG, and also pushes down ORDER BY and LIMIT.

[0173] Execution Instructions: PG returns "Function does not exist" (explicit error), triggering a three-level fallback—L3 only pulls the function back to local execution, while the rest are still pushed, and writes the function to the process-level capability negative table for cross-session effect; if the function cannot be partially pushed down, it escalates to L2 for the entire aggregation to be executed locally; if it still fails, it falls back to L1, only pushing down filtering and column pruning, while the rest are executed locally. Retrying is limited to 3 times, pushing down a little less each time until success or falling back to baseline scanning. If the error is a vague error (timeout / network reset), only the session-level overlay table is written, and the query is discarded after completion, without polluting the long-term capability profile. Regardless of the path taken, the query ultimately returns the correct result; a failed pushdown only manifests as being "slower."

[0174] In summary, the present invention provides a time-series data federated query method as follows: Figure 1 As shown, this is used to access external heterogeneous databases with different functions and models as query objects for time series databases. A single SQL statement can be used to simultaneously query local time series data and data from one or more external heterogeneous databases, including:

[0175] Mapping heterogeneous external databases as external sources to a unified namespace allows a single SQL statement to unambiguously mix references to local tables and tables from any number of external sources; and

[0176] The data models of the heterogeneous databases are mapped to a unified conceptual system of time-series databases. The unified conceptual system includes: database, ordinary table, super table, sub-table, label column, data column, and timestamp primary key.

[0177] Methods for querying local time-series data and data from one or more external heterogeneous databases simultaneously using a single SQL statement include:

[0178] The parser identifies the external path expression in the SQL statement to be executed, reads external metadata and external source capability profiles from the metadata cache, and performs a validity check.

[0179] The logic planner generates a plan tree containing external scan nodes;

[0180] The optimizer performs federated pushdown based on the external source capability profile, traverses the plan tree from bottom to top, obtains pushdown operators and non-pushdown upper-level operators, and harvests the pushdown operators into the remote sub-plans.

[0181] When executing federated queries, the external connector traverses remote sub-plans, converts the time-series window semantics specific to the time-series database into equivalent expressions of the external library's standard SQL containing pushdown operators according to the target database dialect, and pushes them down to the remote end. It also converts the external results returned by the remote end into internal data blocks. Non-pushdown upper-level operators read data from the internal data blocks and perform further calculations on the read data locally.

[0182] This invention maps external heterogeneous databases as external sources to a unified namespace, including: all external objects are uniformly addressed using the path source.[db|schema.]table; mapping MySQL / InfluxDB middleware without schema concept to database, and mapping PostgreSQL middleware with schema concept to schema; and ensuring that the external source name does not conflict with the local database name.

[0183] This invention converts the time-series window semantics specific to time-series databases into equivalent expressions in standard SQL for external libraries. This includes: converting INTERVAL rolling windows to GROUP BY time buckets according to the target library's inherent precision; bucketing COUNT_WINDOW by row number division; grouping STATE_WINDOW by using the window function LAG to mark state change points and accumulating the window numbers using SUM() OVER; grouping SESSION_WINDOW by marking window breaks based on whether adjacent time intervals exceed the gap; and converting PARTITION BY TBNAME to grouping by all Tag columns on external sources with super-table alignment semantics. This allows non-time-series databases to perform time window, count window, status window, and session window aggregation and sub-table grouping locally. The window function-based rewriting is contingent on the target library supporting window functions and common table expressions; if these are not met or there is no equivalent expression, it degenerates into local computation with correct results.

[0184] The external library standard SQL equivalent expression pushdown method described in this invention includes: layer-by-layer gating based on dialect bitmasks using three whitelist capability matrices (clauses / operators / functions), recursively determining whether an operator can be pushed down based on the mappability of the expression, and continuously harvesting pushable operators from the bottom up along the plan tree from the external scanning node into the remote sub-plan, stopping only when the first non-pushable operator is reached, and pushing down complex structures such as nested queries / multi-way JOIN / UNION across clauses as a whole. The pushable operators include condition operators, grouping operators, window operators, aggregation operators, sorting operators, projection operators, restriction operators, same-origin JOIN operators, and subquery operators.

[0185] This invention allows pushdown operators to push down under the assumption that the external database supports them. When execution fails, it uses a three-level progressive rollback approach: function / operator / type level, clause level, and only scan fallback level. It pulls the truly unsupported parts back to the local machine, automatically replans and retryes after rollback, and if it still fails within the upper limit, it switches to baseline scan fallback.

[0186] The time-series data federated query method of the present invention also includes an error-driven runtime pushdown capability self-learning method, specifically: remote errors are attributed according to deterministic classification, errors are explicitly written to the process-level capability negative table for cross-session effect, and fuzzy errors are only written to the session-level overlay table and discarded after the query ends. Invariants such as "no repeated entries in the retry chain, no deletion after appending, no automatic clearing of static default items, and capping of retry limit" are used to ensure stable convergence of capability profiles and prevent occasional failures from polluting long-term capability cache.

[0187] The external data source access method of this invention is source-level registration; after executing CREATE EXTERNAL SOURCE to register the remote database instance, all databases, tables and fields under the instance are automatically made accessible, without needing to register external tables one by one; each external source namespace is independent and isolated from each other.

[0188] In the time-series data federated query method of this invention, external sources are used as management units, and metadata self-consistency is maintained through "automatic discovery + on-demand lazy loading + error-driven automatic synchronization of schema changes + automatic timed refresh + forced refresh". For structural changes that will trigger remote mismatch errors, the latest schema is automatically retrieved again by remote error-driven mechanism, the cache is updated, and the query is re-executed with the latest schema. For structural changes that do not trigger remote mismatch errors, the automatic timed refresh executed periodically synchronizes the cache with the external source after one refresh cycle, so that such queries automatically obtain the latest columns.

[0189] In the time-series data federated query method of this invention, a column-level cross-source data weaving method is used, which uses a virtual table to reference an external path, weaves the local time-series measurement column and the external static ledger column into a unified logical table at the column level according to the timestamp, and verifies the timestamp primary key of the referenced external table before the table is built.

[0190] The time-series data federated query method of this invention also includes a time semantic self-consistent method for time-series federated queries, which specifically includes: each timestamp column maintains its inherent precision of the data source and is transmitted independently column by column along the entire link; when comparing / joining / aligning across precisions, the coarser precision side is scaled to a finer precision before comparison; when the time zone type is included, UTC is directly taken; when the time zone type is not included, it is interpreted according to the client's time zone; and the timestamp is read using the binary protocol throughout the process, while ensuring that the pure local query behavior remains completely unchanged.

[0191] In the time-series data federated query method of this invention, federated JOIN performs a three-way flow scheduling; when two data tables belong to the same external source, the JOIN operator is pushed down to the remote end for execution; when joining cross-source data tables, the operators on both sides are pushed down to simplify the dataset first, and the join operation is executed locally. Before joining, the field types, time zones, and timestamp precision are aligned; ASOF-JOIN and Window-JOIN time-series-specific join operators are forced to run on the local engine.

[0192] Although the present invention has been described in detail above, it is not limited thereto, and those skilled in the art can make various modifications based on the principles of the present invention. Therefore, all modifications made in accordance with the principles of the present invention should be understood to fall within the protection scope of the present invention.

Claims

1. A time-series data federated query method, used to access external heterogeneous databases with different functions and models as query objects of time-series databases, using a single SQL statement to simultaneously query local time-series data and data from one or more external heterogeneous databases, including: Map external heterogeneous databases as external sources to a unified namespace so that a single SQL statement can unambiguously mix references to local tables and tables from any number of external sources. A unified conceptual system for mapping the data models of external heterogeneous databases to time-series databases is established. This unified conceptual system includes: database, ordinary table, super table, sub-table, label column, data column, and timestamp primary key. Methods for querying local time-series data and data from one or more external heterogeneous databases simultaneously using a single SQL statement include: The parser identifies external path expressions in the SQL statement to be executed, reads external metadata and external source capability profiles from the metadata cache, and performs legality verification. The logic planner generates a plan tree containing external scan nodes; The optimizer performs federated pushdown based on the external source capability profile, traverses the plan tree from bottom to top, obtains pushdown operators and non-pushdown upper-level operators, and harvests the pushdown operators into the remote sub-plans. When executing federated queries, the external connector traverses remote sub-plans, converts the time-series window semantics specific to the time-series database into equivalent expressions of the external library's standard SQL containing pushdown operators according to the target database dialect, and pushes them down to the remote end. It also converts the external results returned by the remote end into internal data blocks. Non-pushdown upper-level operators read data from the internal data blocks and perform further calculations on the read data locally.

2. The time-series data federated query method according to claim 1, wherein, Mapping external heterogeneous databases as external sources to a unified namespace includes: All external objects are addressed using the path source.[db|schema.]table; Map schema-less MySQL / InfluxDB middleware segments to databases, and schema-based PostgreSQL middleware segments to schemas; and External source names must not conflict with local database names.

3. The time-series data federated query method according to claim 2, wherein, Converting the time-series window semantics specific to time-series databases into equivalent expressions in standard SQL for external databases includes: converting INTERVAL rolling windows to GROUP BY time buckets according to the inherent precision of the target database; dividing COUNT_WINDOW into buckets by row number; grouping STATE_WINDOW by marking state change points with the window function LAG and accumulating the window numbers using SUM() OVER; grouping SESSION_WINDOW by marking window breaks based on whether adjacent time intervals exceed the gap; and converting PARTITION BY TBNAME to grouping by all tag columns on external sources with super table alignment semantics. This allows non-time-series databases to perform time window, count window, status window, and session window aggregation and sub-table grouping locally. The window function-based rewriting is based on the premise that the target database supports window functions and common table expressions. If the target database does not meet the requirements or there is no equivalent expression, it degenerates into local calculation with correct results.

4. The time-series data federated query method according to claim 2, wherein, The external library standard SQL equivalent expression pushdown includes: a time-series federated computation pushdown method that uses a whitelist capability matrix of clauses / operators / functions, gates layer by layer according to dialect bitmasks, and recursively determines whether an operator can be pushed down based on the mappability of the expression. It also continuously harvests pushable operators from the bottom up along the plan tree from the external scanning node into the remote sub-plan, and stops only when the first non-pushable operator is reached. It can push down complex structures such as nested queries / multi-way JOIN / UNION across clauses. The pushable operators include condition operators, grouping operators, window operators, aggregation operators, sorting operators, projection operators, restriction operators, same-origin JOIN operators, and subquery operators.

5. The time-series data federated query method according to claim 2, wherein, The pushdown operator can be pushed down under the assumption that the external database supports it. When the execution fails, it will pull the parts that are not supported back to the local machine in a three-level progressive rollback method: function / operator / type level, clause level, and only scan fallback level. After rollback, it will automatically replan and retry. If it still fails within the upper limit, it will switch to baseline scan fallback.

6. The time-series data federated query method according to claim 2, wherein, It also includes an error-driven runtime pushdown capability self-learning method, which specifically involves: attributing remote errors according to deterministic classification, explicitly writing errors persistently to the process-level capability negative table for cross-session effects, and writing ambiguous errors only to the session-level overlay table and discarding them after the query ends. It also uses invariants such as "no repeated entries in the retry chain, no deletion after appending, no automatic clearing of static default items, and capping of the retry limit" to ensure stable convergence of capability profiles and prevent occasional failures from polluting the long-term capability cache.

7. The time-series data federated query method according to claim 2, wherein, External data source access is achieved through source-level registration; after registering the remote database instance using CREATE EXTERNAL SOURCE, all databases, tables, and fields under the instance are automatically made accessible, eliminating the need to register external tables one by one; and each external source namespace is independent and isolated from the others.

8. The time-series data federated query method according to claim 2, wherein, Using external sources as the management unit, metadata consistency is maintained through "automatic discovery + on-demand lazy loading + error-driven automatic synchronization of schema changes + automatic scheduled refresh + forced refresh". For structural changes that trigger remote mismatch errors, the latest schema is automatically retrieved and the cache is updated by remote error-driven mechanism, and the query is re-executed with the latest schema. For structural changes that do not trigger remote mismatch errors, the cache is synchronized with the external source after a refresh cycle by the periodically executed automatic scheduled refresh, so that such queries automatically obtain the latest columns.

9. The time-series data federated query method according to claim 2, wherein, This method involves using virtual table column references to point to external paths, weaving local time-series measurement columns and external static ledger columns into a unified logical table at the column level based on timestamps, and validating the timestamp primary key of the referenced external table at the column level before table creation.

10. The time-series data federated query method according to claim 2, wherein, It also includes a temporal semantic self-consistent method for time-series federated queries, which specifically includes: each timestamp column maintains its inherent precision from the data source and is transmitted independently column by column along the entire link; when comparing / joining / aligning across precisions, the coarser precision side is scaled to a finer precision before comparison; when the time zone type is included, it directly takes UTC; when the time zone type is not included, it is interpreted according to the client's time zone; and the timestamp is read using the binary protocol throughout the process, while ensuring that the behavior of pure local queries remains completely unchanged.

11. The time-series data federated query method according to claim 2, wherein, Federated JOIN execution involves a three-way scheduling; when two data tables belong to the same external source, the JOIN operator is pushed down to the remote end for execution. When joining cross-source data tables, operators on both sides are pushed down to simplify the dataset first, the join operation is performed locally, and the field type, time zone, and timestamp precision are aligned before the join. ASOF-JOIN and Window-JOIN timing-specific association operators force the local engine to run.