1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Schema definitions for DataChunk
use linkrs_core::DataType;
/// Simple schema representation
#[derive(Debug, Clone)]
pub struct Schema {
pub columns: Vec<ColumnInfo>,
}
#[derive(Debug, Clone)]
pub struct ColumnInfo {
pub name: String,
/// Column data type (inferred from values if not specified)
///
/// Display-oriented lowercase string (e.g. `"int"`, `"unknown"`).
/// Use [`ColumnInfo::typed_data_type`] for the typed view.
pub data_type: String,
}
impl ColumnInfo {
/// Typed view of [`ColumnInfo::data_type`].
///
/// Unrecognized strings map to `DataType::Unknown` so display-only
/// producers never break typed consumers.
pub fn typed_data_type(&self) -> DataType {
match self.data_type.to_lowercase().as_str() {
"bool" => DataType::Bool,
"int" | "integer" | "int64" => DataType::Int,
"float" | "double" | "float64" => DataType::Float,
"string" | "str" => DataType::String,
_ => DataType::Unknown,
}
}
}
impl Schema {
pub fn new(columns: Vec<ColumnInfo>) -> Self {
Self { columns }
}
/// Build a schema from names plus resolved types.
pub fn with_typed_data_types(names: &[String], types: &[DataType]) -> Self {
let columns = names
.iter()
.enumerate()
.map(|(i, name)| {
let data_type = types
.get(i)
.map(|dt| dt.to_string().to_lowercase())
.unwrap_or_else(|| "unknown".to_string());
ColumnInfo {
name: name.clone(),
data_type,
}
})
.collect();
Self { columns }
}
pub fn empty() -> Self {
Self { columns: vec![] }
}
pub fn column_count(&self) -> usize {
self.columns.len()
}
}