@@ -29,15 +29,15 @@ def test_name_setter
2929
3030 def test_return_type_setter
3131 sf = DuckDB ::ScalarFunction . new
32- logical_type = DuckDB ::LogicalType . new ( 4 ) # DUCKDB_TYPE_INTEGER
32+ logical_type = DuckDB ::LogicalType :: INTEGER
3333 sf . return_type = logical_type
3434
3535 assert_instance_of DuckDB ::ScalarFunction , sf
3636 end
3737
3838 def test_return_type_setter_raises_error_for_unsupported_type
3939 sf = DuckDB ::ScalarFunction . new
40- interval_type = DuckDB ::LogicalType . new ( 15 ) # DUCKDB_TYPE_INTERVAL (unsupported)
40+ interval_type = DuckDB ::LogicalType :: INTERVAL # Unsupported type for testing
4141
4242 error = assert_raises ( DuckDB ::Error ) do
4343 sf . return_type = interval_type
@@ -60,7 +60,7 @@ def test_register_scalar_function
6060
6161 sf = DuckDB ::ScalarFunction . new
6262 sf . name = 'foo'
63- sf . return_type = DuckDB ::LogicalType . new ( 4 ) # INTEGER
63+ sf . return_type = DuckDB ::LogicalType :: INTEGER
6464 sf . set_function { 1 }
6565
6666 @con . register_scalar_function ( sf )
@@ -73,7 +73,7 @@ def test_register_scalar_function
7373 def test_register_scalar_function_raises_error_without_single_thread
7474 sf = DuckDB ::ScalarFunction . new
7575 sf . name = 'will_fail'
76- sf . return_type = DuckDB ::LogicalType . new ( 4 ) # INTEGER
76+ sf . return_type = DuckDB ::LogicalType :: INTEGER
7777 sf . set_function { 1 }
7878
7979 # Should raise error because threads is not 1
@@ -87,7 +87,7 @@ def test_register_scalar_function_raises_error_without_single_thread
8787
8888 def test_add_parameter
8989 sf = DuckDB ::ScalarFunction . new
90- logical_type = DuckDB ::LogicalType . new ( 4 ) # DUCKDB_TYPE_INTEGER
90+ logical_type = DuckDB ::LogicalType :: INTEGER
9191
9292 result = sf . add_parameter ( logical_type )
9393
@@ -97,7 +97,7 @@ def test_add_parameter
9797
9898 def test_add_parameter_raises_error_for_unsupported_type
9999 sf = DuckDB ::ScalarFunction . new
100- interval_type = DuckDB ::LogicalType . new ( 15 ) # DUCKDB_TYPE_INTERVAL (unsupported)
100+ interval_type = DuckDB ::LogicalType :: INTERVAL # Unsupported type for testing
101101
102102 error = assert_raises ( DuckDB ::Error ) do
103103 sf . add_parameter ( interval_type )
@@ -123,8 +123,8 @@ def test_scalar_function_with_one_parameter # rubocop:disable Metrics/MethodLeng
123123
124124 sf = DuckDB ::ScalarFunction . new
125125 sf . name = 'double'
126- sf . add_parameter ( DuckDB ::LogicalType . new ( 4 ) ) # INTEGER
127- sf . return_type = DuckDB ::LogicalType . new ( 4 ) # INTEGER
126+ sf . add_parameter ( DuckDB ::LogicalType :: INTEGER )
127+ sf . return_type = DuckDB ::LogicalType :: INTEGER
128128 sf . set_function { |col1 | 2 * col1 }
129129
130130 @con . register_scalar_function ( sf )
@@ -133,16 +133,16 @@ def test_scalar_function_with_one_parameter # rubocop:disable Metrics/MethodLeng
133133 assert_equal [ [ 10 ] , [ 20 ] , [ 30 ] ] , result . to_a
134134 end
135135
136- def test_scalar_function_with_two_parameters # rubocop:disable Metrics/AbcSize, Metrics/ MethodLength
136+ def test_scalar_function_with_two_parameters # rubocop:disable Metrics/MethodLength
137137 @con . execute ( 'SET threads=1' )
138138 @con . execute ( 'CREATE TABLE test_table (a INTEGER, b INTEGER)' )
139139 @con . execute ( 'INSERT INTO test_table VALUES (5, 3), (10, 2), (15, 4)' )
140140
141141 sf = DuckDB ::ScalarFunction . new
142142 sf . name = 'add_nums'
143- sf . add_parameter ( DuckDB ::LogicalType . new ( 4 ) ) # INTEGER
144- sf . add_parameter ( DuckDB ::LogicalType . new ( 4 ) ) # INTEGER
145- sf . return_type = DuckDB ::LogicalType . new ( 4 ) # INTEGER
143+ sf . add_parameter ( DuckDB ::LogicalType :: INTEGER )
144+ sf . add_parameter ( DuckDB ::LogicalType :: INTEGER )
145+ sf . return_type = DuckDB ::LogicalType :: INTEGER
146146 sf . set_function { |a , b | a + b }
147147
148148 @con . register_scalar_function ( sf )
@@ -158,8 +158,8 @@ def test_scalar_function_with_null_input # rubocop:disable Metrics/MethodLength
158158
159159 sf = DuckDB ::ScalarFunction . new
160160 sf . name = 'double'
161- sf . add_parameter ( DuckDB ::LogicalType . new ( 4 ) ) # INTEGER
162- sf . return_type = DuckDB ::LogicalType . new ( 4 ) # INTEGER
161+ sf . add_parameter ( DuckDB ::LogicalType :: INTEGER )
162+ sf . return_type = DuckDB ::LogicalType :: INTEGER
163163 sf . set_function { |col1 | col1 . nil? ? nil : 2 * col1 }
164164
165165 @con . register_scalar_function ( sf )
@@ -175,8 +175,8 @@ def test_scalar_function_bigint_return_type # rubocop:disable Metrics/MethodLeng
175175
176176 sf = DuckDB ::ScalarFunction . new
177177 sf . name = 'subtract_one'
178- sf . add_parameter ( DuckDB ::LogicalType . new ( 5 ) ) # BIGINT
179- sf . return_type = DuckDB ::LogicalType . new ( 5 ) # BIGINT
178+ sf . add_parameter ( DuckDB ::LogicalType :: BIGINT )
179+ sf . return_type = DuckDB ::LogicalType :: BIGINT
180180 sf . set_function { |v | v - 1 } # Subtract to avoid overflow
181181
182182 @con . register_scalar_function ( sf )
@@ -192,8 +192,8 @@ def test_scalar_function_double_return_type # rubocop:disable Metrics/MethodLeng
192192
193193 sf = DuckDB ::ScalarFunction . new
194194 sf . name = 'multiply_by_two'
195- sf . add_parameter ( DuckDB ::LogicalType . new ( 11 ) ) # DOUBLE (type ID 11 )
196- sf . return_type = DuckDB ::LogicalType . new ( 11 ) # DOUBLE
195+ sf . add_parameter ( DuckDB ::LogicalType :: DOUBLE )
196+ sf . return_type = DuckDB ::LogicalType :: DOUBLE # DOUBLE
197197 sf . set_function { |v | v * 2 }
198198
199199 @con . register_scalar_function ( sf )
@@ -209,8 +209,8 @@ def test_scalar_function_boolean_return_type # rubocop:disable Metrics/MethodLen
209209
210210 sf = DuckDB ::ScalarFunction . new
211211 sf . name = 'is_greater_than_ten'
212- sf . add_parameter ( DuckDB ::LogicalType . new ( 4 ) ) # INTEGER
213- sf . return_type = DuckDB ::LogicalType . new ( 1 ) # BOOLEAN (type ID 1)
212+ sf . add_parameter ( DuckDB ::LogicalType :: INTEGER )
213+ sf . return_type = DuckDB ::LogicalType :: BOOLEAN # BOOLEAN (type ID 1)
214214 sf . set_function { |v | v > 10 }
215215
216216 @con . register_scalar_function ( sf )
@@ -226,8 +226,8 @@ def test_scalar_function_float_return_type # rubocop:disable Metrics/MethodLengt
226226
227227 sf = DuckDB ::ScalarFunction . new
228228 sf . name = 'add_half'
229- sf . add_parameter ( DuckDB ::LogicalType . new ( 10 ) ) # FLOAT (type ID 10 )
230- sf . return_type = DuckDB ::LogicalType . new ( 10 ) # FLOAT
229+ sf . add_parameter ( DuckDB ::LogicalType :: FLOAT )
230+ sf . return_type = DuckDB ::LogicalType :: FLOAT # FLOAT
231231 sf . set_function { |v | v + 0.5 }
232232
233233 @con . register_scalar_function ( sf )
@@ -243,8 +243,8 @@ def test_scalar_function_varchar_return_type # rubocop:disable Metrics/MethodLen
243243
244244 sf = DuckDB ::ScalarFunction . new
245245 sf . name = 'add_greeting'
246- sf . add_parameter ( DuckDB ::LogicalType . new ( 17 ) ) # VARCHAR (type ID 17 )
247- sf . return_type = DuckDB ::LogicalType . new ( 17 ) # VARCHAR
246+ sf . add_parameter ( DuckDB ::LogicalType :: VARCHAR )
247+ sf . return_type = DuckDB ::LogicalType :: VARCHAR # VARCHAR
248248 sf . set_function { |name | "Hello, #{ name } !" }
249249
250250 @con . register_scalar_function ( sf )
@@ -260,8 +260,8 @@ def test_scalar_function_blob_return_type # rubocop:disable Metrics/AbcSize, Met
260260
261261 sf = DuckDB ::ScalarFunction . new
262262 sf . name = 'add_prefix'
263- sf . add_parameter ( DuckDB ::LogicalType . new ( 18 ) ) # BLOB (type ID 18 )
264- sf . return_type = DuckDB ::LogicalType . new ( 18 ) # BLOB
263+ sf . add_parameter ( DuckDB ::LogicalType :: BLOB )
264+ sf . return_type = DuckDB ::LogicalType :: BLOB # BLOB
265265 sf . set_function { |data | DuckDB ::Blob . new ( "\xFF " . b + data ) }
266266
267267 @con . register_scalar_function ( sf )
@@ -280,8 +280,8 @@ def test_scalar_function_timestamp_return_type # rubocop:disable Metrics/AbcSize
280280
281281 sf = DuckDB ::ScalarFunction . new
282282 sf . name = 'add_one_hour'
283- sf . add_parameter ( DuckDB ::LogicalType . new ( 12 ) ) # TIMESTAMP (type ID 12 )
284- sf . return_type = DuckDB ::LogicalType . new ( 12 ) # TIMESTAMP
283+ sf . add_parameter ( DuckDB ::LogicalType :: TIMESTAMP )
284+ sf . return_type = DuckDB ::LogicalType :: TIMESTAMP # TIMESTAMP
285285 sf . set_function { |ts | ts + 3600 } # Add 1 hour (3600 seconds)
286286
287287 @con . register_scalar_function ( sf )
@@ -300,8 +300,8 @@ def test_scalar_function_date_return_type # rubocop:disable Metrics/AbcSize, Met
300300
301301 sf = DuckDB ::ScalarFunction . new
302302 sf . name = 'add_one_day'
303- sf . add_parameter ( DuckDB ::LogicalType . new ( 13 ) ) # DATE (type ID 13 )
304- sf . return_type = DuckDB ::LogicalType . new ( 13 ) # DATE
303+ sf . add_parameter ( DuckDB ::LogicalType :: DATE )
304+ sf . return_type = DuckDB ::LogicalType :: DATE # DATE
305305 sf . set_function { |date | date + 1 } # Add 1 day
306306
307307 @con . register_scalar_function ( sf )
@@ -320,8 +320,8 @@ def test_scalar_function_time_return_type # rubocop:disable Metrics/AbcSize, Met
320320
321321 sf = DuckDB ::ScalarFunction . new
322322 sf . name = 'add_one_hour'
323- sf . add_parameter ( DuckDB ::LogicalType . new ( 14 ) ) # TIME (type ID 14 )
324- sf . return_type = DuckDB ::LogicalType . new ( 14 ) # TIME
323+ sf . add_parameter ( DuckDB ::LogicalType :: TIME )
324+ sf . return_type = DuckDB ::LogicalType :: TIME # TIME
325325 sf . set_function { |time | time + 3600 } # Add 1 hour (3600 seconds)
326326
327327 @con . register_scalar_function ( sf )
@@ -344,8 +344,8 @@ def test_scalar_function_smallint_return_type # rubocop:disable Metrics/AbcSize,
344344
345345 sf = DuckDB ::ScalarFunction . new
346346 sf . name = 'add_100'
347- sf . add_parameter ( DuckDB ::LogicalType . new ( 3 ) ) # SMALLINT (type ID 3 )
348- sf . return_type = DuckDB ::LogicalType . new ( 3 ) # SMALLINT
347+ sf . add_parameter ( DuckDB ::LogicalType :: SMALLINT )
348+ sf . return_type = DuckDB ::LogicalType :: SMALLINT # SMALLINT
349349 sf . set_function { |v | v + 100 }
350350
351351 @con . register_scalar_function ( sf )
@@ -365,8 +365,8 @@ def test_scalar_function_tinyint_return_type # rubocop:disable Metrics/AbcSize,
365365
366366 sf = DuckDB ::ScalarFunction . new
367367 sf . name = 'double_value'
368- sf . add_parameter ( DuckDB ::LogicalType . new ( 2 ) ) # TINYINT (type ID 2 )
369- sf . return_type = DuckDB ::LogicalType . new ( 2 ) # TINYINT
368+ sf . add_parameter ( DuckDB ::LogicalType :: TINYINT )
369+ sf . return_type = DuckDB ::LogicalType :: TINYINT # TINYINT
370370 sf . set_function { |v | v * 2 }
371371
372372 @con . register_scalar_function ( sf )
@@ -386,8 +386,8 @@ def test_scalar_function_utinyint_return_type # rubocop:disable Metrics/AbcSize,
386386
387387 sf = DuckDB ::ScalarFunction . new
388388 sf . name = 'add_10'
389- sf . add_parameter ( DuckDB ::LogicalType . new ( 6 ) ) # UTINYINT (type ID 6 )
390- sf . return_type = DuckDB ::LogicalType . new ( 6 ) # UTINYINT
389+ sf . add_parameter ( DuckDB ::LogicalType :: UTINYINT )
390+ sf . return_type = DuckDB ::LogicalType :: UTINYINT # UTINYINT
391391 sf . set_function { |v | v + 10 }
392392
393393 @con . register_scalar_function ( sf )
@@ -408,8 +408,8 @@ def test_scalar_function_usmallint_return_type # rubocop:disable Metrics/AbcSize
408408
409409 sf = DuckDB ::ScalarFunction . new
410410 sf . name = 'add_100'
411- sf . add_parameter ( DuckDB ::LogicalType . new ( 7 ) ) # USMALLINT (type ID 7 )
412- sf . return_type = DuckDB ::LogicalType . new ( 7 ) # USMALLINT
411+ sf . add_parameter ( DuckDB ::LogicalType :: USMALLINT )
412+ sf . return_type = DuckDB ::LogicalType :: USMALLINT # USMALLINT
413413 sf . set_function { |v | v + 100 }
414414
415415 @con . register_scalar_function ( sf )
@@ -429,8 +429,8 @@ def test_scalar_function_uinteger_return_type # rubocop:disable Metrics/AbcSize,
429429
430430 sf = DuckDB ::ScalarFunction . new
431431 sf . name = 'add_100'
432- sf . add_parameter ( DuckDB ::LogicalType . new ( 8 ) ) # UINTEGER (type ID 8 )
433- sf . return_type = DuckDB ::LogicalType . new ( 8 ) # UINTEGER
432+ sf . add_parameter ( DuckDB ::LogicalType :: UINTEGER )
433+ sf . return_type = DuckDB ::LogicalType :: UINTEGER # UINTEGER
434434 sf . set_function { |v | v + 100 }
435435
436436 @con . register_scalar_function ( sf )
@@ -450,8 +450,8 @@ def test_scalar_function_ubigint_return_type # rubocop:disable Metrics/AbcSize,
450450
451451 sf = DuckDB ::ScalarFunction . new
452452 sf . name = 'double_value'
453- sf . add_parameter ( DuckDB ::LogicalType . new ( 9 ) ) # UBIGINT (type ID 9 )
454- sf . return_type = DuckDB ::LogicalType . new ( 9 ) # UBIGINT
453+ sf . add_parameter ( DuckDB ::LogicalType :: UBIGINT )
454+ sf . return_type = DuckDB ::LogicalType :: UBIGINT # UBIGINT
455455 sf . set_function { |v | v * 2 }
456456
457457 @con . register_scalar_function ( sf )
@@ -470,7 +470,7 @@ def test_scalar_function_gc_safety # rubocop:disable Metrics/AbcSize, Metrics/Me
470470 # Register function and immediately lose reference
471471 @con . register_scalar_function ( DuckDB ::ScalarFunction . new . tap do |sf |
472472 sf . name = 'test_func'
473- sf . return_type = DuckDB ::LogicalType . new ( 4 ) # INTEGER
473+ sf . return_type = DuckDB ::LogicalType :: INTEGER
474474 sf . set_function { 42 }
475475 end )
476476
0 commit comments