Skip to content

Commit 85e95fc

Browse files
authored
Rename ScalarValue::List to ScalarValue::Tuple (#7672)
## Summary This is a better name for what it actually is, where every value can have a different type. And given that we want `ScalarValue::Array` for list scalars soon this makes more sense. ## API Changes Renames the variant. ## Testing N/A since this is a rename. Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
1 parent e75c62c commit 85e95fc

14 files changed

Lines changed: 66 additions & 63 deletions

File tree

encodings/parquet-variant/src/operations.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ fn scalar_from_shredded_object_scalar(
214214
let fields = StructFields::new(FieldNames::from(names), dtypes);
215215
Scalar::try_new(
216216
DType::Struct(fields, Nullability::NonNullable),
217-
Some(ScalarValue::List(field_values)),
217+
Some(ScalarValue::Tuple(field_values)),
218218
)
219219
}
220220

@@ -330,7 +330,7 @@ fn parquet_variant_to_scalar(variant: PqVariant<'_, '_>) -> VortexResult<Scalar>
330330
let fields = StructFields::new(FieldNames::from(names), dtypes);
331331
Scalar::try_new(
332332
DType::Struct(fields, nn),
333-
Some(ScalarValue::List(field_values)),
333+
Some(ScalarValue::Tuple(field_values)),
334334
)?
335335
}
336336
})

vortex-array/public-api.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13960,10 +13960,10 @@ pub vortex_array::scalar::ScalarValue::Bool(bool)
1396013960

1396113961
pub vortex_array::scalar::ScalarValue::Decimal(vortex_array::scalar::DecimalValue)
1396213962

13963-
pub vortex_array::scalar::ScalarValue::List(alloc::vec::Vec<core::option::Option<vortex_array::scalar::ScalarValue>>)
13964-
1396513963
pub vortex_array::scalar::ScalarValue::Primitive(vortex_array::scalar::PValue)
1396613964

13965+
pub vortex_array::scalar::ScalarValue::Tuple(alloc::vec::Vec<core::option::Option<vortex_array::scalar::ScalarValue>>)
13966+
1396713967
pub vortex_array::scalar::ScalarValue::Utf8(vortex_buffer::string::BufferString)
1396813968

1396913969
pub vortex_array::scalar::ScalarValue::Variant(alloc::boxed::Box<vortex_array::scalar::Scalar>)

vortex-array/src/scalar/arbitrary.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn random_scalar(u: &mut Unstructured, dtype: &DType) -> Result<Scalar> {
6666
.vortex_expect("unable to construct random `Scalar`_"),
6767
DType::Struct(sdt, _) => Scalar::try_new(
6868
dtype.clone(),
69-
Some(ScalarValue::List(
69+
Some(ScalarValue::Tuple(
7070
sdt.fields()
7171
.map(|d| random_scalar(u, &d).map(|s| s.into_value()))
7272
.collect::<Result<Vec<_>>>()?,
@@ -75,7 +75,7 @@ pub fn random_scalar(u: &mut Unstructured, dtype: &DType) -> Result<Scalar> {
7575
.vortex_expect("unable to construct random `Scalar`_"),
7676
DType::List(edt, _) => Scalar::try_new(
7777
dtype.clone(),
78-
Some(ScalarValue::List(
78+
Some(ScalarValue::Tuple(
7979
iter::from_fn(|| {
8080
// Generate elements with 1/4 probability.
8181
u.arbitrary()
@@ -88,7 +88,7 @@ pub fn random_scalar(u: &mut Unstructured, dtype: &DType) -> Result<Scalar> {
8888
.vortex_expect("unable to construct random `Scalar`_"),
8989
DType::FixedSizeList(edt, size, _) => Scalar::try_new(
9090
dtype.clone(),
91-
Some(ScalarValue::List(
91+
Some(ScalarValue::Tuple(
9292
(0..*size)
9393
.map(|_| random_scalar(u, edt).map(|s| s.into_value()))
9494
.collect::<Result<Vec<_>>>()?,

vortex-array/src/scalar/constructor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl Scalar {
166166
ListKind::FixedSize => DType::FixedSizeList(element_dtype, size, nullability),
167167
};
168168

169-
Self::try_new(dtype, Some(ScalarValue::List(children)))
169+
Self::try_new(dtype, Some(ScalarValue::Tuple(children)))
170170
.vortex_expect("unable to construct a list `Scalar`")
171171
}
172172

vortex-array/src/scalar/convert/into_scalar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ where
8282
Scalar: From<T>,
8383
{
8484
fn from(vec: Vec<T>) -> Self {
85-
ScalarValue::List(
85+
ScalarValue::Tuple(
8686
vec.into_iter()
8787
.map(|elem| Scalar::from(elem).into_value())
8888
.collect(),

vortex-array/src/scalar/downcast.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,22 @@ impl Scalar {
115115

116116
/// Returns a view of the scalar as a list scalar.
117117
///
118-
/// Note that we use [`ListScalar`] to represent **both** [`List`](crate::dtype::DType::List) and
119-
/// [`FixedSizeList`](crate::dtype::DType::FixedSizeList).
118+
/// Note that we use [`ListScalar`] to represent **both** [`List`](crate::dtype::DType::List)
119+
/// and [`FixedSizeList`](crate::dtype::DType::FixedSizeList).
120120
///
121121
/// # Panics
122122
///
123-
/// Panics if the scalar does not have a [`List`](crate::dtype::DType::List) or [`FixedSizeList`](crate::dtype::DType::FixedSizeList) type.
123+
/// Panics if the scalar does not have a [`List`](crate::dtype::DType::List) or
124+
/// [`FixedSizeList`](crate::dtype::DType::FixedSizeList) type.
124125
pub fn as_list(&self) -> ListScalar<'_> {
125126
self.as_list_opt()
126127
.vortex_expect("Failed to convert scalar to list")
127128
}
128129

129130
/// Returns a view of the scalar as a list scalar if it has a list type.
130131
///
131-
/// Note that we use [`ListScalar`] to represent **both** [`List`](crate::dtype::DType::List) and
132-
/// [`FixedSizeList`](crate::dtype::DType::FixedSizeList).
132+
/// Note that we use [`ListScalar`] to represent **both** [`List`](crate::dtype::DType::List)
133+
/// and [`FixedSizeList`](crate::dtype::DType::FixedSizeList).
133134
pub fn as_list_opt(&self) -> Option<ListScalar<'_>> {
134135
ListScalar::try_new(self.dtype(), self.value()).ok()
135136
}
@@ -172,7 +173,7 @@ impl Scalar {
172173
}
173174

174175
impl ScalarValue {
175-
/// Returns the boolean value, panicking if the value is not a [`Bool`][ScalarValue::Bool].
176+
/// Returns the boolean value, panicking if the value is not a [`Bool`](ScalarValue::Bool).
176177
pub fn as_bool(&self) -> bool {
177178
match self {
178179
ScalarValue::Bool(b) => *b,
@@ -181,7 +182,7 @@ impl ScalarValue {
181182
}
182183

183184
/// Returns the primitive value, panicking if the value is not a
184-
/// [`Primitive`][ScalarValue::Primitive].
185+
/// [`Primitive`](ScalarValue::Primitive).
185186
pub fn as_primitive(&self) -> &PValue {
186187
match self {
187188
ScalarValue::Primitive(p) => p,
@@ -190,39 +191,39 @@ impl ScalarValue {
190191
}
191192

192193
/// Returns the decimal value, panicking if the value is not a
193-
/// [`Decimal`][ScalarValue::Decimal].
194+
/// [`Decimal`](ScalarValue::Decimal).
194195
pub fn as_decimal(&self) -> &DecimalValue {
195196
match self {
196197
ScalarValue::Decimal(d) => d,
197198
_ => vortex_panic!("ScalarValue is not a Decimal"),
198199
}
199200
}
200201

201-
/// Returns the UTF-8 string value, panicking if the value is not a [`Utf8`][ScalarValue::Utf8].
202+
/// Returns the UTF-8 string value, panicking if the value is not a [`Utf8`](ScalarValue::Utf8).
202203
pub fn as_utf8(&self) -> &BufferString {
203204
match self {
204205
ScalarValue::Utf8(s) => s,
205206
_ => vortex_panic!("ScalarValue is not a Utf8"),
206207
}
207208
}
208209

209-
/// Returns the binary value, panicking if the value is not a [`Binary`][ScalarValue::Binary].
210+
/// Returns the binary value, panicking if the value is not a [`Binary`](ScalarValue::Binary).
210211
pub fn as_binary(&self) -> &ByteBuffer {
211212
match self {
212213
ScalarValue::Binary(b) => b,
213214
_ => vortex_panic!("ScalarValue is not a Binary"),
214215
}
215216
}
216217

217-
/// Returns the list elements, panicking if the value is not a [`List`][ScalarValue::List].
218+
/// Returns the tuple elements, panicking if the value is not a [`Tuple`](ScalarValue::Tuple).
218219
pub fn as_list(&self) -> &[Option<ScalarValue>] {
219220
match self {
220-
ScalarValue::List(elements) => elements,
221-
_ => vortex_panic!("ScalarValue is not a List"),
221+
ScalarValue::Tuple(elements) => elements,
222+
_ => vortex_panic!("ScalarValue is not a Tuple"),
222223
}
223224
}
224225

225-
/// Returns the boolean value, panicking if the value is not a [`Bool`][ScalarValue::Bool].
226+
/// Returns the boolean value, panicking if the value is not a [`Bool`](ScalarValue::Bool).
226227
pub fn into_bool(self) -> bool {
227228
match self {
228229
ScalarValue::Bool(b) => b,
@@ -231,7 +232,7 @@ impl ScalarValue {
231232
}
232233

233234
/// Returns the primitive value, panicking if the value is not a
234-
/// [`Primitive`][ScalarValue::Primitive].
235+
/// [`Primitive`](ScalarValue::Primitive).
235236
pub fn into_primitive(self) -> PValue {
236237
match self {
237238
ScalarValue::Primitive(p) => p,
@@ -240,35 +241,35 @@ impl ScalarValue {
240241
}
241242

242243
/// Returns the decimal value, panicking if the value is not a
243-
/// [`Decimal`][ScalarValue::Decimal].
244+
/// [`Decimal`](ScalarValue::Decimal).
244245
pub fn into_decimal(self) -> DecimalValue {
245246
match self {
246247
ScalarValue::Decimal(d) => d,
247248
_ => vortex_panic!("ScalarValue is not a Decimal"),
248249
}
249250
}
250251

251-
/// Returns the UTF-8 string value, panicking if the value is not a [`Utf8`][ScalarValue::Utf8].
252+
/// Returns the UTF-8 string value, panicking if the value is not a [`Utf8`](ScalarValue::Utf8).
252253
pub fn into_utf8(self) -> BufferString {
253254
match self {
254255
ScalarValue::Utf8(s) => s,
255256
_ => vortex_panic!("ScalarValue is not a Utf8"),
256257
}
257258
}
258259

259-
/// Returns the binary value, panicking if the value is not a [`Binary`][ScalarValue::Binary].
260+
/// Returns the binary value, panicking if the value is not a [`Binary`](ScalarValue::Binary).
260261
pub fn into_binary(self) -> ByteBuffer {
261262
match self {
262263
ScalarValue::Binary(b) => b,
263264
_ => vortex_panic!("ScalarValue is not a Binary"),
264265
}
265266
}
266267

267-
/// Returns the list elements, panicking if the value is not a [`List`][ScalarValue::List].
268+
/// Returns the tuple elements, panicking if the value is not a [`Tuple`](ScalarValue::Tuple).
268269
pub fn into_list(self) -> Vec<Option<ScalarValue>> {
269270
match self {
270-
ScalarValue::List(elements) => elements,
271-
_ => vortex_panic!("ScalarValue is not a List"),
271+
ScalarValue::Tuple(elements) => elements,
272+
_ => vortex_panic!("ScalarValue is not a Tuple"),
272273
}
273274
}
274275

vortex-array/src/scalar/proto.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl From<&ScalarValue> for pb::ScalarValue {
101101
ScalarValue::Binary(v) => pb::ScalarValue {
102102
kind: Some(Kind::BytesValue(v.to_vec())),
103103
},
104-
ScalarValue::List(v) => {
104+
ScalarValue::Tuple(v) => {
105105
let mut values = Vec::with_capacity(v.len());
106106
for elem in v.iter() {
107107
values.push(ScalarValue::to_proto(elem.as_ref()));
@@ -435,7 +435,7 @@ fn bytes_from_proto(bytes: &[u8], dtype: &DType) -> VortexResult<ScalarValue> {
435435
}
436436
}
437437

438-
/// Deserialize a [`ScalarValue::List`] from a protobuf `ListValue`.
438+
/// Deserialize a [`ScalarValue::Tuple`] from a protobuf `ListValue`.
439439
fn list_from_proto(
440440
v: &ListValue,
441441
dtype: &DType,
@@ -454,7 +454,7 @@ fn list_from_proto(
454454
)?);
455455
}
456456

457-
Ok(ScalarValue::List(values))
457+
Ok(ScalarValue::Tuple(values))
458458
}
459459

460460
#[cfg(test)]
@@ -531,7 +531,7 @@ mod tests {
531531
Arc::new(DType::Primitive(PType::I32, Nullability::Nullable)),
532532
Nullability::Nullable,
533533
),
534-
Some(ScalarValue::List(vec![
534+
Some(ScalarValue::Tuple(vec![
535535
Some(ScalarValue::Primitive(42i32.into())),
536536
Some(ScalarValue::Primitive(43i32.into())),
537537
])),

vortex-array/src/scalar/scalar_value.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ pub enum ScalarValue {
3333
Utf8(BufferString),
3434
/// A binary (byte array) value.
3535
Binary(ByteBuffer),
36-
/// A list of potentially null scalar values.
37-
List(Vec<Option<ScalarValue>>),
36+
/// A tuple of potentially null scalar values.
37+
///
38+
/// Used as the underlying representation for list, fixed-size list, and struct scalars.
39+
Tuple(Vec<Option<ScalarValue>>),
3840
/// A row-specific scalar wrapped by `DType::Variant`.
3941
Variant(Box<Scalar>),
4042
}
@@ -49,17 +51,17 @@ impl ScalarValue {
4951
DType::Decimal(dt, ..) => Self::Decimal(DecimalValue::zero(dt)),
5052
DType::Utf8(_) => Self::Utf8(BufferString::empty()),
5153
DType::Binary(_) => Self::Binary(ByteBuffer::empty()),
52-
DType::List(..) => Self::List(vec![]),
54+
DType::List(..) => Self::Tuple(vec![]),
5355
DType::FixedSizeList(edt, size, _) => {
5456
let elements = (0..*size).map(|_| Some(Self::zero_value(edt))).collect();
55-
Self::List(elements)
57+
Self::Tuple(elements)
5658
}
5759
DType::Struct(fields, _) => {
5860
let field_values = fields
5961
.fields()
6062
.map(|f| Some(Self::zero_value(&f)))
6163
.collect();
62-
Self::List(field_values)
64+
Self::Tuple(field_values)
6365
}
6466
DType::Extension(ext_dtype) => {
6567
// Since we have no way to define a "zero" extension value (since we have no idea
@@ -89,14 +91,14 @@ impl ScalarValue {
8991
DType::Decimal(dt, ..) => Self::Decimal(DecimalValue::zero(dt)),
9092
DType::Utf8(_) => Self::Utf8(BufferString::empty()),
9193
DType::Binary(_) => Self::Binary(ByteBuffer::empty()),
92-
DType::List(..) => Self::List(vec![]),
94+
DType::List(..) => Self::Tuple(vec![]),
9395
DType::FixedSizeList(edt, size, _) => {
9496
let elements = (0..*size).map(|_| Self::default_value(edt)).collect();
95-
Self::List(elements)
97+
Self::Tuple(elements)
9698
}
9799
DType::Struct(fields, _) => {
98100
let field_values = fields.fields().map(|f| Self::default_value(&f)).collect();
99-
Self::List(field_values)
101+
Self::Tuple(field_values)
100102
}
101103
DType::Extension(ext_dtype) => {
102104
// Since we have no way to define a "default" extension value (since we have no idea
@@ -117,7 +119,7 @@ impl PartialOrd for ScalarValue {
117119
(ScalarValue::Decimal(a), ScalarValue::Decimal(b)) => a.partial_cmp(b),
118120
(ScalarValue::Utf8(a), ScalarValue::Utf8(b)) => a.partial_cmp(b),
119121
(ScalarValue::Binary(a), ScalarValue::Binary(b)) => a.partial_cmp(b),
120-
(ScalarValue::List(a), ScalarValue::List(b)) => a.partial_cmp(b),
122+
(ScalarValue::Tuple(a), ScalarValue::Tuple(b)) => a.partial_cmp(b),
121123
(ScalarValue::Variant(a), ScalarValue::Variant(b)) => a.partial_cmp(b),
122124
// (ScalarValue::Extension(a), ScalarValue::Extension(b)) => a.partial_cmp(b),
123125
_ => None,
@@ -156,7 +158,7 @@ impl Display for ScalarValue {
156158
write!(f, "{}", to_hex(b))
157159
}
158160
}
159-
ScalarValue::List(elements) => {
161+
ScalarValue::Tuple(elements) => {
160162
write!(f, "[")?;
161163
for (i, element) in elements.iter().enumerate() {
162164
if i > 0 {

vortex-array/src/scalar/tests/casting.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ mod tests {
152152
Some(ScalarValue::Primitive(PValue::F32(f32_value))),
153153
];
154154

155-
let scalar = Scalar::new(struct_dtype, Some(ScalarValue::List(field_values)));
155+
let scalar = Scalar::new(struct_dtype, Some(ScalarValue::Tuple(field_values)));
156156

157157
let struct_scalar = scalar.as_struct();
158158
let fields: Vec<_> = (0..3)
@@ -209,7 +209,7 @@ mod tests {
209209
))),
210210
];
211211

212-
let scalar = Scalar::new(list_dtype, Some(ScalarValue::List(elements)));
212+
let scalar = Scalar::new(list_dtype, Some(ScalarValue::Tuple(elements)));
213213

214214
let list_scalar = scalar.as_list();
215215
let elements = list_scalar.elements().unwrap();
@@ -353,7 +353,7 @@ mod tests {
353353

354354
let scalar = Scalar::new(
355355
DType::Extension(ext_dtype.erased()),
356-
Some(ScalarValue::List(field_values)),
356+
Some(ScalarValue::Tuple(field_values)),
357357
);
358358

359359
// Verify the struct field was coerced

vortex-array/src/scalar/tests/nested.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ mod tests {
311311
Arc::from(DType::Primitive(PType::U16, Nullability::Nullable)),
312312
Nullability::Nullable,
313313
),
314-
Some(ScalarValue::List(vec![
314+
Some(ScalarValue::Tuple(vec![
315315
Some(ScalarValue::Primitive(PValue::U16(6))),
316316
Some(ScalarValue::Primitive(PValue::U16(100))),
317317
])),
@@ -350,7 +350,7 @@ mod tests {
350350
Arc::from(DType::Primitive(PType::U16, Nullability::Nullable)),
351351
Nullability::Nullable,
352352
),
353-
Some(ScalarValue::List(vec![
353+
Some(ScalarValue::Tuple(vec![
354354
Some(ScalarValue::Primitive(PValue::U16(100))),
355355
Some(ScalarValue::Primitive(PValue::U16(256))), // Too large for U8
356356
Some(ScalarValue::Primitive(PValue::U16(1000))), // Too large for U8

0 commit comments

Comments
 (0)