admin管理员组文章数量:1440491
StarRocks业务开发tips
StarRocks
1、StarRocks的非主键表的表字段不支持修改,一般需要重新建表,但是表名可以修改,可以新增或删除列。
2、即使使用了mv_nvl或COALESCE等函数对NULL进行默认值设定,插入数据时还是报错NULL值插入了非空字段,原因是字段类型不匹配,不能自动转换。
3、StarRocks中主键表的insert into在主键冲突时会自动覆盖数据。
参考:.5/sql-reference/sql-statements/data-manipulation/INSERT/
4、开启了动态分区且dynamic_partition.history_partition_num大于0的新创建的表,不会立马创建分区,而是每10分钟自动进行检查和逐步创建分区,也可以考虑手动创建分区。
动态分区相关 FE 配置项:
dynamic_partition_check_interval_seconds
:FE 配置项,动态分区检查的时间周期,默认为 600,单位为 s,即每10分钟检查一次分区情况是否满足PROPERTIES
中动态分区属性,如不满足,则会自动创建和删除分区。
5、若要手动创建分区,执行 ALTER TABLE,修改动态分区的属性,例如暂停或者开启动态分区特性,参考如下示例添加指定分区。
代码语言:javascript代码运行次数:0运行复制ALTER TABLE dws_o2global_ad_unite_effect_wide_hi SET("dynamic_partition.enable"="false");
ALTER TABLE dws_o2global_ad_unite_effect_wide_hi ADD PARTITION p2025031023 VALUES [('2025-03-10 23:00:00'), ('2025-03-11 00:00:00'));
ALTER TABLE dws_o2global_ad_unite_effect_wide_hi SET("dynamic_partition.enable"="true");
或者可以批量创建分区,指定起始时间、结束时间以及分区间隔。
代码语言:javascript代码运行次数:0运行复制ALTER TABLE dws_o2global_ad_unite_effect_wide_hi SET("dynamic_partition.enable"="false");
ALTER TABLE dws_o2global_ad_unite_effect_wide_hi ADD PARTITIONS START ("2023-05-01") END ("2025-06-30") EVERY (INTERVAL 1 DAY);
ALTER TABLE dws_o2global_ad_unite_effect_wide_hi SET("dynamic_partition.enable"="true");
6、StarRocks中的WITH语句和INSERT OVERRITE语句搭配,需要把WITH语句放在INSERT OVERRITE语句内部,示例如下。
代码语言:javascript代码运行次数:0运行复制INSERT OVERWRITE dim_pub_app_extra_df PARTITION(p${YYYYMMDD}, p${YYYYMMDD+1})
WITH temp AS (
SELECT
my_nvl(app_id, '-') AS app_id,
my_nvl(timezone, '-') AS timezone,
my_nvl(app_partition_name, '-') AS app_partition_name,
my_nvl(revenue_decrypt_method, '-') AS revenue_decrypt_method,
CURRENT_TIMESTAMP as update_time
FROM ext_data_conf_dim_app_extra
WHERE isdelete != 1
)
SELECT '${YYYY-MM-DD}' AS statis_date, * FROM temp
UNION ALL
SELECT '${YYYY-MM-DD+1}' AS statis_date, * FROM temp;
7、对于 StarRocks 数据源,通过OLAP外表同步数据,现阶段只支持 Insert 写入,不支持读取,对于其他数据源,现阶段只支持读取,还不支持写入。但是StarRocks集群之间可以通过MySQL协议进行数据同步,查询速度会稍微受到影响,百万级的读取速度在10秒内。
8、StarRocks可以通过MySQL协议读取ClickHouse的数据,需要指定ClickHouse的MySQL协议的地址和端口(一般为9004)。
9、在alter表之后,表的状态会处于SCHEMA_CHANGE状态,此时不能进行插入或更改,需要等待一会。
代码语言:javascript代码运行次数:0运行复制MySQL [itdd_o2global]> alter table dws_o2global_ad_unite_effect_wide_df add column custom_event_id STRING NOT NULL DEFAULT '0' COMMENT '自定义事件ID' after user_source_type;
Query OK, 0 rows affected (0.68 sec)
MySQL [itdd_o2global]> alter table dws_o2global_ad_unite_effect_wide_df add column custom_event_name STRING NOT NULL DEFAULT '-' COMMENT '自定义事件名称' after custom_event_id;
ERROR 1064 (HY000): Unexpected exception: The state of "dws_o2global_ad_unite_effect_wide_df" is SCHEMA_CHANGE. Alter operation is only permitted if NORMAL
10、在 StarRocks 中,date_format(t1.end_date, 'yyyyMMdd')
可以工作,但 date_format(t1.end_date, 'yyyyMMddHH')
不行,这是因为 StarRocks 对日期格式字符串的解析有特定规则。
-- 正确写法(使用%前缀格式符)
SELECT date_format(t1.end_date, '%Y%m%d%H')
FROM your_table t1;
11、INSERT OVERWRITE
插入数据分区时,如果指定的插入分区数少于数据数据本身的分区数,则会报错分区不存在的错误。如果指定的插入分区数多于数据数据本身的分区数,则指定的多余分区的数据会被清空。
-- 正常情况
INSERT OVERWRITE dws_o2global_ad_unite_effect_wide_hi PARTITION(p2025042400,p2025042401,p2025042402)
SELECT * from temp where statis_hour >= '2025-04-24 00:00:00' and statis_hour <= '2025-04-24 02:00:00'
-- 插入分区数少于数据数据本身的分区数,会报错p2025042402分区不存在
INSERT OVERWRITE dws_o2global_ad_unite_effect_wide_hi PARTITION(p2025042400,p2025042401)
SELECT * from temp where statis_hour >= '2025-04-24 00:00:00' and statis_hour <= '2025-04-24 02:00:00'
-- 插入分区数多于数据数据本身的分区数,p2025042402的数据会被清空
INSERT OVERWRITE dws_o2global_ad_unite_effect_wide_hi PARTITION(p2025042400,p2025042401,p2025042402)
SELECT * from temp where statis_hour >= '2025-04-24 00:00:00' and statis_hour <= '2025-04-24 01:00:00'
光源平台
1、光源平台报错给出tracking_url 时,可以curl访问该链接查看错误信息,一般需要在内网跳板机上才可以访问。
代码语言:javascript代码运行次数:0运行复制com.tencent.ieg.bdp.unifiedquerymon.exception.QueryDetailException: SQL 执行失败:Insert has filtered data in strict mode, txn_id = 36456402 tracking_url = http://10.254.5.23:8040/api/_load_error_log?file=error_log_10eb35ccf81011ef_ab705254007c9127
at com.tencent.ieg.bdp.unifiedquery.core.query.QueryAsyncServiceImpl.handleExecuteException(QueryAsyncServiceImpl.java:886)
at com.tencent.ieg.bdp.unifiedquery.core.query.QueryAsyncServiceImpl.executeQuery(QueryAsyncServiceImpl.java:525)
at com.tencent.ieg.bdp.unifiedquery.core.query.QueryService.doQuery(QueryService.java:45)
at com.tencent.ieg.bdp.unifiedquery.core.query.QueryAsyncServiceImpl$QueryTask.call(QueryAsyncServiceImpl.java:1039)
at com.tencent.ieg.bdp.unifiedquery.core.query.execution.QueryTaskWrapper.call(QueryTaskWrapper.java:41)
at com.tencent.ieg.bdp.unifiedquery.core.query.execution.QueryTaskWrapper.call(QueryTaskWrapper.java:14)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:750)
Caused by: java.sql.SQLSyntaxErrorException: Insert has filtered data in strict mode, txn_id = 36456402 tracking_url = http://10.254.5.23:8040/api/_load_error_log?file=error_log_10eb35ccf81011ef_ab705254007c9127
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:121)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:763)
at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:648)
at com.tencent.ieg.bdp.unifiedquery.connector.proxy.ProxyStatement.execute(ProxyStatement.java:109)
at com.tencent.ieg.bdp.unifiedquery.connector.proxy.OnelightProxyStatement.execute(OnelightProxyStatement.java)
at com.tencent.ieg.bdp.unifiedquerymon.util.JdbcUtil.execute(JdbcUtil.java:172)
at com.tencent.ieg.bdp.unifiedquery.core.query.QueryAsyncServiceImpl.executeSql(QueryAsyncServiceImpl.java:701)
at com.tencent.ieg.bdp.unifiedquery.core.query.QueryAsyncServiceImpl.executeQuery(QueryAsyncServiceImpl.java:494)
... 8 more
2、不要选择动态创建CN资源,这个功能在海外没有,这个功能是平台统一提供的CN节点。
若选择天穹资源,也可以正常计算,但是使用了不了CN资源。
本文标签: StarRocks业务开发tips
版权声明:本文标题:StarRocks业务开发tips 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/biancheng/1747737298a2751810.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论