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

Support MERGE for MySQL connector #24428

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chenjian2664
Copy link
Contributor

@chenjian2664 chenjian2664 commented Dec 10, 2024

Description

The tests that are updated in the BaseJdbcConnectorTest because current the implementation of MERGE for Mysql connector requires the table has primary keys, thus modified the table creation logic to use createTestTableForWrites, allowing the MySQL connector test class to override it and add primary keys as needed.

Release notes

## MySQL
* Add support for `MERGE` statement. ({issue}`issuenumber`)

@cla-bot cla-bot bot added the cla-signed label Dec 10, 2024
@chenjian2664 chenjian2664 force-pushed the mysql_merge branch 4 times, most recently from b4e8e08 to c0b86ce Compare December 10, 2024 12:42
@ebyhr
Copy link
Member

ebyhr commented Dec 10, 2024

current the implementation of MERGE for Mysql connector requires the table has primary keys

Is there a test verifying error message when executing MERGE statement on table without primary keys?

@chenjian2664 chenjian2664 force-pushed the mysql_merge branch 3 times, most recently from a4d84a0 to 3deed31 Compare December 16, 2024 09:06
@chenjian2664 chenjian2664 force-pushed the mysql_merge branch 2 times, most recently from 537b087 to 1146ad7 Compare December 19, 2024 07:52
Copy link

github-actions bot commented Jan 9, 2025

This pull request has gone a while without any activity. Tagging for triage help: @mosabua

@github-actions github-actions bot added the stale label Jan 9, 2025
@chenjian2664 chenjian2664 force-pushed the mysql_merge branch 2 times, most recently from d20d159 to 5b93e35 Compare January 15, 2025 09:51
@mosabua
Copy link
Member

mosabua commented Jan 15, 2025

Dont forget the docs update .. should be an easy one line include now ..

@github-actions github-actions bot removed the stale label Jan 15, 2025
@mosabua
Copy link
Member

mosabua commented Jan 15, 2025

Thank you @chenjian2664

@findinpath findinpath requested a review from ebyhr January 16, 2025 08:58
protected void testUpdateWithSubquery()
{
assertThatThrownBy(super::testUpdateWithSubquery).hasMessageContaining("Non-transactional MERGE is disabled");
abort("skipped");
Copy link
Member

Choose a reason for hiding this comment

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

Why does this test have abort and other two tests don't have the call?

Comment on lines +56 to +57
case SUPPORTS_ROW_LEVEL_UPDATE:
case SUPPORTS_MERGE:
Copy link
Member

Choose a reason for hiding this comment

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

Order by alphabetically.

@Override
protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
{
switch (connectorBehavior) {
case SUPPORTS_RENAME_SCHEMA:
return false;

case SUPPORTS_ROW_LEVEL_UPDATE:
case SUPPORTS_MERGE:
return true;
Copy link
Member

Choose a reason for hiding this comment

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

Move true cases above false case.

protected TestTable createTestTableForWrites(String tablePrefix)
{
TestTable table = super.createTestTableForWrites(tablePrefix);
String tableName = table.getName();
Copy link
Member

Choose a reason for hiding this comment

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

Inline tableName.

protected TestTable createTestTableForWrites(String namePrefix, String tableDefinition, String primaryKey)
{
TestTable testTable = super.createTestTableForWrites(namePrefix, tableDefinition, primaryKey);
String tableName = testTable.getName();
Copy link
Member

Choose a reason for hiding this comment

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

Inline tableName.

protected TestTable createTestTableForWrites(String namePrefix, String tableDefinition, List<String> rowsToInsert, String primaryKey)
{
TestTable testTable = super.createTestTableForWrites(namePrefix, tableDefinition, rowsToInsert, primaryKey);
String tableName = testTable.getName();
Copy link
Member

Choose a reason for hiding this comment

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

Inline tableName.

}

@Test
public void testMergeTargetWithNoPrimaryKeys()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public void testMergeTargetWithNoPrimaryKeys()
public void testMergeTargetWithoutPrimaryKeys()

Comment on lines +104 to +109
assertQueryFails(format("DELETE FROM %s WHERE a IS NOT NULL AND abs(a + b) > 10", tableName), "The connector can not perform merge on the target table without primary keys");
assertQueryFails(format("UPDATE %s SET a = a+b WHERE a IS NOT NULL AND (a + b) > 10", tableName), "The connector can not perform merge on the target table without primary keys");
assertQueryFails(format("MERGE INTO %s t USING (VALUES (3, 3)) AS s(x, y) " +
" ON t.a = s.x " +
" WHEN MATCHED THEN UPDATE SET b = y " +
" WHEN NOT MATCHED THEN INSERT (a, b) VALUES (s.x, s.y) ", tableName), "The connector can not perform merge on the target table without primary keys");
Copy link
Member

Choose a reason for hiding this comment

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

This exception comes from DefaultJdbcMetadata, not MySQL connector. Can we move this test to BaseJdbcConnectorTest?


Set<String> primaryKeyNames = new HashSet<>();
while (primaryKeys.next()) {
String columnName = primaryKeys.getString("COLUMN_NAME");
Copy link
Member

Choose a reason for hiding this comment

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

Inline columnName.

continue;
}
JdbcTypeHandle handle = columnHandle.getJdbcTypeHandle();
CaseSensitivity caseSensitivity = handle.caseSensitivity().orElse(CASE_INSENSITIVE);
Copy link
Member

Choose a reason for hiding this comment

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

Why do we want to set CASE_INSENSITIVE by default?

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