Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-23.1: sql: difference built-in as wrong return value type #109752

Merged
merged 1 commit into from
Aug 31, 2023
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
2 changes: 1 addition & 1 deletion docs/generated/sql/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2769,7 +2769,7 @@ The output can be used to recreate a database.’</p>
</span></td><td>Immutable</td></tr>
<tr><td><a name="decompress"></a><code>decompress(data: <a href="bytes.html">bytes</a>, codec: <a href="string.html">string</a>) &rarr; <a href="bytes.html">bytes</a></code></td><td><span class="funcdesc"><p>Decompress <code>data</code> with the specified <code>codec</code> (<code>gzip</code>, ‘lz4’, ‘snappy’, 'zstd).</p>
</span></td><td>Immutable</td></tr>
<tr><td><a name="difference"></a><code>difference(source: <a href="string.html">string</a>, target: <a href="string.html">string</a>) &rarr; <a href="string.html">string</a></code></td><td><span class="funcdesc"><p>Convert two strings to their Soundex codes and then reports the number of matching code positions.</p>
<tr><td><a name="difference"></a><code>difference(source: <a href="string.html">string</a>, target: <a href="string.html">string</a>) &rarr; <a href="int.html">int</a></code></td><td><span class="funcdesc"><p>Convert two strings to their Soundex codes and then reports the number of matching code positions.</p>
</span></td><td>Immutable</td></tr>
<tr><td><a name="encode"></a><code>encode(data: <a href="bytes.html">bytes</a>, format: <a href="string.html">string</a>) &rarr; <a href="string.html">string</a></code></td><td><span class="funcdesc"><p>Encodes <code>data</code> using <code>format</code> (<code>hex</code> / <code>escape</code> / <code>base64</code>).</p>
</span></td><td>Immutable</td></tr>
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/logictest/testdata/logic_test/fuzzystrmatch
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ SELECT soundex('hello world!')
----
H464

query TTT
query TTI
SELECT soundex('Anne'), soundex('Ann'), difference('Anne', 'Ann');
----
A500 A500 4

query TTT
query TTI
SELECT soundex('Anne'), soundex('Andrew'), difference('Anne', 'Andrew');
----
A500 A536 2

query TTT
query TTI
SELECT soundex('Anne'), soundex('Margaret'), difference('Anne', 'Margaret');
----
A500 M626 0

query TTTT
query TTTI
SELECT soundex('Anne'), soundex(NULL), difference('Anne', NULL), difference(NULL, 'Bob');
----
A500 NULL NULL NULL
5 changes: 2 additions & 3 deletions pkg/sql/sem/builtins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"math/rand"
"net"
"regexp/syntax"
"strconv"
"strings"
"time"
"unicode"
Expand Down Expand Up @@ -3809,11 +3808,11 @@ value if you rely on the HLC for accuracy.`,
tree.FunctionProperties{Category: builtinconstants.CategoryString},
tree.Overload{
Types: tree.ParamTypes{{Name: "source", Typ: types.String}, {Name: "target", Typ: types.String}},
ReturnType: tree.FixedReturnType(types.String),
ReturnType: tree.FixedReturnType(types.Int),
Fn: func(_ context.Context, _ *eval.Context, args tree.Datums) (tree.Datum, error) {
s, t := string(tree.MustBeDString(args[0])), string(tree.MustBeDString(args[1]))
diff := fuzzystrmatch.Difference(s, t)
return tree.NewDString(strconv.Itoa(diff)), nil
return tree.NewDInt(tree.DInt(diff)), nil
},
Info: "Convert two strings to their Soundex codes and then reports the number of matching code positions.",
Volatility: volatility.Immutable,
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/sem/builtins/fixed_oids.go
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ var builtinOidsArray = []string{
1234: `array_positions(array: anyenum[], elem: anyenum) -> int[]`,
1235: `array_positions(array: tuple[], elem: tuple) -> int[]`,
1236: `soundex(source: string) -> string`,
1237: `difference(source: string, target: string) -> string`,
1237: `difference(source: string, target: string) -> int`,
1238: `levenshtein(source: string, target: string) -> int`,
1239: `levenshtein(source: string, target: string, ins_cost: int, del_cost: int, sub_cost: int) -> int`,
1240: `json_remove_path(val: jsonb, path: string[]) -> jsonb`,
Expand Down