rdblue commented on a change in pull request #4262:
URL: https://github.com/apache/iceberg/pull/4262#discussion_r830659951



##########
File path: python/tests/expression/test_literals.py
##########
@@ -0,0 +1,665 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import math
+import uuid
+from datetime import datetime
+from decimal import Decimal
+
+import dateutil.parser
+import pytest
+from fastavro.write import LOGICAL_WRITERS
+from pytest import raises
+
+from iceberg.expression.literals import (
+    EPOCH,
+    AboveMax,
+    BaseLiteral,
+    BelowMin,
+    ComparableLiteral,
+    DateLiteral,
+    Literal,
+    StringLiteral,
+    TimestampLiteral,
+    literal,
+)
+from iceberg.types import (
+    BinaryType,
+    BooleanType,
+    DateType,
+    DecimalType,
+    DoubleType,
+    FixedType,
+    FloatType,
+    IntegerType,
+    LongType,
+    StringType,
+    TimestampType,
+    TimestamptzType,
+    TimeType,
+    UUIDType,
+)
+
+# Base
+
+
+def test_literal_from_none_error():
+    with pytest.raises(TypeError) as e:
+        literal(None)
+    assert "Unimplemented Type Literal for value" in str(e.value)
+
+
+def test_string_literal_with_none_value_error():
+    with pytest.raises(TypeError) as e:
+        StringLiteral(None)
+    assert "Cannot set value of BaseLiteral to None" in str(e.value)
+
+
[email protected](
+    "clazz",
+    [
+        Literal(),
+        BaseLiteral("baseLiteral", 123),
+        ComparableLiteral("comparableLiteral", 456),
+    ],
+)
+def test_base_class_not_implemented_error(clazz):
+    with pytest.raises(NotImplementedError):
+        clazz.to(IntegerType())
+
+
+def test_base_literal():
+    b = BaseLiteral("baseLiteral", 3.14)
+    assert repr(b) == "baseLiteral"
+    assert str(b) == "3.14"
+    assert b.value == 3.14
+
+
+# Numeric
+
+
+def test_numeric_literal_comparison():
+    small_lit = literal(10).to(IntegerType())
+    big_lit = literal(1000).to(IntegerType())
+    assert small_lit != big_lit
+    assert small_lit == literal(10)
+    assert small_lit < big_lit
+    assert small_lit <= big_lit
+    assert big_lit > small_lit
+    assert big_lit >= small_lit
+
+
+def test_integer_to_long_conversion():
+    lit = literal(34)
+    long_lit = lit.to(LongType())
+
+    assert lit.value == long_lit.value
+
+
+def test_integer_to_float_conversion():
+    lit = literal(34)
+    float_lit = lit.to(FloatType())
+
+    assert math.isclose(lit.value, float_lit.value)
+
+
+def test_integer_to_double_conversion():
+    lit = literal(34)
+    dbl_lit = lit.to(DoubleType())
+
+    assert math.isclose(lit.value, dbl_lit.value)
+
+
[email protected](
+    "decimalType, decimalValue", [(DecimalType(9, 0), "34"), (DecimalType(9, 
2), "34.00"), (DecimalType(9, 4), "34.0000")]
+)
+def test_integer_to_decimal_conversion(decimalType, decimalValue):
+    lit = literal(34)
+
+    assert lit.to(decimalType).value.as_tuple() == 
Decimal(decimalValue).as_tuple()
+
+
+def test_integer_to_date_conversion():
+    lit = literal(20220303)
+    dbl_lit = lit.to(DateType())

Review comment:
       Did you mean to rename the variable?




-- 
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