Skip to content

feat(flow): use batching mode&fix sqlness#5903

Merged
waynexia merged 25 commits intoGreptimeTeam:mainfrom
discord9:rr_part_6
Apr 23, 2025
Merged

feat(flow): use batching mode&fix sqlness#5903
waynexia merged 25 commits intoGreptimeTeam:mainfrom
discord9:rr_part_6

Conversation

@discord9
Copy link
Copy Markdown
Contributor

@discord9 discord9 commented Apr 15, 2025

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

related proto change(already merged):
GreptimeTeam/greptime-proto#231

What's changed and what's your intention?

  • use BatchingMode for aggr query with flow
  • fix&update sqlness using batching mode flow
  • many fix to make sure sqlness can run, some noticable fixes are:
    • add a InsertInto plan in greptime_request proto to hack around that substrait WriteRel decode to datafusion INSERT INTO failure(see proto PR and src/common/query/src/logical_plan.rs for it's handling)
    • make standalone mode frontend client use a Weak<frontent::Instance> instead of using grpc conn(see src/cmd/src/standalone.rs & src/flow/src/batching_mode/frontend_client.rs), notice here use GrpcQueryHandlerWithBoxedError to type erase the frontend::Instance
    • add a determiner in metasrv to decide which flow type a query should use(for now it's aggr query for batching mode, and non-aggr query for streaming mode), see src/common/meta/src/ddl/create_flow.rs
    • add a determiner in frontend to determine FlowType by visiting and search for Aggregate&Distinct, see src/operator/src/statement/ddl.rs
    • move recover_flows logic on flownode start up to when the flownode start worker(see src/flow/src/adapter/flownode_impl.rs: ConsistentCheckTask::start_check_task) and make the task always running to check for inconsistent(i.e. metasrv have flow task's metadata, but flownode is not running it) and emit a warning when that happen
    • make some changes to flush_flow and drop_flow logic so when flownode startup and flows are not fully recovered they won't fail due to can't found flow, the logic here may need further cleanup, for now if flow is not found in drop flow, it will signal the check task and allow it to drop flow if it have no corrseponding metadata (see src/flow/src/adapter/flownode_impl.rs)
    • check to make sure flow's source table not having a ttl=instant,THIS IS BREAKING CHANGE to flow's behavior, as it accept ttl=instant before
    • remove tumble from sqlness for now(which is already removed from docs)
    • fix config in sqlness runner so that frontend can send correct grpc server addr through heartbeat
    • fix insert into plan's column alias by auto add AS <column_name> in query when needed, see src/flow/src/batching_mode/task.rs:gen_insert_plan & gen_query_with_time_window & AddAutoColumnRewriter
    • use one ChannelManager in dist mode frontend client: src/flow/src/batching_mode/frontend_client.rs
    • not change column default value for auto added column(update_at&__ts_placeholder) for compatibility
    • feat: flush_flow now flush all ranges, if expire_after is set, range is (now()-expire_after, now)(aligned to time window), if not set, is (0, now()) (aligned to time window), see state.rs: gen_filter_exprs & task.rs: mark_all_windows_as_dirty & engine.rs: flush_flow_inner

PS: about 600+ line changes are sqlness update so this is not a very large PR(

non-blocking:

  • FlowStat need to include batch mode flow, but prefer to do it in a separate PR

PR Checklist

Please convert it to a draft if some of the following conditions are not met.

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR requires documentation updates.
  • API changes are backward compatible.
  • Schema or data changes are backward compatible.

Summary by CodeRabbit

  • New Features

    • Introduced support for explicit flow flushing with the flush_flow operation.
    • Added background consistency checking for flows to ensure metadata and runtime synchronization.
    • Enhanced flow batching with time window alignment and explicit time window handling using date_bin.
    • Added the ability to determine and set flow type (batching or streaming) based on SQL analysis.
  • Improvements

    • Refined flow output schemas to use a single high-precision time_window column instead of window_start and window_end.
    • Improved error messages and validation for flows on tables with instant TTL.
    • Updated flow and table creation logic to better handle append mode and timestamp columns.
    • Enhanced schema and query plan handling for flow operations and batching tasks.
    • Improved test coverage for flows, including rebuild, TTL, and flush scenarios.
  • Bug Fixes

    • Addressed issues with flow statistics updates and flow consistency after restarts.
    • Improved error handling for logical plan decoding and insert operations.
  • Documentation

    • Updated comments and documentation for time window expressions and configuration templates.
  • Chores

    • Updated dependencies and configuration templates for dynamic address substitution.
    • Added new and updated test cases for flow functionality, batching, and time windowing.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 15, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This update introduces substantial enhancements to the flow processing infrastructure, focusing on batching mode, flow consistency, and schema handling. The core flow engine is refactored to a dual-engine architecture with a new background consistency check mechanism that reconciles flows between metadata and runtime engines. Batching mode receives improved schema alignment, time window handling, and robust logical plan manipulation for insert operations. The FrontendClient abstraction is extended to support both distributed and standalone modes with unified error handling. Test cases and SQL scripts are updated to use explicit time windowing with date_bin instead of tumble, and table schemas are revised for append mode and timestamp handling. Several configuration and error handling improvements are also included.

Changes

File(s) Change Summary
Cargo.toml, src/frontend/Cargo.toml Updated dependencies: greptime-proto revision and added bytes crate.
src/api/src/helper.rs Extended query_request_type to recognize InsertIntoPlan variant.
src/catalog/src/table_source.rs Made dummy_catalog module public.
src/cmd/src/flownode.rs, src/cmd/src/standalone.rs, tests-integration/src/standalone.rs Refactored flow engine/client initialization: replaced gRPC client creation with in-process handler, updated references to use streaming engine, and linked frontend handler.
src/common/meta/src/ddl/create_flow.rs, src/common/meta/src/ddl/tests/create_flow.rs Flow type is now extracted from flow options; error handling added for unknown types; test SQL updated.
src/common/query/src/logical_plan.rs Added functions for breaking up and constructing insert logical plans.
src/flow/src/adapter.rs, src/flow/src/adapter/flownode_impl.rs, src/flow/src/engine.rs, src/flow/src/server.rs Introduced FlowDualEngine with background consistency check, async locking, and list_flows method; migrated server to dual-engine architecture.
src/flow/src/batching_mode/engine.rs, src/flow/src/batching_mode/state.rs, src/flow/src/batching_mode/task.rs, src/flow/src/batching_mode/time_window.rs, src/flow/src/batching_mode/utils.rs Enhanced batching mode: catalog manager integration, TTL validation, time window alignment, schema/plan rewriting, error handling, and async helpers.
src/flow/src/batching_mode/frontend_client.rs, src/flow/src/lib.rs Refactored FrontendClient for distributed/standalone modes, unified error handling, new trait export.
src/frontend/src/error.rs, src/frontend/src/instance.rs, src/frontend/src/instance/grpc.rs Error source for Substrait decoding changed, logical plan execution passes cloned plan, and support for InsertIntoPlan added.
src/operator/src/statement/ddl.rs Flow type is now inferred from SQL plan structure before task submission.
src/servers/tests/mod.rs InsertIntoPlan variant added to unimplemented match arm in test instance.
tests/cases/standalone/common/flow/flow_advance_ttl.*, tests/cases/standalone/common/flow/flow_auto_sink_table.*, tests/cases/standalone/common/flow/flow_basic.*, tests/cases/standalone/common/flow/flow_blog.*, tests/cases/standalone/common/flow/flow_call_df_func.*, tests/cases/standalone/common/flow/flow_flush.*, tests/cases/standalone/common/flow/flow_null.*, tests/cases/standalone/common/flow/flow_rebuild.*, tests/cases/standalone/common/flow/flow_user_guide.*, tests/cases/standalone/common/flow/flow_view.* Test cases updated: use date_bin for windowing, append mode table options, timestamp column renaming, explicit flush and validation steps, and new/modified queries for flow and table state.
tests/conf/frontend-test.toml.template, tests/runner/src/server_mode.rs Config template now uses variable for gRPC address; runner adds server address argument for frontend mode.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant FlowDualEngine
    participant StreamingEngine
    participant BatchingEngine
    participant FlowMetadataManager
    participant CatalogManager

    Client->>FlowDualEngine: create_flow / remove_flow / flush_flow
    FlowDualEngine->>FlowMetadataManager: Query metadata for flows
    FlowDualEngine->>CatalogManager: Resolve table info
    FlowDualEngine->>StreamingEngine: Create/Remove/Flush flow if streaming
    FlowDualEngine->>BatchingEngine: Create/Remove/Flush flow if batching
    FlowDualEngine-->>Client: Respond with result

    Note over FlowDualEngine: Background Consistency Check Task
    FlowDualEngine->>FlowMetadataManager: Periodically fetch flow metadata
    FlowDualEngine->>StreamingEngine: List actual flows
    FlowDualEngine->>BatchingEngine: List actual flows
    FlowDualEngine->>StreamingEngine: Create/Drop flows to match metadata
    FlowDualEngine->>BatchingEngine: Create/Drop flows to match metadata
Loading
sequenceDiagram
    participant FrontendClient
    participant DistributedPeer
    participant StandaloneHandler

    alt Distributed Mode
        FrontendClient->>DistributedPeer: Send request via ChannelManager
        DistributedPeer-->>FrontendClient: Return result
    else Standalone Mode
        FrontendClient->>StandaloneHandler: Lock & upgrade handler
        StandaloneHandler->>StandaloneHandler: Execute query
        StandaloneHandler-->>FrontendClient: Return result
    end
Loading

Poem

A rabbit hopped through fields of flow,
Where time windows now align and grow.
With engines dual and checks that run,
Consistency shines like the morning sun.
Append mode tables, schemas bright,
Date_bin windows bring delight.
Test meadows bloom, and all is right! 🐇✨

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions Bot added the docs-not-required This change does not impact docs. label Apr 15, 2025
Comment thread tests/conf/frontend-test.toml.template Outdated
@discord9 discord9 marked this pull request as ready for review April 16, 2025 14:33
@discord9 discord9 requested review from a team, waynexia and zhongzc as code owners April 16, 2025 14:33
@discord9
Copy link
Copy Markdown
Contributor Author

Some sqlness is still not fixed, but other code are ready for review

Comment thread src/frontend/src/instance/grpc.rs Outdated
Comment thread src/flow/src/batching_mode/task.rs Outdated
Comment thread src/flow/src/batching_mode/task.rs Outdated
@discord9 discord9 changed the title feat(flow): use batching mode&fix sqlness feat(flow)!: use batching mode&fix sqlness Apr 18, 2025
@discord9 discord9 changed the title feat(flow)!: use batching mode&fix sqlness feat(flow): use batching mode&fix sqlness Apr 18, 2025
@discord9 discord9 force-pushed the rr_part_6 branch 2 times, most recently from d45f81f to 97028f3 Compare April 18, 2025 11:41
@github-actions github-actions Bot added docs-required This change requires docs update. and removed docs-not-required This change does not impact docs. labels Apr 18, 2025
@github-actions github-actions Bot added docs-not-required This change does not impact docs. and removed docs-required This change requires docs update. labels Apr 18, 2025
@waynexia waynexia requested a review from Copilot April 21, 2025 03:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the flow engine to adopt a batching mode for aggregate queries, while also updating the SQL planning/insert logic and frontend client usage. Key changes include:

  • Replacing the traditional manager with a dual engine interface (dual_engine) and updating relevant function calls
  • Extensive modifications in batching_mode components (engine, task, frontend_client) to support new query plans and recovery mechanisms
  • Minor fixes in proto version and test adjustments for SQL query consistency

Reviewed Changes

Copilot reviewed 49 out of 49 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/frontend/Cargo.toml Added dependency bytes.workspace
src/flow/src/server.rs Updated engine references to use dual_engine in service creation
src/flow/src/lib.rs Added new re-exports for GrpcQueryHandlerWithBoxedError
src/flow/src/engine.rs Introduced list_flows into the FlowEngine trait
src/flow/src/batching_mode/* Numerous updates to query generation, auto-column rewriting, and task state handling
src/flow/src/adapter/flownode_impl.rs Refactored flownode implementation to use FlowDualEngine and consistent check task management
src/cmd/src/standalone.rs & src/cmd/src/flownode.rs Adjusted client creation to support new frontend grpc handler usage
Cargo.toml Updated greptime-proto to a new revision

@discord9
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 21, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 11

🔭 Outside diff range comments (3)
src/flow/src/batching_mode/state.rs (1)

50-63: ⚠️ Potential issue

task_handle is never awaited or aborted – leaked join handle

TaskState now stores task_handle: Option<JoinHandle<()>> but no code
ever awaits, joins or cancels the task during shutdown. This may:

  • keep the runtime alive after BatchingTask is dropped,
  • swallow panics inside the task (they will be logged only when joined).

Consider:

impl TaskState {
    pub fn set_task_handle(&mut self, handle: JoinHandle<()>) {
        self.task_handle = Some(handle);
    }

    pub async fn stop(&mut self) {
        if let Some(handle) = self.task_handle.take() {
            handle.abort();          // or .await
        }
    }
}

and invoking stop() from the owning engine’s shutdown path.

tests/cases/standalone/common/flow/flow_basic.sql (1)

274-278: 🛠️ Refactor suggestion

⚠️ Potential issue

Remove the dangling commas in SELECT … lists

Several SELECT clauses end their projection list with a trailing comma right before the FROM keyword:

SELECT
    DISTINCT country,               -- <‑ trailing comma
FROM
    ngx_access_log;
…
SELECT
    DISTINCT country,
    date_bin( … ) as time_window,   -- <‑ trailing comma
FROM
    ngx_access_log

Although Greptime’s parser may currently tolerate this, ANSI SQL (and most third‑party parsers/editors/lint tools) treat the extra comma as a syntax error. Keeping it limits cross‑DB portability and makes automated tooling complain.

-SELECT
-    DISTINCT country,
-FROM
-    ngx_access_log;
+SELECT DISTINCT country
+FROM ngx_access_log;

-    date_bin(INTERVAL '1 hour', access_time) as time_window,
+    date_bin(INTERVAL '1 hour', access_time) as time_window

A quick search shows the same pattern in the Android‑log flow (lines 678‑684). Please drop the final comma at each affected spot.

Also applies to: 336-342, 678-684, 734-740

src/flow/src/server.rs (1)

343-375: 💡 Verification agent

🧩 Analysis chain

Flow recovery is no longer executed after switching to FlowDualEngine

FlownodeBuilder::build used to call self.recover_flows(&manager) so flows were recreated on restart.
After migrating to the dual‑engine the call disappeared, meaning flows are not recovered any more:

let dual = FlowDualEngine::new();
// missing: self.recover_flows(&dual).await?;

Unless recovery moved elsewhere, this breaks durability across restarts.

@@
 let dual = FlowDualEngine::new(…);

 // Recover persisted flows before exposing services
-let server = FlownodeServer::new(FlowService::new(Arc::new(dual)));
+let recovered = self.recover_flows(&dual).await?;
+info!("Recovered {} flows", recovered);
+
+let server = FlownodeServer::new(FlowService::new(Arc::new(dual)));

Please verify the regression and restore recovery logic or document why it is no longer required.


🏁 Script executed:

#!/bin/bash
# Search for recover_flows definition and usages in the codebase
rg -n "recover_flows" -A 5

Length of output: 500


Invoke flow recovery before starting the server

The recover_flows method is defined (src/flow/src/server.rs:391) but never called in FlownodeBuilder::build. Without invoking it on the FlowDualEngine, persisted flows won’t be recreated on restart, breaking durability.

• Location needing fix:

  • src/flow/src/server.rs, in pub async fn build after creating dual
    • Suggested change:
 let dual = FlowDualEngine::new(
     manager.clone(),
     batching,
     self.flow_metadata_manager.clone(),
     self.catalog_manager.clone(),
 );

+// Recover persisted flows before exposing services
+let recovered = self.recover_flows(&dual).await?;
+info!("Recovered {} flows", recovered);

 let server = FlownodeServer::new(FlowService::new(Arc::new(dual)));

Please restore the recovery call or document why it’s no longer required.

🧹 Nitpick comments (24)
tests/cases/standalone/common/flow/flow_blog.sql (1)

29-29: Grouping by window start is valid
Grouping on the start_window alias correctly buckets rows into 5‑second windows. For more predictable test results, consider adding an ORDER BY start_window in the final SELECT queries to enforce deterministic output ordering.

tests/cases/standalone/common/flow/flow_view.sql (1)

35-35: Track the new TODO in an issue.
The added -- TODO(discord9): fix flow stat update for batching mode flow highlights a gap in your test coverage for batching mode. Please ensure this is linked to a ticket or issue ID and that there’s sufficient context (expected vs. actual stats behavior) so it can be prioritized and addressed.

tests/conf/frontend-test.toml.template (1)

2-3: Document the {grpc_addr} placeholder usage.
These dynamic placeholders require a templating step (e.g., via strfmt) to inject the actual gRPC address. Consider adding a comment here or updating your documentation/README to show how and where {grpc_addr} is set during test runs.

src/frontend/src/instance.rs (1)

281-282: Consider impact of plan cloning on performance

The change to clone the logical plan before passing it to execute seems reasonable as it ensures the original plan remains available after execution, which may be needed for subsequent operations. However, large plans could impact performance if executed frequently.

Consider adding a comment explaining why the plan needs to be cloned here to help future maintainers understand the reasoning.

src/common/meta/src/ddl/create_flow.rs (1)

309-323: Well-implemented function for flow type extraction.

The get_flow_type_from_options function:

  • Correctly extracts flow type from options
  • Handles known flow types (BATCHING, STREAMING)
  • Returns appropriate error for unknown types
  • Maintains backward compatibility by defaulting to Batching

Consider adding unit tests to verify this function's behavior for all possible inputs.

tests/cases/standalone/common/flow/flow_flush.result (1)

19-26: Prefer explicit column aliases to avoid quoted identifiers in result snapshots

The SELECT list uses sum(number) without an alias, which causes SQLness to emit the engine‑generated identifier "sum(numbers_input_basic.number)".
Adding an explicit alias (… AS total_sum) will

  1. make the output easier to read,
  2. reduce the chance of brittle test failures if the automatic name formatting ever changes, and
  3. simplify downstream parsing if these results are consumed elsewhere.

Example:

SELECT
    sum(number) AS total_sum,
    date_bin(…)
FROMGROUP BY time_window;
tests/cases/standalone/common/flow/flow_rebuild.sql (1)

174-186: Sleep‑based stabilisation leads to slow & flaky tests

Multiple fixed -- SQLNESS SLEEP 3s pauses are introduced to “give flownode a second to rebuild flow”.
Hard‑coded sleeps:

  1. slow the suite unnecessarily on healthy runs,
  2. can still be too short on busy CI machines, and
  3. mask real readiness problems.

A more robust pattern is to poll for a readiness condition with a timeout, e.g. retry ADMIN SHOW_FLOW('…') until it reports RUNNING or REBUILDING flag disappears, then proceed.
This trims idle time while keeping determinism.

Would you like guidance or a helper script to implement polling in SQLness?

tests/cases/standalone/common/flow/flow_advance_ttl.result (1)

108-116: Wall‑clock sleep may be unnecessary for TTL driven by timestamp column

Rows are inserted with timestamps in 2021, so a ttl = '5s' based on the ts column will consider them expired immediately—no 6 s real‑time wait is required.
Relying on -- SQLNESS SLEEP 6s increases runtime and can introduce flakiness on slow CI nodes.

Consider removing the sleep and simply invoking ADMIN FLUSH_TABLE right away, or insert rows whose ts is computed relative to now() if true wall‑clock expiry is what you intend to test.

tests-integration/src/standalone.rs (3)

177-188: Frontend ↔︎ Flownode coupling: retain strong reference to the client

FlownodeBuilder receives Arc::new(frontend_client), but the variable itself is moved into the Arc and not kept elsewhere.
That’s fine, however make sure no future code expects to access the same FrontendClient instance outside the Arc, otherwise it will have been moved.

Small nit: consider naming the tuple return to make ownership clearer:

let (frontend_client, frontend_handler) = FrontendClient::from_empty_grpc_handler();
let frontend_client = Arc::new(frontend_client); // explicit

253-260: Unwrap on mutex lock can panic and hide deadlocks

Using:

frontend_instance_handler
    .lock()
    .unwrap()
    .replace(weak_grpc_handler);

will panic the whole test binary if the mutex is poisoned (e.g. due to a previous panic on another thread). Although acceptable in unit tests, replacing with expect("mutex poisoned") gives a clearer message, or propagate the error with ? in async contexts.

-    .lock()
-    .unwrap()
+    .lock()
+    .expect("frontend_instance_handler mutex poisoned")

261-262: Keep a reference to streaming_engine() until after invoker injection

flow_worker_manager.set_frontend_invoker(invoker).await;

relies on flow_worker_manager staying alive. You already cloned it, so it is safe, but note that if the FlownodeInstance drops later in the test setup, the invoker will lose its callback early.
Consider storing the clone in GreptimeDbStandalone (next to frontend) if subsequent test logic needs it.

src/cmd/src/standalone.rs (1)

527-538: Avoid the extra clone & double‐wrapping of FrontendClient

Arc::new(frontend_client.clone()) allocates a fresh FrontendClient and then wraps it again in an Arc.
Because frontend_client is already owned by the current scope, you can hand it over directly and avoid an
unnecessary clone:

-let flow_builder = FlownodeBuilder::new(
-    flownode_options,
-    plugins.clone(),
-    table_metadata_manager.clone(),
-    catalog_manager.clone(),
-    flow_metadata_manager.clone(),
-    Arc::new(frontend_client.clone()),
-);
+let flow_builder = FlownodeBuilder::new(
+    flownode_options,
+    plugins.clone(),
+    table_metadata_manager.clone(),
+    catalog_manager.clone(),
+    flow_metadata_manager.clone(),
+    Arc::new(frontend_client),   // move, no extra clone
+);

Minor, but keeps allocations down and avoids two layers of reference counting on the same object.

src/operator/src/statement/ddl.rs (1)

389-421: determine_flow_type does not need to be async

The function performs no .await operations, yet it is declared async and is awaited by
the caller (determine_flow_type(&plan).await?).
The extra state machine adds overhead and needlessly complicates the call‑site.

-async fn determine_flow_type(plan: &LogicalPlan) -> Result<FlowType> {
+fn determine_flow_type(plan: &LogicalPlan) -> Result<FlowType> {
     …
 }
 …
-let flow_type = determine_flow_type(&plan).await?;
+let flow_type = determine_flow_type(&plan)?;

Removing the async keyword yields clearer intent and slightly better performance.

src/flow/src/batching_mode/state.rs (1)

122-125: add_window ignores merging logic – possible explosion of window entries

add_window() directly inserts (start, end) without calling
merge_dirty_time_windows, so two overlapping or adjacent windows added
through this API will stay separate and may blow past
MAX_FILTER_NUM, causing unexpected truncation later.

Recommend invoking the merge immediately or documenting the expectation
that callers perform a subsequent merge_dirty_time_windows call.

src/common/query/src/logical_plan.rs (1)

90-126: Consider handling unsupported/unknown WriteOp more explicitly

breakup_insert_plan silently returns None when the plan is not an INSERT ... APPEND.
Returning an error variant (or at least logging a debug trace) will make diagnosis much easier for callers that rely on the presence of an insert without checking the return value.

src/frontend/src/instance/grpc.rs (1)

318-338: Optional: optimise after augmenting the plan, not before

The first decoding step disables optimisation (optimize = false) but the subsequent analysis/optimise pass happens after the insert node has been added.
If the initial logical plan is large, decoding it twice per request may become a bottleneck. You could:

  1. Decode & optimise the plan once.
  2. Insert the write op.
  3. Run the (cheaper) rule‑based projection/column pruning pass.

This would avoid doing heavy optimisation work twice.

src/flow/src/batching_mode/engine.rs (2)

365-367: Logging placeholder prints literally {flow_id}

tracing::info! treats the format string as format_args!, so the braces do not interpolate variables.
Use positional formatting or structured logging:

-        info!("Try flush flow {flow_id}");
+        info!("Try flush flow {}", flow_id);
+        // or
+        // info!(flow_id, "Try flush flow");

190-209: Avoid double table‑info lookups and improve naming utilities

get_table_name immediately calls get_table_info, which then fetches the same value again when the caller needs both the name and meta.
Returning the TableInfoValue once and letting the caller extract what it needs removes one round‑trip to the underlying store:

let table_info = get_table_info(...).await?;
let table_name = table_info.table_name();

Consider exposing table_name directly on TableInfoValue to streamline this common access pattern.

src/flow/src/server.rs (2)

189-194: The consistency‑check task is never awaited on shutdown

stop_workers signals cancellation but does not await / join the underlying task created by start_flow_consistent_check_task. If that task owns resources (locks, I/O handles) it may keep running past shutdown or panic later.

Please expose a JoinHandle from start_flow_consistent_check_task and await it here (or at least call abort).


70-80: Stale TODO & naming nit

The struct still carries a “TODO: replace with dual engine” even though the replacement is complete, and the field is named dual_engine, not a “manager”. Clean‑up improves readability.

-pub struct FlowService {
-    /// TODO(discord9): replace with dual engine
-    pub dual_engine: FlowDualEngineRef,
-}
+pub struct FlowService {
+    /// Shared dual engine (streaming + batching)
+    pub dual_engine: FlowDualEngineRef,
+}
src/flow/src/batching_mode/frontend_client.rs (1)

260-267: Overflow risk when down‑casting affected_rows to u32

affected_rows arrives as u64 but is truncated via try_into() to u32.
Large batch inserts will silently error out once the row count exceeds u32::MAX (≈4 B). Consider:

  • returning the original u64, or
  • capping with a clear error message before the conversion.
src/flow/src/batching_mode/task.rs (1)

435-445: Error handling loop can create a tight log‑spam cycle

After logging an error the loop sleeps only MIN_REFRESH_DURATION (currently very small) and immediately retries, potentially spamming logs if the root cause is persistent (e.g. schema mismatch).

Consider exponential back‑off or capping the retry rate for repeated identical errors to keep logs readable and avoid unnecessary load.

src/flow/src/adapter/flownode_impl.rs (2)

446-456: Defaulting to Batching when the option is absent may break existing users

Historically flows were streaming unless explicitly marked as batching. Switching the
implicit default to Batching changes behaviour for any client that does not send the
flow_type option (e.g. older CLI versions, scripts, tests). Silent behavioural changes
are hard to diagnose.

Consider:

  1. Making the field mandatory and returning a validation error when missing.
  2. Keeping the previous default (Streaming) for backward compatibility and requiring
    an explicit flag for batching.
  3. At minimum, emit a warn! log indicating which flow is being defaulted.

Clarifying this avoids unexpected production surprises.


518-523: list_flows may return duplicate IDs

streaming_engine.list_flows() and batching_engine.list_flows() are blindly concatenated.
If (mis‑configuration, transition period, or bug) ever places the same flow_id in both
engines the caller will receive duplicates, potentially exploding metrics or causing
double‑drops.

-        stream_flows.extend(batch_flows);
-        Ok(stream_flows)
+        stream_flows.extend(batch_flows);
+        stream_flows.sort_unstable();
+        stream_flows.dedup();
+        Ok(stream_flows)

A set‑based merge is cheap (the vectors are tiny) and gives stronger API guarantees.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1e394af and 33a8489.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (48)
  • Cargo.toml (1 hunks)
  • src/api/src/helper.rs (1 hunks)
  • src/catalog/src/table_source.rs (1 hunks)
  • src/cmd/src/flownode.rs (2 hunks)
  • src/cmd/src/standalone.rs (4 hunks)
  • src/common/meta/src/ddl/create_flow.rs (4 hunks)
  • src/common/meta/src/ddl/tests/create_flow.rs (1 hunks)
  • src/common/query/src/logical_plan.rs (2 hunks)
  • src/flow/src/adapter.rs (2 hunks)
  • src/flow/src/adapter/flownode_impl.rs (6 hunks)
  • src/flow/src/batching_mode/engine.rs (12 hunks)
  • src/flow/src/batching_mode/frontend_client.rs (3 hunks)
  • src/flow/src/batching_mode/state.rs (8 hunks)
  • src/flow/src/batching_mode/task.rs (21 hunks)
  • src/flow/src/batching_mode/time_window.rs (2 hunks)
  • src/flow/src/batching_mode/utils.rs (13 hunks)
  • src/flow/src/engine.rs (1 hunks)
  • src/flow/src/lib.rs (1 hunks)
  • src/flow/src/server.rs (11 hunks)
  • src/frontend/Cargo.toml (1 hunks)
  • src/frontend/src/error.rs (1 hunks)
  • src/frontend/src/instance.rs (1 hunks)
  • src/frontend/src/instance/grpc.rs (3 hunks)
  • src/operator/src/statement/ddl.rs (4 hunks)
  • src/servers/tests/mod.rs (1 hunks)
  • tests-integration/src/standalone.rs (4 hunks)
  • tests/cases/standalone/common/flow/flow_advance_ttl.result (4 hunks)
  • tests/cases/standalone/common/flow/flow_advance_ttl.sql (2 hunks)
  • tests/cases/standalone/common/flow/flow_auto_sink_table.result (4 hunks)
  • tests/cases/standalone/common/flow/flow_auto_sink_table.sql (1 hunks)
  • tests/cases/standalone/common/flow/flow_basic.result (15 hunks)
  • tests/cases/standalone/common/flow/flow_basic.sql (10 hunks)
  • tests/cases/standalone/common/flow/flow_blog.result (2 hunks)
  • tests/cases/standalone/common/flow/flow_blog.sql (2 hunks)
  • tests/cases/standalone/common/flow/flow_call_df_func.result (6 hunks)
  • tests/cases/standalone/common/flow/flow_call_df_func.sql (6 hunks)
  • tests/cases/standalone/common/flow/flow_flush.result (1 hunks)
  • tests/cases/standalone/common/flow/flow_flush.sql (1 hunks)
  • tests/cases/standalone/common/flow/flow_null.result (2 hunks)
  • tests/cases/standalone/common/flow/flow_null.sql (2 hunks)
  • tests/cases/standalone/common/flow/flow_rebuild.result (15 hunks)
  • tests/cases/standalone/common/flow/flow_rebuild.sql (9 hunks)
  • tests/cases/standalone/common/flow/flow_user_guide.result (4 hunks)
  • tests/cases/standalone/common/flow/flow_user_guide.sql (4 hunks)
  • tests/cases/standalone/common/flow/flow_view.result (1 hunks)
  • tests/cases/standalone/common/flow/flow_view.sql (1 hunks)
  • tests/conf/frontend-test.toml.template (1 hunks)
  • tests/runner/src/server_mode.rs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
tests-integration/src/standalone.rs (2)
src/flow/src/batching_mode/frontend_client.rs (1)
  • from_empty_grpc_handler (89-97)
src/cmd/src/flownode.rs (1)
  • flownode (68-70)
src/operator/src/statement/ddl.rs (6)
src/flow/src/adapter/flownode_impl.rs (2)
  • create_flow (440-470)
  • create_flow (783-785)
src/common/meta/src/ddl/create_flow.rs (2)
  • value (424-429)
  • value (430-435)
src/operator/src/statement.rs (2)
  • plan (445-455)
  • new (102-122)
src/query/src/plan.rs (2)
  • extract_and_rewrite_full_table_names (116-123)
  • f_down (37-102)
src/frontend/src/instance.rs (1)
  • query_engine (137-139)
src/query/src/query_engine.rs (1)
  • query_engine (150-152)
🔇 Additional comments (65)
tests/cases/standalone/common/flow/flow_null.sql (2)

9-10: Enable append mode for requests table
The new append_mode = 'true' option correctly configures the requests table for append‑only ingestion in streaming flows and aligns this test with the broader append‑mode changes in the PR.


64-65: Enable append mode for ngx_access_log table
Adding append_mode = 'true' to ngx_access_log ensures this test exercises the updated append‑mode behavior for key‑value stream processing, consistent with other test cases.

tests/cases/standalone/common/flow/flow_blog.sql (1)

18-20: Switch to explicit time binning for windowing is correct
Using date_bin(INTERVAL '5 second', ts) to derive start_window and then adding the interval for end_window aligns with the PR’s move away from tumble. The aliases are clear and should integrate smoothly with batching mode.

src/frontend/Cargo.toml (1)

18-18: Verify that bytes is needed in frontend.
You’ve added bytes.workspace = true—please confirm this crate is actually used in the frontend module (e.g., for buffer manipulation in the new InsertIntoPlan support). If it’s unused, removing it will keep dependencies lean.

src/common/meta/src/ddl/tests/create_flow.rs (1)

49-49: Approve realistic SQL in test utility.
Switching the sql field from a placeholder to "select 1" makes this helper exercise the SQL parsing and flow type detection logic in your production code. This is a positive change.

Cargo.toml (1)

132-132: Validate the greptime-proto revision bump.
Updating the git rev for greptime-proto may change generated Protobuf types. Make sure to run the full test suite (including any codegen) and address any API mismatches introduced by this new commit.

src/servers/tests/mod.rs (1)

135-135: Good update for handling the new InsertIntoPlan query type.

This change adds the new Query::InsertIntoPlan(_) variant to the match arm, ensuring the dummy test implementation handles this new query type the same way as LogicalPlan queries (with unimplemented!). This aligns with the broader addition of InsertIntoPlan in the PR.

src/api/src/helper.rs (1)

517-517: LGTM: Proper type identification for the new InsertIntoPlan query.

This change correctly adds support for the new Query::InsertIntoPlan variant in the query type identification function, returning the appropriate type string "query.insert_into_plan". This is consistent with how other query types are handled.

src/flow/src/engine.rs (1)

52-53: LGTM: Added flow enumeration capability.

The new list_flows method is a good addition to the FlowEngine trait, allowing enumeration of all current flows. This supports the new flow consistency checking functionality mentioned in the PR objectives.

tests/runner/src/server_mode.rs (1)

392-394: LGTM: Essential server address configuration for local testing.

Adding the --rpc-server-addr argument with the same value as the bind address ensures proper server address advertisement in the cluster info when running tests locally. This is essential for the frontend client changes in this PR, where proper server addressing is crucial.

tests/cases/standalone/common/flow/flow_view.result (2)

75-75: Acknowledge the TODO comment for tracking work

This TODO comment correctly identifies a known issue with flow statistics updates for batching mode flows. Ensure this is tracked in your issue management system.


81-81: Verify test result change is expected

The test result now expects last_execution_time IS NOT NULL to be false, which is a behavior change from the previous implementation. This matches with the TODO comment about flow stat updates for batching mode.

src/flow/src/adapter.rs (2)

61-61: Module visibility change supports new dual-engine architecture

Making flownode_impl module public within the crate enables the integration with the new FlowDualEngine architecture that combines streaming and batching engines.


161-161: Field visibility change for dual-engine integration

Making the node_id field public allows other components in the crate to access this identifier directly, which supports the new dual-engine architecture. This is a reasonable change given the architectural updates.

tests/cases/standalone/common/flow/flow_null.result (2)

8-9: Table schema updated for append mode compatibility

Adding the append_mode = 'true' option to the table definition aligns with the batching mode flow enhancements. This change is consistent with similar updates across multiple flow-related tests.


98-99: Table schema updated for append mode compatibility

Adding the append_mode = 'true' option to the ngx_access_log table definition maintains consistency with other flow-related test tables that have been updated to support batching mode.

src/frontend/src/error.rs (1)

348-348: Clean update to error handling for substrait decode operations.

The source error type for SubstraitDecodeLogicalPlan has been changed from substrait::error::Error to common_query::error::Error, which aligns the error handling with the broader query error module used across the system. This change supports the modifications to logical plan decoding infrastructure.

src/catalog/src/table_source.rs (1)

30-30: Module visibility change to support catalog list integration.

Making the dummy_catalog module public allows external modules to access DummyCatalogList, which is needed for the new InsertIntoPlan handling in the gRPC frontend instance. This change enables proper catalog management during plan decoding.

src/flow/src/lib.rs (1)

47-47: Added export for the new error handling abstraction.

Exposing GrpcQueryHandlerWithBoxedError alongside FrontendClient supports the enhanced frontend client abstraction that can work in both distributed and standalone modes. This export is essential for the dual-engine architecture mentioned in the PR objectives.

src/flow/src/batching_mode/time_window.rs (2)

75-84: Added Display implementation to improve debugging.

This implementation enhances logging and debugging capabilities for time window expressions, which are critical for batching mode operations. The formatted output includes all relevant fields needed for troubleshooting time window alignment issues.


270-271: Documentation improvement using backticks.

The comment was updated to format the returned tuple elements using backticks, which improves readability and clarity in the documentation.

tests/cases/standalone/common/flow/flow_auto_sink_table.sql (2)

10-11: Time window implementation updated from tumble to date_bin

The code now uses date_bin function for time windowing instead of the previous tumble approach. This change aligns with the batching mode improvements that provide better time window expressions and schema handling.


15-15: GROUP BY clause updated to use named window column

The GROUP BY clause now references the aliased time_window column, which provides better clarity and consistency with the SELECT clause definition.

tests/cases/standalone/common/flow/flow_user_guide.result (4)

400-400: Column renamed from update_at to event_ts

The timestamp column has been renamed from update_at to event_ts for better semantics, indicating that it represents an event timestamp rather than an update timestamp.


411-411: Added event timestamp to flow output

The flow now explicitly selects max(ts) as event_ts, ensuring that event timestamp information is preserved in the output. This improves data lineage tracking and helps with time-based analysis.


442-443: Updated SELECT query to include event_ts

The SELECT query has been updated to include the renamed event_ts column alongside max_temp, maintaining consistency with the schema changes.


476-481: Updated result table to show event_ts column

The result table now displays the event_ts values alongside the sensor data, providing better visibility into when the temperature readings occurred.

src/cmd/src/flownode.rs (2)

348-348: Updated to use new dual-engine architecture

The code now uses flownode.flow_engine().streaming_engine() instead of flownode.flow_worker_manager(), reflecting the architectural change to a dual-engine model that separates streaming and batching engines.


358-360: Frontend invoker now set on streaming engine

The frontend invoker is now set on the streaming engine component of the flow engine rather than directly on the flow worker manager, aligning with the new architecture.

tests/cases/standalone/common/flow/flow_blog.result (2)

22-24: Enhanced flow definition with explicit time window calculations

The flow now:

  1. Calculates average speed as avg((left_wheel + right_wheel) / 2) with a clear alias
  2. Uses date_bin for start window computation instead of the previous tumble function
  3. Adds an explicit end window calculation by adding the interval to the start window

This provides more flexibility and clearer window boundary representations.


33-33: GROUP BY clause updated to use named window column

The GROUP BY clause now references the aliased start_window column, providing better clarity and consistency with the window definition in the SELECT clause.

tests/cases/standalone/common/flow/flow_advance_ttl.sql (3)

9-16: Excellent test case for validating flow creation constraints on instant TTL tables.

This test correctly verifies that creating a flow on a table with TTL='instant' should fail, which aligns with the batching mode validation that rejects flows on tables with instant TTL.


17-17: Validates the flow creation transition path after TTL change.

Good test approach - changing the TTL to a non-instant value should allow flow creation to succeed in the following steps.


47-67: Well-structured test for TTL expiration effects on flow data processing.

This section properly tests how the flow behaves after TTL expiration by:

  1. Waiting for TTL to expire
  2. Flushing table and flow
  3. Inserting new data
  4. Verifying the flow state reflects the TTL-affected data correctly

The use of SQLNESS directives ensures stable test output.

tests/cases/standalone/common/flow/flow_user_guide.sql (3)

294-294: Good semantic improvement for timestamp column naming.

Renaming from 'update_at' to 'event_ts' better represents the actual meaning of the timestamp - the time when the max temperature event occurred.


303-303: Flow definition properly updated to include event timestamp.

Adding max(ts) as event_ts ensures the timestamp of the maximum temperature reading is propagated properly.


324-325: Queries consistently updated to reflect schema changes.

The SELECT queries have been properly updated to match the schema changes in the table and flow definition.

Also applies to: 342-343

tests/cases/standalone/common/flow/flow_flush.sql (1)

1-38: Well-structured test for flow flushing functionality.

This test effectively validates the FLUSH_FLOW command by:

  1. Creating a source table with timestamp data
  2. Defining a flow with time-windowed aggregation
  3. Executing FLUSH_FLOW to propagate data
  4. Verifying the aggregated results in the output table

The test includes proper data preparation, explicit time windows, and thorough cleanup.

src/common/meta/src/ddl/create_flow.rs (2)

174-174: Flow type now dynamically determined from task options.

Good improvement. The flow type is now extracted from the options via get_flow_type_from_options instead of being hardcoded, supporting both streaming and batching modes.


199-201: Enhanced logging includes flow type information.

Improved log message now includes the flow type alongside flow ID and peers, which will aid in debugging and observability.

tests/cases/standalone/common/flow/flow_rebuild.sql (1)

100-105: Added assertion is valuable but should be paired with deterministic expectation

SELECT count(*) FROM input_basic; is a good cross‑check, yet the expected value is not captured in the .sql file.
If the result is only verified indirectly in the paired .result file, please ensure:

  • the count is stable across all rebuild/restart paths,
  • and the .result snapshot explicitly lists the expected row count, otherwise test drift may go unnoticed.

If you prefer not to hard‑code the number, consider adding a -- SQLNESS CHECK directive with a pattern.

tests-integration/src/standalone.rs (1)

191-192: flow_engine() replaces flow_worker_manager() – double‑check feature parity

Switching to the dual engine is the right direction, but some helper methods (metrics, diagnostic dumps) previously exposed by flow_worker_manager() may not yet be forwarded by flow_engine().
Please verify that any test utilities or admin commands used elsewhere in the suite still work after this change.

tests/cases/standalone/common/flow/flow_call_df_func.sql (4)

12-12: Consistent replacement of tumble with date_bin time window approach

The change from tumble to date_bin for time window grouping is well-implemented, maintaining the same time interval (1 second) and origin time ('2021-07-01 00:00:00'). This change aligns with the batch mode improvements described in the PR.


27-27: Correctly updated SELECT queries to use the new time_window column

The SELECT queries have been properly updated to reference the new time_window column instead of the previous window_start/window_end columns, maintaining query result consistency.

Also applies to: 41-41


58-58: Consistent application of date_bin in the second flow definition

The second flow definition correctly implements the same time window pattern using date_bin, maintaining consistency across all flow definitions.


72-72: Correctly updated all dependent SELECT queries

All dependent queries have been consistently updated to use the new time_window schema, ensuring the test logic remains valid.

Also applies to: 85-85

tests/cases/standalone/common/flow/flow_call_df_func.result (2)

14-14: Consistent SQL output updates to match new time_window approach

The result file has been properly updated to reflect the new query structure using date_bin and the time_window column, ensuring the expected outputs match the modified queries.

Also applies to: 45-45, 79-79, 143-143, 176-176


47-51: Result table structure correctly updated for new schema

The expected output tables have been properly adjusted to show a single time_window column instead of separate window_start/window_end columns, with properly aligned column headers and data.

Also applies to: 81-86, 145-149, 178-183

tests/cases/standalone/common/flow/flow_rebuild.result (5)

6-8: Added append_mode to table creation for batching compatibility

The append_mode = 'true' property was added to the table definition, which is necessary for proper operation with the new batching mode flow engine. This is consistent with the architectural changes described in the PR.


171-172: Added helpful comments documenting batching mode behavior

Comments have been added to clarify that the test is now operating in flow batching mode, which helps with understanding the expected behavior changes.

Also applies to: 513-514


180-186: Added validation queries to verify batching mode behavior

New queries were added to count rows in the input tables, providing additional verification of the batching mode's correct operation.

Also applies to: 522-528


315-322: Added synchronization points for flow rebuilds

Multiple SELECT 1; statements and SQLNESS SLEEP 3s directives have been added to ensure proper synchronization between test steps, addressing the asynchronous nature of flow rebuilds in the new dual-engine architecture.

Also applies to: 323-324, 333-334, 382-389, 390-391, 400-401, 432-439, 440-441, 450-452, 484-494


519-520: Updated expected count to match batching mode behavior

The expected count in the wildcard query output has been updated from 3 to 4, correctly reflecting the behavior change in batching mode where all rows are processed together.

tests/cases/standalone/common/flow/flow_auto_sink_table.result (3)

12-14: Updated flow definition with date_bin-based time window

The flow definition has been updated to use date_bin for time window calculations, consistent with the changes in other flow test files and aligning with the batching mode improvements.

Also applies to: 17-17


28-29: Sink table schema correctly updated with higher precision timestamp

The sink table schema has been properly updated to:

  1. Replace separate window_start/window_end columns with a single time_window column
  2. Increase time precision from TIMESTAMP(3) to TIMESTAMP(9) for more accurate time handling
  3. Update the TIME INDEX to reference the new time_window column

This change is properly maintained after system restart as confirmed in lines 54-56.

Also applies to: 30-30, 54-55, 56-56


65-71: Updated SHOW CREATE FLOW output to reflect new query structure

The SHOW CREATE FLOW command output has been updated to correctly reflect the new query structure that uses date_bin and the time_window column approach.

src/operator/src/statement/ddl.rs (1)

428-433: Confirm string representation of FlowType matches downstream parser

flow_options.insert(FLOW_TYPE_KEY, flow_type.to_string()) relies on
Display returning exactly the sentinel strings compared
with in flow::adapter::flownode_impl ("batching" / "streaming").

Mismatch in capitalisation (“Batching” vs “batching”) will route the flow to
FlowType::Batching by default and silently ignore the requested type.

Please double‑check the two implementations or standardise via
flow_type.as_str() returning a lowercase &'static str.

src/common/query/src/logical_plan.rs (1)

100-110: 🛠️ Refactor suggestion

Partial TableReference loses provided schema – use the value coming from the plan instead of the fallback one

When the incoming plan contains a TableReference::Partial { schema, table }, the caller has already supplied a schema. Overwriting it with the schema argument silently discards information and may route the insert to the wrong schema when the current session‐level default differs from the reference in the plan.

-        let table_name = match table_name {
+        let table_name = match table_name {
             TableReference::Bare { table } => TableName {
                 catalog_name: catalog.to_string(),
                 schema_name: schema.to_string(),
                 table_name: table.to_string(),
             },
             TableReference::Partial { schema, table } => TableName {
                 catalog_name: catalog.to_string(),
-                schema_name: schema.to_string(),
+                // honour the schema provided by the plan
+                schema_name: schema.to_string(),
                 table_name: table.to_string(),
             },

Likely an incorrect or invalid review comment.

tests/cases/standalone/common/flow/flow_basic.result (7)

12-17: Flow query syntax updated to use date_bin instead of tumble

The test now uses date_bin(INTERVAL '1 second', ts, '2021-07-01 00:00:00') as time_window for time windowing instead of the previous tumble function. This aligns with the PR's objective to use batching mode for aggregation queries and fix SQL correctness.


28-30: Schema updated to use TIMESTAMP(9) precision for time windows

The output table schema now uses a single time_window column with TIMESTAMP(9) precision instead of separate window_start/window_end columns. This higher precision timestamp provides more accurate time tracking for flow operations.


88-92: Output format updated to reflect schema changes

The query result format has been updated to show results with the new time_window column format, maintaining consistency with the schema changes.


894-896: Table option added for append-only behavior

The append_mode = 'true' option has been added to the table definition, indicating that this table only supports appending data. This is important for the batching mode operation as mentioned in the PR objectives.


904-905: Timestamp column renamed and update_at column added

The timestamp column was renamed from ts to event_ts and an update_at timestamp column was added. This provides better separation between the event time and update time, which is beneficial for correct time-based processing in flows.


915-915: Flow query updated to use event_ts for timestamp

The query has been modified to select max(ts) as event_ts to match the schema changes in the target table, ensuring proper time indexing.


1054-1056: All data source tables consistently configured for append-only mode

All source tables for flows (ngx_access_log, requests, android_log) have been updated with append_mode = 'true', which indicates a consistent pattern of making tables append-only for use with flows in batching mode.

Also applies to: 1190-1192, 1401-1403, 1514-1516

Comment thread tests/cases/standalone/common/flow/flow_rebuild.sql
Comment thread src/cmd/src/standalone.rs
Comment thread src/frontend/src/instance/grpc.rs
Comment thread src/flow/src/server.rs
Comment thread src/flow/src/batching_mode/utils.rs
Comment thread src/flow/src/batching_mode/frontend_client.rs
Comment thread src/flow/src/batching_mode/task.rs
Comment thread src/flow/src/batching_mode/task.rs Outdated
Comment thread src/flow/src/adapter/flownode_impl.rs
Comment thread src/flow/src/adapter/flownode_impl.rs Outdated
Comment thread src/flow/src/adapter/flownode_impl.rs Outdated
Comment thread src/flow/src/adapter/flownode_impl.rs
Comment thread src/flow/src/adapter/flownode_impl.rs Outdated
Comment thread src/flow/src/batching_mode/frontend_client.rs
Comment thread src/flow/src/batching_mode/task.rs Outdated
Comment thread src/flow/src/batching_mode/task.rs Outdated
Comment thread src/flow/src/batching_mode/task.rs Outdated
Comment thread src/flow/src/batching_mode/task.rs Outdated
@waynexia waynexia enabled auto-merge April 23, 2025 14:43
@waynexia waynexia added this pull request to the merge queue Apr 23, 2025
Merged via the queue into GreptimeTeam:main with commit a0900f5 Apr 23, 2025
38 checks passed
@evenyag
Copy link
Copy Markdown
Contributor

evenyag commented May 1, 2025

This looks like a breaking change. @discord9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-not-required This change does not impact docs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants