Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit b45503e

Browse files
authored
Merge pull request #560 from ajnavarro/fix-soundex-type
Fix soundex type
2 parents 2e4eb83 + 2a888c8 commit b45503e

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

sql/expression/function/soundex.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (s *Soundex) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
5757
last = code
5858
}
5959
if b.Len() == 0 {
60-
return "", nil
60+
return "0000", nil
6161
}
6262
for i := len([]rune(b.String())); i < 4; i++ {
6363
b.WriteRune('0')
@@ -98,5 +98,5 @@ func (s *Soundex) TransformUp(f sql.TransformExprFunc) (sql.Expression, error) {
9898

9999
// Type implements the Expression interface.
100100
func (s *Soundex) Type() sql.Type {
101-
return s.Child.Type()
101+
return sql.Text
102102
}

sql/expression/function/soundex_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ func TestSoundex(t *testing.T) {
1616
expected interface{}
1717
}{
1818
{"text nil", sql.Text, sql.NewRow(nil), nil},
19-
{"text empty", sql.Text, sql.NewRow(""), ""},
20-
{"text ignored character", sql.Text, sql.NewRow("-"), ""},
19+
{"text empty", sql.Text, sql.NewRow(""), "0000"},
20+
{"text ignored character", sql.Text, sql.NewRow("-"), "0000"},
2121
{"text runes", sql.Text, sql.NewRow("日本語"), "日000"},
2222
{"text Hello ok", sql.Text, sql.NewRow("Hello"), "H400"},
2323
{"text Quadratically ok", sql.Text, sql.NewRow("Quadratically"), "Q36324"},
@@ -31,8 +31,9 @@ func TestSoundex(t *testing.T) {
3131
{"text Chesley ok", sql.Text, sql.NewRow("Chesley"), "C400"},
3232
{"text Tachenion ok", sql.Text, sql.NewRow("Tachenion"), "T250"},
3333
{"text Wilcox ok", sql.Text, sql.NewRow("Wilcox"), "W420"},
34-
{"binary ok", sql.Blob, sql.NewRow([]byte("Harvey")), "H610"},
35-
{"other type", sql.Int32, sql.NewRow(int32(1)), ""},
34+
{"binary ok", sql.Text, sql.NewRow([]byte("Harvey")), "H610"},
35+
{"string one", sql.Text, sql.NewRow("1"), "0000"},
36+
{"other type", sql.Text, sql.NewRow(int32(1)), "0000"},
3637
}
3738

3839
for _, tt := range testCases {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy