Skip to content

Commit 182f4a1

Browse files
committed
preserves_order function for persist encoding
1 parent 369d9da commit 182f4a1

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/repr/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub use crate::relation::{
5959
VersionedRelationDesc,
6060
};
6161
pub use crate::row::collection::{ProtoRowCollection, RowCollection, SortedRowCollectionIter};
62-
pub use crate::row::encode::{RowColumnarDecoder, RowColumnarEncoder};
62+
pub use crate::row::encode::{preserves_order, RowColumnarDecoder, RowColumnarEncoder};
6363
pub use crate::row::iter::{IntoRowIterator, RowIterator};
6464
pub use crate::row::{
6565
datum_list_size, datum_size, datums_size, read_datum, row_size, DatumList, DatumMap,

src/repr/src/row/encode.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,52 @@ mod fixed_binary_sizes {
8484
}
8585
use fixed_binary_sizes::*;
8686

87+
/// Returns true iff the ordering of the "raw" and Persist-encoded versions of this columm would match:
88+
/// ie. `sort(encode(column)) == encode(sort(column))`. This encoding has been designed so that this
89+
/// is true for many types.
90+
pub fn preserves_order(scalar_type: &ScalarType) -> bool {
91+
match scalar_type {
92+
ScalarType::Bool
93+
| ScalarType::Int16
94+
| ScalarType::Int32
95+
| ScalarType::Int64
96+
| ScalarType::UInt16
97+
| ScalarType::UInt32
98+
| ScalarType::UInt64
99+
| ScalarType::Float32
100+
| ScalarType::Float64
101+
| ScalarType::Numeric { .. }
102+
| ScalarType::Date
103+
| ScalarType::Time
104+
| ScalarType::Timestamp { .. }
105+
| ScalarType::TimestampTz { .. }
106+
| ScalarType::Interval
107+
| ScalarType::Bytes
108+
| ScalarType::String
109+
| ScalarType::Uuid
110+
| ScalarType::MzTimestamp
111+
| ScalarType::MzAclItem
112+
| ScalarType::AclItem => true,
113+
ScalarType::Record { fields, .. } => fields
114+
.iter()
115+
.all(|(_, field_type)| preserves_order(&field_type.scalar_type)),
116+
ScalarType::PgLegacyChar
117+
| ScalarType::PgLegacyName
118+
| ScalarType::Char { .. }
119+
| ScalarType::VarChar { .. }
120+
| ScalarType::Jsonb
121+
| ScalarType::Array(_)
122+
| ScalarType::List { .. }
123+
| ScalarType::Oid
124+
| ScalarType::Map { .. }
125+
| ScalarType::RegProc
126+
| ScalarType::RegType
127+
| ScalarType::RegClass
128+
| ScalarType::Int2Vector
129+
| ScalarType::Range { .. } => false,
130+
}
131+
}
132+
87133
/// An encoder for a column of [`Datum`]s.
88134
#[derive(Debug)]
89135
struct DatumEncoder {

0 commit comments

Comments
 (0)