Skip to content

Conversation

@qian0817
Copy link

Both sql
SELECT brand, size, sum(sales) FROM items_sold GROUP BY brand, size, GROUPING SETS ((brand), (size), ());
and
SELECT brand, size, sum(sales) FROM items_sold GROUP BY brand, size GROUPING SETS ((brand), (size), ());
is allowed in many dbms like hive,spark,odps. we need to support them.

@CLAassistant
Copy link

CLAassistant commented Apr 15, 2025

CLA assistant check
All committers have signed the CLA.

@wenshao wenshao requested a review from lingo-xp May 8, 2025 01:28
}

public boolean isGroupingSetsHaveComma() {
return groupingSetsHaveComma;

Choose a reason for hiding this comment

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

将“是否有逗号”作为 group by 子句的一个属性,虽然能解决当前需求,但这种语法细节直接暴露在 AST 层,可能导致后续 AST 结构膨胀,不利于维护和扩展。
建议:
逗号本质是语法格式,建议在 Visitor 层处理,而不是 AST 层增加属性。AST 层应只表达语义,不表达格式细节。

item.addBeforeComment(comments);
}
if (item instanceof SQLGroupingSetExpr && hasComma) {
groupBy.setGroupingSetsHaveComma(true);

Choose a reason for hiding this comment

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

解析器通过 hasComma 标记逗号出现,进而设置 groupBy 的属性。这种做法会导致解析器和 AST 之间耦合过高,且对复杂 SQL(如嵌套、注释、换行)可能不够健壮。

println();
}
} else {
println(',');

Choose a reason for hiding this comment

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

Visitor 层根据 AST 属性决定是否输出逗号,导致 Visitor 依赖 AST 的格式属性,违背了 AST 只表达语义的设计原则。

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.

3 participants