Skip to main content

Types API

The GoosePyType class represents a type instance of our data types.

Converting from Other Types

To make the API as easy to use as possible, we have added implicit conversions from existing type objects to a GoosePyType instance. This means that wherever a GoosePyType object is expected, it is also possible to provide any of the options listed below.

Python Built-Ins

The table below shows the mapping of Python Built-in types to Goose type.

Built-in typesGoose type
boolBOOLEAN
bytearrayBLOB
bytesBLOB
floatDOUBLE
intBIGINT
strVARCHAR

Numpy DTypes

The table below shows the mapping of Numpy DType to Goose type.

TypeGoose type
boolBOOLEAN
float32FLOAT
float64DOUBLE
int16SMALLINT
int32INTEGER
int64BIGINT
int8TINYINT
uint16USMALLINT
uint32UINTEGER
uint64UBIGINT
uint8UTINYINT

Nested Types

list[child_type]

list type objects map to a LIST type of the child type. Which can also be arbitrarily nested.

import goose.sqltypes
from typing import Union

goose.sqltypes.GoosePyType(list[dict[Union[str, int], str]])
MAP(UNION(u1 VARCHAR, u2 BIGINT), VARCHAR)[]

dict[key_type, value_type]

dict type objects map to a MAP type of the key type and the value type.

import goose.sqltypes

print(goose.sqltypes.GoosePyType(dict[str, int]))
MAP(VARCHAR, BIGINT)

{'a': field_one, 'b': field_two, ..., 'n': field_n}

dict objects map to a STRUCT composed of the keys and values of the dict.

import goose.sqltypes

print(goose.sqltypes.GoosePyType({'a': str, 'b': int}))
STRUCT(a VARCHAR, b BIGINT)

Union[type_1, ... type_n]

typing.Union objects map to a UNION type of the provided types.

import goose.sqltypes
from typing import Union

print(goose.sqltypes.GoosePyType(Union[int, str, bool, bytearray]))
UNION(u1 BIGINT, u2 VARCHAR, u3 BOOLEAN, u4 BLOB)

Creation Functions

For the built-in types, you can use the constants defined in goose.sqltypes:

Goose type
BIGINT
BIT
BLOB
BOOLEAN
DATE
DOUBLE
FLOAT
HUGEINT
INTEGER
INTERVAL
SMALLINT
SQLNULL
TIME_TZ
TIME
TIMESTAMP_MS
TIMESTAMP_NS
TIMESTAMP_S
TIMESTAMP_TZ
TIMESTAMP
TINYINT
UBIGINT
UHUGEINT
UINTEGER
USMALLINT
UTINYINT
UUID
VARCHAR

For the complex types there are methods available on the GoosePyConnection object or the goose module. Anywhere a GoosePyType is accepted, we will also accept one of the type objects that can implicitly convert to a GoosePyType.

list_type | array_type

Parameters:

  • child_type: GoosePyType

struct_type | row_type

Parameters:

  • fields: Union[list[GoosePyType], dict[str, GoosePyType]]

map_type

Parameters:

  • key_type: GoosePyType
  • value_type: GoosePyType

decimal_type

Parameters:

  • width: int
  • scale: int

union_type

Parameters:

  • members: Union[list[GoosePyType], dict[str, GoosePyType]]

string_type

Parameters:

  • collation: Optional[str]