Skip to content

Commit 6deefb7

Browse files
authored
Add CI tests for parquet-variant crate and fix clippy (#7601)
# Which issue does this PR close? We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. - part of #6736 - Follow on to #7535 from @mkarbo # Rationale for this change While doing local development I found there were several clippy failures in the parquet-variant crate which failed when running `cargo clippy --workspace` I fixed them to get a clean run and added some CI checks to avoid in the future # What changes are included in this PR? 1. Add basic CI checks for `parquet-variant` (test, clippy, and compile) 2. Fix clippy errors # Are there any user-facing changes? No, this is all internal work only
1 parent 950f4d0 commit 6deefb7

File tree

5 files changed

+103
-28
lines changed

5 files changed

+103
-28
lines changed

.github/workflows/dev_pr/labeler.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ arrow-flight:
4444

4545
parquet:
4646
- changed-files:
47-
- any-glob-to-any-file: [ 'parquet/**/*' ]
47+
- any-glob-to-any-file:
48+
- 'parquet/**/*'
49+
- 'parquet-variant/**/*'
4850

4951
parquet-derive:
5052
- changed-files:
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
---
19+
# tests for parquet-variant crate
20+
name: "parquet-variant"
21+
22+
concurrency:
23+
group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }}
24+
cancel-in-progress: true
25+
26+
# trigger for all PRs that touch certain files and changes to main
27+
on:
28+
push:
29+
branches:
30+
- main
31+
pull_request:
32+
paths:
33+
- parquet-variant/**
34+
- .github/**
35+
36+
jobs:
37+
# test the crate
38+
linux-test:
39+
name: Test
40+
runs-on: ubuntu-latest
41+
container:
42+
image: amd64/rust
43+
steps:
44+
- uses: actions/checkout@v4
45+
with:
46+
submodules: true
47+
- name: Setup Rust toolchain
48+
uses: ./.github/actions/setup-builder
49+
- name: Test
50+
run: cargo test -p parquet-variant
51+
52+
# test compilation
53+
linux-features:
54+
name: Check Compilation
55+
runs-on: ubuntu-latest
56+
container:
57+
image: amd64/rust
58+
steps:
59+
- uses: actions/checkout@v4
60+
with:
61+
submodules: true
62+
- name: Setup Rust toolchain
63+
uses: ./.github/actions/setup-builder
64+
- name: Check compilation
65+
run: cargo check -p parquet-variant
66+
67+
clippy:
68+
name: Clippy
69+
runs-on: ubuntu-latest
70+
container:
71+
image: amd64/rust
72+
steps:
73+
- uses: actions/checkout@v4
74+
- name: Setup Rust toolchain
75+
uses: ./.github/actions/setup-builder
76+
- name: Setup Clippy
77+
run: rustup component add clippy
78+
- name: Run clippy
79+
run: cargo clippy -p parquet-variant --all-targets --all-features -- -D warnings

parquet-variant/src/decoder.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ mod tests {
112112
#[test]
113113
fn test_i8() -> Result<(), ArrowError> {
114114
let value = [
115-
0 | 3 << 2, // Primitive type for i8
115+
3 << 2, // Primitive type for i8
116116
42,
117117
];
118118
let result = decode_int8(&value)?;
@@ -124,12 +124,12 @@ mod tests {
124124
fn test_short_string() -> Result<(), ArrowError> {
125125
let value = [
126126
1 | 5 << 2, // Basic type for short string | length of short string
127-
'H' as u8,
128-
'e' as u8,
129-
'l' as u8,
130-
'l' as u8,
131-
'o' as u8,
132-
'o' as u8,
127+
b'H',
128+
b'e',
129+
b'l',
130+
b'l',
131+
b'o',
132+
b'o',
133133
];
134134
let result = decode_short_string(&value)?;
135135
assert_eq!(result, "Hello");
@@ -139,17 +139,17 @@ mod tests {
139139
#[test]
140140
fn test_string() -> Result<(), ArrowError> {
141141
let value = [
142-
0 | 16 << 2, // Basic type for short string | length of short string
142+
16 << 2, // Basic type for short string | length of short string
143143
5,
144144
0,
145145
0,
146146
0, // Length of string
147-
'H' as u8,
148-
'e' as u8,
149-
'l' as u8,
150-
'l' as u8,
151-
'o' as u8,
152-
'o' as u8,
147+
b'H',
148+
b'e',
149+
b'l',
150+
b'l',
151+
b'o',
152+
b'o',
153153
];
154154
let result = decode_long_string(&value)?;
155155
assert_eq!(result, "Hello");

parquet-variant/src/utils.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use std::fmt::Debug;
2222
use std::slice::SliceIndex;
2323

2424
#[inline]
25-
2625
pub(crate) fn slice_from_slice<I: SliceIndex<[u8]> + Clone + Debug>(
2726
bytes: &[u8],
2827
index: I,
@@ -49,7 +48,7 @@ pub(crate) fn map_try_from_slice_error(e: TryFromSliceError) -> ArrowError {
4948

5049
pub(crate) fn first_byte_from_slice(slice: &[u8]) -> Result<&u8, ArrowError> {
5150
slice
52-
.get(0)
51+
.first()
5352
.ok_or_else(|| ArrowError::InvalidArgumentError("Received empty bytes".to_string()))
5453
}
5554

parquet-variant/src/variant.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ use crate::decoder::{
1919
};
2020
use crate::utils::{array_from_slice, first_byte_from_slice, slice_from_slice, string_from_slice};
2121
use arrow_schema::ArrowError;
22-
use std::{
23-
num::TryFromIntError,
24-
ops::{Index, Range},
25-
};
22+
use std::{num::TryFromIntError, ops::Range};
2623

2724
#[derive(Clone, Debug, Copy, PartialEq)]
2825
enum OffsetSizeBytes {
@@ -251,7 +248,7 @@ impl<'m> VariantMetadata<'m> {
251248

252249
// Skipping the header byte (setting byte_offset = 1) and the dictionary_size (setting offset_index +1)
253250
let unpack = |i| self.header.offset_size.unpack_usize(self.bytes, 1, i + 1);
254-
Ok(unpack(index)?)
251+
unpack(index)
255252
}
256253

257254
/// Get the key-name by index
@@ -278,7 +275,7 @@ impl<'m> VariantMetadata<'m> {
278275
let offset_size = self.header.offset_size; // `Copy`
279276
let bytes = self.bytes;
280277

281-
let iterator = (0..self.dict_size).map(move |i| {
278+
(0..self.dict_size).map(move |i| {
282279
// This wont be out of bounds as long as dict_size and offsets have been validated
283280
// during construction via `try_new`, as it calls unpack_usize for the
284281
// indices `1..dict_size+1` already.
@@ -289,9 +286,7 @@ impl<'m> VariantMetadata<'m> {
289286
(Ok(s), Ok(e)) => Ok(s..e),
290287
(Err(e), _) | (_, Err(e)) => Err(e),
291288
}
292-
});
293-
294-
iterator
289+
})
295290
}
296291

297292
/// Get all key-names as an Iterator of strings
@@ -547,13 +542,13 @@ mod tests {
547542
OffsetSizeBytes::Three
548543
.unpack_usize(&buf_three, 0, 0)
549544
.unwrap(),
550-
0x0302_01
545+
0x030201
551546
);
552547
assert_eq!(
553548
OffsetSizeBytes::Three
554549
.unpack_usize(&buf_three, 0, 1)
555550
.unwrap(),
556-
0x0000_FF
551+
0x0000FF
557552
);
558553

559554
// Four-byte offsets (0x12345678, 0x90ABCDEF)

0 commit comments

Comments
 (0)