-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
42137: colexec: add support for percent_rank and cume_dist window functions r=yuzefovich a=yuzefovich **colexec: add window peer grouper** This commit adds an operator that populates a boolean column to signify whether the corresponding tuple is the start of a new peer group. Peers are such tuples that belong to the same partition and are equal on the ordering columns. Some window functions must return the same output for all peers in the peer group. Currently this operator is not used. Release note: None **colexec: minor refactor of rank and denseRank operators** Previously, rank and denseRank operators contained the logic to figure out the boundaries of the peer groups, but now that we have a window peer grouper, it is no longer necessary which simplified the code a little bit. Release note: None **colexec: add support for PERCENT_RANK window function** This commit adds the support for PERCENT_RANK window function. This function differs from two other rank variances in that it needs to know the number of tuples in the partition. If there is no PARTITION BY clause, then we have no other choice but to buffer the input fully. If PARTITION BY clause is present, we need to buffer all tuples that belong to each partition before we can populate the output. However, for simplicity, the current implementation of the operator with PARTITION BY clause also fully buffers the whole input before emitting any output. This commit also adds a couple of "vec-on" configs to 'window' logic test. This will increase the test coverage of window functions supported by the vectorized engine. Addresses: #37035. Release note: None **colexec: add support for cume_dist window function** This commit adds support for CUME_DIST window function. This function is quite similar to PERCENT_RANK, so it reuses the same template. "percent_rank" things have been renamed to "relative_rank" things. This commit also enables running of `row_number`, `rank`, and `dense_rank` with `vectorize=auto`. The reason is that these window functions are streaming and internally they might a sorter which can fallback to disk if necessary. Addresses: #37035. Release note: None Co-authored-by: Yahor Yuzefovich <yahor@cockroachlabs.com>
- Loading branch information
Showing
16 changed files
with
962 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2020 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package main | ||
|
||
import ( | ||
"io" | ||
"io/ioutil" | ||
"strings" | ||
"text/template" | ||
) | ||
|
||
type relativeRankTmplInfo struct { | ||
IsPercentRank bool | ||
IsCumeDist bool | ||
HasPartition bool | ||
String string | ||
} | ||
|
||
func genRelativeRankOps(wr io.Writer) error { | ||
d, err := ioutil.ReadFile("pkg/sql/colexec/relative_rank_tmpl.go") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
s := string(d) | ||
|
||
s = strings.Replace(s, "_RELATIVE_RANK_STRING", "{{.String}}", -1) | ||
|
||
computeNumPeersRe := makeFunctionRegex("_COMPUTE_NUM_PEERS", 0) | ||
s = computeNumPeersRe.ReplaceAllString(s, `{{template "computeNumPeers"}}`) | ||
computeCumeDistRe := makeFunctionRegex("_COMPUTE_CUME_DIST", 0) | ||
s = computeCumeDistRe.ReplaceAllString(s, `{{template "computeCumeDist"}}`) | ||
|
||
// Now, generate the op, from the template. | ||
tmpl, err := template.New("relative_rank_op").Parse(s) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
relativeRankTmplInfos := []relativeRankTmplInfo{ | ||
{IsPercentRank: true, HasPartition: false, String: "percentRankNoPartition"}, | ||
{IsPercentRank: true, HasPartition: true, String: "percentRankWithPartition"}, | ||
{IsCumeDist: true, HasPartition: false, String: "cumeDistNoPartition"}, | ||
{IsCumeDist: true, HasPartition: true, String: "cumeDistWithPartition"}, | ||
} | ||
return tmpl.Execute(wr, relativeRankTmplInfos) | ||
} | ||
|
||
func init() { | ||
registerGenerator(genRelativeRankOps, "relative_rank.eg.go") | ||
} |
52 changes: 52 additions & 0 deletions
52
pkg/sql/colexec/execgen/cmd/execgen/window_peer_grouper_gen.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2019 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package main | ||
|
||
import ( | ||
"io" | ||
"io/ioutil" | ||
"strings" | ||
"text/template" | ||
) | ||
|
||
type windowPeerGrouperTmplInfo struct { | ||
AllPeers bool | ||
HasPartition bool | ||
String string | ||
} | ||
|
||
func genWindowPeerGrouperOps(wr io.Writer) error { | ||
d, err := ioutil.ReadFile("pkg/sql/colexec/window_peer_grouper_tmpl.go") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
s := string(d) | ||
s = strings.Replace(s, "_PEER_GROUPER_STRING", "{{.String}}", -1) | ||
|
||
// Now, generate the op, from the template. | ||
tmpl, err := template.New("peer_grouper_op").Parse(s) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
windowPeerGrouperTmplInfos := []windowPeerGrouperTmplInfo{ | ||
{AllPeers: false, HasPartition: false, String: "windowPeerGrouperNoPartition"}, | ||
{AllPeers: false, HasPartition: true, String: "windowPeerGrouperWithPartition"}, | ||
{AllPeers: true, HasPartition: false, String: "windowPeerGrouperAllPeersNoPartition"}, | ||
{AllPeers: true, HasPartition: true, String: "windowPeerGrouperAllPeersWithPartition"}, | ||
} | ||
return tmpl.Execute(wr, windowPeerGrouperTmplInfos) | ||
} | ||
|
||
func init() { | ||
registerGenerator(genWindowPeerGrouperOps, "window_peer_grouper.eg.go") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.