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

builtins: add extract functionality for intervals #43293

Merged
merged 1 commit into from
Jan 9, 2020

Conversation

otan
Copy link
Contributor

@otan otan commented Dec 18, 2019

Resolves #43209

This adds the postgres-esque implementation of extract for intervals.
Tested a variety of edge cases and compared against what postgres
returns.

Currently leaving the extract_duration function alone - we could
thereoetically get rid of it after this PR. It does behave slightly
differently as well.

Release note (sql change): Added new ability to call extract on an
interval, e.g. extract(day from interval '254 days'). This follows
the postgres implementation. Furthermore, this deprecates
extract_duration, which will be removed at a later date.

@otan otan requested a review from a team December 18, 2019 17:00
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

Very nice :lgtm_strong:

However please change the release note to add an actual deprecation notice for extract_duration, as well as a note to the same effect in that function's text description.

Thanks

Reviewed 4 of 4 files at r1.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @solongordon)

This adds the postgres-esque implementation of extract for intervals.
Tested a variety of edge cases and compared against what postgres
returns.

Currently leaving the `extract_duration` function alone - we could
thereoetically get rid of it after this PR. It does behave slightly
differently as well.

Release note (sql change): Added new ability to call extract on an
interval, e.g. `extract(day from interval '254 days')`. This follows
the postgres implementation. Furthermore, this deprecates
`extract_duration`, which will be removed at a later date.
@otan
Copy link
Contributor Author

otan commented Jan 9, 2020

bors r=knz

thanks for the review :)

craig bot pushed a commit that referenced this pull request Jan 9, 2020
39308: sql/sem: fix interaction between framing and peers in window functions r=yuzefovich a=yuzefovich

**rowexec: minor refactor of partitionPeerGrouper**

This commit removes allPeers peerGroupChecker and refactors
partitionPeerGrouper to support the case of omitted ORDER BY clause.

Release note: None

**sql/sem: fix interaction between framing and peers in window functions**

Previously, whenever we had a result of a window function already
computed for a peer of the row, we would return that result. However,
the concept of window framing takes precedence over the concept of peers
(i.e. if the window frame over which we computed the result for a peer
is different from the window frame of the current row, we need to
recompute the result). Now this is fixed by tracking the boundaries of
the window frame over which peerRes is computed and recomputing the
latter when needed.

There was also a bug in IsDefaultFrame where we forgot to check whether
the mode of framing is RANGE. This caused incorrect results in some
cases when ROWS or GROUPS modes of framing were used.

Fixes: #38901.
Fixes: #42935.

Release note (bug fix): CockroachDB previously was returning incorrect
results for some aggregate functions when used as window functions with
non-default window frame. Now this is fixed. Note that MIN, MAX, SUM,
AVG as well as "pure" window functions (i.e. non-aggregates) were not
affected.

43293: builtins: add extract functionality for intervals r=knz a=otan

Resolves #43209

This adds the postgres-esque implementation of extract for intervals.
Tested a variety of edge cases and compared against what postgres
returns.

Currently leaving the `extract_duration` function alone - we could
thereoetically get rid of it after this PR. It does behave slightly
differently as well.


Release note (sql change): Added new ability to call extract on an
interval, e.g. `extract(day from interval '254 days')`. This follows
the postgres implementation. Furthermore, this deprecates
`extract_duration`, which will be removed at a later date.

43834: colexec: speed up ordered sync r=yuzefovich a=yuzefovich

**colexec: refactor ordered sync to use assign instead of append**

Ordered synchronizer sets the output one row at a time. Previously, we
were calling Append on the output vectors, but it is faster to use Sets
in such scenario.

Release note: None

**colexec: speed up ordered sync**

This commit speeds up the ordered synchronizer with two modifications:
1. instead of updating the allocator after we copy a single whole row,
we will now update the allocator after we copy a full batch of rows
2. to reduce the number of interface conversions we will "strip" output
vectors to get to the underlying slices and will use those directly when
copying the data.

Release note: None

Co-authored-by: Yahor Yuzefovich <yahor@cockroachlabs.com>
Co-authored-by: Oliver Tan <otan@cockroachlabs.com>
@craig
Copy link
Contributor

craig bot commented Jan 9, 2020

Build succeeded

@craig craig bot merged commit 8dc28e1 into cockroachdb:master Jan 9, 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 extract(string, interval)
3 participants