|
| 1 | +### 1、parser-dorse版本对照 |
| 2 | + |
| 3 | +| parser-dorse版本 | doris版本 | 备注 | |
| 4 | +| ---------------- | -------------- | ---- | |
| 5 | +| master | 0.14.0-release | | |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +### 2、单独编译 |
| 10 | + |
| 11 | +```shell |
| 12 | +mvn clean package -Dmvn.skip.test=true |
| 13 | +``` |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +### 3、使用 |
| 18 | + |
| 19 | +编译后上传到私服就可以通过mvn来引用了 |
| 20 | + |
| 21 | +```xml |
| 22 | +<dependency> |
| 23 | + <groupId>com.lfsenior.sql.parser</groupId> |
| 24 | + <artifactId>parser-doris</artifactId> |
| 25 | + <version>1.0-SNAPSHOT</version> |
| 26 | +</dependency> |
| 27 | + |
| 28 | +<dependency> |
| 29 | + <groupId>net.sourceforge.czt.dev</groupId> |
| 30 | + <artifactId>java-cup</artifactId> |
| 31 | + <version>0.11-a-czt02-cdh</version> |
| 32 | +</dependency> |
| 33 | + |
| 34 | +<dependency> |
| 35 | + <groupId>net.sourceforge.czt.dev</groupId> |
| 36 | + <artifactId>java-cup-runtime</artifactId> |
| 37 | + <version>0.11-a-czt01-cdh</version> |
| 38 | +</dependency> |
| 39 | + |
| 40 | +<dependency> |
| 41 | + <groupId>com.google.guava</groupId> |
| 42 | + <artifactId>guava</artifactId> |
| 43 | + <version>29.0-jre</version> |
| 44 | +</dependency> |
| 45 | +<dependency> |
| 46 | + <groupId>com.google.code.gson</groupId> |
| 47 | + <artifactId>gson</artifactId> |
| 48 | + <version>2.8.6</version> |
| 49 | +</dependency> |
| 50 | + |
| 51 | +<dependency> |
| 52 | + <groupId>org.projectlombok</groupId> |
| 53 | + <artifactId>lombok</artifactId> |
| 54 | + <version>1.18.16</version> |
| 55 | +</dependency> |
| 56 | +``` |
| 57 | + |
| 58 | +demo |
| 59 | + |
| 60 | +```java |
| 61 | +package com.lfsenior.parser; |
| 62 | + |
| 63 | +import com.lfsenior.sql.parser.doris.analysis.SqlParser; |
| 64 | +import com.lfsenior.sql.parser.doris.analysis.SqlScanner; |
| 65 | +import com.lfsenior.sql.parser.doris.analysis.StatementBase; |
| 66 | +import com.lfsenior.sql.parser.doris.common.util.SqlParserUtils; |
| 67 | +import org.junit.Test; |
| 68 | + |
| 69 | +import java.io.StringReader; |
| 70 | +import java.util.List; |
| 71 | + |
| 72 | +/** |
| 73 | + * @program: Antlr4ForClickHouse |
| 74 | + * @package: com.lfsenior.parser |
| 75 | + * @description: |
| 76 | + * @author: DingLuPan |
| 77 | + * @create: 2021/11/1 16:42 |
| 78 | + **/ |
| 79 | +public class DorisSqlParser { |
| 80 | + @Test |
| 81 | + public void createTableTest() throws Exception { |
| 82 | + String sql = "CREATE TABLE `doris_example` ( \n" + |
| 83 | + "`project_id` bigint DEFAULT NULL COMMENT '销售项目id', \n" + |
| 84 | + "`project_code` string DEFAULT NULL COMMENT '销售项目编码', \n" + |
| 85 | + "`project_way` int DEFAULT NULL COMMENT '项目方式[crm_fresh_project_way](10按寄件公司运作,20按付款公司运作,30按寄件和付款公司运作)', \n" + |
| 86 | + "`project_status` int DEFAULT NULL COMMENT '项目状态 [crm_market_project_status] 10-待审核,20-审核中,30-被驳回,40-已生效,50-已放弃,60-已结束]', \n" + |
| 87 | + "`etl_date` datetime DEFAULT NULL COMMENT '跑批时间', \n" + |
| 88 | + "`project_type` int sum DEFAULT NULL COMMENT '项目类型:10生鲜项目,20展会项目,30服装城项目,40其他', \n" + |
| 89 | + "`main_responsible_person_id` bigint sum DEFAULT NULL COMMENT '总负责人id', \n" + |
| 90 | + "`project_type_detail` int max DEFAULT NULL COMMENT '项目细项,根据项目类型联动,crm_market_project_detail_fresh,crm_market_project_detail_exhibition,...', \n" + |
| 91 | + "`customer_short_name` string max DEFAULT NULL COMMENT '客户简称', \n" + |
| 92 | + "`customer_id` bigint min DEFAULT NULL COMMENT '客户ID', \n" + |
| 93 | + "`customer_code` string max DEFAULT NULL COMMENT '客户编码', \n" + |
| 94 | + "`market_id` bigint sum DEFAULT NULL COMMENT '销售经理id', \n" + |
| 95 | + "`market_name` string max DEFAULT NULL COMMENT '销售经理', \n" + |
| 96 | + "`assistant_id` bigint sum DEFAULT NULL COMMENT '销售助理ID', \n" + |
| 97 | + "`assistant_name` string min DEFAULT NULL COMMENT '销售助理', \n" + |
| 98 | + "`calculation_id` bigint sum DEFAULT NULL COMMENT '销售总监id', \n" + |
| 99 | + "`calculation_name` string max DEFAULT NULL COMMENT '销售总监', \n" + |
| 100 | + "`senior_manager_id` bigint max DEFAULT NULL COMMENT '销售高监id', \n" + |
| 101 | + "`senior_manager_name` string replace DEFAULT NULL COMMENT '销售高监', \n" + |
| 102 | + "`target_amount` decimal(13,2) sum DEFAULT NULL COMMENT '目标额度', \n" + |
| 103 | + "`create_time` datetime max NOT NULL COMMENT '创建时间', \n" + |
| 104 | + "`_version` bigint replace DEFAULT NULL COMMENT '版本号' \n" + |
| 105 | + ") \n" + |
| 106 | + "AGGREGATE KEY(project_id,project_code,project_way,project_status,etl_date) \n" + |
| 107 | + "COMMENT \"doris测试复合分区\" \n" + |
| 108 | + "PARTITION BY RANGE (etl_date) \n" + |
| 109 | + "( \n" + |
| 110 | + "PARTITION P1 VALUES [('2021-08-07 00:00:00'), ('2021-08-15 00:00:00')), \n" + |
| 111 | + "PARTITION P2 VALUES [('2021-08-16 00:00:00'), ('2021-08-31 00:00:00')) \n" + |
| 112 | + ") \n" + |
| 113 | + "DISTRIBUTED BY HASH(project_id,project_code) BUCKETS 3 \n" + |
| 114 | + "rollup (\n" + |
| 115 | + " r1(project_code,project_id,project_type_detail)\n" + |
| 116 | + " ) \n" + |
| 117 | + "PROPERTIES ( \n" + |
| 118 | + "\"replication_num\" = \"2\",\n" + |
| 119 | + "\"dynamic_partition.time_unit\" = \"DAY\",\n" + |
| 120 | + "\"dynamic_partition.buckets\" = \"3\",\n" + |
| 121 | + "\"dynamic_partition.end\" = \"2\",\n" + |
| 122 | + "\"dynamic_partition.prefix\" = \"P\" \n" + |
| 123 | + ") \n" + |
| 124 | + ";\n" + |
| 125 | + "\n" + |
| 126 | + "\n"; |
| 127 | + SqlScanner sqlScanner = new SqlScanner(new StringReader(sql), 0l); |
| 128 | + SqlParser sqlParser = new SqlParser(sqlScanner); |
| 129 | + List<StatementBase> multiStmts = SqlParserUtils.getMultiStmts(sqlParser); |
| 130 | + System.out.println(multiStmts.toString()); |
| 131 | + } |
| 132 | + |
| 133 | + @Test |
| 134 | + public void alterTableAddColumnTest() throws Exception { |
| 135 | + String sql = "ALTER TABLE doris_example ADD COLUMN (user_name varchar(400) NULL COMMENT \"用户名称\")"; |
| 136 | + SqlScanner sqlScanner = new SqlScanner(new StringReader(sql), 0L); |
| 137 | + SqlParser sqlParser = new SqlParser(sqlScanner); |
| 138 | + List<StatementBase> multiStmts = SqlParserUtils.getMultiStmts(sqlParser); |
| 139 | + System.out.println(multiStmts.toString()); |
| 140 | + } |
| 141 | + |
| 142 | + @Test |
| 143 | + public void alterTableModifyColumnTest() throws Exception { |
| 144 | + String sql = "ALTER TABLE doris_example MODIFY COLUMN supplier_name varchar(500) NULL COMMENT \"供应商名称\""; |
| 145 | + SqlScanner sqlScanner = new SqlScanner(new StringReader(sql), 0l); |
| 146 | + SqlParser sqlParser = new SqlParser(sqlScanner); |
| 147 | + List<StatementBase> multiStmts = SqlParserUtils.getMultiStmts(sqlParser); |
| 148 | + System.out.println(multiStmts.toString()); |
| 149 | + } |
| 150 | + |
| 151 | + @Test |
| 152 | + public void alterTableRenameTest() throws Exception { |
| 153 | + String sql = "alter table doris_example rename doris_new_example;"; |
| 154 | + SqlScanner sqlScanner = new SqlScanner(new StringReader(sql), 0l); |
| 155 | + SqlParser sqlParser = new SqlParser(sqlScanner); |
| 156 | + List<StatementBase> multiStmts = SqlParserUtils.getMultiStmts(sqlParser); |
| 157 | + System.out.println(multiStmts.toString()); |
| 158 | + } |
| 159 | +} |
| 160 | + |
| 161 | +``` |
| 162 | + |
| 163 | + |
| 164 | + |
| 165 | +4、相关 |
| 166 | + |
| 167 | +[实现](./doc/1、accomplish.md) |
0 commit comments