CREATE TABLE local.dim_pub_date
on cluster cluster_3shards_1replicas
(
`dt` Date,
`dt_str` String,
`yea` UInt16,
`quar` UInt8,
`mon` UInt8,
`daynumber_of_year` UInt16,
`daynumber_of_Week` UInt8,
`tmstamp` UInt32
)
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{layer}-{shard}/dim_pub_date', '{replica}')
PARTITION BY yea
ORDER BY dt
SETTINGS index_granularity = 8192
--根据现有本地表创建分布式表
CREATE TABLE dw.dim_pub_date
on cluster cluster_3shards_1replicas
as local.dim_pub_date
ENGINE = Distributed('cluster_3shards_1replicas', 'local', dim_pub_date, rand());
insert into dw.dim_pub_date
WITH arrayMap(i -> (toDate('2010-01-01') + i), range(29220)) AS Calendar
SELECT
arrayJoin(Calendar) as dt
,cast(dt as String) as dt_str
,toYear(dt) yea
,toQuarter(dt) quar
,toMonth(dt) mon
,toDayOfYear(dt) daynumber_of_year
,toDayOfWeek(dt) daynumber_of_Week
,toUnixTimestamp(toDateTime(dt)) tmstamp
order by dt desc;
clickhouse创建时间维表
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 我们有时候做分析或者报表的时候,会遇到这样的问题:我们想看1月1日至1月31日每一天的某一指标的变化趋势,但是,有...
- select * from INFORMATION_SCHEMA.TABLES where TABLE_SCHEM...