-
Notifications
You must be signed in to change notification settings - Fork 750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support sort for Decimal
data type
#1487
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
and link the pr to the issue #1137 |
@yjshen Can you provide sql in the datafusion side?
sort data by desc.
|
The test data is from |
It's been used in two places in DataFusion:
|
#[tokio::test]
async fn csv_query_with_decimal_by_sql() -> Result<()> {
let mut ctx = SessionContext::new();
register_simple_aggregate_csv_with_decimal_by_sql(&mut ctx).await;
let sql = "SELECT * from aggregate_simple order by c1, c2";
let actual = execute_to_batches(&ctx, sql).await;
...
}
The error message is too long, so I cut the inner info |
(Decimal(_, _), Decimal(_, _)) => { | ||
let left: DecimalArray = DecimalArray::from(left.data().clone()); | ||
let right: DecimalArray = DecimalArray::from(right.data().clone()); | ||
Box::new(move |i, j| left.value(i).cmp(&right.value(j))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the precision
and scale
of left
and right
are not the same? In that case I don't think calling cmp
on the value is correct
If precision
and scale
are always the same, maybe we can add an assert_eq!
to make that clear
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's validated in the beginning of this function
pub fn build_compare(left: &dyn Array, right: &dyn Array) -> Result<DynComparator> {
use DataType::*;
use IntervalUnit::*;
use TimeUnit::*;
Ok(match (left.data_type(), right.data_type()) {
(a, b) if a != b => {
return Err(ArrowError::InvalidArgumentError(
"Can't compare arrays of different types".to_string(),
));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I assert it again here?
Decimal
data type
Which issue does this PR close?
Closes #1137 .
Rationale for this change
We already have
sort_decimal
but fail to sort by decimal columns in DataFusion.What changes are included in this PR?
Support decimal type for
build_compare
.Are there any user-facing changes?
No.