Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

视图中执行SQL报错,未提示具体错误原因,且该语句在davinci中正常执行 #365

Closed
Cheney1997 opened this issue Dec 14, 2021 · 9 comments
Assignees

Comments

@Cheney1997
Copy link

从davinci中的SQL语句, 修改后在datart中执行异常,页面无具体报错原因

image

日志中输出以下错误

image

@scottsut
Copy link
Contributor

scottsut commented Dec 15, 2021

请提供详细信息帮助定位问题:

  1. 操作系统
  2. 数据库及版本
  3. SQL 语句示例

@Cheney1997
Copy link
Author

1.操作系统 win11 22518.1012

2.数据库及版本 MySQL 5.7.35

3.SQL语句示例(含变量, 测试语句)

SELECT
  CASE
    WHEN (source_type < 2000) THEN 'ods'
    WHEN (source_type < 3000) THEN 'dwd'
    WHEN (source_type < 4000) THEN 'dws'
    ELSE 'ads'
  END AS warehouse_level,
  SUM(total_num) AS 'total_num',
  ROUND(SUM(total_num) + RAND(1) * SUM(total_num)) AS  'num',
  ROUND(RAND(1) * 10) AS 'delay_event_num'
FROM
  `data_monitor_statistic_template`
WHERE
  source_type % 10 != 0
  AND (
    (
      $ $ time_type $ = 1
      AND capture_day = DATE_FORMAT($ $ capture_day $, '%Y%m%d')
    )
    OR (
      $ $ time_type $ = 2
      AND INSERT(SUBSTR(capture_day, 1, 6), 5, 0, '-') = $ $ capture_month $
    )
  )
GROUP BY
  warehouse_level;

@scottsut
Copy link
Contributor

time_typecapture_month 是变量吗?

@Cheney1997
Copy link
Author

time_typecapture_month 是变量吗?

是的,还有capture_day也是变量,当我将变量去掉,换成相应的默认值, 直接执行,也是一样的报错

@scottsut
Copy link
Contributor

从 SQL 语句来看是变量语法不正确导致的。目前 SQL 美化功能还有问题,美化之后的 freemarker 语法和变量语法都不对。变量前后的$符号与变量名称之间不能有空格。

如果方便的话,可以把替换成默认值的 SQL 语句也发一下,我们定位一下是否为 SQL 解析问题

@Cheney1997
Copy link
Author

以下为替换为默认值的语句,在navicat和davinci中正常执行

SELECT
  CASE
    WHEN (source_type < 2000) THEN 'ods'
    WHEN (source_type < 3000) THEN 'dwd'
    WHEN (source_type < 4000) THEN 'dws'
    ELSE 'ads'
  END AS warehouse_level,
  SUM(total_num) AS 'total_num',
  ROUND(SUM(total_num) + RAND(1) * SUM(total_num)) AS  'num',
  ROUND(RAND(1) * 10) AS 'delay_event_num'
FROM
  `deye_data_monitor_statistic`.`data_monitor_statistic_template`
WHERE
  source_type % 10 != 0
  AND (
    (
      1 = 1
      AND capture_day = DATE_FORMAT('2021-11-30', '%Y%m%d')
    )
    OR (
      1 = 2
      AND INSERT(SUBSTR(capture_day, 1, 6), 5, 0, '-') = '2021-11'
    )
  )
GROUP BY
  warehouse_level;

@Cheney1997
Copy link
Author

从 SQL 语句来看是变量语法不正确导致的。目前 SQL 美化功能还有问题,美化之后的 freemarker 语法和变量语法都不对。变量前后的$符号与变量名称之间不能有空格。

如果方便的话,可以把替换成默认值的 SQL 语句也发一下,我们定位一下是否为 SQL 解析问题

经过定位,是INSERT函数不识别的问题,移除该函数,可以正常执行,建议修复此问题

@scottsut
Copy link
Contributor

datart 只能执行查询语句,其他的 DML 和 DDL 暂时都不计划支持

@tianlu-root
Copy link
Contributor

tianlu-root commented Dec 20, 2021

SQL中使用了 INSERT 函数,INSERT属于SQL中的保留关键字,使用这类关键字作为其它用途时,需要用符号包裹。如mysql中应该写成 `INSERT` 。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants