graviti.portex.builtin#

The Portex builtin types.

Module Contents#

Classes#

PortexBuiltinType

The base class of Portex builtin type.

string

Portex primitive type string.

binary

Portex primitive type binary.

boolean

Portex primitive type boolean.

int32

Portex primitive type int32.

int64

Portex primitive type int64.

float32

Portex primitive type float32.

float64

Portex primitive type float64.

record

Portex complex type record.

enum

Portex complex type enum.

array

Portex complex type array.

date

Portex temporal type date.

time

Portex temporal type time.

timestamp

Portex temporal type timestamp.

timedelta

Portex temporal type timedelta.

Attributes#

graviti.portex.builtin.tz_checker[source]#
graviti.portex.builtin.builtins[source]#
class graviti.portex.builtin.PortexBuiltinType(nullable=False)[source]#

Bases: graviti.portex.base.PortexType

The base class of Portex builtin type.

Parameters

nullable (bool) –

to_builtin(self)[source]#

Expand the top level type to Portex builtin type.

Returns

The expanded Portex builtin type.

Parameters

self (_T) –

Return type

_T

class graviti.portex.builtin.string(nullable=False)[source]#

Bases: PortexBuiltinType

Portex primitive type string.

Parameters

nullable (bool) – Whether it is a nullable type.

Examples

>>> t = string()
>>> t
string()
to_pyarrow(self, *, _to_backend=False)[source]#

Convert the Portex type to the corresponding builtin PyArrow DataType.

Returns

The corresponding builtin PyArrow DataType.

Parameters

_to_backend (bool) –

Return type

pyarrow.DataType

class graviti.portex.builtin.binary(nullable=False)[source]#

Bases: PortexBuiltinType

Portex primitive type binary.

Parameters

nullable (bool) – Whether it is a nullable type.

Examples

>>> t = binary()
>>> t
binary()
to_pyarrow(self, *, _to_backend=False)[source]#

Convert the Portex type to the corresponding builtin PyArrow DataType.

Returns

The corresponding builtin PyArrow DataType.

Parameters

_to_backend (bool) –

Return type

pyarrow.DataType

class graviti.portex.builtin.boolean(nullable=False)[source]#

Bases: PortexBuiltinType

Portex primitive type boolean.

Parameters

nullable (bool) – Whether it is a nullable type.

Examples

>>> t = boolean()
>>> t
boolean()
to_pyarrow(self, *, _to_backend=False)[source]#

Convert the Portex type to the corresponding builtin PyArrow DataType.

Returns

The corresponding builtin PyArrow DataType.

Parameters

_to_backend (bool) –

Return type

pyarrow.DataType

class graviti.portex.builtin.int32(nullable=False)[source]#

Bases: PortexBuiltinType

Portex primitive type int32.

Parameters

nullable (bool) – Whether it is a nullable type.

Examples

>>> t = int32()
>>> t
int32()
to_pyarrow(self, *, _to_backend=False)[source]#

Convert the Portex type to the corresponding builtin PyArrow DataType.

Returns

The corresponding builtin PyArrow DataType.

Parameters

_to_backend (bool) –

Return type

pyarrow.DataType

class graviti.portex.builtin.int64(nullable=False)[source]#

Bases: PortexBuiltinType

Portex primitive type int64.

Parameters

nullable (bool) – Whether it is a nullable type.

Examples

>>> t = int64()
>>> t
int64()
to_pyarrow(self, *, _to_backend=False)[source]#

Convert the Portex type to the corresponding builtin PyArrow DataType.

Returns

The corresponding builtin PyArrow DataType.

Parameters

_to_backend (bool) –

Return type

pyarrow.DataType

class graviti.portex.builtin.float32(nullable=False)[source]#

Bases: PortexBuiltinType

Portex primitive type float32.

Parameters

nullable (bool) – Whether it is a nullable type.

Examples

>>> t = float32()
>>> t
float32()
to_pyarrow(self, *, _to_backend=False)[source]#

Convert the Portex type to the corresponding builtin PyArrow DataType.

Returns

The corresponding builtin PyArrow DataType.

Parameters

_to_backend (bool) –

Return type

pyarrow.DataType

class graviti.portex.builtin.float64(nullable=False)[source]#

Bases: PortexBuiltinType

Portex primitive type float64.

Parameters

nullable (bool) – Whether it is a nullable type.

Examples

>>> t = float64()
>>> t
float64()
to_pyarrow(self, *, _to_backend=False)[source]#

Convert the Portex type to the corresponding builtin PyArrow DataType.

Returns

The corresponding builtin PyArrow DataType.

Parameters

_to_backend (bool) –

Return type

pyarrow.DataType

class graviti.portex.builtin.record(fields, nullable=False)[source]#

Bases: PortexBuiltinType, graviti.portex.base.PortexRecordBase

Portex complex type record.

Parameters

Examples

Create a record by dict:

>>> t = record({"f0": int32(), "f1": float32()})
>>> t
record(
  fields={
    'f0': int32(),
    'f1': float32(),
  },
)

Create a record by tuple list:

>>> t = record([("f0", string()), ("f1", enum(["v0", "v1"]))])
>>> t
record(
  fields={
    'f0': string(),
    'f1': enum(
      values=['v0', 'v1'],
    ),
  },
)
to_pyarrow(self, *, _to_backend=False)[source]#

Convert the Portex type to the corresponding builtin PyArrow DataType.

Returns

The corresponding builtin PyArrow struct DataType.

Parameters

_to_backend (bool) –

Return type

pyarrow.DataType

class graviti.portex.builtin.enum(values, nullable=False)[source]#

Bases: PortexBuiltinType

Portex complex type enum.

Parameters
  • values (Iterable[_E]) – The values of the enum members.

  • nullable (bool) – Whether it is a nullable type.

Examples

>>> t = enum(["v0", "v1"])
>>> t
enum(
  values=['v0', 'v1'],
)
to_pyarrow(self, *, _to_backend=False)[source]#

Convert the Portex type to the corresponding builtin PyArrow DataType.

Returns

The corresponding builtin PyArrow DataType.

Parameters

_to_backend (bool) –

Return type

pyarrow.DataType

class graviti.portex.builtin.array(items, length=None, nullable=False)[source]#

Bases: PortexBuiltinType

Portex complex type array.

Parameters
  • items (graviti.portex.base.PortexType) – The item type of the array.

  • length (Optional[int]) – The length of the array.

  • nullable (bool) – Whether it is a nullable type.

Examples

>>> t = array(int32(0), 100)
>>> t
array(
  items=int32(
    minimum=0,
  ),
  length=100,
)
to_pyarrow(self, *, _to_backend=False)[source]#

Convert the Portex type to the corresponding builtin PyArrow DataType.

Returns

The corresponding builtin PyArrow DataType.

Parameters

_to_backend (bool) –

Return type

pyarrow.DataType

class graviti.portex.builtin.date(nullable=False)[source]#

Bases: PortexBuiltinType

Portex temporal type date.

Parameters

nullable (bool) – Whether it is a nullable type.

Examples

>>> t = date()
>>> t
date()
to_pyarrow(self, *, _to_backend=False)[source]#

Convert the Portex type to the corresponding builtin PyArrow DataType.

Returns

The corresponding builtin PyArrow DataType.

Parameters

_to_backend (bool) –

Return type

pyarrow.DataType

class graviti.portex.builtin.time(unit, nullable=False)[source]#

Bases: PortexBuiltinType

Portex temporal type time.

Parameters
  • unit (str) – The unit of the time, supports ‘s’, ‘ms’, ‘us’ and ‘ns’.

  • nullable (bool) – Whether it is a nullable type.

Examples

>>> t = time("ms")
>>> t
times(
  unit='ms',
)
to_pyarrow(self, *, _to_backend=False)[source]#

Convert the Portex type to the corresponding builtin PyArrow DataType.

Returns

The corresponding builtin PyArrow DataType.

Parameters

_to_backend (bool) –

Return type

pyarrow.DataType

class graviti.portex.builtin.timestamp(unit, tz=None, nullable=False)[source]#

Bases: PortexBuiltinType

Portex temporal type timestamp.

Parameters
  • unit (str) – The unit of the timestamp, supports ‘s’, ‘ms’, ‘us’ and ‘ns’.

  • tz (Optional[str]) – The name of the timezone, None indicates the timestamp is naive.

  • nullable (bool) – Whether it is a nullable type.

Examples

>>> t = timestamp("ms")
>>> t
timestamp(
  unit='ms',
)
>>>
>>> t = timestamp("us", tz="UTC")
>>> t
timestamp(
  unit='ms',
  tz='UTC',
)
to_pyarrow(self, *, _to_backend=False)[source]#

Convert the Portex type to the corresponding builtin PyArrow DataType.

Returns

The corresponding builtin PyArrow DataType.

Parameters

_to_backend (bool) –

Return type

pyarrow.DataType

class graviti.portex.builtin.timedelta(unit, nullable=False)[source]#

Bases: PortexBuiltinType

Portex temporal type timedelta.

Parameters
  • unit (str) – The unit of the timedelta, supports ‘s’, ‘ms’, ‘us’ and ‘ns’.

  • nullable (bool) – Whether it is a nullable type.

Examples

>>> t = timedelta("ms")
>>> t
timedelta(
  unit='ms',
)
to_pyarrow(self, *, _to_backend=False)[source]#

Convert the Portex type to the corresponding builtin PyArrow DataType.

Returns

The corresponding builtin PyArrow DataType.

Parameters

_to_backend (bool) –

Return type

pyarrow.DataType