Skip to content
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

feat: add column_struct_operation.rs #333

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

iajoiner
Copy link
Contributor

@iajoiner iajoiner commented Nov 1, 2024

Please be sure to look over the pull request guidelines here: https://github.com/spaceandtimelabs/sxt-proof-of-sql/blob/main/CONTRIBUTING.md#submit-pr.

Please go through the following checklist

Rationale for this change

The equivalent of owned_column_operation.rs for Columns.

What changes are included in this PR?

Are these changes tested?

@iajoiner iajoiner force-pushed the feat/column-ops branch 6 times, most recently from 9dd1011 to c115121 Compare November 1, 2024 20:57
@iajoiner iajoiner marked this pull request as ready for review November 3, 2024 05:04

/// Element-wise equality check for two columns
#[allow(clippy::too_many_lines)]
pub fn element_wise_eq(&self, rhs: &Self, alloc: &'a Bump) -> ColumnOperationResult<Self> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all of these functions are identical (I think), could we just replace them all with a single function that we can pass in a few slice_op parameters?

Suggested change
pub fn element_wise_eq(&self, rhs: &Self, alloc: &'a Bump) -> ColumnOperationResult<Self> {
pub fn element_wise_binary_compare_op<F,G,H>(&self, rhs: &Self, alloc: &'a Bump, slice_op: F, slice_op_with_casting: G, decimal_slice_op: H) -> ColumnOperationResult<Self> {

Not sure if the generic parameters are needed.

}
match (self, rhs) {
(Self::TinyInt(lhs), Self::TinyInt(rhs)) => Ok(Self::Boolean(
alloc.alloc_slice_copy(slice_eq(lhs, rhs).as_ref()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we change slice_eq to be the following?

pub(super) fn slice_eq<'a, T>(lhs: &'a [T], rhs: &'a [T]) -> impl Iterator<Item = bool> + 'a

That way, we can do this:

Suggested change
alloc.alloc_slice_copy(slice_eq(lhs, rhs).as_ref()),
alloc.alloc_slice_fill_iter(slice_eq(lhs, rhs)),

Alternatively, add a slice_eq_iter that is called from slice_eq to avoid refactoring existing code.


#[allow(clippy::too_many_lines)]
/// Element-wise + for two columns
pub fn element_wise_add(&self, rhs: &Self, alloc: &'a Bump) -> ColumnOperationResult<Self> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another generic function could cover all of these.
I'm not sure if there's a clever way to combine these with the comparison ones, but maybe there is.

}
match (&self, &rhs) {
(Self::TinyInt(lhs), Self::TinyInt(rhs)) => Ok(Self::TinyInt(
alloc.alloc_slice_copy(try_add_slices(lhs, rhs)?.as_ref()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here as above. I don't like unnecessary copy. This is how it could look using the process_results method from itertools:

Suggested change
alloc.alloc_slice_copy(try_add_slices(lhs, rhs)?.as_ref()),
try_add_slices(lhs, rhs).process_results(|iter| alloc.alloc_slice_copy(iter)),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants