def literal()

in pyiceberg/expressions/literals.py [0:0]


def literal(value: L) -> Literal[L]:
    """
    Construct an Iceberg Literal based on Python primitive data type.

    Args:
        value (Python primitive type): the value to be associated with literal.

    Example:
        from pyiceberg.expressions.literals import literal.
        >>> literal(123)
        LongLiteral(123)
    """
    if isinstance(value, float):
        return DoubleLiteral(value)  # type: ignore
    elif isinstance(value, bool):
        return BooleanLiteral(value)
    elif isinstance(value, int):
        return LongLiteral(value)
    elif isinstance(value, str):
        return StringLiteral(value)
    elif isinstance(value, UUID):
        return UUIDLiteral(value.bytes)  # type: ignore
    elif isinstance(value, bytes):
        return BinaryLiteral(value)
    elif isinstance(value, Decimal):
        return DecimalLiteral(value)
    elif isinstance(value, datetime):
        return TimestampLiteral(datetime_to_micros(value))  # type: ignore
    elif isinstance(value, date):
        return DateLiteral(date_to_days(value))  # type: ignore
    elif isinstance(value, time):
        return TimeLiteral(time_to_micros(value))  # type: ignore
    else:
        raise TypeError(f"Invalid literal value: {repr(value)}")