Skip to content

Commit bdc01a7

Browse files
authored
Merge pull request #3096 from dolthub/angela/emptystringset
Allow empty strings in set string conversions
2 parents 12ff127 + 48617cb commit bdc01a7

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

enginetest/queries/script_queries.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9764,6 +9764,8 @@ where
97649764
},
97659765
},
97669766
{
9767+
// this is failing due to a type coercion bug in comparison.Compare
9768+
// https://github.com/dolthub/dolt/issues/9510
97679769
Skip: true,
97689770
Query: "select i, s + 0, s from t where s = '';",
97699771
Expected: []sql.Row{
@@ -9773,7 +9775,6 @@ where
97739775
},
97749776
},
97759777
{
9776-
Skip: true,
97779778
Query: "select i, s + 0, s from tt;",
97789779
Expected: []sql.Row{
97799780
{0, float64(3), "something,"},

sql/types/set.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,6 @@ func (t SetType) convertBitFieldToString(bitField uint64) (string, error) {
347347
if !ok {
348348
return "", sql.ErrInvalidSetValue.New(bitField)
349349
}
350-
if len(val) == 0 {
351-
continue
352-
}
353350
if writeCommas {
354351
strBuilder.WriteByte(',')
355352
} else {
@@ -367,6 +364,7 @@ func (t SetType) convertStringToBitField(str string) (uint64, error) {
367364
return 0, nil
368365
}
369366
var bitField uint64
367+
_, allowEmptyString := t.valToBit[""]
370368
lastI := 0
371369
var val string
372370
for i := 0; i < len(str)+1; i++ {
@@ -375,7 +373,7 @@ func (t SetType) convertStringToBitField(str string) (uint64, error) {
375373
}
376374

377375
// empty string should hash to 0, so just skip
378-
if lastI == i {
376+
if lastI == i && !allowEmptyString {
379377
lastI = i + 1
380378
continue
381379
}

sql/types/set_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ func TestSetConvertToString(t *testing.T) {
272272
bit uint64
273273
expectedStr string
274274
}{
275-
{[]string{"", "a", "b", "c"}, sql.Collation_Default, 15, "a,b,c"},
275+
{[]string{"", "a", "b", "c"}, sql.Collation_Default, 15, ",a,b,c"},
276276
{[]string{"", "a", "b", "c"}, sql.Collation_Default, 14, "a,b,c"},
277277
}
278278

0 commit comments

Comments
 (0)