Skip to content

Commit a22fc43

Browse files
kesmit13claude
andcommitted
Enable VECTOR type with element type validation in dtypes
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5dfacae commit a22fc43

File tree

1 file changed

+49
-46
lines changed

1 file changed

+49
-46
lines changed

singlestoredb/functions/dtypes.py

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,49 +1744,52 @@ def GEOGRAPHY(
17441744
# return out
17451745

17461746

1747-
# F32 = 'F32'
1748-
# F64 = 'F64'
1749-
# I8 = 'I8'
1750-
# I16 = 'I16'
1751-
# I32 = 'I32'
1752-
# I64 = 'I64'
1753-
1754-
1755-
# def VECTOR(
1756-
# length: int,
1757-
# element_type: str = F32,
1758-
# *,
1759-
# nullable: bool = True,
1760-
# default: Optional[bytes] = None,
1761-
# name: Optional[str] = None,
1762-
# ) -> SQLString:
1763-
# """
1764-
# VECTOR type specification.
1765-
#
1766-
# Parameters
1767-
# ----------
1768-
# n : int
1769-
# Number of elements in vector
1770-
# element_type : str, optional
1771-
# Type of the elements in the vector:
1772-
# F32, F64, I8, I16, I32, I64
1773-
# nullable : bool, optional
1774-
# Can the value be NULL?
1775-
# default : str, optional
1776-
# Default value
1777-
# name : str, optional
1778-
# Name of the column / parameter
1779-
#
1780-
# Returns
1781-
# -------
1782-
# SQLString
1783-
#
1784-
# """
1785-
# out = f'VECTOR({int(length)}, {element_type})'
1786-
# out = SQLString(
1787-
# out + _modifiers(
1788-
# nullable=nullable, default=default,
1789-
# ),
1790-
# )
1791-
# out.name = name
1792-
# return out
1747+
F16 = 'F16'
1748+
F32 = 'F32'
1749+
F64 = 'F64'
1750+
I8 = 'I8'
1751+
I16 = 'I16'
1752+
I32 = 'I32'
1753+
I64 = 'I64'
1754+
1755+
1756+
def VECTOR(
1757+
length: int,
1758+
element_type: str = F32,
1759+
*,
1760+
nullable: bool = True,
1761+
default: Optional[bytes] = None,
1762+
name: Optional[str] = None,
1763+
) -> SQLString:
1764+
"""
1765+
VECTOR type specification.
1766+
1767+
Parameters
1768+
----------
1769+
n : int
1770+
Number of elements in vector
1771+
element_type : str, optional
1772+
Type of the elements in the vector:
1773+
F16, F32, F64, I8, I16, I32, I64
1774+
nullable : bool, optional
1775+
Can the value be NULL?
1776+
default : str, optional
1777+
Default value
1778+
name : str, optional
1779+
Name of the column / parameter
1780+
1781+
Returns
1782+
-------
1783+
SQLString
1784+
1785+
"""
1786+
if element_type.upper() not in (F16, F32, F64, I8, I16, I32, I64):
1787+
raise ValueError(f'unsupported element type: {element_type}')
1788+
out = f'VECTOR({int(length)}, {element_type})'
1789+
out = SQLString(
1790+
out + _modifiers(
1791+
nullable=nullable, default=default,
1792+
),
1793+
)
1794+
out.name = name
1795+
return out

0 commit comments

Comments
 (0)