HonahX commented on code in PR #8267:
URL: https://github.com/apache/iceberg/pull/8267#discussion_r1289664294


##########
python/pyiceberg/expressions/literals.py:
##########
@@ -139,7 +139,7 @@ def literal(value: L) -> Literal[L]:
     elif isinstance(value, str):
         return StringLiteral(value)
     elif isinstance(value, UUID):
-        return UUIDLiteral(value)
+        return UUIDLiteral(value)  # type: ignore

Review Comment:
   Thanks for the explanation! I added conversions from `BinaryLiteral` to 
`UUID` and from `FixedLiteral` to `UUID`, and related tests.
   Here is a summarization of the supported conversion now:
   ```python
   from pyiceberg.expressions.literals import *
   from pyiceberg.types import *
   import uuid
   
   test_uuid = uuid.UUID('d4ccb06d-e7de-48e6-ad05-649fe8deda50')
   
   lu = literal(test_uuid)
   ls = literal('d4ccb06d-e7de-48e6-ad05-649fe8deda50')
   lbinary = literal(test_uuid.bytes)
   lfixed = literal(test_uuid.bytes).to(FixedType(16))
   
   assert lu.value == test_uuid.bytes
   assert ls.to(UUIDType()) == lu
   assert lbinary.to(UUIDType()) == lu
   assert lfixed.to(UUIDType()) == lu
   ```
   
   For conversion from `StringLiteral` to `UUID`, I think It fails because the 
console mode does not work well with `@singledispatchmethod`
   
   For example:
   ```python
   >>> i = literal('1')
   >>> i.to(IntegerType)
   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     File 
"/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/functools.py",
 line 914, in _method
       return method.__get__(obj, cls)(*args, **kwargs)
     File 
"/Users/jonasjiang/Workspace/Apache_Iceberg_ws/iceberg_python/python/pyiceberg/expressions/literals.py",
 line 519, in to
       raise TypeError(f"Cannot convert StringLiteral into {type_var}")
   TypeError: Cannot convert StringLiteral into <class 
'pyiceberg.types.IntegerType'>
   ```
   the conversion from string to int should work but it also fails
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to