未验证 提交 6564673f 编写于 作者: B Bolek Ziobrowski 提交者: GitHub

fix(sql): ALTER TABLE ADD COLUMN parse error #1612 (#1634)

上级 bdd70fed
......@@ -1062,7 +1062,8 @@ public class SqlCompiler implements Closeable {
int symbolCapacity;
final boolean indexed;
if (ColumnType.isSymbol(type) && tok != null && !Chars.equals(tok, ',')) {
if (ColumnType.isSymbol(type) && tok != null &&
!Chars.equals(tok, ',') && !Chars.equals(tok, ';')) {
if (isCapacityKeyword(tok)) {
tok = expectToken(lexer, "symbol capacity");
......@@ -1123,7 +1124,7 @@ public class SqlCompiler implements Closeable {
} else {
indexValueBlockCapacity = configuration.getIndexValueBlockSize();
}
} else {
} else { //set defaults
//ignoring `NULL` and `NOT NULL`
if (tok != null && SqlKeywords.isNotKeyword(tok)) {
......@@ -1161,7 +1162,7 @@ public class SqlCompiler implements Closeable {
.put(']');
}
if (tok == null) {
if (tok == null || Chars.equals(tok, ';')) {
break;
}
......
......@@ -351,6 +351,30 @@ public class AlterTableAddColumnTest extends AbstractGriffinTest {
assertFailure("alter table x add column abc blah", 29, "invalid type");
}
@Test
public void testAddSymbolWithStatementEndingWithSemicolon_DoesntThrowException() throws Exception {
assertMemoryLeak(
() -> {
createX();
engine.clear();
try (CairoEngine engine = new CairoEngine(configuration)) {
try (SqlCompiler compiler = new SqlCompiler(engine)) {
Assert.assertEquals(ALTER, compiler.compile("alter table x add column meh symbol;", sqlExecutionContext).getType());
try (TableReader reader = engine.getReader(AllowAllCairoSecurityContext.INSTANCE, "x", TableUtils.ANY_TABLE_ID, TableUtils.ANY_TABLE_VERSION)) {
SymbolMapReader smr = reader.getSymbolMapReader(16);
Assert.assertNotNull(smr);
Assert.assertEquals(configuration.getDefaultSymbolCapacity(), smr.getSymbolCapacity());
Assert.assertFalse(reader.getMetadata().isColumnIndexed(16));
Assert.assertEquals(configuration.getIndexValueBlockSize(), reader.getMetadata().getIndexValueBlockCapacity(16));
}
}
}
}
);
}
@Test
public void testAddSymbolCache() throws Exception {
assertMemoryLeak(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册