Skip to content

Commit

Permalink
support to_nullable(decimal)
Browse files Browse the repository at this point in the history
  • Loading branch information
TCeason committed Feb 23, 2023
1 parent 3992e8c commit b59fa70
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
20 changes: 6 additions & 14 deletions src/query/expression/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1330,14 +1330,12 @@ impl From<&DataType> for ArrowDataType {
DataType::Number(ty) => with_number_type!(|TYPE| match ty {
NumberDataType::TYPE => ArrowDataType::TYPE,
}),
DataType::Decimal(ty) => match ty {
DecimalDataType::Decimal128(s) => {
ArrowDataType::Decimal(s.precision.into(), s.scale.into())
}
DecimalDataType::Decimal256(s) => {
ArrowDataType::Decimal256(s.precision.into(), s.scale.into())
}
},
DataType::Decimal(DecimalDataType::Decimal128(s)) => {
ArrowDataType::Decimal(s.precision.into(), s.scale.into())
}
DataType::Decimal(DecimalDataType::Decimal256(s)) => {
ArrowDataType::Decimal256(s.precision.into(), s.scale.into())
}
DataType::Timestamp => ArrowDataType::Timestamp(TimeUnit::Microsecond, None),
DataType::Date => ArrowDataType::Date32,
DataType::Nullable(ty) => ty.as_ref().into(),
Expand Down Expand Up @@ -1374,12 +1372,6 @@ impl From<&DataType> for ArrowDataType {
Box::new(ArrowDataType::LargeBinary),
None,
),
DataType::Decimal(DecimalDataType::Decimal128(s)) => {
ArrowDataType::Decimal(s.precision as usize, s.scale as usize)
}
DataType::Decimal(DecimalDataType::Decimal256(s)) => {
ArrowDataType::Decimal256(s.precision as usize, s.scale as usize)
}

_ => unreachable!(),
}
Expand Down
7 changes: 0 additions & 7 deletions src/query/expression/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ use crate::deserializations::TimestampDeserializer;
use crate::deserializations::TupleDeserializer;
use crate::deserializations::VariantDeserializer;
use crate::property::Domain;
use crate::types::decimal::DecimalScalar;
use crate::values::Column;
use crate::values::Scalar;
use crate::ColumnBuilder;
Expand Down Expand Up @@ -299,12 +298,6 @@ impl DataType {
Scalar::Tuple(tys.iter().map(|ty| ty.default_value()).collect())
}
DataType::Variant => Scalar::Variant(vec![]),
DataType::Decimal(DecimalDataType::Decimal128(s)) => {
Scalar::Decimal(DecimalScalar::Decimal128(0.into(), *s))
}
DataType::Decimal(DecimalDataType::Decimal256(s)) => {
Scalar::Decimal(DecimalScalar::Decimal256(0.into(), *s))
}

_ => unimplemented!(),
}
Expand Down
1 change: 1 addition & 0 deletions src/query/expression/src/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,7 @@ impl ColumnBuilder {
(ColumnBuilder::Null { len }, ScalarRef::Null) => *len += 1,
(ColumnBuilder::EmptyArray { len }, ScalarRef::EmptyArray) => *len += 1,
(ColumnBuilder::Number(builder), ScalarRef::Number(value)) => builder.push(value),
(ColumnBuilder::Decimal(builder), ScalarRef::Decimal(value)) => builder.push(value),
(ColumnBuilder::Boolean(builder), ScalarRef::Boolean(value)) => builder.push(value),
(ColumnBuilder::String(builder), ScalarRef::String(value)) => {
builder.put_slice(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ drop table if exists t
statement ok
drop table if exists t1

statement ok
drop table if exists t2

statement ok
create table t(c1 decimal(38,2))

Expand Down Expand Up @@ -361,8 +364,26 @@ select * from t order by c1
statement error 1002
select * from t1 order by c1

statement ok
create table t2(c1 decimal(6,2) null)

statement ok
insert into t2 values(1.23)

statement ok
insert into t2 values(null);

query T
select * from t2 order by c1 asc
----
1.23
NULL

statement ok
drop table if exists t

statement ok
drop table if exists t1

statement ok
drop table if exists t2

0 comments on commit b59fa70

Please sign in to comment.