为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【DM版本】:Dm8
【操作系统】:Centos7
【CPU】:
【问题描述】*:创建完视图查询视图报错语法分析错误:[42000][-2007] 第2 行附近出现错误: 语法分析出错
创建视图的sql可以执行:
set schema demo1;
create view dq_datasource_rule_view as
select t.datasource_id,
t.datasource_name,
t.database_name,
t.table_name,
t2.task_id,
t1.rule_id,
t1.rule_name,
t1.rule_dimension,
t1.rule_desc,
t1.type,
t1.level,
t1.ori_sql,
t1.source_sql,
t1.target_sql
from (
select m.datasource_id AS datasource_id,
z.name AS datasource_name,
m.database_name AS database_name,
m.table_name AS table_name,
n.rule_id AS rule_id
from demo1.dq_report m
left join (
select *
from demo1.dq_report_rule a
where rule_id is not null
) n
on m.id = n.report_id
left join demo1.dq_datasource z
on m.datasource_id = z.id
) t
left join (
select b.id AS rule_id,
b.name AS rule_name,
b.rule_dimension AS rule_dimension,
b."DESC" AS rule_desc,
b.type AS type,
b.level AS level,
if(
(b.type = 'DB'),
json_unquote(json_extract(
cast(b.datasource_params as json),
'$.sql')),
NULL) AS ori_sql,
if(
(b.type = 'DBTODB'),
json_unquote(json_extract(
cast(b.datasource_params as json),
'$.sourceSql')),
NULL) AS source_sql,
if(
(b.type = 'DBTODB'),
json_unquote(json_extract(
cast(b.datasource_params as json),
'$.targetSql')),
NULL) AS target_sql
from demo1.dq_rule_definition b
) t1
on t.rule_id = t1.rule_id
left join (
select c.task_id AS task_id,
c.rule_id AS rule_id
from demo1.dq_task_instance c
group by c.task_id, c.rule_id
) t2
on t.rule_id = t2.rule_id;
单独的sql是可以查询出结果的。
但是对创建好之后的视图进行查询则会报错:
select *
from dq_datasource_rule_view tttt
试一下,先从外联的 t1 子查询中注解掉解析json串的 ori_sql、source_sql、target_sql 三个表达式字段,然后从SELECT子句中也去掉这三列,创建视图后再查询看看是否还报这个错误。
已解决了
您的视图在我的管理工具是可以执行的
set schema demo1; create view dq_datasource_rule_view as select t.datasource_id, t.datasource_name, t.database_name, t.table_name, t2.task_id, t1.rule_id, t1.rule_name, t1.rule_dimension, t1.rule_desc, t1.type, t1.level, t1.ori_sql, t1.source_sql, t1.target_sql from ( select m.datasource_id AS datasource_id, z.name AS datasource_name, m.database_name AS database_name, m.table_name AS table_name, n.rule_id AS rule_id from demo1.dq_report m left join ( select * from demo1.dq_report_rule a where rule_id is not null ) n on m.id = n.report_id left join demo1.dq_datasource z on m.datasource_id = z.id ) t left join ( select b.id AS rule_id, b.name AS rule_name, b.rule_dimension AS rule_dimension, b."DESC" AS rule_desc, b.type AS type, b.level AS level, if( (b.type = 'DB'), json_unquote(json_extract( cast(b.datasource_params as json), '$.sql')), NULL) AS ori_sql, if( (b.type = 'DBTODB'), json_unquote(json_extract( cast(b.datasource_params as json), '$.sourceSql')), NULL) AS source_sql, if( (b.type = 'DBTODB'), json_unquote(json_extract( cast(b.datasource_params as json), '$.targetSql')), NULL) AS target_sql from demo1.dq_rule_definition b ) t1 on t.rule_id = t1.rule_id left join ( select c.task_id AS task_id, c.rule_id AS rule_id from demo1.dq_task_instance c group by c.task_id, c.rule_id ) t2 on t.rule_id = t2.rule_id; select * from dq_datasource_rule_view ttt