Skip to content

avg by() in CREATE FLOW TQL fails with FieldNotFound #7794

@jacson-junior

Description

@jacson-junior

What type of bug is this?

Unexpected error

What subsystems are affected?

Query Engine

Minimal reproduce step

-- Step 1: Create tables
CREATE TABLE sensor_readings (
value DOUBLE,
timestamp TIMESTAMP TIME INDEX,
sensor STRING,
loc STRING,
PRIMARY KEY (sensor, loc)
);

CREATE TABLE sensor_readings_avg (
value DOUBLE,
timestamp TIMESTAMP TIME INDEX,
sensor STRING,
PRIMARY KEY (sensor)
);

-- Step 2: Insert sample data
INSERT INTO sensor_readings VALUES (20, now(), 'test', 'A');

-- Step 3: Verify standalone TQL works (this succeeds)
TQL EVAL (now() - '1m'::interval, now(), '1m')
avg by(sensor) (sensor_readings) as value;

-- Step 4: Create flow with avg by() (this fails)
CREATE FLOW sensor_readings_avg_flow
SINK TO sensor_readings_avg
EVAL INTERVAL '1m' AS
TQL EVAL (now() - '1m'::interval, now(), '1m')
avg by(sensor) (sensor_readings) as value;

What did you expect to see?

Flow created successfully, consistent with how the same TQL expression works in standalone evaluation and how sum by() / count by() work in flows

What did you see instead?

Query 1 ERROR at Line 18: : (EngineExecuteQuery): Datafusion error:
Context("type_coercion", SchemaError(FieldNotFound {
field: Column { relation: None, name: "count(sensor_readings.value)" },
valid_fields: [
Column { relation: Some(Bare { table: "sensor_readings" }), name: "value" },
Column { relation: Some(Bare { table: "sensor_readings" }), name: "timestamp" },
Column { relation: Some(Bare { table: "sensor_readings" }), name: "sensor" },
Column { relation: Some(Bare { table: "sensor_readings" }), name: "loc" }
]
}))

What operating system did you use?

linux/arm64 container running on macOS 15.7.4 arm64

What version of GreptimeDB did you use?

1.0.0-beta.1

Relevant log output and stack trace

Metadata

Metadata

Assignees

Labels

C-bugCategory Bugs

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions