Skip to content

[Bug]: 不完整的多个 union all 导致溢出 #454

@iGarym

Description

@iGarym

Version

v4.3.1

Which SQL?

Spark

SQL content

select
  market,
  from_unixtime (
    unix_timestamp (cast(`date` as string), 'yyyyMMdd'),
    'yyyy-MM-dd'
  ) as prev_trade_date,
  row_number() over (
    partition by
      market
    order by
      `date` desc
  ) as rn
FROM
  (
    SELECT
      'US' AS market,
      '20251128' AS `date`
    UNION ALL
    SELECT
      'US' AS market,
      '20251127' AS `date`
    UNION ALL
    SELECT
      'US' AS market,
      '20251126' AS `date`
    UNION ALL
    SELECT
      'US' AS market,
      '20251125' AS `date`
    UNION ALL
    SELECT
      'US' AS market,
      '20251124' AS `date`
    UNION ALL
    SELECT
      'US' AS market,
      '20251123' AS `date`
    UNION ALL
    SELECT
      'US' AS market,
      '20251122' AS `date`
    UNION ALL
    SELECT
      'US' AS market,
      '20251121' AS `date`
    UNION ALL
    SELECT
      'US' AS market,
      '20251120' AS `date`
    UNION ALL
    SELECT
      'US' AS market,
      '20251119' AS `date`
    UNION ALL
    SELECT
      'US' AS market,
      '20251118' AS `date`
    UNION ALL
    SELECT
      'US' AS market,
      '20251117' AS `date`
    UNION ALL
    SELECT
      'US' AS market,
      '20251116' AS `date`
    UNION ALL
    SELECT
      'US' AS market,
      '20251115' AS `date`
    UNION ALL
    SELECT
      'US' AS market,
      '20251114' AS `date`
    UNION ALL
    SELECT
      'US' AS market,
      '20251113' AS `date`
    UNION ALL -- 这里需要带上一个多余的 UNION ALL
  ) a
where
  `date` >= cast(
    date_format (date_sub ('20251127', 60), 'yyyyMMdd') as bigint
  )
  and `date` < cast(
    date_format ('20251127', 'yyyyMMdd') as bigint
  );

JavaScript/TypeScript code

import { SparkSQL } from 'dt-sql-parser';


const sparksql = new SparkSQL();

const start = Date.now()

spark.validate(sql)

const end = Date.now()
console.log(`Time taken: ${end - start}ms`)

What happened?

校验上述 sparksql,validate 函数执行耗时异常;继续增加几个以下代码片段后代码执行溢出。

SELECT
 'US' AS market,
 '20251113' AS `date`
UNION ALL

初步定位是 src/lib/spark/SparkSqlParser.ts 文件 L818 这行代码的问题

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions