Skip to content

Commit

Permalink
Merge pull request #560 from Altinity/fix_alter_column
Browse files Browse the repository at this point in the history
Fix alter drop column
  • Loading branch information
subkanthi authored May 5, 2024
2 parents 3548fe4 + 313c8b8 commit d8ba8ee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ public void enterAlterTable(MySqlParser.AlterTableContext alterTableContext) {
for (ParseTree dropColumnTree : ((MySqlParser.AlterByDropColumnContext) (tree)).children) {
if (dropColumnTree instanceof MySqlParser.UidContext) {
for(ParseTree dropColumnChild: ((MySqlParser.UidContext) dropColumnTree).children) {
if(dropColumnChild instanceof MySqlParser.SimpleIdContext) {
if(dropColumnChild instanceof MySqlParser.SimpleIdContext || dropColumnChild instanceof TerminalNodeImpl) {
this.query.append(String.format(Constants.DROP_COLUMN, dropColumnChild.getText()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public void testAddColumn() throws Exception {
conn.prepareStatement(" alter table add_test drop column col101;").execute();
conn.prepareStatement(" alter table add_test add column col5 ENUM ('M','F');").execute();
conn.prepareStatement(" alter table add_test add column col6 JSON;").execute();
conn.prepareStatement(" alter table add_test drop col4").execute();

Thread.sleep(25000);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,16 @@ public void testDropColumn() {

}

@Test
public void testDropColumnWithoutColumnSyntax() {
StringBuffer clickHouseQuery = new StringBuffer();

String sql = "alter table `leads` drop `country`";
mySQLDDLParserService.parseSql(sql, "", clickHouseQuery);

Assert.assertTrue(clickHouseQuery.toString().equalsIgnoreCase("alter table employees.`leads` drop column `country`"));
}

@Test
public void renameMultipleTables() {
StringBuffer clickHouseQuery = new StringBuffer();
Expand Down

0 comments on commit d8ba8ee

Please sign in to comment.