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

spanner/spansql: generated columns #3618

Closed
geerttouquet opened this issue Jan 27, 2021 · 9 comments · Fixed by #3625 or #3633
Closed

spanner/spansql: generated columns #3618

geerttouquet opened this issue Jan 27, 2021 · 9 comments · Fixed by #3625 or #3633
Assignees
Labels
api: spanner Issues related to the Spanner API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@geerttouquet
Copy link

Client

spansql Version v1.13.0

Environment

windows

Go Environment

$ go version : go version go1.13 windows/amd64
$ go env

If you extract the following example
CREATE TABLE users (
Id STRING(20) NOT NULL,
FirstName STRING(50),
LastName STRING(50),
Age INT64 NOT NULL,
FullName STRING(100) AS (ARRAY_TO_STRING([FirstName, LastName], " ")) STORED,
) PRIMARY KEY (Id);

You got error : ParseDDL("CREATE TABLE users (\n\tId STRING(20) NOT NULL,\n\tFirstName STRING(50),\n\tLastName STRING(50),\n\tAge INT64 NOT NULL,\n\tFullName STRING(100) AS (ARRAY_TO_STRING([FirstName, LastName], " ")) STORED,\n) PRIMARY KEY (Id);"): filename:6: got "(" while expecting ")"

@geerttouquet geerttouquet added the triage me I really want to be triaged. label Jan 27, 2021
@geerttouquet
Copy link
Author

geerttouquet commented Jan 27, 2021

a strange thing
CREATE TABLE GenCol (
Name STRING(MAX) NOT NULL,
NameLen INT64 AS (CHAR_LENGTH(Name)) STORED,
) PRIMARY KEY (Name);
this succeeds as in test
CREATE TABLE GenCol (
Name STRING(MAX) NOT NULL,
NameLen INT64 AS (UPPER(Name)) STORED,
) PRIMARY KEY (Name);
fails

@codyoss codyoss changed the title spansql: generated columns spanner/spansql: generated columns Jan 27, 2021
@codyoss codyoss added api: spanner Issues related to the Spanner API. and removed triage me I really want to be triaged. labels Jan 27, 2021
@skuruppu skuruppu assigned dsymonds and unassigned skuruppu Jan 28, 2021
@skuruppu skuruppu added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Jan 28, 2021
@dsymonds
Copy link
Contributor

The problem is not with generated columns, but with the limited support for builtin functions. ARRAY_TO_STRING and UPPER are not implemented, but CHAR_LENGTH is. We can add more functions to the list easily enough, but they take a fair bit of effort to implement in spannertest, so it depends on whether you're just trying to parse these or want spannertest to act on them.

Note that generated columns remain a TODO for spannertest (see spanner/spannertest/README.md).

@geerttouquet
Copy link
Author

We use UPPER in our configuration already, now this gives an error to parse :-) It would be nice if this succeeds

@dsymonds
Copy link
Contributor

Sure, no problem. Easy enough to flesh out the list of string funcs at least. See #3625.

@dsymonds dsymonds added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jan 28, 2021
@geerttouquet
Copy link
Author

geerttouquet commented Jan 28, 2021

thanks ! spansql works very good

gcf-merge-on-green bot pushed a commit that referenced this issue Jan 28, 2021
This doesn't implement them, but only declares them for accurate
parsing.

Fixes #3618.
@geerttouquet
Copy link
Author

I have test with NameLen INT64 AS (UPPER(Name)) STORED, -> this works perfect, thanks

@geerttouquet
Copy link
Author

example
CREATE TABLE users (
Id STRING(20) NOT NULL,
FirstName STRING(50),
LastName STRING(50),
Age INT64 NOT NULL,
FullName STRING(100) AS (ARRAY_TO_STRING([FirstName, LastName], " ")) STORED,
) PRIMARY KEY (Id);

this still gives error
ParseDDL("CREATE TABLE users (\n\t\t\tId STRING(20) NOT NULL,\n\t\t\tFirstName STRING(50),\n\t\t\tLastName STRING(50),\n\t\t\tAge INT64 NOT NULL,\n\t\t\tFullName STRING(100) AS (ARRAY_TO_STRING([FirstName, LastName], " ")) STORED,\n\t\t) PRIMARY KEY (Id);"): filename:6: got "(" while expecting ")"

@dsymonds
Copy link
Contributor

Ah, that's an array function rather than a string function, but I can add those too.

@dsymonds dsymonds reopened this Jan 28, 2021
gcf-merge-on-green bot pushed a commit that referenced this issue Jan 28, 2021
As with a previous change, this doesn't implement these but permits
correct parsing.

Fixes #3618.
@geerttouquet
Copy link
Author

David

thanks it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the Spanner API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
4 participants