Skip to content

sql: new built-in generator pg_get_keywords#19127

Merged
knz merged 5 commits intocockroachdb:masterfrom
knz:20171009-get-keywords
Oct 9, 2017
Merged

sql: new built-in generator pg_get_keywords#19127
knz merged 5 commits intocockroachdb:masterfrom
knz:20171009-get-keywords

Conversation

@knz
Copy link
Copy Markdown
Contributor

@knz knz commented Oct 9, 2017

Requested in #10291 (comment).

This PR includes some other useful refactors and cleanups.

@knz knz requested review from a team, justinj and nvb October 9, 2017 14:25
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Contributor

@justinj justinj left a comment

Choose a reason for hiding this comment

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

LGTM (with two comments), I wonder why PG chose to make this a generator function rather than a system table.

-9223372036854775807

# pg_get_keywords for compatibility (#10291)
query TTT
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably worth doing a colnames for this test?

}
}
columns := make(sqlbase.ResultColumns, len(tType.Cols))
for i := range columns {
Copy link
Copy Markdown
Contributor

@justinj justinj Oct 9, 2017

Choose a reason for hiding this comment

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

I just realized PG lets you specify the label for a single-column generator:

justin=# select * from unnest(array[1,2,3]) a;
 a
---
 1
 2
 3
(3 rows)

is that something we can easily support?

@knz knz force-pushed the 20171009-get-keywords branch from 9549f26 to 897ba35 Compare October 9, 2017 15:19
@knz
Copy link
Copy Markdown
Contributor Author

knz commented Oct 9, 2017

Review status: 0 of 11 files reviewed at latest revision, 2 unresolved discussions.


pkg/sql/generator.go, line 62 at r4 (raw file):

Previously, justinj (Justin Jaffray) wrote…

I just realized PG lets you specify the label for a single-column generator:

justin=# select * from unnest(array[1,2,3]) a;
 a
---
 1
 2
 3
(3 rows)

is that something we can easily support?

Awwww bad pg, bad. This is a weird mechanism. I'll investigate. However it's separate, it wasn't supported before this PR anyways.


pkg/sql/logictest/testdata/logic_test/generators, line 247 at r4 (raw file):

Previously, justinj (Justin Jaffray) wrote…

Probably worth doing a colnames for this test?

Yes indeed. Done.


Comments from Reviewable

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Oct 9, 2017

Added a commit with the pg behavior, PTAL

@knz knz force-pushed the 20171009-get-keywords branch 2 times, most recently from 803ec33 to 1d69e26 Compare October 9, 2017 16:03
@nvb
Copy link
Copy Markdown
Contributor

nvb commented Oct 9, 2017

Reviewed 2 of 2 files at r1, 4 of 4 files at r2, 6 of 6 files at r5, 4 of 4 files at r6, 2 of 2 files at r7.
Review status: all files reviewed at latest revision, 6 unresolved discussions, some commit checks failed.


pkg/sql/data_source.go, line 491 at r7 (raw file):

		// column name and table name.
		if vg, ok := src.plan.(*valueGenerator); ok &&
			(len(src.info.sourceAliases) == 0 ||

pull out these two conditions into variables


pkg/sql/parser/generator_builtins.go, line 237 at r2 (raw file):

// ResolvedType implements the ValueGenerator interface.
func (s *arrayValueGenerator) ResolvedType() TTable {
	return TTable{

Consider pulling this into a static variable too.


pkg/sql/parser/generator_builtins.go, line 220 at r5 (raw file):

// that pg_get_keywords returns deterministic results.
var keywordNames = func() []string {
	ret := make([]string, len(keywords))

nit: efficiency doesn't matter here so just set the capacity and append to get rid of i.


pkg/sql/parser/sql.y, line 5617 at r1 (raw file):

| /* EMPTY */
  {
    $$.val = Exprs{}

This is creating a zero-length Expr slice. I think you want a nil slice. Try Exprs(nil).


Comments from Reviewable

@nvb
Copy link
Copy Markdown
Contributor

nvb commented Oct 9, 2017

:lgtm: mostly just nits. Nice change!


Review status: all files reviewed at latest revision, 6 unresolved discussions, some commit checks failed.


Comments from Reviewable

knz added 2 commits October 9, 2017 22:05
This patch makes the built-in definitions decide themselves the labels
of the result columns. This in turn simplifies logical planning.
@knz
Copy link
Copy Markdown
Contributor Author

knz commented Oct 9, 2017

Review status: all files reviewed at latest revision, 6 unresolved discussions, some commit checks failed.


pkg/sql/data_source.go, line 491 at r7 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

pull out these two conditions into variables

Done.


pkg/sql/parser/generator_builtins.go, line 237 at r2 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Consider pulling this into a static variable too.

Can't do, it's dependent on s.


pkg/sql/parser/generator_builtins.go, line 220 at r5 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

nit: efficiency doesn't matter here so just set the capacity and append to get rid of i.

Done.


pkg/sql/parser/sql.y, line 5617 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

This is creating a zero-length Expr slice. I think you want a nil slice. Try Exprs(nil).

Done.


Comments from Reviewable

@knz knz force-pushed the 20171009-get-keywords branch from 1d69e26 to 4061df8 Compare October 9, 2017 20:13
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.

4 participants