Skip to content

Commit 38667e1

Browse files
map float types to real logical_type (#289)
* map float types to real logical_type * separate sessions tests to avoid blocking issues * unit test for floats datatype maped into real logical type
1 parent 17d2008 commit 38667e1

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

crates/control_plane/src/models/mod.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,12 +485,16 @@ impl ColumnInfo {
485485
| DataType::UInt8
486486
| DataType::UInt16
487487
| DataType::UInt32
488-
| DataType::UInt64
489-
| DataType::Float32 => {
488+
| DataType::UInt64 => {
490489
column_info.r#type = "fixed".to_string();
491490
column_info.precision = Some(38);
492491
column_info.scale = Some(0);
493492
}
493+
DataType::Float16 | DataType::Float32 | DataType::Float64 => {
494+
column_info.r#type = "real".to_string();
495+
column_info.precision = Some(38);
496+
column_info.scale = Some(16);
497+
}
494498
DataType::Decimal128(precision, scale) | DataType::Decimal256(precision, scale) => {
495499
column_info.r#type = "fixed".to_string();
496500
column_info.precision = Some(i32::from(*precision));
@@ -773,6 +777,25 @@ mod tests {
773777
assert_eq!(column_info.r#type, "text");
774778
assert_eq!(column_info.byte_length, None);
775779
assert_eq!(column_info.length, None);
780+
781+
let floats = [
782+
(DataType::Float16, 16, true),
783+
(DataType::Float32, 16, true),
784+
(DataType::Float64, 16, true),
785+
(DataType::Float64, 17, false),
786+
];
787+
for (float_datatype, scale, outcome) in floats {
788+
let field = Field::new("test_field", float_datatype, false);
789+
let column_info = ColumnInfo::from_field(&field);
790+
assert_eq!(column_info.name, "test_field");
791+
assert_eq!(column_info.r#type, "real");
792+
assert_eq!(column_info.precision.unwrap(), 38);
793+
if outcome {
794+
assert_eq!(column_info.scale.unwrap(), scale);
795+
} else {
796+
assert_ne!(column_info.scale.unwrap(), scale);
797+
}
798+
}
776799
}
777800

778801
#[tokio::test]

crates/control_plane/src/service.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,11 @@ mod tests {
804804
assert!(result.is_ok());
805805
let sessions = service.df_sessions.read().await;
806806
assert!(!sessions.contains_key(&session_id));
807+
}
807808

809+
#[tokio::test]
810+
async fn test_delete_non_existent_session() {
811+
let service = service();
808812
let session_id = "non_existent_session".to_string();
809813
let result = service.delete_session(session_id.clone()).await;
810814
assert!(result.is_ok());

crates/control_plane/src/utils.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,11 @@ mod tests {
503503
assert_eq!(converted_timestamp_array.value(2), 1_627_846_262);
504504
}
505505

506-
#[allow(clippy::needless_pass_by_value)]
506+
#[allow(
507+
clippy::needless_pass_by_value,
508+
clippy::cast_sign_loss,
509+
clippy::cast_possible_truncation
510+
)]
507511
fn check_record_batches_uint_to_int(
508512
batches: Vec<RecordBatch>,
509513
converted_batches: Vec<RecordBatch>,
@@ -540,7 +544,10 @@ mod tests {
540544
assert_eq!(column_info.scale.unwrap(), metadata_scale);
541545
match field.data_type() {
542546
DataType::UInt64 => {
543-
assert_eq!(*converted_field.data_type(), DataType::Decimal128(38, 0));
547+
assert_eq!(
548+
*converted_field.data_type(),
549+
DataType::Decimal128(metadata_precision as u8, metadata_scale as i8)
550+
);
544551
let values: Decimal128Array = converted_column
545552
.as_any()
546553
.downcast_ref::<Decimal128Array>()

0 commit comments

Comments
 (0)