Skip to content

Commit 0fca011

Browse files
committed
add tests
1 parent e30d14d commit 0fca011

File tree

6 files changed

+250
-130
lines changed

6 files changed

+250
-130
lines changed

enginetest/memory_engine_test.go

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -203,68 +203,19 @@ func TestSingleScript(t *testing.T) {
203203
t.Skip()
204204
var scripts = []queries.ScriptTest{
205205
{
206-
// https://github.com/dolthub/dolt/issues/9916
207-
Name: "TRUNCATE(X,D) function behavior",
206+
Name: "AS OF propagates to nested CALLs",
208207
SetUpScript: []string{},
209208
Assertions: []queries.ScriptTestAssertion{
210209
{
211-
Query: "SELECT TRUNCATE(1.223,1)",
210+
Query: "create procedure create_proc() create table t (i int primary key, j int);",
212211
Expected: []sql.Row{
213-
{"1.2"},
212+
{types.NewOkResult(0)},
214213
},
215214
},
216215
{
217-
Query: "SELECT TRUNCATE(1.999,1)",
216+
Query: "call create_proc()",
218217
Expected: []sql.Row{
219-
{"1.9"},
220-
},
221-
},
222-
{
223-
Query: "SELECT TRUNCATE(1.999,0)",
224-
Expected: []sql.Row{
225-
{"1"},
226-
},
227-
},
228-
{
229-
Query: "SELECT TRUNCATE(-1.999,1)",
230-
Expected: []sql.Row{
231-
{"-1.9"},
232-
},
233-
},
234-
{
235-
Query: "SELECT TRUNCATE(122,-2)",
236-
Expected: []sql.Row{
237-
{100},
238-
},
239-
},
240-
{
241-
Query: "SELECT TRUNCATE(10.28*100,0)",
242-
Expected: []sql.Row{
243-
{"1028"},
244-
},
245-
},
246-
{
247-
Query: "SELECT TRUNCATE(NULL,1)",
248-
Expected: []sql.Row{
249-
{nil},
250-
},
251-
},
252-
{
253-
Query: "SELECT TRUNCATE(1.223,NULL)",
254-
Expected: []sql.Row{
255-
{nil},
256-
},
257-
},
258-
{
259-
Query: "SELECT TRUNCATE(0.5,0)",
260-
Expected: []sql.Row{
261-
{"0"},
262-
},
263-
},
264-
{
265-
Query: "SELECT TRUNCATE(-0.5,0)",
266-
Expected: []sql.Row{
267-
{"0"},
218+
{types.NewOkResult(0)},
268219
},
269220
},
270221
},

enginetest/queries/script_queries.go

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,208 @@ type ScriptTestAssertion struct {
122122
// Unlike other engine tests, ScriptTests must be self-contained. No other tables are created outside the definition of
123123
// the tests.
124124
var ScriptTests = []ScriptTest{
125+
{
126+
// https://github.com/dolthub/dolt/issues/9916
127+
Name: "TRUNCATE(X,D) function behavior",
128+
SetUpScript: []string{},
129+
Assertions: []ScriptTestAssertion{
130+
{
131+
Query: "SELECT TRUNCATE(1.223,1)",
132+
Expected: []sql.Row{
133+
{"1.2"},
134+
},
135+
},
136+
{
137+
Query: "SELECT TRUNCATE(1.999,1)",
138+
Expected: []sql.Row{
139+
{"1.9"},
140+
},
141+
},
142+
{
143+
Query: "SELECT TRUNCATE(1.999,0)",
144+
Expected: []sql.Row{
145+
{"1"},
146+
},
147+
},
148+
{
149+
Query: "SELECT TRUNCATE(-1.999,1)",
150+
Expected: []sql.Row{
151+
{"-1.9"},
152+
},
153+
},
154+
{
155+
Query: "SELECT TRUNCATE(122,-2)",
156+
Expected: []sql.Row{
157+
{100},
158+
},
159+
},
160+
{
161+
Query: "SELECT TRUNCATE(10.28*100,0)",
162+
Expected: []sql.Row{
163+
{"1028"},
164+
},
165+
},
166+
{
167+
Query: "SELECT TRUNCATE(NULL,1)",
168+
Expected: []sql.Row{
169+
{nil},
170+
},
171+
},
172+
{
173+
Query: "SELECT TRUNCATE(1.223,NULL)",
174+
Expected: []sql.Row{
175+
{nil},
176+
},
177+
},
178+
{
179+
Query: "SELECT TRUNCATE(0.5,0)",
180+
Expected: []sql.Row{
181+
{"0"},
182+
},
183+
},
184+
{
185+
Query: "SELECT TRUNCATE(-0.5,0)",
186+
Expected: []sql.Row{
187+
{"0"},
188+
},
189+
},
190+
{
191+
Query: "SELECT TRUNCATE(1.223,100)",
192+
Expected: []sql.Row{
193+
{"1.223"},
194+
},
195+
},
196+
{
197+
Query: "SELECT TRUNCATE(1.223,-100)",
198+
Expected: []sql.Row{
199+
{"0"},
200+
},
201+
},
202+
{
203+
Query: "SELECT TRUNCATE('abc',1)",
204+
Expected: []sql.Row{
205+
{0.0},
206+
},
207+
},
208+
{
209+
Query: "SELECT TRUNCATE(1.223,'xyz')",
210+
Expected: []sql.Row{
211+
{"1"},
212+
},
213+
},
214+
{
215+
Query: "SELECT TRUNCATE(1.223,1.5)",
216+
Expected: []sql.Row{
217+
{"1.22"},
218+
},
219+
},
220+
{
221+
Query: "SELECT TRUNCATE(1.223,1.7)",
222+
Expected: []sql.Row{
223+
{"1.22"},
224+
},
225+
},
226+
{
227+
Query: "SELECT TRUNCATE(1.223,0.1)",
228+
Expected: []sql.Row{
229+
{"1"},
230+
},
231+
},
232+
{
233+
Query: "SELECT TRUNCATE(1.223,0.9)",
234+
Expected: []sql.Row{
235+
{"1.2"},
236+
},
237+
},
238+
{
239+
Query: "SELECT TRUNCATE(1.223,-0.5)",
240+
Expected: []sql.Row{
241+
{"0"},
242+
},
243+
},
244+
{
245+
Query: "SELECT TRUNCATE(1.223,-0.9)",
246+
Expected: []sql.Row{
247+
{"0"},
248+
},
249+
},
250+
{
251+
Query: "SELECT TRUNCATE('123abc',1)",
252+
Expected: []sql.Row{
253+
{123.0},
254+
},
255+
ExpectedWarning: mysql.ERTruncatedWrongValue,
256+
ExpectedWarningsCount: 1,
257+
ExpectedWarningMessageSubstring: "Truncated incorrect DOUBLE value",
258+
},
259+
{
260+
Query: "SELECT TRUNCATE('1.5abc',1)",
261+
Expected: []sql.Row{
262+
{1.5},
263+
},
264+
ExpectedWarning: mysql.ERTruncatedWrongValue,
265+
ExpectedWarningsCount: 1,
266+
ExpectedWarningMessageSubstring: "Truncated incorrect DOUBLE value",
267+
},
268+
{
269+
Query: "SELECT TRUNCATE('999xyz',2)",
270+
Expected: []sql.Row{
271+
{999.0},
272+
},
273+
ExpectedWarning: mysql.ERTruncatedWrongValue,
274+
ExpectedWarningsCount: 1,
275+
ExpectedWarningMessageSubstring: "Truncated incorrect DOUBLE value",
276+
},
277+
{
278+
Query: "SELECT TRUNCATE(1.223,'1.5abc')",
279+
Expected: []sql.Row{
280+
{"1.2"},
281+
},
282+
ExpectedWarning: mysql.ERTruncatedWrongValue,
283+
ExpectedWarningsCount: 2, // Both input and precision conversions generate warnings
284+
ExpectedWarningMessageSubstring: "Truncated incorrect int value",
285+
},
286+
{
287+
Query: "SELECT TRUNCATE(1.223,'0.5')",
288+
Expected: []sql.Row{
289+
{"1"},
290+
},
291+
ExpectedWarning: mysql.ERTruncatedWrongValue,
292+
ExpectedWarningsCount: 2, // Both input and precision conversions generate warnings
293+
ExpectedWarningMessageSubstring: "Truncated incorrect int value",
294+
},
295+
{
296+
Query: "SELECT TRUNCATE(1.223,'2.7')",
297+
Expected: []sql.Row{
298+
{"1.22"},
299+
},
300+
ExpectedWarning: mysql.ERTruncatedWrongValue,
301+
ExpectedWarningsCount: 2, // Both input and precision conversions generate warnings
302+
ExpectedWarningMessageSubstring: "Truncated incorrect int value",
303+
},
304+
{
305+
Query: "SELECT TRUNCATE(1.223,'invalid_precision')",
306+
Expected: []sql.Row{
307+
{"1"},
308+
},
309+
ExpectedWarning: mysql.ERTruncatedWrongValue,
310+
ExpectedWarningsCount: 2, // Both input and precision conversions generate warnings
311+
ExpectedWarningMessageSubstring: "Truncated incorrect int value",
312+
},
313+
{
314+
Query: "SELECT TRUNCATE()",
315+
ExpectedErrStr: "syntax error",
316+
},
317+
{
318+
Query: "SELECT TRUNCATE(1)",
319+
ExpectedErrStr: "syntax error",
320+
},
321+
{
322+
Query: "SELECT TRUNCATE(1,2,3)",
323+
ExpectedErrStr: "syntax error",
324+
},
325+
},
326+
},
125327
{
126328
// https://github.com/dolthub/dolt/issues/9873
127329
// TODO: `FOR UPDATE OF` (`FOR UPDATE` in general) is currently a no-op: https://www.dolthub.com/blog/2023-10-23-hold-my-beer/

sql/expression/function/ceil_round_floor.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,19 @@ import (
2929
// numericRetType returns the appropriate return type for numeric functions
3030
// like ROUND() and TRUNCATE() according to MySQL specification:
3131
// Integer types return BIGINT
32-
// Floating-point types or non-numeric types return DOUBLE
32+
// Floating-point types or non-numeric types return DOUBLE
3333
// DECIMAL values return DECIMAL
3434
func numericRetType(inputType sql.Type) sql.Type {
3535
if types.IsSigned(inputType) || types.IsUnsigned(inputType) {
36-
return types.Int64 // BIGINT
36+
return types.Int64
3737
} else if types.IsFloat(inputType) {
38-
return types.Float64 // DOUBLE
38+
return types.Float64
3939
} else if types.IsDecimal(inputType) {
40-
return inputType // DECIMAL (same type)
40+
return inputType
4141
} else if types.IsTextBlob(inputType) {
4242
return types.Float64 // DOUBLE for non-numeric types
4343
}
44-
45-
// Default fallback
44+
4645
return types.Float64
4746
}
4847

sql/expression/function/registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ var BuiltIns = []sql.Function{
333333
sql.FunctionN{Name: "distance", Fn: vector.NewGenericDistance},
334334
sql.Function1{Name: "string_to_vector", Fn: vector.NewStringToVector},
335335
sql.Function1{Name: "to_vector", Fn: vector.NewStringToVector},
336-
sql.FunctionN{Name: "truncate", Fn: NewTruncate},
336+
sql.Function2{Name: "truncate", Fn: NewTruncate},
337337
sql.Function1{Name: "vec_fromtext", Fn: vector.NewStringToVector},
338338
sql.Function1{Name: "vector_to_string", Fn: vector.NewVectorToString},
339339
sql.Function1{Name: "from_vector", Fn: vector.NewVectorToString},

0 commit comments

Comments
 (0)