Time series data federation query method and system based on TDengine

CN123030634APending Publication Date: 2026-11-03NANTONG WOHUIYUN ENERGY TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611219543.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-12
Publication Date
2026-11-03

AI Technical Summary

Technical Problem

该方案存在三个缺陷:第一,架构复杂度高,需要独立部署Presto集群,维护成本大

Benefits of technology

架构简化:本发明在TDengine原生引擎中即可扩展联邦查询能力,无需独立部署Presto或Flink集群,运维节点减少60%以上,架构复杂度大幅降低。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123030634A_ABST
    Figure CN123030634A_ABST
Patent Text Reader

Abstract

The application discloses a time series data federation query method and system based on TDengine, and belongs to the technical field of computer data processing. A virtual super table is configured in a TDengine query engine to uniformly map heterogeneous data sources, cross-source query SQL is received and metadata is parsed, a time range pushdown, label filter pushdown, aggregation operator decomposition, time series join optimization and pre-computed summary utilization rule are applied by a time series feature perception query optimizer to generate an optimal physical execution plan, the plan is decomposed into sub-queries and pushed down to each data source for local execution and query-level desensitization, and only aggregated summaries or filtered results are transmitted, global aggregation, sorting and limit operations are performed by a coordination node, and the final result is returned in a streaming manner. The application does not require an external federation query component, realizes safe cross-source analysis without domain data, effectively reduces bandwidth and storage costs, and improves the efficiency of time series data federation query.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of computer data processing technology, specifically relating to a time-series data federated query method and system based on TDengine. Background Technology

[0002] TDengine is a domestically developed open-source time-series database that uses a super-table concept to manage massive amounts of time-series data and supports standard SQL queries and JDBC interfaces. Its core features include columnar storage, automatic time-series data sharding, a tag indexing mechanism, data subscription, and streaming computing capabilities.

[0003] Presto is an open-source distributed SQL query engine that supports federated queries across multiple data sources and adapts to different storage systems through a Connector architecture. Its query execution employs a memory-parallel computing model, but it is not optimized for time-series data.

[0004] Flink is a stream processing framework that supports real-time computation using Table API and SQL. It can connect to external systems via TableConnector, but it is primarily used for streaming computation rather than ad-hoc queries.

[0005] One existing technology is a federated query architecture based on Presto. This approach configures TDengineConnector, MySQL Connector, Kafka Connector, etc., in Presto to execute cross-origin SQL through Presto's distributed query engine. This approach has three drawbacks: First, it has high architectural complexity, requiring independent deployment of a Presto cluster, resulting in high maintenance costs. Second, Presto's query optimizer is designed for general relational data and cannot utilize the time-range characteristics of time-series data for pruning optimization. Third, data needs to be pulled into the Presto cluster's memory for processing, causing additional network transmission and computational resource consumption.

[0006] The second existing technology is real-time data integration based on Flink. This solution uses Flink CDC to capture changes in the data source, synchronizes them in real time to a unified storage such as DataX, and then performs query analysis. This solution has three drawbacks: First, real-time synchronization has a latency of seconds, which cannot meet the needs of ad-hoc queries. Second, redundant data storage doubles the storage cost. Third, the synchronization link is complex, making fault diagnosis difficult.

[0007] The third existing technology is TDengine's data subscription and taosAdapter interface. This solution provides an HTTP RESTful interface through taosAdapter, allowing external applications to implement their own data aggregation logic. This solution has two drawbacks: First, implementing federated queries at the application layer incurs high development costs, with each application reinventing the wheel. Second, it lacks a unified query optimization and security control mechanism.

[0008] In existing technologies, enterprise time-series data is scattered across multiple TDengine clusters, traditional relational databases, and big data platforms, forming data silos. Cross-source correlation analysis requires data migration, leading to a surge in network bandwidth and storage costs. Data migration introduces the risk of sensitive data being taken off-site, violating data security and compliance requirements, especially in critical infrastructure areas such as industrial control and energy management. Existing federated query solutions use external components such as Presto or Flink, which have complex architectures, high resource consumption, and cannot be specifically optimized for the characteristics of time-series data, resulting in poor query performance. Time alignment and label mapping for cross-source time-series data lack automated mechanisms, and manual configuration is costly and prone to errors. Summary of the Invention

[0009] The purpose of this invention is to overcome the existing defects and provide a time-series data federated query method and system based on TDengine.

[0010] To solve the above-mentioned technical problems, the present invention provides the following technical solution: The primary objective of this invention is to provide a time-series data federated query method based on TDengine, comprising the following steps: Configure virtual super tables in the TDengine query engine to uniformly map heterogeneous data sources to TDengine super table semantics, and connect multiple TDengine clusters, relational databases, message queues or file systems through adapters; It receives cross-source query SQL submitted by the client, identifies the data sources involved through the query parsing layer, and retrieves metadata using the schema cache; The logical execution plan is optimized by a time-series feature-aware query optimizer. The query optimizer uses rules including time range pushdown, label filtering pushdown, aggregation operator decomposition, time-series join optimization, and pre-computed summary utilization to generate multiple physical execution plans and select the optimal physical execution plan based on the cost model. The optimal physical execution plan is decomposed into subqueries and sent to each data source adapter in parallel. Each data source adapter executes the subqueries locally and performs query-level desensitization, only returning the aggregated summary or filtered results serialized. The coordinating node receives the results from each data source, performs global aggregation, sorting, and limit operations, and streams the final results back to the client.

[0011] Furthermore, the creation process of the virtual super table includes: Retrieve and parse the user-submitted CREATE VIRTUAL STABLE statement, extracting the data source type, connection configuration, local table name, and schema hints; The adapter connects to the corresponding data source and performs automatic schema discovery. It samples data rows and analyzes column features to identify timestamp columns and candidate label columns, generates a schema mapping draft and a label mapping draft, and persists the metadata after user confirmation and registers it to the schema cache.

[0012] Furthermore, the virtual super table includes the following metadata: global table name, data source type, connection configuration, local table name or topic name, schema mapping definition, tag mapping definition, and sampled data cache; The proposed tag mapping is based on column cardinality and keyword identification of candidate tags. Tag conflicts from different data sources are resolved through a tag alias mapping table, and the tag value format is unified.

[0013] Furthermore, the optimization rules of the query optimizer specifically include: The time range is pushed down to identify timestamp conditions in the WHERE clause and convert the time range into native filtering conditions for each data source. Tag filtering is pushed down to identify tag equality conditions and range conditions, and then pushed down to the data source for execution. The aggregation operator decomposition breaks down global aggregation into two stages: local aggregation of data sources and global aggregation. Local aggregation is executed in each data source and only returns the aggregation result, while global aggregation merges the local results at the coordination node. The time-series join optimization identifies scenarios where two time-series tables are associated by timestamp and optimizes them into a sliding window alignment algorithm. For non-precise timestamp matching, a nearest neighbor matching strategy is adopted, and data alignment is performed on the local data source based on the configured tolerance window. For precise matching, it is converted into a timestamp equal-value join condition.

[0014] If the data source maintains a pre-computed summary in a pre-aggregated table or materialized view of TDengine, the rewritten query utilizes the summary data instead of the original data.

[0015] Furthermore, in the selection of the optimal physical execution plan based on the cost model, the cost model comprehensively evaluates network transmission cost, computational complexity cost, I / O scan cost and timing feature weighting factor, and selects the physical execution plan with the minimum total cost as the optimal plan; Among them, the temporal feature weight factor is dynamically calculated based on the time range span, tag filtering selection rate, aggregation granularity, and pre-calculated summary hit rate.

[0016] Furthermore, the query-level desensitization specifically includes: Sensitive fields are processed locally in each data source according to pre-configured de-identification rules. Processing methods include device ID hashing, geographic location obfuscation, or numerical range simplification, so that the original sensitive data does not leave the domain.

[0017] Another objective of this invention is to provide a time-series data federated query system based on TDengine, characterized in that the system comprises a query interface layer, a query parsing layer, a query optimization layer, a data source adaptation layer, and a data source layer connected in sequence. The query interface layer is compatible with TDengine standard SQL syntax, extends the FEDERATED keyword to identify cross-source queries, and supports JDBC, ODBC, and RESTful API access; The query parsing layer includes an SQL parser, a schema cache, and a cross-source query identifier. The SQL parser is an extension of the TDengine native parser, adding support for federated query syntax. The schema cache is used to maintain the table structure, tag definitions, and sampled data of each data source. The cross-source query identifier is used to analyze the FROM clause and JOIN conditions to identify the data sources involved. The query optimization layer includes a time-series feature extractor, an optimization rule engine, and an execution plan generator. The time-series feature extractor is used to extract time range, label filtering conditions, and aggregation granularity from query conditions. The optimization rule engine is used to apply time-series-specific optimization rules. The execution plan generator is used to construct a distributed execution plan tree.

[0018] The data source adaptation layer includes a TDengine cluster adapter, a relational database adapter, a message queue adapter, and a file system adapter. Each adapter implements a unified virtual super table abstraction, shielding the differences in the underlying storage. The data source layer includes multiple TDengine clusters, MySQL, PostgreSQL, Kafka, and HDFS heterogeneous storage systems.

[0019] Furthermore, it also includes a security control module for implementing role-based data source access permissions, with fine granularity down to the table and column levels, as well as recording audit logs for all cross-source queries.

[0020] Another object of the present invention is to provide an electronic device, including a processor and a memory storing a computer program, wherein the processor executes the computer program to implement the TDengine-based time-series data federated query method provided by the first object of the present invention.

[0021] Another object of the present invention is to provide a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the TDengine-based time-series data federated query method provided by the first object of the present invention.

[0022] In combination with the above technical solutions, the beneficial effects of the present invention compared with the prior art are as follows: Simplified architecture: This invention can extend federated query capabilities within the native TDengine engine without the need for separate deployment of Presto or Flink clusters, reducing the number of operation and maintenance nodes by more than 60% and significantly reducing architectural complexity.

[0023] Cost-controllable: This invention reduces network bandwidth consumption by 90% through a query mode that eliminates the need for redundant data storage, reducing storage costs by over 50%. Query pushdown and aggregated summary transmission reduce data transmission volume by 95%.

[0024] Superior query performance: This invention optimizes cross-source time-series queries by reducing latency from minutes to seconds through time-series feature awareness, achieving a performance improvement of more than 5 times compared to the Presto solution. Time range pruning avoids full scans, aggregation pushdown reduces transmission volume, and time-series join optimization reduces computational complexity. The introduced cost model accurately assesses the resource consumption of different execution strategies, dynamically selecting the optimal execution path in complex cross-source scenarios, further improving query efficiency by more than 20%.

[0025] Security and Compliance: This invention meets data security regulations through query-level anonymization and auditing mechanisms, ensuring that sensitive data does not leave the domain and supporting applications in heavily regulated industries such as finance, energy, and healthcare. Attached Figure Description

[0026] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings: Figure 1 This is a flowchart of the time-series data federated query method based on TDengine provided in this embodiment of the invention; Figure 2 This is a schematic diagram of the architecture of the time-series data federated query system based on TDengine provided in this embodiment of the invention. Detailed Implementation

[0027] The preferred embodiments of the present invention will be described below with reference to the accompanying drawings. It should be understood that the preferred embodiments described herein are for illustration and explanation only and are not intended to limit the present invention.

[0028] Example 1:

[0029] like Figure 1 The image shows an embodiment of the time-series data federated query method based on TDengine provided by the present invention, which specifically includes the following steps: S1: Configure a virtual super table in the TDengine query engine to uniformly map heterogeneous data sources to TDengine super table semantics, and connect multiple TDengine clusters, relational databases, message queues or file systems through adapters; S2: Receive cross-source query SQL submitted by the client, identify the data sources involved through the query parsing layer, and obtain metadata using the schema cache; S3: The logical execution plan is optimized by a time-series feature-aware query optimizer. The query optimizer uses rules including time range pushdown, label filtering pushdown, aggregation operator decomposition, time-series join optimization, and pre-computed summary utilization to generate multiple physical execution plans and select the optimal physical execution plan based on the cost model. S4: Decompose the optimal physical execution plan into subqueries and send them to each data source adapter in parallel. Each data source adapter executes the subqueries locally and performs query-level desensitization, only returning the aggregated summary or filtered results serialized. S5: The coordinating node receives the results from each data source, performs global aggregation, sorting, and limit operations, and streams the final results back to the client.

[0030] Specifically, the virtual supertable is the core abstract concept in this embodiment, which uniformly maps heterogeneous data sources to the supertable semantics of TDengine. The virtual supertable contains the following metadata: global table name, data source type, connection configuration, local table name or topic name, schema mapping definition, tag mapping definition, and sampled data cache.

[0031] Virtual super table creation process: The creation of a virtual super table begins with the user submitting the CREATE VIRTUAL STABLE statement. The statement is parsed to extract the data source type, connection configuration, local table name, and schema hints.

[0032] The adapter connects to the data source and performs automatic schema discovery. It samples data rows, analyzes column characteristics, and identifies timestamp columns and candidate label columns. It then generates a draft schema mapping and a draft label mapping.

[0033] The system prompts the user to confirm the mapping relationship. The user can adjust the tag recognition results, set desensitization rules, and configure access permissions. After confirmation, the virtual super table metadata is persisted and registered in the schema cache.

[0034] The TDengine cluster adapter is implemented as follows: For multiple homogeneous TDengine clusters, the adapter maintains cluster topology information, including node addresses, database names, and super table names. During queries, the global table name is mapped to the local database name plus the super table name, and the SQL statement is directly forwarded.

[0035] The relational database adapter is implemented as follows: For relational databases such as MySQL and PostgreSQL, the adapter maps time-series data tables to virtual super tables. Schema mapping maps the columns of the relational table to TDengine columns with labels, and timestamp columns are identified as primary timestamps. Label mapping supports static configuration and automatic discovery. During automatic discovery, the cardinality of the sampled data rows is analyzed, and low-cardinality columns are automatically identified as candidate labels.

[0036] The message queue adapter is implemented as follows: For streaming data sources such as Kafka and MQTT, the adapter maps topics to virtual super tables. The schema is inferred from the schema registry or sampled messages, supporting Avro, JSON, and Protobuf formats. Timestamps are extracted from message fields or Kafka message timestamps.

[0037] The file system adapter is implemented as follows: For Parquet and ORC files on HDFS and S3, the adapter maps file directories to virtual supertables. It utilizes time ranges in file metadata for partition pruning and supports predicate pushdown to the file read layer.

[0038] Timing Join Execution Flow: The execution of a time-series join begins with identifying the join conditions. If the join key contains a timestamp, the time-series join optimization path is entered.

[0039] The coordinating node sends a subquery to the data sources of both tables, containing filtered conditions with an expanded time range. The expanded range is determined by the configured tolerance window; for example, if querying data for 1 hour, it is expanded to 1 hour plus 5 seconds before and after.

[0040] Each data source returns a data stream sorted by timestamp. The coordinating node executes a merge sort algorithm to align the timestamps of the left and right streams. For exact matches, a direct association is performed. For nearest neighbor matches, the nearest data point is found within a tolerance window.

[0041] The aligned result is then projected and filtered before being returned to the client. The entire process is streamed to avoid full loading.

[0042] As a preferred embodiment, the query optimizer in this embodiment adopts a time-series-specific optimization rule set, which includes five core rules.

[0043] The first rule is time range pushdown. It identifies timestamp conditions in the WHERE clause and converts the time range into native filtering conditions for each data source. For TDengine, this is converted to timestamp range queries; for relational databases, it's converted to index range scans; and for file systems, it's converted to directory partition selection.

[0044] The second rule is tag filtering pushdown. It identifies tag equality conditions and range conditions and pushes them down to the data source for execution. For TDengine, this utilizes tag indexes; for relational databases, it's converted to WHERE conditions; and for Kafka, it's converted to Topic partition selection or message filtering.

[0045] The third rule is aggregation operator decomposition. Global aggregation is decomposed into two stages: local aggregation at each data source and global aggregation. Local aggregation is executed at each data source, returning only the aggregation result. Global aggregation merges the local results at the coordinating node. Supported aggregation functions include COUNT, SUM, AVG, MIN, MAX, FIRST, LAST, PERCENTILE, etc.

[0046] The fourth rule is time series join optimization. It identifies scenarios where two time series tables are joined by timestamps and optimizes this to a sliding window alignment algorithm. For inaccurate timestamp matching, a nearest neighbor matching strategy is used, with a configurable tolerance window such as 5 seconds. For exact matches, it is converted to a timestamp-equal-value join.

[0047] The fifth rule is the use of pre-computed summaries. If the data source maintains pre-computed summaries, such as TDengine's pre-aggregated tables or materialized views, the optimizer rewrites queries using the summary data instead of the original data.

[0048] The optimizer execution flow is as follows: First, it parses the query to generate a logical plan tree. Then, it extracts time-series features, including time range, label filtering, aggregation granularity, and join conditions. Next, it applies five optimization rules in sequence to generate a physical execution plan. Finally, it estimates the cost of each plan and selects the optimal plan.

[0049] In the selection of the optimal physical execution plan based on the cost model, the cost model comprehensively evaluates the network transmission cost, computational complexity cost, I / O scan cost, and temporal feature weighting factor, and selects the physical execution plan with the minimum total cost as the optimal plan; among which, the temporal feature weighting factor is dynamically calculated based on the time range span, tag filtering selection rate, aggregation granularity, and pre-computed summary hit rate.

[0050] The secure federated analysis of data not leaving the domain in this embodiment is reflected in: The query execution adopts a distributed pipeline architecture to ensure that the original data does not leave the domain.

[0051] The execution process is divided into three stages. The first stage is query decomposition, where the coordinating node breaks down the global SQL into subqueries, each targeting a single data source. Subqueries include pushdown filtering conditions, aggregation operators, and a list of returned columns.

[0052] The second phase involves parallel execution, where each data source adapter executes subqueries locally. For TDengine, subqueries are executed directly by the local query engine. For relational databases, SQL is sent via JDBC. For Kafka, a Consumer is used to pull data and perform local filtering and aggregation. The execution results are serialized into a compressed columnar format such as Arrow.

[0053] The third stage is result aggregation. The coordinating node receives the aggregated results from various data sources and performs global aggregation, sorting, limit, and other operations. The results are returned to the client in a streaming manner to avoid full caching.

[0054] The security layer implements three mechanisms. The first is query-level data masking, where sensitive fields are configured with masking rules, including device ID hashing, geolocation obfuscation, and numerical range definition. Masking is performed locally on the data source and completed before leaving the domain. The second is access control, with role-based data source access permissions, granular down to the table and column levels. The third is audit logs, recording all cross-source queries' SQL, data source, number of returned rows, and execution time, supporting compliance auditing and tracing.

[0055] The schema auto-discovery process in this embodiment is as follows: Upon initial configuration of the virtual supertable, the adapter connects to the data source to sample data. For TDengine, the DESCRIBE command is executed to obtain the schema. For relational databases, the INFORMATION_SCHEMA is queried. For Kafka, sample messages are consumed to infer the schema.

[0056] The intelligent label mapping algorithm in this embodiment is as follows: It analyzes the cardinality (i.e., the number of unique values) of each column in the sampled data. Columns with a cardinality below 1000 are marked as candidate labels. Columns containing specific keywords such as device, sensor, and location are promoted to higher label priority. For timestamp columns, the format is identified and mapped to primary timestamp.

[0057] Tag conflict resolution is achieved by maintaining a tag alias mapping table when tags with the same meaning from different data sources have inconsistent names. Global tag names are used during queries, and converted to local tag names during execution. Tag value normalization is supported, such as case sensitivity and unit conversion.

[0058] This invention directly extends federated query capabilities within the native TDengine engine, eliminating the need for independent deployment of external clusters such as Presto or Flink, fundamentally solving the problems of complex architecture and numerous maintenance nodes. Specific technical benefits include: a 100% reduction in the number of deployed nodes. In a 5-node TDengine cluster environment of the same size, the Presto federated solution requires at least 8 additional nodes, and the Flink CDC solution requires at least 6 additional nodes, while this invention requires no additional nodes; a 75% reduction in component dependencies, eliminating the need for external components such as ZooKeeper and Hive Metastore, reducing the number of components from 12 in the Presto solution to 3; and an over 80% reduction in operational learning costs, as all federated query logic is embedded within the TDengine engine, uniformly utilizing TDengine's operational toolchain.

[0059] This invention utilizes a time-series feature-aware query optimizer to specifically optimize the time range characteristics, tag indexing mechanism, and aggregation mode of time-series data, fundamentally solving the problem of low query performance caused by the inability of existing federated query schemes to utilize the characteristics of time-series data. The specific technical effects are as follows: Cross-source time-series query latency is significantly reduced. When performing aggregation queries across three TDengine clusters (each with 100 million rows of data), the query latency of this invention is 8.5 seconds, compared to 145.2 seconds for the Presto solution and 198.6 seconds for the Flink CDC solution, representing performance improvements of 17.1 times and 23.4 times, respectively. Time-series join query efficiency is significantly improved. For a scenario of joining two time-series tables by timestamp, with a data scale of 1 billion rows, the sliding window alignment algorithm of this invention executes the join in 65.3 seconds, while Presto's general Hash Join requires 1200.5 seconds, representing a performance improvement of 18.4 times. Pre-computed digests further accelerate the process. When the data source maintains a TDengine pre-aggregate table, in a daily-granularity aggregation query scenario, the query latency is further reduced from 65.3 seconds for the original data to 0.8 seconds, achieving an acceleration ratio of 81.6 times.

[0060] This invention achieves a "data not leaving the domain" federated analysis model through query pushdown and aggregation summary transmission mechanisms. Specific technical effects include: significantly reduced network bandwidth consumption. In a scenario with 10 million rows of aggregation queries, the original data volume is approximately 4.5GB. Presto needs to pull approximately 4.3GB of the entire data into memory, while this invention only transmits the aggregation summary of approximately 18.5MB, reducing network transmission volume by 99.6%. Significantly reduced storage costs. In a scenario with 5 data sources and a total of 50TB of time-series data, the Flink CDC solution requires an additional 50TB of synchronous storage, incurring additional monthly cloud storage costs. This invention requires no additional storage, reducing storage costs by 100%. Sensitive data does not leave the domain. By performing query-level anonymization locally on each data source, taking the energy industry scenario as an example, time-series data involving 100,000 electricity meters is processed. Device IDs are hashed using SHA-256 and their geographical locations are obfuscated to 500-meter accuracy using GeoHash, meeting the compliance requirements of the Data Security Law and the Personal Information Protection Law.

[0061] This invention fundamentally solves the problems of reliance on manual configuration, high configuration costs, and susceptibility to errors by using an automatic schema discovery and intelligent tag mapping algorithm for virtual super tables. Specifically, the technical effects are as follows: high accuracy in automatic schema discovery; in a test environment including five heterogeneous data sources (TDengine, MySQL, PostgreSQL, Kafka, and HDFS), the accuracy rate for identifying timestamp columns reached 98.5% (197 / 200 test tables), and the accuracy rate for identifying candidate tag columns reached 94.0% (470 / 500 test columns); high efficiency in tag conflict resolution; in tests across five data sources, there were instances of inconsistent tag naming (e.g., device_id, dev_id...). (deviceID and d_id actually represent the same meaning). The tag alias mapping table of this invention automatically identifies conflicts through column cardinality similarity and keyword matching, with an automatic resolution rate of 87.3%. The configuration time is reduced from 4-6 hours in manual solutions to 15-30 minutes, improving efficiency by 90%. The time alignment accuracy of time-series joins is high. For nearest neighbor joins with non-precise timestamp matching, under a tolerance window of 5 seconds, the data alignment accuracy reaches 99.97% in the join test of 1 billion rows × 2 tables, meeting the data alignment accuracy requirements of industrial control scenarios.

[0062] This invention addresses the lack of an execution plan cost evaluation mechanism tailored to the characteristics of time-series data by introducing a cost model that integrates network transmission cost, computational complexity cost, I / O scan cost, and a time-series feature weighting factor. Specifically, the technical effects are as follows: high execution plan selection accuracy. In a test set containing 100 typical cross-source queries, the optimal execution plan selected by the cost model of this invention achieved an accuracy of 92% after actual execution verification. In contrast, the accuracy of heuristic strategies based on fixed rules was only 67%, representing a 25 percentage point improvement by the cost model. Significant performance improvement in complex scenarios. In complex query scenarios involving time range filtering, tag filtering, aggregation, time-series join, and pre-computed summaries, the cost model dynamically adjusts the time-series feature weighting factor W. ts It can adaptively select optimization strategies based on query characteristics, reducing the average latency of complex queries from 185.3 seconds to 42.6 seconds, an improvement of 4.3 times; the cost estimation accuracy continues to improve. Through the feedback and update mechanism of actual statistical information after query execution, after online learning of 1,000 queries, the prediction error of the cost model has been reduced from the initial 35% to 8%, meeting the accuracy requirements of the production environment for execution plan selection.

[0063] The technical effects of the present invention will be further explained below with reference to simulation experiments.

[0064] When executing a single-table aggregation query "SELECT location, AVG(temperature) FROM sensor WHERE ts>'2024-06-01' AND ts<'2024-06-02' GROUP BY location, 1h" across three TDengine clusters, the execution flow of this invention is as follows: the query parsing layer identifies three data sources; the time-series feature extractor extracts the time range (1 day) and label filtering (location); the optimizer applies time range pushdown (each cluster scans only 1 day of data, not all 2 years of data) and aggregation operator decomposition (each cluster calculates hourly averages locally); each cluster returns 24 aggregated records; the coordinating node merges 72 records, sorts them, and returns the result, with a total latency of 0.35 seconds. The Presto solution's execution flow is as follows: it pulls 1 day's raw data (approximately 450MB) from the three clusters to Presto memory; filtering and aggregation are performed in Presto, with a total latency of 2.5 seconds. The latency of this invention's solution is 14% of Presto's.

[0065] When executing the time-series Join query "SELECT a.device_id, a.temperature, b.pressure FROM sensor_temp a JOIN sensor_pressure b ON a.device_id=b.device_id AND a.ts=b.tsWHERE a.ts>'2024-06-01'AND a.ts<'2024-06-02'", the present invention optimizes the identification of timestamp-equal Join conditions through time-series Join, converting it into a sliding window alignment algorithm. After scanning one day of data from each table, the data is merged and sorted by timestamp, resulting in a Join complexity of O(N+M). The Presto solution uses a general Hash Join, requiring the full data from both tables to be loaded into memory to build a hash table, resulting in a Join complexity of O(N×M). In a scenario where each table has 100 million rows of data, the present invention's solution has a latency of 65.3 seconds, while the Presto solution has a latency of 1200.5 seconds.

[0066] In the cost model test, for the large-span aggregation query "SELECT AVG(voltage) FROM meterWHERE ts>'2023-01-01'AND ts<'2024-01-01'AND location='Beijing' GROUP BY 1d", the cost model calculates the time-series feature weight factor W. ts =0.3×log(365)+0.3×(1-0.02)+0.2×0.1+0.2×1.0=0.768+0.294+0.02+0.2=1.282. Since W ts Larger and pre-computed summary hit rate H pre =1.0, with the cost model selected using the pre-calculated digest utilization strategy, the query latency is 2.3 seconds. If the full scan strategy is selected, the estimated latency is 420.5 seconds. Actual execution verification shows that the actual latency for the digest strategy is 2.1 seconds, and the actual latency for the scan strategy is 415.3 seconds, indicating that the cost model selection is correct.

[0067] For a small-span aggregation query, "SELECT AVG(voltage) FROM meter WHERE ts>'2024-06-01' AND ts<'2024-06-02' AND location='Beijing'GROUP BY 1h", where the time range spans T... span =1 day, tag filter selectivity S select =0.05, pre-calculated summary hit rate H pre =0, calculated as W ts=0.3×log(1)+0.3×(1-0.05)+0.2×0.1+0.2×0=0+0.285+0.02+0=0.305. Since W ts The cost model tends to choose a time range pushdown plus label filtering pushdown strategy, with a query latency of 0.15 seconds, which is better than the 0.85 seconds of the fixed rule strategy.

[0068] Example 2:

[0069] like Figure 2 As shown, this embodiment of the invention provides a time-series data federated query system based on TDengine, including a query interface layer, a query parsing layer, a query optimization layer, a data source adaptation layer, and a data source layer connected in sequence. The query interface layer is compatible with TDengine standard SQL syntax, extends the FEDERATED keyword to identify cross-source queries, and supports JDBC, ODBC, and RESTful API access; The query parsing layer includes an SQL parser, a schema cache, and a cross-source query identifier. The SQL parser is an extension of the TDengine native parser, adding support for federated query syntax. The schema cache is used to maintain the table structure, tag definitions, and sampled data of each data source. The cross-source query identifier is used to analyze the FROM clause and JOIN conditions to identify the data sources involved. The query optimization layer includes a time-series feature extractor, an optimization rule engine, and an execution plan generator. The time-series feature extractor is used to extract time range, label filtering conditions, and aggregation granularity from query conditions. The optimization rule engine is used to apply time-series-specific optimization rules. The execution plan generator is used to construct a distributed execution plan tree.

[0070] The data source adaptation layer includes a TDengine cluster adapter, a relational database adapter, a message queue adapter, and a file system adapter. Each adapter implements a unified virtual super table abstraction, shielding the differences in the underlying storage. The data source layer includes multiple TDengine clusters, MySQL, PostgreSQL, Kafka, and HDFS heterogeneous storage systems.

[0071] Preferably, this embodiment also includes a security control module for implementing role-based data source access permissions, with fine granularity down to the table and column levels, and recording audit logs for all cross-source queries.

[0072] Example 3:

[0073] This invention provides an electronic device, including a processor and a memory storing a computer program. When the processor executes the computer program, it implements the TDengine-based time-series data federated query method provided by the first objective of this invention.

[0074] Example 4:

[0075] The present invention provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the time-series data federated query method based on TDengine provided by the first objective of the present invention.

[0076] It should be understood that although the steps in the flowcharts of the various embodiments of the present invention are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated in the present invention, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least some steps in the various embodiments may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least a portion of the sub-steps or stages of other steps.

[0077] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided by this invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0078] Finally, it should be noted that the above descriptions are merely preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A time-series data federated query method based on TDengine, characterized in that, The method includes the following steps: Configure virtual super tables in the TDengine query engine to uniformly map heterogeneous data sources to TDengine super table semantics, and connect multiple TDengine clusters, relational databases, message queues or file systems through adapters; It receives cross-source query SQL submitted by the client, identifies the data sources involved through the query parsing layer, and retrieves metadata using the schema cache; The logical execution plan is optimized by a time-series feature-aware query optimizer. The query optimizer uses rules including time range pushdown, label filtering pushdown, aggregation operator decomposition, time-series join optimization, and pre-computed summary utilization to generate multiple physical execution plans and select the optimal physical execution plan based on the cost model. The optimal physical execution plan is decomposed into subqueries and sent to each data source adapter in parallel. Each data source adapter executes the subqueries locally and performs query-level desensitization, only returning the aggregated summary or filtered results serialized. The coordinating node receives the results from each data source, performs global aggregation, sorting, and limit operations, and streams the final results back to the client.

2. The time-series data federated query method based on TDengine according to claim 1, characterized in that, The creation process of the virtual super table includes: Retrieve and parse the user-submitted CREATE VIRTUAL STABLE statement, extracting the data source type, connection configuration, local table name, and schema hints; The adapter connects to the corresponding data source and performs automatic schema discovery. It samples data rows and analyzes column features to identify timestamp columns and candidate label columns, generates a schema mapping draft and a label mapping draft, and persists the metadata after user confirmation and registers it to the schema cache.

3. The time-series data federated query method based on TDengine according to claim 2, characterized in that, The virtual super table contains the following metadata: global table name, data source type, connection configuration, local table name or topic name, schema mapping definition, tag mapping definition, and sampled data cache; The proposed tag mapping is based on column cardinality and keyword identification of candidate tags. Tag conflicts from different data sources are resolved through a tag alias mapping table, and the tag value format is unified.

4. The time-series data federated query method based on TDengine according to claim 1, characterized in that, The optimization rules of the query optimizer specifically include: The time range is pushed down to identify timestamp conditions in the WHERE clause and convert the time range into native filtering conditions for each data source. Tag filtering is pushed down to identify tag equality conditions and range conditions, and then pushed down to the data source for execution. The aggregation operator decomposition breaks down global aggregation into two stages: local aggregation of data sources and global aggregation. Local aggregation is executed in each data source and only returns the aggregation result, while global aggregation merges the local results at the coordination node. The time series join optimization identifies scenarios where two time series tables are joined by timestamps and optimizes them into a sliding window alignment algorithm. For non-precise timestamp matching, a nearest neighbor matching strategy is adopted, and data alignment is performed on the local data source based on the configured tolerance window. For precise matching, it is converted into a timestamp equal value join condition. If the data source maintains a pre-computed summary in a pre-aggregated table or materialized view of TDengine, the rewritten query utilizes the summary data instead of the original data.

5. The time-series data federated query method based on TDengine according to claim 1, characterized in that, In the selection of the optimal physical execution plan based on the cost model, the cost model comprehensively evaluates network transmission cost, computational complexity cost, I / O scan cost and timing feature weighting factor, and selects the physical execution plan with the minimum total cost as the optimal plan; Among them, the temporal feature weight factor is dynamically calculated based on the time range span, tag filtering selection rate, aggregation granularity, and pre-calculated summary hit rate.

6. The time-series data federated query method based on TDengine according to claim 1, characterized in that, The query-level masking specifically includes: Sensitive fields are processed locally in each data source according to pre-configured de-identification rules. Processing methods include device ID hashing, geographic location obfuscation, or numerical range scaling, so that the original sensitive data does not leave the domain.

7. A time-series data federated query system based on TDengine, characterized in that, The system comprises a query interface layer, a query parsing layer, a query optimization layer, a data source adaptation layer, and a data source layer, which are connected in sequence. The query interface layer is compatible with TDengine standard SQL syntax, extends the FEDERATED keyword to identify cross-source queries, and supports JDBC, ODBC, and RESTful API access; The query parsing layer includes an SQL parser, a schema cache, and a cross-source query identifier. The SQL parser is an extension of the TDengine native parser, adding support for federated query syntax. The schema cache is used to maintain the table structure, tag definitions, and sampled data of each data source. The cross-source query identifier is used to analyze the FROM clause and JOIN conditions to identify the data sources involved. The query optimization layer includes a time-series feature extractor, an optimization rule engine, and an execution plan generator. The time-series feature extractor is used to extract time range, label filtering conditions, and aggregation granularity from query conditions. The optimization rule engine is used to apply time-series-specific optimization rules. The execution plan generator is used to construct a distributed execution plan tree. The data source adaptation layer includes a TDengine cluster adapter, a relational database adapter, a message queue adapter, and a file system adapter. Each adapter implements a unified virtual super table abstraction, shielding the differences in the underlying storage. The data source layer includes multiple TDengine clusters, MySQL, PostgreSQL, Kafka, and HDFS heterogeneous storage systems.

8. The time-series data federated query method based on TDengine according to claim 1, characterized in that, It also includes a security control module for implementing role-based data source access permissions, with fine granularity down to the table and column levels, and for recording audit logs for all cross-source queries.

9. An electronic device comprising a processor and a memory storing a computer program, characterized in that, When the processor executes the computer program, it implements the time-series data federated query method based on TDengine as described in any one of claims 1 to 6.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the time-series data federated query method based on TDengine as described in any one of claims 1 to 6.