-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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 ability to access a specific column in a labeled tuple #25810
Conversation
pkg/sql/sem/tree/type_check.go, line 890 at r1 (raw file):
This worries me a bit. It uses memory and I don't think it fully safeguards against it. The alternative is to do a single pass through all the labels in the columnAccessExpr type check to see if there is a double and if so fail for being ambiguous. Thoughts? Comments from Reviewable |
This implementation is adequate because it is correct. Just a few nits below. Meanwhile, since our discussion yesterday I have thought of an optimization. See my comment below. Let me know what you think. Reviewed 6 of 9 files at r1, 4 of 4 files at r2. pkg/sql/logictest/testdata/logic_test/tuple, line 797 at r2 (raw file):
This is super verbose. I'd recommend more simply: pkg/sql/sem/tree/eval.go, line 3398 at r2 (raw file):
Idea for optimization: keep the error that was here originally. See my other comment below. pkg/sql/sem/tree/expr.go, line 1496 at r2 (raw file):
Idea for optimization: do not add this field. See my comment below. pkg/sql/sem/tree/type_check.go, line 890 at r1 (raw file): Previously, BramGruneir (Bram Gruneir) wrote…
Yes I think the n^2 algorithm is appropriate here: for i := range expr.Labels {
for j := 0; j < i; j++ {
if expr.Labels[i] == expr.Labels[j] { ... error ... }
}
} Make the error: pkg/sql/sem/tree/type_check.go, line 406 at r2 (raw file):
factor the pkg/sql/sem/tree/type_check.go, line 417 at r2 (raw file):
Idea for optimization: define a local variable pkg/sql/sem/tree/type_check.go, line 429 at r2 (raw file):
Idea for optimization, here:
And zoooooom - both the ColumnAccessExpr and the tuple evaporate in a puff of nothingness. Comments from Reviewable |
All comments addressed. PTAL. Review status: 4 of 9 files reviewed at latest revision, 7 unresolved discussions, all commit checks successful. pkg/sql/logictest/testdata/logic_test/tuple, line 797 at r2 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/sem/tree/eval.go, line 3398 at r2 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/sem/tree/type_check.go, line 890 at r1 (raw file): Previously, knz (kena) wrote…
Done,. I could just check for the duplicate label when pulling out the column instead of during the definition. pkg/sql/sem/tree/type_check.go, line 406 at r2 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/sem/tree/type_check.go, line 417 at r2 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/sem/tree/type_check.go, line 429 at r2 (raw file): Previously, knz (kena) wrote…
Wonderful idea. Done. pkg/sql/sem/tree/expr.go, line 1496 at r2 (raw file): Previously, knz (kena) wrote…
Done. Comments from Reviewable |
with a nit and a required fix. See comment below. Reviewed 6 of 6 files at r3. pkg/sql/sem/tree/type_check.go, line 435 at r3 (raw file):
You need to call pkg/sql/sem/tree/type_check.go, line 898 at r3 (raw file):
I'd recommend Comments from Reviewable |
TFTR! Review status: 6 of 9 files reviewed at latest revision, 2 unresolved discussions, some commit checks pending. pkg/sql/sem/tree/type_check.go, line 435 at r3 (raw file): Previously, knz (kena) wrote…
Ah, excellent, I was annoyed by that. pkg/sql/sem/tree/type_check.go, line 898 at r3 (raw file): Previously, knz (kena) wrote…
Done. Comments from Reviewable |
This work is yet another step towards cockroachdb#16971. The labeled tuples introduced in cockroachdb#25283 can now be accessed using their labels. It's important to note that they require an extra parentheses around them to do so. ```sql SELECT (((1,'2',true) AS a, b, c)).a +---+ | a | +---+ | 1 | +---+ SELECT (((1,'2',true) AS a, b, c)).b +---+ | b | +---+ | 2 | +---+ SELECT (((1,'2',true) AS a, b, c)).c +------+ | c | +------+ | true | +------+ ``` This change prompted the need to restrict the labels in the tuple to be unique; checks and test cases for that have been added as well. Star expansion is still not allowed. Release note: Labeled tuples can now be accessed using their labels (e.g. `SELECT (((1,'2',true) AS a, b, c)).a` but it requires an extra level of parentheses to do so.
Reviewed 3 of 4 files at r4. Comments from Reviewable |
Reviewed 1 of 4 files at r4. Comments from Reviewable |
bors r+
…On Fri, May 25, 2018, 13:23 kena ***@***.***> wrote:
Reviewed 1 of 4 files at r4.
Review status: all files reviewed at latest revision, all discussions
resolved, all commit checks successful.
------------------------------
*Comments from Reviewable
<https://reviewable.io/reviews/cockroachdb/cockroach/25810>*
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#25810 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABihudO0DR_XZ2I3hZXMvDB8dlWobsxeks5t2D4egaJpZM4UJBZU>
.
|
25810: sql: Add the ability to access a specific column in a labeled tuple r=BramGruneir a=BramGruneir This work is yet another step towards #16971. The labeled tuples introduced in #25283 can now be accessed using their labels. It's important to note that they require an extra parentheses around them to do so. ```sql SELECT (((1,'2',true) AS a, b, c)).a +---+ | a | +---+ | 1 | +---+ SELECT (((1,'2',true) AS a, b, c)).b +---+ | b | +---+ | 2 | +---+ SELECT (((1,'2',true) AS a, b, c)).c +------+ | c | +------+ | true | +------+ ``` This change prompted the need to restrict the labels in the tuple to be unique; checks and test cases for that have been added as well. Star expansion is still not allowed. Release note: Labeled tuples can now be accessed using their labels (e.g. `SELECT (((1,'2',true) AS a, b, c)).a` but it requires an extra level of parentheses to do so. 26096: scripts: add Yahor to release notes r=yuzefovich a=yuzefovich This adds Yahor Yuzefovich to the roachers list. Release note: None Co-authored-by: Bram Gruneir <bram@cockroachlabs.com> Co-authored-by: yuzefovich <yahor@cockroachlabs.com>
Build succeeded |
This work is yet another step towards #16971.
The labeled tuples introduced in #25283 can now be accessed using their labels.
It's important to note that they require an extra parentheses around them to
do so.
This change prompted the need to restrict the labels in the tuple to be unique;
checks and test cases for that have been added as well.
Star expansion is still not allowed.
Release note: Labeled tuples can now be accessed using their labels (e.g.
SELECT (((1,'2',true) AS a, b, c)).a
but it requires an extra level ofparentheses to do so.