-
Notifications
You must be signed in to change notification settings - Fork 150
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: Expression system. #132
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
//! This module defines bound expressions. | ||
|
||
use crate::expr::Operator; | ||
use crate::spec::{Literal, NestedFieldRef}; | ||
|
||
/// Bound expression. | ||
pub enum Bound { | ||
/// Constants such as 1, 'a', true, false, null. | ||
Literal(Literal), | ||
/// Reference to some field in schema | ||
Reference { | ||
/// Nested field found in schema. | ||
field: NestedFieldRef, | ||
}, | ||
/// Expressions | ||
Expr { | ||
/// Operator for this expression, such as `And`, `Or`, `IsNull`, `Eq`, `LessThan`. | ||
op: Operator, | ||
/// Arguments for this expression. For example, `a > b` would have `a` and `b` as [`inputs`] | ||
inputs: Vec<Bound>, | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
//! This module contains expressions used in apache iceberg. | ||
liurenjie1024 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
mod bound; | ||
pub use bound::*; | ||
amogh-jahagirdar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mod unbound; | ||
pub use unbound::*; | ||
|
||
/// Operators used in expressions. | ||
#[allow(missing_docs)] | ||
pub enum Operator { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is an Enum appropriate here? In Python we carry for example the invert on the Operators itself: https://github.com/apache/iceberg-python/blob/main/pyiceberg/expressions/__init__.py#L491-L498
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The design here is a little different from python. Expressions are classified into two categories:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the short review last time, let me give a bit more context here. I hope it helps to understand my concern. The main challenge with using statistics to prune datafiles is that they are truncated. This is both the case for Iceberg statistics and Parquet statistics as well. By default on Iceberg a If we start pruning based on two columns we need to have a big test suite to make sure that everything works correctly (there are a lot of edge cases such as UTF8) overflow. I also don't think that comparing two columns is the most commonly used scenario, so I'd rather postpone it for now. What I think that's going to be asked for in the foreseeable future is applying transforms, such as |
||
IsNull, | ||
NotNull, | ||
IsNan, | ||
NotNan, | ||
LessThan, | ||
LessThanOrEq, | ||
GreaterThan, | ||
GreaterThanOrEq, | ||
Eq, | ||
NotEq, | ||
In, | ||
NotIn, | ||
Not, | ||
And, | ||
Or, | ||
StartsWith, | ||
NotStartsWith, | ||
Count, | ||
CountStar, | ||
Max, | ||
Min, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are aggregations, do we want them in here as well? Mostly because they don't evaluate as a boolean expression on its own. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see java implementation has aggregations: https://github.com/apache/iceberg/blob/8271791061e72dbf554028e477746e89fca9ec02/api/src/main/java/org/apache/iceberg/expressions/Expression.java#L47 I think this is meaningful since we can do optimization with aggregations. For example, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those aggregations are tricky, since we need to if the min/max aren't truncated. I also see value in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that aggregation pushdown optimizations can be very powerful but I'd argue that we don't add the expression until we actually use those. It makes maintaining public APIs easier until we have a need. That was the same model followed in the Java expression case (the count/max/min expression was only added when Spark aggregation pushdown was worked on). Let me know what you think @liurenjie1024 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds reasonable to me. We can remove this first. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
//! This module defines unbound expressions. | ||
|
||
use crate::error::Result; | ||
use crate::expr::bound::Bound; | ||
use crate::expr::Operator; | ||
use crate::spec::{Literal, Schema}; | ||
|
||
/// Unbound expressions. | ||
pub enum Unbound { | ||
/// Constants, such as 1, 'a', true, false, null. | ||
Literal(Literal), | ||
liurenjie1024 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// References to fields, such as `col` or `tbl.col`. | ||
Reference(String), | ||
/// Expressions | ||
Expr { | ||
/// Operator for this expression, such as `AND` or `OR`. | ||
operator: Operator, | ||
/// Arguments of this express. | ||
liurenjie1024 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
inputs: Vec<Unbound>, | ||
}, | ||
} | ||
|
||
impl Unbound { | ||
/// Bind expression to schema. | ||
pub fn bind(&self, _schema: &Schema, _case_sensitive: bool) -> Result<Bound> { | ||
todo!() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,5 +44,6 @@ mod avro; | |
pub mod io; | ||
pub mod spec; | ||
|
||
pub mod expr; | ||
pub mod transaction; | ||
pub mod transform; |
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.
The only thing I'm unsure about is having a Literal as a bound. It feels counterintuitive to me since you cannot bind a literal.
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 is for completeness of the model of an expression.
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.
Should we follow a model closer to what's done in the Java library? Even though literals are technically the leaf they don't extend Expression.
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.
Seems like this model is not familiar to people in iceberg community. I think it's worth to refactor it to a model easier to read.