-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Field::Index to Field::Name expr transform #1894
Merged
Merged
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
0d0b59e
add hash to vortex-expr and therefore vortex-scalar
joseph-isaacs b2453a4
use dyn-hash
joseph-isaacs e8b7d94
clippy
joseph-isaacs 4314b62
fix
joseph-isaacs f122076
derive hash impl PartialEq
joseph-isaacs f91f062
wip
joseph-isaacs ca5253e
wip
joseph-isaacs aff1c14
wip
joseph-isaacs e1211bc
wip
joseph-isaacs e917d73
wip
joseph-isaacs 9d47a02
Merge branch 'develop' into ji/rescope-exprs
joseph-isaacs 0e54bb6
rescope exprs
joseph-isaacs 912387e
Merge branch 'develop' into ji/rescope-exprs
joseph-isaacs c379aec
no dt
joseph-isaacs b4fa31e
update
joseph-isaacs fa0c6ac
update
joseph-isaacs 2a0e675
update
joseph-isaacs 2ce862a
update
joseph-isaacs 7789787
update
joseph-isaacs abf15be
update
joseph-isaacs 8ee6e0b
no add
joseph-isaacs 4697fb0
added idx -> name transform for get item
joseph-isaacs 3ae8e01
update
joseph-isaacs e979bff
dead code
joseph-isaacs 4a99e91
Merge
gatesn 6ef4e20
Fix conflicts
gatesn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use vortex_error::VortexResult; | ||
|
||
use crate::traversal::{FoldChildren, FoldUp, FolderMut, Node}; | ||
use crate::{ExprRef, GetItem, Pack}; | ||
|
||
pub struct ExprSimplify(); | ||
|
||
impl ExprSimplify { | ||
pub fn simplify(e: ExprRef) -> VortexResult<ExprRef> { | ||
let mut folder = ExprSimplify(); | ||
e.transform_with_context(&mut folder, ()) | ||
.map(|e| e.result()) | ||
} | ||
} | ||
|
||
impl FolderMut for ExprSimplify { | ||
type NodeTy = ExprRef; | ||
type Out = ExprRef; | ||
type Context = (); | ||
|
||
fn visit_up( | ||
&mut self, | ||
node: Self::NodeTy, | ||
_context: Self::Context, | ||
children: FoldChildren<Self::Out>, | ||
) -> VortexResult<FoldUp<Self::Out>> { | ||
if let Some(get_item) = node.as_any().downcast_ref::<GetItem>() { | ||
if let Some(pack) = get_item.child().as_any().downcast_ref::<Pack>() { | ||
let expr = pack.field(get_item.field())?; | ||
return Ok(FoldUp::Continue(expr)); | ||
} | ||
} | ||
Ok(FoldUp::Continue( | ||
node.replacing_children(children.contained_children()), | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
use vortex_array::{ArrayDType, Canonical, IntoArrayData}; | ||
use vortex_dtype::DType; | ||
use vortex_error::{vortex_bail, VortexResult}; | ||
|
||
use crate::traversal::{MutNodeVisitor, Node, TransformResult}; | ||
use crate::{ExprRef, GetItem}; | ||
|
||
pub struct FieldToNameTransform { | ||
ident_dt: DType, | ||
} | ||
|
||
impl FieldToNameTransform { | ||
fn new(ident_dt: DType) -> Self { | ||
Self { ident_dt } | ||
} | ||
|
||
pub fn transform(expr: ExprRef, ident_dt: DType) -> VortexResult<ExprRef> { | ||
let mut visitor = FieldToNameTransform::new(ident_dt); | ||
expr.transform(&mut visitor).map(|node| node.result) | ||
} | ||
} | ||
|
||
impl MutNodeVisitor for FieldToNameTransform { | ||
type NodeTy = ExprRef; | ||
|
||
fn visit_up(&mut self, node: Self::NodeTy) -> VortexResult<TransformResult<Self::NodeTy>> { | ||
if let Some(get_item) = node.as_any().downcast_ref::<GetItem>() { | ||
if get_item.field().is_named() { | ||
return Ok(TransformResult::no(node)); | ||
} | ||
|
||
// TODO(joe) expr::dtype | ||
let child_dtype = get_item | ||
.child() | ||
.evaluate(&Canonical::empty(&self.ident_dt)?.into_array())? | ||
.dtype() | ||
.clone(); | ||
|
||
let DType::Struct(s_dtype, _) = child_dtype else { | ||
vortex_bail!( | ||
"get_item requires child to have struct dtype, however it was {}", | ||
child_dtype | ||
); | ||
}; | ||
|
||
return Ok(TransformResult::yes(GetItem::new_expr( | ||
get_item.field().clone().into_named_field(s_dtype.names())?, | ||
get_item.child().clone(), | ||
))); | ||
} | ||
|
||
Ok(TransformResult::no(node)) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use vortex_dtype::Nullability::NonNullable; | ||
use vortex_dtype::PType::I32; | ||
use vortex_dtype::{DType, StructDType}; | ||
|
||
use crate::transform::field_type::FieldToNameTransform; | ||
use crate::{get_item, ident}; | ||
|
||
#[test] | ||
fn test_idx_to_name_expr() { | ||
let dtype = DType::Struct( | ||
StructDType::new( | ||
vec!["a".into(), "b".into()].into(), | ||
vec![ | ||
DType::Struct( | ||
StructDType::new( | ||
vec!["c".into(), "d".into()].into(), | ||
vec![I32.into(), I32.into()], | ||
), | ||
NonNullable, | ||
), | ||
DType::Struct( | ||
StructDType::new( | ||
vec!["e".into(), "f".into()].into(), | ||
vec![I32.into(), I32.into()], | ||
), | ||
NonNullable, | ||
), | ||
], | ||
), | ||
NonNullable, | ||
); | ||
let expr = get_item(1, get_item("a", ident())); | ||
let new_expr = FieldToNameTransform::transform(expr, dtype.clone()).unwrap(); | ||
assert_eq!(&new_expr, &get_item("d", get_item("a", ident()))); | ||
|
||
let expr = get_item(0, get_item(1, ident())); | ||
let new_expr = FieldToNameTransform::transform(expr, dtype).unwrap(); | ||
assert_eq!(&new_expr, &get_item("e", get_item("b", ident()))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#[allow(dead_code)] | ||
mod expr_simplify; | ||
mod field_type; | ||
#[allow(dead_code)] | ||
mod project_expr; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you write a doc string please. And also one for
new
since it's not obvious to me what ident_dt means? It's too abbreviated