Skip to content

Conversation

@zchazc
Copy link

@zchazc zchazc commented Jun 20, 2025

看了下 wiki 的“如何参与”,貌似可以直接提 PR ,我就提了,一个有关于 oracle using_index_clause 小的语法解析支持。详见 issue #6458

using.setIndex(createIndex);
accept(Token.RPAREN);
} else if (lexer.token() == Token.LITERAL_ALIAS) {
SQLName index = new OracleStatementParser(lexer).getExprParser().name();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if分支不够健壮,可能还有IDENTIFIER 或其他 token,建议补充其他情况使用else if
直接用 OracleStatementParser(lexer).getExprParser().name() 解析 index 名称,可能会影响 lexer 状态,建议复用当前 parser 实例,避免新建对象导致上下文丢失。
没有进行异常处理,建议补充异常处理和日志



@Test
public void testUsingIndex() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只测试了 index 名称为 "SC"."PK_XXX" 的场景,未覆盖 index 名为普通标识符、带 storage/tablespace、无 index 名等边界情况。
没有负面测试(如语法错误、异常分支)

只断言了 SQL 还原,未断言 AST 结构是否正确解析 index 名称。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"带 storage/tablespace" 指的是图例中的 schema 吗?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"带 storage/tablespace" 指的是图例中的 schema 吗?

storage/tablespace指定索引的物理存储位置的 TABLESPACE 子句,用于管理数据的物理存储位置和特性。比如,CREATE INDEX idx_name ON table_name (column_name) TABLESPACE tablespace_name;
感谢您的回复,这个范围更小一点,只是其中一个具体的物理存储属性。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 根据图例来看,using_index_clause 有三个分支。
  • 我这边添加的是最上直接指定 (schema.)index 的分支。
  • 中间的分支create_index 已经实现了,最下的分支是 index_properties 。
  • 继续查询图例得知 “带 storage/tablespace” 属于 index_attributes, index_properties 包含 index_attributes , create_index 包含 index_properties。

所以您的意思是让我将最下面第三个分支 index_properties 也同时实现吗?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我将除 index_properties 以外的其它内容处理了,不知道是否符合您的要求。

  • "未断言 AST 结构是否正确解析 index 名称" 的原因是因为我参考了其它的单元测试,不太清楚我这样写是否合适。
  • 有关于 index_properties,我认为需要像 com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleUsingIndexClause 做独立实现,来确保被可以被其它地方复用,这个坑有点儿多,因为我看到后续有很多类似的语句都没有独立实现,所以短时间内没办法做到。

1. add identifier support and unit test.
2. add parsing exception and unit test.
3. reuse current parser to parse name.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants