Keith Wall
05/03/2024, 2:15 PMKeith Wall
05/03/2024, 2:16 PMSELECT * from employee_information WHERE dept_id = 1; and the continuous query SELECT
dept_id,
COUNT(*) as emp_count
FROM employee_information
GROUP BY dept_id;. That all works as expected.Keith Wall
05/03/2024, 2:17 PMKeith Wall
05/03/2024, 2:19 PMFlink SQL>
>
> CREATE TABLE employee_information (
> emp_id INT,
> name VARCHAR,
> dept_id INT
> ) WITH (
> 'connector' = 'filesystem',
> 'path' = '/tmp/employees.csv',
> 'format' = 'csv'
> );Keith Wall
05/03/2024, 2:19 PMSELECT * from employee_information WHERE dept_id = 1;Keith Wall
05/03/2024, 2:20 PMFlink SQL>
> INSERT INTO department_counts
> SELECT
> dept_id,
> COUNT(*) as emp_count
> FROM employee_information;
[ERROR] Could not execute SQL statement. Reason:
org.apache.calcite.sql.validate.SqlValidatorException: Expression 'dept_id' is not being groupedKeith Wall
05/03/2024, 2:20 PMKeith Wall
05/03/2024, 2:21 PMFlink SQL> INSERT INTO department_counts
> SELECT
> dept_id,
> COUNT(*) as emp_count
> FROM employee_information
> GROUP BY dept_id;
[ERROR] Could not execute SQL statement. Reason:
org.apache.flink.table.api.TableException: Cannot find table '`default_catalog`.`default_database`.`department_counts`' in any of the catalogs [default_catalog], nor as a temporary table.Keith Wall
05/03/2024, 2:22 PMdepartment_counts myself first? how?Keith Wall
05/03/2024, 2:23 PMCREATE TABLE department_counts
> (dept_id INT, emp_count BIGINT NOT NULL)
> WITH ('connector' = 'filesystem', 'path' = '/tmp/department_counts.csv', 'format' = 'csv')
but that fails:
[ERROR] Could not execute SQL statement. Reason:
org.apache.flink.table.api.TableException: Table sink 'default_catalog.default_database.department_counts' doesn't support consuming update changes which is produced by node GroupAggregate(groupBy=[dept_id], select=[dept_id, COUNT(*) AS emp_count])Keith Wall
05/03/2024, 2:26 PMrmoff
05/03/2024, 2:31 PMrmoff
05/03/2024, 2:31 PMGROUP BYrmoff
05/03/2024, 2:32 PMINSERT (which as you say, won't work if you don't have the table) you could try
CREATE TABLE department_counts AS
SELECT
dept_id,
COUNT(*) as emp_count
FROM employee_information
GROUP BY dept_id;rmoff
05/03/2024, 2:32 PMWITHrmoff
05/03/2024, 2:32 PMrmoff
05/03/2024, 2:36 PMrmoff
05/03/2024, 2:38 PMFlink SQL> CREATE TABLE department_name with ('connector' = 'filesystem', 'path' = '/tmp/dept.csv','format' = 'csv') AS
> SELECT
> dept_id,
> name
> FROM employee_information ;
[INFO] Submitting SQL update statement to the cluster...
[INFO] SQL update statement has been successfully submitted to the cluster:
Job ID: b6349b836eed898004e8d8d5cfa3fe2crmoff
05/03/2024, 2:38 PM❯ cat /tmp/dept.csv/part-eb52363b-81c4-48d8-936c-e3c4c85f87e8-0-0
42,FOO
42,BARrmoff
05/03/2024, 2:39 PMKeith Wall
05/03/2024, 2:43 PMrmoff
05/03/2024, 2:46 PMdebezium format would be valid for the filesystem connector too.Keith Wall
05/03/2024, 2:48 PMrmoff
05/03/2024, 2:48 PMKeith Wall
05/03/2024, 3:39 PMCREATE TABLE department_counts (
dept_id INT, emp_count BIGINT NOT NULL
) WITH (
'connector' = 'filesystem',
'path' = '/tmp/department_counts.csv',
'format' = 'debezium-json'
);
then :
INSERT INTO department_counts
SELECT
dept_id,
COUNT(*) as emp_count
FROM employee_information
GROUP BY dept_id