Schema generation
This page documents the API for generating table schemas that are compatible with both upsert and insert.
builder
builder(schema, *, key=None)
Generate an empty schema for a keyed or unkeyed q table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema |
Dict
|
The definition of the schema to be created mapping a 'str'
to a |
required |
key |
Optional[Union[str, List[str]]]
|
The column name(s) in |
None
|
Returns:
Type | Description |
---|---|
k.K
|
A |
Examples:
Create a simple pykx.Table
with four columns of different types
>>> import pykx as kx
>>> qtab = kx.schema.builder({
'col1' : kx.GUIDAtom,
'col2': kx.TimeAtom,
'col3': kx.BooleanAtom,
'col4': kx.FloatAtom
})
>>> qtab
pykx.Table(pykx.q('
col1 col2 col3 col4
-------------------
'))
>>> kx.q.meta(qtab)
pykx.KeyedTable(pykx.q('
c | t f a
----| -----
col1| g
col2| t
col3| b
col4| f
'))
Create a pykx.KeyedTable
with a single primary key.
>>> import pykx as kx
>>> qtab = kx.schema.builder({
'col1': kx.TimestampAtom,
'col2': kx.FloatAtom,
'col3': kx.IntAtom},
key = 'col1'
)
>>> qtab
pykx.KeyedTable(pykx.q('
col1| col2 col3
----| ---------
'))
>>> kx.q.meta(qtab)
pykx.KeyedTable(pykx.q('
c | t f a
----| -----
col1| p
col2| f
col3| i
'))
Create a pykx.KeyedTable
with multiple primary keys.
>>> import pykx as kx
>>> qtab = kx.schema.builder({
'col1': kx.TimestampAtom,
'col2': kx.SymbolAtom,
'col3': kx.IntAtom,
'col4': kx.List},
key = ['col1', 'col2']
)
>>> qtab
pykx.KeyedTable(pykx.q('
col1 col2| col3 col4
---------| ---------
'))
>>> kx.q.meta(qtab)
pykx.KeyedTable(pykx.q('
c | t f a
----| -----
col1| p
col2| s
col3| i
col4|
'))