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

Added unit test to validate modify column followed by default NULL #966

Open
wants to merge 7 commits into
base: 2.5.1
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class Constants {
public static final String ADD_COLUMN = "ADD COLUMN %s %s";
public static final String ADD_COLUMN_NULLABLE = "ADD COLUMN %s Nullable(%s)";


public static final String MODIFY_COLUMN = "MODIFY COLUMN %s %s";
public static final String MODIFY_COLUMN_NULLABLE = "MODIFY COLUMN %s Nullable(%s)";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,9 @@ private void parseAlterTable(ParseTree tree) {
if (columnDefChild.getText().equalsIgnoreCase(Constants.NULL))
isNullColumn = true;
else if(columnDefChild.getText().equalsIgnoreCase(Constants.NOT_NULL)) {
isNullColumn = false;
if(!modifier.equalsIgnoreCase(Constants.ADD_COLUMN)) {
isNullColumn = false;
}
}
} else if (columnDefChild instanceof MySqlParser.DefaultColumnConstraintContext) {
if (columnDefChild.getChildCount() >= 2) {
Expand Down Expand Up @@ -528,6 +530,8 @@ else if(columnDefChild.getText().equalsIgnoreCase(Constants.NOT_NULL)) {
Map<String, Boolean> isNullableList = dbMetadata.getColumnsIsNullableForTable(tableName, writer.getConnection(), databaseName);
if (isNullableList.get(columnName) != null && isNullableList.get(columnName)) {
isNullColumn = true;
} else if (isNullableList.get(columnName) == null) {
isNullColumn = true;
} else {
isNullColumn = false;
}
Expand All @@ -541,8 +545,10 @@ else if(columnDefChild.getText().equalsIgnoreCase(Constants.NOT_NULL)) {
if (columnName != null && columnType != null)
if (isNullColumn) {
this.query.append(" ").append(String.format(modifierWithNull, columnName, columnType)).append(" ");
} else
}
else
this.query.append(" ").append(String.format(modifier, columnName, columnType));

if (defaultModifier != null && defaultModifier.isEmpty() == false) {
this.query.append(" ").append(defaultModifier);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@
StringBuffer clickHouseQuery = new StringBuffer();
mySQLDDLParserService.parseSql(mysqlQuery, "add_test", clickHouseQuery);

String expectedCHQuery = "ALTER TABLE employees.add_test ADD COLUMN customer_address String, ADD COLUMN customer_name Nullable(String)";
String expectedCHQuery = "ALTER TABLE employees.add_test ADD COLUMN customer_address Nullable(String), ADD COLUMN customer_name Nullable(String)";
Assert.assertTrue(clickHouseQuery.toString().equalsIgnoreCase(expectedCHQuery));
log.info("CLICKHOUSE QUERY: " + clickHouseQuery);
}
Expand Down Expand Up @@ -436,6 +436,13 @@
Assert.assertTrue(clickHouseQuery.toString().equalsIgnoreCase("ALTER TABLE employees.add_test MODIFY COLUMN col1 Int32"));
}

@Test
public void testAlterTableModifyAddColumn() {
StringBuffer clickHouseQuery2 = new StringBuffer();
String alterTableModifyColumn2 = "alter table test1 add column `vendor_folder` varchar(128) COLLATE latin1_general_cs NOT NULL after expected_arrival_time";
mySQLDDLParserService.parseSql(alterTableModifyColumn2, "add_test", clickHouseQuery2);
Assert.assertTrue(clickHouseQuery2.toString().equalsIgnoreCase("ALTER TABLE employees.test1 ADD COLUMN `vendor_folder` Nullable(String) after expected_arrival_time"));
}

@Test
public void testAlterDatabaseModifyColumns() {
Expand Down Expand Up @@ -465,7 +472,7 @@

mySQLDDLParserService.parseSql(sql, "products", clickHouseQuery);

Assert.assertTrue(clickHouseQuery.toString().equalsIgnoreCase("ALTER TABLE employees.products ADD COLUMN stocks Int32"));

Check failure on line 475 in sink-connector-lightweight/src/test/java/com/altinity/clickhouse/debezium/embedded/ddl/parser/MySqlDDLParserListenerImplTest.java

View workflow job for this annotation

GitHub Actions / JUnit Test Report

MySqlDDLParserListenerImplTest.testAlterTableWithNotNullAndDefault

java.lang.AssertionError at com.altinity.clickhouse.debezium.embedded.ddl.parser.MySqlDDLParserListenerImplTest.testAlterTableWithNotNullAndDefault(MySqlDDLParserListenerImplTest.java:475)
Raw output
java.lang.AssertionError
	at com.altinity.clickhouse.debezium.embedded.ddl.parser.MySqlDDLParserListenerImplTest.testAlterTableWithNotNullAndDefault(MySqlDDLParserListenerImplTest.java:475)
StringBuffer clickHouseQuery2 = new StringBuffer();

String defaultSql = "alter table add_test add column stocks bool null default 1;";
Expand Down Expand Up @@ -871,7 +878,7 @@
log.info("CLICKHOUSE QUERY " + clickHouseQuery);

Assert.assertTrue(clickHouseQuery != null && clickHouseQuery.length() != 0);
Assert.assertTrue(clickHouseQuery.toString().equalsIgnoreCase(clickhouseExpectedQuery));

Check failure on line 881 in sink-connector-lightweight/src/test/java/com/altinity/clickhouse/debezium/embedded/ddl/parser/MySqlDDLParserListenerImplTest.java

View workflow job for this annotation

GitHub Actions / JUnit Test Report

MySqlDDLParserListenerImplTest.testAlterDatabaseAddColumnEnum

java.lang.AssertionError at com.altinity.clickhouse.debezium.embedded.ddl.parser.MySqlDDLParserListenerImplTest.testAlterDatabaseAddColumnEnum(MySqlDDLParserListenerImplTest.java:881)
Raw output
java.lang.AssertionError
	at com.altinity.clickhouse.debezium.embedded.ddl.parser.MySqlDDLParserListenerImplTest.testAlterDatabaseAddColumnEnum(MySqlDDLParserListenerImplTest.java:881)
}

@Test
Expand All @@ -884,7 +891,7 @@
log.info("CLICKHOUSE QUERY " + clickHouseQuery);

Assert.assertTrue(clickHouseQuery != null && clickHouseQuery.length() != 0);
Assert.assertTrue(clickHouseQuery.toString().equalsIgnoreCase(clickhouseExpectedQuery));

Check failure on line 894 in sink-connector-lightweight/src/test/java/com/altinity/clickhouse/debezium/embedded/ddl/parser/MySqlDDLParserListenerImplTest.java

View workflow job for this annotation

GitHub Actions / JUnit Test Report

MySqlDDLParserListenerImplTest.testAlterDatabaseAddColumnJson

java.lang.AssertionError at com.altinity.clickhouse.debezium.embedded.ddl.parser.MySqlDDLParserListenerImplTest.testAlterDatabaseAddColumnJson(MySqlDDLParserListenerImplTest.java:894)
Raw output
java.lang.AssertionError
	at com.altinity.clickhouse.debezium.embedded.ddl.parser.MySqlDDLParserListenerImplTest.testAlterDatabaseAddColumnJson(MySqlDDLParserListenerImplTest.java:894)
}

@Test
Expand Down
Loading