Skip to content

Conversation

@alamb
Copy link
Contributor

@alamb alamb commented Oct 21, 2021

Which issue does this PR close?

Resolves #1159

PR is mostly tests

Sorry for what looks like a large PR :( I blame the test

Rationale for this change

See #1159

This is mostly interesting so that during constant folding / simplification we can simplify down de-generate expressions like true = false

Now that @jimexist added apache/arrow-rs#860 and @Dandandan added apache/arrow-rs#844 in arrow, this PR hooks that up

Also, it has the nice side effect benefit parquet row group pruning is now supported for boolean columns as well 🎉

What changes are included in this PR?

  1. Update to arrow 6.2.0
  2. Support =, <, <=, >, >=, !=,is distinct from, is not distinct from for BooleanArray(aka for boolean columns)
  3. Simple implementations of *_scalar_bool
  4. Many tests
  5. Update the pruning tests to reflect the fact that boolean pruning now happens

Are there any user-facing changes?

Less errors

Ok(Arc::new(BinaryExpr::new(l, op, r)))
}

// TODO file a ticket with arrow-rs to include these kernels
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
// TODO file a ticket with arrow-rs to include these kernels
// When arrow-rs has these kernels, can remove this implementation
// see https://github.com/apache/arrow-rs/issues/842

Filed ticket in arrow apache/arrow-rs#842

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FWIW @Dandandan has added these kernels upstream to Arrow so we can use 6.1.0 when that comes out (in a week or so): apache/arrow-rs#844

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jimexist has actually implemented operations like bool_lt etc in apache/arrow-rs#860 so when that is available in datafusion (next week) I will update this PR to include those operations as well

@alamb alamb marked this pull request as draft October 26, 2021 10:51
@alamb alamb changed the title Support <bool col> = <bool col> and <bool col> != <bool col> (WIP) Support <bool col> = <bool col> and <bool col> != <bool col> Oct 26, 2021
@alamb
Copy link
Contributor Author

alamb commented Nov 2, 2021

This one is waiting on arrow-rs 6.1 to be released, and then I should be able to clean it up and get it ready for a proper review

@alamb
Copy link
Contributor Author

alamb commented Nov 5, 2021

Turns out that we forgot to make the required functions public 🤦 . Will wait for arrow 6.2 to include apache/arrow-rs#913

@alamb alamb changed the title (WIP) Support <bool col> = <bool col> and <bool col> != <bool col> Support <bool col> = <bool col> and <bool col> != <bool col> Nov 15, 2021
@alamb alamb marked this pull request as ready for review November 15, 2021 19:19
@alamb alamb changed the title Support <bool col> = <bool col> and <bool col> != <bool col> Support =, <, <=, >, >=, != for BooleanArray Nov 15, 2021
@alamb alamb changed the title Support =, <, <=, >, >=, != for BooleanArray Support =, <, <=, >, >=, !=, is distinct from, is not distinct from for BooleanArray Nov 15, 2021
Copy link
Contributor Author

@alamb alamb left a comment

Choose a reason for hiding this comment

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

result
)
let result = p.prune(&statistics).unwrap();
assert_eq!(result, expected_true);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

pruning works for boolean columns now

DataType::Date64 => {
compute_op_scalar!($LEFT, $RIGHT, $OP, Date64Array)
}
DataType::Boolean => compute_bool_op_scalar!($LEFT, $RIGHT, $OP, BooleanArray),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

adding this line and the one below it adds all the new support, which is kind of cool! It is terrifying how many functions end up being called :)

// where a null array is generated for some statistics columns
// int > 1 and bool = true => c1_max > 1 and null
let expr = col("c1").gt(lit(15)).and(col("c2").eq(lit(true)));
// test row group predicate with an unknown (Null) expr
Copy link
Contributor Author

Choose a reason for hiding this comment

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

now bool stats don't result in null columns, so I needed to use a constant to get the same effect

@alamb alamb requested review from Dandandan and jimexist November 15, 2021 22:06
@alamb
Copy link
Contributor Author

alamb commented Nov 18, 2021

This PR is ready for review / analysis if/when you get a chance @jimexist / @Dandandan / @houqp / @rdettai. It looks much bigger than it is because of the tests. It is mostly about hooking up some more arrow compute kernels

There are many PRs flying in DataFusion recently 😅 fun times

Copy link
Contributor

@rdettai rdettai left a comment

Choose a reason for hiding this comment

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

Great addition @alamb ! thanks !

Copy link
Contributor Author

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks for the review @rdettai -- I'll plan to merge this one in tomorrow and file arrow-rs tickets if there are no other comments.

.expect("compute_op failed to downcast array");
// generate the scalar function name, such as lt_scalar, from the $OP parameter
// (which could have a value of lt) and the suffix _scalar
Ok(Arc::new(paste::expr! {[<$OP _bool_scalar>]}(
Copy link
Member

Choose a reason for hiding this comment

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

TIL

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the record this pattern is used elsewhere in this file, I was just following it :)

@alamb alamb merged commit 00850a4 into apache:master Nov 20, 2021
@alamb alamb deleted the alamb/bool_expr branch November 20, 2021 12:59
@alamb alamb added the enhancement New feature or request label Feb 10, 2022
unkloud pushed a commit to unkloud/datafusion that referenced this pull request Mar 23, 2025
* feat: add support for array_contains expression

* test: add unit test for array_contains function

* Removes unnecessary case expression for handling null values

* chore: Move more expressions from core crate to spark-expr crate (apache#1152)

* move aggregate expressions to spark-expr crate

* move more expressions

* move benchmark

* normalize_nan

* bitwise not

* comet scalar funcs

* update bench imports

* remove dead code (apache#1155)

* fix: Spark 4.0-preview1 SPARK-47120 (apache#1156)

## Which issue does this PR close?

Part of apache/datafusion-comet#372 and apache/datafusion-comet#551

## Rationale for this change

To be ready for Spark 4.0

## What changes are included in this PR?

This PR fixes the new test SPARK-47120 added in Spark 4.0

## How are these changes tested?

tests enabled

* chore: Move string kernels and expressions to spark-expr crate (apache#1164)

* Move string kernels and expressions to spark-expr crate

* remove unused hash kernel

* remove unused dependencies

* chore: Move remaining expressions to spark-expr crate + some minor refactoring (apache#1165)

* move CheckOverflow to spark-expr crate

* move NegativeExpr to spark-expr crate

* move UnboundColumn to spark-expr crate

* move ExpandExec from execution::datafusion::operators to execution::operators

* refactoring to remove datafusion subpackage

* update imports in benches

* fix

* fix

* chore: Add ignored tests for reading complex types from Parquet (apache#1167)

* Add ignored tests for reading structs from Parquet

* add basic map test

* add tests for Map and Array

* feat: Add Spark-compatible implementation of SchemaAdapterFactory (apache#1169)

* Add Spark-compatible SchemaAdapterFactory implementation

* remove prototype code

* fix

* refactor

* implement more cast logic

* implement more cast logic

* add basic test

* improve test

* cleanup

* fmt

* add support for casting unsigned int to signed int

* clippy

* address feedback

* fix test

* fix: Document enabling comet explain plan usage in Spark (4.0) (apache#1176)

* test: enabling Spark tests with offHeap requirement (apache#1177)

## Which issue does this PR close?

## Rationale for this change

After apache/datafusion-comet#1062 We have not running Spark tests for native execution

## What changes are included in this PR?

Removed the off heap requirement for testing

## How are these changes tested?

Bringing back Spark tests for native execution

* feat: Improve shuffle metrics (second attempt) (apache#1175)

* improve shuffle metrics

* docs

* more metrics

* refactor

* address feedback

* fix: stddev_pop should not directly return 0.0 when count is 1.0 (apache#1184)

* add test

* fix

* fix

* fix

* feat: Make native shuffle compression configurable and respect `spark.shuffle.compress` (apache#1185)

* Make shuffle compression codec and level configurable

* remove lz4 references

* docs

* update comment

* clippy

* fix benches

* clippy

* clippy

* disable test for miri

* remove lz4 reference from proto

* minor: move shuffle classes from common to spark (apache#1193)

* minor: refactor decodeBatches to make private in broadcast exchange (apache#1195)

* minor: refactor prepare_output so that it does not require an ExecutionContext (apache#1194)

* fix: fix missing explanation for then branch in case when (apache#1200)

* minor: remove unused source files (apache#1202)

* chore: Upgrade to DataFusion 44.0.0-rc2 (apache#1154)

* move aggregate expressions to spark-expr crate

* move more expressions

* move benchmark

* normalize_nan

* bitwise not

* comet scalar funcs

* update bench imports

* save

* save

* save

* remove unused imports

* clippy

* implement more hashers

* implement Hash and PartialEq

* implement Hash and PartialEq

* implement Hash and PartialEq

* benches

* fix ScalarUDFImpl.return_type failure

* exclude test from miri

* ignore correct test

* ignore another test

* remove miri checks

* use return_type_from_exprs

* Revert "use return_type_from_exprs"

This reverts commit febc1f1ec1301f9b359fc23ad6a117224fce35b7.

* use DF main branch

* hacky workaround for regression in ScalarUDFImpl.return_type

* fix repo url

* pin to revision

* bump to latest rev

* bump to latest DF rev

* bump DF to rev 9f530dd

* add Cargo.lock

* bump DF version

* no default features

* Revert "remove miri checks"

This reverts commit 4638fe3aa5501966cd5d8b53acf26c698b10b3c9.

* Update pin to DataFusion e99e02b

* update pin

* Update Cargo.toml

Bump to 44.0.0-rc2

* update cargo lock

* revert miri change

---------

Co-authored-by: Andrew Lamb <[email protected]>

* update UT

Signed-off-by: Dharan Aditya <[email protected]>

* fix typo in UT

Signed-off-by: Dharan Aditya <[email protected]>

---------

Signed-off-by: Dharan Aditya <[email protected]>
Co-authored-by: Andy Grove <[email protected]>
Co-authored-by: KAZUYUKI TANIMURA <[email protected]>
Co-authored-by: Parth Chandra <[email protected]>
Co-authored-by: Liang-Chi Hsieh <[email protected]>
Co-authored-by: Raz Luvaton <[email protected]>
Co-authored-by: Andrew Lamb <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support boolean == boolean and boolean != boolean operators

3 participants