GoogleCloudPlatform / cloud-spanner-emulator

An open source emulator for Cloud Spanner.
Apache License 2.0
265 stars 44 forks source link

COLUMN_DEFAULT of INFORMATION_SCHEMA.COLUMNS returns incorrect value #114

Closed takabow closed 1 year ago

takabow commented 1 year ago

The output of the COLUMN_DEFAULT column in Cloud Spanner Emulator's INFORMATION_SCHEMA.COLUMNS may be missing when a function is used in the DEFAULT Value. Specifically, the brackets at the end of the function are missing.

For example, create the following table on the Cloud Spanner Emulator v1.5.4.

CREATE TABLE test_table (
  id INT64 NOT NULL,
  col_default_timestamp TIMESTAMP DEFAULT (CURRENT_TIMESTAMP())
) PRIMARY KEY(id);

Then query INFORMATION_SCHEMA.COLUMNS.

SELECT
    COLUMN_NAME,
    COLUMN_DEFAULT
FROM
    INFORMATION_SCHEMA.COLUMNS
WHERE
    TABLE_NAME="test_table";

Expected output:

+-----------------------+---------------------+
| COLUMN_NAME           | COLUMN_DEFAULT      |
+-----------------------+---------------------+
| id                    | NULL                |
| col_default_timestamp | CURRENT_TIMESTAMP() |
+-----------------------+---------------------+

Actual output:

+-----------------------+--------------------+
| COLUMN_NAME           | COLUMN_DEFAULT     |
+-----------------------+--------------------+
| id                    | NULL               |
| col_default_timestamp | CURRENT_TIMESTAMP( |
+-----------------------+--------------------+

As mentioned above, the output should be CURRENT_TIMESTAMP(), but it is output as CURRENT_TIMESTAMP(. The closing bracket ) is missing. As far as I have tested, this only occurs in Cloud Spanner Emulator v1.5.1 and later. v1.4.8 and v.1.5.0 print the expected output.

https://github.com/GoogleCloudPlatform/cloud-spanner-emulator/compare/v1.5.0...v1.5.1 The brackets in the value returned by col->expression().value() appear to have changed between v1.5.0 and v1.5.1, according to the revision history of backend/schema/updater/schema_updater_tests/column_default_values.cc.

image

https://github.com/GoogleCloudPlatform/cloud-spanner-emulator/blob/v1.5.4/backend/query/information_schema_catalog.cc#L388-L389 I have not checked all the processes, but the process of trimming the brackets () is still left, so I suspect that only the ) of CURRENT_TIMESTAMP() was deleted here.

This may seem like a minor issue, but if the results of INFORMATION_SCHEMA.COLUMNS are used in the test of the application, the test will fail because the expected output is not obtained.

gauravpurohit06 commented 1 year ago

Thank you @takabow for raising it here. We have fixed the issue and it will be rolled out in next release.