Partition#

class swordfish.connection.Partition(partition_type, partition_scheme)#

A class for implementing data partitioning.

build()#
classmethod seq(n)#

Partitions data into n partitions using the SEQ partitioning type.

Parameters:

n (Any) – The number of partitions to create.

Returns:

A Partition object that divides the data into n partitions.

Return type:

Partition

Examples

>>> import swordfish as sf
>>> sf.Partition.seq(8)
Partition(SEQ, 8)
classmethod range(v)#

Partitions data using the specified range boundaries.

Parameters:

v (Any) – A list of values representing the range boundaries.

Returns:

A Partition object that divides the data based on the specified range boundaries.

Return type:

Partition

Examples

>>> import swordfish as sf
>>> sf.Partition.range([0, 5, 10])
Partition(RANGE, [0,5,10])
classmethod value(v)#

Partitions data based on the specified values in the partitioning column.

Parameters:

v (Any) – A list of values to partition the data.

Returns:

A Partition object that divides the data based on the provided values.

Return type:

Partition

Examples

>>> import swordfish as sf
>>> sf.Partition.value([1, 2, 3])
Partition(VALUE, [1,2,3])
classmethod list(v)#

Partitions data based on specified sets of values in the partitioning column.

Parameters:

v (Any) – A list of lists representing the partition.

Returns:

A Partition object that divides the data based on the provided lists.

Return type:

Partition

Examples

>>> import swordfish as sf
>>> sf.Partition.list([[1, 2, 3], [4, 5]])
Partition(LIST, ([1,2,3],[4,5]))
classmethod hash(t, n)#

Partitions data using a hash function on the partitioning column.

Parameters:
  • t (int) – The type of the partitioning column.

  • n (int) – The number of partitions to create.

Returns:

A Partition object that divides data based on the given arguments.

Return type:

Partition

Examples

>>> import swordfish as sf
>>> sf.Partition.hash(sf.types.INT, 8)
Partition(HASH, [4,8])
classmethod compo(partitions)#

Partitions data using the COMPO partitioning type, which combines two or three dimensions.

Parameters:

partitions (list of Partition) – A list of Partition objects.

Returns:

A Partition object that combines the provided partitions.

Return type:

Partition

Examples

>>> import swordfish as sf
>>> sf.Partition.compo([sf.Partition.seq(2), sf.Partition.seq(5)])
Partition(COMPO, [Partition(SEQ, 2), Partition(SEQ, 5)])