Skip to content

Commit afebee3

Browse files
committed
chore(cubestore): Fix couple decimal tests
1 parent 0b1cdfe commit afebee3

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

rust/cubestore/cubestore/src/metastore/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,10 +571,10 @@ impl<'a> Into<Field> for &'a Column {
571571
ColumnType::Timestamp => DataType::Timestamp(Microsecond, None),
572572
ColumnType::Boolean => DataType::Boolean,
573573
ColumnType::Decimal { scale, precision } => {
574-
DataType::Decimal128(scale as u8, precision as i8)
574+
DataType::Decimal128(precision as u8, scale as i8)
575575
}
576576
ColumnType::Decimal96 { scale, precision } => {
577-
DataType::Decimal128(scale as u8, precision as i8)
577+
DataType::Decimal128(precision as u8, scale as i8)
578578
}
579579
ColumnType::Bytes => DataType::Binary,
580580
ColumnType::HyperLogLog(_) => DataType::Binary,

rust/cubestore/cubestore/src/queryplanner/query_executor.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ use crate::util::memory::MemoryHandler;
2222
use crate::{app_metrics, CubeError};
2323
use async_trait::async_trait;
2424
use core::fmt;
25-
use datafusion::arrow::array::{
26-
make_array, Array, ArrayRef, BinaryArray, BooleanArray, Float64Array, Int16Array, Int32Array,
27-
Int64Array, MutableArrayData, StringArray, TimestampMicrosecondArray, TimestampNanosecondArray,
28-
UInt16Array, UInt32Array, UInt64Array,
29-
};
25+
use datafusion::arrow::array::{make_array, Array, ArrayRef, BinaryArray, BooleanArray, Decimal128Array, Float64Array, Int16Array, Int32Array, Int64Array, MutableArrayData, StringArray, TimestampMicrosecondArray, TimestampNanosecondArray, UInt16Array, UInt32Array, UInt64Array};
3026
use datafusion::arrow::compute::SortOptions;
3127
use datafusion::arrow::datatypes::{DataType, Field, Schema, SchemaRef, TimeUnit};
3228
use datafusion::arrow::ipc::reader::StreamReader;
@@ -1694,14 +1690,14 @@ pub fn batches_to_dataframe(batches: Vec<RecordBatch>) -> Result<DataFrame, Cube
16941690
}
16951691
}
16961692
// TODO upgrade DF
1697-
// DataType::Int64Decimal(0) => convert_array!(
1698-
// array,
1699-
// num_rows,
1700-
// rows,
1701-
// Int64Decimal0Array,
1702-
// Decimal,
1703-
// (Decimal)
1704-
// ),
1693+
DataType::Decimal128(_, _) => convert_array!(
1694+
array,
1695+
num_rows,
1696+
rows,
1697+
Decimal128Array,
1698+
Decimal,
1699+
(Decimal)
1700+
),
17051701
// DataType::Int64Decimal(1) => convert_array!(
17061702
// array,
17071703
// num_rows,
@@ -1880,6 +1876,10 @@ pub fn arrow_to_column_type(arrow_type: DataType) -> Result<ColumnType, CubeErro
18801876
// scale: scale as i32,
18811877
// precision: 27,
18821878
// }),
1879+
DataType::Decimal128(precision, scale) => Ok(ColumnType::Decimal {
1880+
scale: scale as i32,
1881+
precision: precision as i32,
1882+
}),
18831883
DataType::Boolean => Ok(ColumnType::Boolean),
18841884
DataType::Int8
18851885
| DataType::Int16

rust/cubestore/cubestore/src/table/data.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,18 @@ macro_rules! match_column_type {
150150
ColumnType::Timestamp => $matcher!(Timestamp, TimestampMicrosecondBuilder, Timestamp),
151151
ColumnType::Boolean => $matcher!(Boolean, BooleanBuilder, Boolean),
152152
// TODO upgrade DF
153-
ColumnType::Decimal { .. } => $matcher!(Decimal, Decimal128Builder, Decimal),
154-
ColumnType::Decimal96 { .. } => $matcher!(Decimal, Decimal128Builder, Decimal),
153+
ColumnType::Decimal { scale, precision } => $matcher!(Decimal, Decimal128Builder, Decimal, scale, precision),
154+
ColumnType::Decimal96 { scale, precision } => $matcher!(Decimal, Decimal128Builder, Decimal, scale, precision),
155155
ColumnType::Float => $matcher!(Float, Float64Builder, Float),
156156
}
157157
}};
158158
}
159159

160160
pub fn create_array_builder(t: &ColumnType) -> Box<dyn ArrayBuilder> {
161161
macro_rules! create_builder {
162+
($type: tt, Decimal128Builder, Decimal, $scale: expr, $precision: expr) => {
163+
Box::new(Decimal128Builder::new().with_data_type(datafusion::arrow::datatypes::DataType::Decimal128(*$precision as u8, *$scale as i8)))
164+
};
162165
($type: tt, $builder: tt $(,$arg: tt)*) => {
163166
Box::new($builder::new())
164167
};

0 commit comments

Comments
 (0)