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



##########
File path: python/tests/expression/test_literals.py
##########
@@ -0,0 +1,667 @@
+# 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 datetime
+import uuid
+from decimal import Decimal
+
+import pytest
+
+from iceberg.expression.literals import (
+    EPOCH,
+    AboveMax,
+    BelowMin,
+    DateLiteral,
+    FixedLiteral,
+    IntegerLiteral,
+    StringLiteral,
+    TimeLiteral,
+    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 "Invalid literal value: None" in str(e.value)
+
+
+# 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).to(IntegerType())
+    long_lit = lit.to(LongType())
+
+    assert lit.value == long_lit.value
+
+
+def test_integer_to_float_conversion():
+    lit = literal(34).to(IntegerType())
+    float_lit = lit.to(FloatType())
+
+    assert lit.value == float_lit.value
+
+
+def test_integer_to_double_conversion():
+    lit = literal(34).to(IntegerType())
+    dbl_lit = lit.to(DoubleType())
+
+    assert 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).to(IntegerType())
+
+    assert lit.to(decimalType).value.as_tuple() == 
Decimal(decimalValue).as_tuple()
+
+
+def test_integer_to_date_conversion():
+    one_day = "2022-03-28"
+    date_delta = (datetime.date.fromisoformat(one_day) - 
datetime.date.fromisoformat("1970-01-01")).days
+    date_lit = IntegerLiteral(date_delta).to(DateType())
+
+    assert isinstance(date_lit, DateLiteral)
+    assert date_lit.value == date_delta
+
+
+def test_long_to_integer_within_bound():
+    lit = literal(34).to(LongType())
+    int_lit = lit.to(IntegerType())
+
+    assert lit.value == int_lit.value
+
+
+def test_long_to_integer_outside_bound():
+    big_lit = literal(IntegerType.max + 1).to(LongType())
+    above_max_lit = big_lit.to(IntegerType())
+    assert above_max_lit == AboveMax()
+
+    small_lit = literal(IntegerType.min - 1).to(LongType())
+    below_min_lit = small_lit.to(IntegerType())
+    assert below_min_lit == BelowMin()
+
+
+def test_long_to_float_conversion():
+    lit = literal(34).to(LongType())
+    float_lit = lit.to(FloatType())
+
+    assert lit.value == float_lit.value
+
+
+def test_long_to_double_conversion():
+    lit = literal(34).to(LongType())
+    dbl_lit = lit.to(DoubleType())
+
+    assert lit.value == dbl_lit.value

Review comment:
       This isn't correct because the value has not been converted to float.




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