未验证 提交 fe40ded2 编写于 作者: M marregui 提交者: GitHub

fix(sql): allow quotes around dedup keys (#3691)

上级 ff0723e5
...@@ -914,9 +914,9 @@ public class SqlCompilerImpl implements SqlCompiler, Closeable { ...@@ -914,9 +914,9 @@ public class SqlCompilerImpl implements SqlCompiler, Closeable {
int columnListPos = lexer.lastTokenPosition(); int columnListPos = lexer.lastTokenPosition();
while (tok != null && !Chars.equals(tok, ')')) { while (tok != null && !Chars.equals(tok, ')')) {
final CharSequence columnName = tok;
validateLiteral(lexer.lastTokenPosition(), tok); validateLiteral(lexer.lastTokenPosition(), tok);
final CharSequence columnName = GenericLexer.unquote(tok);
int colIndex = tableMetadata.getColumnIndexQuiet(columnName); int colIndex = tableMetadata.getColumnIndexQuiet(columnName);
if (colIndex < 0) { if (colIndex < 0) {
throw SqlException.position(lexer.lastTokenPosition()).put("deduplicate key column not found [column=").put(columnName).put(']'); throw SqlException.position(lexer.lastTokenPosition()).put("deduplicate key column not found [column=").put(columnName).put(']');
......
...@@ -639,8 +639,8 @@ public class SqlParser { ...@@ -639,8 +639,8 @@ public class SqlParser {
int columnListPos = lexer.lastTokenPosition(); int columnListPos = lexer.lastTokenPosition();
while (tok != null && !Chars.equals(tok, ')')) { while (tok != null && !Chars.equals(tok, ')')) {
final CharSequence columnName = tok;
validateLiteral(lexer.lastTokenPosition(), tok); validateLiteral(lexer.lastTokenPosition(), tok);
final CharSequence columnName = GenericLexer.unquote(tok);
int colIndex = model.getColumnIndex(columnName); int colIndex = model.getColumnIndex(columnName);
if (colIndex < 0) { if (colIndex < 0) {
......
...@@ -162,6 +162,37 @@ public class CreateTableDedupTest extends AbstractCairoTest { ...@@ -162,6 +162,37 @@ public class CreateTableDedupTest extends AbstractCairoTest {
}); });
} }
@Test
public void testCreateTableWithDoubleQuotes() throws Exception {
String tableName = testName.getMethodName() + " a 欢迎回来 to you";
assertMemoryLeak(ff, () -> {
ddl(
"CREATE TABLE '" + tableName + "' (\n" +
" Status SYMBOL capacity 16 CACHE,\n" +
" \"Reported time\" TIMESTAMP\n" +
" ) timestamp (\"Reported time\") PARTITION BY DAY WAL DEDUP UPSERT KEYS(\"Reported time\");"
);
try (TableWriter writer = getWriter(tableName)) {
Assert.assertTrue(writer.getMetadata().isDedupKey(1));
}
assertSql(
"column\ttype\tindexed\tindexBlockCapacity\tsymbolCached\tsymbolCapacity\tdesignated\tupsertKey\n" +
"Status\tSYMBOL\tfalse\t256\ttrue\t16\tfalse\tfalse\n" +
"Reported time\tTIMESTAMP\tfalse\t0\tfalse\t0\ttrue\ttrue\n",
"SHOW COLUMNS FROM '" + tableName + '\''
);
ddl("alter table '" + tableName + "' DEDUP DISABLE;");
ddl("alter table '" + tableName + "' DEDUP ENABLE UPSERT KEYS(\"Reported time\");");
drainWalQueue();
assertSql(
"column\ttype\tindexed\tindexBlockCapacity\tsymbolCached\tsymbolCapacity\tdesignated\tupsertKey\n" +
"Status\tSYMBOL\tfalse\t256\ttrue\t16\tfalse\tfalse\n" +
"Reported time\tTIMESTAMP\tfalse\t0\tfalse\t0\ttrue\ttrue\n",
"SHOW COLUMNS FROM '" + tableName + '\''
);
});
}
@Test @Test
public void testDedupEnabledTimestampOnly() throws Exception { public void testDedupEnabledTimestampOnly() throws Exception {
String tableName = testName.getMethodName(); String tableName = testName.getMethodName();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册