fix SQLColumnDefinition#getParent() is null, for issue #4492

This commit is contained in:
shaojin.wensj
2022-11-14 16:05:09 +08:00
parent 1e0e3ca1b7
commit cf1cdc4b23
2 changed files with 27 additions and 1 deletions
@@ -210,7 +210,7 @@ public class OdpsCreateTableParser extends SQLCreateTableParser {
throw new ParserException("expect identifier. " + lexer.info());
}
stmt.getTableElementList().add(column);
stmt.addColumn(column);
if (lexer.isKeepComments() && lexer.hasComment()) {
column.addAfterComment(lexer.readAndResetComments());
@@ -0,0 +1,26 @@
package com.alibaba.druid.bvt.sql.odps.issues;
import com.alibaba.druid.DbType;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
import org.junit.Test;
import static org.junit.Assert.*;
public class Issue4992 {
@Test
public void testInsert() {
String sql = "CREATE TABLE IF NOT EXISTS test_table \n" +
"(\n" +
" user_id STRING COMMENT\"userid\"\n" +
" ,user_features STRING COMMENT\"用户特征\"\n" +
")\n" +
";";
SQLCreateTableStatement stmt = (SQLCreateTableStatement) SQLUtils.parseSingleStatement(sql, DbType.odps);
SQLColumnDefinition column = stmt.getColumn("user_id");
assertNotNull(column);
assertNotNull(column.getParent());
assertSame(stmt, column.getParent());
}
}