table#

swordfish.streaming.table(data: Any = None, *, types: Dict[str, DataType | str] = None) StreamTable#
swordfish.streaming.table(data: Any = None, *, names: List[str] = None, types: List[DataType | str] = None) StreamTable
swordfish.streaming.table(*, types: Dict[str, DataType | str] = None, size: int = 0, capacity: int = 1) StreamTable
swordfish.streaming.table(*, names: List[str] = None, types: List[DataType | str] = None, size: int = 0, capacity: int = 1) StreamTable

Creates a StreamTable from data, schema, or empty specification.

Parameters:
  • data (Any, optional) – Input data to be converted into a StreamTable. Default is None.

  • names (list of str, optional) – List of column names for the StreamTable. Used with types.

  • types (dict or list, optional) – Dictionary mapping column names to types, or list of types for columns.

  • size (int, optional) – Initial number of rows in the StreamTable. Default is 0.

  • capacity (int, optional) – Initial allocated capacity for storing rows. Default is 1.

Returns:

An instance of StreamTable created from the provided data and schema.

Return type:

StreamTable

Examples

Create from dict and type dict:
>>> import swordfish as sf
>>> my_dict = {
...     "id": [1, 2, 3, 4],
...     "name": ["Alice", "Bob", "Charlie", "David"],
...     "age": [25, 30, 35, 40],
... }
>>> column_types = {
...     "id": "LONG",
...     "name": "STRING",
...     "age": "INT",
... }
>>> x = sf.streaming.table(my_dict, types=column_types)
>>> x
id name    age
-- ------- ---
1  Alice   25
2  Bob     30
3  Charlie 35
4  David   40
Create from dict, names, and type list:
>>> table = sf.streaming.table(
...     data=my_dict,
...     names=["id", "name", "age"],
...     types=["LONG", "STRING", "INT"]
... )
>>> table
id name    age
-- ------- ---
1  Alice   25
2  Bob     30
3  Charlie 35
4  David   40
Create empty table with type dict, size, and capacity:
>>> column_types = {
...     "id": "LONG",
...     "name": "STRING",
...     "age": "INT",
... }
>>> table = sf.streaming.table(types=column_types, size=5, capacity=10)
>>> table
id name age
-- ---- ---
Create empty table with names, type list, size, and capacity:
>>> table = sf.streaming.table(
...     names=["id", "name", "age"],
...     types=["INT", "STRING", "INT"],
...     size=5,
...     capacity=10
... )
>>> table
id name age
-- ---- ---
Raises:

ProgrammingError – If the number of names and types do not match, or schema is invalid.