diff --git a/core/src/main/java/com/questdb/cairo/TableUtils.java b/core/src/main/java/com/questdb/cairo/TableUtils.java index ddd613624122a36f07f75b5798d2ecc090b36868..ccd0209d1531b234227181f78318fe63259ff6a6 100644 --- a/core/src/main/java/com/questdb/cairo/TableUtils.java +++ b/core/src/main/java/com/questdb/cairo/TableUtils.java @@ -383,6 +383,12 @@ public final class TableUtils { } } + public static void validateSymbolCapacityCached(boolean cache, int symbolCapacity, int cacheKeywordPosition) throws SqlException { + if (cache && symbolCapacity > MAX_SYMBOL_CAPACITY_CACHED) { + throw SqlException.$(cacheKeywordPosition, "max cached symbol capacity is ").put(MAX_SYMBOL_CAPACITY_CACHED); + } + } + static { DateFormatCompiler compiler = new DateFormatCompiler(); fmtDay = compiler.compile("yyyy-MM-dd"); diff --git a/core/src/main/java/com/questdb/griffin/SqlCompiler.java b/core/src/main/java/com/questdb/griffin/SqlCompiler.java index 07e0fd327fbf5c1fc419b640e724fb7944e80ea6..93d82133c0780dc2244726cf4bec37c3b1613f76 100644 --- a/core/src/main/java/com/questdb/griffin/SqlCompiler.java +++ b/core/src/main/java/com/questdb/griffin/SqlCompiler.java @@ -703,9 +703,7 @@ public class SqlCompiler implements Closeable { cache = configuration.getDefaultSymbolCacheFlag(); } - if (cache && symbolCapacity > TableUtils.MAX_SYMBOL_CAPACITY_CACHED) { - throw SqlException.$(lexer.lastTokenPosition(), "max cached symbol capacity is ").put(TableUtils.MAX_SYMBOL_CAPACITY_CACHED); - } + TableUtils.validateSymbolCapacityCached(cache, symbolCapacity, lexer.lastTokenPosition()); indexed = Chars.equalsNc("index", tok); if (indexed) { @@ -1028,17 +1026,31 @@ public class SqlCompiler implements Closeable { } if (columnType == ColumnType.SYMBOL) { - int symbolCapacity = model.getSymbolCapacity(i); - if (symbolCapacity == -1) { - symbolCapacity = configuration.getDefaultSymbolCapacity(); + final ColumnCastModel ccm = model.getColumnCastModels().get(metadata.getColumnName(i)); + int symbolCapacity; + if (ccm != null) { + symbolCapacity = ccm.getSymbolCapacity(); + } else { + symbolCapacity = model.getSymbolCapacity(i); + if (symbolCapacity == -1) { + symbolCapacity = configuration.getDefaultSymbolCapacity(); + } } + + boolean cached; + if (ccm != null) { + cached = ccm.isCached(); + } else { + cached = model.getSymbolCacheFlag(i); + } + SymbolMapWriter.createSymbolMapFiles( ff, mem, path.trimTo(rootLen), model.getColumnName(i), symbolCapacity, - model.getSymbolCacheFlag(i) + cached ); symbolMapCount++; } diff --git a/core/src/main/java/com/questdb/griffin/SqlParser.java b/core/src/main/java/com/questdb/griffin/SqlParser.java index 48d6f5856c26cf1fa066deed608f0ff07e80416b..af316e757850bc36425df13d73d6b895081ba6d0 100644 --- a/core/src/main/java/com/questdb/griffin/SqlParser.java +++ b/core/src/main/java/com/questdb/griffin/SqlParser.java @@ -339,11 +339,35 @@ public final class SqlParser { columnCastModel.setType(type, columnName.position, columnType.position); if (type == ColumnType.SYMBOL) { - if (Chars.equals(optTok(lexer), "capacity")) { - columnCastModel.setSymbolCapacity(parseSymbolCapacity(lexer)); + CharSequence tok = tok(lexer, "'capacity', 'nocache', 'cache', 'index' or ')'"); + + int symbolCapacity; + int capacityPosition; + if (Chars.equals(tok, "capacity")) { + capacityPosition = lexer.getPosition(); + columnCastModel.setSymbolCapacity(symbolCapacity = parseSymbolCapacity(lexer)); + tok = tok(lexer, "'nocache', 'cache', 'index' or ')'"); } else { - lexer.unparse(); columnCastModel.setSymbolCapacity(configuration.getDefaultSymbolCapacity()); + symbolCapacity = -1; + capacityPosition = -1; + } + + final boolean cached; + if (Chars.equals(tok, "nocache")) { + cached = false; + } else if (Chars.equals(tok, "cache")) { + cached = true; + } else { + cached = configuration.getDefaultSymbolCacheFlag(); + lexer.unparse(); + } + + columnCastModel.setCached(cached); + + if (cached && symbolCapacity != -1) { + assert capacityPosition != -1; + TableUtils.validateSymbolCapacityCached(true, symbolCapacity, capacityPosition); } } @@ -371,18 +395,28 @@ public final class SqlParser { case ColumnType.SYMBOL: tok = tok(lexer, "'capacity', 'nocache', 'cache', 'index' or ')'"); + int symbolCapacity; if (Chars.equals(tok, "capacity")) { - model.symbolCapacity(parseSymbolCapacity(lexer)); + // when capacity is not set explicitly it will default via configuration + model.symbolCapacity(symbolCapacity = parseSymbolCapacity(lexer)); tok = tok(lexer, "'nocache', 'cache', 'index' or ')'"); + } else { + symbolCapacity = -1; } + final boolean cached; if (Chars.equals(tok, "nocache")) { - model.cached(false); + cached = false; } else if (Chars.equals(tok, "cache")) { - model.cached(true); + cached = true; } else { + cached = configuration.getDefaultSymbolCacheFlag(); lexer.unparse(); } + model.cached(cached); + if (cached && symbolCapacity != -1) { + TableUtils.validateSymbolCapacityCached(true, symbolCapacity, lexer.lastTokenPosition()); + } tok = parseCreateTableInlineIndexDef(lexer, model); break; default: diff --git a/core/src/main/java/com/questdb/griffin/model/ColumnCastModel.java b/core/src/main/java/com/questdb/griffin/model/ColumnCastModel.java index 608b26bc1d00c7c000f8975d1250373c7529d389..dba89332f329331488af7359c3728d4f60361e75 100644 --- a/core/src/main/java/com/questdb/griffin/model/ColumnCastModel.java +++ b/core/src/main/java/com/questdb/griffin/model/ColumnCastModel.java @@ -34,6 +34,7 @@ public class ColumnCastModel implements Mutable { private int columnTypePos; private int columnNamePos; private int symbolCapacity; + private boolean cached; private ColumnCastModel() { } @@ -71,6 +72,14 @@ public class ColumnCastModel implements Mutable { this.symbolCapacity = symbolCapacity; } + public boolean isCached() { + return cached; + } + + public void setCached(boolean cached) { + this.cached = cached; + } + public void setType(int columnType, int columnNamePos, int columnTypePos) { this.columnType = columnType; this.columnNamePos = columnNamePos; diff --git a/core/src/test/java/com/questdb/griffin/SqlCodeGeneratorTest.java b/core/src/test/java/com/questdb/griffin/SqlCodeGeneratorTest.java index e283717fc90a7350f5f4b31f3596b52dfade3421..57c6f7737b5b8076b5839a041889bb038876d93b 100644 --- a/core/src/test/java/com/questdb/griffin/SqlCodeGeneratorTest.java +++ b/core/src/test/java/com/questdb/griffin/SqlCodeGeneratorTest.java @@ -55,6 +55,23 @@ public class SqlCodeGeneratorTest extends AbstractGriffinTest { null, null); } + @Test + public void testCreateTableSymbolColumnViaCastCachedSymbolCapacityHigh() throws Exception { + TestUtils.assertMemoryLeak(() -> { + Assert.assertNull(compiler.compile("create table x (col string)", bindVariableService)); + try { + compiler.compile("create table y as (x), cast(col as symbol capacity 100000000)", bindVariableService); + Assert.fail(); + } catch (SqlException e) { + Assert.assertEquals(51, e.getPosition()); + TestUtils.assertContains(e.getMessage(), "max cached symbol capacity"); + } + + engine.releaseAllWriters(); + engine.releaseAllReaders(); + }); + } + @Test public void testFilterAPI() throws Exception { TestMatchFunctionFactory.clear(); @@ -2092,6 +2109,211 @@ public class SqlCodeGeneratorTest extends AbstractGriffinTest { "1569490116\tfalse\tZ\tNaN\t0.7611\t428\t2015-05-16T20:27:48.158Z\tVTJW\t-8671107786057422727\t1970-01-01T00:00:00.000000Z\t26\t00000000 68 61 26 af 19 c4 95 94 36 53 49\tFOWLPD\n"); } + @Test + public void testOrderByFull() throws Exception { + assertQuery("b\tsum\tk\n" + + "\t19.202208853548\t1970-01-03T00:00:00.000000Z\n" + + "\t32.540322001542\t1970-01-03T18:00:00.000000Z\n" + + "BHF\t87.996347253916\t1970-01-03T06:00:00.000000Z\n" + + "CPS\t80.432240999684\t1970-01-03T00:00:00.000000Z\n" + + "DEY\t66.938371476317\t1970-01-03T03:00:00.000000Z\n" + + "DOT\t45.659895188240\t1970-01-03T15:00:00.000000Z\n" + + "DXY\t2.165181900725\t1970-01-03T06:00:00.000000Z\n" + + "EDR\t96.874232769402\t1970-01-03T09:00:00.000000Z\n" + + "FBV\t77.639046748187\t1970-01-03T12:00:00.000000Z\n" + + "JMY\t38.642336707856\t1970-01-03T12:00:00.000000Z\n" + + "KGH\t56.594291398612\t1970-01-03T15:00:00.000000Z\n" + + "OFJ\t34.356853329430\t1970-01-03T09:00:00.000000Z\n" + + "OOZ\t49.005104498852\t1970-01-03T12:00:00.000000Z\n" + + "PGW\t55.991618048008\t1970-01-03T03:00:00.000000Z\n" + + "RSZ\t41.381647482277\t1970-01-03T09:00:00.000000Z\n" + + "UOJ\t63.816075311785\t1970-01-03T06:00:00.000000Z\n" + + "UXI\t34.910703637305\t1970-01-03T03:00:00.000000Z\n" + + "XPE\t20.447441837878\t1970-01-03T00:00:00.000000Z\n" + + "YCT\t57.789479151824\t1970-01-03T18:00:00.000000Z\n" + + "ZOU\t65.903416076922\t1970-01-03T15:00:00.000000Z\n", + // we have 'sample by fill(none)' because it doesn't support + // random record access, which is what we intend on testing + "select b, sum(a), k from x sample by 3h fill(none) order by b", + "create table x as " + + "(" + + "select" + + " rnd_double(0)*100 a," + + " rnd_str(3,3,2) b," + + " timestamp_sequence(to_timestamp(172800000000), 3600000000) k" + + " from" + + " long_sequence(20)" + + ") timestamp(k) partition by NONE", + null, + "insert into x select * from (" + + "select" + + " rnd_double(0)*100 a," + + " rnd_str(3,3,2) b," + + " timestamp_sequence(to_timestamp(277200000000), 3600000000) k" + + " from" + + " long_sequence(5)" + + ") timestamp(k)", + "b\tsum\tk\n" + + "\t19.202208853548\t1970-01-03T00:00:00.000000Z\n" + + "\t32.540322001542\t1970-01-03T18:00:00.000000Z\n" + + "\t3.831785863681\t1970-01-04T03:00:00.000000Z\n" + + "\t71.339102715558\t1970-01-04T06:00:00.000000Z\n" + + "BHF\t87.996347253916\t1970-01-03T06:00:00.000000Z\n" + + "CPS\t80.432240999684\t1970-01-03T00:00:00.000000Z\n" + + "DEY\t66.938371476317\t1970-01-03T03:00:00.000000Z\n" + + "DOT\t45.659895188240\t1970-01-03T15:00:00.000000Z\n" + + "DXY\t2.165181900725\t1970-01-03T06:00:00.000000Z\n" + + "EDR\t96.874232769402\t1970-01-03T09:00:00.000000Z\n" + + "FBV\t77.639046748187\t1970-01-03T12:00:00.000000Z\n" + + "JMY\t38.642336707856\t1970-01-03T12:00:00.000000Z\n" + + "KGH\t56.594291398612\t1970-01-03T15:00:00.000000Z\n" + + "NVT\t95.400690890497\t1970-01-04T06:00:00.000000Z\n" + + "OFJ\t34.356853329430\t1970-01-03T09:00:00.000000Z\n" + + "OOZ\t49.005104498852\t1970-01-03T12:00:00.000000Z\n" + + "PGW\t55.991618048008\t1970-01-03T03:00:00.000000Z\n" + + "RSZ\t41.381647482277\t1970-01-03T09:00:00.000000Z\n" + + "UOJ\t63.816075311785\t1970-01-03T06:00:00.000000Z\n" + + "UXI\t34.910703637305\t1970-01-03T03:00:00.000000Z\n" + + "WUG\t58.912164838798\t1970-01-04T06:00:00.000000Z\n" + + "XIO\t14.830552335849\t1970-01-04T09:00:00.000000Z\n" + + "XPE\t20.447441837878\t1970-01-03T00:00:00.000000Z\n" + + "YCT\t57.789479151824\t1970-01-03T18:00:00.000000Z\n" + + "ZOU\t65.903416076922\t1970-01-03T15:00:00.000000Z\n", + true); + } + + @Test + public void testOrderByFullSymbol() throws Exception { + assertQuery("b\tsum\tk\n" + + "\t144.984487170905\t1970-01-03T00:00:00.000000Z\n" + + "\t87.996347253916\t1970-01-03T03:00:00.000000Z\n" + + "\t146.379436136862\t1970-01-03T06:00:00.000000Z\n" + + "\t52.984059417621\t1970-01-03T12:00:00.000000Z\n" + + "\t177.513199934642\t1970-01-03T15:00:00.000000Z\n" + + "CPSW\t78.830658300550\t1970-01-03T12:00:00.000000Z\n" + + "HYRX\t186.000108135441\t1970-01-03T09:00:00.000000Z\n" + + "HYRX\t84.452581772111\t1970-01-03T12:00:00.000000Z\n" + + "HYRX\t157.953455546780\t1970-01-03T18:00:00.000000Z\n" + + "PEHN\t11.427984775756\t1970-01-03T00:00:00.000000Z\n" + + "PEHN\t94.848894980177\t1970-01-03T03:00:00.000000Z\n" + + "PEHN\t49.005104498852\t1970-01-03T15:00:00.000000Z\n" + + "VTJW\t40.228106267796\t1970-01-03T09:00:00.000000Z\n", + // we have 'sample by fill(none)' because it doesn't support + // random record access, which is what we intend on testing + "select b, sum(a), k from x sample by 3h fill(none) order by b", + "create table x as " + + "(" + + "select" + + " rnd_double(0)*100 a," + + " rnd_symbol(4,4,4,2) b," + + " timestamp_sequence(to_timestamp(172800000000), 3600000000) k" + + " from" + + " long_sequence(20)" + + ") timestamp(k) partition by NONE", + null, + "insert into x select * from (" + + "select" + + " rnd_double(0)*100 a," + + " rnd_symbol(4,4,4,2) b," + + " timestamp_sequence(to_timestamp(277200000000), 3600000000) k" + + " from" + + " long_sequence(5)" + + ") timestamp(k)", + "b\tsum\tk\n" + + "\t144.984487170905\t1970-01-03T00:00:00.000000Z\n" + + "\t87.996347253916\t1970-01-03T03:00:00.000000Z\n" + + "\t146.379436136862\t1970-01-03T06:00:00.000000Z\n" + + "\t52.984059417621\t1970-01-03T12:00:00.000000Z\n" + + "\t177.513199934642\t1970-01-03T15:00:00.000000Z\n" + + "\t57.789479151824\t1970-01-04T03:00:00.000000Z\n" + + "\t49.428905119585\t1970-01-04T06:00:00.000000Z\n" + + "CPSW\t78.830658300550\t1970-01-03T12:00:00.000000Z\n" + + "HYRX\t186.000108135441\t1970-01-03T09:00:00.000000Z\n" + + "HYRX\t84.452581772111\t1970-01-03T12:00:00.000000Z\n" + + "HYRX\t157.953455546780\t1970-01-03T18:00:00.000000Z\n" + + "OUIC\t86.851543054196\t1970-01-04T06:00:00.000000Z\n" + + "PEHN\t11.427984775756\t1970-01-03T00:00:00.000000Z\n" + + "PEHN\t94.848894980177\t1970-01-03T03:00:00.000000Z\n" + + "PEHN\t49.005104498852\t1970-01-03T15:00:00.000000Z\n" + + "SDOT\t12.024160875735\t1970-01-04T06:00:00.000000Z\n" + + "SDOT\t65.513358397963\t1970-01-04T09:00:00.000000Z\n" + + "VTJW\t40.228106267796\t1970-01-03T09:00:00.000000Z\n", + true); + } + + @Test + public void testOrderByFullTimestampLead() throws Exception { + assertQuery("b\tsum\tk\n" + + "\t19.202208853548\t1970-01-03T00:00:00.000000Z\n" + + "CPS\t80.432240999684\t1970-01-03T00:00:00.000000Z\n" + + "XPE\t20.447441837878\t1970-01-03T00:00:00.000000Z\n" + + "DEY\t66.938371476317\t1970-01-03T03:00:00.000000Z\n" + + "PGW\t55.991618048008\t1970-01-03T03:00:00.000000Z\n" + + "UXI\t34.910703637305\t1970-01-03T03:00:00.000000Z\n" + + "BHF\t87.996347253916\t1970-01-03T06:00:00.000000Z\n" + + "DXY\t2.165181900725\t1970-01-03T06:00:00.000000Z\n" + + "UOJ\t63.816075311785\t1970-01-03T06:00:00.000000Z\n" + + "EDR\t96.874232769402\t1970-01-03T09:00:00.000000Z\n" + + "OFJ\t34.356853329430\t1970-01-03T09:00:00.000000Z\n" + + "RSZ\t41.381647482277\t1970-01-03T09:00:00.000000Z\n" + + "FBV\t77.639046748187\t1970-01-03T12:00:00.000000Z\n" + + "JMY\t38.642336707856\t1970-01-03T12:00:00.000000Z\n" + + "OOZ\t49.005104498852\t1970-01-03T12:00:00.000000Z\n" + + "DOT\t45.659895188240\t1970-01-03T15:00:00.000000Z\n" + + "KGH\t56.594291398612\t1970-01-03T15:00:00.000000Z\n" + + "ZOU\t65.903416076922\t1970-01-03T15:00:00.000000Z\n" + + "\t32.540322001542\t1970-01-03T18:00:00.000000Z\n" + + "YCT\t57.789479151824\t1970-01-03T18:00:00.000000Z\n", + // we have 'sample by fill(none)' because it doesn't support + // random record access, which is what we intend on testing + "select b, sum(a), k from x sample by 3h fill(none) order by k,b", + "create table x as " + + "(" + + "select" + + " rnd_double(0)*100 a," + + " rnd_str(3,3,2) b," + + " timestamp_sequence(to_timestamp(172800000000), 3600000000) k" + + " from" + + " long_sequence(20)" + + ") timestamp(k) partition by NONE", + "k", + "insert into x select * from (" + + "select" + + " rnd_double(0)*100 a," + + " rnd_str(3,3,2) b," + + " timestamp_sequence(to_timestamp(277200000000), 3600000000) k" + + " from" + + " long_sequence(5)" + + ") timestamp(k)", + "b\tsum\tk\n" + + "\t19.202208853548\t1970-01-03T00:00:00.000000Z\n" + + "CPS\t80.432240999684\t1970-01-03T00:00:00.000000Z\n" + + "XPE\t20.447441837878\t1970-01-03T00:00:00.000000Z\n" + + "DEY\t66.938371476317\t1970-01-03T03:00:00.000000Z\n" + + "PGW\t55.991618048008\t1970-01-03T03:00:00.000000Z\n" + + "UXI\t34.910703637305\t1970-01-03T03:00:00.000000Z\n" + + "BHF\t87.996347253916\t1970-01-03T06:00:00.000000Z\n" + + "DXY\t2.165181900725\t1970-01-03T06:00:00.000000Z\n" + + "UOJ\t63.816075311785\t1970-01-03T06:00:00.000000Z\n" + + "EDR\t96.874232769402\t1970-01-03T09:00:00.000000Z\n" + + "OFJ\t34.356853329430\t1970-01-03T09:00:00.000000Z\n" + + "RSZ\t41.381647482277\t1970-01-03T09:00:00.000000Z\n" + + "FBV\t77.639046748187\t1970-01-03T12:00:00.000000Z\n" + + "JMY\t38.642336707856\t1970-01-03T12:00:00.000000Z\n" + + "OOZ\t49.005104498852\t1970-01-03T12:00:00.000000Z\n" + + "DOT\t45.659895188240\t1970-01-03T15:00:00.000000Z\n" + + "KGH\t56.594291398612\t1970-01-03T15:00:00.000000Z\n" + + "ZOU\t65.903416076922\t1970-01-03T15:00:00.000000Z\n" + + "\t32.540322001542\t1970-01-03T18:00:00.000000Z\n" + + "YCT\t57.789479151824\t1970-01-03T18:00:00.000000Z\n" + + "\t3.831785863681\t1970-01-04T03:00:00.000000Z\n" + + "\t71.339102715558\t1970-01-04T06:00:00.000000Z\n" + + "NVT\t95.400690890497\t1970-01-04T06:00:00.000000Z\n" + + "WUG\t58.912164838798\t1970-01-04T06:00:00.000000Z\n" + + "XIO\t14.830552335849\t1970-01-04T09:00:00.000000Z\n", + true); + } + @Test public void testOrderByNonUnique() throws Exception { final String expected = "a\tc\tk\tn\n" + @@ -2369,211 +2591,6 @@ public class SqlCodeGeneratorTest extends AbstractGriffinTest { } - @Test - public void testOrderByFull() throws Exception { - assertQuery("b\tsum\tk\n" + - "\t19.202208853548\t1970-01-03T00:00:00.000000Z\n" + - "\t32.540322001542\t1970-01-03T18:00:00.000000Z\n" + - "BHF\t87.996347253916\t1970-01-03T06:00:00.000000Z\n" + - "CPS\t80.432240999684\t1970-01-03T00:00:00.000000Z\n" + - "DEY\t66.938371476317\t1970-01-03T03:00:00.000000Z\n" + - "DOT\t45.659895188240\t1970-01-03T15:00:00.000000Z\n" + - "DXY\t2.165181900725\t1970-01-03T06:00:00.000000Z\n" + - "EDR\t96.874232769402\t1970-01-03T09:00:00.000000Z\n" + - "FBV\t77.639046748187\t1970-01-03T12:00:00.000000Z\n" + - "JMY\t38.642336707856\t1970-01-03T12:00:00.000000Z\n" + - "KGH\t56.594291398612\t1970-01-03T15:00:00.000000Z\n" + - "OFJ\t34.356853329430\t1970-01-03T09:00:00.000000Z\n" + - "OOZ\t49.005104498852\t1970-01-03T12:00:00.000000Z\n" + - "PGW\t55.991618048008\t1970-01-03T03:00:00.000000Z\n" + - "RSZ\t41.381647482277\t1970-01-03T09:00:00.000000Z\n" + - "UOJ\t63.816075311785\t1970-01-03T06:00:00.000000Z\n" + - "UXI\t34.910703637305\t1970-01-03T03:00:00.000000Z\n" + - "XPE\t20.447441837878\t1970-01-03T00:00:00.000000Z\n" + - "YCT\t57.789479151824\t1970-01-03T18:00:00.000000Z\n" + - "ZOU\t65.903416076922\t1970-01-03T15:00:00.000000Z\n", - // we have 'sample by fill(none)' because it doesn't support - // random record access, which is what we intend on testing - "select b, sum(a), k from x sample by 3h fill(none) order by b", - "create table x as " + - "(" + - "select" + - " rnd_double(0)*100 a," + - " rnd_str(3,3,2) b," + - " timestamp_sequence(to_timestamp(172800000000), 3600000000) k" + - " from" + - " long_sequence(20)" + - ") timestamp(k) partition by NONE", - null, - "insert into x select * from (" + - "select" + - " rnd_double(0)*100 a," + - " rnd_str(3,3,2) b," + - " timestamp_sequence(to_timestamp(277200000000), 3600000000) k" + - " from" + - " long_sequence(5)" + - ") timestamp(k)", - "b\tsum\tk\n" + - "\t19.202208853548\t1970-01-03T00:00:00.000000Z\n" + - "\t32.540322001542\t1970-01-03T18:00:00.000000Z\n" + - "\t3.831785863681\t1970-01-04T03:00:00.000000Z\n" + - "\t71.339102715558\t1970-01-04T06:00:00.000000Z\n" + - "BHF\t87.996347253916\t1970-01-03T06:00:00.000000Z\n" + - "CPS\t80.432240999684\t1970-01-03T00:00:00.000000Z\n" + - "DEY\t66.938371476317\t1970-01-03T03:00:00.000000Z\n" + - "DOT\t45.659895188240\t1970-01-03T15:00:00.000000Z\n" + - "DXY\t2.165181900725\t1970-01-03T06:00:00.000000Z\n" + - "EDR\t96.874232769402\t1970-01-03T09:00:00.000000Z\n" + - "FBV\t77.639046748187\t1970-01-03T12:00:00.000000Z\n" + - "JMY\t38.642336707856\t1970-01-03T12:00:00.000000Z\n" + - "KGH\t56.594291398612\t1970-01-03T15:00:00.000000Z\n" + - "NVT\t95.400690890497\t1970-01-04T06:00:00.000000Z\n" + - "OFJ\t34.356853329430\t1970-01-03T09:00:00.000000Z\n" + - "OOZ\t49.005104498852\t1970-01-03T12:00:00.000000Z\n" + - "PGW\t55.991618048008\t1970-01-03T03:00:00.000000Z\n" + - "RSZ\t41.381647482277\t1970-01-03T09:00:00.000000Z\n" + - "UOJ\t63.816075311785\t1970-01-03T06:00:00.000000Z\n" + - "UXI\t34.910703637305\t1970-01-03T03:00:00.000000Z\n" + - "WUG\t58.912164838798\t1970-01-04T06:00:00.000000Z\n" + - "XIO\t14.830552335849\t1970-01-04T09:00:00.000000Z\n" + - "XPE\t20.447441837878\t1970-01-03T00:00:00.000000Z\n" + - "YCT\t57.789479151824\t1970-01-03T18:00:00.000000Z\n" + - "ZOU\t65.903416076922\t1970-01-03T15:00:00.000000Z\n", - true); - } - - @Test - public void testOrderByFullTimestampLead() throws Exception { - assertQuery("b\tsum\tk\n" + - "\t19.202208853548\t1970-01-03T00:00:00.000000Z\n" + - "CPS\t80.432240999684\t1970-01-03T00:00:00.000000Z\n" + - "XPE\t20.447441837878\t1970-01-03T00:00:00.000000Z\n" + - "DEY\t66.938371476317\t1970-01-03T03:00:00.000000Z\n" + - "PGW\t55.991618048008\t1970-01-03T03:00:00.000000Z\n" + - "UXI\t34.910703637305\t1970-01-03T03:00:00.000000Z\n" + - "BHF\t87.996347253916\t1970-01-03T06:00:00.000000Z\n" + - "DXY\t2.165181900725\t1970-01-03T06:00:00.000000Z\n" + - "UOJ\t63.816075311785\t1970-01-03T06:00:00.000000Z\n" + - "EDR\t96.874232769402\t1970-01-03T09:00:00.000000Z\n" + - "OFJ\t34.356853329430\t1970-01-03T09:00:00.000000Z\n" + - "RSZ\t41.381647482277\t1970-01-03T09:00:00.000000Z\n" + - "FBV\t77.639046748187\t1970-01-03T12:00:00.000000Z\n" + - "JMY\t38.642336707856\t1970-01-03T12:00:00.000000Z\n" + - "OOZ\t49.005104498852\t1970-01-03T12:00:00.000000Z\n" + - "DOT\t45.659895188240\t1970-01-03T15:00:00.000000Z\n" + - "KGH\t56.594291398612\t1970-01-03T15:00:00.000000Z\n" + - "ZOU\t65.903416076922\t1970-01-03T15:00:00.000000Z\n" + - "\t32.540322001542\t1970-01-03T18:00:00.000000Z\n" + - "YCT\t57.789479151824\t1970-01-03T18:00:00.000000Z\n", - // we have 'sample by fill(none)' because it doesn't support - // random record access, which is what we intend on testing - "select b, sum(a), k from x sample by 3h fill(none) order by k,b", - "create table x as " + - "(" + - "select" + - " rnd_double(0)*100 a," + - " rnd_str(3,3,2) b," + - " timestamp_sequence(to_timestamp(172800000000), 3600000000) k" + - " from" + - " long_sequence(20)" + - ") timestamp(k) partition by NONE", - "k", - "insert into x select * from (" + - "select" + - " rnd_double(0)*100 a," + - " rnd_str(3,3,2) b," + - " timestamp_sequence(to_timestamp(277200000000), 3600000000) k" + - " from" + - " long_sequence(5)" + - ") timestamp(k)", - "b\tsum\tk\n" + - "\t19.202208853548\t1970-01-03T00:00:00.000000Z\n" + - "CPS\t80.432240999684\t1970-01-03T00:00:00.000000Z\n" + - "XPE\t20.447441837878\t1970-01-03T00:00:00.000000Z\n" + - "DEY\t66.938371476317\t1970-01-03T03:00:00.000000Z\n" + - "PGW\t55.991618048008\t1970-01-03T03:00:00.000000Z\n" + - "UXI\t34.910703637305\t1970-01-03T03:00:00.000000Z\n" + - "BHF\t87.996347253916\t1970-01-03T06:00:00.000000Z\n" + - "DXY\t2.165181900725\t1970-01-03T06:00:00.000000Z\n" + - "UOJ\t63.816075311785\t1970-01-03T06:00:00.000000Z\n" + - "EDR\t96.874232769402\t1970-01-03T09:00:00.000000Z\n" + - "OFJ\t34.356853329430\t1970-01-03T09:00:00.000000Z\n" + - "RSZ\t41.381647482277\t1970-01-03T09:00:00.000000Z\n" + - "FBV\t77.639046748187\t1970-01-03T12:00:00.000000Z\n" + - "JMY\t38.642336707856\t1970-01-03T12:00:00.000000Z\n" + - "OOZ\t49.005104498852\t1970-01-03T12:00:00.000000Z\n" + - "DOT\t45.659895188240\t1970-01-03T15:00:00.000000Z\n" + - "KGH\t56.594291398612\t1970-01-03T15:00:00.000000Z\n" + - "ZOU\t65.903416076922\t1970-01-03T15:00:00.000000Z\n" + - "\t32.540322001542\t1970-01-03T18:00:00.000000Z\n" + - "YCT\t57.789479151824\t1970-01-03T18:00:00.000000Z\n" + - "\t3.831785863681\t1970-01-04T03:00:00.000000Z\n" + - "\t71.339102715558\t1970-01-04T06:00:00.000000Z\n" + - "NVT\t95.400690890497\t1970-01-04T06:00:00.000000Z\n" + - "WUG\t58.912164838798\t1970-01-04T06:00:00.000000Z\n" + - "XIO\t14.830552335849\t1970-01-04T09:00:00.000000Z\n", - true); - } - - @Test - public void testOrderByFullSymbol() throws Exception { - assertQuery("b\tsum\tk\n" + - "\t144.984487170905\t1970-01-03T00:00:00.000000Z\n" + - "\t87.996347253916\t1970-01-03T03:00:00.000000Z\n" + - "\t146.379436136862\t1970-01-03T06:00:00.000000Z\n" + - "\t52.984059417621\t1970-01-03T12:00:00.000000Z\n" + - "\t177.513199934642\t1970-01-03T15:00:00.000000Z\n" + - "CPSW\t78.830658300550\t1970-01-03T12:00:00.000000Z\n" + - "HYRX\t186.000108135441\t1970-01-03T09:00:00.000000Z\n" + - "HYRX\t84.452581772111\t1970-01-03T12:00:00.000000Z\n" + - "HYRX\t157.953455546780\t1970-01-03T18:00:00.000000Z\n" + - "PEHN\t11.427984775756\t1970-01-03T00:00:00.000000Z\n" + - "PEHN\t94.848894980177\t1970-01-03T03:00:00.000000Z\n" + - "PEHN\t49.005104498852\t1970-01-03T15:00:00.000000Z\n" + - "VTJW\t40.228106267796\t1970-01-03T09:00:00.000000Z\n", - // we have 'sample by fill(none)' because it doesn't support - // random record access, which is what we intend on testing - "select b, sum(a), k from x sample by 3h fill(none) order by b", - "create table x as " + - "(" + - "select" + - " rnd_double(0)*100 a," + - " rnd_symbol(4,4,4,2) b," + - " timestamp_sequence(to_timestamp(172800000000), 3600000000) k" + - " from" + - " long_sequence(20)" + - ") timestamp(k) partition by NONE", - null, - "insert into x select * from (" + - "select" + - " rnd_double(0)*100 a," + - " rnd_symbol(4,4,4,2) b," + - " timestamp_sequence(to_timestamp(277200000000), 3600000000) k" + - " from" + - " long_sequence(5)" + - ") timestamp(k)", - "b\tsum\tk\n" + - "\t144.984487170905\t1970-01-03T00:00:00.000000Z\n" + - "\t87.996347253916\t1970-01-03T03:00:00.000000Z\n" + - "\t146.379436136862\t1970-01-03T06:00:00.000000Z\n" + - "\t52.984059417621\t1970-01-03T12:00:00.000000Z\n" + - "\t177.513199934642\t1970-01-03T15:00:00.000000Z\n" + - "\t57.789479151824\t1970-01-04T03:00:00.000000Z\n" + - "\t49.428905119585\t1970-01-04T06:00:00.000000Z\n" + - "CPSW\t78.830658300550\t1970-01-03T12:00:00.000000Z\n" + - "HYRX\t186.000108135441\t1970-01-03T09:00:00.000000Z\n" + - "HYRX\t84.452581772111\t1970-01-03T12:00:00.000000Z\n" + - "HYRX\t157.953455546780\t1970-01-03T18:00:00.000000Z\n" + - "OUIC\t86.851543054196\t1970-01-04T06:00:00.000000Z\n" + - "PEHN\t11.427984775756\t1970-01-03T00:00:00.000000Z\n" + - "PEHN\t94.848894980177\t1970-01-03T03:00:00.000000Z\n" + - "PEHN\t49.005104498852\t1970-01-03T15:00:00.000000Z\n" + - "SDOT\t12.024160875735\t1970-01-04T06:00:00.000000Z\n" + - "SDOT\t65.513358397963\t1970-01-04T09:00:00.000000Z\n" + - "VTJW\t40.228106267796\t1970-01-03T09:00:00.000000Z\n", - true); - } - @Test public void testSelectColumns() throws Exception { assertQuery("a\ta1\tb\tc\td\te\tf1\tf\tg\th\ti\tj\tj1\tk\tl\tm\n" + diff --git a/core/src/test/java/com/questdb/griffin/SqlParserTest.java b/core/src/test/java/com/questdb/griffin/SqlParserTest.java index f5afbcea696159432cdc9a124692bfba1b1ab8f8..6b3aaf73fe58d07946574c4fb7903ce4fb4f0ab4 100644 --- a/core/src/test/java/com/questdb/griffin/SqlParserTest.java +++ b/core/src/test/java/com/questdb/griffin/SqlParserTest.java @@ -647,7 +647,7 @@ public class SqlParserTest extends AbstractGriffinTest { } @Test - public void testCreateTableCastRoundedCapacityDef() throws SqlException { + public void testCreateTableCastRoundedSymbolCapacityDef() throws SqlException { // 20 is rounded to next power of 2, which is 32 assertCreateTable( "create table x as (select-choose a, b, c from (tab)), cast(a as DOUBLE:35), cast(c as SYMBOL:54 capacity 32)", @@ -1084,7 +1084,7 @@ public class SqlParserTest extends AbstractGriffinTest { } @Test - public void testCreateTableSymbolCapacityRounding() throws SqlException { + public void testCreateTableRoundedSymbolCapacity() throws SqlException { assertCreateTable( "create table x (" + "a INT," +