-
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 labels to Tuples #25283
sql: add labels to Tuples #25283
Conversation
@rytaft There are some minor changes to optimizer code here and this introduces a change to our SQL grammar. |
Thank you for this. The code is mostly good. I am agreeably surprised by the regularity and the thoroughness of this change. Minor comments below. Reviewed 20 of 20 files at r1. pkg/sql/logictest/testdata/logic_test/tuple, line 689 at r1 (raw file):
wait why is NULL not printed. I'd have expected it to be printed. pkg/sql/logictest/testdata/logic_test/tuple, line 694 at r1 (raw file):
remove tabs here and below pkg/sql/parser/sql.y, line 6749 at r1 (raw file):
This wants some changes in pkg/sql/sem/tree/type_check.go, line 813 at r1 (raw file):
Pull this check up above, then share the rest of the code for the two cases. Comments from Reviewable |
How does this relate to Postgres composite types? How come we're going off in this direction rather than implementing some subset of composite types? Or is the plan to take an initial step in that direction? Is our Review status: all files reviewed at latest revision, 4 unresolved discussions. pkg/sql/sem/types/types.go, line 323 at r1 (raw file):
Comments from Reviewable |
Review status: all files reviewed at latest revision, 5 unresolved discussions. pkg/sql/sem/types/types.go, line 339 at r1 (raw file):
I believe this string gets printed out by the Comments from Reviewable |
It relates well (see below)
There's no "off" nor "rather". We are going purposefully in this direction exactly in order to implement postgres' composite types.
Yes this is one of the steps towards addressing #24866 in turn needed to solve #16971 in turn needed to solve #16491.
With a resounding yes: if you look at pg's code they actually use a single data structure with a field column labels to represent every tuple type (with or without label). We just had failed to recognize the usefulness of this earlier. This patch fixes that. Review status: all files reviewed at latest revision, 6 unresolved discussions, some commit checks failed. pkg/sql/sem/types/types.go, line 323 at r1 (raw file): Previously, andy-kimball (Andy Kimball) wrote…
Bram and I found out that pkg/sql/sem/types/types.go, line 339 at r1 (raw file): Previously, andy-kimball (Andy Kimball) wrote…
We'll implement this transient type name logic in a later iteration. The logic is simple: any composite type derived from a table name gets the name of the table; everything else gets named "record". Comments from Reviewable |
All comments addressed, PTAL. Review status: 8 of 22 files reviewed at latest revision, 6 unresolved discussions. pkg/sql/logictest/testdata/logic_test/tuple, line 689 at r1 (raw file): Previously, knz (kena) wrote…
Nope. Here's the result from Postgres: SELECT (1, 2, 'hello', NULL, NULL), (true, NULL, (false, 6.6, false));
row | row
---------------+------------------
(1,2,hello,,) | (t,,"(f,6.6,f)")
(1 row)
And from us without the labels: SELECT (1, 2, 'hello', NULL, NULL), (true, NULL, (false, 6.6, false));
+-----------------------------+--------------------------------+
| (1, 2, 'hello', NULL, NULL) | (true, NULL, (false, 6.6, |
| | false)) |
+-----------------------------+--------------------------------+
| (1,2,'hello',,) | (true,,(false, 6.6, false)) |
+-----------------------------+--------------------------------+
(1 row)
But I will add colnames, because I want us to be explicit about any changes to them. -(2.1) pkg/sql/logictest/testdata/logic_test/tuple, line 694 at r1 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/parser/sql.y, line 6749 at r1 (raw file): Previously, knz (kena) wrote…
Indeed. Added. pkg/sql/sem/tree/type_check.go, line 813 at r1 (raw file): Previously, knz (kena) wrote…
Done. Much cleaner. I didn't like the duplication. pkg/sql/sem/types/types.go, line 339 at r1 (raw file): Previously, knz (kena) wrote…
I just added the labels here, but I'm cool with changing how the output looks. Let me know if we want a different format. Comments from Reviewable |
LGTM modulo minor nits and missing links to new follow-up issues. Reviewed 13 of 14 files at r2. pkg/sql/logictest/testdata/logic_test/tuple, line 689 at r1 (raw file): Previously, BramGruneir (Bram Gruneir) wrote…
The pretty-printing of tuples as now implemented is sufficient for a first round but is still incomplete to be compatible with pg's. Please file an issue with your example:
then add a TODO pointing to the new issue both around here and the corresponding pretty-printing code. We had to do something similar for arrays before. cc Justin on the new issue. pkg/sql/logictest/testdata/logic_test/tuple, line 13 at r2 (raw file):
tabs here and below (I know you didn't introduce the tabs, but since you're at it already....) pkg/sql/sem/types/types.go, line 339 at r1 (raw file): Previously, BramGruneir (Bram Gruneir) wrote…
I think this function is OK for troubleshooting/debugging purposes. We need to change the logic of Comments from Reviewable |
Review status: 18 of 23 files reviewed at latest revision, 4 unresolved discussions. pkg/sql/logictest/testdata/logic_test/tuple, line 689 at r1 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/logictest/testdata/logic_test/tuple, line 13 at r2 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/sem/types/types.go, line 339 at r1 (raw file): Previously, knz (kena) wrote…
Done. Comments from Reviewable |
Reviewed 5 of 5 files at r3. Comments from Reviewable |
bors r+
…On Tue, May 15, 2018, 13:31 kena ***@***.***> wrote:
Reviewed 5 of 5 files at r3.
Review status: all files reviewed at latest revision, 2 unresolved
discussions.
------------------------------
*Comments from Reviewable
<https://reviewable.io/reviews/cockroachdb/cockroach/25283>*
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#25283 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABihuRZVhadNov-U7InOsaQlRpjq3BPbks5tyxDugaJpZM4TxgCD>
.
|
Merge conflict (retrying...) |
bors r+ |
Merge conflict (retrying...) |
bors r+ |
Build failed (retrying...) |
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.
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.
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.
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>
This work is yet another step towards cockroachdb#16971. The labeled tuples introduced in cockroachdb#25283 can now be accessed using their labels. Star expansion is still not allowed for tuples with fewer or more than 1 columns. Release note (sql change): Labeled tuples can now be accessed using their labels (e.g. `SELECT (x).word FROM (SELECT pg_expand_keywords() AS x)`. Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>
This work is yet another step towards cockroachdb#16971. The labeled tuples introduced in cockroachdb#25283 can now be accessed using their labels. Star expansion is still not allowed for tuples with fewer or more than 1 columns. Release note (sql change): Labeled tuples can now be accessed using their labels (e.g. `SELECT (x).word FROM (SELECT pg_expand_keywords() AS x)`. Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>
This work is yet another step towards cockroachdb#16971. The labeled tuples introduced in cockroachdb#25283 can now be accessed using their labels or using a star, e.g. `(E).*`. Release note (sql change): Labeled tuples can now be accessed using their labels (e.g. `SELECT (x).word FROM (SELECT pg_expand_keywords() AS x)` or a star (e.g. `SELECT (x).* FROM (SELECT pg_expand_keywords() AS x)`). Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>
This work is yet another step towards cockroachdb#16971. The labeled tuples introduced in cockroachdb#25283 can now be accessed using their labels or using a star, e.g. `(E).*`. Release note (sql change): Labeled tuples can now be accessed using their labels (e.g. `SELECT (x).word FROM (SELECT pg_expand_keywords() AS x)` or a star (e.g. `SELECT (x).* FROM (SELECT pg_expand_keywords() AS x)`). Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>
This work is yet another step towards cockroachdb#16971. The labeled tuples introduced in cockroachdb#25283 can now be accessed using their labels or using a star, e.g. `(E).*`. Release note (sql change): Labeled tuples can now be accessed using their labels (e.g. `SELECT (x).word FROM (SELECT pg_expand_keywords() AS x)` or a star (e.g. `SELECT (x).* FROM (SELECT pg_expand_keywords() AS x)`). Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>
This work is yet another step towards cockroachdb#16971. The labeled tuples introduced in cockroachdb#25283 can now be accessed using their labels or using a star, e.g. `(E).*`. Release note (sql change): Labeled tuples can now be accessed using their labels (e.g. `SELECT (x).word FROM (SELECT pg_expand_keywords() AS x)` or a star (e.g. `SELECT (x).* FROM (SELECT pg_expand_keywords() AS x)`). Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>
26628: sql: Support tuple column access and tuple stars r=knz a=knz First commits from #26621. Completes the fix to #24866 by re-activating disabled tests. This work is yet another step towards #16971. It would actually fix #16971 if it were not for #26627, #26624 and #26629. This work is yet another step towards #16971. The labeled tuples introduced in #25283 can now be accessed using their labels or using a star, e.g. `(E).*`. Release note (sql change): Labeled tuples can now be accessed using their labels (e.g. `SELECT (x).word FROM (SELECT pg_expand_keywords() AS x)` or a star (e.g. `SELECT (x).* FROM (SELECT pg_expand_keywords() AS x)`). Fixes #26720. Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com> Co-authored-by: Bram Gruneir <bram@cockroachlabs.com>
In order to further solving #16971, the ability to access the content of a
tuple based on a label is required. Until now, tuples had no labels and thus
there was no way access a specific element in a tuple. This commit adds labels
to tuples and also the ability to specify them directly in the SQL dialect.
However, it does not go to the next step of adding the ability to choose an
element based on the label. That will be in a follow up commit.
Note that the ability to give tuples labels is an extension on top of Postgres'
SQL grammar. But it should be noted that this functionality is mostly for
internal use and ease of testing.
Specifically, one can now specify the names for a tuple using the following:
Similar to unlabeled tuples, the ROW keyword is optional unless there is only
a single element in the tuple.
However, the enclosing parentheses are always required.
Furthermore, when comparing tuples, the labels are ignored and only the types
of the elements must be comparable to each other.
This change started out by adding a
Labels
element to both the Tuple andTTuple structs. And following the though where all the required changes led.
After this, updates to Tuple's TypeCheck where required and then a lot of
testing to ensure the correct format was applied when printing or typing them.
Release note (sql change): Tuples can now be specified with labels. They can be
specified using the new grammar
((1,2,3) AS a,b,c)
.