Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions python/iceberg/api/transforms/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
Operation)
from ..types.types import (IntegerType,
TypeID)
from ...api.types.conversions import Conversions


class Bucket(Transform):
Expand Down Expand Up @@ -69,7 +70,7 @@ def __key(self):
return Bucket.__class__, self.n

def __repr__(self):
return "Bucket(n)" % self.n
return "Bucket[%s]" % self.n

def __str__(self):
return "bucket[%s]" % self.n
Expand Down Expand Up @@ -167,14 +168,24 @@ def can_transform(self, type_var):

class BucketByteBuffer(Bucket):
def __init__(self, n):
# super(BucketByteBuffer, self).__init__(n)
raise NotImplementedError()
super(BucketByteBuffer, self).__init__(n)

def hash(self, value):
return Bucket.MURMUR3.hash(value)

def can_transform(self, type_var):
return type_var.type_id in [TypeID.BINARY, TypeID.FIXED]


class BucketUUID(Bucket):
def __init__(self, n):
# super(BucketUUID, self).__init__(n)
raise NotImplementedError()
super(BucketUUID, self).__init__(n)

def hash(self, value):
return Bucket.MURMUR3.hash(Conversions.to_byte_buffer(TypeID.UUID, value))

def can_transform(self, type_var):
return type_var.type_id == TypeID.UUID


def to_bytes(n, length, byteorder='big'):
Expand Down
12 changes: 5 additions & 7 deletions python/tests/api/test_partition_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ def test_transforms(self):
PartitionSpec.builder_for(schema).bucket("ts", 128).build(),
PartitionSpec.builder_for(schema).bucket("dec", 128).build(),
PartitionSpec.builder_for(schema).bucket("s", 128).build(),
# todo support them
# PartitionSpec.builder_for(schema).bucket("u", 128).build(),
# PartitionSpec.builder_for(schema).bucket("f", 128).build(),
# PartitionSpec.builder_for(schema).bucket("b", 128).build(),
PartitionSpec.builder_for(schema).bucket("u", 128).build(),
PartitionSpec.builder_for(schema).bucket("f", 128).build(),
PartitionSpec.builder_for(schema).bucket("b", 128).build(),
PartitionSpec.builder_for(schema).year("d").build(),
PartitionSpec.builder_for(schema).month("d").build(),
PartitionSpec.builder_for(schema).day("d").build(),
Expand All @@ -75,9 +74,8 @@ def test_transforms(self):
PartitionSpec.builder_for(schema).truncate("l", 10).build(),
PartitionSpec.builder_for(schema).truncate("dec", 10).build(),
PartitionSpec.builder_for(schema).truncate("s", 10).build(),
# todo support them
# PartitionSpec.builder_for(schema).add_without_field_id(6, "dec_unsupported", "unsupported").build(),
# PartitionSpec.builder_for(schema).add(6, 1111, "dec_unsupported", "unsupported").build(),
PartitionSpec.builder_for(schema).add_without_field_id(6, "dec_unsupported", "unsupported").build(),
PartitionSpec.builder_for(schema).add(6, 1111, "dec_unsupported", "unsupported").build(),
]

for spec in specs:
Expand Down