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

Add support in AggregationFuzzer to compare against reference DB for non deterministic functions on unsorted inputs #9009

Closed
wants to merge 2 commits into from

Conversation

kgpai
Copy link
Contributor

@kgpai kgpai commented Mar 8, 2024

Why
Currently for aggregate functions with custom verifiers, we do not verify plans against the reference db. This is because for these functions the reference db results differ and require us to use custom verifiers - typically the ResultVerifier::compare api. The compare api requires VeloxVectors and previously the results of the reference query runner were in materialized row format and thus couldnt be called. Recently support was added to return the reference db results as velox vectors (#8880). With this we can now validate functions which require custom verifiers.

What
We add support in the AggregationFuzzer to use the new 'executeVector' api if supported by the refrence query runner, and use that to validate non deterministic functions that require a custom verifier.

Results
Currently with this change we have increased the number of plans being verified against reference db from 40 % to 80+%.

 Total masked aggregations: 78 (14.58%)
Total global aggregations: 41 (7.66%)
Total group-by aggregations: 392 (73.27%)
Total distinct aggregations: 49 (9.16%)
 Total aggregations over distinct inputs: 40 (7.48%)
Total window expressions: 53 (9.91%)
 Total functions tested: 38
 Total iterations requiring sorted inputs: 43 (8.04%)
Total iterations verified against reference DB: 448 (83.74%)
 Total functions not verified (verification skipped / not supported by reference DB / reference DB failed): 53 (9.91%) / 6 (1.12%) / 3 (0.56%)
 Total failed functions: 27 (5.05%)

Experimental runs :
https://github.com/facebookincubator/velox/actions/runs/8199583642/job/22443872635
https://github.com/facebookincubator/velox/actions/runs/8199583642/job/22424917125

Notes
Certain functions have been skiplisted for following reasons:

  1. map_union_sum : This requires us to use the lates presto due to a bug on Presto end in version .284 not supporting reals.
  2. approx_set: Signatures supported by Velox are more than supported by Presto
  3. min_by, max_by: Requires custom verifiers (order by not supported by Presto)
  4. any_value: alias for arbitrary but this alias isnt present in Presto.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 8, 2024
Copy link

netlify bot commented Mar 8, 2024

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit 9dee0c6
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/65f36efaec71c400089409d9

Copy link
Collaborator

@duanmeng duanmeng left a comment

Choose a reason for hiding this comment

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

@kgpai Looks great % some nits.

@@ -77,6 +77,20 @@ DEFINE_bool(

namespace facebook::velox::exec::test {

bool AggregationFuzzerBase::isSupportedType(const TypePtr& type) const {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any chance to add a comment for it?

referenceQueryRunner_->executeVector(
sql.value(), input, plan->outputType()),
ReferenceQueryErrorCode::kSuccess);
} catch (std::exception& e) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

const std::exception& ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesnt look like we use it, I can just remove it .

sql.value(), input, plan->outputType()),
ReferenceQueryErrorCode::kSuccess);
} catch (std::exception& e) {
// ++stats_.numReferenceQueryFailed;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we remove this?

Copy link
Contributor

@kagamiori kagamiori left a comment

Choose a reason for hiding this comment

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

Hi @kgpai, thank you for adding this support! I left a few comments.

VELOX_CHECK(
verifier->verify(resultOrError.result),
"Aggregation results failed custom verification");
if (expectedResult && resultOrError.result) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: resultOrError.result != nullptr is already checked at line 1031, so no need to check it again here.

if (resultOrError.result != nullptr) {
if (!customVerification) {
std::optional<MaterializedRowMultiset> expectedResult;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: simply auto expectedResult = referenceResult.first below would be easier?

"Velox and reference DB results don't match");
LOG(INFO) << "Verified results against reference DB";
}
} else if (referenceQueryRunner_->supportsVeloxVectorResults()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we check the verifier supports compare here too? And if not, we still call verify()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I considered only cases where compare is supported, but its still helpful to run against reference even where the verifier only supports verify, for e.g to ensure that the signatures are supported by Presto (if velox supports more signatures). I dont think we lose anything by having it run against Presto.

Comment on lines 1058 to 1072
// Merge all the results into one.
auto results = referenceResult.first.value();
auto totalCount = 0;
for (const auto& result : results) {
totalCount += result->size();
}
auto copy = BaseVector::create<RowVector>(
results[0]->type(), totalCount, pool_.get());
auto copyCount = 0;
for (const auto& result : results) {
copy->copy(result.get(), copyCount, 0, result->size());
copyCount += result->size();
}

expected.result = copy;
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 extract this into a helper method?

@@ -77,6 +77,20 @@ DEFINE_bool(

namespace facebook::velox::exec::test {

bool AggregationFuzzerBase::isSupportedType(const TypePtr& type) const {
if (type->isDate() || type->isIntervalDayTime() || type->isUnKnown()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to explain why these types are not supported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am wondering whether I should make this a property of referenceQueryRunner.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are they supported in DuckQueryRunner? If so, we cannot make them a property of referenceQueryRunner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think ddb doesnt support Timestamp (because of nanosecond precision), and these types arent supported in PQR; so I still feel at some level this should be properties of respective query runner. Let me know what you think.

LOG(INFO) << "Query not supported by the reference DB";
}

return std::make_pair(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Move this into the else branch to be with the log statement together?

@kgpai kgpai force-pushed the agg_fuzzer_unsorted branch 2 times, most recently from 74e06d1 to d702f45 Compare March 12, 2024 21:30
Copy link
Contributor

@kagamiori kagamiori left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@@ -77,6 +77,20 @@ DEFINE_bool(

namespace facebook::velox::exec::test {

bool AggregationFuzzerBase::isSupportedType(const TypePtr& type) const {
if (type->isDate() || type->isIntervalDayTime() || type->isUnKnown()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are they supported in DuckQueryRunner? If so, we cannot make them a property of referenceQueryRunner.


/// Returns false if the type or its children are unsupported.
/// Currently returns false if type is Date,IntervalDayTime or Unknown.
/// \param type
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Why do we use /// instead of // here? Should this be "@param" and "@return"?

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 was auto generated , I will change it to @param and @return , the convention is for /// if we want to make a docstring .

@kgpai kgpai force-pushed the agg_fuzzer_unsorted branch from d702f45 to f39362e Compare March 14, 2024 18:08
@facebook-github-bot
Copy link
Contributor

@kgpai has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@kgpai kgpai force-pushed the agg_fuzzer_unsorted branch from f39362e to 9dee0c6 Compare March 14, 2024 21:41
@facebook-github-bot
Copy link
Contributor

@kgpai has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@kgpai merged this pull request in 03d017f.

Joe-Abraham pushed a commit to Joe-Abraham/velox that referenced this pull request Jun 7, 2024
…non deterministic functions on unsorted inputs (facebookincubator#9009)

Summary:
**Why**
 Currently for aggregate functions with custom verifiers, we do not verify plans against the reference db. This is because for these functions the reference db results differ and require us to use custom verifiers - typically the ResultVerifier::compare api. The compare api requires VeloxVectors and previously the results of the reference query runner were in materialized row format and thus couldnt be called. Recently support was added to return the reference db results as velox vectors (facebookincubator#8880). With this we can now validate functions which require custom verifiers.

**What**
We add support in the AggregationFuzzer to use the new 'executeVector' api if supported by the refrence query runner, and use that to validate non deterministic functions that require a custom verifier.

**Results**
Currently with this change we have increased the number of plans being verified against reference db from 40 % to 80+%.

```
 Total masked aggregations: 78 (14.58%)
Total global aggregations: 41 (7.66%)
Total group-by aggregations: 392 (73.27%)
Total distinct aggregations: 49 (9.16%)
 Total aggregations over distinct inputs: 40 (7.48%)
Total window expressions: 53 (9.91%)
 Total functions tested: 38
 Total iterations requiring sorted inputs: 43 (8.04%)
Total iterations verified against reference DB: 448 (83.74%)
 Total functions not verified (verification skipped / not supported by reference DB / reference DB failed): 53 (9.91%) / 6 (1.12%) / 3 (0.56%)
 Total failed functions: 27 (5.05%)
```

Experimental runs :
https://github.com/facebookincubator/velox/actions/runs/8199583642/job/22443872635
 https://github.com/facebookincubator/velox/actions/runs/8199583642/job/22424917125

 **Notes**
 Certain functions have been skiplisted for following reasons:
 1. map_union_sum : This requires us to use the lates presto due to a bug on Presto end in version .284 not supporting reals.
 2. approx_set: Signatures supported by Velox are more than supported by Presto
 3. min_by, max_by: Requires custom verifiers (order by not supported by Presto)
 4. any_value: alias for arbitrary but this alias isnt present in Presto.

Pull Request resolved: facebookincubator#9009

Reviewed By: kagamiori

Differential Revision: D54911135

Pulled By: kgpai

fbshipit-source-id: e2fc1fc91a367eb1a3538aa87e755e31ae1018a6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants