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

sql: add the 'every' aggregate function #46059

Merged
merged 1 commit into from
Mar 16, 2020
Merged

Conversation

rohany
Copy link
Contributor

@rohany rohany commented Mar 13, 2020

Fixes #45842.

Release justification: low risk update to functionality
Release note (sql change): This PR adds the every aggregate function.

@rohany rohany requested a review from a team as a code owner March 13, 2020 00:42
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@rohany
Copy link
Contributor Author

rohany commented Mar 13, 2020

Not sure if there is an easier way of just translating the every function into bool_and -- maybe something in the optimizer can make this easier?

@andy-kimball
Copy link
Contributor

andy-kimball commented Mar 13, 2020

As far as I understand, this function is exactly equivalent to bool_and, so it should definitely be an optimizer thing. I hadn't realized that before. If so, then I'd expect change to be something like:

	case "bit_and", "every":
		return b.factory.ConstructBitAndAgg(args[0])

@rohany
Copy link
Contributor Author

rohany commented Mar 13, 2020

Sounds good -- editing the distsql infra seemed wrong. I'll still have to make a scalar for it though, right?

@andy-kimball
Copy link
Contributor

No need for a scalar. We'll just create the BitAnd scalar operator directly.

@rohany
Copy link
Contributor Author

rohany commented Mar 13, 2020

Alright done. Two things though:

  • I want to include the distsqlversion bump because of some other aggregates that have been added that need a bump.
  • I'm leaning on keeping the every entry in the aggregate funcs map so that a docs entry gets generated for it -- not sure if there is an easy way around that

@andy-kimball
Copy link
Contributor


pkg/sql/rowexec/version_history.txt, line 109 at r1 (raw file):

    - Change how DArray datums are hashed for distinct and aggregation operations.
- Version: 28 (MinAcceptedVersion: 28)
    - Some new aggregate functions have been added (BIT_AND, BIT_OR, CORR)

Haven't BIT_AND and BIT_OR been around for a while?

Copy link
Contributor

@andy-kimball andy-kimball left a comment

Choose a reason for hiding this comment

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

That's fine to keep it in the map.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @andy-kimball, @rohany, and @yuzefovich)

Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 6 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @andy-kimball and @rohany)


pkg/sql/rowexec/version_history.txt, line 109 at r1 (raw file):

Previously, andy-kimball (Andy Kimball) wrote…

Haven't BIT_AND and BIT_OR been around for a while?

For a few months, yes.

I don't think bumping up the version here is strictly required, yet it is beneficial. I believe without the bump the following can occur in a mixed version cluster:

  • the gateway node has the newest version that supports BIT_AND, so when the query with this function is issued against the gateway, it thinks everything is great, so it sends out the flow specifications containing this function to remote nodes
  • the remote nodes, however, are running an older version which doesn't have the support for BIT_AND, so they will return an error to the gateway because they don't recognize the constant that corresponds to BIT_AND, and the whole query will fail.

The important point is that we do not change the order of aggregate functions (i.e. the respective constants remain unchanged), so there is no change of some "internal" error or a crash due to aggregates mismatch. (If my understanding is incorrect, please let me know :) )


pkg/sql/sem/builtins/aggregate_builtins.go, line 148 at r1 (raw file):

	),

	"every": makeBuiltin(aggProps(),

nit: these functions are sorted lexicographically.

Fixes cockroachdb#45842.

Release justification: low risk update to functionality
Release note (sql change): This PR adds the `every` aggregate function.
@rohany
Copy link
Contributor Author

rohany commented Mar 13, 2020

Sorry, I misread the dates on the commit that added bit_and and bit_or.

I don't think bumping up the version here is strictly required, yet it is beneficial. I believe without the bump the following can occur in a mixed version cluster:

Yeah, this is what I'm thinking as well.

Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

:lgtm: but I believe we need an approval from a tech lead or from Andy K since we're in stability period.

Reviewed 2 of 2 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @andy-kimball and @rohany)

@rohany
Copy link
Contributor Author

rohany commented Mar 16, 2020

cc @andy-kimball for approval

Copy link
Contributor

@andy-kimball andy-kimball left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on @andy-kimball and @rohany)

@rohany
Copy link
Contributor Author

rohany commented Mar 16, 2020

bors r+

@craig
Copy link
Contributor

craig bot commented Mar 16, 2020

Build failed (retrying...)

@craig
Copy link
Contributor

craig bot commented Mar 16, 2020

Build succeeded

@craig craig bot merged commit 06fdc13 into cockroachdb:master Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql: add support for the EVERY boolean aggregate function
4 participants