Skip to content

Conversation

@alamb
Copy link
Contributor

@alamb alamb commented Jul 12, 2022

Draft until:

Which issue does this PR close?

Closes #2874
Closes #2875
Closes #2873

Rationale for this change

See #2873 and #2874

TLDR is that on master, ScalarValue loses the fact that it came from a Dictionary type so casting a Scalar to a Dictionary and then converting into an array does not produce a DictionaryArray, causing #2873 and other issues

Supporting ScalarValue::Dictionary will also ensure the rest of the DataFusion machinery works as expected and without special case (e.g. specialized scalar value kernels for Dictionaries)

What changes are included in this PR?

Implement ScalarValue::Dictionary

Are there any user-facing changes?

New type of ScalarValue

@alamb alamb force-pushed the alamb/scalar_dictionaries branch 2 times, most recently from 1b0f169 to 5e08360 Compare July 14, 2022 18:42
@alamb alamb force-pushed the alamb/scalar_dictionaries branch from 5e08360 to d133fb1 Compare July 14, 2022 19:18
@github-actions github-actions bot added core Core DataFusion crate physical-expr Changes to the physical-expr crates labels Jul 14, 2022
@alamb alamb force-pushed the alamb/scalar_dictionaries branch 2 times, most recently from 701aca9 to 6044b91 Compare July 14, 2022 20:36
let month = match ScalarValue::try_from_array(results[0].column(1), 0)? {
ScalarValue::Utf8(Some(month)) => month,
s => panic!("Expected count as Int64 found {}", s.get_datatype()),
let s = ScalarValue::try_from_array(results[0].column(1), 0)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is because the dictionary encoding is preserved in the ScalarValue now

}
}

/// return the type to use to accumulate state for the specified input type
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this workaround is no longer needed 🎉

@codecov-commenter
Copy link

codecov-commenter commented Jul 14, 2022

Codecov Report

Merging #2891 (3cf218b) into master (b66dda5) will increase coverage by 0.01%.
The diff coverage is 83.88%.

❗ Current head 3cf218b differs from pull request most recent head 43bcb4b. Consider uploading reports for the commit 43bcb4b to get more accurate results

@@            Coverage Diff             @@
##           master    #2891      +/-   ##
==========================================
+ Coverage   85.32%   85.33%   +0.01%     
==========================================
  Files         273      273              
  Lines       49351    49472     +121     
==========================================
+ Hits        42108    42217     +109     
- Misses       7243     7255      +12     
Impacted Files Coverage Δ
datafusion/core/tests/path_partition.rs 85.78% <77.77%> (-0.08%) ⬇️
datafusion/common/src/scalar.rs 84.75% <82.11%> (+0.16%) ⬆️
datafusion/core/tests/sql/projection.rs 96.80% <100.00%> (+0.43%) ⬆️
...sion/physical-expr/src/aggregate/count_distinct.rs 95.01% <100.00%> (+0.30%) ⬆️
datafusion/physical-expr/src/expressions/binary.rs 95.05% <100.00%> (+0.01%) ⬆️
datafusion/expr/src/logical_plan/plan.rs 76.78% <0.00%> (-0.18%) ⬇️
datafusion/expr/src/window_frame.rs 93.27% <0.00%> (+0.84%) ⬆️
datafusion/expr/src/conditional_expressions.rs 100.00% <0.00%> (+2.56%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b66dda5...43bcb4b. Read the comment docs.

@alamb alamb force-pushed the alamb/scalar_dictionaries branch from 16ecff6 to 5b96042 Compare July 15, 2022 11:07
/// struct of nested ScalarValue
Struct(Option<Vec<ScalarValue>>, Box<Vec<Field>>),
/// Dictionary type: index type and value
Dictionary(Box<DataType>, Box<ScalarValue>),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The core change is to introduce this variant and the rest of the PR is implementing it as well as removing the partial support for Dictionaries that existed previously

_ => unreachable!("Invalid dictionary keys type: {:?}", key_type),
}
}
// explicitly enumerate unsupported types so newly added
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It took me a while to find that ScalarValue::Dictionary was missing here due to the default _ match.


check_scalar_cast(ScalarValue::Float64(None), DataType::Int16);

check_scalar_cast(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test would fail before this change

}

#[tokio::test]
async fn project_cast_dictionary() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reproducer for #2873

@alamb alamb marked this pull request as ready for review July 15, 2022 11:15
@alamb alamb requested a review from tustvold July 15, 2022 11:15
alamb and others added 2 commits July 18, 2022 06:22
Co-authored-by: Raphael Taylor-Davies <1781103+tustvold@users.noreply.github.com>
@alamb alamb merged commit 60c57cc into apache:master Jul 18, 2022
@alamb alamb deleted the alamb/scalar_dictionaries branch July 18, 2022 13:15
@ursabot
Copy link

ursabot commented Jul 18, 2022

Benchmark runs are scheduled for baseline = b66dda5 and contender = 60c57cc. 60c57cc is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate physical-expr Changes to the physical-expr crates

Projects

None yet

4 participants