Skip to content

Commit 06941ed

Browse files
committed
Use Decimal.String() for hashkey in hashjoin lookups
1 parent 0cab8e8 commit 06941ed

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

enginetest/join_op_tests.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,6 +2046,26 @@ WHERE
20462046
},
20472047
},
20482048
},
2049+
{
2050+
name: "join with % condition",
2051+
setup: [][]string{
2052+
{
2053+
"create table t1(c0 int)",
2054+
"create table t2(c0 int)",
2055+
"insert into t1 values (1),(2)",
2056+
"insert into t2 values (3),(4)",
2057+
},
2058+
},
2059+
tests: []JoinOpTests{
2060+
{
2061+
Query: `select * from t1 join t2 on (t1.c0 % 2) = (t2.c0 % 2)`,
2062+
Expected: []sql.Row{
2063+
{1, 3},
2064+
{2, 4},
2065+
},
2066+
},
2067+
},
2068+
},
20492069
}
20502070

20512071
var rangeJoinOpTests = []JoinOpTests{

sql/plan/hash_lookup.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package plan
1616

1717
import (
1818
"fmt"
19+
"github.com/shopspring/decimal"
1920
"sync"
2021

2122
"github.com/dolthub/go-mysql-server/sql"
@@ -137,6 +138,10 @@ func (n *HashLookup) GetHashKey(ctx *sql.Context, e sql.Expression, row sql.Row)
137138
if k, ok := key.([]byte); ok {
138139
key = string(k)
139140
}
141+
// decimals are not hashable
142+
if d, ok := key.(decimal.Decimal); ok {
143+
key = d.String()
144+
}
140145
return key, nil
141146
}
142147

0 commit comments

Comments
 (0)