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

Fix soundex type #560

Merged
merged 2 commits into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sql/expression/function/soundex.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *Soundex) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
last = code
}
if b.Len() == 0 {
return "", nil
return "0000", nil
}
for i := len([]rune(b.String())); i < 4; i++ {
b.WriteRune('0')
Expand Down Expand Up @@ -98,5 +98,5 @@ func (s *Soundex) TransformUp(f sql.TransformExprFunc) (sql.Expression, error) {

// Type implements the Expression interface.
func (s *Soundex) Type() sql.Type {
return s.Child.Type()
return sql.Text
}
9 changes: 5 additions & 4 deletions sql/expression/function/soundex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func TestSoundex(t *testing.T) {
expected interface{}
}{
{"text nil", sql.Text, sql.NewRow(nil), nil},
{"text empty", sql.Text, sql.NewRow(""), ""},
{"text ignored character", sql.Text, sql.NewRow("-"), ""},
{"text empty", sql.Text, sql.NewRow(""), "0000"},
{"text ignored character", sql.Text, sql.NewRow("-"), "0000"},
{"text runes", sql.Text, sql.NewRow("日本語"), "日000"},
{"text Hello ok", sql.Text, sql.NewRow("Hello"), "H400"},
{"text Quadratically ok", sql.Text, sql.NewRow("Quadratically"), "Q36324"},
Expand All @@ -31,8 +31,9 @@ func TestSoundex(t *testing.T) {
{"text Chesley ok", sql.Text, sql.NewRow("Chesley"), "C400"},
{"text Tachenion ok", sql.Text, sql.NewRow("Tachenion"), "T250"},
{"text Wilcox ok", sql.Text, sql.NewRow("Wilcox"), "W420"},
{"binary ok", sql.Blob, sql.NewRow([]byte("Harvey")), "H610"},
{"other type", sql.Int32, sql.NewRow(int32(1)), ""},
{"binary ok", sql.Text, sql.NewRow([]byte("Harvey")), "H610"},
{"string one", sql.Text, sql.NewRow("1"), "0000"},
{"other type", sql.Text, sql.NewRow(int32(1)), "0000"},
}

for _, tt := range testCases {
Expand Down
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