Skip to content

Allow enabling CDF using ALTER TABLE SET PROPERTIES#16221

Closed
homar wants to merge 2 commits intotrinodb:masterfrom
homar:homar/implement_set_table_properties_for_delta_lake
Closed

Allow enabling CDF using ALTER TABLE SET PROPERTIES#16221
homar wants to merge 2 commits intotrinodb:masterfrom
homar:homar/implement_set_table_properties_for_delta_lake

Conversation

@homar
Copy link
Copy Markdown
Member

@homar homar commented Feb 22, 2023

Description

Based on #16165
Allows setting on and off change_data_feed_enabled property

Additional context and related issues

Release notes

( ) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text:

# Section
* Fix some things. ({issue}`issuenumber`)

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.

Can we create a helper method to get the MetadataEntry? and we can use that helper method in appendTableEntries as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I tried but it became messy, I will do it as another PR, ok ?

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.

Since we are now supporting additional property in ALTER TABLE ..., protocolEntry should be appended if present.

Copy link
Copy Markdown
Member Author

@homar homar Feb 23, 2023

Choose a reason for hiding this comment

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

So I've just checked, I did run this three operations:
CREATE TABLE student31 (id INT, name STRING, age INT) USING DELTA LOCATION XXXX
INSERT INTO student31 VALUES(1, 'homar', 13);
ALTER TABLE student31 SET TBLPROPERTIES (delta.enableChangeDataFeed = true)

The last one resulted in creation of 00000000000000000002.json.
And it has protocol entry that looks like this:

{
  "protocol": {
    "minReaderVersion": 1,
    "minWriterVersion": 4
  }
}

So I don't think there is a need to add changeDataFeed there

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.

Yes, right the protocol version will not get updated and use the previous protocol version.

My point was whether adding a protocol entry in the transaction log is necessary if the user has not set reader_version or writer_version property using ALTER TABLE ....

CC: @alexjo2144

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

oh ok I see what you mean, so imho if we throw when writerVersion is too low then protocol version doesn't change here so there is no need to append it. i will change this

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.

testAlterTableWithUnsupportedProperties needs to be updated.

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.

Can we have tests with a combination of change_data_feed_enabled, ALTER_TABLE, and writer_version?

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.

Something like testCreateTableWithCdfEnabledAndUnsupportedWriterVersionFails, testCreateTableAsWithCdfPropertyWriterVersionNotUpgraded

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I modified the test I added and renamed it to testSettingChangeDataGeedEnabledProperty

@krvikash krvikash added the delta-lake Delta Lake connector label Feb 23, 2023
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.

nit: bring configuration inside the subsequent if - this is where it is only used (at the moment).

@homar homar force-pushed the homar/implement_set_table_properties_for_delta_lake branch from ffdab4f to d18c8fe Compare February 23, 2023 13:14
@krvikash
Copy link
Copy Markdown
Contributor

Please resolve conflicts. #16165 is merged now.

@homar homar force-pushed the homar/implement_set_table_properties_for_delta_lake branch from d18c8fe to b7332d5 Compare February 23, 2023 13:49
@homar homar changed the title Homar/implement set table properties for delta lake Allow enabling CDF using ALTER TABLE SET PROPERTIES Feb 23, 2023
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.

IMO, I'd go with earlier implementation instead of adding methods in ProtocolEntry.

        Optional<ProtocolEntry> protocolEntry = Optional.empty();
        if (readerVersion.isPresent() || writerVersion.isPresent()) {
            protocolEntry = Optional.of(new ProtocolEntry(
                    readerVersion.orElse(currentProtocolEntry.getMinReaderVersion()),
                    writerVersion.orElse(currentProtocolEntry.getMinWriterVersion())));
       }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ok, but i liked mine version ;)

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.

Can we keep this and verify the error does not include change_data_feed_enabled?

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.

I think this should work. since we are not enabling cdf. enabling cdf with writer_version less than 4 should throw exception.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

But in this case we don't set writer_version so it is set to 2, it is verified at the beginning of this test. I thought we agreed that we should not increase writer_version silently.

Copy link
Copy Markdown
Contributor

@krvikash krvikash Feb 24, 2023

Choose a reason for hiding this comment

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

yes right, we are not increasing writer_version silently.

change_data_feed_enabled = false is the same as not setting change_data_feed_enabled.

In my opinion, executing CREATE TABLE test (a INT) WITH (change_data_feed_enabled = false, writer_version = 3) or CREATE TABLE test (a INT) WITH (change_data_feed_enabled = false) does not result in an exception. Similarly, when running ALTER TABLE test SET PROPERTIES change_data_feed_enabled = false, exception should not be thrown, regardless of the value of writer_version.

Copy link
Copy Markdown
Contributor

@krvikash krvikash Feb 24, 2023

Choose a reason for hiding this comment

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

Edit: Validation of the writer_version should only be performed if the cdf is enabled.

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.

can we verify writer_version as well here along with change_data_feed_enabled?

@homar homar force-pushed the homar/implement_set_table_properties_for_delta_lake branch from b7332d5 to 05c94b8 Compare February 24, 2023 10:34
Copy link
Copy Markdown
Contributor

@krvikash krvikash left a comment

Choose a reason for hiding this comment

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

LGTM. few comments.

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.

We can remove this. Already covered inside testCreateTableWithCdfPropertyWriterVersionNotUpgraded.

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.

we can include test for ALTER TABLE " + tableName + " SET PROPERTIES change_data_feed_enabled = false, writer_version = 3

@homar homar force-pushed the homar/implement_set_table_properties_for_delta_lake branch from 05c94b8 to 777c0b3 Compare February 24, 2023 11:38
@homar homar requested a review from krvikash February 24, 2023 11:38
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.

nit: tableName1 -> tableName

@homar homar force-pushed the homar/implement_set_table_properties_for_delta_lake branch from 777c0b3 to 0d87b39 Compare February 24, 2023 12:11
Comment on lines 1922 to 1924
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
metadataEntry = Optional.of(buildMetadataEntry(session, handle, configuration, createdTime));
if (changeDataFeedEnabled && ((writerVersion.isPresent() && writerVersion.get() < CDF_SUPPORTED_WRITER_VERSION) ||
(currentProtocolEntry.getMinWriterVersion() < CDF_SUPPORTED_WRITER_VERSION))) {
metadataEntry = Optional.of(buildMetadataEntry(session, handle, configuration, createdTime));
long newWriterVersion = writerVersion.orElse(currentProtocolEntry.getMinWriterVersion());
if (changeDataFeedEnabled && newWriterVersion < CDF_SUPPORTED_WRITER_VERSION) {

@homar homar force-pushed the homar/implement_set_table_properties_for_delta_lake branch from 0d87b39 to 7fd9cbd Compare February 24, 2023 20:30
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Move up with the other public properties

@homar homar force-pushed the homar/implement_set_table_properties_for_delta_lake branch from 7fd9cbd to 37f9211 Compare February 27, 2023 21:00
@ebyhr
Copy link
Copy Markdown
Member

ebyhr commented Feb 27, 2023

/test-with-secrets sha=37f9211dfa8fc250637eee45015afcd811ce5e90

ebyhr
ebyhr previously approved these changes Feb 28, 2023
@github-actions
Copy link
Copy Markdown

The CI workflow run with tests that require additional secrets finished as failure: https://github.com/trinodb/trino/actions/runs/4288682058

@homar homar force-pushed the homar/implement_set_table_properties_for_delta_lake branch from 37f9211 to ba0dfb5 Compare February 28, 2023 09:14
@ebyhr
Copy link
Copy Markdown
Member

ebyhr commented Feb 28, 2023

/test-with-secrets sha=ba0dfb55a6ac1b1601f113810b7590bfe5064362

@homar homar force-pushed the homar/implement_set_table_properties_for_delta_lake branch from ba0dfb5 to 14c03fc Compare February 28, 2023 15:46
@homar homar force-pushed the homar/implement_set_table_properties_for_delta_lake branch from 14c03fc to 4371c32 Compare February 28, 2023 18:27
@ebyhr ebyhr dismissed their stale review March 1, 2023 05:25

We're going to increase writer version automatically.

Optional<MetadataEntry> metadataEntry = Optional.empty();
if (properties.containsKey(CHANGE_DATA_FEED_ENABLED_PROPERTY)) {
boolean changeDataFeedEnabled = (Boolean) properties.get(CHANGE_DATA_FEED_ENABLED_PROPERTY)
.orElseThrow(() -> new IllegalArgumentException("The change_data_feed_enabled property cannot be empty"));
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.

double space.

@homar
Copy link
Copy Markdown
Member Author

homar commented Mar 1, 2023

closing in favour of #16310

@homar homar closed this Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

5 participants