reifydb-core 0.4.12

Core database interfaces and data structures for ReifyDB
Documentation
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2025 ReifyDB

//! RowShape consolidation utilities - STUB
//!
//! This module will eventually provide functionality to:
//! - Consolidate multiple shapes into a single unified shape
//! - Widen types when merging incompatible field types
//!
//! Currently stubbed with unimplemented!() as this is out of scope
//! for the initial implementation.

use reifydb_runtime::hash::Hash64;
use reifydb_type::value::r#type::Type;

use super::RowShape;

/// Type widening rules - STUB
///
/// Future: implement proper widening hierarchy (e.g., Int4 -> Int8 -> Int16)
pub fn widen_type(a: Type, b: Type) -> Type {
	match (a, b) {
		(Type::Option(_), t) | (t, Type::Option(_)) => t,
		(ref a, ref b) if a == b => a.clone(),
		(a, b) => unimplemented!("type widening not yet supported: {:?} vs {:?}", a, b),
	}
}

/// Find widest compatible shape from multiple fingerprints - STUB
///
/// Future: this will merge shapes by:
/// 1. Finding all unique field names
/// 2. For each field, finding the widest compatible type
/// 3. Producing a new shape that can represent all input shapes
#[allow(unused_variables)]
pub fn consolidate_shapes(fingerprints: &[Hash64], lookup: impl Fn(Hash64) -> Option<RowShape>) -> RowShape {
	unimplemented!("shape consolidation not yet supported")
}

#[cfg(test)]
mod tests {
	use super::*;

	#[test]
	fn test_widen_type_same() {
		assert_eq!(widen_type(Type::Int4, Type::Int4), Type::Int4);
	}

	#[test]
	fn test_widen_type_undefined() {
		assert_eq!(widen_type(Type::Option(Box::new(Type::Boolean)), Type::Int4), Type::Int4);
		assert_eq!(widen_type(Type::Int4, Type::Option(Box::new(Type::Boolean))), Type::Int4);
	}

	#[test]
	#[should_panic(expected = "type widening not yet supported")]
	fn test_widen_type_different_panics() {
		widen_type(Type::Int4, Type::Utf8);
	}
}