Skip to content

Commit

Permalink
refactor(DataType): cleanup outdated helpers (#7685)
Browse files Browse the repository at this point in the history
The following 2 helpers are no longer used in any place: `is_type_encodable`, `mem_cmp_eq_value_enc`.

Note: right now all DataTypes are encodable in memcomparable format. We will reintroduce the difference and disallow certain types from being used as memcomparable later.

Approved-By: liurenjie1024
  • Loading branch information
xiangjinwu authored Feb 6, 2023
1 parent b996ba1 commit 167afb3
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 28 deletions.
12 changes: 0 additions & 12 deletions src/common/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,18 +342,6 @@ impl DataType {
}
}

/// Checks if memcomparable encoding of datatype is equivalent to its value encoding.
pub fn mem_cmp_eq_value_enc(&self) -> bool {
use DataType::*;
match self {
Boolean | Int16 | Int32 | Int64 => true,
Float32 | Float64 | Decimal | Date | Varchar | Time | Timestamp | Timestamptz
| Interval | Bytea => false,
Struct(t) => t.fields.iter().all(|dt| dt.mem_cmp_eq_value_enc()),
List { datatype } => datatype.mem_cmp_eq_value_enc(),
}
}

pub fn new_struct(fields: Vec<DataType>, field_names: Vec<String>) -> Self {
Self::Struct(
StructType {
Expand Down
17 changes: 1 addition & 16 deletions src/common/src/util/encoding_for_comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,9 @@ use itertools::Itertools;
use crate::array::{ArrayImpl, DataChunk};
use crate::error::Result;
use crate::row::OwnedRow;
use crate::types::{memcmp_serialize_datum_into, DataType, ScalarRefImpl};
use crate::types::{memcmp_serialize_datum_into, ScalarRefImpl};
use crate::util::sort_util::{OrderPair, OrderType};

/// This function is used to check whether we can perform encoding on this type.
/// TODO: based on `memcomparable`, we may support more data type in the future.
pub fn is_type_encodable(t: DataType) -> bool {
matches!(
t,
DataType::Boolean
| DataType::Int16
| DataType::Int32
| DataType::Int64
| DataType::Float32
| DataType::Float64
| DataType::Varchar
)
}

fn encode_value(value: Option<ScalarRefImpl<'_>>, order: &OrderType) -> Result<Vec<u8>> {
let mut serializer = memcomparable::Serializer::new(vec![]);
serializer.set_reverse(order == &OrderType::Descending);
Expand Down

0 comments on commit 167afb3

Please sign in to comment.