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

Could hammer support generated columns? #38

Closed
jameszhujian opened this issue Jul 12, 2022 · 4 comments
Closed

Could hammer support generated columns? #38

jameszhujian opened this issue Jul 12, 2022 · 4 comments

Comments

@jameszhujian
Copy link

Hi there,
We want to add a generated column to our schema, but hammer doesn't like the syntax. The DDL is like:
expiry TIMESTAMP AS (IF(status IS NULL, updated_at, '10000-01-01 00:00:00 UTC')) STORED

Thanks.

James

@daichirata
Copy link
Owner

daichirata commented Jul 14, 2022

Thanks for the report. hammer uses https://pkg.go.dev/cloud.google.com/go/spanner/spansql for parsing DDL.

spansql can correctly parse the following DDLs.

CREATE TABLE user (
  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);

But, when I try to parse the next DDL, I seem to get an error.

CREATE TABLE user (
  Id STRING(20) NOT NULL,
  FirstName STRING(50),
  LastName STRING(50),
  Age INT64 NOT NULL,
  AgeAbove18 INT64 AS (IF(Age > 18, Age, NULL)) STORED;
) PRIMARY KEY (Id);

Detailed conditions are not known, but https://github.com/googleapis/google-cloud-go/tree/main/spanner/spansql needs to be modified to correct this.

@neglect-yp
Copy link
Contributor

neglect-yp commented Jul 14, 2022

I've created a PR for this issue. googleapis/google-cloud-go#6341

However, there are few conditional expressions that are not yet supported.

@neglect-yp
Copy link
Contributor

You can try hammer v0.5.10, which has been released with added support for IF and IFNULL expressions. It will work fine > if you are not using NULLIF or COALESCE expressions (or other unsupported syntax).

#37 (comment)

@daichirata
Copy link
Owner

This change is included in the v0.5.10 release.

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

No branches or pull requests

3 participants