Skip to content

Commit d98e42a

Browse files
elianddbclaude
andcommitted
dolthub/dolt#9426 - Expand enum string context support
Added support for LIKE pattern matching and GROUP_CONCAT aggregation with enum values. Enhanced enum conversion to strings test with comprehensive coverage. Changes: - Fixed LIKE expression to use ConvertToCollatedString for enum types - Fixed GROUP_CONCAT aggregation to use type-aware string conversion - Added comprehensive test cases for pattern matching and aggregation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 07e7247 commit d98e42a

File tree

3 files changed

+53
-14
lines changed

3 files changed

+53
-14
lines changed

enginetest/queries/script_queries.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9094,7 +9094,6 @@ where
90949094
},
90959095
Assertions: []ScriptTestAssertion{
90969096
{
9097-
// We incorrectly use the numeric values of the enum, resulting in length of 1
90989097
Query: "select e, length(e) from t order by e;",
90999098
Expected: []sql.Row{
91009099
{"abc", 3},
@@ -9103,14 +9102,39 @@ where
91039102
},
91049103
},
91059104
{
9106-
// We incorrectly use the numeric values of the enum, resulting in length of 1
91079105
Query: "select e, concat(e, 'test') from t order by e;",
91089106
Expected: []sql.Row{
91099107
{"abc", "abctest"},
91109108
{"defg", "defgtest"},
91119109
{"hjikl", "hjikltest"},
91129110
},
91139111
},
9112+
{
9113+
Query: "select e, e like 'a%', e like '%g' from t order by e;",
9114+
Expected: []sql.Row{
9115+
{"abc", true, false},
9116+
{"defg", false, true},
9117+
{"hjikl", false, false},
9118+
},
9119+
},
9120+
{
9121+
Query: "select group_concat(e order by e) as grouped from t;",
9122+
Expected: []sql.Row{
9123+
{"abc,defg,hjikl"},
9124+
},
9125+
},
9126+
{
9127+
Query: "select e from t where e = 'abc';",
9128+
Expected: []sql.Row{
9129+
{"abc"},
9130+
},
9131+
},
9132+
{
9133+
Query: "select count(*) from t where e = 'defg';",
9134+
Expected: []sql.Row{
9135+
{1},
9136+
},
9137+
},
91149138
},
91159139
},
91169140
{

sql/expression/function/aggregation/group_concat.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -271,16 +271,27 @@ func (g *groupConcatBuffer) Update(ctx *sql.Context, originalRow sql.Row) error
271271
return nil
272272
}
273273
} else {
274-
v, _, err = types.LongText.Convert(ctx, evalRow[0])
275-
if err != nil {
276-
return err
277-
}
278-
if v == nil {
279-
return nil
280-
}
281-
vs, _, err = sql.Unwrap[string](ctx, v)
282-
if err != nil {
283-
return err
274+
// Use type-aware conversion for enum types
275+
if len(g.gc.selectExprs) > 0 {
276+
vs, _, err = types.ConvertToCollatedString(ctx, evalRow[0], g.gc.selectExprs[0].Type())
277+
if err != nil {
278+
return err
279+
}
280+
if vs == "" {
281+
return nil
282+
}
283+
} else {
284+
v, _, err = types.LongText.Convert(ctx, evalRow[0])
285+
if err != nil {
286+
return err
287+
}
288+
if v == nil {
289+
return nil
290+
}
291+
vs, _, err = sql.Unwrap[string](ctx, v)
292+
if err != nil {
293+
return err
294+
}
284295
}
285296
}
286297

sql/expression/like.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,12 @@ func (l *Like) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
8686
return nil, err
8787
}
8888
if _, ok := left.(string); !ok {
89-
left, _, err = types.LongText.Convert(ctx, left)
89+
// Use type-aware conversion for enum types
90+
leftStr, _, err := types.ConvertToCollatedString(ctx, left, l.Left().Type())
9091
if err != nil {
9192
return nil, err
9293
}
94+
left = leftStr
9395
}
9496

9597
var lm LikeMatcher
@@ -138,10 +140,12 @@ func (l *Like) evalRight(ctx *sql.Context, row sql.Row) (right *string, escape r
138140
return nil, 0, err
139141
}
140142
if _, ok := rightVal.(string); !ok {
141-
rightVal, _, err = types.LongText.Convert(ctx, rightVal)
143+
// Use type-aware conversion for enum types
144+
rightStr, _, err := types.ConvertToCollatedString(ctx, rightVal, l.Right().Type())
142145
if err != nil {
143146
return nil, 0, err
144147
}
148+
rightVal = rightStr
145149
}
146150

147151
var escapeVal interface{}

0 commit comments

Comments
 (0)