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

Add test to ensure consistency of generated column and CDF in Delta #14629

Merged
merged 1 commit into from
Oct 26, 2022

Conversation

ebyhr
Copy link
Member

@ebyhr ebyhr commented Oct 14, 2022

Description

Add test to ensure consistency of generated column in Delta
Relates to #12637

Release notes

(x) This is not user-visible or docs only and no release notes are required.

@cla-bot cla-bot bot added the cla-signed label Oct 14, 2022
@ebyhr ebyhr force-pushed the ebi/delta-generated-column branch from 398c6f1 to 2882103 Compare October 14, 2022 05:47
@ebyhr ebyhr changed the title Add test to ensure consistency of generated column in Delta Add test to ensure consistency of generated column and CDF in Delta Oct 14, 2022
@ebyhr ebyhr mentioned this pull request Oct 14, 2022
6 tasks
@ebyhr ebyhr force-pushed the ebi/delta-generated-column branch 3 times, most recently from 1943ead to 7587828 Compare October 14, 2022 09:39
@ebyhr ebyhr requested review from homar and alexjo2144 October 14, 2022 09:39
@ebyhr ebyhr requested a review from findepi October 14, 2022 10:10
String tableDirectory = "databricks-compatibility-test-" + tableName;

onDelta().executeQuery(format("" +
"CREATE TABLE default.%s (col int) " +
Copy link
Member

Choose a reason for hiding this comment

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

nit: you can use multiline string literal

onTrino().executeQuery("COMMENT ON TABLE delta.default." + tableName + " IS 'test table comment'");
onTrino().executeQuery("ALTER TABLE delta.default." + tableName + " ADD COLUMN new_column INT");

List<?> enableChangeDataFeed = getOnlyElement(onDelta().executeQuery("SHOW TBLPROPERTIES " + tableName + "(delta.enableChangeDataFeed)").rows());
Copy link
Member

Choose a reason for hiding this comment

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

getOnlyElement -> getOnlyValue?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can't use getOnlyValue because SHOW TBLPROPERTIES returns two columns (key & value).

onTrino().executeQuery("ALTER TABLE delta.default." + tableName + " ADD COLUMN new_column INT");

List<?> enableChangeDataFeed = getOnlyElement(onDelta().executeQuery("SHOW TBLPROPERTIES " + tableName + "(delta.enableChangeDataFeed)").rows());
assertTrue(Boolean.parseBoolean((String) enableChangeDataFeed.get(1)));
Copy link
Member

Choose a reason for hiding this comment

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

try to use assertj so that enableChangeDataFeed value is provided (original, before parsing) when the assertion fails

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to getOnlyElement + QueryResult#column to improve the readability.

String tableDirectory = "databricks-compatibility-test-" + tableName;

onDelta().executeQuery(format("" +
"CREATE TABLE default.%s (a INT, b BOOLEAN GENERATED ALWAYS AS (CAST(true AS BOOLEAN))) " +
Copy link
Member

Choose a reason for hiding this comment

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

is the CAST required?

Would it make sense to have a slightly more complicated case. where you generate b from a value?

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to b INT GENERATED ALWAYS AS (a * 2) instead.

@ebyhr ebyhr force-pushed the ebi/delta-generated-column branch 2 times, most recently from f5b4be1 to 6c92d3b Compare October 21, 2022 07:55
@ebyhr ebyhr force-pushed the ebi/delta-generated-column branch from 6c92d3b to 667d842 Compare October 26, 2022 01:27
@ebyhr ebyhr merged commit aef32af into master Oct 26, 2022
@ebyhr ebyhr deleted the ebi/delta-generated-column branch October 26, 2022 03:24
@ebyhr ebyhr added this to the 401 milestone Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants