我有以下设置:
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;
Run Code Online (Sandbox Code Playgroud)
我想添加新列,例如。ip
到my request_income
表。根据文档,为了做到这一点,我需要执行以下步骤:
分离视图以停止接收来自 Kafka 的消息。
分离表请求收入;
由于 Kafka 引擎不支持ALTER
查询,因此删除了从 Kafka 流式传输数据的表。
DROP TABLE request_income_buffer
使用新字段重新创建从 Kafka 流式传输数据的表。
如果不存在则创建表 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' , '组', 'JSONEachRow');
根据这篇文章更新分离物化视图的 .inner 表
ALTER TABLE `.inner.request_income` 在主机之后添加列 ip 字符串;
根据上面更新视图的选择查询的帖子
ATTACH TABLE request_income
问题是如何更新视图的选择查询?
所以看起来更新物化视图的选择查询的方法如下:
SELECT metadata_path FROM system.tables WHERE name = 'request_income';
使用您喜欢的文本编辑器来修改视图的 sql。在我的情况下,编辑后的 sql 看起来像
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
附加修改后的视图
附表 request_income;
归档时间: |
|
查看次数: |
4520 次 |
最近记录: |