Real-time streaming computing window optimization method for multi-source heterogeneous data fusion
By constructing a common baseline window and a plan status mapping table, the problem of inconsistent query plan switching in multi-source heterogeneous data processing is solved, achieving smooth migration of window status and consistency of results in streaming databases, and reducing redundant calculations and data omissions.
Patent Information
- Application Number
- CN202611381885.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-08
- Publication Date
- 2026-11-27
AI Technical Summary
In multi-source heterogeneous data processing environments, existing technologies struggle to effectively coordinate window state migration, recalculation range, and query plan switching in streaming databases, leading to inconsistencies and duplication in data processing.
By constructing a common baseline window, rewriting the query plan, establishing a plan status mapping table, dividing the state into migrateable and recalculated states, and combining boundary result fingerprints with window end state fingerprint verification, the query waterline is controlled to achieve smooth switching and state consistency of the query plan.
It improves the consistency of query plan switching results in multi-source heterogeneous data processing, reduces redundant calculations and data omissions, and ensures the continuity and accuracy of streaming data processing.
Smart Images

Figure CN123178446A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of continuous database query processing technology in big data processing, and in particular to a real-time streaming computing window optimization method for multi-source heterogeneous data fusion. Background Technology
[0002] With the increasing scale and arrival rate of real-time data in big data processing, streaming databases and streaming query engines are widely used to continuously receive and process streaming data from multiple heterogeneous data sources. Streaming databases typically map continuously arriving data to streaming relational tables and continuously execute query processing based on pre-registered continuous query statements. These continuous query statements typically include window operators, multi-table join operators, and aggregation operators. Window operators are used to limit the range of data participating in the query according to event time; multi-table join operators are used to establish relationships between different streaming relational tables based on association key fields; and aggregation operators are used to perform statistical processing on the data within the window range.
[0003] Continuous queries are characterized by continuous execution and maintenance of query state. As the data patterns of heterogeneous data sources, continuous query conditions, or the arrival status of streaming data change, the original query plan may no longer meet the current query processing requirements, necessitating a switch from the currently executing initial query plan to a newly generated candidate query plan. Since window operators, multi-table join operators, and aggregation operators typically need to save window state, join matching state, or aggregation state, query plan switching involves not only adjusting the operator execution order but also the correspondence, migration, and recalculation of window states between different query plans.
[0004] The paper "Dynamic Plan Migration for Continuous Queries Over Data Streams" by Yali Zhu, Elke A. Rundensteiner, and George T. Heineman proposes a dynamic migration method for query plans in continuous data stream queries. This method migrates an executing continuous query plan to another semantically equivalent query plan, and proposes a state movement strategy and a parallel track strategy for query plans containing state operators. The state movement strategy migrates reusable states based on the correspondence between operator states in the old and new query plans, and reconstructs states that cannot be directly reused. The parallel track strategy enables the old and new query plans to process input data in parallel during the migration and controls the output of the results from both plans.
[0005] The dynamic migration method for query plans described above can address, to some extent, the issues of state reuse and result output during online conversion of continuous query plans. However, when multiple heterogeneous data sources participate in continuous queries, different streaming relational tables may have different data schemas, event time fields, and association key fields. When the data schema changes, the mapping relationship between the unified field identifier and the source field may change accordingly, thus affecting the state key, state value, and state dependencies between window operators. Judging whether a window state can be reused solely based on operator type or state data structure makes it difficult to accurately determine the window states affected by data schema changes and the range of states that need to be recalculated.
[0006] Furthermore, after rewriting the windowing operators, multi-table join operators, and aggregation operators in the continuous query plan, the old and new query plans may employ different window boundary partitioning methods or different operator dependencies. The same streaming data record may have different window entry and exit times in the two query plans, and the join matching status of the multi-table join operator may also change with changes in window members. For late streaming data records arriving after the corresponding window has ended, corrections to the existing window state may also occur. If only the final aggregation results output by the old and new query plans are compared, it is difficult to determine whether window entry records, window exit records, late correction records, and join matching change records are consistent in the two query plans, and it is also difficult to discover situations where the final results are the same but the intermediate window states have differed.
[0007] Continuous query plan switching also requires selecting a switching point that aligns with the progress of window state processing. If the switch is performed before the relevant streaming data records have been processed or the window state has not yet closed, some streaming data records may be processed repeatedly, missed, or written to incorrect window states. Once the candidate query plan has completed its window state migration and taken effect, if subsequent verification reveals inconsistencies between the migration result and the initial query plan, it is necessary to restore the initial query plan and its corresponding window state. Current technology struggles to coordinate window state migration, recalculation of pending states, query plan switching, and version recovery after verification failures based on the state correspondence between the old and new query plans, the progress of window boundary processing, and the consistency of query results.
[0008] Therefore, in a multi-source heterogeneous big data processing environment, the main technical problem that needs to be solved in continuous query processing of streaming databases is how to determine the migration and recalculation range of window states based on the window state correspondence between the old and new query plans during the continuous reception of streaming data records, and complete the query plan switching at the boundary that is compatible with the window state processing progress, while maintaining the consistency of window entry, window exit, late correction, connection matching results and window end state fingerprint before and after the switch. Summary of the Invention
[0009] To overcome the aforementioned technical deficiencies, the present invention aims to provide a real-time streaming computing window optimization method for multi-source heterogeneous data fusion. This invention constructs a common baseline window and rewrites the continuous query plan, establishes a plan state mapping table between the initial query plan and candidate query plans, divides the window state into a migrated state and a recalculation-pending state, and combines boundary result fingerprint and window end state fingerprint verification, query watermark control, query plan and window state version switching, and verification failure recovery to maintain consistency in window state and query results before and after switching multi-source heterogeneous continuous query plans.
[0010] This invention discloses a real-time streaming computing window optimization method for multi-source heterogeneous data fusion, used for continuous database queries in big data processing, including:
[0011] Obtain the data schema, continuous query statements, and query watermarks from heterogeneous data sources, and map the data schema into a streaming relational table with unified field identifiers, event time fields, association key fields, and schema mapping versions;
[0012] The continuous query statement is converted into an initial query plan containing window operators, multi-table join operators and aggregation operators. The initial query plan is parsed to obtain the input relationship of each window operator, the operator dependency relationship between each operator, the field lineage relationship of each unified field identifier between each operator, and the window state dependency relationship between each window state. The window operator has window boundaries, state keys and state values.
[0013] Based on input relationships, window boundaries, association key fields, and operator dependencies, a window dependency cluster is constructed, a common baseline window is determined, and window operators are rewritten as shared window operators that call the common window state and differential window operators that handle boundary differences, generating candidate query plans;
[0014] Establish a plan status mapping table based on field lineage, pattern mapping version, and window status dependency. Divide window status into migrateable status and recalculation status. Configure query plan version for each query plan and window status version for each window status.
[0015] During the verification period between adjacent common baseline window boundaries, each query plan processes the same streaming data records, generating boundary result fingerprints and window end status fingerprints for window entry records, window exit records, late correction records, and connection matching change records.
[0016] When the boundary result fingerprints and window end state fingerprints of each query plan are consistent, and the query waterline reaches the end boundary of the verification period, the window state of the initial query plan is frozen, the migrateable state is migrated and the state to be recalculated is calculated, and the candidate query plan and the window state of the candidate query plan are switched to the effective version.
[0017] If the verification fails during the first verification cycle after the switch, restore the query plan version and window state version of the initial query plan.
[0018] Preferably, the window state is divided into a transitional state and a recalculation-pending state, including:
[0019] Retrieve the source field path, unified field identifier, data type, and association key conversion rules recorded in the current and previous versions of the schema mapping version;
[0020] Compare the current version with the previous version to identify changed fields whose source field paths, uniform field identifiers, data types, or association key conversion rules have changed;
[0021] Following field lineage and operator dependency, the process propagates downstream from the operator that references the modified field, forming a set of affected operators;
[0022] Window states that reference change fields using status keys or status values are classified as pending recalculation states, while window states that do not reference change fields are classified as migrateable states.
[0023] The local replay interval is determined based on the earliest common reference window boundary and the query water level corresponding to the affected operator set, and then written into the plan status mapping table.
[0024] Preferably, the end boundary of the verification period is determined as the version switching boundary, and a source relation table identifier and late arrival allowance are configured for each streaming relation table, and a source sequence identifier is configured for each streaming data record;
[0025] Based on the event time, source relation table identifier, source sequence identifier, and pattern mapping version of the late streaming data record, determine the common baseline window and window state version corresponding to the late streaming data record;
[0026] The allowed lateness interval is determined based on the end boundary of the common reference window and the allowed lateness duration. The start point of the allowed lateness interval is the end boundary of the common reference window, and the end point is the time corresponding to the sum of the end boundary and the allowed lateness duration.
[0027] When the event time is earlier than the version switch boundary and the late allowance interval is not closed, the late streaming data record is written to the window state version corresponding to the initial query plan to generate the late correction amount.
[0028] According to the plan state mapping table, the late correction amount is propagated to the operators in the candidate query plan that depend on the corresponding migrateable state or recalculation state within the local replay interval.
[0029] After the late arrival allowance interval is closed and the late arrival correction has been propagated, close the window state version of the corresponding common baseline window in the initial query plan.
[0030] Preferably, determining the common reference window includes:
[0031] Obtain the window length, window step size, and window start point of each window operator within the same window dependency cluster, determine the grouping field and aggregation function for each window operator, and generate intermediate aggregation states based on the aggregation function;
[0032] Generate a set of common time granularities based on the length and step size of each window;
[0033] Remove common time granularities from the common time granularity set that do not meet the conditions of consistent window start remainder, consistent association key field, consistent grouping field, or mergeable intermediate aggregation state.
[0034] For the remaining covenant time granularities, determine the number of differential boundary segments, the coverage of transferable states, and the cross-window propagation range of late correction records for the corresponding windows.
[0035] The windows are sorted in ascending order by the number of differential boundary segments, descending order by the coverage of migrateable states, and ascending order by the propagation range across windows. The window corresponding to the common time granularity at the top of the sorted list is determined as the common reference window.
[0036] Preferably, generating candidate query plans includes:
[0037] Extract a window join subgraph consisting of window operators, multi-table join operators, and aggregation operators from the initial query plan;
[0038] For the window connection subgraph, generate a first rewrite subgraph that first forms a common window state and then performs multi-table joins, and a second rewrite subgraph that first performs multi-table joins and then forms a common window state.
[0039] For each state operator in the rewritten subgraph, a state equivalence mapping term is generated. The state equivalence mapping term includes the source operator identifier, the target operator identifier, the state key transformation rule, the state value merging rule, and the effective mode mapping version range.
[0040] State dependency paths are formed based on the state dependencies between each state operator;
[0041] Each state-dependent path has a corresponding state-equivalent mapping item, or a rewritten subgraph that can complete state recalculation through streaming data records that do not exceed the window length of the corresponding window operator. The retained rewritten subgraphs are then combined into candidate query plans.
[0042] Preferably, generating a candidate query plan further includes:
[0043] For each candidate query plan, generate a state access list, a state transition path list, and a late correction propagation list;
[0044] The number of state records to be migrated and the number of state records to be recalculated are determined based on the state access list. The common baseline window boundary corresponding to the completion of state migration is determined based on the state migration path list. The set of operators that late correction records can reach is determined based on the late correction propagation list.
[0045] Delete candidate query plans whose state transition completion boundary is later than the end boundary of the next verification cycle;
[0046] Delete the candidate query plans corresponding to the verification paths of records that have not been established for window entry, window exit, late correction, and connection matching changes;
[0047] The remaining candidate query plans are sorted in ascending order by the number of state records to be migrated, the number of state records to be recalculated, and the number of operators that late correction records can reach.
[0048] Preferably, generating boundary result fingerprints and window end state fingerprints includes:
[0049] Configure a source relation table identifier for each streaming relation table and a source sequence identifier for each streaming data record;
[0050] Configure boundary record types for each window entry record, window exit record, late correction record, and connection matching change record, and record the source relation table identifier, source sequence identifier, event time, unified field identifier, association key field value, schema mapping version, pre-state value before state change, and post-state value after state change.
[0051] For records of the same boundary record type and the same associated key field value, sort the corresponding records according to the source sequence identifier to generate a record set fingerprint;
[0052] Connect the subsequent state value of the previous record with the previous state value of the next record in sequence to form a state transition chain, and generate a state transition chain fingerprint based on the state transition chain.
[0053] The fingerprints of each record set and each state transition chain are combined in the order of the preset boundary record types to form the boundary result fingerprint;
[0054] The window status at the end of the verification period is sorted and encoded according to the public baseline window identifier, the associated key field value, the status key, and the status value to form a window end status fingerprint.
[0055] Preferably, when the boundary result fingerprints of the initial query plan and the candidate query plan are inconsistent, the method further includes:
[0056] Determine the first inconsistent boundary record type in the order of window entry record, window exit record, late correction record, and connection matching change record;
[0057] In the record corresponding to the first inconsistent boundary record type, identify the inconsistent record that is first in the source sequence identifier order;
[0058] Based on the unified field identifier, field lineage, and operator dependency of the inconsistent records, determine the earliest divergence operator that produces different state values in the initial query plan and the candidate query plan;
[0059] The bifurcation operator and its downstream operators are defined as recalculated operator subgraphs;
[0060] The operator subgraph is reprocessed and recalculated based on the previous common baseline window boundary corresponding to the divergence operator, and the boundary result fingerprint and window end state fingerprint are regenerated.
[0061] Preferably, the process of obtaining the query water level and determining the version switch boundary includes:
[0062] Configure a late arrival allowance for each streaming relation table participating in consecutive query statements;
[0063] The table closing time is determined based on the maximum event time and corresponding lateness allowance in the streaming data records received for each streaming relation table;
[0064] The earliest closing time among all relation tables is determined as the query water level.
[0065] From the public reference window boundaries that are no later than the query water level line, select the public reference window boundary that does not contain any incomplete late correction records or incomplete connection matching change records that cross the public reference window boundary, and use it as the version switching boundary.
[0066] Preferably, the process of migrating the transferable state and calculating the state to be recalculated includes:
[0067] Using the transitionable state and the state to be recalculated as state nodes, state transition dependency edges are established between each state node based on aggregated state dependency, connected matching state dependency, and differential window state dependency, thus generating a state transition dependency graph.
[0068] Write a status freeze flag for the window status of the initial query plan at the version switch boundary;
[0069] The streaming data records received after the write status freeze flag will be written to the migration buffer according to the source relation table flag and the source sequence flag;
[0070] Transmit the transitionable states according to the state dependency order in the state transition dependency graph and calculate the states to be recalculated.
[0071] For each state node, a node state fingerprint is generated based on the migrated or recalculated state key and state value. After the mapping result of the node state fingerprint is consistent with the corresponding equivalent mapping item in the planned state mapping table, the corresponding successor state node is processed.
[0072] After the migration to the migrateable state is completed and the recalculation of the state to be recalculated is completed, the streaming data records in the migration buffer are written into the window state of the candidate query plan in the order of the source sequence identifier, and the streaming data records in the migration buffer are retained until the end of the first verification cycle after the switch.
[0073] Preferably, the activation of the candidate query plan and the window state of the candidate query plan includes:
[0074] Configure a query output pointer that points to the initial query plan;
[0075] During state transition, the query results of the initial query plan are output through the query output pointer, and the candidate query plan generates a validation query result that is not output through the query output pointer.
[0076] When the candidate query plan completes the state transition and passes the boundary result fingerprint verification of the first verification cycle after the switch, write the version commit identifier and switch the query output pointer to the candidate query plan;
[0077] When a candidate query plan fails the boundary result fingerprint verification, stop writing streaming data records to the window state of the candidate query plan, write the streaming data records in the migration buffer to the window state of the initial query plan, and keep the query output pointer pointing to the initial query plan.
[0078] After the initial query plan has processed the streaming data records in the migration buffer, the query plan version and window state version of the candidate query plan are revoked.
[0079] Preferably, after canceling the query plan version and window state version of the candidate query plan, the method further includes:
[0080] Based on the first inconsistent boundary record type and divergence operator, the cause of the inconsistency in the verification is determined to be inconsistent field mapping, inconsistent window boundary decomposition, inconsistent connection matching state transition, or inconsistent late correction propagation.
[0081] Generate rewrite constraints that prohibit the migration of corresponding window states for inconsistent field mappings;
[0082] For inconsistent window boundary decomposition, the rewrite constraint of the corresponding common reference window is prohibited.
[0083] To address the inconsistent state transitions in connection matching, the rewrite constraints for the corresponding connection matching states are recalculated.
[0084] Rewrite constraints to address inconsistencies in late correction propagation and to expand the set of late correction propagation operators;
[0085] The generated rewrite constraints are associated with and stored in the query operator graph and pattern mapping version corresponding to the consecutive query statements, and candidate query plans that do not meet the rewrite constraints are deleted when candidate query plans are generated again.
[0086] Preferably, after the candidate query plan passes the boundary result fingerprint verification of the first verification cycle after the switch, the method further includes:
[0087] Obtain the query operator graph corresponding to consecutive query statements;
[0088] Generate relation schema fingerprints based on the unified field identifiers, field lineages, and schema mapping versions of each streaming relation table;
[0089] Generate a query operator graph fingerprint based on the operator type, input fields, output fields, and operator dependencies of each operator in the query operator graph;
[0090] Generate a window dependency fingerprint based on window boundaries, common baseline windows, association key fields, and window state dependencies;
[0091] The relation schema fingerprint, query operator graph fingerprint, window dependency fingerprint, plan status mapping table, and the verified query plan version are associated and stored as a query plan template;
[0092] When a new consecutive query statement is received, it is determined that the unified field identifier, operator type and operator dependency relationship corresponding to the new consecutive query statement have a one-to-one correspondence with the query plan template, and the corresponding pattern mapping version is a successor version of the pattern mapping version of the query plan template record.
[0093] After ensuring that the data types and conversion rules of the state key source field and state value source field remain unchanged in consecutive successive versions, and that the version change fields only correspond to the projected output fields that have not entered the state dependency path, the query plan template is called to generate a new candidate query plan.
[0094] Preferably, when the query operator graphs of multiple consecutive query statements contain an equivalent window join subgraph consisting of the same streaming relation table, the same association key field, the same event time field, and the same common baseline window, the method further includes:
[0095] Merge the equivalent window connection subgraphs into a shared window connection subgraph;
[0096] A shared intermediate relationship table is established based on the shared window connection subgraph. The shared intermediate relationship table uses the common baseline window identifier, the association key field value and the pattern mapping version as the composite key to store the common window aggregation status and connection matching status.
[0097] For each consecutive query statement, the query reference identifier, required output fields, differential window range, and set of late correction propagation operators are recorded in the shared intermediate relation table;
[0098] When the aggregation state or connection matching state of the common window in the shared intermediate relation table is corrected, the state correction amount of the corresponding consecutive query statement is generated according to the query reference identifier, the required output field, the differential window range and the set of late correction propagation operators, and the state correction amount is propagated to the query operator graph of the corresponding consecutive query statement.
[0099] Preferably, the state version management of the shared intermediate relationship table includes:
[0100] Configure the corresponding target query plan version, target window state version, target output pointer, and target migration buffer for each consecutive query statement that references the shared intermediate relation table;
[0101] When the target query plan version corresponding to any consecutive query statement is restored, the query reference identifier corresponding to any consecutive query statement is revoked, and the streaming data record in the corresponding target migration buffer is written to the restored target window state version.
[0102] Keep the query reference identifier, target query plan version, target window state version, and target output pointer unchanged for other consecutive query statements;
[0103] The public benchmark window state is deleted after all query reference identifiers corresponding to the same public benchmark window state have been revoked, the late allowance time corresponding to each consecutive query statement referencing the public benchmark window state has expired, and there are no uncompleted late correction propagation tasks.
[0104] Compared with existing technologies, the above technical solution has the following advantages:
[0105] 1. This invention constructs window dependency clusters and determines common baseline windows, rewriting the window operators in the initial query plan into shared window operators and differential window operators, enabling multiple windows with time coverage relationships to reuse common window states, reducing redundant state maintenance and redundant query calculations between different window operators.
[0106] 2. This invention establishes a plan state mapping table based on field lineage, schema mapping version, and window state dependency, dividing the window state into a migrateable state and a recalculation state. This allows window states unaffected by data schema changes to be directly migrated, and limits the recalculation scope to operators affected by changed fields and their corresponding local replay intervals, reducing the amount of state recalculation during query plan switching.
[0107] 3. This invention enables the initial query plan and candidate query plans to process the same streaming data records within the verification period, and generates boundary result fingerprints for window entry records, window exit records, late correction records, and connection matching change records, respectively. At the same time, it verifies the window end state fingerprint, thereby enabling the identification of situations where the final query results are the same but the window state change process is inconsistent, thus improving the consistency of continuous query plan switching results.
[0108] 4. This invention determines the query waterline based on the event time processing progress and late arrival allowance of each streaming relation table, and performs window state freezing, migration and recalculation after the query waterline reaches the version switching boundary corresponding to the common benchmark window, thereby reducing the risk of streaming data records that have not yet been processed being missed, processed repeatedly or written to the wrong window state version.
[0109] 5. This invention controls the activation process of candidate query plans in a coordinated manner through query plan version, window state version, state freeze flag, migration buffer and query output pointer, and restores the initial query plan version and corresponding window state version when the verification results after switching are inconsistent, so that continuous query plans can complete switching and abnormal recovery during the continuous reception of streaming data records.
[0110] 6. This invention determines the corresponding common baseline window and window state version based on the event time, source relation table identifier, source sequence identifier, and pattern mapping version of the late streaming data record, and propagates the late correction amount through the plan state mapping table, so that the relevant window states before and after the query plan switch can be corrected according to the corresponding dependency relationship, thereby reducing the state omission or duplicate correction caused by late streaming data records.
[0111] 7. This invention establishes a shared intermediate relation table by merging the equivalent window connection subgraphs in multiple consecutive query statements, and sets query reference identifiers, query plan versions, window state versions, output pointers and migration buffers respectively, so that different consecutive query statements can share the common window aggregation state and connection matching state, while supporting the independent execution of version recovery for a single consecutive query statement without affecting other consecutive query statements. Attached Figure Description
[0113] Figure 1 This is a flowchart illustrating the real-time streaming computing window optimization method for multi-source heterogeneous data fusion according to the present invention.
[0114] Figure 2 This is a query operator diagram and a lineage diagram of the initial query plan and candidate query plans of the present invention.
[0115] Figure 3 This is a timing diagram illustrating the event time, query water level, common reference window boundary, and late arrival allowance interval of this invention.
[0116] Figure 4 This is a schematic diagram of window state transitions and state transition dependencies in this invention.
[0117] Figure 5 This is a schematic diagram illustrating the generation of boundary result fingerprints and window end state fingerprints in this invention.
[0118] Figure 6 This diagram illustrates the bifurcation location, local recalculation, and constraint rewriting generation after the verification failure of this invention.
[0119] Figure 7 This is a schematic diagram illustrating the merging of equivalent window connection subgraphs, sharing of intermediate relationship tables, and independent rollback at the query level in this invention. Detailed Implementation
[0121] The following description, in conjunction with the accompanying drawings, further illustrates the real-time streaming computing window optimization method for multi-source heterogeneous data fusion. This method is directly applied to continuous query processing of streaming databases in big data processing environments. The processing objects include streaming relational tables, continuous query statements, window operators, multi-table join operators, aggregation operators, query plans, and corresponding window states. The following implementation methods are used to illustrate the processing relationships and feasible procedures between various technical features and are not intended to limit the method to specific streaming database products, data source formats, window types, or hash algorithms.
[0122] Figure 1 A flowchart illustrating a real-time streaming computing window optimization method for multi-source heterogeneous data fusion; Figure 2This diagram illustrates the query operator graph, field lineage, and plan status mapping between the initial query plan and candidate query plans. Figure 3 This is a timeline diagram showing the event time, query water level, common reference window boundary, verification cycle, and allowable late interval; Figure 4 This diagram illustrates window state transitions, state transition dependencies, and version commits or restores. Figure 5 This diagram illustrates the generation of boundary result fingerprints and window end state fingerprints. Figure 6 A schematic diagram is generated for bifurcation location, local recalculation, and constraint rewriting after verification failure. Figure 7 This diagram illustrates the merging of subgraphs connected by equivalent windows, the sharing of intermediate relation tables, and independent rollback at the query level.
[0123] Example 1
[0124] This embodiment sets up a streaming database continuous query engine, which continuously receives order streaming data and payment streaming data, and performs continuous database queries based on the event time field. Order streaming data comes from message queue topics and uses a data object format with nested fields; payment streaming data comes from relational database change logs and uses a relational table row change format. Order streaming data and payment streaming data are only examples of multi-source heterogeneous data. In other embodiments, device time-series data, object storage incremental files, message middleware data, or other data that can be mapped to streaming relational tables can also be received.
[0125] The streaming database continuous query engine retrieves the data patterns, continuous query statements, and query watermark configurations for order streaming data and payment streaming data. The data pattern for order streaming data includes at least the following fields: order user, order product, order amount, and order event time. The data pattern for payment streaming data includes at least the following fields: payment user, payment product, payment amount, payment status, and payment event time.
[0126] The streaming database continuous query engine maps the order streaming data and the payment streaming data into an order streaming relation table and a payment streaming relation table, respectively, based on the schema mapping configuration. Both the order streaming relation table and the payment streaming relation table have a unified field identifier `user_id`, a unified field identifier `item_id`, and an event time field `event_time`. The unified field identifier `user_id` and the unified field identifier `item_id` together constitute the association key field. The order streaming relation table also has a unified field identifier `amount`, and the payment streaming relation table also has a unified field identifier `pay_amount`.
[0127] One pattern mapping relationship is shown in Table 1.
[0128] Table 1 Multi-source heterogeneous data pattern mapping table
[0129]
[0130] In this embodiment, pattern mapping version V1.0 is the previous pattern mapping version, and pattern mapping version V1.1 is the current pattern mapping version. Pattern mapping version V1.1 takes effect before the candidate query plan is generated. Compared with pattern mapping version V1.0, pattern mapping version V1.1 changes the field conversion rule of the payment item field from removing leading and trailing null characters to removing leading and trailing null characters and converting them to uppercase characters. Since the unified field identifier item_id obtained by mapping the payment item field participates in the window status key and the association key of the multi-table join operator, this change will affect the payment window status and the join matching status.
[0131] The streaming database continuous query engine configures a source relation table identifier for each streaming relation table and a source sequence identifier for each streaming data record. The source sequence identifier in a message queue topic consists of a partition identifier and a message offset, while the source sequence identifier in a relational database change log uses a log sequence number. For cases where the source sequence identifier may be duplicated in different streaming relation tables, the source relation table identifier and the internal source sequence number are combined to form a global source sequence identifier.
[0132] In this embodiment, the received continuous query statement is used to count the order amount for each user for each product within a 10-minute order window, and then associate the order amount with the number of payment records in a 15-minute payment window covering the corresponding time range. An example continuous query statement is as follows:
[0133] WITH OrderWindow AS ( SELECT user_id, item_id, window_start, window_end, SUM(amount) AS order_sum FROM TABLE( TUMBLE( TABLE Order_Stream,DESCRIPTOR(event_time), INTERVAL '10'minUTE ) ) GROUP BY user_id, item_id,window_start, window_end),PaymentWindow AS ( SELECT user_id, item_id, window_start, window_end, COUNT(*) AS payment_count, SUM(pay_amount) AS payment_sumFROM TABLE( HOP( TABLE Payment_Stream, DESCRIPTOR(event_time), INTERVAL '5'minUTE, INTERVAL '15'minUTE ) ) GROUP BY user_id, item_id, window_start,window_end)SELECT OrderWindow.user_id, OrderWindow.item_id,OrderWindow.window_start, OrderWindow.window_end, OrderWindow.order_sum,PaymentWindow.payment_count, PaymentWindow.payment_sumFROM OrderWindowJOINPaymentWindowON OrderWindow.user_id = PaymentWindow.user_idANDOrderWindow.item_id = PaymentWindow.item_idAND OrderWindow.window_start >=PaymentWindow.window_startAND OrderWindow.window_end <= PaymentWindow.window_end;
[0134] The streaming database continuous query engine converts the continuous query statement into an initial query plan. Such as Figure 2As shown, the initial query plan includes an order input operator, a payment input operator, a first window operator, a second window operator, a first aggregation operator, a second aggregation operator, a multi-table join operator, and an output operator. The first window operator has a window length and a window step of 10 minutes, while the second window operator has a window length of 15 minutes and a window step of 5 minutes.
[0135] The streaming database continuous query engine parses the initial query plan to obtain the input relationships of each window operator, the operator dependencies between operators, the field lineage of each unified field identifier between operators, and the window state dependencies between window states. The input relationship of the first window operator is the order streaming relationship table, and the input relationship of the second window operator is the payment streaming relationship table. The directed relationships from the order input operator to the first window operator, from the first window operator to the first aggregate operator, and from the first aggregate operator to the most-table join operator constitute the first operator dependency path; the directed relationships from the payment input operator to the second window operator, from the second window operator to the second aggregate operator, and from the second aggregate operator to the most-table join operator constitute the second operator dependency path.
[0136] The status keys for the first window operator include the unified field identifiers user_id and item_id, and the 10-minute window identifier. The status values for the first window operator include the cumulative value of the corresponding order amount. The status keys for the second window operator include the unified field identifiers user_id and item_id, and the 15-minute window identifier. The status values for the second window operator include the number of payment records and the cumulative value of the payment amount. The status keys for the multi-table join operator include the unified field identifiers user_id and item_id, and the window identifiers involved in the join. The status values for the multi-table join operator include records to be matched, matched records, and a join match flag.
[0137] The streaming database continuous query engine constructs window dependency clusters based on the input relationships, window boundaries, association key fields, and operator dependencies. For window operators to be included in the same window dependency cluster, the corresponding event time fields must use the same time base, the association key fields must have a definite mapping relationship, the grouping fields must be consistent or able to establish a one-to-one correspondence, and the corresponding aggregation states must be merged according to preset state merging rules.
[0138] Let the first The window length of the window operator is Window step size is Candidate time granularity is The candidate time granularity needs to satisfy:
[0139]
[0140] in, Indicates the window operator number. Indicates the first Window length of a window operator Indicates the candidate time granularity. This represents the modulo operation. and Use the same time unit.
[0141]
[0142] in, Indicates the window operator number. Indicates the first Window step size of a window operator Indicates the candidate time granularity. This represents the modulo operation. and Use the same time unit.
[0143] Let the first The window starting point of each window operator is... The public reference starting point is , No. The window start remainder of the window operator is ,but:
[0144]
[0145] in, Indicates the window operator number. Indicates the first Window start remainder of each window operator Indicates the first The window starting point of a window operator Indicates a common reference starting point. Indicates the candidate time granularity. This represents the modulo operation. , , and Use the same time unit.
[0146] When the window start remainders of the window operators within the same window dependency cluster are the same, the corresponding candidate time granularity is retained; when the window start remainders of at least two window operators are different, the corresponding candidate time granularity is deleted.
[0147] In this embodiment, the window length and window step of the first window operator are both 10 min, and the window length of the second window operator is 15 min and the window step is 5 min. The window start points of both window operators are aligned with 09:00. Both 1 min and 5 min satisfy equations (1) to (3). When using a 5 min candidate time granularity, a 10 min order window can be composed of two 5 min windows, and a 15 min payment window can be composed of three 5 min windows, with the window start remainder being zero.
[0148] For each candidate time granularity, the streaming database continuous query engine determines the number of differential boundary segments, the coverage of transferable states, and the cross-window propagation range of late correction records within the corresponding window. The streaming database continuous query engine sorts these segments in ascending order of differential boundary segment count, descending order of transferable state coverage, and ascending order of cross-window propagation range. When all three are the same, the segments are sorted in descending order of candidate time granularity to reduce the number of common window states. Therefore, the 5-minute window is determined as the common baseline window.
[0149] When the corresponding window can be covered by the complete common reference window, the differential window operator outputs a null differential state, or is bypassed in the physical execution plan; when the window start or window end boundary cannot coincide with the common reference window boundary, the differential window operator processes the streaming data records in the start boundary segment and the end boundary segment.
[0150] For the order streaming relation table and the payment streaming relation table, set up shared window operator instances respectively. The two shared window operator instances use the same 5-minute common baseline window configuration, but each stores the order common window state and the payment common window state in an independent state partition, without mixing the original records from the two streaming relation tables.
[0151] The streaming database continuous query engine extracts a window join subgraph consisting of window operators, multi-table join operators, and aggregation operators from the initial query plan, and generates a first rewrite subgraph that first forms a common window state before performing multi-table joins, and a second rewrite subgraph that first performs multi-table joins before forming a common window state.
[0152] For each state operator in the rewritten subgraph, a state equivalence mapping term is generated. This term includes the source operator identifier, the target operator identifier, a state key transformation rule, a state value merging rule, and a valid mode mapping version range. For a 10-minute order window state, the state key transformation rule converts one 10-minute window identifier into two consecutive 5-minute common baseline window identifiers, and the state value merging rule adds the cumulative order amounts from the two 5-minute common order window states.
[0153] State dependency paths are formed between the various state operators. These paths start from the input common window state and extend along the aggregation state, the connection matching state, and the post-connection aggregation state to the query result state. Each state dependency path has a state equivalence mapping term, or, if state recalculation can be completed using streaming data records not exceeding the corresponding window length, the corresponding rewritten subgraph is retained.
[0154] The candidate query plan screening results in this embodiment are shown in Table 2.
[0155] Table 2 Example of Candidate Query Plan Filtering
[0156] Candidate Program Processing order Migrationable state Pending recalculation status State recalculation range Validate path Processing results P1 Perform multi-table joins after processing in the public window. Order public window status Payment public window status, connection matching status, and downstream status No more than 15 minutes All four types of boundary records are covered reserve P2 After joining multiple tables, a common window is executed. Partial pre-connection state Connection matching status and window status after all connections are established More than 15 minutes Incomplete connection matching change path delete
[0157] The streaming database continuous query engine generates a state access list, a state transition path list, and a late correction propagation list for the retained candidate query plans. Candidate query plans whose state transition completion boundary is later than the end boundary of the next verification cycle are deleted, as are candidate query plans whose verification paths for missing window entry records, window exit records, late correction records, and join match change records are also deleted. If no remaining candidate query plans exist, the initial query plan continues to run.
[0158] The streaming database continuous query engine compares the previous schema mapping version V1.0 with the current schema mapping version V1.1 and determines that the field conversion rules for the unified field identifier item_id have changed. Following field lineage and operator dependencies, the process propagates downstream from the second window operator referencing the unified field identifier item_id in the streaming payment relation table, forming a set of affected operators including the second window operator, the second aggregation operator, the multi-table join operator, and the aggregation operator after the join.
[0159] Window states that reference a change field via a status key or status value are classified as pending recalculation states, while window states that do not reference a change field are classified as migrateable states. The planning state mapping relationship in this embodiment is shown in Table 3.
[0160] Table 3. Plan Status Mapping Table
[0161] State operator identifier status key State value Change field dependency State division Handling method Partial playback range Win_Order_10 user_id, item_id, window_id SUM(amount) The item_id on the order side remained unchanged. Migrationable state Merge the status of two 5-minute orders in the common window. none Win_Pay_15 user_id, item_id, window_id COUNT(*), SUM(pay_amount) Changes in payment-side item_id conversion rules Pending recalculation status Playback of payment window records 10:00—10:15 Join_State_01 user_id, item_id, window_pair Join record set and matching tag Depends on payment side item_id Pending recalculation status Recalculate connection matching state 10:00—10:15 Agg_State_01 user_id, item_id, window_id Aggregate value after joining Depends on Join_State_01 Pending recalculation status Recalculated based on connection matching status 10:00—10:15
[0162] The starting point of the local replay interval is the earliest common reference window boundary corresponding to the set of affected operators, and the ending point of the local replay interval is the nearest common reference window boundary no later than the query water level. The streaming database continuous query engine writes the local replay interval into the plan status mapping table.
[0163] The streaming database continuous query engine configures query plan versions Plan_V1.0 and Plan_V1.1 for the initial query plan and candidate query plans, respectively, and configures window state versions State_V1.0 and State_V1.1 for the corresponding window states.
[0164] like Figure 3 As shown, this is the first [number] query to participate in a series of queries. Configure the late arrival allowance for each streaming relation table. , obtain the first The maximum event time in the streaming data records already received by the streaming relation table. And determine the closing time of the relation table. :
[0165]
[0166] in, Indicates the sequence number of the flow relation table. Indicates the first The closing time of a streaming relational table. Indicates the first The maximum event time in the streaming data records already received by the streaming relational table. Indicates the first The allowed late arrival time for each streaming relation table; and Represented using millisecond timestamps, Use milliseconds as the unit of measurement.
[0167] When shared When multiple streaming relational tables participate in consecutive query statements, the query water level is used. for:
[0168]
[0169] in, This indicates a query for water level lines. Indicates the number of streaming relational tables involved in consecutive query statements. to These represent the closing times of the relation tables for each streaming relation table. This operation represents retrieving the earliest value in chronological order.
[0170] The streaming database continuous query engine can update the query level after receiving each streaming data record, or it can recalculate the query level according to a preset query level update cycle; the preset query level update cycle is determined based on the streaming data arrival rate and the processing time occupied by the query level update.
[0171] In this embodiment, the maximum event time for the order streaming relation table is 10:16:20, the allowed late arrival time is 60 seconds, and the relation table closing time is 10:15:20; the maximum event time for the payment streaming relation table is 10:16:40, the allowed late arrival time is 90 seconds, and the relation table closing time is 10:15:10. The query watermark is at 10:15:10.
[0172] The 5-minute common baseline window boundaries include 10:00, 10:05, 10:10, and 10:15. Since the query waterline has already crossed 10:15, and there are no incomplete late correction records or incomplete connection matching change records that cross the 10:15 boundary, 10:15 is determined as the version switch boundary.
[0173] During the verification period from 10:10 to 10:15, the initial query plan and the candidate query plan process the same streaming data records. The query results generated by the initial query plan are output externally, while the query results generated by the candidate query plan are saved as verification query results.
[0174] When a streaming data record is first included in the corresponding window state, a window entry record is generated; when the sliding window advances or the window state is cleared so that the streaming data record no longer belongs to the corresponding window, a window exit record is generated; when the window state changes due to the arrival of a late streaming data record after the window is initially closed, a late correction record is generated; when the state of the multi-table join operator changes from unmatched to matched, from matched to unmatched, or the matching object changes, a join matching change record is generated.
[0175] Each boundary record includes at least the source relation table identifier, source sequence identifier, event time, uniform field identifier, association key field value, schema mapping version, previous state value, and subsequent state value.
[0176] Let the first The first in the class boundary record The boundary record is coded as ,but:
[0177]
[0178] in, Indicates the boundary record type sequence number. This indicates the record sorting number within the corresponding boundary record type. Indicates the first The first in the class boundary record Boundary record encoding, Represents canonical encoding operations. Indicates the source relation table identifier. Indicates the source sequence identifier. Indicates the time of the event. Indicates a uniform field identifier. This represents the value of the associated key field. Indicates the pattern mapping version. Indicates the previous state value. This represents the state value after the change.
[0179] The standardized encoding adopts a structure of "field type + 4-byte field length + field value". Strings are encoded in UTF-8, timestamps are used for timestamps in milliseconds, decimal amounts are uniformly retained to two decimal places, and null values are identified by independent null values. This avoids encoding ambiguity caused by direct concatenation of fields.
[0180] For records of the same boundary type and the same association key field value, sort according to the source relation table identifier and the source sequence identifier. Let the first... Class boundary records have Article, No. The fingerprint of the record set of class boundary records is ,but:
[0181]
[0182] in, Indicates the boundary record type sequence number. Indicates the first The fingerprint of the record set of class boundary records. Indicates the first The number of records at the class boundary. to These represent the codes of each boundary record after sorting. This represents the SHA-256 hash operation. This indicates byte string concatenation.
[0183] For the sorted adjacent boundary records, the state transition continuity condition must also be satisfied:
[0184]
[0185] in, Indicates the boundary record type sequence number. This indicates the record sorting number within the corresponding boundary record type. Indicates the first The post-state value of the boundary record. Indicates the first The previous state value of each boundary record.
[0186] When equation (8) is not true, the corresponding boundary record type is directly determined to be inconsistent.
[0187] No. State transition chain fingerprint of class boundary record for:
[0188]
[0189] in, Indicates the boundary record type sequence number. Indicates the first The state transition chain fingerprint of the class boundary record Indicates the first The number of records at the class boundary. to These represent the previous state values of each boundary record. to These represent the post-state values of each boundary record. This represents the SHA-256 hash operation. This indicates byte string concatenation.
[0190] Following the order of window entry records, window exit records, late correction records, and connection matching change records, the fingerprints of the four types of record sets and the four types of state transition chain fingerprints are combined to form the boundary result fingerprint. :
[0191]
[0192] in, Represents the boundary result fingerprint, to These represent fingerprints of four types of record sets arranged in a preset order. to These represent the corresponding four types of state transition chain fingerprints. This represents the SHA-256 hash operation. This indicates byte string concatenation.
[0193] At the end of the verification period, the common baseline window identifier, the value of the associated key field, the status key, the status value, and the window status version are sorted and encoded to form the window end status fingerprint. Even if the boundary result fingerprints of two query plans are the same, if the number of boundary records or the window end state fingerprints are different, it is still considered that the verification is inconsistent.
[0194] A boundary record data structure is shown in Table 4.
[0195] Table 4 Example of Boundary Record Data Structure
[0196] Boundary record type Source sequence identifier Associated key field value Previous state value Post-state value State change type Window entry record Seq_001 U102-I018 0 150.00 INSERT Window Exit Log Seq_004 U102-I018 150.00 0 DELETE Late correction record Seq_006 U102-I018 150.00 200.00 UPDATE Connect matching change records Seq_009 U102-I018 Not matched Matched MATCH
[0197] When the boundary result fingerprints of the initial query plan and the candidate query plan are inconsistent, the first inconsistent boundary record type is determined in the order of window entry record, window exit record, late correction record, and join matching change record, and the inconsistent record with the source sequence identifier at the beginning is determined in the corresponding record.
[0198] Based on the unified field identifier in the inconsistent records, the source field path is traced backward along the field lineage, and then the earliest divergent operator that generated different state values is determined along the operator dependency relationship. The divergent operator and its downstream operators are identified as the recalculated operator subgraph, and local replay is performed starting from the boundary of the previous common baseline window corresponding to the divergent operator. After local replay, the boundary result fingerprint and the window end state fingerprint are regenerated; if inconsistency still exists after re-verification, the corresponding candidate query plan is deleted while the initial query plan is kept running.
[0199] When the boundary result fingerprints, window end state fingerprints, and boundary record counts of the initial query plan and candidate query plans are all consistent, and the query waterline reaches the end boundary of the verification period, the window state migration begins.
[0200] like Figure 4 As shown, using transitionable states and states to be recalculated as state nodes, state transition dependency edges are established based on aggregated state dependencies, connected matching state dependencies, and differential window state dependencies, generating a state transition dependency graph. When cyclic dependencies exist in the state transition dependency graph, the cyclically dependent state nodes are merged into composite state nodes, and then the compressed directed acyclic graph is migrated according to the topological order.
[0201] At the version switch boundary, a status freeze flag is written to the window state of the initial query plan. After writing the status freeze flag, the received streaming data records are written to the migration buffer according to the source relation table identifier and the source sequence identifier. The migration buffer preferentially uses an in-memory ordered queue; when the number of records in the migration buffer reaches a preset record number threshold or the occupied space reaches a preset storage capacity threshold, subsequent records are overflowed to the persistent incremental log in the order of the source sequence identifier. The preset record number threshold and the preset storage capacity threshold are determined based on the available storage space of the migration buffer and the expected arrival volume of streaming data records in the first verification cycle after the switch.
[0202] Transitioning the transitionable states according to the state dependency order in the state transition dependency graph and calculating the states to be recalculated. Let the first state be... The state key encoding of each state node is as follows: The status value is encoded as The pattern mapping version is encoded as The node status fingerprint is ,but:
[0203]
[0204] in, Indicates the state node sequence number. Indicates the first The node state fingerprint of each state node Indicates the first The state key encoding of each state node. Indicates the first The state value encoding of each state node. Indicates the first The pattern mapping version encoding of each state node. This represents the SHA-256 hash operation. This indicates byte string concatenation.
[0205] When the mapping result of the node state fingerprint is consistent with the corresponding state equivalent mapping item, the subsequent state node can be processed; when they are inconsistent, the subsequent state transition is stopped and the current state node is determined as the state node corresponding to the divergence operator.
[0206] After the migration to the migrateable state is completed and the recalculation of the state to be recalculated is finished, the streaming data records in the migration buffer are written to the window state of the candidate query plan in the order of source relation table identifier and source sequence identifier. An idempotent write key is formed by the source relation table identifier, source sequence identifier, and window state version; if the corresponding idempotent write key already exists, it will not be written again.
[0207] The streaming database continuous query engine is configured with a query output pointer that points to the initial query plan. During state transitions, the query results of the initial query plan are output through this query output pointer, while candidate query plans generate validation query results that are not output.
[0208] After the candidate query plan completes its state transition, it continues to process the same streaming data records as the initial query plan during the first verification cycle after the switch. When the candidate query plan passes the boundary result fingerprint verification, a version commit identifier is written, and in the same version commit operation, the version commit identifier is written and the query output pointer is switched to the candidate query plan.
[0209] When a candidate query plan fails the boundary result fingerprint verification, writing new streaming data records to the candidate query plan's window state is stopped. The streaming data records in the migration buffer and persistent incremental log are then written back to the initial query plan's window state in the order of their source sequence identifiers. The write-back process uses the aforementioned idempotent write key to prevent the same streaming data record from being processed repeatedly. After the initial query plan has processed all incremental records, the candidate query plan version and the candidate window state version are revoked.
[0210] For late streaming data records, the common baseline window and window state version corresponding to the late streaming data record are determined based on the event time, source relation table identifier, source sequence identifier, and pattern mapping version. When the event time is earlier than the version switching boundary and the late allowable interval has not yet been closed, the late streaming data record is written into the window state version corresponding to the initial query plan, and a late correction amount is generated.
[0211] Each late correction is configured with a unique correction identifier, which consists of a source relation table identifier, a source sequence identifier, a common baseline window identifier, and a correction sequence number. Late corrections are propagated to the dependency operators in the candidate query plan according to the plan status mapping table. Each window status version stores a set of already processed correction identifiers to prevent the same late correction from being propagated repeatedly.
[0212] When the late arrival allowance interval is closed, the corresponding late arrival correction has been propagated, and there are no unfinished connection matching change tasks, close the window state version of the corresponding common baseline window in the initial query plan.
[0213] After a candidate query plan fails to be validated and is revoked, the reason for the validation inconsistency is determined based on the type of the first inconsistent boundary record and the divergence operator. When field mappings are inconsistent, a rewrite constraint is generated that prohibits the migration of the corresponding window state; when window boundary decomposition is inconsistent, a rewrite constraint is generated that prohibits the use of the corresponding common baseline window; when join matching state migration is inconsistent, a rewrite constraint is generated that requires recalculation of the join matching state; when late correction propagation is inconsistent, a rewrite constraint is generated that expands the set of late correction propagation operators.
[0214] When generating candidate query plans again, the following constraints are executed in sequence: prohibit state transition constraints, require state recalculation constraints, prohibit common baseline window constraints, and expand the scope of late correction propagation constraints. Candidate query plans that do not satisfy any of the rewrite constraints are deleted.
[0215] After the candidate query plan passes the first verification cycle after the switch, a relational pattern fingerprint, a query operator graph fingerprint, and a window dependency fingerprint are generated. The fingerprints, the plan status mapping table, and the verified query plan version are then associated and stored as a query plan template.
[0216] The new continuous query statement invokes the query plan template only when all of the following conditions are met: there is a one-to-one correspondence between the unified field identifier and the template; the operator type and operator dependency remain unchanged; the pattern mapping version is a continuous successor version; the data types and field conversion rules of the state key source field and the state value source field have not changed; and the version change field is only the projection output field that has not entered the state dependency path.
[0217] Example 2
[0218] like Figure 7 As shown, when both the query operator graphs of consecutive query statement A and consecutive query statement B contain equivalent window connection subgraphs consisting of the same order flow relation table, the same payment flow relation table, the same association key field, the same event time field, and the same common baseline window, the two equivalent window connection subgraphs are merged into a shared window connection subgraph.
[0219] Continuous query A outputs the order amount and number of payment records for each user and each product, while continuous query B outputs the order amount and payment amount for each user and each product. Both continuous queries use the same 5-minute common baseline window and the same multi-table join conditions.
[0220] A shared intermediate relationship table is established based on the shared window connection subgraph. The shared intermediate relationship table uses the common baseline window identifier, the association key field value, and the schema mapping version as the composite key, and stores the common window aggregation status, connection matching status, composite key version number, and query reference identifier set.
[0221] For consecutive query statements A and B, record the query reference identifier, required output fields, differential window range, late correction propagation operator set, target query plan version, target window state version, target output pointer, and target migration buffer, respectively.
[0222] When the common window aggregation state or join matching state in the shared intermediate relationship table is modified, the corresponding composite key version number is read, the state modification amount is merged, and a conditional write is performed. If the composite key version number has not changed during the conditional write, the corresponding state is updated and the composite key version number is incremented; if the composite key version number has changed, the corresponding state is read again and the modification amount is merged again.
[0223] When performing query plan version recovery for consecutive query statement A, only query reference identifier A is removed, and the streaming data records in target migration buffer A are written to the recovered target window state version A. The query reference identifier B, target query plan version B, target window state version B, and target output pointer B for consecutive query statement B remain unchanged.
[0224] The corresponding public baseline window state is deleted only when all query references to the corresponding public baseline window state have been revoked, the late allowable intervals corresponding to each consecutive query statement have been closed, and there are no uncompleted late correction propagation tasks.
[0225] Verification Example
[0226] To verify the state partitioning and local recalculation mechanisms, a set of reproducible software simulations was constructed. The simulation environment used 5 virtual processor cores, 5.9GB of available memory, and Python 3.13.5. The processor model was AMD EPYC9V74. The simulation generated 120,000 order streaming data records and 120,000 payment streaming data records, with an event time coverage of 10 minutes, 3,000 users, and 600 products. 15% of the product identifiers in the payment streaming data records were in lowercase to simulate the association key conversion required when switching from schema mapping version V1.0 to schema mapping version V1.1.
[0227] Comparative Example 1
[0228] Comparative Example 1 re-establishes all window states without migrating the window states of the initial query plan.
[0229] Comparative Example 2
[0230] The second example migrates the partially matched state, but performs a complete recalculation of the payment window state and connection state within the last 15 minutes.
[0231] How to handle verification examples
[0232] This embodiment migrates the order public window state unaffected by the changed fields, and only performs partial recalculation on the payment window state, connection matching state, and downstream state of the connection matching state that depend on the changed fields. Comparative Example 1, Comparative Example 2, and this embodiment use the same dataset and simulation environment, and each method is run 5 times, with the median execution time taken.
[0233] Table 5 Reproducible Simulation Results
[0234] Test Plan Number of regenerated state keys Number of directly reused status keys State reuse rate Median of 5 runs Comparative Example 1: All states are reformed 236061 0 0% 317ms Comparative Example 2: State Shift and Overall Recalculation of Intervals 177133 58928 24.96% 211ms This example demonstrates local recalculation based on field lineage. 13480 222581 94.29% 45ms
[0235] The simulation results are used to illustrate the impact of state partitioning, planned state mapping, and local replay range on the number of reformed states, and do not constitute a limitation on the performance of a specific production deployment environment. Actual execution time is also affected by the streaming database implementation, state storage medium, streaming data arrival rate, and the number of query operators.
[0236] Through the aforementioned implementation process, the common baseline window simultaneously constitutes the formation boundary, verification cycle boundary, window state freezing boundary, and local replay boundary of the shared window state; the plan state mapping table is used to determine the migrateable state and the state to be recalculated; the boundary result fingerprint and the window end state fingerprint are used to verify the window semantics before and after the query plan switch; the query waterline is used to determine the version switch boundary that can freeze the window state; the migration buffer, query plan version, and window state version are used to restore the initial query plan when verification fails; the shared intermediate relationship table and query reference identifier are used to share the window state among multiple consecutive query statements and keep other queries unaffected when a single query execution version is restored.
[0237] It should be noted that the embodiments of the present invention have better implementability and are not intended to limit the present invention in any way. Any person skilled in the art may use the above-disclosed technical content to change or modify it into equivalent effective embodiments. However, any modifications or equivalent changes and modifications made to the above embodiments based on the technical essence of the present invention without departing from the content of the technical solution of the present invention shall still fall within the scope of the technical solution of the present invention.
Claims
1. A real-time streaming computing window optimization method for multi-source heterogeneous data fusion, used for continuous database queries in big data processing, comprising: Obtain the data pattern, continuous query statements and query watermarks of heterogeneous data sources, and map the data pattern into a streaming relational table containing a unified field identifier, an event time field, a correlation key field and a pattern mapping version; The continuous query statement is converted into an initial query plan containing window operators, multi-table join operators and aggregation operators. The initial query plan is then parsed to obtain the input relationship, operator dependency relationship, field lineage relationship and window state dependency relationship. Based on the input relationships, association key fields, and operator dependencies, a window dependency cluster is constructed, a common baseline window is determined, the window operator is rewritten, and a candidate query plan is generated. Establish a plan status mapping table based on the pattern mapping version changes, the lineage of the fields, and the window status dependency, divide the migrateable state into the recalculated state, and configure the query plan version and window status version; During the verification period between adjacent common benchmark window boundaries, the initial query plan and the candidate query plan process the same streaming data record, and generate boundary result fingerprints and window end status fingerprints based on window entry, window exit, late correction and connection matching change records. The version switching boundary is determined based on the query water level line; When the boundary result fingerprint and the window end state fingerprint are consistent and the query waterline reaches the version switching boundary, the window state of the initial query plan is frozen, the migrateable state is migrated and the state to be recalculated is calculated, so that the candidate query plan and window state take effect. If the verification is inconsistent during the first verification cycle after the switch, restore the query plan version and window state version of the initial query plan.
2. The real-time streaming computing window optimization method for multi-source heterogeneous data fusion according to claim 1, characterized in that, The process of dividing the window state into a transitional state and a recalculation-pending state includes: Obtain the source field path, unified field identifier, data type, and association key conversion rules recorded in the current version and the previous version of the pattern mapping version, respectively; Compare the current version with the previous version to determine the changed fields whose source field path, unified field identifier, data type, or association key conversion rules have changed; Following the field lineage and operator dependency, the process propagates downstream from the operator that references the changed field, forming a set of affected operators; Window states that reference the changed field using a status key or status value are classified as the states to be recalculated, and window states that do not reference the changed field are classified as the states that can be migrated. The local replay interval is determined based on the earliest common reference window boundary corresponding to the affected operator set and the query water level, and the local replay interval is written into the plan status mapping table.
3. The real-time streaming computing window optimization method for multi-source heterogeneous data fusion according to claim 2, characterized in that, The end boundary of the verification period is determined as the version switching boundary, and a source relation table identifier and late arrival allowance are configured for each streaming relation table, and a source sequence identifier is configured for each streaming data record. Based on the event time of the late streaming data record, the source relation table identifier, the source sequence identifier, and the pattern mapping version, determine the common baseline window and window state version corresponding to the late streaming data record; The lateness allowance interval is determined based on the end boundary of the common reference window and the lateness allowance duration; When the event time is earlier than the version switching boundary and the late allowance interval is not closed, the late streaming data record is written to the window state version corresponding to the initial query plan to generate a late correction amount; According to the plan state mapping table, the late correction amount is propagated to the operators in the candidate query plan that depend on the corresponding migrateable state or recalculation state within the local replay interval; After the late arrival allowance interval is closed and the late arrival correction amount has been propagated, the window state version of the corresponding common baseline window in the initial query plan is closed.
4. The real-time streaming computing window optimization method for multi-source heterogeneous data fusion according to claim 1, characterized in that, The determination of the common benchmark window includes: Obtain the window length, window step size, and window start point of each window operator within the same window dependency cluster; determine the grouping field and aggregation function for each window operator; and generate intermediate aggregation states based on the aggregation function. Generate a common time granularity set based on each window length and the window step size; Remove common time granularities from the set of common time granularities that do not meet the conditions of consistent window start remainder, consistent association key field, consistent grouping field, or mergeable intermediate aggregation state. For the remaining covenant time granularities, determine the number of differential boundary segments, the coverage of transferable states, and the cross-window propagation range of late correction records for the corresponding windows. The windows are sorted sequentially according to the number of differential boundary segments in ascending order, the coverage range of the migrated states in descending order, and the cross-window propagation range in ascending order. The window corresponding to the common time granularity at the top of the sorted list is determined as the common reference window.
5. The real-time streaming computing window optimization method for multi-source heterogeneous data fusion according to claim 4, characterized in that, The generation of candidate query plans includes: Extract a window join subgraph consisting of window operators, multi-table join operators, and aggregation operators from the initial query plan; For the window connection subgraph, a first rewrite subgraph is generated that first forms a common window state and then performs multi-table joins, and a second rewrite subgraph is generated that first performs multi-table joins and then forms a common window state. For each state operator in the rewritten subgraph, a state equivalence mapping term is generated. The state equivalence mapping term includes the source operator identifier, the target operator identifier, the state key transformation rule, the state value merging rule, and the effective mode mapping version range. State dependency paths are formed based on the state dependencies between each state operator; Each state-dependent path is retained to have a corresponding state-equivalent mapping item, or a rewritten subgraph that can complete state recalculation through streaming data records that do not exceed the window length of the corresponding window operator, and the retained rewritten subgraphs are combined into the candidate query plan.
6. The real-time streaming computing window optimization method for multi-source heterogeneous data fusion according to claim 5, characterized in that, The generation of candidate query plans also includes: For each candidate query plan, generate a state access list, a state transition path list, and a late correction propagation list; The number of state records to be migrated and the number of state records to be recalculated are determined according to the state access list. The common baseline window boundary corresponding to the completion of state migration is determined according to the state migration path list. The set of operators that late correction records can reach is determined according to the late correction propagation list. Delete candidate query plans whose state transition completion boundary is later than the end boundary of the next verification cycle; Delete the candidate query plans corresponding to the verification paths of records that have not been established for window entry, window exit, late correction, and connection matching changes; The remaining candidate query plans are arranged in ascending order of the number of state records to be migrated, the number of state records to be recalculated, and the number of operators that the late correction records can reach.
7. The real-time streaming computing window optimization method for multi-source heterogeneous data fusion according to claim 6, characterized in that, The generated boundary result fingerprint and window end state fingerprint include: Configure a source relation table identifier for each of the streaming relation tables, and configure a source sequence identifier for each streaming data record; Configure boundary record types for each window entry record, window exit record, late correction record, and connection matching change record, and record the source relation table identifier, the source sequence identifier, the event time, the unified field identifier, the association key field value, the pattern mapping version, the previous state value before the state change, and the subsequent state value after the state change. For records of the same boundary record type and the same associated key field value, sort the corresponding records according to the source sequence identifier to generate a record set fingerprint; The subsequent state value of the previous record is sequentially connected with the previous state value of the next record to form a state transition chain, and a state transition chain fingerprint is generated based on the state transition chain. The boundary result fingerprint is formed by combining the fingerprints of each record set and each state transition chain in a preset boundary record type order. The window state at the end of the verification period is sorted and encoded according to the public baseline window identifier, the association key field value, the status key and the status value to form the window end state fingerprint.
8. The real-time streaming computing window optimization method for multi-source heterogeneous data fusion according to claim 7, characterized in that, When the boundary result fingerprints of the initial query plan and the candidate query plan are inconsistent, the method further includes: Determine the first inconsistent boundary record type in the order of window entry record, window exit record, late correction record, and connection matching change record; Among the records corresponding to the first inconsistent boundary record type, identify the inconsistent record that is first in the source sequence identifier order; Based on the unified field identifier corresponding to the inconsistent record, the field lineage, and the operator dependency, determine the earliest divergence operator among the initial query plan and the candidate query plans that produces different state values; The bifurcation operator and its downstream operators are defined as a recalculation operator subgraph; The recalculated operator subgraph is reprocessed based on the previous common reference window boundary corresponding to the divergence operator, and the boundary result fingerprint and the window end state fingerprint are regenerated.
9. The real-time streaming computing window optimization method for multi-source heterogeneous data fusion according to claim 8, characterized in that, The process of obtaining the query water level and determining the version switch boundary includes: Configure a late arrival allowance for each streaming relation table participating in the consecutive query statements; The closing time of a relation table is determined based on the maximum event time and the corresponding lateness allowance in the streaming data records received for each of the aforementioned streaming relation tables. The earliest closing time of the relation table in chronological order among the closing times of each relation table is determined as the query water level. From the public reference window boundaries that are no later than the query water level, select the public reference window boundary that does not contain any incomplete late correction records or incomplete connection matching change records that cross the public reference window boundary, and use it as the version switching boundary.
10. The real-time streaming computing window optimization method for multi-source heterogeneous data fusion according to claim 9, characterized in that, The migration of the migrateable state and the calculation of the state to be recalculated include: Using the transitionable state and the recalculated state as state nodes, state transition dependency edges are established between each state node based on aggregated state dependency, connection matching state dependency, and differential window state dependency, thus generating a state transition dependency graph. Write a status freeze flag for the window status of the initial query plan at the version switch boundary; The streaming data records received after the state freeze flag is written will be written into the migration buffer according to the source relation table flag and the source sequence flag; The migrateable states are migrated according to the state dependency order in the state transition dependency graph, and the states to be recalculated are calculated. For each state node, a node state fingerprint is generated based on the migrated or recalculated state key and state value. After the mapping result of the node state fingerprint is consistent with the corresponding state equivalent mapping item in the planned state mapping table, the corresponding successor state node is processed. After the migration to the migrateable state is completed and the calculation of the state to be recalculated is completed, the streaming data records in the migration buffer are written into the window state of the candidate query plan in the order of the source sequence identifier, and the streaming data records in the migration buffer are retained until the end of the first verification cycle after the switch.
