I have following setup:
CREATE TABLE IF NOT EXISTS request_income_buffer (
timestamp UInt64,
timestamp_micro Float32,
traceId Int64,
host String,
type String,
service String,
message String,
caller String,
context String
) ENGINE = Kafka('kafka:9092', 'request_income', 'group', 'JSONEachRow');
CREATE MATERIALIZED VIEW IF NOT EXISTS request_income
ENGINE = MergeTree(date, microtime, 8192) AS
SELECT
toDate(toDateTime(timestamp)) AS `date`,
toDateTime(timestamp) as `date_time`,
timestamp,
timestamp_micro AS `microtime`,
traceId,
host,
type,
service,
message,
caller,
context
FROM
request_income_buffer;
I want to add new column, ex. ip
to my request_income
table.
According to docs in order to do so I will need to follow next steps:
Detach view to stop receiving messages from Kafka.
DETACH TABLE request_income;
Drop table that streams data from Kafka since Kafka engine doesn't support ALTER
queries.
DROP TABLE request_income_buffer
Recreate table that streams data from Kafka with new field.
CREATE TABLE IF NOT EXISTS request_income_buffer ( timestamp UInt64, timestamp_micro Float32, traceId Int64, host String, ip String, type String, service String, message String, caller String, context String ) ENGINE = Kafka('kafka:9092', 'request_income', 'group', 'JSONEachRow');
According to this post update .inner table of the detached materialized view
ALTER TABLE `.inner.request_income` ADD COLUMN ip String AFTER host;
According to post from above update view's select query
ATTACH TABLE request_income
Question is how to update view's select query?
So it appears the way to update materialized view's select query is as follows:
SELECT metadata_path FROM system.tables WHERE name = 'request_income';
Use your favorite text editor to modify view's sql. In my case edited sql will look like
ATTACH MATERIALIZED VIEW request_income ( date Date, date_time DateTime, timestamp UInt64, microtime Float32, traceId Int64, host String, ip String, type String, service String, message String, caller String, context String ) ENGINE = MergeTree(date, microtime, 8192) AS SELECT toDate(toDateTime(timestamp)) AS date, toDateTime(timestamp) AS date_time, timestamp, timestamp_micro AS microtime, traceId, host, ip, type, service, message, caller, context FROM default.request_income_buffer
Attach modified view back
ATTACH TABLE request_income;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With