iceberg/spec/values/primitive.rs
1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18//! Primitive literal types
19
20use ordered_float::OrderedFloat;
21
22/// Values present in iceberg type
23#[derive(Clone, Debug, PartialOrd, PartialEq, Hash, Eq)]
24pub enum PrimitiveLiteral {
25 /// 0x00 for false, non-zero byte for true
26 Boolean(bool),
27 /// Stored as 4-byte little-endian
28 Int(i32),
29 /// Stored as 8-byte little-endian
30 Long(i64),
31 /// Stored as 4-byte little-endian
32 Float(OrderedFloat<f32>),
33 /// Stored as 8-byte little-endian
34 Double(OrderedFloat<f64>),
35 /// UTF-8 bytes (without length)
36 String(String),
37 /// Binary value (without length)
38 Binary(Vec<u8>),
39 /// Stored as 16-byte little-endian
40 Int128(i128),
41 /// Stored as 16-byte little-endian
42 UInt128(u128),
43 /// When a number is larger than it can hold
44 AboveMax,
45 /// When a number is smaller than it can hold
46 BelowMin,
47}
48
49impl PrimitiveLiteral {
50 /// Returns true if the Literal represents a primitive type
51 /// that can be a NaN, and that it's value is NaN
52 pub fn is_nan(&self) -> bool {
53 match self {
54 PrimitiveLiteral::Double(val) => val.is_nan(),
55 PrimitiveLiteral::Float(val) => val.is_nan(),
56 _ => false,
57 }
58 }
59}