Skip to content

Commit 786f3a1

Browse files
author
James Cor
committed
check for error
1 parent a1a954b commit 786f3a1

File tree

1 file changed

+58
-88
lines changed

1 file changed

+58
-88
lines changed

sql/hash/hash.go

Lines changed: 58 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -69,101 +69,71 @@ func HashOf(ctx *sql.Context, sch sql.Schema, row sql.Row) (uint64, error) {
6969

7070
// TODO: we may not always have the type information available, so we check schema length.
7171
// Then, defer to original behavior
72-
if i >= len(sch) {
73-
switch v := v.(type) {
74-
case int:
75-
hash.WriteString(strconv.FormatInt(int64(v), 10))
76-
case int8:
77-
hash.WriteString(strconv.FormatInt(int64(v), 10))
78-
case int16:
79-
hash.WriteString(strconv.FormatInt(int64(v), 10))
80-
case int32:
81-
hash.WriteString(strconv.FormatInt(int64(v), 10))
82-
case int64:
83-
hash.WriteString(strconv.FormatInt(v, 10))
84-
case uint:
85-
hash.WriteString(strconv.FormatUint(uint64(v), 10))
86-
case uint8:
87-
hash.WriteString(strconv.FormatUint(uint64(v), 10))
88-
case uint16:
89-
hash.WriteString(strconv.FormatUint(uint64(v), 10))
90-
case uint32:
91-
hash.WriteString(strconv.FormatUint(uint64(v), 10))
92-
case uint64:
93-
hash.WriteString(strconv.FormatUint(v, 10))
94-
case float32:
95-
str := strconv.FormatFloat(float64(v), 'f', -1, 32)
96-
if str == "-0" {
97-
str = "0"
72+
if i < len(sch) {
73+
switch typ := sch[i].Type.(type) {
74+
case sql.ExtendedType:
75+
// TODO: Doltgres follows Postgres conventions which don't align with the expectations of MySQL,
76+
// so we're using the old (probably incorrect) behavior for now
77+
_, err := hash.WriteString(fmt.Sprintf("%v", v))
78+
if err != nil {
79+
return 0, err
9880
}
99-
hash.WriteString(str)
100-
case float64:
101-
str := strconv.FormatFloat(v, 'f', -1, 64)
102-
if str == "-0" {
103-
str = "0"
81+
continue
82+
case types.StringType:
83+
var strVal string
84+
strVal, err = types.ConvertToString(ctx, v, typ, nil)
85+
if err != nil {
86+
return 0, err
10487
}
105-
hash.WriteString(str)
106-
default:
107-
hash.WriteString(fmt.Sprintf("%v", v))
88+
err = typ.Collation().WriteWeightString(hash, strVal)
89+
if err != nil {
90+
return 0, err
91+
}
92+
continue
10893
}
109-
continue
11094
}
111-
112-
switch typ := sch[i].Type.(type) {
113-
case sql.ExtendedType:
114-
// TODO: Doltgres follows Postgres conventions which don't align with the expectations of MySQL,
115-
// so we're using the old (probably incorrect) behavior for now
116-
_, err = fmt.Fprintf(hash, "%v", v)
117-
if err != nil {
118-
return 0, err
119-
}
120-
case types.StringType:
121-
var strVal string
122-
strVal, err = types.ConvertToString(ctx, v, typ, nil)
123-
if err != nil {
124-
return 0, err
95+
switch v := v.(type) {
96+
case int:
97+
_, err = hash.WriteString(strconv.FormatInt(int64(v), 10))
98+
case int8:
99+
_, err = hash.WriteString(strconv.FormatInt(int64(v), 10))
100+
case int16:
101+
_, err = hash.WriteString(strconv.FormatInt(int64(v), 10))
102+
case int32:
103+
_, err = hash.WriteString(strconv.FormatInt(int64(v), 10))
104+
case int64:
105+
_, err = hash.WriteString(strconv.FormatInt(v, 10))
106+
case uint:
107+
_, err = hash.WriteString(strconv.FormatUint(uint64(v), 10))
108+
case uint8:
109+
_, err = hash.WriteString(strconv.FormatUint(uint64(v), 10))
110+
case uint16:
111+
_, err = hash.WriteString(strconv.FormatUint(uint64(v), 10))
112+
case uint32:
113+
_, err = hash.WriteString(strconv.FormatUint(uint64(v), 10))
114+
case uint64:
115+
_, err = hash.WriteString(strconv.FormatUint(v, 10))
116+
case float32:
117+
str := strconv.FormatFloat(float64(v), 'f', -1, 32)
118+
if str == "-0" {
119+
str = "0"
125120
}
126-
err = typ.Collation().WriteWeightString(hash, strVal)
127-
if err != nil {
128-
return 0, err
121+
_, err = hash.WriteString(str)
122+
case float64:
123+
str := strconv.FormatFloat(v, 'f', -1, 64)
124+
if str == "-0" {
125+
str = "0"
129126
}
127+
_, err = hash.WriteString(str)
128+
case string:
129+
_, err = hash.WriteString(v)
130+
case []byte:
131+
_, err = hash.Write(v)
130132
default:
131-
switch v := v.(type) {
132-
case int:
133-
hash.WriteString(strconv.FormatInt(int64(v), 10))
134-
case int8:
135-
hash.WriteString(strconv.FormatInt(int64(v), 10))
136-
case int16:
137-
hash.WriteString(strconv.FormatInt(int64(v), 10))
138-
case int32:
139-
hash.WriteString(strconv.FormatInt(int64(v), 10))
140-
case int64:
141-
hash.WriteString(strconv.FormatInt(v, 10))
142-
case uint:
143-
hash.WriteString(strconv.FormatUint(uint64(v), 10))
144-
case uint8:
145-
hash.WriteString(strconv.FormatUint(uint64(v), 10))
146-
case uint16:
147-
hash.WriteString(strconv.FormatUint(uint64(v), 10))
148-
case uint32:
149-
hash.WriteString(strconv.FormatUint(uint64(v), 10))
150-
case uint64:
151-
hash.WriteString(strconv.FormatUint(v, 10))
152-
case float32:
153-
str := strconv.FormatFloat(float64(v), 'f', -1, 32)
154-
if str == "-0" {
155-
str = "0"
156-
}
157-
hash.WriteString(str)
158-
case float64:
159-
str := strconv.FormatFloat(v, 'f', -1, 64)
160-
if str == "-0" {
161-
str = "0"
162-
}
163-
hash.WriteString(str)
164-
default:
165-
hash.WriteString(fmt.Sprintf("%v", v))
166-
}
133+
_, err = hash.WriteString(fmt.Sprintf("%v", v))
134+
}
135+
if err != nil {
136+
return 0, err
167137
}
168138
}
169139
return hash.Sum64(), nil

0 commit comments

Comments
 (0)