Slice with a stride and no upper bound (`arr[1: :4]`) is displayed as `arr[1::4]`, which doesn't parse

未关闭 适合新手
#2,807 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
70/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust, sql
领域
devtools

调研方向

问题出在 upper_bound 缺失但设置了 stride 时 Subscript::Slice 的输出方式。请从 src/ast/mod.rs 中的 Display 实现开始,那里的两个冒号是相邻书写的。检查解析器对 [1: :4] 和 [1:-:4] 的 slice 处理,确定哪种写法必须能够往返转换。完成的标准是:issue 中的三个复现查询都能重新解析,并且在 tests/sqlparser_common.rs 中现有 slice 测试旁边添加了一个往返转换测试。

由索引模型根据 Issue 内容生成。

描述

DuckDB Prolific Author

Subscript::Slice with upper_bound: None and a stride prints the two colons next to each other, and the tokenizer then reads :: (cast):

SELECT ([1, 2, 3, 4, 5, 6, 7, 8, 9])[1: :4]
  -> displays as: SELECT ([1, 2, 3, 4, 5, 6, 7, 8, 9])[1::4]
  -> reparse: Expected: a data type name, found: 4 at Line: 1, Column: 41
SELECT ([1, 2, 3, 4, 5, 6, 7, 8, 9])[: :4]
  -> displays as: SELECT ([1, 2, 3, 4, 5, 6, 7, 8, 9])[::4]
  -> reparse: Expected: an expression, found: :: at Line: 1, Column: 38
SELECT ([1, 2, 3, 4, 5, 6, 7, 8, 9])[1:-:4]
  -> round-trips (fine)

DuckDB documents [1:-:4] for this (https://duckdb.org/docs/stable/sql/functions/list#slicing), but it also runs [1: :4] (returns [1, 5, 9]), and the parser accepts it. Something like [1: :4] in Display would round-trip.

Tested with DuckDbDialect on main ce12f1f6 (also 0.63.0 and 0.58.0).

Found with a property-based fuzzer (round trip check); I used AI assistance for triage and verified every case above.

主要语言
Rust
星标
3.5k
派生
801
平均合并
2 天 19 小时
30 天内合并 PR
108

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/datafusion-sqlparser-rs 的其他 Issue

查看 apache/datafusion-sqlparser-rs 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。