Skip to main content
Version: latest

Data Types

CnosDB SQL is implemented using Apache Arrow DataFusion, DataFusion uses Arrow types to execute queries, and the data types stored in CnosDB are mapped to SQL data types when queried.

You can see the corresponding Arrow type for any SQL expression using the arrow_typeof function. For example:

SELECT arrow_typeof('Hello CnosDB!');
+-------------------------------------+
| arrow_typeof(Utf8("Hello CnosDB!")) |
+-------------------------------------+
| Utf8 |
+-------------------------------------+

You can also convert the content in the SQL expression to a specified Arrow type, such as converting Timestamp type to Date32:

SELECT arrow_cast(now(), 'Date32');
+------------+
| now() |
+------------+
| 2024-03-05 |
+------------+

CnosDB can only store partial data types, for detailed information please refer to CREATE DATABASE.

Character Types

SQL Data TypesArrow Data Type
CHARUtf8
VARCHARUtf8
TEXTUtf8
STRINGUtf8

Numeric Types

SQL Data TypesArrow Data Type
TINYINTInt8
SMALLINTInt16
INT or INTEGERInt32
BIGINTInt64
TINYINT UNSIGNEDUInt8
SMALLINT UNSIGNEDUInt16
INT UNSIGNED or INTEGER UNSIGNEDUInt32
BIGINT UNSIGNEDUInt64
FLOATFloat32
REALFloat32
DOUBLEFloat64

Date/Time Types

SQL Data TypesArrow Data Type
DATEDate32
TIMETime64(Nanosecond)
TIMESTAMPTimestamp(Nanosecond, None)
INTERVALInterval(MonthDayNano)

Boolean Types

SQL Data TypesArrow Data Type
BOOLEANBoolean

Binary Types

SQL Data TypesArrow Data Type
BYTEABinary

Geospatial Type

CnosDB uses WKT (Well-known text) to support geospatial type (Geometry) data queries.

Geometry typesSyntax
PointPOINT (<x1> <y1>)
LineStringLINESTRING (<x1> <y1>, <x2> <y2>, ...)
PolygonPOLYGON ((<x1> <y1>, <x2> <y2>, ...))
MultiPointMULTIPOINT (<x1> <y1>, <x2> <y2>, ...)
MultiLineStringMULTILINESTRING ((<x1> <y1>, <x2> <y2>, ...), (<x1> <y1>, <x2> <y2>, ...))
MultiPolygonMULTIPOLYGON (((<x1> <y1>, <x2> <y2>, ...)), ((<x1> <y1>, <x2> <y2>, ...)))
GeometryCollectionGEOMETRYCOLLECTION (<geometry tag1> <wkt data1>, <geometry tag2> <wkt data2>, ...)

Unsupported SQL Types

SQL Data TypesArrow Data Type
UUIDUnsupported
BLOBUnsupported
CLOBUnsupported
BINARYUnsupported
VARBINARYUnsupported
REGCLASSUnsupported
NVARCHARUnsupported
CUSTOMUnsupported
ARRAYUnsupported
ENUMUnsupported
SETUnsupported
DATETIMEUnsupported

Supported Arrow Types

The following types are supported by the ARROW_TYPEOF function:

Arrow Types
Null
Boolean
Int8
Int16
Int32
Int64
UInt8
UInt16
UInt32
UInt64
Float16
Float32
Float64
Utf8
LargeUtf8
Binary
Timestamp(Second, None)
Timestamp(Millisecond, None)
Timestamp(Microsecond, None)
Timestamp(Nanosecond, None)
Time32
Time64
Duration(Second)
Duration(Millisecond)
Duration(Microsecond)
Duration(Nanosecond)
Interval(YearMonth)
Interval(DayTime)
Interval(MonthDayNano)
FixedSizeBinary(<len>) (e.g. FixedSizeBinary(16))
Decimal128(<precision>, <scale>) e.g. Decimal128(3, 10)
Decimal256(<precision>, <scale>) e.g. Decimal256(3, 10)