Skip to content

Type Mapping ​

These tables describe release 0.1.8 and were checked against the published xqdb wheel and the @xbbg/xqdb package. For nulls and infinities, see Values, Nulls, and Text.

q to Python ​

q typeType numberPython valueNotes
boolean-1bool
guid-2strHyphenated form, for example 12345678-1234-5678-1234-567812345678
byte-4int
short, int, long-5, -6, -7intNull and infinity atoms come back as their raw integer values
real, float-8, -9float
char-10strOne character
symbol-11strFollows symbol_encoding
timestamp-12datetime.datetime, naiveValueError if the value has digits below a microsecond
month-13datetime.dateThe first day of the month
date-14datetime.dateOverflowError outside the years 1 to 9999
datetime-15datetime.datetime, naive
timespan-16datetime.timedeltaValueError if the value has digits below a microsecond
minute, second, time-17, -18, -19datetime.time
string (char vector)10str, or bytes if the bytes are not valid UTF-8Not affected by symbol_encoding
Typed list1 to 19, except 10narwhals.SeriesThe column types are in q columns to Arrow. month lists are not supported.
General list0tupleConverted element by element
Dictionary99dictKeys must be symbols. An empty dictionary, including ()!(), becomes {}.
Table98narwhals.DataFrame
Keyed table99narwhals.DataFrameKey columns first, then value columns
Lambda100xqdb.XqdbQLambda.source and .context
Primitive101 to 103xqdb.XqdbQOperator.name, for example "+"
Generic null ::101()An empty tuple, not None
Error-128Raises xqdb.XqdbErrorThe message reads Internal Server Error - "<q error>"

A dictionary whose keys are not symbols raises XqdbError.

q columns to Arrow ​

Table columns and typed lists are decoded into Arrow. The Arrow types that Python sees through PyArrow and that Node.js sees through apache-arrow differ slightly, because Node.js receives them over Arrow IPC:

q columnPyArrow type (Python)apache-arrow type (Node.js)Nulls
booleanboolBool
guidbinary_view, 16 bytes per valueLargeBinary
byteuint8Uint8
short, int, longint16, int32, int64Int16, Int32, Int640N and ±0W become null
real, floatfloat, doubleFloat32, Float640n becomes null; ±0w stays ±inf
charstring_viewLargeUtf8
string (general list of char vectors)string_viewLargeUtf8
symboldictionary<values=string_view, indices=uint32>Dictionary<Uint32, LargeUtf8>
timestamptimestamp[ns]Timestamp<NANOSECOND>0Np becomes null
monthNot supportedNot supported
datedate32[day]Date32<DAY>0Nd becomes null
datetimetimestamp[ns]Timestamp<NANOSECOND>0Nz becomes null
timespanduration[ns]Duration<NANOSECOND>0Nn becomes null
minute, second, timetime64[ns]Time64<NANOSECOND>0Nu, 0Nv, 0Nt become null
Nested typed lists, for example a float list per rowlarge_list<…>LargeList<…>

With the pandas or Polars backend, Narwhals builds the backend's own types from these Arrow columns. Symbols become pandas category or Polars Categorical, for example. See DataFrames and Arrow.

Python to q ​

Python valueq valueNotes
Nonegeneric null ::
boolboolean
intlongOverflowError outside the signed 64-bit range
floatfloat
strsymbolXqdbError if it contains a NUL character
bytesstring (char vector)Every byte is kept
datetime.datetimetimestampA naive value is sent as-is. An aware value is converted to UTC.
pandas.TimestamptimestampKeeps the extra digits in .nanosecond
datetime.datedate
datetime.timetimeMust be whole milliseconds, otherwise ValueError
datetime.timedeltatimespan
dict with str keysdictionary with symbol keys{} becomes (`symbol$())!(). Other key types raise TypeError.
list, tuplegeneral list
xqdb.XqdbQOperatorprimitive
xqdb.XqdbQLambdalambda
Eager DataFrame: pyarrow.Table, pandas, Polars, NarwhalstableColumns follow the table below
Eager Series: pyarrow.ChunkedArray, pandas, Polars, Narwhalstyped list
Lazy frameTypeErrorCollect it first
Anything else, including set and a bare pyarrow.ArrayTypeError

Values can nest at most 64 levels deep, and cyclic containers raise ValueError.

Arrow columns to q ​

The same rules apply to Node.js Table and Vector arguments, which reach the core as Arrow IPC.

Arrow typeq type
boolboolean
uint8byte
int16, int32, int64short, int, long
float32, float64real, float
string, large_string, string_viewgeneral list of strings
dictionary<string> (pandas category, Polars Categorical)symbol
fixed_size_binary(16), or binary values that are all 16 bytesguid
date32date
timestamp[ms]datetime
timestamp[us], timestamp[ns], with or without a time zonetimestamp
durationtimespan
time32, time64time, whole milliseconds only
list or fixed_size_list of booleans or numbersgeneral list of typed lists

Other Arrow types, such as int8, uint16, uint32, and uint64, raise an error. Arrow nulls become the q null of the column's type.

q to JavaScript ​

q typeJavaScript value
booleanboolean
guidstring
byte, short, intnumber
longbigint
real, floatnumber
charnumber, the byte value
symbolstring
timestamp, datetimeXqdbTimestamp, nanoseconds since the Unix epoch
monthXqdbDate, the first day of the month
dateXqdbDate
timespanXqdbTimespan
minute, second, timeXqdbTime, nanoseconds since midnight
string (char vector)Buffer, holding the raw bytes
Typed listArrow Vector. month lists are not supported.
General listArray
DictionaryPlain object. An empty dictionary becomes {}.
Table, keyed tableArrow Table, with key columns first for a keyed table
LambdaXqdbQLambda
PrimitiveXqdbQOperator
Generic null ::null
ErrorRejects with XqdbError, code XQDB_SERVER

JavaScript to q ​

JavaScript valueq valueNotes
nullgeneric null ::
booleanboolean
numberfloatUse bigint for a long
bigintlong
stringsymbolRejected if it contains NUL
Buffer, Uint8Arraystring (char vector)Every byte is kept
Arraygeneral list
Plain object with string keysdictionary with symbol keys{} becomes (`symbol$())!()
Arrow Vectortyped listColumns follow Arrow columns to q
Arrow Tabletable
XqdbTimestamptimestamp
XqdbDatedateYYYY-MM-DD
XqdbTimetimeWhole milliseconds, less than one day
XqdbTimespantimespan
XqdbQOperatorprimitive
XqdbQLambdalambda

Anything else, such as undefined, a Date, a Map, a class instance, or a cyclic structure, rejects with XQDB_CONVERSION. Values can nest at most 64 levels deep.

Operators and lambdas ​

XqdbQOperator(name) accepts these q primitive names. Each group is listed in wire order.

  • Unary (type 101): +: -: *: %: &: |: ^: =: <: >: $: ,: #: _: ~: !: ?: @: .: 0:: 1:: 2:: avg last sum prd min max exit getenv abs sqrt log exp sin asin cos acos tan atan enlist
  • Binary (type 102): : + - * % & | ^ = < > $ , # _ ~ ! ? @ . 0: 1: 2: in within like bin ss insert wsum wavg div xexp setenv
  • Ternary (type 103): ' / \

XqdbQLambda(source, context) sends a q lambda. source must be enclosed in braces, optionally prefixed with k). context is a namespace name without its leading dot, such as "analytics" for .analytics. Neither field may contain NUL. Both classes are immutable and are also what xqdb returns when q sends back a primitive or a function. See Queries and Subscriptions.

xbbg is independent open-source software and is not affiliated with, endorsed by, sponsored by, or approved by Bloomberg Finance L.P.