• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vortex-data / vortex / 16331938722

16 Jul 2025 10:49PM UTC coverage: 80.702% (-0.9%) from 81.557%
16331938722

push

github

web-flow
feat: build with stable rust (#3881)

120 of 173 new or added lines in 28 files covered. (69.36%)

174 existing lines in 102 files now uncovered.

41861 of 51871 relevant lines covered (80.7%)

157487.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

52.86
/vortex-array/src/compress.rs
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3

4
// TODO(ngates): make this a function on a PrimitiveArray
5
use vortex_dtype::{DType, PType};
6
use vortex_error::{VortexExpect, VortexResult};
7
use vortex_scalar::Scalar;
8

9
use crate::arrays::{ConstantArray, PrimitiveArray, PrimitiveEncoding, PrimitiveVTable};
10
use crate::compute::{cast, min_max};
11
use crate::{Array, ArrayRef, IntoArray, ToCanonical};
12

13
/// Downscale a primitive array to the narrowest PType that fits all the values.
14
pub fn downscale_integer_array(array: ArrayRef) -> VortexResult<ArrayRef> {
3,580✔
15
    if !array.is_encoding(PrimitiveEncoding.id()) {
3,580✔
16
        // This can happen if e.g. the array is ConstantArray.
17
        return Ok(array);
×
18
    }
3,580✔
19
    if array.is_empty() {
3,580✔
20
        return Ok(array);
×
21
    }
3,580✔
22
    let array = array
3,580✔
23
        .as_opt::<PrimitiveVTable>()
3,580✔
24
        .vortex_expect("Checked earlier");
3,580✔
25

26
    let Some(min_max) = min_max(array.as_ref())? else {
3,580✔
27
        // This array but be all nulls.
28
        return Ok(
×
29
            ConstantArray::new(Scalar::null(array.dtype().clone()), array.len()).into_array(),
×
30
        );
×
31
    };
32

33
    // If we can't cast to i64, then leave the array as its original type.
34
    // It's too big to downcast anyway.
35
    let Ok(min) = i64::try_from(min_max.min.value()) else {
3,580✔
36
        return Ok(array.to_array());
×
37
    };
38
    let Ok(max) = i64::try_from(min_max.max.value()) else {
3,580✔
39
        return Ok(array.to_array());
×
40
    };
41

42
    downscale_primitive_integer_array(array.clone(), min, max).map(|a| a.into_array())
3,580✔
43
}
3,580✔
44

45
/// Downscale a primitive array to the narrowest PType that fits all the values.
46
fn downscale_primitive_integer_array(
3,580✔
47
    array: PrimitiveArray,
3,580✔
48
    min: i64,
3,580✔
49
    max: i64,
3,580✔
50
) -> VortexResult<PrimitiveArray> {
3,580✔
51
    if min < 0 || max < 0 {
3,580✔
52
        // Signed
53
        if min >= i8::MIN as i64 && max <= i8::MAX as i64 {
×
54
            return cast(
×
55
                array.as_ref(),
×
56
                &DType::Primitive(PType::I8, array.dtype().nullability()),
×
57
            )?
×
58
            .to_primitive();
×
59
        }
×
60

61
        if min >= i16::MIN as i64 && max <= i16::MAX as i64 {
×
62
            return cast(
×
63
                array.as_ref(),
×
64
                &DType::Primitive(PType::I16, array.dtype().nullability()),
×
65
            )?
×
66
            .to_primitive();
×
67
        }
×
68

69
        if min >= i32::MIN as i64 && max <= i32::MAX as i64 {
×
70
            return cast(
×
71
                array.as_ref(),
×
72
                &DType::Primitive(PType::I32, array.dtype().nullability()),
×
73
            )?
×
74
            .to_primitive();
×
75
        }
×
76
    } else {
77
        // Unsigned
78
        if max <= u8::MAX as i64 {
3,580✔
79
            return cast(
2,488✔
80
                array.as_ref(),
2,488✔
81
                &DType::Primitive(PType::U8, array.dtype().nullability()),
2,488✔
UNCOV
82
            )?
×
83
            .to_primitive();
2,488✔
84
        }
1,092✔
85

86
        if max <= u16::MAX as i64 {
1,092✔
87
            return cast(
1,052✔
88
                array.as_ref(),
1,052✔
89
                &DType::Primitive(PType::U16, array.dtype().nullability()),
1,052✔
UNCOV
90
            )?
×
91
            .to_primitive();
1,052✔
92
        }
40✔
93

94
        if max <= u32::MAX as i64 {
40✔
95
            return cast(
40✔
96
                array.as_ref(),
40✔
97
                &DType::Primitive(PType::U32, array.dtype().nullability()),
40✔
UNCOV
98
            )?
×
99
            .to_primitive();
40✔
100
        }
×
101
    }
102

103
    Ok(array)
×
104
}
3,580✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc