-
Notifications
You must be signed in to change notification settings - Fork 214
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!: remove table_length
from ProofExpr::result_evaluate
and return ColumnarValue
#334
Conversation
table_length
from ProofExpr::result_evaluate
table_length
from ProofExpr::result_evaluate
b1d74e6
to
327ebb1
Compare
327ebb1
to
ef6b931
Compare
2b92209
to
bbff8fb
Compare
bbff8fb
to
3e7cd99
Compare
3e7cd99
to
0835eab
Compare
table_length
from ProofExpr::result_evaluate
table_length
from ProofExpr::result_evaluate
and return ColumnarValue
d17b716
to
e8e94a5
Compare
let rhs_columnar_value: ColumnarValue<'a, S> = self.rhs.result_evaluate(alloc, accessor); | ||
lhs_columnar_value | ||
.apply_boolean_binary_operator(&rhs_columnar_value, BinaryOperator::And, alloc) | ||
.expect("Failed to apply boolean binary operator") |
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.
This expect
also wouldn't be needed if you do my suggestion above.
let is_literal = matches!( | ||
(&lhs_columnar_value, &rhs_columnar_value), | ||
(&ColumnarValue::Literal(_), &ColumnarValue::Literal(_)) | ||
); | ||
let lhs_scale = self.lhs.data_type().scale().unwrap_or(0); | ||
let rhs_scale = self.rhs.data_type().scale().unwrap_or(0); | ||
let res = scale_and_subtract(alloc, lhs_column, rhs_column, lhs_scale, rhs_scale, true) | ||
.expect("Failed to scale and subtract"); | ||
Column::Boolean(result_evaluate_equals_zero(table_length, alloc, res)) | ||
let res = scale_and_subtract_columnar_value( | ||
alloc, | ||
lhs_columnar_value, | ||
rhs_columnar_value, | ||
lhs_scale, | ||
rhs_scale, | ||
true, | ||
) | ||
.expect("Failed to scale and subtract"); | ||
let raw_result = result_evaluate_equals_zero(res.len(), alloc, res); | ||
if is_literal { | ||
ColumnarValue::Literal(LiteralValue::Boolean(raw_result[0])) | ||
} else { | ||
ColumnarValue::Column(Column::Boolean(raw_result)) | ||
} |
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.
Using an is_literal
flag and returning a length 1 slice for Literals is very messy.
This code would be extremely difficult to modify in the future.
At this point, I think the result_evaluate_equals_zero
is outdated and simply needs to be replaced with a proper solution.
There's no reason this can't look very similar to what the AndExpr::result_evaluate
now looks like.
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.
See #342 for a better alternative to the changes in this file.
let is_literal = matches!( | ||
(&lhs_columnar_value, &rhs_columnar_value), | ||
(&ColumnarValue::Literal(_), &ColumnarValue::Literal(_)) | ||
); | ||
let lhs_scale = self.lhs.data_type().scale().unwrap_or(0); | ||
let rhs_scale = self.rhs.data_type().scale().unwrap_or(0); | ||
let diff = if self.is_lte { | ||
scale_and_subtract(alloc, lhs_column, rhs_column, lhs_scale, rhs_scale, false) | ||
.expect("Failed to scale and subtract") | ||
scale_and_subtract_columnar_value( | ||
alloc, | ||
lhs_columnar_value, | ||
rhs_columnar_value, | ||
lhs_scale, | ||
rhs_scale, | ||
false, | ||
) | ||
.expect("Failed to scale and subtract") | ||
} else { | ||
scale_and_subtract(alloc, rhs_column, lhs_column, rhs_scale, lhs_scale, false) | ||
.expect("Failed to scale and subtract") | ||
scale_and_subtract_columnar_value( | ||
alloc, | ||
rhs_columnar_value, | ||
lhs_columnar_value, | ||
rhs_scale, | ||
lhs_scale, | ||
false, | ||
) | ||
.expect("Failed to scale and subtract") | ||
}; | ||
let diff_len = diff.len(); | ||
|
||
// diff == 0 | ||
let equals_zero = result_evaluate_equals_zero(table_length, alloc, diff); | ||
let equals_zero = result_evaluate_equals_zero(diff_len, alloc, diff); | ||
|
||
// sign(diff) == -1 | ||
let sign = result_evaluate_sign(table_length, alloc, diff); | ||
let sign = result_evaluate_sign(diff_len, alloc, diff); | ||
|
||
// (diff == 0) || (sign(diff) == -1) | ||
Column::Boolean(result_evaluate_or(table_length, alloc, equals_zero, sign)) | ||
let raw_result = result_evaluate_or(diff_len, alloc, equals_zero, sign); | ||
if is_literal { | ||
ColumnarValue::Literal(LiteralValue::Boolean(raw_result[0])) | ||
} else { | ||
ColumnarValue::Column(Column::Boolean(raw_result)) | ||
} |
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.
Same concern here as with equality. This one is even worse.
.where_clause | ||
.result_evaluate(alloc, accessor) | ||
.into_column(input_length, alloc) | ||
.expect("Failed to convert columnar value to column"); |
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 add a # Panics
doc to ProverEvaluate
indicating that the underlying columns must all have the same length?
e8e94a5
to
bdc0f9f
Compare
Pull request was closed
bdc0f9f
to
bb46fcb
Compare
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
!
is used if and only if at least one breaking change has been introduced.source scripts/run_ci_checks.sh
.Rationale for this change
In order to make
ProofPlan
s composable it is necessary to allow one or moreProofPlan
s as the input to another. As such it is a great idea to removetable_length
as an argument inProofPlan::result_evaluate
which in turn requires removal inProofExpr
.What changes are included in this PR?
table_length
fromProofExpr::result_evaluate
and returnColumnarValue
.table_length
fromProofPlan::result_evaluate
.Are these changes tested?
Yes