Skip to content

Commit 04c5d28

Browse files
committed
feat[vortex-array]: add
Signed-off-by: Joe Isaacs <[email protected]>
1 parent 5fcd36b commit 04c5d28

File tree

5 files changed

+42
-41
lines changed

5 files changed

+42
-41
lines changed

vortex-array/src/array/session/rewrite.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4+
use std::fmt::Debug;
45
use std::marker::PhantomData;
56
use std::sync::Arc;
67

@@ -11,17 +12,17 @@ use crate::EncodingId;
1112
use crate::array::ArrayRef;
1213
use crate::array::transform::context::ArrayRuleContext;
1314
use crate::array::transform::rules::{
14-
AnyParent, ArrayParentMatcher, ArrayParentReduceRule, ArrayReduceRule,
15+
AnyArrayParent, ArrayParentMatcher, ArrayParentReduceRule, ArrayReduceRule,
1516
};
1617
use crate::vtable::VTable;
1718

1819
/// Dynamic trait for array reduce rules
19-
pub trait DynArrayReduceRule: std::fmt::Debug + Send + Sync {
20+
pub trait DynArrayReduceRule: Debug + Send + Sync {
2021
fn reduce(&self, array: &ArrayRef, ctx: &ArrayRuleContext) -> VortexResult<Option<ArrayRef>>;
2122
}
2223

2324
/// Dynamic trait for array parent reduce rules
24-
pub trait DynArrayParentReduceRule: std::fmt::Debug + Send + Sync {
25+
pub trait DynArrayParentReduceRule: Debug + Send + Sync {
2526
fn reduce_parent(
2627
&self,
2728
array: &ArrayRef,
@@ -118,10 +119,9 @@ impl ArrayRewriteRuleRegistry {
118119
pub fn register_reduce_rule<V, R>(&self, encoding: &V::Encoding, rule: R)
119120
where
120121
V: VTable,
121-
R: 'static,
122-
R: ArrayReduceRule<V>,
122+
R: ArrayReduceRule<V> + 'static,
123123
{
124-
let adapter: ArrayReduceRuleAdapter<V, R> = ArrayReduceRuleAdapter {
124+
let adapter = ArrayReduceRuleAdapter {
125125
rule,
126126
_phantom: PhantomData,
127127
};
@@ -142,14 +142,12 @@ impl ArrayRewriteRuleRegistry {
142142
) where
143143
Child: VTable,
144144
Parent: VTable,
145-
R: 'static,
146-
R: ArrayParentReduceRule<Child, Parent>,
145+
R: ArrayParentReduceRule<Child, Parent> + 'static,
147146
{
148-
let adapter: ArrayParentReduceRuleAdapter<Child, Parent, R> =
149-
ArrayParentReduceRuleAdapter {
150-
rule,
151-
_phantom: PhantomData,
152-
};
147+
let adapter = ArrayParentReduceRuleAdapter {
148+
rule,
149+
_phantom: PhantomData,
150+
};
153151
let child_id = Child::id(child_encoding);
154152
let parent_id = Parent::id(parent_encoding);
155153
self.inner
@@ -163,14 +161,12 @@ impl ArrayRewriteRuleRegistry {
163161
pub fn register_any_parent_rule<Child, R>(&self, child_encoding: &Child::Encoding, rule: R)
164162
where
165163
Child: VTable,
166-
R: 'static,
167-
R: ArrayParentReduceRule<Child, AnyParent>,
164+
R: ArrayParentReduceRule<Child, AnyArrayParent> + 'static,
168165
{
169-
let adapter: ArrayParentReduceRuleAdapter<Child, AnyParent, R> =
170-
ArrayParentReduceRuleAdapter {
171-
rule,
172-
_phantom: PhantomData,
173-
};
166+
let adapter = ArrayParentReduceRuleAdapter {
167+
rule,
168+
_phantom: PhantomData,
169+
};
174170
let child_id = Child::id(child_encoding);
175171
self.inner
176172
.any_parent_rules

vortex-array/src/array/transform/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ mod tests;
99

1010
pub use context::ArrayRuleContext;
1111
pub use optimizer::ArrayOptimizer;
12-
pub use rules::{AnyParent, ArrayParentMatcher, ArrayParentReduceRule, ArrayReduceRule};
12+
pub use rules::{AnyArrayParent, ArrayParentMatcher, ArrayParentReduceRule, ArrayReduceRule};

vortex-array/src/array/transform/rules.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ pub trait ArrayParentMatcher: Debug + Send + Sync + 'static {
1919

2020
/// Matches any parent type (wildcard matcher)
2121
#[derive(Debug)]
22-
pub struct AnyParent;
22+
pub struct AnyArrayParent;
2323

24-
impl ArrayParentMatcher for AnyParent {
24+
impl ArrayParentMatcher for AnyArrayParent {
2525
type View<'a> = &'a ArrayRef;
2626

2727
fn try_match(parent: &ArrayRef) -> Option<Self::View<'_>> {

vortex-array/src/expr/session/rewrite.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl RewriteRuleRegistry {
156156
V: VTable,
157157
R: Debug + Send + Sync + 'static + ReduceRule<V, TypedRuleContext>,
158158
{
159-
let adapter: ReduceRuleAdapter<V, R> = ReduceRuleAdapter {
159+
let adapter = ReduceRuleAdapter {
160160
rule,
161161
_phantom: PhantomData,
162162
};
@@ -174,7 +174,7 @@ impl RewriteRuleRegistry {
174174
V: VTable,
175175
R: Debug + Send + Sync + 'static + ReduceRule<V, RuleContext>,
176176
{
177-
let adapter: ReduceRuleAdapter<V, R> = ReduceRuleAdapter {
177+
let adapter = ReduceRuleAdapter {
178178
rule,
179179
_phantom: PhantomData,
180180
};
@@ -196,7 +196,7 @@ impl RewriteRuleRegistry {
196196
Parent: VTable,
197197
R: Debug + Send + Sync + 'static + ParentReduceRule<Child, Parent, RuleContext>,
198198
{
199-
let adapter: ReduceParentRuleAdapter<Child, Parent, R> = ReduceParentRuleAdapter {
199+
let adapter = ReduceParentRuleAdapter {
200200
rule,
201201
_phantom: PhantomData,
202202
};
@@ -213,7 +213,7 @@ impl RewriteRuleRegistry {
213213
Child: VTable,
214214
R: Debug + Send + Sync + 'static + ParentReduceRule<Child, AnyParent, RuleContext>,
215215
{
216-
let adapter: ReduceParentRuleAdapter<Child, AnyParent, R> = ReduceParentRuleAdapter {
216+
let adapter = ReduceParentRuleAdapter {
217217
rule,
218218
_phantom: PhantomData,
219219
};
@@ -235,7 +235,7 @@ impl RewriteRuleRegistry {
235235
Parent: VTable,
236236
R: Debug + Send + Sync + 'static + ParentReduceRule<Child, Parent, TypedRuleContext>,
237237
{
238-
let adapter: ReduceParentRuleAdapter<Child, Parent, R> = ReduceParentRuleAdapter {
238+
let adapter = ReduceParentRuleAdapter {
239239
rule,
240240
_phantom: PhantomData,
241241
};
@@ -255,7 +255,7 @@ impl RewriteRuleRegistry {
255255
Child: VTable,
256256
R: Debug + Send + Sync + 'static + ParentReduceRule<Child, AnyParent, TypedRuleContext>,
257257
{
258-
let adapter: ReduceParentRuleAdapter<Child, AnyParent, R> = ReduceParentRuleAdapter {
258+
let adapter = ReduceParentRuleAdapter {
259259
rule,
260260
_phantom: PhantomData,
261261
};

vortex-array/src/lib.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
//! arrays can be [canonicalized](Canonical) into for ease of access in compute functions.
1414
1515
pub use array::*;
16+
use arrays::{
17+
BoolMaskedValidityRule, BoolVTable, DecimalMaskedValidityRule, DecimalVTable,
18+
ExprOptimizationRule, ExprVTable, MaskedVTable, PrimitiveMaskedValidityRule, PrimitiveVTable,
19+
StructExprPartitionRule, StructVTable,
20+
};
1621
pub use canonical::*;
1722
pub use context::*;
1823
pub use encoding::*;
@@ -23,7 +28,7 @@ use vortex_session::registry::Registry;
2328
use vortex_session::{Ref, SessionExt};
2429

2530
use crate::array::session::rewrite::ArrayRewriteRuleRegistry;
26-
use crate::array::transform::{AnyParent, ArrayOptimizer, ArrayParentReduceRule, ArrayReduceRule};
31+
use crate::array::transform::{AnyArrayParent, ArrayOptimizer, ArrayParentReduceRule, ArrayReduceRule};
2732
use crate::arrays::{
2833
BoolEncoding, ChunkedEncoding, ConstantEncoding, DecimalEncoding, ExtensionEncoding,
2934
FixedSizeListEncoding, ListEncoding, ListViewEncoding, MaskedEncoding, NullEncoding,
@@ -130,7 +135,7 @@ impl ArraySession {
130135
pub fn register_any_parent_rule<Child, R>(&self, child_encoding: &Child::Encoding, rule: R)
131136
where
132137
Child: VTable,
133-
R: 'static + ArrayParentReduceRule<Child, AnyParent>,
138+
R: 'static + ArrayParentReduceRule<Child, AnyArrayParent>,
134139
{
135140
self.rewrite_rules
136141
.register_any_parent_rule::<Child, R>(child_encoding, rule);
@@ -173,33 +178,33 @@ impl Default for ArraySession {
173178
rewrite_rules: ArrayRewriteRuleRegistry::default(),
174179
};
175180

176-
session.register_parent_rule::<arrays::BoolVTable, arrays::MaskedVTable, arrays::BoolMaskedValidityRule>(
181+
session.register_parent_rule::<BoolVTable, MaskedVTable, BoolMaskedValidityRule>(
177182
&BoolEncoding,
178183
&MaskedEncoding,
179-
arrays::BoolMaskedValidityRule,
184+
BoolMaskedValidityRule,
180185
);
181186

182-
session.register_parent_rule::<arrays::PrimitiveVTable, arrays::MaskedVTable, arrays::PrimitiveMaskedValidityRule>(
187+
session.register_parent_rule::<PrimitiveVTable, MaskedVTable, PrimitiveMaskedValidityRule>(
183188
&PrimitiveEncoding,
184189
&MaskedEncoding,
185-
arrays::PrimitiveMaskedValidityRule,
190+
PrimitiveMaskedValidityRule,
186191
);
187192

188-
session.register_parent_rule::<arrays::DecimalVTable, arrays::MaskedVTable, arrays::DecimalMaskedValidityRule>(
193+
session.register_parent_rule::<DecimalVTable, MaskedVTable, DecimalMaskedValidityRule>(
189194
&DecimalEncoding,
190195
&MaskedEncoding,
191-
arrays::DecimalMaskedValidityRule,
196+
DecimalMaskedValidityRule,
192197
);
193198

194-
session.register_parent_rule::<arrays::StructVTable, arrays::ExprVTable, arrays::StructExprPartitionRule>(
199+
session.register_parent_rule::<StructVTable, ExprVTable, StructExprPartitionRule>(
195200
&StructEncoding,
196201
&arrays::ExprEncoding,
197-
arrays::StructExprPartitionRule,
202+
StructExprPartitionRule,
198203
);
199204

200-
session.register_reduce_rule::<arrays::ExprVTable, arrays::ExprOptimizationRule>(
205+
session.register_reduce_rule::<ExprVTable, ExprOptimizationRule>(
201206
&arrays::ExprEncoding,
202-
arrays::ExprOptimizationRule,
207+
ExprOptimizationRule,
203208
);
204209

205210
session

0 commit comments

Comments
 (0)