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
//! This module provides utility functions for working with Arrow schemas in the context of Proof of SQL.
//! It includes functionality to convert Arrow schemas to PoSQL-compatible formats.
use alloc::sync::Arc;
use arrow::datatypes::{DataType, Field, Schema, SchemaRef};
/// Converts an Arrow schema to a PoSQL-compatible schema.
///
/// This function takes an Arrow `SchemaRef` and returns a new `SchemaRef` where
/// floating-point data types (Float16, Float32, Float64) are converted to Decimal256(75, 30).
/// Other data types remain unchanged.
///
/// # Arguments
///
/// * `schema` - The input Arrow schema to convert.
///
/// # Returns
///
/// A new `SchemaRef` with PoSQL-compatible data types.
#[must_use]
pub fn get_posql_compatible_schema(schema: &SchemaRef) -> SchemaRef {
let new_fields: Vec<Field> = schema
.fields()
.iter()
.map(|field| {
let new_data_type = match field.data_type() {
DataType::Float16 | DataType::Float32 | DataType::Float64 => {
DataType::Decimal256(20, 10)
}
_ => field.data_type().clone(),
};
Field::new(field.name(), new_data_type, field.is_nullable())
})
.collect();
Arc::new(Schema::new(new_fields))
}