Skip to content

本页尚未翻译

本页内容仍为英文原文,源自官方文档 sql/data-types。中文翻译正在分批进行中。

SQL data types ​

How Lance columns appear to SQL, including the types SQL has no name for.

Applies to: Embedded ❌, Enterprise ✅

There is no SQL type layer over Lance storage. The table provider hands DataFusion the dataset's Arrow schema directly, so a column is the same object to the query engine as it is to the format.

The consequence is that SQL type names here are spellings of Arrow types, not a system that maps onto them. Data types documents the storage side; this page covers what changes when you reach a column from SQL.

The Arrow types a column can be ​

CategoryTypes
Nullnull
Booleanbool
Integerint8, int16, int32, int64 and their uint counterparts
Floating pointfloat16, float32, float64
Stringutf8, large_utf8
Binarybinary, large_binary, fixed_size_binary(n)
Date and timedate32, date64, time32, time64, timestamp (with or without timezone), duration
Nestedstruct, list, large_list, fixed_size_list, map
Dictionarydictionary(key, value)

Two limits are worth stating because they surface as schema errors rather than as documentation:

  • A map with keys_sorted = true is rejected. Sorted-key maps do not survive the round trip through the Python bindings, so they are refused rather than silently unsorted.
  • Not every type is legal as a fixed_size_list child. The vector case is, which is what matters in practice.

SQL names for Arrow types ​

SQLArrow
BOOLEANBoolean
TINYINT SMALLINT INT BIGINTInt8 Int16 Int32 Int64
UTINYINT … UBIGINTthe unsigned counterparts
REAL / FLOATFloat32
DOUBLEFloat64
VARCHAR / TEXT / STRINGUtf8
BYTEA / BINARYBinary
DATEDate32
TIMETime64
TIMESTAMPTimestamp, with or without a timezone
INTERVALInterval
STRUCT / LIST / MAPthe nested equivalents

DataFusion's type reference describes the full mapping.

Types SQL has no name for ​

Some column kinds have no SQL type name.

Vectors ​

A dense vector column has a fixed dimension, commonly represented as FixedSizeList<Float32, dim>. Other supported vector element types are possible; inspect the column with arrow_typeof rather than assuming Float32. It is selectable and testable for nullness:

sql
SELECT id FROM documents WHERE vector IS NOT NULL

注意

A list representation does not imply that ordinary arithmetic operators perform vector arithmetic. Use supported distance functions for similarity calculations. SQL vector search depends on the Enterprise server version and query plan; see SQL.

bfloat16 ​

Sixteen-bit floats in the bfloat16 layout, stored as fixed_size_binary(2). Useful as a vector element type when halving the memory matters more than the precision does.

Pseudo-columns ​

Availability depends on the SQL table provider. The ordinary table provider exposes the stored dataset schema; naming a Lance scan metadata field does not make it available as a SQL column. The fts() provider adds _score to its schema, so _score is included in SELECT * FROM fts(...).

ColumnType
_rowidUInt64Lance scan row identifier; stability requires stable row ids
_rowaddrUInt64physical row address
_rowoffsetUInt64offset within the fragment
_scoreFloat32relevance, from fts()

_rowid, _rowaddr, and _rowoffset describe Lance scan metadata, not columns automatically registered on an ordinary SQL table. Select _score from an fts() relation explicitly when you want a projection containing it.

Casting ​

sql
SELECT CAST(identifier AS VARCHAR) FROM documents
SELECT TRY_CAST(maybe_number AS BIGINT) FROM raw

TRY_CAST yields null rather than failing the query on a value that will not convert. See Operators.