Skip to content

Commit 2a57a5f

Browse files
authored
Add CODEC/compression expression support in EXPLAIN output (#86)
1 parent fec9a6b commit 2a57a5f

File tree

62 files changed

+85
-300
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+85
-300
lines changed

internal/explain/explain.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ func Column(sb *strings.Builder, col *ast.ColumnDeclaration, depth int) {
197197
if col.Default != nil || hasEphemeralDefault {
198198
children++
199199
}
200+
if col.Codec != nil {
201+
children++
202+
}
200203
fmt.Fprintf(sb, "%sColumnDeclaration %s (children %d)\n", indent, col.Name, children)
201204
if col.Type != nil {
202205
Node(sb, col.Type, depth+1)
@@ -207,6 +210,34 @@ func Column(sb *strings.Builder, col *ast.ColumnDeclaration, depth int) {
207210
// EPHEMERAL columns without explicit default value show defaultValueOfTypeName function
208211
fmt.Fprintf(sb, "%s Function defaultValueOfTypeName\n", indent)
209212
}
213+
if col.Codec != nil {
214+
explainCodecExpr(sb, col.Codec, indent+" ", depth+1)
215+
}
216+
}
217+
218+
// explainCodecExpr handles CODEC expressions in column declarations
219+
func explainCodecExpr(sb *strings.Builder, codec *ast.CodecExpr, indent string, depth int) {
220+
// CODEC is rendered as a Function with one child (ExpressionList of codecs)
221+
fmt.Fprintf(sb, "%sFunction CODEC (children 1)\n", indent)
222+
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, len(codec.Codecs))
223+
for _, c := range codec.Codecs {
224+
explainCodecFunction(sb, c, indent+" ", depth+2)
225+
}
226+
}
227+
228+
// explainCodecFunction handles individual codec functions (e.g., LZ4, ZSTD(10), Gorilla(1))
229+
func explainCodecFunction(sb *strings.Builder, fn *ast.FunctionCall, indent string, depth int) {
230+
if len(fn.Arguments) == 0 {
231+
// Codec without parameters: just the function name
232+
fmt.Fprintf(sb, "%sFunction %s\n", indent, fn.Name)
233+
} else {
234+
// Codec with parameters: function with ExpressionList of arguments
235+
fmt.Fprintf(sb, "%sFunction %s (children 1)\n", indent, fn.Name)
236+
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, len(fn.Arguments))
237+
for _, arg := range fn.Arguments {
238+
Node(sb, arg, depth+2)
239+
}
240+
}
210241
}
211242

212243
func Index(sb *strings.Builder, idx *ast.IndexDefinition, depth int) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"explain_todo":{"stmt2":true}}
1+
{}

parser/testdata/00804_test_alter_compression_codecs/metadata.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,8 @@
55
"stmt20": true,
66
"stmt21": true,
77
"stmt27": true,
8-
"stmt3": true,
9-
"stmt30": true,
10-
"stmt31": true,
11-
"stmt32": true,
12-
"stmt36": true,
138
"stmt41": true,
149
"stmt43": true,
15-
"stmt7": true,
1610
"stmt8": true
1711
}
1812
}
Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt22": true,
4-
"stmt23": true,
5-
"stmt24": true,
6-
"stmt25": true,
7-
"stmt26": true,
8-
"stmt27": true,
9-
"stmt28": true,
10-
"stmt38": true,
11-
"stmt4": true,
12-
"stmt49": true,
13-
"stmt50": true,
14-
"stmt58": true,
15-
"stmt69": true
16-
}
17-
}
1+
{}
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt16": true,
4-
"stmt28": true,
5-
"stmt4": true,
6-
"stmt40": true
7-
}
8-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt4": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
{
22
"explain_todo": {
33
"stmt12": true,
4-
"stmt18": true,
5-
"stmt19": true,
64
"stmt20": true,
75
"stmt24": true,
8-
"stmt30": true,
9-
"stmt31": true,
10-
"stmt36": true,
11-
"stmt5": true,
12-
"stmt6": true
6+
"stmt36": true
137
}
148
}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
{"explain_todo":{"stmt4":true,"stmt5":true,"stmt6":true,"stmt7":true,"stmt8":true,"stmt9":true}}
1+
{
2+
"explain_todo": {
3+
"stmt5": true,
4+
"stmt6": true,
5+
"stmt7": true,
6+
"stmt9": true
7+
}
8+
}
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt4": true,
4-
"stmt5": true,
5-
"stmt6": true
6-
}
7-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt2": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)