File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -609,6 +609,19 @@ def to(self, type_var: IcebergType) -> Literal: # type: ignore
609609 def _ (self , _ : UUIDType ) -> Literal [bytes ]:
610610 return self
611611
612+ @to .register (FixedType )
613+ def _ (self , type_var : FixedType ) -> Literal [bytes ]:
614+ if len (type_var ) == UUID_BYTES_LENGTH :
615+ return FixedLiteral (self .value )
616+ else :
617+ raise TypeError (
618+ f"Cannot convert UUIDLiteral into { type_var } , different length: { len (type_var )} <> { UUID_BYTES_LENGTH } "
619+ )
620+
621+ @to .register (BinaryType )
622+ def _ (self , _ : BinaryType ) -> Literal [bytes ]:
623+ return BinaryLiteral (self .value )
624+
612625
613626class FixedLiteral (Literal [bytes ]):
614627 def __init__ (self , value : bytes ) -> None :
Original file line number Diff line number Diff line change @@ -758,7 +758,6 @@ def test_invalid_uuid_conversions() -> None:
758758 DecimalType (9 , 2 ),
759759 StringType (),
760760 FixedType (1 ),
761- BinaryType (),
762761 ],
763762 )
764763
@@ -882,6 +881,25 @@ def test_uuid_literal_initialization() -> None:
882881 assert test_uuid .bytes == uuid_literal .value
883882
884883
884+ def test_uuid_to_fixed () -> None :
885+ test_uuid = uuid .uuid4 ()
886+ uuid_literal = literal (test_uuid )
887+ fixed_literal = uuid_literal .to (FixedType (16 ))
888+ assert test_uuid .bytes == fixed_literal .value
889+ with pytest .raises (TypeError ) as e :
890+ uuid_literal .to (FixedType (15 ))
891+ assert "Cannot convert UUIDLiteral into fixed[15], different length: 15 <> 16" in str (e .value )
892+ assert isinstance (fixed_literal , FixedLiteral ) # type: ignore
893+
894+
895+ def test_uuid_to_binary () -> None :
896+ test_uuid = uuid .uuid4 ()
897+ uuid_literal = literal (test_uuid )
898+ binary_literal = uuid_literal .to (BinaryType ())
899+ assert test_uuid .bytes == binary_literal .value
900+ assert isinstance (binary_literal , BinaryLiteral ) # type: ignore
901+
902+
885903# __ __ ___
886904# | \/ |_ _| _ \_ _
887905# | |\/| | || | _/ || |
You can’t perform that action at this time.
0 commit comments