Skip to content

Commit 20e6170

Browse files
authored
fix decimal (#4)
1 parent 27f304d commit 20e6170

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

datafusion/core/src/catalog/information_schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ impl InformationSchemaColumnsBuilder {
508508
Float32 => (Some(24), Some(2), None),
509509
// Numbers from postgres `double` type
510510
Float64 => (Some(24), Some(2), None),
511-
Decimal(precision, scale) => {
511+
Decimal128(precision, scale) => {
512512
(Some(*precision as u64), Some(10), Some(*scale as u64))
513513
}
514514
_ => (None, None, None),

datafusion/physical-expr/src/expressions/binary.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ where
132132
{
133133
Ok(left
134134
.iter()
135-
.map(|left| left.map(|left| op(left, right)))
135+
.map(|left| left.map(|left| op(left.as_i128(), right)))
136136
.collect())
137137
}
138138

@@ -151,7 +151,7 @@ where
151151
.zip(right.iter())
152152
.map(|(left, right)| {
153153
if let (Some(left), Some(right)) = (left, right) {
154-
Some(op(left, right))
154+
Some(op(left.as_i128(), right.as_i128()))
155155
} else {
156156
None
157157
}
@@ -263,7 +263,7 @@ where
263263
.zip(right.iter())
264264
.map(|(left, right)| {
265265
if let (Some(left), Some(right)) = (left, right) {
266-
Some(op(left, right)).transpose()
266+
Some(op(left.as_i128(), right.as_i128())).transpose()
267267
} else {
268268
Ok(None)
269269
}
@@ -282,7 +282,7 @@ where
282282
left.iter()
283283
.map(|left| {
284284
if let Some(left) = left {
285-
Some(op(left, right)).transpose()
285+
Some(op(left.as_i128(), right)).transpose()
286286
} else {
287287
Ok(None)
288288
}

datafusion/physical-expr/src/expressions/in_list.rs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,45 @@ macro_rules! collection_contains_check {
254254
}};
255255
}
256256

257+
macro_rules! collection_contains_check_decimal {
258+
($ARRAY:expr, $VALUES:expr, $NEGATED:expr, $CONTAINS_NULL:expr) => {{
259+
let bool_array = if $NEGATED {
260+
// Not in
261+
if $CONTAINS_NULL {
262+
$ARRAY
263+
.iter()
264+
.map(|vop| match vop.map(|v| !$VALUES.contains(&v.as_i128())) {
265+
Some(true) => None,
266+
x => x,
267+
})
268+
.collect::<BooleanArray>()
269+
} else {
270+
$ARRAY
271+
.iter()
272+
.map(|vop| vop.map(|v| !$VALUES.contains(&v.as_i128())))
273+
.collect::<BooleanArray>()
274+
}
275+
} else {
276+
// In
277+
if $CONTAINS_NULL {
278+
$ARRAY
279+
.iter()
280+
.map(|vop| match vop.map(|v| $VALUES.contains(&v.as_i128())) {
281+
Some(false) => None,
282+
x => x,
283+
})
284+
.collect::<BooleanArray>()
285+
} else {
286+
$ARRAY
287+
.iter()
288+
.map(|vop| vop.map(|v| $VALUES.contains(&v.as_i128())))
289+
.collect::<BooleanArray>()
290+
}
291+
};
292+
ColumnarValue::Array(Arc::new(bool_array))
293+
}};
294+
}
295+
257296
// whether each value on the left (can be null) is contained in the non-null list
258297
fn in_list_utf8<OffsetSize: OffsetSizeTrait>(
259298
array: &GenericStringArray<OffsetSize>,
@@ -315,7 +354,7 @@ fn make_list_contains_decimal(
315354
})
316355
.collect::<Vec<_>>();
317356

318-
collection_contains_check!(array, values, negated, contains_null)
357+
collection_contains_check_decimal!(array, values, negated, contains_null)
319358
}
320359

321360
fn make_set_contains_decimal(
@@ -335,7 +374,7 @@ fn make_set_contains_decimal(
335374
.collect::<Vec<_>>();
336375
let native_set: HashSet<i128> = HashSet::from_iter(native_array);
337376

338-
collection_contains_check!(array, native_set, negated, contains_null)
377+
collection_contains_check_decimal!(array, native_set, negated, contains_null)
339378
}
340379

341380
fn set_contains_utf8<OffsetSize: OffsetSizeTrait>(

0 commit comments

Comments
 (0)