33module DuckDB
44 # DuckDB::ScalarFunction encapsulates DuckDB's scalar function
55 class ScalarFunction
6+ # Supported return types for scalar functions
7+ SUPPORTED_RETURN_TYPES = %i[
8+ bigint
9+ blob
10+ boolean
11+ date
12+ double
13+ float
14+ integer
15+ smallint
16+ time
17+ timestamp
18+ tinyint
19+ ubigint
20+ uinteger
21+ usmallint
22+ utinyint
23+ varchar
24+ ] . freeze
25+
26+ private_constant :SUPPORTED_RETURN_TYPES
27+
628 # Sets the return type for the scalar function.
729 # Currently supports BIGINT, BLOB, BOOLEAN, DATE, DOUBLE, FLOAT, INTEGER, SMALLINT, TIME, TIMESTAMP, TINYINT,
830 # UBIGINT, UINTEGER, USMALLINT, UTINYINT, and VARCHAR types.
@@ -13,13 +35,10 @@ class ScalarFunction
1335 def return_type = ( logical_type )
1436 raise DuckDB ::Error , 'logical_type must be a DuckDB::LogicalType' unless logical_type . is_a? ( DuckDB ::LogicalType )
1537
16- # Check if the type is supported
17- supported_types = %i[ bigint blob boolean date double float integer smallint time timestamp tinyint ubigint
18- uinteger usmallint utinyint varchar ]
19- unless supported_types . include? ( logical_type . type )
38+ unless SUPPORTED_RETURN_TYPES . include? ( logical_type . type )
39+ type_list = SUPPORTED_RETURN_TYPES . map ( &:upcase ) . join ( ', ' )
2040 raise DuckDB ::Error ,
21- 'Only BIGINT, BLOB, BOOLEAN, DATE, DOUBLE, FLOAT, INTEGER, SMALLINT, TIME, TIMESTAMP, TINYINT, ' \
22- 'UBIGINT, UINTEGER, USMALLINT, UTINYINT, and VARCHAR return types are currently supported'
41+ "Only #{ type_list } return types are currently supported"
2342 end
2443
2544 _set_return_type ( logical_type )
0 commit comments