Skip to content

Commit

Permalink
feat(query): support desc table with decimal type and support order bโ€ฆ
Browse files Browse the repository at this point in the history
โ€ฆy decmail type col
  • Loading branch information
TCeason committed Feb 18, 2023
1 parent 1b0bdd0 commit 85d8000
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/query/expression/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,12 @@ 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
10 changes: 10 additions & 0 deletions src/query/expression/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ 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::with_decimal_type;
use crate::ColumnBuilder;
use crate::ScalarRef;
use crate::TypeDeserializerImpl;
Expand Down Expand Up @@ -288,6 +290,14 @@ impl DataType {
Scalar::Tuple(tys.iter().map(|ty| ty.default_value()).collect())
}
DataType::Variant => Scalar::Variant(vec![]),
DataType::Decimal(decimal) => match decimal {
DecimalDataType::Decimal128(s) => {
Scalar::Decimal(DecimalScalar::Decimal128(0.into(), *s))
}
DecimalDataType::Decimal256(s) => {
Scalar::Decimal(DecimalScalar::Decimal256(0.into(), *s))
}
},
_ => unimplemented!(),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,30 @@ query I
SELECT ANY(CAST(2.34 AS DECIMAL(6, 2)))
----
2.34

statement ok
drop table if exists t

statement ok
drop table if exists t1

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

statement ok
create table t1(c0 int, c1 decimal(39,2))

statement ok
select * from t order by c1

## https://github.com/jorgecarleitao/parquet2/blob/main/src/schema/types/converted_type.rs#L25
## https://github.com/jorgecarleitao/arrow2/blob/main/src/io/parquet/write/schema.rs#L323
## the parquet2 and arrow2 not impl decimal256
statement error 1002
select * from t1 order by c1

statement ok
drop table if exists t

statement ok
drop table if exists t1

0 comments on commit 85d8000

Please sign in to comment.