doris日期维度表

insert into dim.dim_date

select row_number() over ( order by dim.date_value) id,

date_format(dim.date_value,'%Y-%m-%d') date_key,

date_format(dim.date_value,'%Y%m%d') date_value,

day(dim.date_value) day_of_month,

month(dim.date_value) month_value,

date_format(dim.date_value,'%Y%m') year_month,

date_trunc(dim.date_value,'month') month_first,

last_day(dim.date_value) month_end,

weekday(dim.date_value) + 1 day_of_week,

case

when weekday(dim.date_value) = 0 then '星期一'

when weekday(dim.date_value) = 1 then '星期二'

when weekday(dim.date_value) = 2 then '星期三'

when weekday(dim.date_value) = 3 then '星期四'

when weekday(dim.date_value) = 4 then '星期五'

when weekday(dim.date_value) = 5 then '星期六'

when weekday(dim.date_value) = 6 then '星期日'

end week_cn,

case

when weekday(dim.date_value) = 0 then 'Mon'

when weekday(dim.date_value) = 1 then 'Tues'

when weekday(dim.date_value) = 2 then 'Wed'

when weekday(dim.date_value) = 3 then 'Thur'

when weekday(dim.date_value) = 4 then 'Fri'

when weekday(dim.date_value) = 5 then 'Sat'

when weekday(dim.date_value) = 6 then 'Sun'

end week_en,

substr(yearweek(dim.date_value,1),-2) week_num,

yearweek(dim.date_value,1) year_week,

quarter(dim.date_value) season,

year(dim.date_value)*10 + quarter(dim.date_value) season_of_year,

if(month(dim.date_value)>6,2,1) half_year,

date_trunc(dim.date_value,'year') year_first,

days_sub(date_trunc(years_sub(dim.date_value,-1),'year'),1) year_end,

year(dim.date_value) year_num

from (select adddate('1900-01-01', number) date_value from numbers("number" = '73048')) dim -- 73048

-- select datediff('1900-01-01','2100-01-01')

### Apache Doris 分区使用指南 #### 什么是分区? 在 Apache Doris 中,分区是一种用于管理和优化大规模数据的技术。它允许用户按照某些列的值将表中的数据划分为多个逻辑部分,从而提高查询性能并简化数据管理[^1]。 #### 分区的作用 分区的主要作用在于提升查询效率和降低资源消耗。通过合理的分区设计,可以减少扫描的数据量,加速过滤操作,并支持更高效的分布式计算[^2]。 #### 常见的分区类型 Apache Doris 支持多种类型的分区方式,以下是几种常见的分区策略: - **Range 分区** Range 分区基于某一列的范围来划分数据。例如,可以根据时间戳字段创建按天、周或的分区。这种方式非常适合处理具有明显时间特征的数据集[^3]。 - **Hash 分区** Hash 分区通过对指定列的值进行哈希运算并将结果映射到固定的分区上。这种分区方法能够均匀分布数据,适用于需要随机访问不同数据子集的场景。 - **List 分区** List 分区适合于离散值集合的情况。比如,如果某列只有有限几个可能取值,则可以通过显式列举这些值来进行分区定义。 #### 如何配置分区? 下面是一个简单的例子展示如何在一个新表中设置 `Range` 类型的时间维度上的分区: ```sql CREATE TABLE example_table ( id BIGINT, date DATE, value DOUBLE ) PARTITION BY RANGE(date) ( PARTITION p202301 VALUES LESS THAN ('2023-02-01'), PARTITION p202302 VALUES LESS THAN ('2023-03-01') ); ``` 上述 SQL 创建了一个名为 `example_table` 的表格,并将其依据日期字段进行了两个阶段式的 range 划分。 对于 hash 分区而言,通常会结合 bucketing 来进一步细化控制每一分区内数据的具体布局情况如下所示: ```sql CREATE TABLE another_example ( key STRING, val INT ) DISTRIBUTED BY HASH(key) BUCKETS 8; ``` 此命令表示该表将会被分配至八个独立 buckets 当中去执行后续的操作流程。 ---
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值