From 6564673ff92ca6dd2328dddb1515e71d0cb96ee8 Mon Sep 17 00:00:00 2001 From: Bolek Ziobrowski Date: Tue, 30 Nov 2021 18:15:17 +0100 Subject: [PATCH] fix(sql): ALTER TABLE ADD COLUMN parse error #1612 (#1634) --- .../java/io/questdb/griffin/SqlCompiler.java | 7 +++--- .../griffin/AlterTableAddColumnTest.java | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/io/questdb/griffin/SqlCompiler.java b/core/src/main/java/io/questdb/griffin/SqlCompiler.java index 41cbf42f9..c0be2914d 100644 --- a/core/src/main/java/io/questdb/griffin/SqlCompiler.java +++ b/core/src/main/java/io/questdb/griffin/SqlCompiler.java @@ -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; } diff --git a/core/src/test/java/io/questdb/griffin/AlterTableAddColumnTest.java b/core/src/test/java/io/questdb/griffin/AlterTableAddColumnTest.java index 62406f0fb..53dd530c7 100644 --- a/core/src/test/java/io/questdb/griffin/AlterTableAddColumnTest.java +++ b/core/src/test/java/io/questdb/griffin/AlterTableAddColumnTest.java @@ -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( -- GitLab