使用 开源代码解析器 ZGLanguage 对SQL代码进行拆解标注
# 假设存在 SQL 代码如下所示:
DROP TABLE IF EXISTS TMP_IPT.TMP_XXX_01
;
CREATE TABLE IF NOT EXISTS TMP_IPT.TMP_XXX_01
AS
with tmp1 as
(
select * from table1
UNION
select * from table2
)
, tmp2 as
(
select 'asdf' + "x" from table9
)
, tmp3 as
(
select * from table10
UNION
select * from table11
)
select *
from (select *
from (select * from table3) t1
, (select *
from (select * from table4)) t2
) t1
join table5
on 1=1
join (select * from table6
union all
select * from table7
union all
select * from table8
) t2
on 1=1
union all ---------------
select *
from (with tmp_s as(
select * from table13
)
select *
from table12 t1
, tmp_s t2
where t1.a = t2.b
) T1
;
# 通过 ZGLanguage 配置拆解标注规则如下所示:
__DEF_FUZZY__ N
__DEF_DEBUG__ N
__DEF_CASE_SENSITIVE__ N
__DEF_LINE_COMMENT__ --
__DEF_LINES_COMMENT__ /* */
__DEF_STR__ __IF_KW__
<1,100>
[1,1]ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
[0,100]ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_
__DEF_PATH__ __DROP_TABLE__
1 : cre @ | drop
: tab @ | table
: if @ CAN_SKIP | if
: exists @ CAN_SKIP | exists
1 : tartab @ | __NAME__
+ : schema @ | __NAME__
: pp @ | .
: tartab2 @ | __NAME__
1 : end @ | ;
-------------------------------------------------------------------
1 : cre @ | drop
: tab @ | table
: if @ | if
: exists @ | exists
: tartab @ | __NAME__
: schema @ | __NAME__
: pp @ \ .
: tartab2 @ \ __NAME__
: end @ | {;;;}
__DEF_PATH__ __CREATE_TABLE_SELECT__
11 : cre @ | create
: tab @ | table
: if @ CAN_SKIP | if
: not @ CAN_SKIP | not
: exists @ CAN_SKIP | exists
11 : tartab @ | __NAME__
++ : schema @ | __NAME__
: pp @ | .
: tartab2 @ | __NAME__
11 : as @ | as
: with @ CAN_SKIP | __WITH_AS_SELECT__
: sel @ | __SELECT__
0N : uni @ | __UNION_SELECT__
1 : end @ | ;
-------------------------------------------------------------------
1 : cre @ | create
: tab @ | table
: if @ | if
: not @ | not
: exists @ | exists
: tartab @ | {###}<tartab>{###}
: tartab @ \ __NAME__
: tartab @ \ {###}</tartab>{###}
: schema @ | {###}<schema>{###}
: schema @ \ __NAME__
: schema @ \ {###}</schema>{###}
: pp @ \ .
: tartab2 @ \ {###}<tartab>{###}
: tartab2 @ \ __NAME__
: tartab2 @ \ {###}</tartab>{###}
: as @ | as
: with @ | __WITH_AS_S