From 6f7e31129cc39309bb59fac0d2ae1fbccecb15fd Mon Sep 17 00:00:00 2001 From: Vlad Ilyushchenko Date: Fri, 12 Jul 2019 01:01:27 +0100 Subject: [PATCH] RELEASE 3.2.0 Removed tests for legacy code (it will be deleted soon too, after all parts have been migrated) --- benchmarks/pom.xml | 2 +- core/pom.xml | 29 +- .../com/questdb/FactoryEventLoggerTest.java | 91 - .../questdb/net/ha/AbstractJournalTest.java | 96 - .../com/questdb/net/ha/AuthorizationTest.java | 271 - .../questdb/net/ha/ClientRecoveryTest.java | 59 - .../questdb/net/ha/ClusterControllerTest.java | 548 -- .../java/com/questdb/net/ha/DataLossTest.java | 125 - .../com/questdb/net/ha/FixedColumnTest.java | 247 - .../java/com/questdb/net/ha/GenericTest.java | 378 -- .../test/java/com/questdb/net/ha/IntTest.java | 48 - .../com/questdb/net/ha/IntegrationTest.java | 1046 ---- .../net/ha/JournalEventBridgeTest.java | 146 - .../com/questdb/net/ha/JournalLagTest.java | 71 - .../net/ha/JournalServerAgentTest.java | 213 - .../net/ha/JournalSymbolTableTest.java | 130 - .../java/com/questdb/net/ha/JournalTest.java | 150 - .../net/ha/LinkedJournalSymbolTableTest.java | 103 - .../net/ha/MetadataReplicationTest.java | 63 - .../com/questdb/net/ha/MockByteChannel.java | 93 - .../com/questdb/net/ha/MulticastTest.java | 141 - .../com/questdb/net/ha/PartitionTest.java | 183 - .../com/questdb/net/ha/ReconnectTest.java | 133 - .../test/java/com/questdb/net/ha/SSLTest.java | 357 -- .../java/com/questdb/net/ha/ScenarioTest.java | 210 - .../com/questdb/net/ha/ServerNodeTest.java | 70 - .../java/com/questdb/net/ha/SetKeyTest.java | 68 - .../questdb/net/ha/VariableColumnTest.java | 254 - .../com/questdb/net/http/HttpServerTest.java | 1157 ----- .../handlers/QueryHandlerConsistencyTest.java | 215 - .../handlers/QueryHandlerSmallBufferTest.java | 108 - .../net/http/handlers/QueryHandlerTest.java | 371 -- .../parser/sql/AbstractOptimiserTest.java | 237 - .../questdb/parser/sql/AggregationTest.java | 503 -- .../questdb/parser/sql/DateFunctionTest.java | 77 - .../questdb/parser/sql/ExprParserTest.java | 168 - .../parser/sql/IntervalCompilerTest.java | 324 -- .../sql/InvertedBooleanOptimisationTest.java | 136 - .../com/questdb/parser/sql/JoinQueryTest.java | 1920 ------- .../com/questdb/parser/sql/LocalesTest.java | 194 - .../parser/sql/NullAggregationTest.java | 116 - .../questdb/parser/sql/NullCountingTest.java | 161 - .../com/questdb/parser/sql/QueryDateTest.java | 79 - .../parser/sql/QueryFilterAnalyserTest.java | 883 ---- .../questdb/parser/sql/QueryParserTest.java | 738 --- .../questdb/parser/sql/ResamplingTest.java | 323 -- .../com/questdb/parser/sql/RpnBuilder.java | 44 - .../com/questdb/parser/sql/SignatureTest.java | 61 - .../parser/sql/SingleJournalQueryTest.java | 4441 ----------------- .../com/questdb/ql/AbstractAllTypeTest.java | 99 - .../AsOfPartitionedJoinRecordSourceTest.java | 529 -- .../test/java/com/questdb/ql/DDLTests.java | 1253 ----- .../questdb/ql/HashJoinRecordSourceTest.java | 209 - .../questdb/ql/JoinStringToSymbolTest.java | 113 - .../questdb/ql/JournalRecordSourceTest.java | 195 - .../com/questdb/ql/MergingRowSourceTest.java | 92 - .../ql/MultiIntervalPartitionSourceTest.java | 85 - .../java/com/questdb/ql/OperatorTest.java | 669 --- .../com/questdb/ql/OrderByOptimiserTest.java | 102 - .../java/com/questdb/ql/ParameterTest.java | 104 - .../java/com/questdb/ql/RecordListTest.java | 306 -- .../com/questdb/ql/RenameJournalTest.java | 169 - .../com/questdb/ql/RoundFunctionsTest.java | 178 - .../com/questdb/ql/SubqueryOptimiserTest.java | 152 - .../com/questdb/ql/SymbolNullQueryTest.java | 610 --- .../com/questdb/ql/TopRecordSourceTest.java | 103 - .../com/questdb/ql/VirtualColumnTest.java | 334 -- .../questdb/ql/aggregation/SamplerTest.java | 110 - .../DenseRankAnalyticFunctionTest.java | 126 - .../ql/analytic/MiscAnalyticFunctionTest.java | 38 - .../ql/analytic/NextAnalyticFunctionTest.java | 741 --- .../ql/analytic/PrevAnalyticFunctionTest.java | 1512 ------ .../questdb/ql/collections/FreeListTest.java | 82 - .../questdb/ql/join/JoinComplianceTest.java | 447 -- .../questdb/ql/join/MultiColumnJoinTest.java | 95 - .../com/questdb/ql/map/DirectMapTest.java | 310 -- .../ql/map/RecordKeyCopierCompilerTest.java | 110 - .../com/questdb/ql/map/RedBlackTreeTest.java | 103 - .../com/questdb/ql/ops/regex/BMPTestCases.txt | 951 ---- .../com/questdb/ql/ops/regex/POSIX_ASCII.java | 248 - .../questdb/ql/ops/regex/POSIX_Unicode.java | 145 - .../com/questdb/ql/ops/regex/RegExTest.java | 3933 --------------- .../ql/ops/regex/SupplementaryTestCases.txt | 1434 ------ .../com/questdb/ql/ops/regex/TestCases.txt | 1092 ---- .../ql/sort/ComparatorCompilerTest.java | 216 - .../ql/sort/RBTreeSortedRecordSourceTest.java | 556 --- .../questdb/ql/sys/$ColsRecordSourceTest.java | 48 - .../questdb/ql/sys/$TabsRecordSourceTest.java | 66 - .../java/com/questdb/store/IteratorTest.java | 376 -- .../com/questdb/test/tools/HttpTestUtils.java | 135 - 90 files changed, 5 insertions(+), 35752 deletions(-) delete mode 100644 core/src/test/java/com/questdb/FactoryEventLoggerTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/AbstractJournalTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/AuthorizationTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/ClientRecoveryTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/ClusterControllerTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/DataLossTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/FixedColumnTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/GenericTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/IntTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/IntegrationTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/JournalEventBridgeTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/JournalLagTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/JournalServerAgentTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/JournalSymbolTableTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/JournalTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/LinkedJournalSymbolTableTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/MetadataReplicationTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/MockByteChannel.java delete mode 100644 core/src/test/java/com/questdb/net/ha/MulticastTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/PartitionTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/ReconnectTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/SSLTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/ScenarioTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/ServerNodeTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/SetKeyTest.java delete mode 100644 core/src/test/java/com/questdb/net/ha/VariableColumnTest.java delete mode 100644 core/src/test/java/com/questdb/net/http/HttpServerTest.java delete mode 100644 core/src/test/java/com/questdb/net/http/handlers/QueryHandlerConsistencyTest.java delete mode 100644 core/src/test/java/com/questdb/net/http/handlers/QueryHandlerSmallBufferTest.java delete mode 100644 core/src/test/java/com/questdb/net/http/handlers/QueryHandlerTest.java delete mode 100644 core/src/test/java/com/questdb/parser/sql/AbstractOptimiserTest.java delete mode 100644 core/src/test/java/com/questdb/parser/sql/AggregationTest.java delete mode 100644 core/src/test/java/com/questdb/parser/sql/DateFunctionTest.java delete mode 100644 core/src/test/java/com/questdb/parser/sql/ExprParserTest.java delete mode 100644 core/src/test/java/com/questdb/parser/sql/IntervalCompilerTest.java delete mode 100644 core/src/test/java/com/questdb/parser/sql/InvertedBooleanOptimisationTest.java delete mode 100644 core/src/test/java/com/questdb/parser/sql/JoinQueryTest.java delete mode 100644 core/src/test/java/com/questdb/parser/sql/LocalesTest.java delete mode 100644 core/src/test/java/com/questdb/parser/sql/NullAggregationTest.java delete mode 100644 core/src/test/java/com/questdb/parser/sql/NullCountingTest.java delete mode 100644 core/src/test/java/com/questdb/parser/sql/QueryDateTest.java delete mode 100644 core/src/test/java/com/questdb/parser/sql/QueryFilterAnalyserTest.java delete mode 100644 core/src/test/java/com/questdb/parser/sql/QueryParserTest.java delete mode 100644 core/src/test/java/com/questdb/parser/sql/ResamplingTest.java delete mode 100644 core/src/test/java/com/questdb/parser/sql/RpnBuilder.java delete mode 100644 core/src/test/java/com/questdb/parser/sql/SignatureTest.java delete mode 100644 core/src/test/java/com/questdb/parser/sql/SingleJournalQueryTest.java delete mode 100644 core/src/test/java/com/questdb/ql/AbstractAllTypeTest.java delete mode 100644 core/src/test/java/com/questdb/ql/AsOfPartitionedJoinRecordSourceTest.java delete mode 100644 core/src/test/java/com/questdb/ql/DDLTests.java delete mode 100644 core/src/test/java/com/questdb/ql/HashJoinRecordSourceTest.java delete mode 100644 core/src/test/java/com/questdb/ql/JoinStringToSymbolTest.java delete mode 100644 core/src/test/java/com/questdb/ql/JournalRecordSourceTest.java delete mode 100644 core/src/test/java/com/questdb/ql/MergingRowSourceTest.java delete mode 100644 core/src/test/java/com/questdb/ql/MultiIntervalPartitionSourceTest.java delete mode 100644 core/src/test/java/com/questdb/ql/OperatorTest.java delete mode 100644 core/src/test/java/com/questdb/ql/OrderByOptimiserTest.java delete mode 100644 core/src/test/java/com/questdb/ql/ParameterTest.java delete mode 100644 core/src/test/java/com/questdb/ql/RecordListTest.java delete mode 100644 core/src/test/java/com/questdb/ql/RenameJournalTest.java delete mode 100644 core/src/test/java/com/questdb/ql/RoundFunctionsTest.java delete mode 100644 core/src/test/java/com/questdb/ql/SubqueryOptimiserTest.java delete mode 100644 core/src/test/java/com/questdb/ql/SymbolNullQueryTest.java delete mode 100644 core/src/test/java/com/questdb/ql/TopRecordSourceTest.java delete mode 100644 core/src/test/java/com/questdb/ql/VirtualColumnTest.java delete mode 100644 core/src/test/java/com/questdb/ql/aggregation/SamplerTest.java delete mode 100644 core/src/test/java/com/questdb/ql/analytic/DenseRankAnalyticFunctionTest.java delete mode 100644 core/src/test/java/com/questdb/ql/analytic/MiscAnalyticFunctionTest.java delete mode 100644 core/src/test/java/com/questdb/ql/analytic/NextAnalyticFunctionTest.java delete mode 100644 core/src/test/java/com/questdb/ql/analytic/PrevAnalyticFunctionTest.java delete mode 100644 core/src/test/java/com/questdb/ql/collections/FreeListTest.java delete mode 100644 core/src/test/java/com/questdb/ql/join/JoinComplianceTest.java delete mode 100644 core/src/test/java/com/questdb/ql/join/MultiColumnJoinTest.java delete mode 100644 core/src/test/java/com/questdb/ql/map/DirectMapTest.java delete mode 100644 core/src/test/java/com/questdb/ql/map/RecordKeyCopierCompilerTest.java delete mode 100644 core/src/test/java/com/questdb/ql/map/RedBlackTreeTest.java delete mode 100644 core/src/test/java/com/questdb/ql/ops/regex/BMPTestCases.txt delete mode 100644 core/src/test/java/com/questdb/ql/ops/regex/POSIX_ASCII.java delete mode 100644 core/src/test/java/com/questdb/ql/ops/regex/POSIX_Unicode.java delete mode 100644 core/src/test/java/com/questdb/ql/ops/regex/RegExTest.java delete mode 100644 core/src/test/java/com/questdb/ql/ops/regex/SupplementaryTestCases.txt delete mode 100644 core/src/test/java/com/questdb/ql/ops/regex/TestCases.txt delete mode 100644 core/src/test/java/com/questdb/ql/sort/ComparatorCompilerTest.java delete mode 100644 core/src/test/java/com/questdb/ql/sort/RBTreeSortedRecordSourceTest.java delete mode 100644 core/src/test/java/com/questdb/ql/sys/$ColsRecordSourceTest.java delete mode 100644 core/src/test/java/com/questdb/ql/sys/$TabsRecordSourceTest.java delete mode 100644 core/src/test/java/com/questdb/store/IteratorTest.java delete mode 100644 core/src/test/java/com/questdb/test/tools/HttpTestUtils.java diff --git a/benchmarks/pom.xml b/benchmarks/pom.xml index 6a6d70e4f..85a34f570 100644 --- a/benchmarks/pom.xml +++ b/benchmarks/pom.xml @@ -52,7 +52,7 @@ org.questdb questdb-core - 3.1.4-SNAPSHOT + 3.2.0 org.apache.logging.log4j diff --git a/core/pom.xml b/core/pom.xml index b7d8ed416..76a23c8c6 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -31,7 +31,7 @@ UTF-8 - 3.1.4-SNAPSHOT + 3.2.0 org.questdb questdb-core jar @@ -196,7 +196,7 @@ - gpg2 + gpg @@ -226,33 +226,12 @@ - com.intellij + org.jetbrains annotations - 12.0 + 17.0.0 provided - - org.apache.httpcomponents - httpclient - 4.5.3 - test - - - - org.apache.httpcomponents - httpmime - 4.5.3 - test - - - - com.google.code.gson - gson - 2.8.1 - test - - org.postgresql postgresql diff --git a/core/src/test/java/com/questdb/FactoryEventLoggerTest.java b/core/src/test/java/com/questdb/FactoryEventLoggerTest.java deleted file mode 100644 index b1f465921..000000000 --- a/core/src/test/java/com/questdb/FactoryEventLoggerTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb; - -import com.questdb.std.microtime.MicrosecondClockImpl; -import com.questdb.store.Journal; -import com.questdb.store.factory.FactoryEventListener; -import com.questdb.test.tools.AbstractTest; -import org.junit.Ignore; -import org.junit.Test; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.CyclicBarrier; -import java.util.concurrent.locks.LockSupport; - -public class FactoryEventLoggerTest extends AbstractTest { - - @Test - @Ignore - public void testThroughput() throws Exception { - final FactoryEventLogger logger = new FactoryEventLogger(getFactory(), 1000, 1000, MicrosecondClockImpl.INSTANCE); - - final int count = 1000; - final CountDownLatch done = new CountDownLatch(1); - final CyclicBarrier barrier = new CyclicBarrier(2); - final FactoryEventListener listener = getFactory().getEventListener(); - - new Thread(() -> { - try (Journal r = getFactory().reader("$mon_factory")) { - barrier.await(); - int i = 0; - while (i < count) { - if (logger.run()) { - i++; - } else { - r.refresh(); - if (r.size() == count) { - break; - } - } - } - } catch (Exception e) { - e.printStackTrace(); - } finally { - done.countDown(); - } - }).start(); - - barrier.await(); - - - int i = 0; - while (i < count) { - if (listener.onEvent((byte) 1, 1, "test", (short) 1, (short) 0, (short) 5)) { - i++; - } else { - LockSupport.parkNanos(1); - } - } - - done.await(); - - logger.close(); - - try (Journal r = getFactory().reader("$mon_factory")) { - System.out.println(r.size()); - } - - } -} \ No newline at end of file diff --git a/core/src/test/java/com/questdb/net/ha/AbstractJournalTest.java b/core/src/test/java/com/questdb/net/ha/AbstractJournalTest.java deleted file mode 100644 index e5e0fc768..000000000 --- a/core/src/test/java/com/questdb/net/ha/AbstractJournalTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.model.Quote; -import com.questdb.net.ha.comsumer.JournalClientStateConsumer; -import com.questdb.net.ha.comsumer.JournalDeltaConsumer; -import com.questdb.net.ha.model.IndexedJournal; -import com.questdb.net.ha.producer.JournalClientStateProducer; -import com.questdb.net.ha.producer.JournalDeltaProducer; -import com.questdb.std.ex.JournalException; -import com.questdb.std.ex.JournalNetworkException; -import com.questdb.store.Journal; -import com.questdb.store.JournalWriter; -import com.questdb.test.tools.AbstractTest; -import com.questdb.test.tools.TestUtils; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; - -public abstract class AbstractJournalTest extends AbstractTest { - - JournalWriter origin; - JournalWriter master; - JournalWriter slave; - - private MockByteChannel channel; - - private JournalDeltaProducer journalDeltaProducer; - private JournalDeltaConsumer journalDeltaConsumer; - private JournalClientStateProducer journalClientStateProducer; - private JournalClientStateConsumer journalClientStateConsumer; - private Journal masterReader; - - @Before - public void setUp() throws Exception { - origin = getFactory().writer(Quote.class, "origin"); - slave = getFactory().writer(Quote.class, "slave"); - master = getFactory().writer(Quote.class, "master"); - - journalClientStateProducer = new JournalClientStateProducer(); - journalClientStateConsumer = new JournalClientStateConsumer(); - - this.masterReader = getFactory().reader(Quote.class, "master"); - journalDeltaProducer = new JournalDeltaProducer(masterReader); - journalDeltaConsumer = new JournalDeltaConsumer(slave); - channel = new MockByteChannel(); - } - - @After - public void tearDown() throws Exception { - origin.close(); - slave.close(); - master.close(); - masterReader.close(); - journalDeltaProducer.free(); - journalDeltaConsumer.free(); - super.tearDown(); - - } - - void executeSequence(boolean expectContent) throws JournalNetworkException, JournalException { - slave.refresh(); - journalClientStateProducer.write(channel, new IndexedJournal(0, slave)); - journalClientStateConsumer.read(channel); - - journalDeltaProducer.configure(journalClientStateConsumer.getValue().getTxn(), journalClientStateConsumer.getValue().getTxPin()); - Assert.assertEquals(expectContent, journalDeltaProducer.hasContent()); - if (expectContent) { - journalDeltaProducer.write(channel); - journalDeltaConsumer.read(channel); - TestUtils.assertEquals(master, slave); - } - } -} diff --git a/core/src/test/java/com/questdb/net/ha/AuthorizationTest.java b/core/src/test/java/com/questdb/net/ha/AuthorizationTest.java deleted file mode 100644 index 0ac7af8dc..000000000 --- a/core/src/test/java/com/questdb/net/ha/AuthorizationTest.java +++ /dev/null @@ -1,271 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.model.Quote; -import com.questdb.net.ha.config.ClientConfig; -import com.questdb.net.ha.config.ServerConfig; -import com.questdb.net.ha.config.ServerNode; -import com.questdb.net.ha.krb.SSOCredentialProvider; -import com.questdb.std.NumericException; -import com.questdb.std.ex.FatalError; -import com.questdb.std.ex.JournalException; -import com.questdb.std.ex.JournalNetworkException; -import com.questdb.store.Journal; -import com.questdb.store.JournalListener; -import com.questdb.store.JournalWriter; -import com.questdb.test.tools.AbstractTest; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Test; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -public class AuthorizationTest extends AbstractTest { - - private final ClientConfig local = new ClientConfig("localhost") {{ - addNode(new ServerNode(1, "xyz")); - addNode(new ServerNode(2, "localhost")); - }}; - - @Test - public void testClientAndServerSuccessfulAuth() throws Exception { - - JournalServer server = new JournalServer( - new ServerConfig() {{ - setHeartbeatFrequency(TimeUnit.MILLISECONDS.toMillis(100)); - setEnableMultiCast(false); - }} - , getFactory() - , - (token, requestedKeys) -> "SECRET".equals(new String(token))); - - - JournalClient client = new JournalClient(local, getFactory(), "SECRET"::getBytes); - beginSync(server, client); - } - - @Test - public void testClientWithoutAuthProvider() throws Exception { - JournalServer server = new JournalServer( - new ServerConfig() {{ - setHeartbeatFrequency(TimeUnit.MILLISECONDS.toMillis(500)); - setEnableMultiCast(false); - }} - , getFactory() - , - (token, requestedKeys) -> "SECRET".equals(new String(token))); - - server.start(); - try { - - final AtomicInteger authErrors = new AtomicInteger(); - final CountDownLatch error = new CountDownLatch(1); - JournalClient client = new JournalClient(local, getFactory(), null, evt -> { - switch (evt) { - case JournalClientEvents.EVT_AUTH_CONFIG_ERROR: - authErrors.incrementAndGet(); - break; - case JournalClientEvents.EVT_TERMINATED: - error.countDown(); - break; - default: - break; - } - }); - - client.start(); - Assert.assertTrue(error.await(5, TimeUnit.SECONDS)); - Assert.assertFalse(client.isRunning()); - } finally { - server.halt(); - } - } - - @Test - public void testClientWrongAuth() throws Exception { - JournalServer server = new JournalServer( - new ServerConfig() {{ - setHeartbeatFrequency(TimeUnit.MILLISECONDS.toMillis(500)); - setEnableMultiCast(false); - }} - , getFactory() - , - (token, requestedKeys) -> "SECRET".equals(new String(token))); - - - final AtomicInteger authErrorCount = new AtomicInteger(); - final CountDownLatch serverError = new CountDownLatch(1); - - JournalClient client = new JournalClient( - local, - getFactory(), - "NON_SECRET"::getBytes, - evt -> { - switch (evt) { - case JournalClientEvents.EVT_AUTH_ERROR: - authErrorCount.incrementAndGet(); - break; - case JournalClientEvents.EVT_TERMINATED: - serverError.countDown(); - break; - default: - break; - } - }); - - server.start(); - try { - client.start(); - Assert.assertTrue(serverError.await(5, TimeUnit.SECONDS)); - Assert.assertFalse(client.isRunning()); - Assert.assertEquals(1, authErrorCount.get()); - } finally { - server.halt(); - } - - } - - @Test - public void testExceptionInCredentialProvider() throws Exception { - JournalServer server = new JournalServer( - new ServerConfig() {{ - setHeartbeatFrequency(TimeUnit.MILLISECONDS.toMillis(500)); - setEnableMultiCast(false); - }} - , getFactory() - , - (token, requestedKeys) -> "SECRET".equals(new String(token))); - - - final AtomicInteger authErrorCount = new AtomicInteger(); - final CountDownLatch terminated = new CountDownLatch(1); - JournalClient client = new JournalClient(local, getFactory(), new SSOCredentialProvider("HOST/test"), - evt -> { - switch (evt) { - case JournalClientEvents.EVT_AUTH_CONFIG_ERROR: - authErrorCount.incrementAndGet(); - break; - case JournalClientEvents.EVT_TERMINATED: - terminated.countDown(); - break; - default: - break; - } - }); - - server.start(); - try { - client.start(); - Assert.assertTrue(terminated.await(5, TimeUnit.SECONDS)); - Assert.assertEquals(1, authErrorCount.get()); - Assert.assertFalse(client.isRunning()); - } finally { - server.halt(); - } - } - - @Test - public void testServerAuthException() throws Exception { - JournalServer server = new JournalServer( - new ServerConfig() {{ - setHeartbeatFrequency(TimeUnit.MILLISECONDS.toMillis(500)); - setEnableMultiCast(false); - }} - , getFactory() - , - (token, requestedKeys) -> { - throw new FatalError("BANG!"); - }); - - final AtomicInteger authErrorCount = new AtomicInteger(); - final CountDownLatch serverError = new CountDownLatch(1); - - JournalClient client = new JournalClient(local, getFactory(), "SECRET"::getBytes, evt -> { - switch (evt) { - case JournalClientEvents.EVT_AUTH_ERROR: - authErrorCount.incrementAndGet(); - break; - case JournalClientEvents.EVT_TERMINATED: - serverError.countDown(); - break; - default: - break; - } - - }); - - - server.start(); - try { - client.start(); - Assert.assertTrue(serverError.await(5, TimeUnit.SECONDS)); - Assert.assertFalse(client.isRunning()); - Assert.assertEquals(1, authErrorCount.get()); - } finally { - server.halt(); - } - } - - private void beginSync(JournalServer server, JournalClient client) throws JournalException, JournalNetworkException, InterruptedException, NumericException { - int size = 100000; - try (JournalWriter remote = getFactory().writer(Quote.class, "remote", 2 * size)) { - server.publish(remote); - server.start(); - try { - final CountDownLatch latch = new CountDownLatch(1); - client.subscribe(Quote.class, "remote", "local", 2 * size, new JournalListener() { - @Override - public void onCommit() { - latch.countDown(); - } - - @Override - public void onEvent(int event) { - - } - }); - - client.start(); - - try { - TestUtils.generateQuoteData(remote, size); - - latch.await(); - - try (Journal local = getFactory().reader(Quote.class, "local")) { - TestUtils.assertDataEquals(remote, local); - } - - } finally { - client.halt(); - } - } finally { - server.halt(0, TimeUnit.SECONDS); - } - } - } -} diff --git a/core/src/test/java/com/questdb/net/ha/ClientRecoveryTest.java b/core/src/test/java/com/questdb/net/ha/ClientRecoveryTest.java deleted file mode 100644 index 6511c638c..000000000 --- a/core/src/test/java/com/questdb/net/ha/ClientRecoveryTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2019 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.model.Quote; -import com.questdb.net.ha.config.ClientConfig; -import com.questdb.store.JournalWriter; -import com.questdb.test.tools.AbstractTest; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -@Ignore -public class ClientRecoveryTest extends AbstractTest { - @Test - public void testClientWriterRelease() throws Exception { - final CountDownLatch serverError = new CountDownLatch(1); - JournalClient client = new JournalClient(new ClientConfig("localhost"), getFactory(), null, evt -> { - if (evt == JournalClientEvents.EVT_TERMINATED) { - serverError.countDown(); - } - }); - - client.subscribe(Quote.class); - client.start(); - - Assert.assertTrue(serverError.await(5, TimeUnit.SECONDS)); - Assert.assertFalse(client.isRunning()); - - // should be able to get writer after client failure. - try (JournalWriter w = getFactory().writer(Quote.class)) { - Assert.assertNotNull(w); - } - } -} diff --git a/core/src/test/java/com/questdb/net/ha/ClusterControllerTest.java b/core/src/test/java/com/questdb/net/ha/ClusterControllerTest.java deleted file mode 100644 index badc33370..000000000 --- a/core/src/test/java/com/questdb/net/ha/ClusterControllerTest.java +++ /dev/null @@ -1,548 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.log.Log; -import com.questdb.log.LogFactory; -import com.questdb.model.Quote; -import com.questdb.model.configuration.ModelConfiguration; -import com.questdb.net.ha.config.ClientConfig; -import com.questdb.net.ha.config.ServerConfig; -import com.questdb.net.ha.config.ServerNode; -import com.questdb.std.NumericException; -import com.questdb.std.ex.JournalException; -import com.questdb.store.JournalWriter; -import com.questdb.store.factory.Factory; -import com.questdb.test.tools.AbstractTest; -import com.questdb.test.tools.FactoryContainer; -import com.questdb.test.tools.TestUtils; -import org.junit.*; - -import java.util.ArrayList; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; - -@Ignore -public class ClusterControllerTest extends AbstractTest { - - private final static Log LOG = LogFactory.getLog(ClusterController.class); - @Rule - public final FactoryContainer tf = new FactoryContainer(ModelConfiguration.MAIN); - - @Rule - public final FactoryContainer tf1 = new FactoryContainer(ModelConfiguration.MAIN); - - @Rule - public final FactoryContainer tf2 = new FactoryContainer(ModelConfiguration.MAIN); - - @Rule - public final FactoryContainer tf3 = new FactoryContainer(ModelConfiguration.MAIN); - - @Rule - public final FactoryContainer tf4 = new FactoryContainer(ModelConfiguration.MAIN); - - @Rule - public final FactoryContainer tf5 = new FactoryContainer(ModelConfiguration.MAIN); - - @After - public void tearDown() { - Assert.assertEquals(0, tf.getFactory().getBusyWriterCount()); - Assert.assertEquals(0, tf1.getFactory().getBusyWriterCount()); - Assert.assertEquals(0, tf2.getFactory().getBusyWriterCount()); - Assert.assertEquals(0, tf3.getFactory().getBusyWriterCount()); - Assert.assertEquals(0, tf4.getFactory().getBusyWriterCount()); - Assert.assertEquals(0, tf5.getFactory().getBusyWriterCount()); - - Assert.assertEquals(0, tf.getFactory().getBusyReaderCount()); - Assert.assertEquals(0, tf1.getFactory().getBusyReaderCount()); - Assert.assertEquals(0, tf2.getFactory().getBusyReaderCount()); - Assert.assertEquals(0, tf3.getFactory().getBusyReaderCount()); - Assert.assertEquals(0, tf4.getFactory().getBusyReaderCount()); - Assert.assertEquals(0, tf5.getFactory().getBusyReaderCount()); - } - - @Test - @Ignore - public void testBusyFailOver() throws Exception { - - try (JournalWriter writer1 = getFactory().writer(Quote.class)) { - try (final JournalWriter writer2 = tf.getFactory().writer(Quote.class)) { - - final CountDownLatch active1 = new CountDownLatch(1); - final CountDownLatch active2 = new CountDownLatch(1); - final CountDownLatch standby2 = new CountDownLatch(1); - - final AtomicLong expected = new AtomicLong(); - final AtomicLong actual = new AtomicLong(); - - - ClusterController controller1 = new ClusterController( - new ServerConfig() {{ - addNode(new ServerNode(0, "localhost:7080")); - addNode(new ServerNode(1, "localhost:7090")); - setEnableMultiCast(false); - setHeartbeatFrequency(50); - }}, - new ClientConfig() {{ - setEnableMultiCast(false); - }}, - getFactory(), - 0, - new ArrayList() {{ - add(writer1); - }}, - new ClusterStatusListener() { - @Override - public void goActive() { - try { - TestUtils.generateQuoteData(writer1, 100000); - TestUtils.generateQuoteData(writer1, 100000, writer1.getMaxTimestamp()); - writer1.commit(); - TestUtils.generateQuoteData(writer1, 100000, writer1.getMaxTimestamp()); - writer1.commit(); - TestUtils.generateQuoteData(writer1, 100000, writer1.getMaxTimestamp()); - writer1.commit(); - TestUtils.generateQuoteData(writer1, 100000, writer1.getMaxTimestamp()); - writer1.commit(); - expected.set(writer1.size()); - active1.countDown(); - } catch (JournalException | NumericException e) { - e.printStackTrace(); - } - } - - @Override - public void goPassive(ServerNode activeNode) { - } - - @Override - public void onShutdown() { - } - } - ); - - ClusterController controller2 = new ClusterController( - new ServerConfig() {{ - addNode(new ServerNode(0, "localhost:7080")); - addNode(new ServerNode(1, "localhost:7090")); - setEnableMultiCast(false); - setHeartbeatFrequency(50); - }}, - new ClientConfig() {{ - setEnableMultiCast(false); - }}, - tf.getFactory(), - 1, - new ArrayList() {{ - add(writer2); - }}, - new ClusterStatusListener() { - @Override - public void goActive() { - try { - actual.set(writer2.size()); - active2.countDown(); - } catch (JournalException e) { - e.printStackTrace(); - } - } - - @Override - public void goPassive(ServerNode activeNode) { - standby2.countDown(); - } - - @Override - public void onShutdown() { - } - } - ); - - controller1.start(); - Assert.assertTrue(active1.await(30, TimeUnit.SECONDS)); - Assert.assertEquals(0, active1.getCount()); - - controller2.start(); - standby2.await(60, TimeUnit.SECONDS); - Assert.assertEquals(0, standby2.getCount()); - - controller1.halt(); - - active2.await(10, TimeUnit.SECONDS); - Assert.assertEquals(0, active2.getCount()); - - controller2.halt(); - Assert.assertTrue(expected.get() > 0); - Assert.assertEquals(expected.get(), actual.get()); - } - } - } - - @Test - public void testFiveNodesVoting() throws Exception { - - AtomicInteger active = new AtomicInteger(); - AtomicInteger standby = new AtomicInteger(); - AtomicInteger shutdown = new AtomicInteger(); - - LOG.info().$("======= VOTING TEST ==========").$(); - - try (JournalWriter writer1 = tf1.getFactory().writer(Quote.class)) { - - try (JournalWriter writer2 = tf2.getFactory().writer(Quote.class)) { - - try (JournalWriter writer3 = tf3.getFactory().writer(Quote.class)) { - - try (JournalWriter writer4 = tf4.getFactory().writer(Quote.class)) { - - try (JournalWriter writer5 = tf5.getFactory().writer(Quote.class)) { - - ClusterController c1 = createController2(writer1, 0, tf1.getFactory(), active, standby, shutdown); - ClusterController c2 = createController2(writer2, 1, tf2.getFactory(), active, standby, shutdown); - ClusterController c3 = createController2(writer3, 2, tf3.getFactory(), active, standby, shutdown); - ClusterController c4 = createController2(writer4, 3, tf4.getFactory(), active, standby, shutdown); - ClusterController c5 = createController2(writer5, 4, tf5.getFactory(), active, standby, shutdown); - - - c1.start(); - c2.start(); - c3.start(); - c4.start(); - c5.start(); - - long t; - - t = System.currentTimeMillis(); - while (standby.get() < 4 && TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - t) < 600) { - Thread.yield(); - } - Assert.assertEquals(4, standby.get()); - - - t = System.currentTimeMillis(); - while (active.get() < 1 && TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - t) < 600) { - Thread.yield(); - } - Assert.assertEquals(1, active.get()); - - // on slower system instances can be subject to staggered startup, which can create noise in message loop - // this noise should get cancelled out given some time. - // 1 second should be plenty of time for any ELECTION message to be suppressed. - Thread.sleep(1000); - - standby.set(0); - active.set(0); - - LOG.info().$("Stage 1, halt leader").$(); - - if (c5.isLeader()) { - c5.halt(); - LOG.info().$("halted 4").$(); - } else if (c4.isLeader()) { - c4.halt(); - LOG.info().$("halted 3").$(); - } else if (c3.isLeader()) { - c3.halt(); - LOG.info().$("halted 2").$(); - } else if (c2.isLeader()) { - c2.halt(); - LOG.info().$("halted 1").$(); - } else if (c1.isLeader()) { - c1.halt(); - LOG.info().$("halted 0").$(); - } else { - Assert.fail("No leader"); - } - - LOG.info().$("Stage 2, waiting for election process to complete").$(); - t = System.currentTimeMillis(); - while ((active.get() < 1 || standby.get() < 3) && TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - t) < 180) { - Thread.yield(); - } - - LOG.info().$("Checking leader").$(); - - try { - Assert.assertEquals(3, standby.get()); - Assert.assertEquals(1, active.get()); - - LOG.info().$("Test complete").$(); - } finally { - c1.halt(); - c2.halt(); - c3.halt(); - c4.halt(); - } - } - } - } - } - } - } - - @Test - public void testStaggeredFailOver() throws Exception { - final CountDownLatch active1Latch = new CountDownLatch(1); - final CountDownLatch active2Latch = new CountDownLatch(1); - final CountDownLatch standby1Latch = new CountDownLatch(1); - final CountDownLatch standby2Latch = new CountDownLatch(1); - final CountDownLatch shutdown1 = new CountDownLatch(1); - final CountDownLatch shutdown2 = new CountDownLatch(1); - - try (JournalWriter writer1 = getFactory().writer(Quote.class)) { - - try (JournalWriter writer2 = tf.getFactory().writer(Quote.class)) { - - ClusterController controller1 = createControllerX(writer1, 0, getFactory(), active1Latch, standby1Latch, shutdown1); - controller1.start(); - - Assert.assertTrue(active1Latch.await(5, TimeUnit.SECONDS)); - Assert.assertEquals("Node 1 is expected to be active", 0, active1Latch.getCount()); - standby1Latch.await(200, TimeUnit.MILLISECONDS); - Assert.assertEquals("Node 1 standby callback is not expected to be called", 1, standby1Latch.getCount()); - - ClusterController controller2 = createControllerX(writer2, 1, tf.getFactory(), active2Latch, standby2Latch, shutdown2); - controller2.start(); - - standby2Latch.await(5, TimeUnit.SECONDS); - Assert.assertEquals("Node 2 is expected to be standing by", 0, standby2Latch.getCount()); - active2Latch.await(200, TimeUnit.MILLISECONDS); - Assert.assertEquals("Node 2 active() callback is not expected to be called", 1, active2Latch.getCount()); - - controller1.halt(); - shutdown1.await(5, TimeUnit.SECONDS); - Assert.assertEquals(0, shutdown1.getCount()); - - active2Latch.await(5, TimeUnit.SECONDS); - Assert.assertEquals(0, active2Latch.getCount()); - - controller2.halt(); - shutdown2.await(5, TimeUnit.SECONDS); - Assert.assertEquals(0, shutdown2.getCount()); - } - } - } - - @Test - public void testStaggeredStartup() throws Exception { - final CountDownLatch active1Latch = new CountDownLatch(1); - final CountDownLatch active2Latch = new CountDownLatch(1); - final CountDownLatch standby1Latch = new CountDownLatch(1); - final CountDownLatch standby2Latch = new CountDownLatch(1); - final CountDownLatch shutdown1 = new CountDownLatch(1); - final CountDownLatch shutdown2 = new CountDownLatch(1); - - try (JournalWriter writer1 = getFactory().writer(Quote.class)) { - - try (JournalWriter writer2 = tf.getFactory().writer(Quote.class)) { - - ClusterController controller1 = createControllerX(writer1, 0, getFactory(), active1Latch, standby1Latch, shutdown1); - controller1.start(); - - Assert.assertTrue(active1Latch.await(5, TimeUnit.SECONDS)); - Assert.assertEquals("Node 1 is expected to be active", 0, active1Latch.getCount()); - standby1Latch.await(200, TimeUnit.MILLISECONDS); - Assert.assertEquals("Node 1 standby callback is not expected to be called", 1, standby1Latch.getCount()); - - ClusterController controller2 = createControllerX(writer2, 1, tf.getFactory(), active2Latch, standby2Latch, shutdown2); - controller2.start(); - - standby2Latch.await(5, TimeUnit.SECONDS); - Assert.assertEquals("Node 2 is expected to be standing by", 0, standby2Latch.getCount()); - active2Latch.await(200, TimeUnit.MILLISECONDS); - Assert.assertEquals("Node 2 active() callback is not expected to be called", 1, active2Latch.getCount()); - - controller2.halt(); - shutdown2.await(5, TimeUnit.SECONDS); - Assert.assertEquals(0, shutdown2.getCount()); - - controller1.halt(); - shutdown1.await(5, TimeUnit.SECONDS); - Assert.assertEquals(0, shutdown1.getCount()); - } - } - } - - @Test - public void testStandalone() throws Exception { - final CountDownLatch active = new CountDownLatch(1); - final CountDownLatch standby = new CountDownLatch(1); - final CountDownLatch shutdown = new CountDownLatch(1); - - try (JournalWriter writer = getFactory().writer(Quote.class)) { - ClusterController controller = createControllerX(writer, 1, getFactory(), active, standby, shutdown); - - controller.start(); - Assert.assertTrue(active.await(5, TimeUnit.SECONDS)); - Assert.assertEquals("goActive() did not fire", 0, active.getCount()); - standby.await(200, TimeUnit.MILLISECONDS); - Assert.assertEquals("goPassive() not expected to fire", 1, standby.getCount()); - - controller.halt(); - shutdown.await(5, TimeUnit.SECONDS); - Assert.assertEquals(0, shutdown.getCount()); - controller.halt(); - } - } - - @Test - public void testTiebreakFailOver() throws Exception { - - final CountDownLatch active1Latch = new CountDownLatch(1); - final CountDownLatch active2Latch = new CountDownLatch(1); - final CountDownLatch standby1Latch = new CountDownLatch(1); - final CountDownLatch standby2Latch = new CountDownLatch(1); - final CountDownLatch shutdown1 = new CountDownLatch(1); - final CountDownLatch shutdown2 = new CountDownLatch(1); - - try (JournalWriter writer1 = getFactory().writer(Quote.class)) { - - try (JournalWriter writer2 = tf.getFactory().writer(Quote.class)) { - ClusterController controller1 = createControllerX(writer1, 0, getFactory(), active1Latch, standby1Latch, shutdown1); - ClusterController controller2 = createControllerX(writer2, 1, tf.getFactory(), active2Latch, standby2Latch, shutdown2); - - // start two controller without pause - controller2.start(); - controller1.start(); - - getFactory().close(); - - long t = System.currentTimeMillis(); - do { - active1Latch.await(1, TimeUnit.MICROSECONDS); - active2Latch.await(1, TimeUnit.MICROSECONDS); - } - while (active1Latch.getCount() > 0 && active2Latch.getCount() > 0 && (System.currentTimeMillis() - t) < 2000); - - Assert.assertFalse("Two nodes are active simultaneously", active1Latch.getCount() == 0 && active2Latch.getCount() == 0); - Assert.assertFalse("No leader", active1Latch.getCount() > 0 && active2Latch.getCount() > 0); - - - if (active1Latch.getCount() == 0) { - standby2Latch.await(2, TimeUnit.SECONDS); - Assert.assertEquals("Node 2 is expected to be on standby", 0, standby2Latch.getCount()); - - standby1Latch.await(200, TimeUnit.MILLISECONDS); - Assert.assertEquals("Node 1 is NOT expected to be on standby", 1, standby1Latch.getCount()); - } else { - standby1Latch.await(2, TimeUnit.SECONDS); - Assert.assertEquals("Node 1 is expected to be on standby", 0, standby1Latch.getCount()); - - standby2Latch.await(200, TimeUnit.MILLISECONDS); - Assert.assertEquals("Node 2 is NOT expected to be on standby", 1, standby2Latch.getCount()); - } - - controller2.halt(); - - - shutdown2.await(5, TimeUnit.SECONDS); - Assert.assertEquals("Controller 2 should have shut down", 0, shutdown2.getCount()); - - active1Latch.await(10, TimeUnit.SECONDS); - Assert.assertEquals("Node 1 is expected to become active", 0, active1Latch.getCount()); - - controller1.halt(); - shutdown1.await(10, TimeUnit.SECONDS); - Assert.assertEquals("Controller 1 should have shut down", 0, shutdown1.getCount()); - } - } - } - - private ClusterController createController2(final JournalWriter writer, int instance, final Factory factory, final AtomicInteger active, final AtomicInteger standby, final AtomicInteger shutdown) { - return new ClusterController( - new ServerConfig() {{ - addNode(new ServerNode(4, "localhost:7040")); - addNode(new ServerNode(3, "localhost:7041")); - addNode(new ServerNode(2, "localhost:7042")); - addNode(new ServerNode(1, "localhost:7043")); - addNode(new ServerNode(0, "localhost:7044")); - setHeartbeatFrequency(50); - setEnableMultiCast(false); - }}, - new ClientConfig() {{ - setEnableMultiCast(false); - setConnectionTimeout(30000); - }}, - factory, - instance, - new ArrayList() {{ - add(writer); - }}, - new ClusterStatusListener() { - @Override - public void goActive() { - active.incrementAndGet(); - } - - @Override - public void goPassive(ServerNode activeNode) { - standby.incrementAndGet(); - } - - @Override - public void onShutdown() { - shutdown.incrementAndGet(); - } - } - ); - } - - private ClusterController createControllerX(final JournalWriter writer, int instance, final Factory factory, final CountDownLatch active, final CountDownLatch standby, final CountDownLatch shutdown) { - return new ClusterController( - new ServerConfig() {{ - addNode(new ServerNode(0, "localhost:7080")); - addNode(new ServerNode(1, "localhost:7090")); - setEnableMultiCast(false); - setHeartbeatFrequency(50); - }}, - new ClientConfig() {{ - setEnableMultiCast(false); - }}, - factory, - instance, - new ArrayList() {{ - add(writer); - }}, - new ClusterStatusListener() { - @Override - public void goActive() { - active.countDown(); - } - - @Override - public void goPassive(ServerNode activeNode) { - standby.countDown(); - } - - @Override - public void onShutdown() { - shutdown.countDown(); - } - } - ); - } - -} diff --git a/core/src/test/java/com/questdb/net/ha/DataLossTest.java b/core/src/test/java/com/questdb/net/ha/DataLossTest.java deleted file mode 100644 index 7ca209e6f..000000000 --- a/core/src/test/java/com/questdb/net/ha/DataLossTest.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.model.Quote; -import com.questdb.net.ha.config.ClientConfig; -import com.questdb.net.ha.config.ServerConfig; -import com.questdb.net.ha.config.ServerNode; -import com.questdb.store.JournalListener; -import com.questdb.store.JournalWriter; -import com.questdb.test.tools.AbstractTest; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -public class DataLossTest extends AbstractTest { - - @Test - @Ignore - public void testDiscardFile() throws Exception { - - // create master journal - try (JournalWriter master = getFactory().writer(Quote.class, "master")) { - TestUtils.generateQuoteData(master, 300, master.getMaxTimestamp()); - master.commit(); - - // publish master out - JournalServer server = new JournalServer( - new ServerConfig() {{ - addNode(new ServerNode(0, "localhost")); - setEnableMultiCast(false); - setHeartbeatFrequency(50); - }} - , getFactory()); - server.publish(master); - server.start(); - - final AtomicInteger counter = new AtomicInteger(); - final AtomicInteger doNotExpect = new AtomicInteger(); - - // equalize slave - JournalClient client = new JournalClient(new ClientConfig("localhost") {{ - setEnableMultiCast(false); - }}, getFactory()); - client.subscribe(Quote.class, "master", "slave", new JournalListener() { - @Override - public void onCommit() { - counter.incrementAndGet(); - } - - @Override - public void onEvent(int event) { - - } - }); - client.start(); - - TestUtils.assertCounter(counter, 1, 10, TimeUnit.SECONDS); - - // stop client to be able to add to slave manually - client.halt(); - - System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); - - // add more data to slave - try (JournalWriter slave = getFactory().writer(Quote.class, "slave")) { - TestUtils.generateQuoteData(slave, 200, slave.getMaxTimestamp()); - slave.commit(); - } - - // synchronise slave again - client = new JournalClient(new ClientConfig("localhost"), getFactory()); - client.subscribe(Quote.class, "master", "slave", new JournalListener() { - @Override - public void onCommit() { - doNotExpect.incrementAndGet(); - } - - @Override - public void onEvent(int event) { - counter.incrementAndGet(); - } - }); - client.start(); - - TestUtils.assertCounter(counter, 2, 180, TimeUnit.SECONDS); - client.halt(); - - Assert.assertEquals(0, doNotExpect.get()); - - // assert that slave journal is closed - - try (JournalWriter w = getFactory().writer(Quote.class, "slave")) { - Assert.assertNotNull(w); - } - - server.halt(); - } - } -} diff --git a/core/src/test/java/com/questdb/net/ha/FixedColumnTest.java b/core/src/test/java/com/questdb/net/ha/FixedColumnTest.java deleted file mode 100644 index 0cc04acc1..000000000 --- a/core/src/test/java/com/questdb/net/ha/FixedColumnTest.java +++ /dev/null @@ -1,247 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.net.ha.comsumer.FixedColumnDeltaConsumer; -import com.questdb.net.ha.producer.FixedColumnDeltaProducer; -import com.questdb.std.ex.JournalException; -import com.questdb.store.FixedColumn; -import com.questdb.store.JournalMode; -import com.questdb.store.MemoryFile; -import org.junit.*; -import org.junit.rules.TemporaryFolder; - -import java.io.File; - -public class FixedColumnTest { - - @Rule - public final TemporaryFolder temporaryFolder = new TemporaryFolder(); - private MemoryFile file; - private MemoryFile file2; - private MockByteChannel channel; - - @After - public void cleanup() { - file.delete(); - file2.delete(); - } - - @Before - public void setUp() throws JournalException { - file = new MemoryFile(new File(temporaryFolder.getRoot(), "col.d"), 22, JournalMode.APPEND, false); - // it is important to keep bit hint small, so that file2 has small buffers. This would made test go via both pathways. - // large number will result in tests not covering all of execution path. - file2 = new MemoryFile(new File(temporaryFolder.getRoot(), "col2.d"), 18, JournalMode.APPEND, false); - channel = new MockByteChannel(); - } - - @After - public void tearDown() { - file.close(); - file2.close(); - } - - @Test - public void testConsumerEqualToProducer() { - FixedColumn col1 = new FixedColumn(file, 4); - FixedColumn col2 = new FixedColumn(file2, 4); - - FixedColumnDeltaProducer producer = new FixedColumnDeltaProducer(col1); - - int max = 1500000; - - for (int i = 0; i < max; i++) { - col1.putInt(max - i); - col1.commit(); - } - - for (int i = 0; i < max; i++) { - col2.putInt(max - i); - col2.commit(); - } - - producer.configure(col2.size(), col1.size()); - - // hasNext() can be true, because of compulsory header - // however, if column doesn't have data, hasContent() must be false. - Assert.assertFalse(producer.hasContent()); - Assert.assertEquals(col1.size(), col2.size()); - - for (int i = 0; i < max; i++) { - Assert.assertEquals(max - i, col2.getInt(i)); - } - } - - @Test - public void testConsumerLargerThanProducer() { - FixedColumn col1 = new FixedColumn(file, 4); - FixedColumn col2 = new FixedColumn(file2, 4); - - FixedColumnDeltaProducer producer = new FixedColumnDeltaProducer(col1); - - int max = 1500000; - - for (int i = 0; i < max - 500000; i++) { - col1.putInt(max - i); - col1.commit(); - } - - for (int i = 0; i < max; i++) { - col2.putInt(max - i); - col2.commit(); - } - - producer.configure(col2.size(), col1.size()); - Assert.assertFalse(producer.hasContent()); - } - - @Test - public void testConsumerReset() throws Exception { - FixedColumn col1 = new FixedColumn(file, 4); - FixedColumn col2 = new FixedColumn(file2, 4); - - FixedColumnDeltaProducer producer = new FixedColumnDeltaProducer(col1); - ChannelConsumer consumer = new FixedColumnDeltaConsumer(col2); - - int max = 1500000; - - for (int i = 0; i < max; i++) { - col1.putInt(max - i); - col1.commit(); - } - - for (int i = 0; i < max - 500000; i++) { - col2.putInt(max - i); - col2.commit(); - } - - producer.configure(col2.size(), col1.size()); - Assert.assertTrue(producer.hasContent()); - producer.write(channel); - consumer.read(channel); - col2.commit(); - - Assert.assertEquals(col1.size(), col2.size()); - - for (int i = 0; i < 10000; i++) { - col1.putInt(max + 10000 - i); - col1.commit(); - } - - producer.configure(col2.size(), col1.size()); - Assert.assertTrue(producer.hasContent()); - producer.write(channel); - consumer.read(channel); - col2.commit(); - - Assert.assertEquals(col1.size(), col2.size()); - - for (int i = 0; i < max; i++) { - Assert.assertEquals(max - i, col2.getInt(i)); - } - - for (int i = max; i < max + 10000; i++) { - Assert.assertEquals(max + max + 10000 - i, col2.getInt(i)); - } - } - - @Test - public void testConsumerSmallerThanProducer() throws Exception { - FixedColumn col1 = new FixedColumn(file, 4); - FixedColumn col2 = new FixedColumn(file2, 4); - - FixedColumnDeltaProducer producer = new FixedColumnDeltaProducer(col1); - ChannelConsumer consumer = new FixedColumnDeltaConsumer(col2); - - int max = 1500000; - - for (int i = 0; i < max; i++) { - col1.putInt(max - i); - col1.commit(); - } - - for (int i = 0; i < max - 500000; i++) { - col2.putInt(max - i); - col2.commit(); - } - - producer.configure(col2.size(), col1.size()); - Assert.assertTrue(producer.hasContent()); - producer.write(channel); - consumer.read(channel); - col2.commit(); - - Assert.assertEquals(col1.size(), col2.size()); - - for (int i = 0; i < max; i++) { - Assert.assertEquals(max - i, col2.getInt(i)); - } - } - - @Test - public void testEmptyConsumerAndPopulatedProducer() throws Exception { - FixedColumn col1 = new FixedColumn(file, 4); - FixedColumn col2 = new FixedColumn(file2, 4); - - FixedColumnDeltaProducer producer = new FixedColumnDeltaProducer(col1); - ChannelConsumer consumer = new FixedColumnDeltaConsumer(col2); - - int max = 1500000; - - for (int i = 0; i < max; i++) { - col1.putInt(max - i); - col1.commit(); - } - - producer.configure(col2.size(), col1.size()); - - // hasNext() can be true, because of compulsory header - // however, if column doesn't have data, hasContent() must be false. - Assert.assertTrue(producer.hasContent()); - producer.write(channel); - consumer.read(channel); - col2.commit(); - - Assert.assertEquals(col1.size(), col2.size()); - - for (int i = 0; i < max; i++) { - Assert.assertEquals(max - i, col2.getInt(i)); - } - } - - @Test - public void testEmptyConsumerAndProducer() { - FixedColumn col1 = new FixedColumn(file, 4); - FixedColumn col2 = new FixedColumn(file2, 4); - - FixedColumnDeltaProducer producer = new FixedColumnDeltaProducer(col1); - producer.configure(col2.size(), col1.size()); - - // hasNext() can be true, because of compulsory header - // however, if column doesn't have data, hasContent() must be false. - Assert.assertFalse(producer.hasContent()); - Assert.assertEquals(col1.size(), col2.size()); - } -} diff --git a/core/src/test/java/com/questdb/net/ha/GenericTest.java b/core/src/test/java/com/questdb/net/ha/GenericTest.java deleted file mode 100644 index a2efd4b5c..000000000 --- a/core/src/test/java/com/questdb/net/ha/GenericTest.java +++ /dev/null @@ -1,378 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.ex.JournalConfigurationException; -import com.questdb.model.Quote; -import com.questdb.net.ha.config.ClientConfig; -import com.questdb.net.ha.config.ServerConfig; -import com.questdb.net.ha.config.ServerNode; -import com.questdb.ql.RecordSource; -import com.questdb.ql.RecordSourcePrinter; -import com.questdb.std.Rnd; -import com.questdb.std.str.StringSink; -import com.questdb.std.time.DateFormatUtils; -import com.questdb.store.*; -import com.questdb.store.factory.configuration.JournalStructure; -import com.questdb.test.tools.AbstractTest; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Test; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -public class GenericTest extends AbstractTest { - - @Test - public void testClassToGenericPublish() throws Exception { - try (JournalWriter w = getFactory().writer(Quote.class, "quote")) { - - JournalServer server = new JournalServer(new ServerConfig() {{ - addNode(new ServerNode(1, "localhost")); - setHeartbeatFrequency(100); - setEnableMultiCast(false); - }}, getFactory()); - - server.publish(w); - server.start(); - - final CountDownLatch ready = new CountDownLatch(1); - - JournalClient client = new JournalClient(new ClientConfig("localhost") {{ - setEnableMultiCast(false); - }}, getFactory()); - - client.subscribe(new JournalKey("quote"), new JournalKey("abc"), new JournalListener() { - @Override - public void onCommit() { - ready.countDown(); - } - - @Override - public void onEvent(int event) { - - } - }); - client.start(); - - TestUtils.generateQuoteData(w, 100, DateFormatUtils.parseDateTime("2015-01-10T12:00:00.000Z")); - w.commit(); - - Assert.assertTrue(ready.await(1, TimeUnit.SECONDS)); - - StringSink sink = new StringSink(); - RecordSourcePrinter p = new RecordSourcePrinter(sink); - try (RecordSource rs = compile("abc")) { - p.print(rs, getFactory()); - - final String expected = "2015-01-10T12:00:00.000Z\tAGK.L\t0.000001189157\t1.050231933594\t1326447242\t948263339\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tBP.L\t104.021850585938\t0.006688738358\t1575378703\t1436881714\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tBP.L\t879.117187500000\t496.806518554688\t1530831067\t339631474\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tRRS.L\t768.000000000000\t0.000020634160\t426455968\t1432278050\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tBT-A.L\t256.000000000000\t0.000000035797\t1404198\t1153445279\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tGKN.L\t920.625000000000\t0.040750414133\t761275053\t1232884790\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tBP.L\t512.000000000000\t896.000000000000\t422941535\t113506296\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tLLOY.L\t12.923866510391\t0.032379742712\t2006313928\t2132716300\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tABF.L\t0.006530375686\t0.000000000000\t1890602616\t2137969456\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tLLOY.L\t0.000000017324\t720.000000000000\t410717394\t458818940\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tBT-A.L\t384.000000000000\t0.000000019700\t1575135393\t530317703\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tABF.L\t0.001165474765\t0.000001752813\t171200398\t2034804966\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tWTB.L\t1.507822513580\t695.796875000000\t1515787781\t66297136\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tAGK.L\t172.796875000000\t1.959461987019\t360860352\t1538602195\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tLLOY.L\t0.000000006081\t942.899414062500\t1857212401\t1985398001\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tTLW.L\t424.828125000000\t1024.000000000000\t1269042121\t1566901076\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tADM.L\t153.473033905029\t0.000355183205\t532665695\t1424048819\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tTLW.L\t632.921875000000\t348.175781250000\t89906802\t373499303\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tABF.L\t186.000000000000\t0.000020114637\t731466113\t1609750740\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tBT-A.L\t0.015470010694\t671.442138671875\t880943673\t1172180184\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tAGK.L\t0.000000009901\t0.060836097226\t1235206821\t817130367\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tLLOY.L\t0.003103211522\t271.689331054688\t1864113037\t865832060\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tBT-A.L\t770.359375000000\t0.000000014643\t618037497\t844704299\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tTLW.L\t1.229880273342\t4.852988362312\t639125092\t519895483\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tWTB.L\t0.000001305853\t767.380859375000\t614536941\t462277692\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tBT-A.L\t0.000000776007\t0.000484068747\t195213883\t283321892\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tABF.L\t583.609375000000\t0.555824235082\t1015055928\t1383560599\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tGKN.L\t296.544433593750\t174.774871826172\t1503763988\t805434743\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tAGK.L\t842.000000000000\t100.000000000000\t514934130\t246923735\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tBT-A.L\t364.462486267090\t0.000002526560\t1475953213\t1023667478\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tABF.L\t0.000603844470\t0.000027837185\t133913299\t2042181314\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tTLW.L\t0.000000261681\t352.000000000000\t684778036\t2076507991\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tLLOY.L\t0.000125102033\t0.000000000000\t880219256\t862447505\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tWTB.L\t0.000000194258\t0.001741337735\t1204245663\t1179767285\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tGKN.L\t218.371459960938\t0.000003607215\t1542366041\t239305284\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tAGK.L\t1024.000000000000\t33.643297195435\t2077041000\t2062507031\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tABF.L\t256.000000000000\t0.001175858604\t292438036\t39497392\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tGKN.L\t144.421875000000\t0.000063085048\t597366062\t370796356\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tLLOY.L\t256.000000000000\t0.000000032050\t484276102\t2017314910\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tBT-A.L\t0.000080152415\t832.000000000000\t1465751763\t36814604\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tLLOY.L\t512.000000000000\t69.914062500000\t874367915\t120660220\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tABF.L\t768.000000000000\t134.988502502441\t1218814076\t1822590290\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tABF.L\t0.000000001871\t589.718750000000\t1484108978\t1962248170\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tAGK.L\t736.000000000000\t0.000003953393\t1570930196\t494223693\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tRRS.L\t0.000000001374\t0.000000014146\t273567866\t365989785\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tAGK.L\t0.115072973073\t3.896593213081\t1180113884\t1863806522\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tLLOY.L\t386.843750000000\t0.000000005098\t689798930\t529035657\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tADM.L\t5.590153217316\t8.408761024475\t976011946\t1594425659\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tLLOY.L\t0.000000248992\t10.084638834000\t557653156\t1440049547\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tLLOY.L\t0.000002116648\t164.218750000000\t1479209616\t1300367617\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tAGK.L\t0.000005107453\t0.000014963527\t2136017735\t782135501\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tABF.L\t629.480468750000\t310.101058959961\t465171440\t1805101061\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tTLW.L\t0.000000049302\t0.611244902015\t297507019\t1197986472\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tGKN.L\t672.000000000000\t7.793050527573\t831951785\t2108259867\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tGKN.L\t0.018715771381\t1.461132109165\t1561652006\t1915752164\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tRRS.L\t655.625000000000\t52.330078125000\t1501720177\t464081554\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tADM.L\t0.000036359392\t121.029296875000\t876817614\t1705668785\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tBT-A.L\t265.807006835938\t0.004646989168\t1912522421\t1654490571\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tBP.L\t0.971607863903\t97.790924072266\t1436639185\t1975151962\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tADM.L\t0.000000000000\t353.683593750000\t1604266757\t647653731\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tGKN.L\t8.039016723633\t7.977778911591\t1341091541\t1977116623\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tGKN.L\t638.000000000000\t0.014096791856\t1091570282\t772867311\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tBT-A.L\t0.000002654824\t820.224609375000\t2094760568\t1194691156\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tAGK.L\t300.093750000000\t0.000000040298\t724165345\t1307291490\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tLLOY.L\t0.005052038119\t0.000785129319\t1418612367\t1933125405\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tRRS.L\t0.127358488739\t0.000000718634\t570261315\t158323100\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tADM.L\t0.000000009919\t0.000000059185\t1290623970\t873017617\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tABF.L\t0.040659694001\t0.000000818963\t2029231362\t400205299\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tGKN.L\t0.000012560774\t5.638884067535\t1722682901\t1025310386\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tBT-A.L\t873.000000000000\t127.708919525146\t1753567161\t256128916\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tTLW.L\t939.150390625000\t512.000000000000\t447593202\t135792148\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tBT-A.L\t978.632812500000\t0.000194281980\t1567482693\t8264817\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tADM.L\t844.000000000000\t46.725388526917\t432358603\t1657803999\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tRRS.L\t31.000000000000\t428.000000000000\t481303173\t739168384\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tWTB.L\t75.842805862427\t0.000002408446\t1297032488\t1215601315\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tADM.L\t283.158325195313\t880.000000000000\t357119340\t970294725\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tBT-A.L\t0.000003385293\t965.151367187500\t844915022\t1889838659\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tABF.L\t0.031326758675\t0.360216885805\t263487884\t1680503149\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tADM.L\t508.375000000000\t768.000000000000\t1923884740\t1121347399\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tRRS.L\t12.290055274963\t0.011763263494\t304383158\t2039181884\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tRRS.L\t4.111308574677\t1.257051765919\t159178348\t604818378\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tAGK.L\t0.000002205143\t228.001586914063\t1815322506\t1197959281\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tAGK.L\t0.000000129186\t0.011274382472\t1060590724\t1159512064\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tBP.L\t19.756743907928\t0.000340424791\t526923908\t1034870849\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tADM.L\t0.000180012023\t0.000000052629\t1406232957\t378247895\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tBP.L\t400.000000000000\t106.662109375000\t1440131320\t971963578\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tWTB.L\t68.043695449829\t380.435256958008\t1204423553\t795316150\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tBT-A.L\t0.004094106262\t0.000000914462\t2138704106\t655076307\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tABF.L\t64.000000000000\t445.875000000000\t1848218326\t1023760162\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tBT-A.L\t0.000000157150\t6.012886285782\t1247892921\t1890713369\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tGKN.L\t497.000000000000\t111.975021362305\t24972718\t1583707719\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tGKN.L\t549.125503540039\t18.834793090820\t957024901\t1487779338\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tGKN.L\t0.000000150060\t412.000000000000\t1158267509\t980916820\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tTLW.L\t0.000000007168\t41.500000000000\t1725416460\t1078921487\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tBP.L\t354.286376953125\t540.000000000000\t1772028439\t1496904948\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tABF.L\t0.000010415702\t372.000000000000\t1262895671\t1914805024\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tRRS.L\t728.300781250000\t15.240249156952\t1926049591\t2113879331\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tGKN.L\t448.000000000000\t0.696862459183\t1499957018\t1753521575\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tLLOY.L\t0.019178653602\t1024.000000000000\t1445553836\t896453005\tFast trading\tLXE\n" + - "2015-01-10T12:00:00.000Z\tRRS.L\t1021.000000000000\t391.000000000000\t856634079\t840591709\tFast trading\tLXE\n"; - - Assert.assertEquals(expected, sink.toString()); - - client.halt(); - server.halt(); - } - } - } - - @Test - public void testDuplicateTimestamp() throws Exception { - try { - getFactory().writer(new JournalStructure("xyz") {{ - $sym("x").index(); - $int("y"); - $double("z"); - $ts("a"); - $ts("b"); - partitionBy(PartitionBy.DAY); - }}).close(); - Assert.fail(); - } catch (JournalConfigurationException ignore) { - // pass - } - } - - @Test - public void testGenericPublish() throws Exception { - - try (JournalWriter w = getFactory().writer(new JournalStructure("xyz") {{ - $sym("x").index(); - $int("y"); - $double("z"); - $ts(); - partitionBy(PartitionBy.DAY); - }})) { - - JournalServer server = new JournalServer(new ServerConfig() {{ - addNode(new ServerNode(1, "localhost")); - setHeartbeatFrequency(100); - setEnableMultiCast(false); - }}, getFactory()); - server.publish(w); - server.start(); - - final CountDownLatch ready = new CountDownLatch(1); - - JournalClient client = new JournalClient(new ClientConfig("localhost") {{ - setEnableMultiCast(false); - }}, getFactory()); - client.subscribe(new JournalKey("xyz"), new JournalKey("abc"), new JournalListener() { - @Override - public void onCommit() { - ready.countDown(); - } - - @Override - public void onEvent(int event) { - - } - }); - client.start(); - - Rnd rnd = new Rnd(); - for (int i = 0; i < 100; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putSym(0, rnd.nextString(10)); - ew.putInt(1, rnd.nextInt()); - ew.putDouble(2, rnd.nextDouble()); - ew.append(); - } - w.commit(); - - Assert.assertTrue(ready.await(1, TimeUnit.SECONDS)); - - StringSink sink = new StringSink(); - RecordSourcePrinter p = new RecordSourcePrinter(sink); - try (RecordSource rs = compile("abc")) { - p.print(rs, getFactory()); - - final String expected = "VTJWCPSWHY\t-1191262516\t0.024494420737\t1970-01-01T00:00:00.000Z\n" + - "EHNRXGZSXU\t-1458132197\t768.000000000000\t1970-01-01T00:00:00.000Z\n" + - "BTGPGWFFYU\t-1125169127\t188.000000000000\t1970-01-01T00:00:00.000Z\n" + - "YQEHBHFOWL\t-938514914\t0.032379742712\t1970-01-01T00:00:00.000Z\n" + - "YSBEOUOJSH\t1890602616\t0.000000003895\t1970-01-01T00:00:00.000Z\n" + - "DRQQULOFJG\t-530317703\t1.583955645561\t1970-01-01T00:00:00.000Z\n" + - "RSZSRYRFBV\t-1787109293\t0.000076281818\t1970-01-01T00:00:00.000Z\n" + - "GOOZZVDZJM\t-1212175298\t11.229226589203\t1970-01-01T00:00:00.000Z\n" + - "CXZOUICWEK\t1876812930\t153.473033905029\t1970-01-01T00:00:00.000Z\n" + - "UVSDOTSEDY\t-998315423\t56.593492507935\t1970-01-01T00:00:00.000Z\n" + - "GQOLYXWCKY\t-2075675260\t0.060836097226\t1970-01-01T00:00:00.000Z\n" + - "WDSWUGSHOL\t1864113037\t-1013.467773437500\t1970-01-01T00:00:00.000Z\n" + - "IQBZXIOVIK\t519895483\t0.053118304349\t1970-01-01T00:00:00.000Z\n" + - "SSUQSRLTKV\t-2080340570\t0.000000002016\t1970-01-01T00:00:00.000Z\n" + - "OJIPHZEPIH\t1362833895\t142.000000000000\t1970-01-01T00:00:00.000Z\n" + - "OVLJUMLGLH\t923501161\t364.462486267090\t1970-01-01T00:00:00.000Z\n" + - "EOYPHRIPZI\t-1280991111\t0.451262347400\t1970-01-01T00:00:00.000Z\n" + - "ZRMFMBEZGH\t-1121895896\t0.001741337735\t1970-01-01T00:00:00.000Z\n" + - "KFLOPJOXPK\t-1542366041\t-1024.000000000000\t1970-01-01T00:00:00.000Z\n" + - "IHYHBOQMYS\t39497392\t26.612817287445\t1970-01-01T00:00:00.000Z\n" + - "GLUOHNZHZS\t-147343840\t0.017535420135\t1970-01-01T00:00:00.000Z\n" + - "GLOGIFOUSZ\t-1775036711\t-911.000000000000\t1970-01-01T00:00:00.000Z\n" + - "QEBNDCQCEH\t1448081412\t0.000000001871\t1970-01-01T00:00:00.000Z\n" + - "VELLKKHTWN\t1147642496\t0.000969694171\t1970-01-01T00:00:00.000Z\n" + - "FLRBROMNXK\t719793244\t0.000000005098\t1970-01-01T00:00:00.000Z\n" + - "ULIGYVFZFK\t976011946\t0.000036501544\t1970-01-01T00:00:00.000Z\n" + - "UOGXHFVWSW\t-1300367617\t488.093750000000\t1970-01-01T00:00:00.000Z\n" + - "OONFCLTJCK\t-799774729\t0.000043022766\t1970-01-01T00:00:00.000Z\n" + - "NTOGMXUKLG\t1746137611\t0.000000038730\t1970-01-01T00:00:00.000Z\n" + - "LUQDYOPHNI\t534328386\t-655.625000000000\t1970-01-01T00:00:00.000Z\n" + - "FDTNPHFLPB\t992057087\t-830.895019531250\t1970-01-01T00:00:00.000Z\n" + - "ZWWCCNGTNL\t-857795778\t-353.683593750000\t1970-01-01T00:00:00.000Z\n" + - "UHHIUGGLNY\t-1341091541\t0.000001089423\t1970-01-01T00:00:00.000Z\n" + - "CBDMIGQZVK\t1194691156\t103.519111633301\t1970-01-01T00:00:00.000Z\n" + - "QZSLQVFGPP\t-770962341\t0.003051488020\t1970-01-01T00:00:00.000Z\n" + - "XBHYSBQYMI\t1289699549\t5.336447119713\t1970-01-01T00:00:00.000Z\n" + - "VTNPIWZNFK\t-460860589\t0.000012560774\t1970-01-01T00:00:00.000Z\n" + - "MCGFNWGRMD\t705091880\t0.000000006800\t1970-01-01T00:00:00.000Z\n" + - "JYDVRVNGST\t855975978\t46.725388526917\t1970-01-01T00:00:00.000Z\n" + - "DRZEIWFOQK\t481303173\t38.688202857971\t1970-01-01T00:00:00.000Z\n" + - "QUWQOEENNE\t-970294725\t832.000000000000\t1970-01-01T00:00:00.000Z\n" + - "EMXDKXEJCT\t-795877457\t768.000000000000\t1970-01-01T00:00:00.000Z\n" + - "YFLUHZQSNP\t1141437597\t301.691406250000\t1970-01-01T00:00:00.000Z\n" + - "JSMKIXEYVT\t-534339619\t0.000002205143\t1970-01-01T00:00:00.000Z\n" + - "HHGGIWHPZR\t-69279231\t0.383871749043\t1970-01-01T00:00:00.000Z\n" + - "GZJYYFLSVI\t-1354963681\t106.662109375000\t1970-01-01T00:00:00.000Z\n" + - "WLEVMLKCJB\t1204423553\t0.000118756758\t1970-01-01T00:00:00.000Z\n" + - "UHLIHYBTVZ\t-1023760162\t0.000001439041\t1970-01-01T00:00:00.000Z\n" + - "NXFSUWPNXH\t882350590\t0.017423127312\t1970-01-01T00:00:00.000Z\n" + - "ZODWKOCPFY\t-1558709522\t640.000000000000\t1970-01-01T00:00:00.000Z\n" + - "KNCBWLNLRH\t-1422542921\t-354.286376953125\t1970-01-01T00:00:00.000Z\n" + - "YPOVFDBZWN\t1927063457\t-384.616943359375\t1970-01-01T00:00:00.000Z\n" + - "EHRUGPBMBT\t996323284\t-1024.000000000000\t1970-01-01T00:00:00.000Z\n" + - "BEGMITINLK\t856634079\t0.000002211302\t1970-01-01T00:00:00.000Z\n" + - "HNRJUEBWVL\t1890990613\t-486.985961914063\t1970-01-01T00:00:00.000Z\n" + - "BETTTKRIVO\t-1001120776\t0.238771528006\t1970-01-01T00:00:00.000Z\n" + - "PUNEFIVQFN\t1820147632\t-162.500000000000\t1970-01-01T00:00:00.000Z\n" + - "SBOSEPGIUQ\t2146422524\t10.085297346115\t1970-01-01T00:00:00.000Z\n" + - "ISQHNOJIGF\t-2139920832\t-256.000000000000\t1970-01-01T00:00:00.000Z\n" + - "GQVZWEVQTQ\t-2129399613\t-492.000000000000\t1970-01-01T00:00:00.000Z\n" + - "XTPNHTDCEB\t1944405123\t0.047431875020\t1970-01-01T00:00:00.000Z\n" + - "BBZVRLPTYX\t882405723\t0.000005221712\t1970-01-01T00:00:00.000Z\n" + - "FUXCDKDWOM\t1226884727\t-215.000000000000\t1970-01-01T00:00:00.000Z\n" + - "BJFRPXZSFX\t-483085744\t-1024.000000000000\t1970-01-01T00:00:00.000Z\n" + - "QXTGNJJILL\t-481534978\t1.034002423286\t1970-01-01T00:00:00.000Z\n" + - "IWTCWLFORG\t1733247129\t19.849394798279\t1970-01-01T00:00:00.000Z\n" + - "VMKPYVGPYK\t12659434\t-948.018188476563\t1970-01-01T00:00:00.000Z\n" + - "QMUDDCIHCN\t880291989\t-1024.000000000000\t1970-01-01T00:00:00.000Z\n" + - "JOPJEUKWMD\t-592205337\t-886.000000000000\t1970-01-01T00:00:00.000Z\n" + - "BBUKOJSOLD\t181870148\t0.014446553774\t1970-01-01T00:00:00.000Z\n" + - "DIPUNRPSMI\t233670179\t0.000001588220\t1970-01-01T00:00:00.000Z\n" + - "PDKOEZBRQS\t-1312915365\t-736.000000000000\t1970-01-01T00:00:00.000Z\n" + - "DIHHNSSTCR\t1881940349\t2.266549527645\t1970-01-01T00:00:00.000Z\n" + - "VQFULMERTP\t767949332\t-960.000000000000\t1970-01-01T00:00:00.000Z\n" + - "UYZVQQHSQS\t-459351439\t5.076923489571\t1970-01-01T00:00:00.000Z\n" + - "BHLNEJRMDI\t-877688809\t987.093750000000\t1970-01-01T00:00:00.000Z\n" + - "SGQFYQPZGP\t2091979674\t0.000000078822\t1970-01-01T00:00:00.000Z\n" + - "VLTPKBBQFN\t-259645664\t0.000000042444\t1970-01-01T00:00:00.000Z\n" + - "NNCTFSNSXH\t-485950131\t2.123810946941\t1970-01-01T00:00:00.000Z\n" + - "LELRUMMZSC\t1124318483\t0.000124199963\t1970-01-01T00:00:00.000Z\n" + - "OUIGENFELW\t-2031363046\t242.145568847656\t1970-01-01T00:00:00.000Z\n" + - "LBMQHGJBFQ\t264877675\t0.000000002151\t1970-01-01T00:00:00.000Z\n" + - "FIJZZYNPPB\t1344590222\t445.768707275391\t1970-01-01T00:00:00.000Z\n" + - "VRIIYMHOWK\t-764794651\t0.000000542615\t1970-01-01T00:00:00.000Z\n" + - "ZNLCNGZTOY\t-74511843\t512.000000000000\t1970-01-01T00:00:00.000Z\n" + - "RSFPVRQLGY\t-560545477\t0.000000971470\t1970-01-01T00:00:00.000Z\n" + - "NLITWGLFCY\t-992831440\t0.119503878057\t1970-01-01T00:00:00.000Z\n" + - "KLHTIIGQEY\t-485549973\t-448.039062500000\t1970-01-01T00:00:00.000Z\n" + - "VRGRQGKNPH\t1946796084\t0.000000093964\t1970-01-01T00:00:00.000Z\n" + - "BVDEGHLXGZ\t-420096736\t0.000084972578\t1970-01-01T00:00:00.000Z\n" + - "THMHZNVZHC\t1870334962\t2.253738045692\t1970-01-01T00:00:00.000Z\n" + - "EQGMPLUCFT\t-1073362485\t0.075787898153\t1970-01-01T00:00:00.000Z\n" + - "YTSZEOCVFF\t712201059\t0.012697421480\t1970-01-01T00:00:00.000Z\n" + - "KPFOYMNWDS\t80777671\t388.000000000000\t1970-01-01T00:00:00.000Z\n" + - "VDRHFBCZIO\t-1534034235\t-272.000000000000\t1970-01-01T00:00:00.000Z\n" + - "PGZHITQJLK\t1143795193\t100.419076919556\t1970-01-01T00:00:00.000Z\n" + - "LVSYLMSRHG\t-535358959\t41.351981163025\t1970-01-01T00:00:00.000Z\n" + - "KUSIMYDXUU\t157435167\t5.152941465378\t1970-01-01T00:00:00.000Z\n" + - "XNMUREIJUH\t1563307851\t433.924621582031\t1970-01-01T00:00:00.000Z\n" + - "CMZCCYVBDM\t-1982292415\t216.046455383301\t1970-01-01T00:00:00.000Z\n"; - - Assert.assertEquals(expected, sink.toString()); - - client.halt(); - server.halt(); - } - } - } -} diff --git a/core/src/test/java/com/questdb/net/ha/IntTest.java b/core/src/test/java/com/questdb/net/ha/IntTest.java deleted file mode 100644 index 7129ae638..000000000 --- a/core/src/test/java/com/questdb/net/ha/IntTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.net.ha.protocol.commands.IntResponseConsumer; -import com.questdb.net.ha.protocol.commands.IntResponseProducer; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class IntTest { - private MockByteChannel channel; - - @Before - public void setUp() { - channel = new MockByteChannel(); - } - - @Test - public void testInt() throws Exception { - IntResponseProducer producer = new IntResponseProducer(); - IntResponseConsumer consumer = new IntResponseConsumer(); - - producer.write(channel, 155); - Assert.assertEquals(155, consumer.getValue(channel)); - } -} diff --git a/core/src/test/java/com/questdb/net/ha/IntegrationTest.java b/core/src/test/java/com/questdb/net/ha/IntegrationTest.java deleted file mode 100644 index 3f5b58626..000000000 --- a/core/src/test/java/com/questdb/net/ha/IntegrationTest.java +++ /dev/null @@ -1,1046 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2019 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.log.Log; -import com.questdb.log.LogFactory; -import com.questdb.model.Quote; -import com.questdb.model.TestEntity; -import com.questdb.net.ha.config.ClientConfig; -import com.questdb.net.ha.config.ServerConfig; -import com.questdb.std.ex.JournalException; -import com.questdb.std.time.DateFormatUtils; -import com.questdb.store.*; -import com.questdb.store.factory.configuration.JournalConfigurationBuilder; -import com.questdb.test.tools.AbstractTest; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.CyclicBarrier; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -@Ignore -public class IntegrationTest extends AbstractTest { - - private static final Log LOG = LogFactory.getLog(IntegrationTest.class); - - private JournalClient client; - private JournalServer server; - - @Before - public void setUp() { - server = new JournalServer(new ServerConfig() {{ - setHeartbeatFrequency(TimeUnit.MILLISECONDS.toMillis(100)); - setEnableMultiCast(false); - }}, getFactory()); - client = new JournalClient(new ClientConfig("localhost"), getFactory()); - } - - @Test - @Ignore - public void testBadJournalDoesNotResubscribe() { - // todo: test that when client reconnects it doesn't retry bad subscriptions - Assert.fail(); - } - - @Test - public void testBadSubscriptionOnTheFlyFollowedByReconnect() throws Exception { - //todo: check that bad subscription doesn't interrupt data flow on good subscription - - try (final JournalWriter origin = getFactory().writer(Quote.class, "origin")) { - final int batchSize = 1000; - final int batchCount = 100; - - server.publish(origin); - - server.start(); - try { - final CountDownLatch terminated = new CountDownLatch(1); - JournalClient client = new JournalClient(new ClientConfig("localhost"), getFactory(), null, evt -> { - if (evt == JournalClientEvents.EVT_TERMINATED) { - terminated.countDown(); - } - }); - - client.start(); - - - final AtomicInteger commits = new AtomicInteger(); - final AtomicInteger errors = new AtomicInteger(); - final CountDownLatch localSubscribed = new CountDownLatch(1); - final CountDownLatch dataReceived = new CountDownLatch(1); - try { - - // create empty journal - getFactory().writer(Quote.class, "local").close(); - - try (final Journal local = getFactory().reader("local")) { - client.subscribe(Quote.class, "origin", "local", new JournalListener() { - @Override - public void onCommit() { - commits.incrementAndGet(); - try { - local.refresh(); - if (local.size() == batchCount * batchSize) { - dataReceived.countDown(); - } - } catch (JournalException e) { - e.printStackTrace(); - errors.incrementAndGet(); - } - } - - @Override - public void onEvent(int event) { - switch (event) { - case JournalEvents.EVT_JNL_SUBSCRIBED: - localSubscribed.countDown(); - break; - default: - errors.incrementAndGet(); - break; - } - } - }); - - final CountDownLatch published = new CountDownLatch(1); - final CyclicBarrier barrier = new CyclicBarrier(2); - final AtomicInteger publisherErrors = new AtomicInteger(); - - new Thread(() -> { - try { - barrier.await(); - - long timestamp = DateFormatUtils.parseDateTime("2013-09-04T10:00:00.000Z"); - long increment = 1000L; - - for (int i = 0; i < batchCount; i++) { - TestUtils.generateQuoteData(origin, batchSize, timestamp, increment); - timestamp += increment * (batchSize); - origin.commit(); - } - } catch (Throwable e) { - e.printStackTrace(); - publisherErrors.incrementAndGet(); - } - published.countDown(); - }).start(); - - Assert.assertTrue(localSubscribed.await(10, TimeUnit.SECONDS)); - barrier.await(); - - - // after publishing stream is setup we attempt to subscribe bad journal - // todo: this part breaks server, fix server and continue -// readerFactory.writer(new JournalConfigurationBuilder().$("x").$int("x").$()).close(); -// -// client.subscribe(Quote.class, "origin", "x", new JournalListener() { -// @Override -// public void onCommit() { -// -// } -// -// @Override -// public void onEvent(int event) { -// System.out.println("bad event: " + event); -// } -// }); - - - Assert.assertTrue(published.await(60, TimeUnit.SECONDS)); - Assert.assertTrue(dataReceived.await(60, TimeUnit.SECONDS)); - Assert.assertEquals(0, publisherErrors.get()); - Assert.assertEquals(0, errors.get()); - Assert.assertTrue(commits.get() > 0); - - local.refresh(); - Assert.assertEquals(batchSize * batchCount, local.size()); - } - } catch (Throwable e) { - e.printStackTrace(); - Assert.fail(); - } finally { - client.halt(); - } - Assert.assertTrue(terminated.await(5, TimeUnit.SECONDS)); - } finally { - server.halt(); - } - } - -// Assert.fail(); - } - - @Test - public void testClientConnect() throws Exception { - final CountDownLatch error = new CountDownLatch(1); - client = new JournalClient(new ClientConfig("localhost"), getFactory(), null, evt -> { - if (evt == JournalClientEvents.EVT_SERVER_ERROR) { - error.countDown(); - } - }); - - client.start(); - - Assert.assertTrue(error.await(30, TimeUnit.SECONDS)); - } - - @Test - public void testClientConnectServerHalt() throws Exception { - server.start(); - client.start(); - Thread.sleep(TimeUnit.SECONDS.toMillis(1)); - server.halt(); - Assert.assertEquals(0, server.getConnectedClients()); - Assert.assertFalse(server.isRunning()); - Thread.sleep(700); - Assert.assertFalse(client.isRunning()); - client.halt(); - } - - @Test - public void testClientDisconnect() throws Exception { - server.start(); - client.start(); - Thread.sleep(100); - client.halt(); - Assert.assertFalse(client.isRunning()); - Thread.sleep(100); - Assert.assertEquals(0, server.getConnectedClients()); - server.halt(); - } - - /** - * Create two journal that are in sync. - * Disconnect synchronisation and advance client by two transaction and server by one - * Server will offer rollback by proving txn of its latest transaction. - * Client will have same txn but different pin, because it was advancing out of sync with server. - * Client should produce and error by reporting unknown txn from server. - */ - @Test - public void testOutOfSyncClient() throws Exception { - int size = 10000; - try (JournalWriter remote = getFactory().writer(Quote.class, "remote", 2 * size)) { - server.publish(remote); - server.start(); - - try { - - final CountDownLatch commitLatch1 = new CountDownLatch(1); - client.subscribe(Quote.class, "remote", "local", 2 * size, new JournalListener() { - @Override - public void onCommit() { - commitLatch1.countDown(); - } - - @Override - public void onEvent(int event) { - - } - }); - client.start(); - - TestUtils.generateQuoteData(remote, size); - - Assert.assertTrue(commitLatch1.await(5, TimeUnit.SECONDS)); - - client.halt(); - - try (Journal local = getFactory().reader(Quote.class, "local")) { - TestUtils.assertDataEquals(remote, local); - } - - TestUtils.generateQuoteData(remote, 10000, remote.getMaxTimestamp()); - remote.commit(); - - try (JournalWriter localW = getFactory().writer(Quote.class, "local")) { - TestUtils.generateQuoteData(localW, 10000, localW.getMaxTimestamp()); - localW.commit(); - - TestUtils.generateQuoteData(localW, 10000, localW.getMaxTimestamp()); - localW.commit(); - } - - final CountDownLatch errorCountDown = new CountDownLatch(1); - - client = new JournalClient(new ClientConfig("localhost"), getFactory()); - client.subscribe(Quote.class, "remote", "local", 2 * size, new JournalListener() { - @Override - public void onCommit() { - } - - @Override - public void onEvent(int event) { - errorCountDown.countDown(); - } - }); - client.start(); - - Assert.assertTrue(errorCountDown.await(5, TimeUnit.SECONDS)); - - client.halt(); - } finally { - server.halt(); - } - } - } - - @Test - @Ignore - // this is failing intermittently, replication is up for rewrite, cant be bothered fixing badly designed code - public void testOutOfSyncServerSide() throws Exception { - int size = 10000; - try (JournalWriter remote = getFactory().writer(Quote.class, "remote", 2 * size)) { - server.publish(remote); - server.start(); - - try { - - final AtomicInteger serverErrors = new AtomicInteger(); - final AtomicInteger commits = new AtomicInteger(); - client = new JournalClient(new ClientConfig("localhost"), getFactory(), null, evt -> { - if (evt == JournalClientEvents.EVT_SERVER_DIED) { - serverErrors.incrementAndGet(); - } - }); - client.subscribe(Quote.class, "remote", "local", 2 * size, new JournalListener() { - @Override - public void onCommit() { - commits.incrementAndGet(); - } - - @Override - public void onEvent(int event) { - - } - }); - client.start(); - - TestUtils.generateQuoteData(remote, size); - - TestUtils.assertCounter(commits, 1, 1, TimeUnit.SECONDS); - - client.halt(); - - try (Journal local = getFactory().reader(Quote.class, "local")) { - TestUtils.assertDataEquals(remote, local); - } - - // ------------------------------- - - TestUtils.generateQuoteData(remote, 10000, remote.getMaxTimestamp()); - remote.commit(); - TestUtils.generateQuoteData(remote, 10000, remote.getMaxTimestamp()); - remote.commit(); - TestUtils.generateQuoteData(remote, 10000, remote.getMaxTimestamp()); - remote.commit(); - - try (JournalWriter localW = getFactory().writer(Quote.class, "local")) { - - TestUtils.generateQuoteData(localW, 10000, localW.getMaxTimestamp()); - localW.commit(); - - TestUtils.generateQuoteData(localW, 10000, localW.getMaxTimestamp()); - localW.commit(); - } - - final AtomicInteger errorCounter = new AtomicInteger(); - client = new JournalClient(new ClientConfig("localhost"), getFactory(), null, evt -> { - if (evt == JournalClientEvents.EVT_SERVER_DIED) { - serverErrors.incrementAndGet(); - } - }); - client.subscribe(Quote.class, "remote", "local", 2 * size, new JournalListener() { - @Override - public void onCommit() { - commits.incrementAndGet(); - } - - @Override - public void onEvent(int event) { - errorCounter.incrementAndGet(); - System.out.println("EV: " + event); - } - }); - client.start(); - - TestUtils.assertCounter(commits, 1, 1, TimeUnit.SECONDS); - TestUtils.assertCounter(errorCounter, 1, 1, TimeUnit.SECONDS); - - client.halt(); - - Assert.assertEquals(0, serverErrors.get()); - - } finally { - server.halt(); - } - } - } - - @Test - public void testResubscribeAfterBadSubscription() throws Exception { - // check that bad subscription doesn't cause dupe check to go haywire - - int size = 1000; - - try (JournalWriter origin = getFactory().writer(Quote.class, "origin")) { - TestUtils.generateQuoteData(origin, size); - server.publish(origin); - - server.start(); - try { - - getFactory().writer(new JournalConfigurationBuilder().$("local").$int("x").$()).close(); - - final CountDownLatch terminated = new CountDownLatch(1); - final AtomicInteger serverDied = new AtomicInteger(); - JournalClient client = new JournalClient(new ClientConfig("localhost"), getFactory(), null, evt -> { - switch (evt) { - case JournalClientEvents.EVT_TERMINATED: - terminated.countDown(); - break; - case JournalClientEvents.EVT_SERVER_DIED: - serverDied.incrementAndGet(); - break; - default: - break; - } - }); - - client.start(); - - try { - final CountDownLatch incompatible = new CountDownLatch(1); - client.subscribe(Quote.class, "origin", "local", new JournalListener() { - @Override - public void onCommit() { - - } - - @Override - public void onEvent(int event) { - if (event == JournalEvents.EVT_JNL_INCOMPATIBLE) { - incompatible.countDown(); - } - } - }); - - Assert.assertTrue(incompatible.await(500, TimeUnit.SECONDS)); - - // delete incompatible journal - getFactory().delete("local"); - - - // subscribe again and have client create compatible journal from server's metadata - final AtomicInteger errorCount = new AtomicInteger(); - final CountDownLatch commit = new CountDownLatch(1); - client.subscribe(Quote.class, "origin", "local", new JournalListener() { - @Override - public void onCommit() { - commit.countDown(); - } - - @Override - public void onEvent(int event) { - if (event != JournalEvents.EVT_JNL_SUBSCRIBED) { - errorCount.incrementAndGet(); - } - } - }); - - Assert.assertTrue(commit.await(30, TimeUnit.SECONDS)); - Assert.assertEquals(0, errorCount.get()); - } finally { - client.halt(); - } - - Assert.assertTrue(terminated.await(5, TimeUnit.SECONDS)); - Assert.assertEquals(0, serverDied.get()); - - try (Journal r = getFactory().reader("local")) { - Assert.assertEquals(size, r.size()); - } - } finally { - server.halt(); - } - } - } - - @Test - @Ignore - public void testResubscribeAfterUnsubscribe() { - //todo: test that it is possible to re-subscribe after unsubscribe call - Assert.fail(); - } - - @Test - public void testServerIdleStartStop() throws Exception { - try (JournalWriter remote = getFactory().writer(Quote.class, "remote")) { - server.publish(remote); - server.start(); - client.subscribe(Quote.class, "remote", "local"); - client.start(); - Thread.sleep(100); - server.halt(); - Assert.assertFalse(server.isRunning()); - } - } - - @Test - public void testServerStartStop() throws Exception { - server.start(); - server.halt(); - Assert.assertFalse(server.isRunning()); - } - - @Test - public void testSingleJournalSync() throws Exception { - int size = 100000; - try (JournalWriter remote = getFactory().writer(Quote.class, "remote", 2 * size)) { - server.publish(remote); - server.start(); - - try { - final CountDownLatch latch = new CountDownLatch(1); - client.subscribe(Quote.class, "remote", "local", 2 * size, new JournalListener() { - @Override - public void onCommit() { - latch.countDown(); - } - - @Override - public void onEvent(int event) { - - } - }); - client.start(); - - TestUtils.generateQuoteData(remote, size); - - latch.await(); - - client.halt(); - } finally { - server.halt(); - } - - try (Journal local = getFactory().reader(Quote.class, "local")) { - TestUtils.assertDataEquals(remote, local); - } - } - } - - @Test - @Ignore - public void testSubscribeCopyOnTheFly() { - // todo: test that server can multiplex journal when needed - Assert.fail(); - } - - @Test - public void testSubscribeIncompatible() throws Exception { - int size = 10000; - - try (JournalWriter origin = getFactory().writer(Quote.class, "origin")) { - TestUtils.generateQuoteData(origin, size); - - try (JournalWriter remote = getFactory().writer(Quote.class, "remote")) { - - server.publish(remote); - - server.start(); - try { - - - remote.append(origin.query().all().asResultSet().subset(0, 1000)); - remote.commit(); - - - getFactory().writer(new JournalConfigurationBuilder().$("local").$int("x").$()).close(); - - final CountDownLatch terminated = new CountDownLatch(1); - JournalClient client = new JournalClient(new ClientConfig("localhost"), getFactory(), null, evt -> { - - if (evt == JournalClientEvents.EVT_TERMINATED) { - terminated.countDown(); - } - }); - - client.start(); - - - final CountDownLatch incompatible = new CountDownLatch(1); - try { - - client.subscribe(Quote.class, "remote", "local", new JournalListener() { - @Override - public void onCommit() { - - } - - @Override - public void onEvent(int event) { - if (event == JournalEvents.EVT_JNL_INCOMPATIBLE) { - incompatible.countDown(); - } - } - }); - - Assert.assertTrue(incompatible.await(500, TimeUnit.SECONDS)); - - remote.append(origin.query().all().asResultSet().subset(1000, 2000)); - remote.commit(); - - } finally { - client.halt(); - } - - Assert.assertTrue(terminated.await(5, TimeUnit.SECONDS)); - } finally { - server.halt(); - } - } - - } - } - - @Test - @SuppressWarnings("unchecked") - public void testSubscribeIncompatibleWriter() throws Exception { - int size = 10000; - - try (JournalWriter origin = getFactory().writer(Quote.class, "origin")) { - TestUtils.generateQuoteData(origin, size); - - try (JournalWriter remote = getFactory().writer(Quote.class, "remote")) { - - server.publish(remote); - - server.start(); - try { - remote.append(origin.query().all().asResultSet().subset(0, 1000)); - remote.commit(); - - - try (JournalWriter writer = getFactory().writer(new JournalConfigurationBuilder().$("local").$int("x").$())) { - - final CountDownLatch terminated = new CountDownLatch(1); - final AtomicInteger serverErrors = new AtomicInteger(); - JournalClient client = new JournalClient(new ClientConfig("localhost"), getFactory(), null, evt -> { - - if (evt == JournalClientEvents.EVT_TERMINATED) { - terminated.countDown(); - } - - if (evt == JournalClientEvents.EVT_SERVER_DIED) { - serverErrors.incrementAndGet(); - } - }); - - client.start(); - - - final CountDownLatch incompatible = new CountDownLatch(1); - try { - - client.subscribe(new JournalKey<>("remote"), writer, new JournalListener() { - @Override - public void onCommit() { - - } - - @Override - public void onEvent(int event) { - if (event == JournalEvents.EVT_JNL_INCOMPATIBLE) { - incompatible.countDown(); - } - } - }); - - Assert.assertTrue(incompatible.await(500, TimeUnit.SECONDS)); - - remote.append(origin.query().all().asResultSet().subset(1000, 2000)); - remote.commit(); - - } finally { - client.halt(); - } - - Assert.assertTrue(terminated.await(5, TimeUnit.SECONDS)); - Assert.assertEquals(0, serverErrors.get()); - } - } finally { - server.halt(); - } - } - } - } - - @Test - public void testSubscribeOnTheFly() throws Exception { - int size = 5000; - - try (JournalWriter origin = getFactory().writer(Quote.class, "origin")) { - TestUtils.generateQuoteData(origin, size); - - try (JournalWriter remote1 = getFactory().writer(Quote.class, "remote1")) { - try (JournalWriter remote2 = getFactory().writer(Quote.class, "remote2")) { - - server.publish(remote1); - server.publish(remote2); - - server.start(); - try { - remote1.append(origin.query().all().asResultSet().subset(0, 1000)); - remote1.commit(); - - remote2.append(origin.query().all().asResultSet().subset(0, 1000)); - remote2.commit(); - - final AtomicInteger counter = new AtomicInteger(); - JournalClient client = new JournalClient(new ClientConfig("localhost"), getFactory()); - client.start(); - - try { - - client.subscribe(Quote.class, "remote1", "local1", new JournalListener() { - @Override - public void onCommit() { - counter.incrementAndGet(); - } - - @Override - public void onEvent(int event) { - - } - }); - - TestUtils.assertCounter(counter, 1, 2, TimeUnit.SECONDS); - - try (Journal r = getFactory().reader("local1")) { - Assert.assertEquals(1000, r.size()); - } - - client.subscribe(Quote.class, "remote2", "local2", new JournalListener() { - @Override - public void onCommit() { - counter.incrementAndGet(); - } - - @Override - public void onEvent(int event) { - - } - }); - - TestUtils.assertCounter(counter, 2, 2, TimeUnit.SECONDS); - - try (Journal r = getFactory().reader("local2")) { - Assert.assertEquals(1000, r.size()); - } - - } finally { - client.halt(); - } - } finally { - server.halt(); - } - } - } - - } - } - - @Test - public void testSubscribeTwice() throws Exception { - int size = 10000; - - try (JournalWriter origin = getFactory().writer(Quote.class, "origin")) { - TestUtils.generateQuoteData(origin, size); - - try (JournalWriter remote1 = getFactory().writer(Quote.class, "remote1")) { - try (JournalWriter remote2 = getFactory().writer(Quote.class, "remote2")) { - - server.publish(remote1); - server.publish(remote2); - - server.start(); - try { - - - remote1.append(origin.query().all().asResultSet().subset(0, 1000)); - remote1.commit(); - - remote2.append(origin.query().all().asResultSet().subset(0, 1000)); - remote2.commit(); - - final AtomicInteger counter = new AtomicInteger(); - final AtomicInteger errors = new AtomicInteger(); - JournalClient client = new JournalClient(new ClientConfig("localhost"), getFactory()); - client.start(); - - try { - - client.subscribe(Quote.class, "remote1", "local1", new JournalListener() { - @Override - public void onCommit() { - counter.incrementAndGet(); - } - - @Override - public void onEvent(int event) { - errors.incrementAndGet(); - } - }); - - TestUtils.assertCounter(counter, 1, 2, TimeUnit.SECONDS); - - try (Journal r = getFactory().reader("local1")) { - Assert.assertEquals(1000, r.size()); - } - - client.subscribe(Quote.class, "remote2", "local1", new JournalListener() { - @Override - public void onCommit() { - counter.incrementAndGet(); - } - - @Override - public void onEvent(int event) { - errors.incrementAndGet(); - } - }); - - TestUtils.assertCounter(counter, 1, 2, TimeUnit.SECONDS); - TestUtils.assertCounter(errors, 1, 2, TimeUnit.SECONDS); - - try (Journal r = getFactory().reader("local1")) { - Assert.assertEquals(1000, r.size()); - } - - } finally { - client.halt(); - } - } finally { - server.halt(); - } - } - } - - } - } - - @Test - public void testTwoClientSync() throws Exception { - int size = 10000; - try (JournalWriter origin = getFactory().writer(Quote.class, "origin")) { - TestUtils.generateQuoteData(origin, size); - - try (JournalWriter remote = getFactory().writer(Quote.class, "remote")) { - remote.append(origin.query().all().asResultSet().subset(0, 1000)); - remote.commit(); - - server.publish(remote); - server.start(); - - final AtomicInteger counter = new AtomicInteger(); - JournalClient client1 = new JournalClient(new ClientConfig("localhost"), getFactory()); - client1.subscribe(Quote.class, "remote", "local1", new JournalListener() { - @Override - public void onCommit() { - counter.incrementAndGet(); - } - - @Override - public void onEvent(int event) { - - } - }); - client1.start(); - - JournalClient client2 = new JournalClient(new ClientConfig("localhost"), getFactory()); - client2.subscribe(Quote.class, "remote", "local2", new JournalListener() { - @Override - public void onCommit() { - counter.incrementAndGet(); - } - - @Override - public void onEvent(int event) { - - } - }); - client2.start(); - - TestUtils.assertCounter(counter, 2, 2, TimeUnit.SECONDS); - client1.halt(); - - remote.append(origin.query().all().asResultSet().subset(1000, 1500)); - remote.commit(); - - TestUtils.assertCounter(counter, 3, 2, TimeUnit.SECONDS); - - LOG.info().$("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~").$(); - - - // this client should receive an update that gets it up to speed - // wait until this happens before adding more rows to remote - - final CountDownLatch waitForUpdate = new CountDownLatch(1); - - client1 = new JournalClient(new ClientConfig("localhost"), getFactory()); - client1.subscribe(Quote.class, "remote", "local1", new JournalListener() { - @Override - public void onCommit() { - counter.incrementAndGet(); - waitForUpdate.countDown(); - } - - @Override - public void onEvent(int event) { - - } - }); - client1.start(); - - waitForUpdate.await(2, TimeUnit.SECONDS); - - remote.append(origin.query().all().asResultSet().subset(1500, size)); - remote.commit(); - - TestUtils.assertCounter(counter, 6, 2, TimeUnit.SECONDS); - - try (Journal local1r = getFactory().reader(Quote.class, "local1")) { - Assert.assertEquals(size, local1r.size()); - } - - try (Journal local2r = getFactory().reader(Quote.class, "local2")) { - Assert.assertEquals(size, local2r.size()); - } - - client1.halt(); - client2.halt(); - server.halt(); - } - } - } - - @Test - public void testTwoJournalsSync() throws Exception { - int size = 10000; - try (JournalWriter remote1 = getFactory().writer(Quote.class, "remote1", 2 * size)) { - try (JournalWriter remote2 = getFactory().writer(TestEntity.class, "remote2", 2 * size)) { - server.publish(remote1); - server.publish(remote2); - server.start(); - - final CountDownLatch latch = new CountDownLatch(2); - client.subscribe(Quote.class, "remote1", "local1", 2 * size, new JournalListener() { - @Override - public void onCommit() { - latch.countDown(); - } - - @Override - public void onEvent(int event) { - - } - }); - - client.subscribe(TestEntity.class, "remote2", "local2", 2 * size, new JournalListener() { - @Override - public void onCommit() { - latch.countDown(); - } - - @Override - public void onEvent(int event) { - - } - }); - client.start(); - - TestUtils.generateQuoteData(remote1, size); - TestUtils.generateTestEntityData(remote2, size); - - latch.await(); - - client.halt(); - server.halt(); - - try (Journal local1 = getFactory().reader(Quote.class, "local1")) { - Assert.assertEquals("Local1 has wrong size", size, local1.size()); - } - - try (Journal local2 = getFactory().reader(TestEntity.class, "local2")) { - Assert.assertEquals("Remote2 has wrong size", size, remote2.size()); - Assert.assertEquals("Local2 has wrong size", size, local2.size()); - } - } - } - } - - @Test - @Ignore - public void testUnsubscribe() { - //todo: check that unsubscribe triggers correct event sequence - Assert.fail(); - } - - @Test - @Ignore - public void testUnsubscribeOnTheFly() { - //todo: test that unsubscribe on the fly does not impact existing data flow - Assert.fail(); - } - - @Test - @Ignore - public void testUnsubscribeReconnectBehaviour() { - // todo: test that unsubscribed journal does not cause re-subscription on client failover - Assert.fail(); - } - - @Test - public void testWriterShutdown() throws Exception { - int size = 10000; - try (JournalWriter remote = getFactory().writer(Quote.class, "remote", 2 * size)) { - server.publish(remote); - server.start(); - - client.subscribe(Quote.class, "remote", "local", 2 * size); - client.start(); - - TestUtils.generateQuoteData(remote, size, 0); - } - - client.halt(); - server.halt(); - } -} diff --git a/core/src/test/java/com/questdb/net/ha/JournalEventBridgeTest.java b/core/src/test/java/com/questdb/net/ha/JournalEventBridgeTest.java deleted file mode 100644 index 1de4088ae..000000000 --- a/core/src/test/java/com/questdb/net/ha/JournalEventBridgeTest.java +++ /dev/null @@ -1,146 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2019 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.net.ha.bridge.JournalEventBridge; -import com.questdb.net.ha.bridge.JournalEventHandler; -import com.questdb.net.ha.bridge.JournalEventProcessor; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; - -import java.util.concurrent.*; - -@Ignore -public class JournalEventBridgeTest { - @Test - public void testStartStop() { - JournalEventBridge bridge = new JournalEventBridge(2, TimeUnit.SECONDS); - for (int i = 0; i < 10000; i++) { - bridge.publish(10, System.currentTimeMillis()); - } - } - - @Test - public void testTwoPublishersThreeConsumers() throws Exception { - ExecutorService service = Executors.newCachedThreadPool(); - final JournalEventBridge bridge = new JournalEventBridge(50, TimeUnit.MILLISECONDS); - final Future[] publishers = new Future[2]; - final Handler[] consumers = new Handler[3]; - final int batchSize = 1000; - - final CyclicBarrier barrier = new CyclicBarrier(publishers.length + consumers.length); - final CountDownLatch latch = new CountDownLatch(publishers.length + consumers.length); - - for (int i = 0; i < publishers.length; i++) { - final int index = i; - publishers[i] = service.submit(() -> { - int count = 0; - try { - barrier.await(); - for (int k = 0; k < batchSize; k++) { - long ts = System.nanoTime(); - bridge.publish(index, ts); - count++; - } - } catch (Exception e) { - e.printStackTrace(); - } finally { - latch.countDown(); - } - - return count; - }); - } - - - for (int i = 0; i < consumers.length; i++) { - final JournalEventProcessor processor = new JournalEventProcessor(bridge); - final Handler handler = new Handler(i); - consumers[i] = handler; - service.submit(() -> { - try { - barrier.await(); - while (true) { - if (!processor.process(handler, true)) { - break; - } - } - } catch (InterruptedException | BrokenBarrierException e) { - e.printStackTrace(); - } finally { - latch.countDown(); - } - }); - } - -// service.submit(new Runnable() { -// @Override -// public void run() { -// try { -// barrier.await(); -// for (int i = 0; i < 1000; i++) { -// Sequence sequence = bridge.createAgentSequence(); -// LockSupport.parkNanos(TimeUnit.MICROSECONDS.toNanos(10)); -// bridge.removeAgentSequence(sequence); -// } -// } catch (InterruptedException | BrokenBarrierException e) { -// e.printStackTrace(); -// } finally { -// latch.countDown(); -// } -// } -// }); - - latch.await(); - - for (Future f : publishers) { - Assert.assertEquals(batchSize, f.get()); - } - - Assert.assertEquals(batchSize, consumers[0].getCounter()); - Assert.assertEquals(batchSize, consumers[1].getCounter()); - Assert.assertEquals(0, consumers[2].getCounter()); - } - - private class Handler implements JournalEventHandler { - private final int index; - private int counter; - - private Handler(int index) { - this.index = index; - } - - public int getCounter() { - return counter; - } - - @Override - public void handle(int journalIndex) { - if (journalIndex == index) { - counter++; - } - } - } -} diff --git a/core/src/test/java/com/questdb/net/ha/JournalLagTest.java b/core/src/test/java/com/questdb/net/ha/JournalLagTest.java deleted file mode 100644 index 444dac8a5..000000000 --- a/core/src/test/java/com/questdb/net/ha/JournalLagTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.std.time.DateFormatUtils; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class JournalLagTest extends AbstractJournalTest { - - @Before - @Override - public void setUp() throws Exception { - super.setUp(); - TestUtils.generateQuoteData(origin, 500, DateFormatUtils.parseDateTime("2013-02-01T00:00:00.000Z"), 100); - TestUtils.generateQuoteData(origin, 500, DateFormatUtils.parseDateTime("2013-02-01T01:00:00.000Z"), 100); - TestUtils.generateQuoteData(origin, 500, DateFormatUtils.parseDateTime("2013-02-01T13:00:00.000Z"), 100); - TestUtils.generateQuoteData(origin, 500, DateFormatUtils.parseDateTime("2013-05-01T00:00:00.000Z"), 100); - } - - @Test - public void testLagDetach() throws Exception { - master.append(origin.query().all().asResultSet().subset(0, 500)); - master.mergeAppend(origin.query().all().asResultSet().subset(500, 600)); - master.commit(); - - executeSequence(true); - master.removeIrregularPartition(); - master.commit(); - executeSequence(true); - } - - @Test - public void testLagOnlyPropagation() throws Exception { - master.append(origin.query().all().asResultSet().subset(0, 500)); - master.mergeAppend(origin.query().all().asResultSet().subset(500, 600)); - master.commit(); - String lagName = master.getIrregularPartition().getName(); - - executeSequence(true); - - master.mergeAppend(origin.query().all().asResultSet().subset(600, 700)); - master.commit(); - Assert.assertEquals(lagName, master.getIrregularPartition().getName()); - - executeSequence(true); - } -} diff --git a/core/src/test/java/com/questdb/net/ha/JournalServerAgentTest.java b/core/src/test/java/com/questdb/net/ha/JournalServerAgentTest.java deleted file mode 100644 index 639709d15..000000000 --- a/core/src/test/java/com/questdb/net/ha/JournalServerAgentTest.java +++ /dev/null @@ -1,213 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.model.Quote; -import com.questdb.model.Trade; -import com.questdb.net.ha.comsumer.HugeBufferConsumer; -import com.questdb.net.ha.comsumer.JournalDeltaConsumer; -import com.questdb.net.ha.config.NetworkConfig; -import com.questdb.net.ha.config.ServerConfig; -import com.questdb.net.ha.model.Command; -import com.questdb.net.ha.model.IndexedJournal; -import com.questdb.net.ha.model.IndexedJournalKey; -import com.questdb.net.ha.producer.JournalClientStateProducer; -import com.questdb.net.ha.protocol.CommandConsumer; -import com.questdb.net.ha.protocol.CommandProducer; -import com.questdb.net.ha.protocol.commands.CharSequenceResponseConsumer; -import com.questdb.net.ha.protocol.commands.IntResponseConsumer; -import com.questdb.net.ha.protocol.commands.SetKeyRequestProducer; -import com.questdb.std.Chars; -import com.questdb.store.Journal; -import com.questdb.store.JournalWriter; -import com.questdb.test.tools.AbstractTest; -import com.questdb.test.tools.TestUtils; -import org.junit.*; -import org.junit.rules.TemporaryFolder; - -import java.net.InetSocketAddress; - -public class JournalServerAgentTest extends AbstractTest { - - @Rule - public final TemporaryFolder temp = new TemporaryFolder(); - private final CommandProducer commandProducer = new CommandProducer(); - private final CommandConsumer commandConsumer = new CommandConsumer(); - private final SetKeyRequestProducer setKeyRequestProducer = new SetKeyRequestProducer(); - private final CharSequenceResponseConsumer charSequenceResponseConsumer = new CharSequenceResponseConsumer(); - private final JournalClientStateProducer journalClientStateProducer = new JournalClientStateProducer(); - private final IntResponseConsumer intResponseConsumer = new IntResponseConsumer(); - private MockByteChannel channel; - private JournalWriter quoteWriter; - private JournalWriter tradeWriter; - private JournalServer server; - private JournalServerAgent agent; - private HugeBufferConsumer hugeBufferConsumer; - - @Before - public void setUp() throws Exception { - channel = new MockByteChannel(); - quoteWriter = getFactory().writer(Quote.class); - tradeWriter = getFactory().writer(Trade.class); - ServerConfig config = new ServerConfig() {{ - setHeartbeatFrequency(100); - setEnableMultiCast(false); - }}; - - server = new JournalServer(config, getFactory()); - server.publish(quoteWriter); - agent = new JournalServerAgent(server, new InetSocketAddress(NetworkConfig.DEFAULT_DATA_PORT), null); - hugeBufferConsumer = new HugeBufferConsumer(temp.newFile()); - } - - @After - public void tearDown() { - quoteWriter.close(); - tradeWriter.close(); - server.halt(); - agent.close(); - hugeBufferConsumer.free(); - } - - @Test - public void testIncrementalInteraction() throws Exception { - try (JournalWriter origin = getFactory().writer(Quote.class, "origin")) { - TestUtils.generateQuoteData(origin, 200); - - server.start(); - try (JournalWriter quoteClientWriter = getFactory().writer(Quote.class, "client")) { - - JournalDeltaConsumer quoteDeltaConsumer = new JournalDeltaConsumer(quoteClientWriter); - - // send quote journal key - commandProducer.write(channel, Command.ADD_KEY_CMD); - setKeyRequestProducer.write(channel, new IndexedJournalKey(0, quoteWriter.getMetadata().getKey())); - agent.process(channel); - charSequenceResponseConsumer.read(channel); - TestUtils.assertEquals("OK", charSequenceResponseConsumer.getValue()); - hugeBufferConsumer.read(channel); - - // send quote state - commandProducer.write(channel, Command.DELTA_REQUEST_CMD); - journalClientStateProducer.write(channel, new IndexedJournal(0, quoteClientWriter)); - agent.process(channel); - charSequenceResponseConsumer.read(channel); - TestUtils.assertEquals("OK", charSequenceResponseConsumer.getValue()); - - quoteWriter.append(origin.query().all().asResultSet().subset(0, 100)); - quoteWriter.commit(); - - commandProducer.write(channel, Command.CLIENT_READY_CMD); - agent.process(channel); - - commandConsumer.read(channel); - Assert.assertEquals(Command.JOURNAL_DELTA_CMD, commandConsumer.getCommand()); - - Assert.assertEquals(0, intResponseConsumer.getValue(channel)); - quoteDeltaConsumer.read(channel); - Assert.assertEquals(100, quoteClientWriter.size()); - - commandConsumer.read(channel); - Assert.assertEquals(Command.SERVER_READY_CMD, commandConsumer.getCommand()); - - quoteWriter.append(origin.query().all().asResultSet().subset(100, 200)); - quoteWriter.commit(); - - // send quote state - commandProducer.write(channel, Command.DELTA_REQUEST_CMD); - journalClientStateProducer.write(channel, new IndexedJournal(0, quoteClientWriter)); - agent.process(channel); - charSequenceResponseConsumer.read(channel); - TestUtils.assertEquals("OK", charSequenceResponseConsumer.getValue()); - - commandProducer.write(channel, Command.CLIENT_READY_CMD); - agent.process(channel); - - commandConsumer.read(channel); - Assert.assertEquals(Command.JOURNAL_DELTA_CMD, commandConsumer.getCommand()); - - Assert.assertEquals(0, intResponseConsumer.getValue(channel)); - quoteDeltaConsumer.read(channel); - Assert.assertEquals(200, quoteClientWriter.size()); - - commandConsumer.read(channel); - Assert.assertEquals(Command.SERVER_READY_CMD, commandConsumer.getCommand()); - } - } - } - - @Test - public void testJournalIndexCorrectness() throws Exception { - server.publish(tradeWriter); - server.start(); - - try (Journal quoteClientWriter = getFactory().writer(Quote.class, "client")) { - - // send quote journal key -// commandProducer.write(channel, Command.ADD_KEY_CMD); -// setKeyRequestProducer.write(channel, new IndexedJournalKey(3, quoteWriter.getKey())); -// agent.process(channel); -// charSequenceResponseConsumer.reset(); -// charSequenceResponseConsumer.read(channel); -// Assert.assertTrue(charSequenceResponseConsumer.isComplete()); -// Assert.assertEquals("Journal index is too large. Max 1", charSequenceResponseConsumer.getValue()); - - - commandProducer.write(channel, Command.ADD_KEY_CMD); - setKeyRequestProducer.write(channel, new IndexedJournalKey(0, quoteWriter.getMetadata().getKey())); - agent.process(channel); - charSequenceResponseConsumer.read(channel); - TestUtils.assertEquals("OK", charSequenceResponseConsumer.getValue()); - hugeBufferConsumer.read(channel); - - commandProducer.write(channel, Command.DELTA_REQUEST_CMD); - journalClientStateProducer.write(channel, new IndexedJournal(1, quoteClientWriter)); - agent.process(channel); - charSequenceResponseConsumer.read(channel); - TestUtils.assertEquals("Journal index does not match key request", charSequenceResponseConsumer.getValue()); - - commandProducer.write(channel, Command.DELTA_REQUEST_CMD); - journalClientStateProducer.write(channel, new IndexedJournal(0, quoteClientWriter)); - agent.process(channel); - charSequenceResponseConsumer.read(channel); - TestUtils.assertEquals("OK", charSequenceResponseConsumer.getValue()); - } - } - - @Test - public void testSetKeyRequestResponse() throws Exception { - commandProducer.write(channel, Command.ADD_KEY_CMD); - setKeyRequestProducer.write(channel, new IndexedJournalKey(0, quoteWriter.getMetadata().getKey())); - agent.process(channel); - charSequenceResponseConsumer.read(channel); - TestUtils.assertEquals("OK", charSequenceResponseConsumer.getValue()); - hugeBufferConsumer.read(channel); - - commandProducer.write(channel, Command.ADD_KEY_CMD); - setKeyRequestProducer.write(channel, new IndexedJournalKey(0, tradeWriter.getMetadata().getKey())); - agent.process(channel); - charSequenceResponseConsumer.read(channel); - Assert.assertTrue(Chars.startsWith(charSequenceResponseConsumer.getValue(), "Requested key not exported")); - } -} diff --git a/core/src/test/java/com/questdb/net/ha/JournalSymbolTableTest.java b/core/src/test/java/com/questdb/net/ha/JournalSymbolTableTest.java deleted file mode 100644 index d20bb3fa1..000000000 --- a/core/src/test/java/com/questdb/net/ha/JournalSymbolTableTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.model.Quote; -import com.questdb.net.ha.comsumer.JournalClientStateConsumer; -import com.questdb.net.ha.comsumer.JournalSymbolTableConsumer; -import com.questdb.net.ha.model.IndexedJournal; -import com.questdb.net.ha.producer.JournalClientStateProducer; -import com.questdb.net.ha.producer.JournalSymbolTableProducer; -import com.questdb.std.ex.JournalNetworkException; -import com.questdb.store.JournalWriter; -import com.questdb.test.tools.AbstractTest; -import com.questdb.test.tools.TestUtils; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class JournalSymbolTableTest extends AbstractTest { - - private final JournalClientStateProducer journalClientStateProducer = new JournalClientStateProducer(); - private final JournalClientStateConsumer journalClientStateConsumer = new JournalClientStateConsumer(); - private JournalWriter origin; - private JournalWriter master; - private JournalWriter slave; - private MockByteChannel channel; - private JournalSymbolTableProducer journalSymbolTableProducer; - private JournalSymbolTableConsumer journalSymbolTableConsumer; - - @Before - public void setUp() throws Exception { - origin = getFactory().writer(Quote.class, "origin"); - master = getFactory().writer(Quote.class, "master"); - slave = getFactory().writer(Quote.class, "slave"); - - channel = new MockByteChannel(); - - journalSymbolTableProducer = new JournalSymbolTableProducer(master); - journalSymbolTableConsumer = new JournalSymbolTableConsumer(slave); - - origin.append(new Quote().setSym("AB").setEx("EX1").setMode("M1")); - origin.append(new Quote().setSym("CD").setEx("EX2").setMode("M2")); - origin.append(new Quote().setSym("EF").setEx("EX3").setMode("M2")); - origin.append(new Quote().setSym("GH").setEx("EX3").setMode("M3")); - } - - @After - public void tearDown() { - origin.close(); - master.close(); - slave.close(); - } - - @Test - public void testConsumerEqualToProducer() throws Exception { - master.append(origin); - master.commit(false, 101L, 10); - slave.append(origin); - slave.commit(false, 101L, 10); - executeSequence(false); - } - - @Test - public void testConsumerLargerThanProducer() throws Exception { - slave.append(origin); - slave.commit(false, 101L, 10); - master.append(origin.query().all().asResultSet().subset(0, 3)); - master.commit(false, 101L, 10); - executeSequence(false); - } - - @Test - public void testConsumerSmallerThanProducer() throws Exception { - master.append(origin.query().all().asResultSet().subset(0, 2)); - master.commit(false, 101L, 10); - master.append(origin.query().all().asResultSet().subset(2, 4)); - master.commit(false, 102L, 20); - - slave.append(origin.query().all().asResultSet().subset(0, 2)); - slave.commit(false, 101L, 10); - executeSequence(true); - } - - @Test - public void testEmptyConsumerAndPopulatedProducer() throws Exception { - master.append(origin); - master.commit(); - executeSequence(true); - } - - @Test - public void testEmptyConsumerAndProducer() throws Exception { - executeSequence(false); - } - - private void executeSequence(boolean expectContent) throws JournalNetworkException { - journalClientStateProducer.write(channel, new IndexedJournal(0, slave)); - journalClientStateConsumer.read(channel); - - journalSymbolTableProducer.configure(master.find(journalClientStateConsumer.getValue().getTxn(), journalClientStateConsumer.getValue().getTxPin())); - Assert.assertEquals(expectContent, journalSymbolTableProducer.hasContent()); - if (expectContent) { - journalSymbolTableProducer.write(channel); - journalSymbolTableConsumer.read(channel); - TestUtils.compareSymbolTables(master, slave); - } - } -} diff --git a/core/src/test/java/com/questdb/net/ha/JournalTest.java b/core/src/test/java/com/questdb/net/ha/JournalTest.java deleted file mode 100644 index 50c2ac6c9..000000000 --- a/core/src/test/java/com/questdb/net/ha/JournalTest.java +++ /dev/null @@ -1,150 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.model.Quote; -import com.questdb.std.time.DateFormatUtils; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class JournalTest extends AbstractJournalTest { - - @Before - @Override - public void setUp() throws Exception { - super.setUp(); - TestUtils.generateQuoteData(origin, 1000); - } - - @Test - public void testConsumerEqualToProducer() throws Exception { - master.append(origin); - master.commit(false, 101L, 10); - slave.append(origin); - slave.commit(false, 101L, 10); - executeSequence(false); - } - - @Test - public void testConsumerLargerThanProducer() throws Exception { - master.append(origin.query().all().asResultSet().subset(0, 550)); - master.commit(false, 101L, 10); - slave.append(origin); - slave.commit(false, 101L, 10); - executeSequence(false); - } - - @Test - public void testConsumerPartitionEdge() throws Exception { - origin.truncate(); - - TestUtils.generateQuoteData(origin, 500, DateFormatUtils.parseDateTime("2013-10-01T00:00:00.000Z")); - TestUtils.generateQuoteData(origin, 500, DateFormatUtils.parseDateTime("2013-11-01T00:00:00.000Z")); - TestUtils.generateQuoteData(origin, 500, DateFormatUtils.parseDateTime("2013-12-01T00:00:00.000Z")); - - master.append(origin.query().all().asResultSet().subset(0, 500)); - master.commit(false, 101L, 10); - master.append(origin.query().all().asResultSet().subset(500, 1500)); - master.commit(false, 102L, 20); - slave.append(origin.query().all().asResultSet().subset(0, 500)); - slave.commit(false, 101L, 10); - Assert.assertEquals(1, slave.getPartitionCount()); - executeSequence(true); - } - - @Test - public void testConsumerReset() throws Exception { - master.append(origin.query().all().asResultSet().subset(0, 200)); - master.commit(false, 101L, 10); - master.append(origin.query().all().asResultSet().subset(200, 550)); - master.commit(false, 102L, 20); - slave.append(origin.query().all().asResultSet().subset(0, 200)); - slave.commit(false, 101L, 10); - executeSequence(true); - master.append(origin.query().all().asResultSet().subset(550, 1000)); - master.commit(false, 103L, 30); - executeSequence(true); - } - - @Test - public void testConsumerSmallerThanProducer() throws Exception { - master.append(origin.query().all().asResultSet().subset(0, 655)); - master.commit(false, 101L, 10); - master.append(origin.query().all().asResultSet().subset(655, (int) origin.size())); - master.commit(false, 102L, 20); - - slave.append(origin.query().all().asResultSet().subset(0, 655)); - slave.commit(false, 101L, 10); - Assert.assertEquals(655, slave.size()); - executeSequence(true); - } - - @Test - public void testEmptyConsumerAndPopulatedProducer() throws Exception { - master.append(origin); - master.commit(); - executeSequence(true); - Assert.assertEquals(1000, slave.size()); - } - - @Test - public void testEmptyConsumerAndProducer() throws Exception { - executeSequence(false); - } - - @Test - public void testEmptyPartitionAdd() throws Exception { - master.append(origin); - master.getAppendPartition(DateFormatUtils.parseDateTime("2013-12-01T00:00:00.000Z")); - master.append(new Quote().setTimestamp(DateFormatUtils.parseDateTime("2014-01-01T00:00:00.000Z"))); - master.commit(); - executeSequence(true); - Assert.assertEquals(master.getPartitionCount(), slave.getPartitionCount()); - } - - @Test - public void testLagConsumerSmallerThanProducer() throws Exception { - master.append(origin.query().all().asResultSet().subset(0, 350)); - master.mergeAppend(origin.query().all().asResultSet().subset(350, 600)); - master.commit(); - executeSequence(true); - } - - @Test - public void testLagReplace() throws Exception { - master.append(origin.query().all().asResultSet().subset(0, 350)); - master.mergeAppend(origin.query().all().asResultSet().subset(350, 600)); - master.commit(false, 101L, 10); - - slave.append(origin.query().all().asResultSet().subset(0, 350)); - slave.mergeAppend(origin.query().all().asResultSet().subset(350, 600)); - slave.commit(false, 101L, 10); - - master.mergeAppend(origin.query().all().asResultSet().subset(600, 1000)); - master.commit(false, 102L, 20); - executeSequence(true); - } -} diff --git a/core/src/test/java/com/questdb/net/ha/LinkedJournalSymbolTableTest.java b/core/src/test/java/com/questdb/net/ha/LinkedJournalSymbolTableTest.java deleted file mode 100644 index 2cdd13539..000000000 --- a/core/src/test/java/com/questdb/net/ha/LinkedJournalSymbolTableTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.model.RDFNode; -import com.questdb.net.ha.comsumer.JournalClientStateConsumer; -import com.questdb.net.ha.comsumer.JournalSymbolTableConsumer; -import com.questdb.net.ha.model.IndexedJournal; -import com.questdb.net.ha.producer.JournalClientStateProducer; -import com.questdb.net.ha.producer.JournalSymbolTableProducer; -import com.questdb.std.ex.JournalNetworkException; -import com.questdb.store.JournalWriter; -import com.questdb.test.tools.AbstractTest; -import com.questdb.test.tools.TestUtils; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class LinkedJournalSymbolTableTest extends AbstractTest { - - private final JournalClientStateProducer journalClientStateProducer = new JournalClientStateProducer(); - private final JournalClientStateConsumer journalClientStateConsumer = new JournalClientStateConsumer(); - private JournalWriter origin; - private JournalWriter master; - private JournalWriter slave; - private MockByteChannel channel; - private JournalSymbolTableProducer journalSymbolTableProducer; - private JournalSymbolTableConsumer journalSymbolTableConsumer; - - @Before - public void setUp() throws Exception { - origin = getFactory().writer(RDFNode.class, "origin"); - master = getFactory().writer(RDFNode.class, "master"); - slave = getFactory().writer(RDFNode.class, "slave"); - - channel = new MockByteChannel(); - - journalSymbolTableProducer = new JournalSymbolTableProducer(master); - journalSymbolTableConsumer = new JournalSymbolTableConsumer(slave); - - origin.append(new RDFNode().setObj("O1").setSubj("S1")); - origin.append(new RDFNode().setObj("O2").setSubj("S1")); - origin.append(new RDFNode().setObj("O3").setSubj("S2")); - origin.append(new RDFNode().setObj("S2").setSubj("S1")); - } - - @After - public void tearDown() { - origin.close(); - master.close(); - slave.close(); - } - - @Test - public void testSameAsSymbolTable() throws Exception { - master.append(origin.query().all().asResultSet().subset(0, 2)); - master.commit(false, 101L, 10); - - master.append(origin.query().all().asResultSet().subset(2, 4)); - master.commit(false, 102L, 20); - - slave.append(origin.query().all().asResultSet().subset(0, 2)); - slave.commit(false, 101L, 10); - executeSequence(true); - } - - private void executeSequence(boolean expectContent) throws JournalNetworkException { - journalClientStateProducer.write(channel, new IndexedJournal(0, slave)); - journalClientStateConsumer.read(channel); - -// journalSymbolTableProducer.configure(journalClientStateConsumer.getValue()); - journalSymbolTableProducer.configure(master.find(journalClientStateConsumer.getValue().getTxn(), journalClientStateConsumer.getValue().getTxPin())); - - Assert.assertEquals(expectContent, journalSymbolTableProducer.hasContent()); - if (expectContent) { - journalSymbolTableProducer.write(channel); - journalSymbolTableConsumer.read(channel); - TestUtils.compareSymbolTables(master, slave); - } - } -} diff --git a/core/src/test/java/com/questdb/net/ha/MetadataReplicationTest.java b/core/src/test/java/com/questdb/net/ha/MetadataReplicationTest.java deleted file mode 100644 index d390145c9..000000000 --- a/core/src/test/java/com/questdb/net/ha/MetadataReplicationTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.model.Quote; -import com.questdb.net.ha.comsumer.HugeBufferConsumer; -import com.questdb.net.ha.producer.HugeBufferProducer; -import com.questdb.store.JournalWriter; -import com.questdb.store.factory.configuration.JournalConfiguration; -import com.questdb.store.factory.configuration.JournalMetadata; -import com.questdb.test.tools.AbstractTest; -import org.junit.Assert; -import org.junit.Test; - -import java.io.File; - -public class MetadataReplicationTest extends AbstractTest { - @Test - public void testReplication() { - - try (JournalWriter w = getFactory().writer(Quote.class)) { - - MockByteChannel channel = new MockByteChannel(); - HugeBufferProducer p = new HugeBufferProducer(new File(w.getLocation(), JournalConfiguration.FILE_NAME)); - HugeBufferConsumer c = new HugeBufferConsumer(new File(w.getLocation(), "_remote")); - p.write(channel); - c.read(channel); - - try (JournalWriter w2 = getFactory().writer( - new JournalMetadata<>(c.getHb(), "xyz") - )) { - - Assert.assertTrue(w.getMetadata().isCompatible(w2.getMetadata(), false)); - } - p.free(); - c.free(); - } catch (Exception e) { - e.printStackTrace(); - } - - } -} diff --git a/core/src/test/java/com/questdb/net/ha/MockByteChannel.java b/core/src/test/java/com/questdb/net/ha/MockByteChannel.java deleted file mode 100644 index e7669088b..000000000 --- a/core/src/test/java/com/questdb/net/ha/MockByteChannel.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import java.io.ByteArrayOutputStream; -import java.nio.ByteBuffer; -import java.nio.channels.ByteChannel; - -class MockByteChannel extends ByteArrayOutputStream implements ByteChannel { - - private int offset = 0; - private int cutoffIndex = -1; - private boolean interrupted = false; - - @Override - public boolean isOpen() { - return true; - } - - @Override - public int read(ByteBuffer dst) { - - if (offset == buf.length) { - return -1; - } - - if (interrupted) { - interrupted = false; - cutoffIndex = -1; - - return 0; - } - - // calculate cutoff point on first read - // this is to simulate non-blocking socket mode, where there is - // suddenly nothing to read from socket - - int oldOffset = offset; - while (dst.remaining() > 0 && offset < buf.length) { - - // if we reached cutoff point - stop filling in buffer - // subsequent call to read() method would return 0 - if (offset == cutoffIndex) { - interrupted = true; - break; - } - dst.put(buf[offset++]); - } - return offset - oldOffset; - } - - @Override - public String toString() { - return "MockByteChannel{" + - "offset=" + offset + - '}'; - } - - @Override - public void close() { - - } - - @Override - public int write(ByteBuffer src) { - int result = src.remaining(); - while (src.remaining() > 0) { - write(src.get()); - } - return result; - } -} diff --git a/core/src/test/java/com/questdb/net/ha/MulticastTest.java b/core/src/test/java/com/questdb/net/ha/MulticastTest.java deleted file mode 100644 index fece4bde1..000000000 --- a/core/src/test/java/com/questdb/net/ha/MulticastTest.java +++ /dev/null @@ -1,141 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.net.ha.config.ClientConfig; -import com.questdb.net.ha.config.ServerConfig; -import com.questdb.net.ha.config.ServerNode; -import com.questdb.net.ha.mcast.AbstractOnDemandSender; -import com.questdb.net.ha.mcast.OnDemandAddressPoller; -import com.questdb.net.ha.mcast.OnDemandAddressSender; -import com.questdb.std.ex.JournalNetworkException; -import com.questdb.test.tools.AbstractTest; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; - -import java.net.Inet6Address; -import java.net.InterfaceAddress; -import java.net.SocketException; -import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -@Ignore -public class MulticastTest extends AbstractTest { - - private boolean multicastDisabled; - - public MulticastTest() throws JournalNetworkException, SocketException { - multicastDisabled = isMulticastDisabled(); - } - - @Test - public void testAllNics() throws Exception { - if (multicastDisabled) { - return; - } - assertMulticast(); - } - - @Test - public void testDefaultNICBehaviour() throws Exception { - if (multicastDisabled) { - return; - } - assertMulticast(); - } - - @Test - public void testIPV4Forced() throws Exception { - if (multicastDisabled) { - return; - } - System.setProperty("java.net.preferIPv4Stack", "true"); - assertMulticast(); - } - - @Test - public void testIPv6() throws Exception { - if (multicastDisabled || !hasIPv6()) { - return; - } - - JournalServer server = new JournalServer(new ServerConfig() {{ - addNode(new ServerNode(0, "[0:0:0:0:0:0:0:0]")); - setHeartbeatFrequency(100); - }}, getFactory(), null, 0); - - final CountDownLatch connected = new CountDownLatch(1); - JournalClient client = new JournalClient(new ClientConfig(), getFactory(), null, evt -> { - if (evt == JournalClientEvents.EVT_CONNECTED) { - connected.countDown(); - } - }); - - - server.start(); - client.start(); - - connected.await(3, TimeUnit.SECONDS); - - client.halt(); - server.halt(); - } - - @Test - public void testLocalhostBehaviour() throws Exception { - - if (multicastDisabled) { - return; - } - - assertMulticast(); - } - - private static boolean isMulticastDisabled() throws JournalNetworkException, SocketException { - return !new ServerConfig().getMultiCastInterface(0).supportsMulticast(); - } - - private static boolean hasIPv6() throws JournalNetworkException { - List ifs = new ServerConfig().getMultiCastInterface(0).getInterfaceAddresses(); - for (int i = 0; i < ifs.size(); i++) { - if (ifs.get(i).getAddress() instanceof Inet6Address) { - return true; - } - } - return false; - } - - private void assertMulticast() throws JournalNetworkException, InterruptedException { - AbstractOnDemandSender sender = new OnDemandAddressSender(new ServerConfig(), 120, 150, 0); - sender.start(); - - Thread.sleep(1000L); - OnDemandAddressPoller poller = new OnDemandAddressPoller(new ClientConfig(), 150, 120); - ServerNode address = poller.poll(2, 500, TimeUnit.MILLISECONDS); - Assert.assertNotNull(address); - sender.halt(); - } -} diff --git a/core/src/test/java/com/questdb/net/ha/PartitionTest.java b/core/src/test/java/com/questdb/net/ha/PartitionTest.java deleted file mode 100644 index af30a6b8e..000000000 --- a/core/src/test/java/com/questdb/net/ha/PartitionTest.java +++ /dev/null @@ -1,183 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.model.Quote; -import com.questdb.net.ha.comsumer.JournalClientStateConsumer; -import com.questdb.net.ha.comsumer.JournalSymbolTableConsumer; -import com.questdb.net.ha.comsumer.PartitionDeltaConsumer; -import com.questdb.net.ha.model.IndexedJournal; -import com.questdb.net.ha.producer.JournalClientStateProducer; -import com.questdb.net.ha.producer.JournalSymbolTableProducer; -import com.questdb.net.ha.producer.PartitionDeltaProducer; -import com.questdb.std.ex.JournalNetworkException; -import com.questdb.std.time.DateFormatUtils; -import com.questdb.store.JournalWriter; -import com.questdb.store.Partition; -import com.questdb.test.tools.AbstractTest; -import com.questdb.test.tools.TestUtils; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class PartitionTest extends AbstractTest { - - private static final long timestamp = DateFormatUtils.parseDateTimeQuiet("2013-12-12T00:00:00.000Z"); - private JournalWriter origin; - private JournalWriter master; - private JournalWriter slave; - - private PartitionDeltaProducer producer; - private PartitionDeltaConsumer consumer; - private MockByteChannel channel; - - private Partition masterPartition; - private Partition slavePartition; - - @Before - public void setUp() throws Exception { - origin = getFactory().writer(Quote.class, "origin"); - master = getFactory().writer(Quote.class, "master"); - slave = getFactory().writer(Quote.class, "slave"); - - masterPartition = master.getAppendPartition(timestamp); - slavePartition = slave.getAppendPartition(timestamp); - - producer = new PartitionDeltaProducer(masterPartition); - consumer = new PartitionDeltaConsumer(slavePartition); - channel = new MockByteChannel(); - - TestUtils.generateQuoteData(origin, 1000, timestamp); - } - - @After - public void tearDown() { - origin.close(); - master.close(); - slave.close(); - } - - @Test - public void testConsumerEqualToProducer() throws Exception { - master.append(origin); - slave.append(origin); - - Assert.assertEquals(1000, masterPartition.size()); - Assert.assertEquals(1000, slavePartition.size()); - - producer.configure(slave.size()); - Assert.assertFalse(producer.hasContent()); - } - - @Test - public void testConsumerLargerThanProducer() throws Exception { - master.append(origin.query().all().asResultSet().subset(0, 700)); - slave.append(origin); - - producer.configure(slave.size()); - Assert.assertFalse(producer.hasContent()); - } - - @Test - public void testConsumerReset() throws Exception { - master.append(origin); - slave.append(origin.query().all().asResultSet().subset(0, 600)); - producer.configure(slave.size()); - Assert.assertTrue(producer.hasContent()); - - syncSymbolTables(); - - producer.write(channel); - consumer.read(channel); - comparePartitions(); - - TestUtils.generateQuoteData(master, 200, DateFormatUtils.parseDateTime("2014-01-01T00:00:00.000Z")); - producer.configure(slave.size()); - producer.write(channel); - consumer.read(channel); - comparePartitions(); - } - - @Test - public void testConsumerSmallerThanProducer() throws Exception { - master.append(origin); - slave.append(origin.query().all().asResultSet().subset(0, 700)); - - Assert.assertEquals(1000, masterPartition.size()); - Assert.assertEquals(700, slavePartition.size()); - - producer.configure(slave.size()); - - Assert.assertTrue(producer.hasContent()); - producer.write(channel); - consumer.read(channel); - - comparePartitions(); - } - - @Test - public void testEmptyConsumerAndPopulatedProducer() throws Exception { - master.append(origin); - producer.configure(slave.size()); - Assert.assertTrue(producer.hasContent()); - - syncSymbolTables(); - - producer.write(channel); - consumer.read(channel); - comparePartitions(); - } - - @Test - public void testEmptyConsumerAndProducer() throws Exception { - producer.configure(slave.size()); - Assert.assertFalse(producer.hasContent()); - } - - private void comparePartitions() { - Assert.assertEquals(masterPartition.size(), slavePartition.size()); - - for (int i = 0; i < slavePartition.size(); i++) { - Assert.assertEquals(masterPartition.read(i), slavePartition.read(i)); - } - } - - private void syncSymbolTables() throws JournalNetworkException { - - JournalClientStateProducer sp = new JournalClientStateProducer(); - JournalClientStateConsumer sc = new JournalClientStateConsumer(); - - sp.write(channel, new IndexedJournal(0, slave)); - sc.read(channel); - - JournalSymbolTableProducer p = new JournalSymbolTableProducer(master); - JournalSymbolTableConsumer c = new JournalSymbolTableConsumer(slave); - - p.configure(master.find(sc.getValue().getTxn(), sc.getValue().getTxPin())); - - p.write(channel); - c.read(channel); - } -} diff --git a/core/src/test/java/com/questdb/net/ha/ReconnectTest.java b/core/src/test/java/com/questdb/net/ha/ReconnectTest.java deleted file mode 100644 index 04ef6a2cb..000000000 --- a/core/src/test/java/com/questdb/net/ha/ReconnectTest.java +++ /dev/null @@ -1,133 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.model.Quote; -import com.questdb.net.ha.config.ClientConfig; -import com.questdb.net.ha.config.ServerConfig; -import com.questdb.std.ex.JournalException; -import com.questdb.store.Journal; -import com.questdb.store.JournalListener; -import com.questdb.store.JournalRuntimeException; -import com.questdb.store.JournalWriter; -import com.questdb.test.tools.AbstractTest; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -public class ReconnectTest extends AbstractTest { - - @Test - @Ignore - public void testServerRestart() throws Exception { - final int size = 10000; - try (JournalWriter remote = getFactory().writer(Quote.class, "remote", 2 * size)) { - - // start server #1 - JournalServer server = newServer(); - server.publish(remote); - server.start(); - - final CountDownLatch connectedLatch = new CountDownLatch(1); - JournalClient client = new JournalClient( - new ClientConfig("localhost") {{ - getReconnectPolicy().setLoginRetryCount(3); - getReconnectPolicy().setRetryCount(5); - getReconnectPolicy().setSleepBetweenRetriesMillis(TimeUnit.SECONDS.toMillis(1)); - }}, getFactory(), null, - evt -> { - if (evt == JournalClientEvents.EVT_CONNECTED) { - connectedLatch.countDown(); - } - } - ); - - // subscribe client, waiting for complete set of data - // when data arrives client triggers latch - final CountDownLatch latch = new CountDownLatch(1); - // create empty "local" - getFactory().writer(Quote.class, "local").close(); - try (final Journal local = getFactory().reader(Quote.class, "local")) { - client.subscribe(Quote.class, "remote", "local", 2 * size, new JournalListener() { - @Override - public void onCommit() { - try { - if (local.refresh() && local.size() == 2 * size) { - latch.countDown(); - } - } catch (JournalException e) { - throw new JournalRuntimeException(e); - } - } - - @Override - public void onEvent(int event) { - - } - }); - - - client.start(); - - Assert.assertTrue(connectedLatch.await(5, TimeUnit.SECONDS)); - // generate first batch - TestUtils.generateQuoteData(remote, size, System.currentTimeMillis(), 1); - remote.commit(); - - // stop server - server.halt(); - - // start server #2 - server = newServer(); - server.publish(remote); - server.start(); - - // generate second batch - TestUtils.generateQuoteData(remote, size, System.currentTimeMillis() + 2 * size, 1); - remote.commit(); - - // wait for client to get full set - latch.await(); - - // stop client and server - client.halt(); - server.halt(); - - // assert client state - TestUtils.assertDataEquals(remote, local); - } - } - } - - private JournalServer newServer() { - return new JournalServer(new ServerConfig() {{ - setHeartbeatFrequency(TimeUnit.MILLISECONDS.toMillis(100)); - setEnableMultiCast(false); - }}, getFactory()); - } -} diff --git a/core/src/test/java/com/questdb/net/ha/SSLTest.java b/core/src/test/java/com/questdb/net/ha/SSLTest.java deleted file mode 100644 index e4c1cb7b5..000000000 --- a/core/src/test/java/com/questdb/net/ha/SSLTest.java +++ /dev/null @@ -1,357 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.model.Quote; -import com.questdb.net.ha.config.ClientConfig; -import com.questdb.net.ha.config.ServerConfig; -import com.questdb.store.Journal; -import com.questdb.store.JournalWriter; -import com.questdb.store.factory.Factory; -import com.questdb.store.factory.configuration.JournalConfigurationBuilder; -import com.questdb.test.tools.FactoryContainer; -import com.questdb.test.tools.TestUtils; -import org.junit.*; - -import java.io.InputStream; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -public class SSLTest { - - @Rule - public final FactoryContainer factoryContainer = new FactoryContainer(new JournalConfigurationBuilder() {{ - $(Quote.class).recordCountHint(2000) - .$sym("sym").valueCountHint(20) - .$sym("mode") - .$sym("ex") - ; - }}); - - @After - public void tearDown() { - Assert.assertEquals(0, getFactory().getBusyWriterCount()); - Assert.assertEquals(0, getFactory().getBusyReaderCount()); - } - - @Test - @Ignore - public void testAuthBothCertsMissing() throws Exception { - - try (JournalWriter remote = getFactory().writer(Quote.class, "remote")) { - JournalServer server = new JournalServer(new ServerConfig() {{ - setHeartbeatFrequency(TimeUnit.MILLISECONDS.toMillis(500)); - getSslConfig().setSecure(true); - getSslConfig().setRequireClientAuth(true); - try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) { - getSslConfig().setKeyStore(is, "changeit"); - } - setEnableMultiCast(false); - setHeartbeatFrequency(50); - }}, getFactory()); - - try { - final AtomicInteger serverErrorCount = new AtomicInteger(); - final CountDownLatch terminated = new CountDownLatch(1); - - JournalClient client = new JournalClient(new ClientConfig("localhost") {{ - getSslConfig().setSecure(true); - try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) { - getSslConfig().setTrustStore(is, "changeit"); - } - }}, getFactory(), null, evt -> { - switch (evt) { - case JournalClientEvents.EVT_SERVER_ERROR: - serverErrorCount.incrementAndGet(); - break; - case JournalClientEvents.EVT_TERMINATED: - terminated.countDown(); - break; - default: - break; - } - }); - - server.publish(remote); - server.start(); - - client.subscribe(Quote.class, "remote", "local"); - client.start(); - Assert.assertTrue(terminated.await(5, TimeUnit.SECONDS)); - Assert.assertEquals(0, server.getConnectedClients()); - Assert.assertFalse(client.isRunning()); - Assert.assertEquals(1, serverErrorCount.get()); - } finally { - server.halt(); - } - } - } - - @Test - public void testClientAuth() throws Exception { - int size = 2000; - - try (JournalWriter remote = getFactory().writer(Quote.class, "remote")) { - - JournalServer server = new JournalServer(new ServerConfig() {{ - setHeartbeatFrequency(TimeUnit.MILLISECONDS.toMillis(500)); - getSslConfig().setSecure(true); - getSslConfig().setRequireClientAuth(true); - try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) { - getSslConfig().setKeyStore(is, "changeit"); - } - try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) { - getSslConfig().setTrustStore(is, "changeit"); - } - setEnableMultiCast(false); - setHeartbeatFrequency(50); - }}, getFactory()); - - try { - - JournalClient client = new JournalClient(new ClientConfig("localhost") {{ - getSslConfig().setSecure(true); - try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) { - getSslConfig().setKeyStore(is, "changeit"); - } - try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) { - getSslConfig().setTrustStore(is, "changeit"); - } - }}, getFactory()); - - server.publish(remote); - server.start(); - - client.subscribe(Quote.class, "remote", "local"); - client.start(); - - TestUtils.generateQuoteData(remote, size); - Thread.sleep(1000); - - client.halt(); - try (Journal local = getFactory().reader(Quote.class, "local")) { - TestUtils.assertDataEquals(remote, local); - } - } finally { - server.halt(); - } - } - } - - @Test - public void testNoCertTrustAllSSL() throws Exception { - int size = 2000; - - try (JournalWriter remote = getFactory().writer(Quote.class, "remote")) { - JournalServer server = new JournalServer(new ServerConfig() {{ - setHeartbeatFrequency(TimeUnit.MILLISECONDS.toMillis(500)); - getSslConfig().setSecure(true); - try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) { - getSslConfig().setKeyStore(is, "changeit"); - } - setEnableMultiCast(false); - setHeartbeatFrequency(50); - }}, getFactory()); - - try { - - JournalClient client = new JournalClient(new ClientConfig("localhost") {{ - getSslConfig().setSecure(true); - getSslConfig().setTrustAll(true); - }}, getFactory()); - - server.publish(remote); - server.start(); - - client.subscribe(Quote.class, "remote", "local"); - client.start(); - - TestUtils.generateQuoteData(remote, size); - Thread.sleep(1000); - - client.halt(); - } finally { - server.halt(); - } - - try (Journal local = getFactory().reader(Quote.class, "local")) { - TestUtils.assertDataEquals(remote, local); - } - } - } - - @Test - public void testNonAuthClientTrustMissing() throws Exception { - try (JournalWriter remote = getFactory().writer(Quote.class, "remote")) { - JournalServer server = new JournalServer(new ServerConfig() {{ - setHeartbeatFrequency(TimeUnit.MILLISECONDS.toMillis(500)); - getSslConfig().setSecure(true); - try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) { - getSslConfig().setKeyStore(is, "changeit"); - } - setEnableMultiCast(false); - setHeartbeatFrequency(50); - }}, getFactory()); - - try { - - - final AtomicInteger serverErrorCount = new AtomicInteger(); - final CountDownLatch terminated = new CountDownLatch(1); - - JournalClient client = new JournalClient(new ClientConfig("localhost") {{ - getSslConfig().setSecure(true); - }}, getFactory(), null, evt -> { - switch (evt) { - case JournalClientEvents.EVT_SERVER_ERROR: - serverErrorCount.incrementAndGet(); - break; - case JournalClientEvents.EVT_TERMINATED: - terminated.countDown(); - break; - default: - break; - } - }); - - server.publish(remote); - server.start(); - - client.subscribe(Quote.class, "remote", "local"); - - client.subscribe(Quote.class, "remote", "local"); - client.start(); - Assert.assertTrue(terminated.await(5, TimeUnit.SECONDS)); -// Assert.assertEquals(0, server.getConnectedClients()); - Assert.assertFalse(client.isRunning()); - Assert.assertEquals(1, serverErrorCount.get()); - client.halt(); - } finally { - server.halt(); - } - } - } - - @Test - public void testServerTrustMissing() throws Exception { - - try (JournalWriter remote = getFactory().writer(Quote.class, "remote")) { - JournalServer server = new JournalServer(new ServerConfig() {{ - setHeartbeatFrequency(TimeUnit.MILLISECONDS.toMillis(500)); - getSslConfig().setSecure(true); - getSslConfig().setRequireClientAuth(true); - try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) { - getSslConfig().setKeyStore(is, "changeit"); - } - setEnableMultiCast(false); - setHeartbeatFrequency(50); - }}, getFactory()); - - try { - final AtomicInteger serverErrorCount = new AtomicInteger(); - final CountDownLatch terminated = new CountDownLatch(1); - - JournalClient client = new JournalClient(new ClientConfig("localhost") {{ - getSslConfig().setSecure(true); - try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) { - getSslConfig().setTrustStore(is, "changeit"); - } - try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) { - getSslConfig().setKeyStore(is, "changeit"); - } - }}, getFactory(), null, evt -> { - switch (evt) { - case JournalClientEvents.EVT_SERVER_ERROR: - serverErrorCount.incrementAndGet(); - break; - case JournalClientEvents.EVT_TERMINATED: - terminated.countDown(); - break; - default: - break; - } - }); - - server.publish(remote); - server.start(); - client.subscribe(Quote.class, "remote", "local"); - client.start(); - Assert.assertTrue(terminated.await(5, TimeUnit.SECONDS)); - Assert.assertFalse(client.isRunning()); - Assert.assertEquals(1, serverErrorCount.get()); - client.halt(); - } finally { - server.halt(); - } - } - } - - @Test - public void testSingleKeySSL() throws Exception { - int size = 1000; - try (JournalWriter remote = getFactory().writer(Quote.class, "remote")) { - JournalServer server = new JournalServer(new ServerConfig() {{ - setHeartbeatFrequency(TimeUnit.MILLISECONDS.toMillis(500)); - getSslConfig().setSecure(true); - try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) { - getSslConfig().setKeyStore(is, "changeit"); - } - setEnableMultiCast(false); - setHeartbeatFrequency(50); - }}, getFactory()); - - try { - - JournalClient client = new JournalClient(new ClientConfig("localhost") {{ - setTcpNoDelay(false); - try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) { - getSslConfig().setTrustStore(is, "changeit"); - } - getSslConfig().setSecure(true); - }}, getFactory()); - - server.publish(remote); - server.start(); - - client.subscribe(Quote.class, "remote", "local"); - client.start(); - - TestUtils.generateQuoteData(remote, size); - Thread.sleep(500); - - client.halt(); - try (Journal local = getFactory().reader(Quote.class, "local")) { - TestUtils.assertDataEquals(remote, local); - } - } finally { - server.halt(); - } - } - } - - private Factory getFactory() { - return factoryContainer.getFactory(); - } -} diff --git a/core/src/test/java/com/questdb/net/ha/ScenarioTest.java b/core/src/test/java/com/questdb/net/ha/ScenarioTest.java deleted file mode 100644 index 920fb5dfd..000000000 --- a/core/src/test/java/com/questdb/net/ha/ScenarioTest.java +++ /dev/null @@ -1,210 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.model.Quote; -import com.questdb.net.ha.config.ClientConfig; -import com.questdb.net.ha.config.ServerConfig; -import com.questdb.std.Rnd; -import com.questdb.std.ex.JournalException; -import com.questdb.store.*; -import com.questdb.store.factory.configuration.Constants; -import com.questdb.test.tools.AbstractTest; -import com.questdb.test.tools.TestData; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -@Ignore -public class ScenarioTest extends AbstractTest { - - private final ServerConfig serverConfig = new ServerConfig() {{ - setHeartbeatFrequency(TimeUnit.MILLISECONDS.toMillis(300)); - setEnableMultiCast(false); - }}; - - private final ClientConfig clientConfig = new ClientConfig("localhost"); - - @Test - public void testLagTrickle() throws Exception { - - // prepare test data - try (JournalWriter origin = getFactory().writer(Quote.class, "origin")) { - TestData.appendQuoteData2(origin); - - try (final JournalWriter randomOrigin = getFactory().writer(new JournalKey<>(Quote.class, "origin-rnd", PartitionBy.NONE, Constants.NULL_RECORD_HINT, false))) { - randomOrigin.append(origin.query().all().asResultSet().shuffle(new Rnd())); - - - try (final JournalWriter remote = getFactory().writer(Quote.class, "remote")) { - try (final Journal remoteReader = getFactory().reader(Quote.class, "remote")) { - - // create empty journal - getFactory().writer(Quote.class, "local").close(); - - // setup local where data should be trickling from client - try (final Journal local = getFactory().reader(Quote.class, "local")) { - Assert.assertEquals(0, local.size()); - - JournalServer server = new JournalServer(serverConfig, getFactory()); - JournalClient client = new JournalClient(clientConfig, getFactory()); - - server.publish(remote); - server.start(); - - final AtomicInteger errors = new AtomicInteger(); - - final CountDownLatch ready = new CountDownLatch(1); - client.subscribe(Quote.class, "remote", "local", new JournalListener() { - @Override - public void onCommit() { - try { - if (local.refresh() && local.size() == 33) { - ready.countDown(); - } - } catch (JournalException e) { - errors.incrementAndGet(); - e.printStackTrace(); - } - } - - @Override - public void onEvent(int event) { - if (event != JournalEvents.EVT_JNL_SUBSCRIBED) { - errors.incrementAndGet(); - } - } - }); - - - client.start(); - - int n = 0; - while (n < 400) { - lagIteration(randomOrigin, remote, n, n + 10); - n += 10; - } - - Assert.assertTrue(ready.await(10, TimeUnit.SECONDS)); - - server.halt(); - client.halt(); - - local.refresh(); - remoteReader.refresh(); - TestUtils.assertEquals(remoteReader, local); - - Assert.assertEquals(0, errors.get()); - } - } - } - } - } - } - - @Test - public void testSingleJournalTrickle() throws Exception { - JournalServer server = new JournalServer(serverConfig, getFactory()); - JournalClient client = new JournalClient(clientConfig, getFactory()); - - // prepare test data - try (JournalWriter origin = getFactory().writer(Quote.class, "origin")) { - TestData.appendQuoteData1(origin); - Assert.assertEquals(100, origin.size()); - - // setup remote we will be trickling test data into - try (JournalWriter remote = getFactory().writer(Quote.class, "remote")) { - - getFactory().writer(Quote.class, "local").close(); - - // setup local where data should be trickling from client - try (Journal local = getFactory().reader(Quote.class, "local")) { - Assert.assertEquals(0, local.size()); - - server.publish(remote); - server.start(); - - client.subscribe(Quote.class, "remote", "local"); - client.start(); - - try { - iteration("2013-02-10T10:03:20.000Z\tALDW\t0.32885755937534\t0.5741201360255567\t1836077773\t693649102\tFast trading\tSK\n" + - "2013-02-10T10:06:40.000Z\tAMD\t0.16781047061245025\t0.4831627617900026\t1423050407\t141794980\tFast trading\tGR\n" + - "2013-02-10T10:07:30.000Z\tHSBA.L\t0.04724340267969518\t0.5988337212476811\t178180342\t1522085049\tFast trading\tSK\n", - origin, remote, local, 0, 10 - ); - - iteration("2013-02-10T10:15:50.000Z\tALDW\t0.7976166367363274\t0.06448758069572669\t1436005581\t1897226585\tFast trading\tGR\n" + - "2013-02-10T10:15:00.000Z\tAMD\t0.6789043827286667\t0.771921575501964\t580589771\t1159590077\tFast trading\tLXE\n" + - "2013-02-10T10:14:10.000Z\tHSBA.L\t0.984512894941384\t0.2664006899723862\t1288300070\t838312365\tFast trading\tLXE\n", - origin, remote, local, 10, 20 - ); - - iteration("2013-02-10T10:24:10.000Z\tALDW\t0.26008876203627374\t0.04354393444455451\t25334630\t1835685418\tFast trading\tGR\n" + - "2013-02-10T10:23:20.000Z\tAMD\t0.9757637204046299\t0.7654386171943978\t23937995\t992860510\tFast trading\tLXE\n" + - "2013-02-10T10:21:40.000Z\tHSBA.L\t0.5630111081489209\t0.4222995146933318\t1534594684\t1153925552\tFast trading\tLN\n", - origin, remote, local, 20, 30 - ); - - - } finally { - client.halt(); - server.halt(); - } - } - } - } - } - - private static void iteration(String expected, Journal origin, JournalWriter remote, Journal local, int lo, int hi) throws Exception { - remote.append(origin.query().all().asResultSet().subset(lo, hi)); - remote.commit(); - - int count = 0; - do { - Thread.sleep(100); - if (count++ > 10) { - Assert.fail("Refresh is too slow!"); - } - } - while (!local.refresh()); - - TestUtils.assertEquals(expected, local.query().head().withKeys().asResultSet()); - } - - private void lagIteration(final Journal origin, final JournalWriter remote, final int lo, final int hi) throws JournalException { - remote.mergeAppend(new ArrayList() {{ - for (Quote q : origin.query().all().asResultSet().subset(lo, hi).sort("timestamp")) { - add(q); - } - }}); - remote.commit(); - } -} diff --git a/core/src/test/java/com/questdb/net/ha/ServerNodeTest.java b/core/src/test/java/com/questdb/net/ha/ServerNodeTest.java deleted file mode 100644 index 18330e264..000000000 --- a/core/src/test/java/com/questdb/net/ha/ServerNodeTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.net.ha.config.ServerNode; -import com.questdb.store.JournalRuntimeException; -import org.junit.Assert; -import org.junit.Test; - -public class ServerNodeTest { - - @Test(expected = JournalRuntimeException.class) - public void testAddressValidation() { - new ServerNode(0, "192.168:x"); - } - - @Test - public void testHostAndPort() { - ServerNode node = new ServerNode(0, "github.questdb.org:8080"); - Assert.assertEquals("github.questdb.org", node.getHostname()); - Assert.assertEquals(8080, node.getPort()); - } - - @Test - public void testIPv4() { - ServerNode node = new ServerNode(0, "192.168.1.10"); - Assert.assertEquals("192.168.1.10", node.getHostname()); - } - - @Test - public void testIPv4AndPort() { - ServerNode node = new ServerNode(0, "192.168.1.10:8080"); - Assert.assertEquals("192.168.1.10", node.getHostname()); - Assert.assertEquals(8080, node.getPort()); - } - - @Test - public void testIPv6() { - ServerNode node = new ServerNode(0, "[fe80::5fc:43c:eef0:5b8e%3]"); - Assert.assertEquals("fe80::5fc:43c:eef0:5b8e%3", node.getHostname()); - } - - @Test - public void testIPv6AndPort() { - ServerNode node = new ServerNode(0, "[fe80::5fc:43c:eef0:5b8e%3]:7090"); - Assert.assertEquals("fe80::5fc:43c:eef0:5b8e%3", node.getHostname()); - Assert.assertEquals(7090, node.getPort()); - } -} diff --git a/core/src/test/java/com/questdb/net/ha/SetKeyTest.java b/core/src/test/java/com/questdb/net/ha/SetKeyTest.java deleted file mode 100644 index cd9ce9da5..000000000 --- a/core/src/test/java/com/questdb/net/ha/SetKeyTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.model.Quote; -import com.questdb.net.ha.model.IndexedJournalKey; -import com.questdb.net.ha.protocol.commands.SetKeyRequestConsumer; -import com.questdb.net.ha.protocol.commands.SetKeyRequestProducer; -import com.questdb.store.JournalKey; -import com.questdb.store.PartitionBy; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class SetKeyTest { - - private MockByteChannel channel; - - @Before - public void setUp() { - channel = new MockByteChannel(); - } - - @Test - public void testProducerConsumer() throws Exception { - SetKeyRequestProducer producer = new SetKeyRequestProducer(); - SetKeyRequestConsumer consumer = new SetKeyRequestConsumer(); - - IndexedJournalKey key = new IndexedJournalKey(0, new JournalKey<>(Quote.class, "loc1", PartitionBy.DAY, 100, true)); - producer.setValue(key); - producer.write(channel); - consumer.read(channel); - Assert.assertEquals(key, consumer.getValue()); - - IndexedJournalKey key2 = new IndexedJournalKey(1, new JournalKey<>(Quote.class, "longer_location", PartitionBy.DAY, 1000, true)); - producer.setValue(key2); - producer.write(channel); - consumer.read(channel); - Assert.assertEquals(key2, consumer.getValue()); - - IndexedJournalKey key3 = new IndexedJournalKey(2, new JournalKey<>(Quote.class, "shorter_loc", PartitionBy.DAY, 1000, true)); - producer.setValue(key3); - producer.write(channel); - consumer.read(channel); - Assert.assertEquals(key3, consumer.getValue()); - } -} diff --git a/core/src/test/java/com/questdb/net/ha/VariableColumnTest.java b/core/src/test/java/com/questdb/net/ha/VariableColumnTest.java deleted file mode 100644 index 398fe8203..000000000 --- a/core/src/test/java/com/questdb/net/ha/VariableColumnTest.java +++ /dev/null @@ -1,254 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.ha; - -import com.questdb.net.ha.comsumer.VariableColumnDeltaConsumer; -import com.questdb.net.ha.producer.VariableColumnDeltaProducer; -import com.questdb.std.ex.JournalException; -import com.questdb.store.JournalMode; -import com.questdb.store.MemoryFile; -import com.questdb.store.VariableColumn; -import org.junit.*; -import org.junit.rules.TemporaryFolder; - -import java.io.File; - -public class VariableColumnTest { - - @Rule - public final TemporaryFolder temporaryFolder = new TemporaryFolder(); - private MemoryFile file; - private MemoryFile file2; - private MemoryFile indexFile; - private MemoryFile indexFile2; - private MockByteChannel channel; - - @After - public void cleanup() { - file.close(); - file2.close(); - indexFile.close(); - indexFile2.close(); - } - - @Before - public void setUp() throws JournalException { - file = new MemoryFile(new File(temporaryFolder.getRoot(), "col.d"), 22, JournalMode.APPEND, false); - // it is important to keep bit hint small, so that file2 has small buffers. This would made test go via both pathways. - // large number will result in tests not covering all of execution path. - file2 = new MemoryFile(new File(temporaryFolder.getRoot(), "col2.d"), 18, JournalMode.APPEND, false); - indexFile = new MemoryFile(new File(temporaryFolder.getRoot(), "col.i"), 22, JournalMode.APPEND, false); - indexFile2 = new MemoryFile(new File(temporaryFolder.getRoot(), "col2.i"), 18, JournalMode.APPEND, false); - channel = new MockByteChannel(); - } - - @Test - public void testConsumerEqualToProducer() { - VariableColumn col1 = new VariableColumn(file, indexFile); - VariableColumn col2 = new VariableColumn(file2, indexFile2); - VariableColumnDeltaProducer producer = new VariableColumnDeltaProducer(col1); - - int max = 150000; - - for (int i = 0; i < max; i++) { - col1.putStr("test123" + (max - i)); - col1.commit(); - } - - for (int i = 0; i < max; i++) { - col2.putStr("test123" + (max - i)); - col2.commit(); - } - - producer.configure(col2.size(), col1.size()); - Assert.assertFalse(producer.hasContent()); - Assert.assertEquals(col1.size(), col2.size()); - - for (int i = 0; i < max; i++) { - Assert.assertEquals("test123" + (max - i), col2.getStr(i)); - } - } - - @Test - public void testConsumerLargerThanProducer() { - VariableColumn col1 = new VariableColumn(file, indexFile); - VariableColumn col2 = new VariableColumn(file2, indexFile2); - VariableColumnDeltaProducer producer = new VariableColumnDeltaProducer(col1); - - int max = 150000; - - for (int i = 0; i < max - 50000; i++) { - col1.putStr("test123" + (max - i)); - col1.commit(); - } - - for (int i = 0; i < max; i++) { - col2.putStr("test123" + (max - i)); - col2.commit(); - } - - producer.configure(col2.size(), col1.size()); - Assert.assertFalse(producer.hasContent()); - } - - @Test - public void testConsumerReset() throws Exception { - VariableColumn col1 = new VariableColumn(file, indexFile); - VariableColumn col2 = new VariableColumn(file2, indexFile2); - ChannelConsumer consumer = new VariableColumnDeltaConsumer(col2); - VariableColumnDeltaProducer producer = new VariableColumnDeltaProducer(col1); - - int max = 150000; - - for (int i = 0; i < max; i++) { - col1.putStr("test123" + (max - i)); - col1.commit(); - } - - for (int i = 0; i < max - 50000; i++) { - col2.putStr("test123" + (max - i)); - col2.commit(); - } - - producer.configure(col2.size(), col1.size()); - Assert.assertTrue(producer.hasContent()); - producer.write(channel); - consumer.read(channel); - col2.commit(); - - Assert.assertEquals(col1.size(), col2.size()); - - for (int i = 0; i < 1000; i++) { - col1.putStr("test123" + (max + 1000 - i)); - col1.commit(); - } - - producer.configure(col2.size(), col1.size()); - Assert.assertTrue(producer.hasContent()); - producer.write(channel); - consumer.read(channel); - col2.commit(); - - Assert.assertEquals(col1.size(), col2.size()); - - for (int i = 0; i < max; i++) { - Assert.assertEquals("test123" + (max - i), col2.getStr(i)); - } - - for (int i = 0; i < 1000; i++) { - Assert.assertEquals("test123" + (max + 1000 - i), col2.getStr(i + max)); - } - } - - @Test - public void testConsumerSmallerThanProducer() throws Exception { - VariableColumn col1 = new VariableColumn(file, indexFile); - VariableColumn col2 = new VariableColumn(file2, indexFile2); - ChannelConsumer consumer = new VariableColumnDeltaConsumer(col2); - VariableColumnDeltaProducer producer = new VariableColumnDeltaProducer(col1); - - int max = 150000; - - for (int i = 0; i < max; i++) { - col1.putStr("test123" + (max - i)); - col1.commit(); - } - - for (int i = 0; i < max - 50000; i++) { - col2.putStr("test123" + (max - i)); - col2.commit(); - } - - producer.configure(col2.size(), col1.size()); - Assert.assertTrue(producer.hasContent()); - producer.write(channel); - consumer.read(channel); - col2.commit(); - - Assert.assertEquals(col1.size(), col2.size()); - - for (int i = 0; i < max; i++) { - Assert.assertEquals("test123" + (max - i), col2.getStr(i)); - } - } - - @Test - public void testEmptyConsumerAndPopulatedProducer() throws Exception { - VariableColumn col1 = new VariableColumn(file, indexFile); - VariableColumn col2 = new VariableColumn(file2, indexFile2); - ChannelConsumer consumer = new VariableColumnDeltaConsumer(col2); - VariableColumnDeltaProducer producer = new VariableColumnDeltaProducer(col1); - - int max = 150000; - - for (int i = 0; i < max; i++) { - col1.putStr("test123" + (max - i)); - col1.commit(); - } - - producer.configure(col2.size(), col1.size()); - Assert.assertTrue(producer.hasContent()); - producer.write(channel); - consumer.read(channel); - col2.commit(); - - Assert.assertEquals(col1.size(), col2.size()); - - for (int i = 0; i < max; i++) { - Assert.assertEquals("test123" + (max - i), col2.getStr(i)); - } - } - - @Test - public void testEmptyConsumerAndProducer() { - VariableColumn col1 = new VariableColumn(file, indexFile); - VariableColumn col2 = new VariableColumn(file2, indexFile2); - VariableColumnDeltaProducer producer = new VariableColumnDeltaProducer(col1); - - producer.configure(col2.size(), col1.size()); - Assert.assertFalse(producer.hasContent()); - Assert.assertEquals(col1.size(), col2.size()); - } - - @Test - public void testNulls() throws Exception { - VariableColumn col1 = new VariableColumn(file, indexFile); - VariableColumn col2 = new VariableColumn(file2, indexFile2); - - ChannelConsumer consumer = new VariableColumnDeltaConsumer(col2); - VariableColumnDeltaProducer producer = new VariableColumnDeltaProducer(col1); - - col1.putNull(); - col1.commit(); - - producer.configure(col2.size(), col1.size()); - Assert.assertTrue(producer.hasContent()); - producer.write(channel); - consumer.read(channel); - col2.commit(); - - Assert.assertEquals(1, col1.size()); - Assert.assertEquals(1, col2.size()); - } -} \ No newline at end of file diff --git a/core/src/test/java/com/questdb/net/http/HttpServerTest.java b/core/src/test/java/com/questdb/net/http/HttpServerTest.java deleted file mode 100644 index 7adef714d..000000000 --- a/core/src/test/java/com/questdb/net/http/HttpServerTest.java +++ /dev/null @@ -1,1157 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2019 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.http; - -import com.questdb.BootstrapEnv; -import com.questdb.ServerConfiguration; -import com.questdb.ex.ResponseContentBufferTooSmallException; -import com.questdb.log.Log; -import com.questdb.log.LogFactory; -import com.questdb.net.ha.AbstractJournalTest; -import com.questdb.net.http.handlers.ImportHandler; -import com.questdb.net.http.handlers.StaticContentHandler; -import com.questdb.net.http.handlers.UploadHandler; -import com.questdb.parser.sql.QueryCompiler; -import com.questdb.parser.typeprobe.TypeProbeCollection; -import com.questdb.ql.RecordSource; -import com.questdb.ql.RecordSourcePrinter; -import com.questdb.std.ByteBuffers; -import com.questdb.std.Chars; -import com.questdb.std.Misc; -import com.questdb.std.Numbers; -import com.questdb.std.str.StringSink; -import com.questdb.std.time.DateFormatFactory; -import com.questdb.std.time.DateFormatUtils; -import com.questdb.std.time.DateLocaleFactory; -import com.questdb.store.ColumnType; -import com.questdb.store.Journal; -import com.questdb.store.JournalEntryWriter; -import com.questdb.store.JournalWriter; -import com.questdb.store.factory.FactoryEventListener; -import com.questdb.store.factory.WriterFactory; -import com.questdb.store.factory.configuration.JournalStructure; -import com.questdb.store.util.FileSink; -import com.questdb.test.tools.HttpTestUtils; -import com.questdb.test.tools.TestUtils; -import org.apache.http.Header; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.config.Registry; -import org.apache.http.config.RegistryBuilder; -import org.apache.http.conn.socket.ConnectionSocketFactory; -import org.apache.http.conn.socket.PlainConnectionSocketFactory; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.entity.mime.MultipartEntityBuilder; -import org.apache.http.entity.mime.content.FileBody; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; -import org.apache.http.ssl.SSLContextBuilder; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -import javax.net.ssl.SSLContext; -import java.io.*; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.net.SocketException; -import java.net.StandardSocketOptions; -import java.nio.ByteBuffer; -import java.nio.channels.SocketChannel; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.CyclicBarrier; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.locks.LockSupport; - -@Ignore -public class HttpServerTest extends AbstractJournalTest { - - private final static Log LOG = LogFactory.getLog(HttpServerTest.class); - private final static TypeProbeCollection TYPE_PROBE_COLLECTION = new TypeProbeCollection(); - private final static DateFormatFactory DATE_FORMAT_FACTORY = new DateFormatFactory(); - - private final static String request = "GET /imp?x=1&z=2 HTTP/1.1\r\n" + - "Host: localhost:80\r\n" + - "Connection: keep-alive\r\n" + - "Cache-Control: max-age=0\r\n" + - "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n" + - "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.48 Safari/537.36\r\n" + - "Accept-Language: en-US,en;q=0.8\r\n" + - "Cookie: textwrapon=false; textautoformat=false; wysiwyg=textarea\r\n" + - "\r\n"; - @Rule - public final TemporaryFolder temp = new TemporaryFolder(); - - public static HttpResponse get(String url) throws IOException { - HttpGet post = new HttpGet(url); - try (CloseableHttpClient client = HttpClients.createDefault()) { - return client.execute(post); - } - } - - @Test - public void testCompressedDownload() throws Exception { - final ServerConfiguration configuration = new ServerConfiguration(new File(resourceFile("/site"), "conf/questdb.conf")); - configuration.getSslConfig().setSecure(true); - configuration.getSslConfig().setKeyStore(new FileInputStream(resourceFile("/keystore/singlekey.ks")), "changeit"); - - BootstrapEnv env = new BootstrapEnv(); - env.configuration = configuration; - env.matcher = new SimpleUrlMatcher() {{ - setDefaultHandler(new StaticContentHandler(env)); - }}; - - HttpServer server = new HttpServer(env); - server.start(); - try { - HttpTestUtils.download(clientBuilder(true), "https://localhost:9000/upload.html", new File(temp.getRoot(), "upload.html")); - } finally { - server.halt(); - } - } - - @Test - public void testConcurrentImport() throws Exception { - final BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(); - env.factory = getFactory(); - env.typeProbeCollection = TYPE_PROBE_COLLECTION; - env.matcher = new SimpleUrlMatcher() {{ - put("/imp", new ImportHandler(env)); - }}; - - HttpServer server = new HttpServer(env); - server.start(); - - final CyclicBarrier barrier = new CyclicBarrier(2); - final CountDownLatch latch = new CountDownLatch(2); - try { - - new Thread(() -> { - try { - barrier.await(); - Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import.csv", "http://localhost:9000/imp", null, null)); - latch.countDown(); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } - }).start(); - - new Thread(() -> { - try { - barrier.await(); - Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import-nan.csv", "http://localhost:9000/imp", null, null)); - latch.countDown(); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } - }).start(); - - latch.await(); - - try (Journal r = getFactory().reader("test-import.csv")) { - Assert.assertEquals("First failed", 129, r.size()); - } - - try (Journal r = getFactory().reader("test-import-nan.csv")) { - Assert.assertEquals("Second failed", 129, r.size()); - } - } finally { - server.halt(); - } - } - - @Test - public void testConnectionCount() throws Exception { - final BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(new File(resourceFile("/site"), "conf/questdb.conf")); - env.configuration.setHttpMaxConnections(10); - env.matcher = new SimpleUrlMatcher() {{ - setDefaultHandler(new StaticContentHandler(env)); - }}; - - HttpServer server = new HttpServer(env); - server.start(); - - try { - CloseableHttpClient c1 = clientBuilder(true).build(); - CloseableHttpClient c2 = clientBuilder(true).build(); - CloseableHttpClient c3 = clientBuilder(true).build(); - CloseableHttpClient c4 = clientBuilder(true).build(); - Assert.assertNotNull(c1.execute(new HttpGet("https://localhost:9000/upload.html"))); - Assert.assertEquals(1, server.getConnectionCount()); - - Assert.assertNotNull(c2.execute(new HttpGet("https://localhost:9000/upload.html"))); - Assert.assertEquals(2, server.getConnectionCount()); - - Assert.assertNotNull(c3.execute(new HttpGet("https://localhost:9000/upload.html"))); - Assert.assertEquals(3, server.getConnectionCount()); - - Assert.assertNotNull(c4.execute(new HttpGet("https://localhost:9000/upload.html"))); - Assert.assertEquals(4, server.getConnectionCount()); - - c1.close(); - c2.close(); - Thread.sleep(300); - Assert.assertEquals(2, server.getConnectionCount()); - - c3.close(); - c4.close(); - Thread.sleep(300); - Assert.assertEquals(0, server.getConnectionCount()); - } finally { - server.halt(); - } - } - - @Test - public void testDefaultDirIndex() throws Exception { - final BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(new File(resourceFile("/site"), "conf/questdb.conf")); - env.configuration.getSslConfig().setSecure(false); - env.typeProbeCollection = TYPE_PROBE_COLLECTION; - env.matcher = new SimpleUrlMatcher() {{ - setDefaultHandler(new StaticContentHandler(env)); - }}; - - HttpServer server = new HttpServer(env); - - server.start(); - try { - HttpTestUtils.download(clientBuilder(false), "http://localhost:9000/", new File(temp.getRoot(), "index.html")); - } finally { - server.halt(); - } - } - - @Test - public void testFragmentedUrl() throws Exception { - final long tick = DateFormatUtils.parseDateTime("2015-12-05T13:30:00.000Z"); - final BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(); - env.matcher = new SimpleUrlMatcher(); - - HttpServer server = new HttpServer(env); - server.setClock(() -> tick); - server.start(); - - try (SocketChannel channel = openChannel()) { - ByteBuffer buf = ByteBuffer.allocate(1024); - ByteBuffer out = ByteBuffer.allocate(1024); - - int n = 5; - for (int i = 0; i < n; i++) { - buf.put((byte) request.charAt(i)); - } - buf.flip(); - ByteBuffers.copy(buf, channel); - - buf.clear(); - for (int i = n; i < request.length(); i++) { - buf.put((byte) request.charAt(i)); - } - buf.flip(); - ByteBuffers.copy(buf, channel); - - channel.configureBlocking(false); - - ByteBuffers.copyGreedyNonBlocking(channel, out, 100000); - - final String expected = "HTTP/1.1 404 Not Found\r\n" + - "Server: questDB/1.0\r\n" + - "Date: Sat, 5 Dec 2015 13:30:00 GMT\r\n" + - "Transfer-Encoding: chunked\r\n" + - "Content-Type: text/html; charset=utf-8\r\n" + - "\r\n" + - "b\r\n" + - "Not Found\r\n" + - "\r\n" + - "0\r\n" + - "\r\n"; - - Assert.assertEquals(expected.length(), out.remaining()); - - for (int i = 0, k = expected.length(); i < k; i++) { - Assert.assertEquals(expected.charAt(i), out.get()); - } - } finally { - server.halt(); - } - } - - @Test - public void testIdleTimeout() throws Exception { - final BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(new File(resourceFile("/site"), "conf/questdb.conf")); - // 500ms timeout - env.configuration.setHttpTimeout(500); - env.configuration.getSslConfig().setSecure(false); - env.matcher = new SimpleUrlMatcher() {{ - setDefaultHandler(new StaticContentHandler(env)); - }}; - - HttpServer server = new HttpServer(env); - server.start(); - - try { - Socket socket = new Socket("127.0.0.1", 9000); - OutputStream os = socket.getOutputStream(); - Thread.sleep(600); - - try { - os.write(request.getBytes()); - - for (int i = 0; i < 4096; i++) { - os.write('c'); - } - os.flush(); - - Assert.fail("Expected exception due to connection timeout"); - } catch (SocketException ignored) { - - } - } finally { - server.halt(); - } - } - - @Test - @Ignore - public void testImportAppend() throws Exception { - - final AtomicInteger errors = new AtomicInteger(); - getFactory().setEventListener((factoryType, thread, name, event, segment, position) -> { - if (event == FactoryEventListener.EV_UNEXPECTED_CLOSE) { - errors.incrementAndGet(); - } - return true; - }); - - BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(); - env.factory = getFactory(); - env.typeProbeCollection = TYPE_PROBE_COLLECTION; - env.matcher = new SimpleUrlMatcher() {{ - put("/imp", new ImportHandler(env)); - }}; - - HttpServer server = new HttpServer(env); - server.start(); - - try { - Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import.csv", "http://localhost:9000/imp?fmt=json", null, null)); - Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import.csv", "http://localhost:9000/imp", null, null)); - StringSink sink = new StringSink(); - RecordSourcePrinter printer = new RecordSourcePrinter(sink); - QueryCompiler qc = new QueryCompiler(env); - printer.print(qc.compile(getFactory(), "select count(StrSym), count(IntSym), count(IntCol), count(long), count() from 'test-import.csv'"), getFactory()); - TestUtils.assertEquals("252\t252\t256\t258\t258\n", sink); - } finally { - server.halt(); - } - - Assert.assertEquals(0, errors.get()); - } - - @Test - public void testImportForcedHeader() throws Exception { - - BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(); - env.factory = getFactory(); - env.typeProbeCollection = TYPE_PROBE_COLLECTION; - env.matcher = new SimpleUrlMatcher() {{ - put("/imp", new ImportHandler(env)); - }}; - HttpServer server = new HttpServer(env); - server.start(); - - try { - StringSink sink = new StringSink(); - RecordSourcePrinter printer = new RecordSourcePrinter(sink); - QueryCompiler qc = new QueryCompiler(env); - - Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-explicit-headers.csv", "http://localhost:9000/imp?name=test-import.csv&overwrite=true&durable=true&forceHeader=true", null, null)); - printer.print(qc.compile(getFactory(), "select count() from 'test-import.csv'"), getFactory()); - // expect first line to be treated as header - TestUtils.assertEquals("2\n", sink); - } finally { - server.halt(); - } - } - - @Test - public void testImportIntoBusyJournal() throws Exception { - try (JournalWriter ignored = getFactory().writer(new JournalStructure("test-import.csv").$int("x").$())) { - BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(); - env.factory = getFactory(); - env.typeProbeCollection = TYPE_PROBE_COLLECTION; - env.matcher = new SimpleUrlMatcher() {{ - put("/imp", new ImportHandler(env)); - }}; - HttpServer server = new HttpServer(env); - server.start(); - - StringBuilder response = new StringBuilder(); - try { - Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import.csv", "http://localhost:9000/imp?fmt=json", null, response)); - TestUtils.assertEquals("{\"status\":\"Journal exists and column count does not match\"}", response); - } catch (IOException e) { - Assert.assertTrue(e.getMessage().contains("Connection reset")); - } finally { - server.halt(); - } - } - } - - @Test - public void testImportIntoBusyJournal2() throws Exception { - WriterFactory f = getFactory(); - - try (JournalWriter w = f.writer(new JournalStructure("small.csv").$int("X").$int("Y").$())) { - JournalEntryWriter ew = w.entryWriter(); - ew.putInt(0, 3); - ew.putInt(1, 30); - ew.append(); - w.commit(); - - BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(); - env.factory = getFactory(); - env.typeProbeCollection = TYPE_PROBE_COLLECTION; - env.matcher = new SimpleUrlMatcher() {{ - put("/imp", new ImportHandler(env)); - }}; - - HttpServer server = new HttpServer(env); - server.start(); - - StringBuilder response = new StringBuilder(); - try { - Assert.assertEquals(200, HttpTestUtils.upload("/csv/small.csv", "http://localhost:9000/imp?fmt=json", null, response)); - Assert.assertTrue(Chars.startsWith(response, "{\"status\":\"com.questdb.ex.WriterBusyException\"}")); - } catch (IOException e) { - Assert.assertTrue(e.getMessage().contains("Connection reset")); - } finally { - server.halt(); - } - } - } - - @Test - public void testImportNoHeader() throws Exception { - final ServerConfiguration configuration = new ServerConfiguration(); - BootstrapEnv env = new BootstrapEnv(); - env.configuration = configuration; - env.factory = getFactory(); - env.typeProbeCollection = TYPE_PROBE_COLLECTION; - env.matcher = new SimpleUrlMatcher() {{ - put("/imp", new ImportHandler(env)); - }}; - - HttpServer server = new HttpServer(env); - server.start(); - - try { - StringSink sink = new StringSink(); - RecordSourcePrinter printer = new RecordSourcePrinter(sink); - QueryCompiler qc = new QueryCompiler(env); - - Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-explicit-headers.csv", "http://localhost:9000/imp?name=test-import.csv&overwrite=true&durable=true", null, null)); - printer.print(qc.compile(getFactory(), "select count() from 'test-import.csv'"), getFactory()); - TestUtils.assertEquals("3\n", sink); - } finally { - server.halt(); - } - } - - @Test - public void testImportNumberPrefixedColumn() throws Exception { - final ServerConfiguration configuration = new ServerConfiguration(); - BootstrapEnv env = new BootstrapEnv(); - env.configuration = configuration; - env.factory = getFactory(); - env.typeProbeCollection = TYPE_PROBE_COLLECTION; - env.matcher = new SimpleUrlMatcher() {{ - put("/imp", new ImportHandler(env)); - }}; - - HttpServer server = new HttpServer(env); - server.start(); - - try { - Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import-num-prefix.csv", "http://localhost:9000/imp?fmt=json", null, null)); - StringSink sink = new StringSink(); - RecordSourcePrinter printer = new RecordSourcePrinter(sink); - QueryCompiler qc = new QueryCompiler(env); - try (RecordSource rs = qc.compile(env.factory, "select count(StrSym), count(IntSym), count(_1IntCol), count(long), count() from 'test-import-num-prefix.csv'")) { - printer.print(rs, env.factory); - } - TestUtils.assertEquals("126\t126\t128\t129\t129\n", sink); - } finally { - server.halt(); - } - } - - @Test - public void testImportNumericHeader() throws Exception { - BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(); - env.factory = getFactory(); - env.typeProbeCollection = TYPE_PROBE_COLLECTION; - env.matcher = new SimpleUrlMatcher() {{ - put("/imp", new ImportHandler(env)); - }}; - - HttpServer server = new HttpServer(env); - server.start(); - - try { - StringSink sink = new StringSink(); - RecordSourcePrinter printer = new RecordSourcePrinter(sink); - QueryCompiler qc = new QueryCompiler(env); - - Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-numeric-headers.csv", "http://localhost:9000/imp?name=test-import.csv&overwrite=true&durable=true&forceHeader=true", null, null)); - printer.print(qc.compile(getFactory(), "select count() from 'test-import.csv'"), getFactory()); - // expect first line to be treated as header - TestUtils.assertEquals("2\n", sink); - } finally { - server.halt(); - } - } - - @Test - @Ignore - public void testImportOverwrite() throws Exception { - final ServerConfiguration configuration = new ServerConfiguration(); - BootstrapEnv env = new BootstrapEnv(); - env.configuration = configuration; - env.factory = getFactory(); - env.typeProbeCollection = TYPE_PROBE_COLLECTION; - env.matcher = new SimpleUrlMatcher() {{ - put("/imp", new ImportHandler(env)); - }}; - - HttpServer server = new HttpServer(env); - server.start(); - - try { - StringSink sink = new StringSink(); - RecordSourcePrinter printer = new RecordSourcePrinter(sink); - QueryCompiler qc = new QueryCompiler(env); - Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import.csv", "http://localhost:9000/imp", null, null)); - printer.print(qc.compile(getFactory(), "select count() from 'test-import.csv'"), getFactory()); - TestUtils.assertEquals("129\n", sink); - sink.clear(); - - Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-headers.csv", "http://localhost:9000/imp?name=test-import.csv&overwrite=true&durable=true", null, null)); - printer.print(qc.compile(getFactory(), "select count() from 'test-import.csv'"), getFactory()); - TestUtils.assertEquals("5\n", sink); - } finally { - server.halt(); - } - } - - @Test - public void testImportUnknownFormat() { - BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(); - env.factory = getFactory(); - env.matcher = new SimpleUrlMatcher() {{ - put("/imp", new ImportHandler(env)); - }}; - - HttpServer server = new HttpServer(env); - - server.start(); - StringBuilder response = new StringBuilder(); - try { - Assert.assertEquals(400, HttpTestUtils.upload("/com/questdb/std/AssociativeCache.class", "http://localhost:9000/imp", null, response)); - TestUtils.assertEquals("Unsupported Data Format", response); - } catch (IOException e) { - Assert.assertTrue(e.getMessage().contains("Connection reset")); - } finally { - server.halt(); - } - } - - @Test - public void testImportUtf8() throws Exception { - - BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(); - env.factory = getFactory(); - env.typeProbeCollection = TYPE_PROBE_COLLECTION; - env.matcher = new SimpleUrlMatcher() {{ - put("/imp", new ImportHandler(env)); - }}; - HttpServer server = new HttpServer(env); - server.start(); - - try { - StringSink sink = new StringSink(); - RecordSourcePrinter printer = new RecordSourcePrinter(sink); - QueryCompiler qc = new QueryCompiler(env); - - Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import-utf8.csv", "http://localhost:9000/imp?overwrite=true&durable=true", null, null)); - printer.print(qc.compile(getFactory(), "'test-import-utf8.csv'"), getFactory()); - // expect first line to be treated as header - TestUtils.assertEquals("авг\tавг\n", sink); - } finally { - server.halt(); - } - } - - @Test - public void testImportWrongType() throws Exception { - BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(); - env.factory = getFactory(); - env.typeProbeCollection = TYPE_PROBE_COLLECTION; - env.dateLocaleFactory = DateLocaleFactory.INSTANCE; - env.dateFormatFactory = DATE_FORMAT_FACTORY; - env.matcher = new SimpleUrlMatcher() {{ - put("/imp", new ImportHandler(env)); - }}; - - HttpServer server = new HttpServer(env); - - server.start(); - - try { - Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import.csv", "http://localhost:9000/imp?fmt=json", "[{\"name\":\"IsoDate\", \"type\":\"DATE\"}, {\"name\":\"IntCol\", \"type\":\"DOUBLE\"}]", null)); - Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import.csv", "http://localhost:9000/imp", "[{\"name\":\"IsoDate\", \"type\":\"DATE\"}]", null)); - StringSink sink = new StringSink(); - RecordSourcePrinter printer = new RecordSourcePrinter(sink); - QueryCompiler qc = new QueryCompiler(env); - RecordSource src1 = qc.compile(env.factory, "select count(StrSym), count(IntSym), count(IntCol), count(long), count() from 'test-import.csv'"); - try { - printer.print(src1, env.factory); - TestUtils.assertEquals("252\t252\t256\t258\t258\n", sink); - } finally { - Misc.free(src1); - } - - RecordSource src2 = qc.compile(env.factory, "'test-import.csv'"); - try { - Assert.assertEquals(ColumnType.DOUBLE, src2.getMetadata().getColumn("IntCol").getType()); - } finally { - Misc.free(src2); - } - } finally { - server.halt(); - } - } - - @Test - public void testImportWrongTypeStrictAtomicity() throws Exception { - BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(); - env.factory = getFactory(); - env.typeProbeCollection = TYPE_PROBE_COLLECTION; - env.matcher = new SimpleUrlMatcher() {{ - put("/imp", new ImportHandler(env)); - }}; - env.dateLocaleFactory = DateLocaleFactory.INSTANCE; - env.dateFormatFactory = DATE_FORMAT_FACTORY; - - HttpServer server = new HttpServer(env); - - server.start(); - - try { - Assert.assertEquals(400, HttpTestUtils.upload( - "/csv/test-import.csv", - "http://localhost:9000/imp?atomicity=strict", - "[{\"name\":\"IsoDate\", \"type\":\"DATE\"}, {\"name\":\"IntCol\", \"type\":\"DATE\"}]", - null)); - StringSink sink = new StringSink(); - RecordSourcePrinter printer = new RecordSourcePrinter(sink); - QueryCompiler qc = new QueryCompiler(env); - RecordSource src1 = qc.compile(env.factory, "select count() from 'test-import.csv'"); - try { - printer.print(src1, env.factory); - TestUtils.assertEquals("0\n", sink); - } finally { - Misc.free(src1); - } - } finally { - server.halt(); - } - } - - @Test - public void testLargeChunkedPlainDownload() throws Exception { - final int count = 3; - final int sz = 16 * 1026 * 1024 - 4; - ServerConfiguration conf = new ServerConfiguration(); - conf.setHttpBufRespContent(sz + 4); - TestUtils.assertEquals(generateLarge(count, sz), downloadChunked(conf, count, sz, false, false)); - } - - @Test - public void testLargeChunkedPlainGzipDownload() throws Exception { - final int count = 3; - final int sz = 16 * 1026 * 1024 - 4; - ServerConfiguration conf = new ServerConfiguration(); - conf.setHttpBufRespContent(sz + 4); - TestUtils.assertEquals(generateLarge(count, sz), downloadChunked(conf, count, sz, false, true)); - } - - @Test - public void testLargeChunkedSSLDownload() throws Exception { - final int count = 3; - final int sz = 16 * 1026 * 1024 - 4; - final ServerConfiguration configuration = new ServerConfiguration(new File(resourceFile("/site"), "conf/questdb.conf")); - configuration.getSslConfig().setSecure(true); - configuration.getSslConfig().setKeyStore(new FileInputStream(resourceFile("/keystore/singlekey.ks")), "changeit"); - configuration.setHttpBufRespContent(sz + 4); - TestUtils.assertEquals(generateLarge(count, sz), downloadChunked(configuration, count, sz, true, false)); - } - - @Test - public void testLargeChunkedSSLGzipDownload() throws Exception { - final int count = 3; - final int sz = 16 * 1026 * 1024 - 4; - final ServerConfiguration configuration = new ServerConfiguration(new File(resourceFile("/site"), "conf/questdb.conf")); - configuration.getSslConfig().setSecure(true); - configuration.getSslConfig().setKeyStore(new FileInputStream(resourceFile("/keystore/singlekey.ks")), "changeit"); - configuration.setHttpBufRespContent(sz + 4); - TestUtils.assertEquals(generateLarge(count, sz), downloadChunked(configuration, count, sz, true, true)); - } - - @Test - @Ignore - // this test fails intermittently, wont fix, this is outgoing code - public void testMaxConnections() throws Exception { - final ServerConfiguration configuration = new ServerConfiguration(new File(resourceFile("/site"), "conf/questdb.conf")); - BootstrapEnv env = new BootstrapEnv(); - env.configuration = configuration; - env.configuration.setHttpMaxConnections(1); - env.matcher = new SimpleUrlMatcher() {{ - setDefaultHandler(new StaticContentHandler(env)); - }}; - HttpServer server = new HttpServer(env); - server.start(); - - try { - Assert.assertNotNull(clientBuilder(true).build().execute(new HttpGet("https://localhost:9000/upload.html"))); - try { - clientBuilder(true).build().execute(new HttpGet("https://localhost:9000/upload.html")); - Assert.fail("Expected server to reject connection"); - } catch (Exception ignored) { - - } - } finally { - server.halt(); - } - } - - @Test - public void testNativeConcurrentDownload() throws Exception { - final ServerConfiguration configuration = new ServerConfiguration(new File(resourceFile("/site"), "conf/questdb.conf")); - BootstrapEnv env = new BootstrapEnv(); - env.configuration = configuration; - env.configuration.getSslConfig().setSecure(false); - env.matcher = new SimpleUrlMatcher() {{ - setDefaultHandler(new StaticContentHandler(env)); - }}; - HttpServer server = new HttpServer(env); - server.start(); - assertConcurrentDownload(server, "http"); - } - - @Test - public void testNativeNotModified() throws Exception { - BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(new File(resourceFile("/site"), "conf/questdb.conf")); - env.configuration.getSslConfig().setSecure(false); - env.matcher = new SimpleUrlMatcher() {{ - setDefaultHandler(new StaticContentHandler(env)); - }}; - assertNotModified(new HttpServer(env)); - } - - @Test - // this test intermittently fails on fedora 25 - // at the same tie it works consistently on OSX and windows - // problem seems to be either with loopback interface and/or kernel - // symptoms are: http client is in blocking write to socket, server epoll triggers fd, but - // recv(fd) returns -1 and EWOULDBLOCK and this goes on forever with epoll keep firing fd that has nothing to show - // fix is in server, which would allow limited number of this iterations after which connection is closed. - @Ignore - public void testRangesNative() throws Exception { - BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(new File(HttpServerTest.class.getResource("/site").getPath(), "conf/questdb.conf")) { - @Override - public File getHttpPublic() { - return temp.getRoot(); - } - }; - env.configuration.setHttpThreads(1); - env.configuration.setHttpSoRetries(10); - env.configuration.getSslConfig().setSecure(false); - env.matcher = new SimpleUrlMatcher() {{ - put("/upload", new UploadHandler(env.configuration.getHttpPublic())); - setDefaultHandler(new StaticContentHandler(env)); - }}; - - assertRanges(new HttpServer(env)); - } - - @Test - public void testSslConcurrentDownload() throws Exception { - BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(new File(resourceFile("/site"), "conf/questdb.conf")); - env.configuration.getSslConfig().setSecure(true); - env.configuration.getSslConfig().setKeyStore(new FileInputStream(resourceFile("/keystore/singlekey.ks")), "changeit"); - env.matcher = new SimpleUrlMatcher() {{ - setDefaultHandler(new StaticContentHandler(env)); - }}; - - HttpServer server = new HttpServer(env); - server.start(); - assertConcurrentDownload(server, "https"); - } - - @Test - public void testStartStop() { - BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(); - env.matcher = new SimpleUrlMatcher(); - HttpServer server = new HttpServer(env); - server.start(); - server.halt(); - } - - @Test - public void testUpload() throws Exception { - final File dir = temp.newFolder(); - BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(); - env.matcher = new SimpleUrlMatcher() {{ - put("/upload", new UploadHandler(dir)); - }}; - - HttpServer server = new HttpServer(env); - server.start(); - - File expected = resourceFile("/csv/test-import.csv"); - File actual = new File(dir, "test-import.csv"); - upload(expected); - - TestUtils.assertEquals(expected, actual); - server.halt(); - } - - private static HttpClientBuilder clientBuilder(boolean ssl) throws Exception { - return (ssl ? createHttpClient_AcceptsUntrustedCerts() : HttpClientBuilder.create()); - } - - private static HttpClientBuilder createHttpClient_AcceptsUntrustedCerts() throws Exception { - HttpClientBuilder b = HttpClientBuilder.create(); - - // setup a Trust Strategy that allows all certificates. - // - SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, (arg0, arg1) -> true).build(); - - b.setSSLContext(sslContext); - - // here's the special part: - // -- need to create an SSL Socket Factory, to use our weakened "trust strategy"; - // -- and create a Registry, to register it. - // - SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, (s, sslSession) -> true); - Registry socketFactoryRegistry = RegistryBuilder.create() - .register("http", PlainConnectionSocketFactory.getSocketFactory()) - .register("https", sslSocketFactory) - .build(); - - // now, we create connection-manager using our Registry. - // -- allows multi-threaded use - b.setConnectionManager(new PoolingHttpClientConnectionManager(socketFactoryRegistry)); - - return b; - } - - - private static File resourceFile(String resource) { - return new File(HttpServerTest.class.getResource(resource).getFile()); - } - - private static void upload(File file) throws IOException { - HttpPost post = new HttpPost("http://localhost:9000/upload"); - try (CloseableHttpClient client = HttpClients.createDefault()) { - MultipartEntityBuilder b = MultipartEntityBuilder.create(); - b.addPart("data", new FileBody(file)); - post.setEntity(b.build()); - client.execute(post); - } - } - - private void assertConcurrentDownload(HttpServer server, final String proto) throws InterruptedException, IOException { - try { - - // ssl - - final File actual1 = new File(temp.getRoot(), "get.html"); - final File actual2 = new File(temp.getRoot(), "post.html"); - final File actual3 = new File(temp.getRoot(), "upload.html"); - - final CyclicBarrier barrier = new CyclicBarrier(3); - final CountDownLatch haltLatch = new CountDownLatch(3); - - final AtomicInteger counter = new AtomicInteger(0); - - new Thread(() -> { - try { - barrier.await(); - HttpTestUtils.download(clientBuilder("https".equals(proto)), proto + "://localhost:9000/get.html", actual1); - } catch (Exception e) { - counter.incrementAndGet(); - e.printStackTrace(); - } finally { - haltLatch.countDown(); - } - }).start(); - - - new Thread(() -> { - try { - barrier.await(); - HttpTestUtils.download(clientBuilder("https".equals(proto)), proto + "://localhost:9000/post.html", actual2); - } catch (Exception e) { - counter.incrementAndGet(); - e.printStackTrace(); - } finally { - haltLatch.countDown(); - } - }).start(); - - new Thread(() -> { - try { - barrier.await(); - HttpTestUtils.download(clientBuilder("https".equals(proto)), proto + "://localhost:9000/upload.html", actual3); - } catch (Exception e) { - counter.incrementAndGet(); - e.printStackTrace(); - } finally { - haltLatch.countDown(); - } - }).start(); - - haltLatch.await(); - - Assert.assertEquals(0, counter.get()); - TestUtils.assertEquals(new File(HttpServerTest.class.getResource("/site/public/get.html").getPath()), actual1); - TestUtils.assertEquals(new File(HttpServerTest.class.getResource("/site/public/post.html").getPath()), actual2); - TestUtils.assertEquals(new File(HttpServerTest.class.getResource("/site/public/upload.html").getPath()), actual3); - - } finally { - server.halt(); - } - } - - private void assertNotModified(HttpServer server) throws IOException { - server.start(); - try { - File out = new File(temp.getRoot(), "get.html"); - HttpGet get = new HttpGet("http://localhost:9000/get.html"); - - try (CloseableHttpClient client = HttpClients.createDefault()) { - - Header h; - try ( - CloseableHttpResponse r = client.execute(get); - FileOutputStream fos = new FileOutputStream(out) - ) { - HttpTestUtils.copy(r.getEntity().getContent(), fos); - Assert.assertEquals(200, r.getStatusLine().getStatusCode()); - h = HttpTestUtils.findHeader("ETag", r.getAllHeaders()); - } - - Assert.assertNotNull(h); - get.addHeader("If-None-Match", h.getValue()); - - try (CloseableHttpResponse r = client.execute(get)) { - Assert.assertEquals(304, r.getStatusLine().getStatusCode()); - } - } - } finally { - server.halt(); - } - } - - private void assertRanges(HttpServer server) throws IOException { - server.start(); - try { - - HttpTestUtils.upload("/large.csv", "http://localhost:9000/upload", null, null); - - File out = new File(temp.getRoot(), "out.csv"); - - HttpGet get = new HttpGet("http://localhost:9000/large.csv?attachment"); - get.addHeader("Range", "xyz"); - - try (CloseableHttpClient client = HttpClients.createDefault()) { - - try (CloseableHttpResponse r = client.execute(get)) { - Assert.assertEquals(416, r.getStatusLine().getStatusCode()); - } - - File f = resourceFile("/large.csv"); - long size; - - try (FileInputStream is = new FileInputStream(f)) { - size = is.available(); - } - - long part = size / 2; - - - try (FileOutputStream fos = new FileOutputStream(out)) { - - // first part - get.addHeader("Range", "bytes=0-" + part); - try (CloseableHttpResponse r = client.execute(get)) { - HttpTestUtils.copy(r.getEntity().getContent(), fos); - Assert.assertEquals(206, r.getStatusLine().getStatusCode()); - } - - // second part - get.addHeader("Range", "bytes=" + part + "-"); - try (CloseableHttpResponse r = client.execute(get)) { - HttpTestUtils.copy(r.getEntity().getContent(), fos); - Assert.assertEquals(206, r.getStatusLine().getStatusCode()); - } - } - - TestUtils.assertEquals(f, out); - } - } finally { - server.halt(); - } - } - - private File downloadChunked(ServerConfiguration conf, final int count, final int sz, boolean ssl, final boolean compressed) throws Exception { - BootstrapEnv env = new BootstrapEnv(); - env.configuration = conf; - env.matcher = new SimpleUrlMatcher() {{ - - put("/test", new ContextHandler() { - - private int counter = -1; - - @Override - public void handle(IOContext context) throws IOException { - ChunkedResponse r = context.chunkedResponse(); - r.setCompressed(compressed); - r.status(200, "text/plain; charset=utf-8"); - r.sendHeader(); - counter = -1; - resume(context); - } - - @Override - public void resume(IOContext context) throws IOException { - ChunkedResponse r = context.chunkedResponse(); - for (int i = counter + 1; i < count; i++) { - counter = i; - try { - for (int k = 0; k < sz; k++) { - Numbers.append(r, i); - } - r.put(Misc.EOL); - } catch (ResponseContentBufferTooSmallException ignore) { - // ignore, send as much as we can in one chunk - LOG.error().$("Response content buffer is too small").$(); - } - r.sendChunk(); - } - r.done(); - } - - @Override - public void setupThread() { - } - }); - }}; - - HttpServer server = new HttpServer(env); - File out = temp.newFile(); - server.start(); - try { - HttpTestUtils.download(clientBuilder(ssl), (ssl ? "https" : "http") + "://localhost:9000/test", out); - } finally { - server.halt(); - } - - return out; - } - - private File generateLarge(int count, int sz) throws IOException { - File file = temp.newFile(); - try (FileSink sink = new FileSink(file)) { - for (int i = 0; i < count; i++) { - for (int k = 0; k < sz; k++) { - Numbers.append(sink, i); - } - sink.put(Misc.EOL); - } - } - return file; - } - - private SocketChannel openChannel() throws IOException { - InetSocketAddress address = new InetSocketAddress("localhost", 9000); - SocketChannel channel = SocketChannel.open() - .setOption(StandardSocketOptions.TCP_NODELAY, Boolean.TRUE); - - channel.configureBlocking(false); - try { - channel.connect(address); - long t = System.currentTimeMillis(); - - while (!channel.finishConnect()) { - LockSupport.parkNanos(500000L); - if (System.currentTimeMillis() - t > (long) 5000) { - throw new IOException("Connection timeout"); - } - } - - channel.configureBlocking(true); - return channel; - } catch (IOException e) { - channel.close(); - throw e; - } - } -} diff --git a/core/src/test/java/com/questdb/net/http/handlers/QueryHandlerConsistencyTest.java b/core/src/test/java/com/questdb/net/http/handlers/QueryHandlerConsistencyTest.java deleted file mode 100644 index 36a16e241..000000000 --- a/core/src/test/java/com/questdb/net/http/handlers/QueryHandlerConsistencyTest.java +++ /dev/null @@ -1,215 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.http.handlers; - -import com.questdb.BootstrapEnv; -import com.questdb.ServerConfiguration; -import com.questdb.net.http.ContextHandler; -import com.questdb.net.http.IOContext; -import com.questdb.parser.sql.AbstractOptimiserTest; -import com.questdb.std.time.MillisecondClockImpl; -import com.questdb.test.tools.TestChannel; -import com.questdb.test.tools.TestUtils; -import org.junit.BeforeClass; -import org.junit.Test; - -public class QueryHandlerConsistencyTest extends AbstractOptimiserTest { - private static final String QUERY1 = "GET /js?query=%27xyz%27&limit=0%2C1000&count=true HTTP/1.1\n" + - "Host: localhost:9000\r\n" + - "Connection: keep-alive\r\n" + - "Accept: */*\r\n" + - "X-Requested-With: XMLHttpRequest\r\n" + - "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36\r\n" + - "Referer: http://localhost:9000/index.html\r\n" + - "Accept-Encoding: gzip, deflate, sdch\r\n" + - "Accept-Language: en-US,en;q=0.8,ru;q=0.6\r\n" + - "Cookie: _ga=GA1.1.825719031.1458963361\r\n" + - "\r\n"; - - @BeforeClass - public static void setUp() throws Exception { - QueryHandlerTest.generateJournal("xyz", 100); - } - - @Test - public void testCsvHandlerConsistency() throws Exception { - BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(); - env.factory = FACTORY_CONTAINER.getFactory(); - testHandler(new CsvHandler(env)); - } - - @Test - public void testCsvOutput() throws Exception { - BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(); - env.factory = FACTORY_CONTAINER.getFactory(); - ContextHandler handler = new CsvHandler(env); - handler.setupThread(); - TestChannel channel = new TestChannel(QUERY1); - String expected = "\"id\",\"x\",\"y\",\"z\",\"w\",\"timestamp\"\r\n" + - "id0,0.0000000019,0.0000011892,-498,171,\"2015-03-12T00:00:00.000Z\"\r\n" + - "id1,0.0066887384,0.0244944207,-339,12,\"2015-03-12T00:00:00.010Z\"\r\n" + - "id2,-432.0000000000,0.2932029516,216,-197,\"2015-03-12T00:00:00.020Z\"\r\n" + - "id3,768.0000000000,,-227,-464,\"2015-03-12T00:00:00.030Z\"\r\n" + - "id4,7.0894718170,0.0000007417,353,228,\"2015-03-12T00:00:00.040Z\"\r\n" + - "id5,920.6250000000,,197,0,\"2015-03-12T00:00:00.050Z\"\r\n" + - "id6,13.7327423096,54.0429687500,-40,-247,\"2015-03-12T00:00:00.060Z\"\r\n" + - "id7,12.9238665104,,-339,-319,\"2015-03-12T00:00:00.070Z\"\r\n" + - "id8,384.0723876953,0.0005276347,10,2,\"2015-03-12T00:00:00.080Z\"\r\n" + - "id9,0.0000000173,,-359,263,\"2015-03-12T00:00:00.090Z\"\r\n" + - "id10,0.0115543692,0.0473926794,409,167,\"2015-03-12T00:00:00.100Z\"\r\n" + - "id11,0.0011654748,0.0000000089,-211,-395,\"2015-03-12T00:00:00.110Z\"\r\n" + - "id12,0.0000001961,-484.0000000000,356,124,\"2015-03-12T00:00:00.120Z\"\r\n" + - "id13,0.5831662863,942.8994140625,247,1,\"2015-03-12T00:00:00.130Z\"\r\n" + - "id14,-249.0703125000,-735.6542968750,288,-121,\"2015-03-12T00:00:00.140Z\"\r\n" + - "id15,-607.9462890625,,327,-319,\"2015-03-12T00:00:00.150Z\"\r\n" + - "id16,0.0004250098,0.0000015750,-311,-302,\"2015-03-12T00:00:00.160Z\"\r\n" + - "id17,0.0000000921,-186.0000000000,,-113,\"2015-03-12T00:00:00.170Z\"\r\n" + - "id18,0.0000000209,0.0154700107,191,-260,\"2015-03-12T00:00:00.180Z\"\r\n" + - "id19,0.0608360972,0.0073713257,-168,355,\"2015-03-12T00:00:00.190Z\"\r\n" + - "id20,768.0000000000,300.1632385254,31,282,\"2015-03-12T00:00:00.200Z\"\r\n" + - "id21,770.3593750000,0.4610133618,-42,-332,\"2015-03-12T00:00:00.210Z\"\r\n" + - "id22,0.0000002364,0.0002006101,-208,-190,\"2015-03-12T00:00:00.220Z\"\r\n" + - "id23,0.1907100230,0.0004840687,410,-392,\"2015-03-12T00:00:00.230Z\"\r\n" + - "id24,-663.0000000000,0.0000302110,-199,428,\"2015-03-12T00:00:00.240Z\"\r\n" + - "id25,0.0000261224,-296.5444335938,-20,-320,\"2015-03-12T00:00:00.250Z\"\r\n" + - "id26,-100.0000000000,-915.7968750000,,85,\"2015-03-12T00:00:00.260Z\"\r\n" + - "id27,0.0000025266,,38,-213,\"2015-03-12T00:00:00.270Z\"\r\n" + - "id28,0.0000320606,0.0006038445,243,-32,\"2015-03-12T00:00:00.280Z\"\r\n" + - "id29,-352.0000000000,0.0000710208,172,-261,\"2015-03-12T00:00:00.290Z\"\r\n" + - "id30,238.6328125000,134.6630859375,-379,-352,\"2015-03-12T00:00:00.300Z\"\r\n" + - "id31,0.0000001943,0.0003494991,416,-97,\"2015-03-12T00:00:00.310Z\"\r\n" + - "id32,0.0000000139,-1024.0000000000,-200,348,\"2015-03-12T00:00:00.320Z\"\r\n" + - "id33,128.0000000000,0.0011758586,-20,392,\"2015-03-12T00:00:00.330Z\"\r\n" + - "id34,26.6128172874,,,169,\"2015-03-12T00:00:00.340Z\"\r\n" + - "id35,-224.0770263672,599.0283203125,207,-340,\"2015-03-12T00:00:00.350Z\"\r\n" + - "id36,0.0175354201,832.0000000000,,32,\"2015-03-12T00:00:00.360Z\"\r\n" + - "id37,3.9599943161,-69.9140625000,-497,-220,\"2015-03-12T00:00:00.370Z\"\r\n" + - "id38,-200.0000000000,-568.0000000000,-434,76,\"2015-03-12T00:00:00.380Z\"\r\n" + - "id39,708.4023437500,0.0000000019,,-478,\"2015-03-12T00:00:00.390Z\"\r\n" + - "id40,585.2304687500,736.0000000000,140,-237,\"2015-03-12T00:00:00.400Z\"\r\n" + - "id41,0.0000000141,0.0046403678,-126,-91,\"2015-03-12T00:00:00.410Z\"\r\n" + - "id42,15.7132420540,-1018.5878906250,389,399,\"2015-03-12T00:00:00.420Z\"\r\n" + - "id43,386.8437500000,296.6113433838,,-4,\"2015-03-12T00:00:00.430Z\"\r\n" + - "id44,5.5901532173,-640.0000000000,,-494,\"2015-03-12T00:00:00.440Z\"\r\n" + - "id45,0.0000002490,0.0000024573,,321,\"2015-03-12T00:00:00.450Z\"\r\n" + - "id46,0.0000021166,488.0937500000,-10,387,\"2015-03-12T00:00:00.460Z\"\r\n" + - "id47,0.0000000154,0.0256510917,342,-229,\"2015-03-12T00:00:00.470Z\"\r\n" + - "id48,0.0000430228,0.6112449020,-26,-472,\"2015-03-12T00:00:00.480Z\"\r\n" + - "id49,0.0000124788,,343,147,\"2015-03-12T00:00:00.490Z\"\r\n" + - "id50,0.0454099961,1.4611321092,-236,-164,\"2015-03-12T00:00:00.500Z\"\r\n" + - "id51,0.0050167134,77.8403434753,-498,-177,\"2015-03-12T00:00:00.510Z\"\r\n" + - "id52,-416.0000000000,0.0000363594,-478,-425,\"2015-03-12T00:00:00.520Z\"\r\n" + - "id53,0.0046469892,281.7617187500,361,-201,\"2015-03-12T00:00:00.530Z\"\r\n" + - "id54,-33.7500000000,-690.2343750000,-356,64,\"2015-03-12T00:00:00.540Z\"\r\n" + - "id55,0.0000000000,0.0000001103,,-380,\"2015-03-12T00:00:00.550Z\"\r\n" + - "id56,8.0390167236,-857.6875000000,499,-275,\"2015-03-12T00:00:00.560Z\"\r\n" + - "id57,21.3488283157,-448.0000000000,120,459,\"2015-03-12T00:00:00.570Z\"\r\n" + - "id58,0.0000000025,,,49,\"2015-03-12T00:00:00.580Z\"\r\n" + - "id59,300.0937500000,,-98,-30,\"2015-03-12T00:00:00.590Z\"\r\n" + - "id60,501.0677947998,0.0030514880,432,-306,\"2015-03-12T00:00:00.600Z\"\r\n" + - "id61,0.1273584887,,-244,-311,\"2015-03-12T00:00:00.610Z\"\r\n" + - "id62,740.9882812500,0.0000000720,468,14,\"2015-03-12T00:00:00.620Z\"\r\n" + - "id63,0.0406596940,0.0000005046,223,403,\"2015-03-12T00:00:00.630Z\"\r\n" + - "id64,0.0000491961,-272.0000000000,-281,80,\"2015-03-12T00:00:00.640Z\"\r\n" + - "id65,0.3140142038,512.0000000000,-225,-148,\"2015-03-12T00:00:00.650Z\"\r\n" + - "id66,0.0055695465,0.0273376359,195,-193,\"2015-03-12T00:00:00.660Z\"\r\n" + - "id67,-512.0000000000,-844.0000000000,-135,307,\"2015-03-12T00:00:00.670Z\"\r\n" + - "id68,428.0000000000,-608.0000000000,-76,415,\"2015-03-12T00:00:00.680Z\"\r\n" + - "id69,-512.0000000000,894.7187500000,402,-362,\"2015-03-12T00:00:00.690Z\"\r\n" + - "id70,-283.1583251953,832.0000000000,367,-372,\"2015-03-12T00:00:00.700Z\"\r\n" + - "id71,1.1517004967,97.2561187744,-76,-457,\"2015-03-12T00:00:00.710Z\"\r\n" + - "id72,768.0000000000,768.0000000000,403,399,\"2015-03-12T00:00:00.720Z\"\r\n" + - "id73,32.0000000000,174.4927864075,448,-158,\"2015-03-12T00:00:00.730Z\"\r\n" + - "id74,934.1573791504,4.1113085747,380,320,\"2015-03-12T00:00:00.740Z\"\r\n" + - "id75,-228.0015869141,0.0066470259,132,105,\"2015-03-12T00:00:00.750Z\"\r\n" + - "id76,0.0021495742,0.0000005019,-91,-31,\"2015-03-12T00:00:00.760Z\"\r\n" + - "id77,19.7567439079,0.0000903588,412,-435,\"2015-03-12T00:00:00.770Z\"\r\n" + - "id78,-1018.3125000000,0.0000000076,-371,60,\"2015-03-12T00:00:00.780Z\"\r\n" + - "id79,-998.3625488281,380.4352569580,430,150,\"2015-03-12T00:00:00.790Z\"\r\n" + - "id80,0.0000762123,-864.8203125000,-327,-106,\"2015-03-12T00:00:00.800Z\"\r\n" + - "id81,288.0000000000,-64.0000000000,-170,385,\"2015-03-12T00:00:00.810Z\"\r\n" + - "id82,6.0128862858,-498.3359375000,405,-87,\"2015-03-12T00:00:00.820Z\"\r\n" + - "id83,64.0000000000,,414,-99,\"2015-03-12T00:00:00.830Z\"\r\n" + - "id84,18.8347930908,-768.0000000000,271,-29,\"2015-03-12T00:00:00.840Z\"\r\n" + - "id85,0.0025632520,640.0000000000,187,-300,\"2015-03-12T00:00:00.850Z\"\r\n" + - "id86,0.0000000072,768.0000000000,-161,165,\"2015-03-12T00:00:00.860Z\"\r\n" + - "id87,0.0000997469,74.7576007843,-139,25,\"2015-03-12T00:00:00.870Z\"\r\n" + - "id88,8.9508481026,15.2402491570,270,331,\"2015-03-12T00:00:00.880Z\"\r\n" + - "id89,0.0407589767,0.0025454164,-15,18,\"2015-03-12T00:00:00.890Z\"\r\n" + - "id90,-642.0000000000,0.0191786536,-164,57,\"2015-03-12T00:00:00.900Z\"\r\n" + - "id91,391.0000000000,0.0000766759,-308,94,\"2015-03-12T00:00:00.910Z\"\r\n" + - "id92,0.0000116505,-220.9241943359,-207,-221,\"2015-03-12T00:00:00.920Z\"\r\n" + - "id93,0.0000000039,-486.9859619141,-479,393,\"2015-03-12T00:00:00.930Z\"\r\n" + - "id94,0.0000383980,0.3997064978,,-338,\"2015-03-12T00:00:00.940Z\"\r\n" + - "id95,-628.5000000000,,352,-462,\"2015-03-12T00:00:00.950Z\"\r\n" + - "id96,-125.0000000000,849.2207031250,490,132,\"2015-03-12T00:00:00.960Z\"\r\n" + - "id97,-162.5000000000,815.0000000000,-297,-414,\"2015-03-12T00:00:00.970Z\"\r\n" + - "id98,0.0001471960,0.2934677303,-284,-357,\"2015-03-12T00:00:00.980Z\"\r\n" + - "id99,-384.0000000000,0.0000000980,-264,355,\"2015-03-12T00:00:00.990Z\"\r\n"; - try { - channel.reset(); - try (IOContext context = new IOContext(channel, new ServerConfiguration(), MillisecondClockImpl.INSTANCE)) { - context.request.read(); - handler.handle(context); - TestUtils.assertEquals(expected, channel.getOutput()); - } - } finally { - channel.free(); - } - } - - @Test - public void testQueryHandlerConsistency() throws Exception { - BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(); - env.factory = FACTORY_CONTAINER.getFactory(); - testHandler(new QueryHandler(env)); - } - - private void testHandler(ContextHandler handler) throws Exception { - TestChannel channel = new TestChannel(QUERY1); - String expected = null; - handler.setupThread(); - try { - ServerConfiguration configuration = new ServerConfiguration(); - for (int i = 128; i < 7500; i++) { - channel.reset(); - configuration.setHttpBufRespContent(i); - try (IOContext context = new IOContext(channel, configuration, MillisecondClockImpl.INSTANCE)) { - context.request.read(); - handler.handle(context); - if (expected != null) { - TestUtils.assertEquals(expected, channel.getOutput()); - } else { - expected = channel.getOutput().toString(); - } - } - } - } finally { - channel.free(); - } - } -} diff --git a/core/src/test/java/com/questdb/net/http/handlers/QueryHandlerSmallBufferTest.java b/core/src/test/java/com/questdb/net/http/handlers/QueryHandlerSmallBufferTest.java deleted file mode 100644 index b91d6ba77..000000000 --- a/core/src/test/java/com/questdb/net/http/handlers/QueryHandlerSmallBufferTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2019 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.http.handlers; - -import com.google.gson.JsonSyntaxException; -import com.questdb.BootstrapEnv; -import com.questdb.ServerConfiguration; -import com.questdb.net.http.HttpServer; -import com.questdb.net.http.QueryResponse; -import com.questdb.net.http.SimpleUrlMatcher; -import com.questdb.parser.sql.AbstractOptimiserTest; -import org.apache.http.MalformedChunkCodingException; -import org.junit.*; -import org.junit.rules.TemporaryFolder; - -import java.sql.Timestamp; - -@Ignore -public class QueryHandlerSmallBufferTest extends AbstractOptimiserTest { - - @ClassRule - public static final TemporaryFolder temp = new TemporaryFolder(); - private static final int RECORD_COUNT = 10000; - private static HttpServer server; - private static QueryHandler handler; - - @BeforeClass - public static void setUp() throws Exception { - BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(); - env.configuration.setHttpBufRespContent(128); - env.factory = FACTORY_CONTAINER.getFactory(); - - handler = new QueryHandler(env); - - env.matcher = new SimpleUrlMatcher() {{ - put("/js", handler); - }}; - - server = new HttpServer(env); - - server.start(); - QueryHandlerTest.generateJournal("large", RECORD_COUNT); - } - - @AfterClass - public static void tearDown2() { - server.halt(); - } - - @Test(expected = MalformedChunkCodingException.class) - public void testColumnValueTooLargeForBuffer() throws Exception { - StringBuilder allChars = new StringBuilder(); - for (char c = Character.MIN_VALUE; c < 0xD800; c++) { // - allChars.append(c); - } - - String allCharString = allChars.toString(); - QueryHandlerTest.generateJournal("xyz", allCharString, 4.900232E-10, 2.598E20, Long.MAX_VALUE, Integer.MIN_VALUE, new Timestamp(-102023)); - String query = "select x, id from xyz \n limit 1"; - QueryHandlerTest.download(query, temp); - } - - @Test - public void testJsonChunkOverflow() throws Exception { - QueryResponse queryResponse = QueryHandlerTest.download("large", temp); - Assert.assertEquals(RECORD_COUNT, queryResponse.dataset.size()); - } - - @Test(expected = JsonSyntaxException.class) - public void testQuerySizeTooLargeForBuffer() throws Exception { - StringBuilder b1 = new StringBuilder(); - StringBuilder b2 = new StringBuilder(); - StringBuilder b = b1; - StringBuilder t = b2; - b.append("large where z = 409"); - for (int i = 0; i < 10000; i++) { - t.append('(').append(b).append(") where z = 409"); - StringBuilder z; - z = t; - t = b; - b = z; - t.setLength(0); - } - QueryHandlerTest.download(b.toString(), temp); - } -} \ No newline at end of file diff --git a/core/src/test/java/com/questdb/net/http/handlers/QueryHandlerTest.java b/core/src/test/java/com/questdb/net/http/handlers/QueryHandlerTest.java deleted file mode 100644 index 3f9933898..000000000 --- a/core/src/test/java/com/questdb/net/http/handlers/QueryHandlerTest.java +++ /dev/null @@ -1,371 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2019 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.net.http.handlers; - -import com.google.gson.GsonBuilder; -import com.questdb.BootstrapEnv; -import com.questdb.ServerConfiguration; -import com.questdb.net.http.HttpServer; -import com.questdb.net.http.QueryResponse; -import com.questdb.net.http.SimpleUrlMatcher; -import com.questdb.parser.sql.AbstractOptimiserTest; -import com.questdb.std.NumericException; -import com.questdb.std.Rnd; -import com.questdb.std.ex.JournalException; -import com.questdb.std.time.DateFormatUtils; -import com.questdb.store.Files; -import com.questdb.store.JournalEntryWriter; -import com.questdb.store.JournalWriter; -import com.questdb.store.factory.configuration.JournalStructure; -import com.questdb.test.tools.HttpTestUtils; -import com.questdb.test.tools.TestUtils; -import org.junit.*; -import org.junit.rules.TemporaryFolder; - -import java.io.File; -import java.net.URLEncoder; -import java.sql.Timestamp; - -public class QueryHandlerTest extends AbstractOptimiserTest { - - @ClassRule - public static final TemporaryFolder temp = new TemporaryFolder(); - - private static HttpServer server; - private static QueryHandler handler; - - @BeforeClass - public static void setUp() throws Exception { - final ServerConfiguration serverConfiguration = new ServerConfiguration(); - BootstrapEnv env = new BootstrapEnv(); - env.configuration = serverConfiguration; - env.configuration.setHttpThreads(1); - env.factory = FACTORY_CONTAINER.getFactory(); - - handler = new QueryHandler(env); - - env.matcher = new SimpleUrlMatcher() {{ - put("/js", handler); - put("/chk", new ExistenceCheckHandler(env)); - put("/csv", new CsvHandler(env)); - }}; - - - server = new HttpServer(env); - - server.start(); - generateJournal(); - } - - @AfterClass - public static void tearDown2() { - server.halt(); - Assert.assertEquals(0, FACTORY_CONTAINER.getFactory().getBusyReaderCount()); - Assert.assertEquals(0, FACTORY_CONTAINER.getFactory().getBusyWriterCount()); - } - - @Override - @After - public void tearDown() { - } - - @Test - public void testDDLCsv() throws Exception { - File f = temp.newFile(); - String url = "http://localhost:9000/csv?query=" + URLEncoder.encode("create table y(a INT)", "UTF-8"); - HttpTestUtils.download(HttpTestUtils.clientBuilder(false), url, f); - String response = Files.readStringFromFile(f); - Assert.assertTrue(response.contains("\"ddl\":\"OK\"}")); - } - - @Test - public void testDDLError() throws Exception { - String response = downloadStr("create table x (a xyz, b DOUBLE)", -1, -1, false, false, temp); - Assert.assertEquals("{\"query\":\"create table x (a xyz, b DOUBLE)\",\"error\":\"Unsupported type\",\"position\":18}", response); - } - - @Test - public void testDDLSimple() throws Exception { - String response = downloadStr("create table x (a INT, b DOUBLE)", -1, -1, false, false, temp); - Assert.assertEquals("{\"ddl\":\"OK\"}", response); - } - - @Test - public void testJournalDoesNotExist() throws Exception { - File f = temp.newFile(); - String url = "http://localhost:9000/chk?j=tab2"; - HttpTestUtils.download(HttpTestUtils.clientBuilder(false), url, f); - TestUtils.assertEquals("Does not exist\r\n", Files.readStringFromFile(f)); - } - - @Test - public void testJournalExist() throws Exception { - File f = temp.newFile(); - String url = "http://localhost:9000/chk?j=tab"; - HttpTestUtils.download(HttpTestUtils.clientBuilder(false), url, f); - TestUtils.assertEquals("Exists\r\n", Files.readStringFromFile(f)); - } - - @Test - public void testJournalExistJson() throws Exception { - File f = temp.newFile(); - String url = "http://localhost:9000/chk?j=tab&f=json"; - HttpTestUtils.download(HttpTestUtils.clientBuilder(false), url, f); - TestUtils.assertEquals("{\"status\":\"Exists\"}", Files.readStringFromFile(f)); - } - - @Test - public void testJsonChunkOverflow() throws Exception { - int count = 10000; - generateJournal("large", count); - QueryResponse queryResponse = download("large"); - Assert.assertEquals(count, queryResponse.dataset.size()); - } - - @Test - public void testJsonEmpty() throws Exception { - QueryResponse queryResponse = download("tab", 0, 0); - Assert.assertEquals(0, queryResponse.dataset.size()); - } - - @Test - public void testJsonEmpty0() throws Exception { - QueryResponse queryResponse = download("tab where 1 = 2", 0, 0); - Assert.assertEquals(0, queryResponse.dataset.size()); - } - - @Test - public void testJsonEmptyQuery() throws Exception { - Assert.assertNull(download("", 0, 0).dataset); - } - - @Test - public void testJsonEncodeControlChars() throws Exception { - java.lang.StringBuilder allChars = new java.lang.StringBuilder(); - for (char c = Character.MIN_VALUE; c < 0xD800; c++) { // - allChars.append(c); - } - - String allCharString = allChars.toString(); - generateJournal("xyz", allCharString, 1.900232E-10, 2.598E20, Long.MAX_VALUE, Integer.MIN_VALUE, new Timestamp(0)); - String query = "select id from xyz \n limit 1"; - QueryResponse queryResponse = download(query); - Assert.assertEquals(query, queryResponse.query); - for (int i = 0; i < allCharString.length(); i++) { - Assert.assertTrue("result len is less than " + i, i < queryResponse.dataset.get(0)[0].length()); - Assert.assertEquals(i + "", allCharString.charAt(i), queryResponse.dataset.get(0)[0].charAt(i)); - } - } - - @Test - public void testJsonEncodeNumbers() throws Exception { - generateJournal("nums", null, 1.900232E-10, Double.MAX_VALUE, Long.MAX_VALUE, Integer.MIN_VALUE, new Timestamp(10)); - QueryResponse queryResponse = download("nums limit 20"); - Assert.assertEquals("0.0000000002", queryResponse.dataset.get(0)[1]); - Assert.assertEquals("1.7976931348623157E308", queryResponse.dataset.get(0)[2]); - Assert.assertEquals("9223372036854775807", queryResponse.dataset.get(0)[3]); - Assert.assertNull(queryResponse.dataset.get(0)[4]); - Assert.assertEquals("1970-01-01T00:00:00.010Z", queryResponse.dataset.get(0)[5]); - - Assert.assertEquals("id4", queryResponse.dataset.get(4)[0]); - Assert.assertNull(queryResponse.dataset.get(4)[2]); - } - - @Test - public void testJsonInvertedLimit() throws Exception { - String query = "tab limit 10"; - QueryResponse queryResponse = download(query, 10, 5); - Assert.assertEquals(0, queryResponse.dataset.size()); - } - - @Test - public void testJsonLimits() throws Exception { - String query = "tab"; - QueryResponse r = download(query, 2, 4); - Assert.assertEquals(2, r.dataset.size()); - Assert.assertEquals("id2", r.dataset.get(0)[0]); - Assert.assertEquals("id3", r.dataset.get(1)[0]); - } - - @Test - public void testJsonPooling() throws Exception { - QueryResponse queryResponse1 = download("tab limit 10"); - QueryResponse queryResponse2 = download("tab limit 10"); - QueryResponse queryResponse3 = download("tab limit 10"); - QueryResponse queryResponse4 = download("tab limit 10"); - - Assert.assertEquals(10, queryResponse1.dataset.size()); - Assert.assertEquals(10, queryResponse2.dataset.size()); - Assert.assertEquals(10, queryResponse3.dataset.size()); - Assert.assertEquals(10, queryResponse4.dataset.size()); - - Assert.assertTrue(handler.getCacheHits() > 0); - Assert.assertTrue(handler.getCacheMisses() > 0); - } - - @Test - public void testJsonSimple() throws Exception { - QueryResponse queryResponse = download("select 1 z from tab limit 10"); - Assert.assertEquals(10, queryResponse.dataset.size()); - } - - @Test - public void testJsonSimpleNoMeta() throws Exception { - QueryResponse queryResponse = download("select 1 z from tab limit 10", 0, 10, true, false, temp); - Assert.assertEquals(10, queryResponse.dataset.size()); - Assert.assertNull(queryResponse.query); - } - - @Test - public void testJsonSimpleNoMetaAndCount() throws Exception { - QueryResponse queryResponse = download("select 1 z from tab", 0, 10, true, true, temp); - Assert.assertEquals(10, queryResponse.dataset.size()); - Assert.assertEquals(1000, queryResponse.count); - Assert.assertNull(queryResponse.query); - } - - @Test - public void testJsonTakeLimit() throws Exception { - QueryResponse queryResponse = download("tab limit 10", 2, -1); - Assert.assertEquals(2, queryResponse.dataset.size()); - } - - @Test - public void testOrderByEmpty() throws Exception { - QueryResponse queryResponse = download("tab where 1 = 2 order by y", 0, 1000); - Assert.assertEquals(0, queryResponse.dataset.size()); - } - - @Test - public void testRename() throws Exception { - generateJournal("tab3", new QueryResponse.Tab[0], 100); - String query = "tab3 limit 10"; - QueryResponse queryResponse = download(query, 0, 5); - Assert.assertEquals(5, queryResponse.dataset.size()); - download("rename table tab3 to tab2"); - TestUtils.assertEquals("{\"query\":\"tab3 limit 10\",\"error\":\"Journal does not exist\",\"position\":0}", downloadStr(query, 0, 5, true, false, temp)); - } - - private static void generateJournal(String name, QueryResponse.Tab[] recs, int count) throws JournalException, NumericException { - try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure(name). - $sym("id"). - $double("x"). - $double("y"). - $long("z"). - $int("w"). - $ts() - - )) { - - Rnd rnd = new Rnd(); - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - - for (int i = 0; i < count; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putSym(0, recs.length > i ? recs[i].id : "id" + i); - ew.putDouble(1, recs.length > i ? recs[i].x : rnd.nextDouble()); - if (recs.length > i) { - ew.putDouble(2, recs[i].y); - ew.putLong(3, recs[i].z); - } else { - if (rnd.nextPositiveInt() % 10 == 0) { - ew.putNull(2); - } else { - ew.putDouble(2, rnd.nextDouble()); - } - if (rnd.nextPositiveInt() % 10 == 0) { - ew.putNull(3); - } else { - ew.putLong(3, rnd.nextLong() % 500); - } - } - ew.putInt(4, recs.length > i ? recs[i].w : rnd.nextInt() % 500); - ew.putDate(5, recs.length > i ? recs[i].timestamp.getTime() : t); - t += 10; - ew.append(); - } - w.commit(); - } - } - - static QueryResponse download(String queryUrl, TemporaryFolder temp) throws Exception { - return download(queryUrl, -1, -1, false, false, temp); - } - - static void generateJournal(String name, int count) throws JournalException, NumericException { - generateJournal(name, new QueryResponse.Tab[0], count); - } - - static void generateJournal(String name, String id, double x, double y, long z, int w, Timestamp timestamp) throws JournalException, NumericException { - QueryResponse.Tab record = new QueryResponse.Tab(); - record.id = id; - record.x = x; - record.y = y; - record.z = z; - record.w = w; - record.timestamp = timestamp; - generateJournal(name, new QueryResponse.Tab[]{record}, 1000); - } - - private static String downloadStr(String queryUrl, int limitFrom, int limitTo, boolean noMeta, boolean count, TemporaryFolder temp) throws Exception { - File f = temp.newFile(); - String url = "http://localhost:9000/js?query=" + URLEncoder.encode(queryUrl, "UTF-8"); - if (limitFrom >= 0) { - url += "&limit=" + limitFrom; - } - if (limitTo >= 0) { - url += "," + limitTo; - } - - if (noMeta) { - url += "&nm=true"; - } - - if (count) { - url += "&count=true"; - } - - HttpTestUtils.download(HttpTestUtils.clientBuilder(false), url, f); - return Files.readStringFromFile(f); - } - - private static QueryResponse download(String queryUrl, int limitFrom, int limitTo, boolean noMeta, boolean count, TemporaryFolder temp) throws Exception { - return new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").create().fromJson( - downloadStr(queryUrl, limitFrom, limitTo, noMeta, count, temp), - QueryResponse.class); - } - - private static void generateJournal() throws JournalException, NumericException { - generateJournal("tab", new QueryResponse.Tab[0], 1000); - } - - private static QueryResponse download(String queryUrl) throws Exception { - return download(queryUrl, temp); - } - - private static QueryResponse download(String queryUrl, int limitFrom, int limitTo) throws Exception { - return download(queryUrl, limitFrom, limitTo, false, false, temp); - } -} \ No newline at end of file diff --git a/core/src/test/java/com/questdb/parser/sql/AbstractOptimiserTest.java b/core/src/test/java/com/questdb/parser/sql/AbstractOptimiserTest.java deleted file mode 100644 index d2614c720..000000000 --- a/core/src/test/java/com/questdb/parser/sql/AbstractOptimiserTest.java +++ /dev/null @@ -1,237 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.parser.sql; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonParser; -import com.questdb.BootstrapEnv; -import com.questdb.ServerConfiguration; -import com.questdb.ex.ParserException; -import com.questdb.ql.RecordSource; -import com.questdb.ql.RecordSourcePrinter; -import com.questdb.std.AssociativeCache; -import com.questdb.std.Misc; -import com.questdb.std.Unsafe; -import com.questdb.std.str.StringSink; -import com.questdb.std.time.DateFormatFactory; -import com.questdb.std.time.DateLocaleFactory; -import com.questdb.store.Record; -import com.questdb.store.RecordCursor; -import com.questdb.store.RecordMetadata; -import com.questdb.store.SymbolTable; -import com.questdb.test.tools.FactoryContainer; -import com.questdb.test.tools.TestUtils; -import org.junit.After; -import org.junit.Assert; -import org.junit.ClassRule; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -public abstract class AbstractOptimiserTest { - - @ClassRule - public static final FactoryContainer FACTORY_CONTAINER = new FactoryContainer(); - protected static final StringSink sink = new StringSink(); - protected static final RecordSourcePrinter printer = new RecordSourcePrinter(sink); - protected static final QueryCompiler compiler; - private static final AssociativeCache cache = new AssociativeCache<>(8, 16); - private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); - private static final JsonParser jp = new JsonParser(); - - public static void assertSymbol(String query, int columnIndex) throws ParserException { - try (RecordSource src = compiler.compile(FACTORY_CONTAINER.getFactory(), query)) { - RecordCursor cursor = src.prepareCursor(FACTORY_CONTAINER.getFactory()); - try { - SymbolTable tab = cursor.getStorageFacade().getSymbolTable(columnIndex); - while (cursor.hasNext()) { - Record r = cursor.next(); - TestUtils.assertEquals(r.getSym(columnIndex), tab.value(r.getInt(columnIndex))); - } - } finally { - cursor.releaseCursor(); - } - } - } - - @After - public void tearDown() { - Assert.assertEquals(0, FACTORY_CONTAINER.getFactory().getBusyWriterCount()); - Assert.assertEquals(0, FACTORY_CONTAINER.getFactory().getBusyReaderCount()); - } - - protected static void assertRowId(String query, String longColumn) throws ParserException { - RecordSource src = compiler.compile(FACTORY_CONTAINER.getFactory(), query); - try { - RecordCursor cursor = src.prepareCursor(FACTORY_CONTAINER.getFactory()); - - try { - int dateIndex = src.getMetadata().getColumnIndex(longColumn); - HashMap map = new HashMap<>(); - - long count = 0; - while (cursor.hasNext()) { - Record record = cursor.next(); - map.put(record.getRowId(), record.getLong(dateIndex)); - count++; - } - - Assert.assertTrue(count > 0); - Record record = cursor.newRecord(); - for (Map.Entry e : map.entrySet()) { - Assert.assertEquals((long) e.getValue(), cursor.recordAt(e.getKey()).getLong(dateIndex)); - cursor.recordAt(record, e.getKey()); - Assert.assertEquals((long) e.getValue(), record.getLong(dateIndex)); - } - } finally { - cursor.releaseCursor(); - } - - } finally { - Misc.free(src); - } - } - - protected void assertEmpty(String query) throws ParserException { - try (RecordSource src = compiler.compile(FACTORY_CONTAINER.getFactory(), query)) { - RecordCursor cursor = src.prepareCursor(FACTORY_CONTAINER.getFactory()); - try { - Assert.assertFalse(cursor.hasNext()); - } finally { - cursor.releaseCursor(); - } - } - } - - protected void assertPlan(String expected, String query) throws ParserException { - TestUtils.assertEquals(expected, compiler.plan(FACTORY_CONTAINER.getFactory(), query)); - } - - protected void assertPlan2(CharSequence expected, CharSequence query) throws ParserException { - sink.clear(); - try (RecordSource recordSource = compiler.compile(FACTORY_CONTAINER.getFactory(), query)) { - recordSource.toSink(sink); - String s = gson.toJson(jp.parse(sink.toString())); - TestUtils.assertEquals(expected, s); - } - } - - protected void assertString(String query, int columnIndex) throws ParserException { - try (RecordSource rs = compiler.compile(FACTORY_CONTAINER.getFactory(), query)) { - RecordCursor cursor = rs.prepareCursor(FACTORY_CONTAINER.getFactory()); - try { - while (cursor.hasNext()) { - Record r = cursor.next(); - int len = r.getStrLen(columnIndex); - CharSequence s = r.getFlyweightStr(columnIndex); - if (s != null) { - CharSequence csB = r.getFlyweightStrB(columnIndex); - TestUtils.assertEquals(s, csB); - Assert.assertEquals(len, s.length()); - Assert.assertNotSame(s, csB); - } else { - Assert.assertEquals(-1, len); - Assert.assertNull(r.getFlyweightStr(columnIndex)); - Assert.assertNull(r.getFlyweightStrB(columnIndex)); - } - } - } finally { - cursor.releaseCursor(); - } - } - } - - protected void assertThat(String expected, String query) throws Exception { - assertThat(expected, query, false); - } - - protected void assertThat(String expected, String query, boolean header) throws Exception { - FACTORY_CONTAINER.getFactory().getConfiguration().releaseThreadLocals(); - TestUtils.assertMemoryLeak(() -> { - assertThat0(expected, query, header); - assertThat0(expected, query, header); - Misc.free(cache.poll(query)); - FACTORY_CONTAINER.getFactory().getConfiguration().releaseThreadLocals(); - }); - } - - protected void assertThat(String expected, RecordSource rs, boolean header) throws IOException { - RecordCursor cursor = rs.prepareCursor(FACTORY_CONTAINER.getFactory()); - try { - assertThat(expected, cursor, rs.getMetadata(), header); - } finally { - cursor.releaseCursor(); - } - TestUtils.assertStrings(rs, FACTORY_CONTAINER.getFactory()); - } - - protected void assertThat(CharSequence expected, RecordCursor cursor, RecordMetadata metadata, boolean header) throws IOException { - sink.clear(); - printer.print(cursor, header, metadata); - TestUtils.assertEquals(expected, sink); - - cursor.toTop(); - - sink.clear(); - printer.print(cursor, header, metadata); - TestUtils.assertEquals(expected, sink); - } - - private void assertThat0(String expected, String query, boolean header) throws ParserException, IOException { - RecordSource rs = cache.peek(query); - if (rs == null) { - cache.put(query, rs = compiler.compile(FACTORY_CONTAINER.getFactory(), query)); - } - assertThat(expected, rs, header); - } - - protected RecordSource compileSource(CharSequence query) throws ParserException { - return compiler.compile(FACTORY_CONTAINER.getFactory(), query); - } - - protected void expectFailure(CharSequence query) throws ParserException { - FACTORY_CONTAINER.getFactory().getConfiguration().releaseThreadLocals(); - long memUsed = Unsafe.getMemUsed(); - try { - compiler.compile(FACTORY_CONTAINER.getFactory(), query); - Assert.fail(); - } catch (ParserException e) { - FACTORY_CONTAINER.getFactory().getConfiguration().releaseThreadLocals(); - Assert.assertEquals(memUsed, Unsafe.getMemUsed()); - throw e; - } finally { - FACTORY_CONTAINER.getFactory().getConfiguration().releaseThreadLocals(); - } - } - - static { - BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(); - env.dateLocaleFactory = DateLocaleFactory.INSTANCE; - env.dateFormatFactory = new DateFormatFactory(); - compiler = new QueryCompiler(env); - } -} diff --git a/core/src/test/java/com/questdb/parser/sql/AggregationTest.java b/core/src/test/java/com/questdb/parser/sql/AggregationTest.java deleted file mode 100644 index fef04258c..000000000 --- a/core/src/test/java/com/questdb/parser/sql/AggregationTest.java +++ /dev/null @@ -1,503 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.parser.sql; - -import com.questdb.ex.ParserException; -import com.questdb.std.Rnd; -import com.questdb.std.time.DateFormatUtils; -import com.questdb.store.JournalEntryWriter; -import com.questdb.store.JournalWriter; -import com.questdb.store.factory.configuration.JournalStructure; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -public class AggregationTest extends AbstractOptimiserTest { - - @BeforeClass - public static void setUp() throws Exception { - int recordCount = 10000; - int employeeCount = 10; - try (JournalWriter orders = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("orders"). - $int("orderId"). - $int("customerId"). - $int("productId"). - $str("employeeId"). - $ts("orderDate"). - $int("quantity"). - $double("price"). - $float("rate"). - recordCountHint(recordCount). - $() - )) { - - - Rnd rnd = new Rnd(); - - String[] employees = new String[employeeCount]; - for (int i = 0; i < employees.length; i++) { - employees[i] = rnd.nextString(9); - } - - long timestamp = DateFormatUtils.parseDateTime("2014-05-04T10:30:00.000Z"); - int tsIncrement = 10000; - - int orderId = 0; - for (int i = 0; i < recordCount; i++) { - JournalEntryWriter w = orders.entryWriter(); - w.putInt(0, ++orderId); - w.putInt(1, rnd.nextPositiveInt() % 500); - w.putInt(2, rnd.nextPositiveInt() % 200); - w.putStr(3, employees[rnd.nextPositiveInt() % employeeCount]); - w.putDate(4, timestamp += tsIncrement); - w.putInt(5, rnd.nextPositiveInt()); - w.putDouble(6, rnd.nextDouble()); - w.putFloat(7, rnd.nextFloat()); - w.append(); - } - orders.commit(); - } - - try (JournalWriter stars = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("stars"). - $int("galaxy"). - $int("star"). - $double("diameter"). - $() - )) { - Rnd rnd = new Rnd(); - long timestamp = DateFormatUtils.parseDateTime("2014-05-04T10:30:00.000Z"); - int tsIncrement = 10000; - for (int i = 0; i < recordCount; i++) { - JournalEntryWriter w = stars.entryWriter(timestamp += tsIncrement); - w.putInt(0, rnd.nextPositiveInt() % 10); - w.putInt(1, rnd.nextPositiveInt()); - int dividend = (rnd.nextPositiveInt() % 10); - w.putDouble(2, Double.MAX_VALUE / (double) (dividend == 0 ? 1 : dividend)); - w.append(); - } - stars.commit(); - } - - try (JournalWriter stars = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("stars2"). - $int("galaxy"). - $int("star"). - $double("diameter"). - $() - )) { - Rnd rnd = new Rnd(); - double r = Math.sqrt(Double.MAX_VALUE); - long timestamp = DateFormatUtils.parseDateTime("2014-05-04T10:30:00.000Z"); - int tsIncrement = 10000; - for (int i = 0; i < recordCount; i++) { - JournalEntryWriter w = stars.entryWriter(timestamp += tsIncrement); - w.putInt(0, rnd.nextPositiveInt() % 10); - w.putInt(1, rnd.nextPositiveInt()); - int dividend = (rnd.nextPositiveInt() % 10); - w.putDouble(2, r / (double) (dividend == 0 ? 1 : dividend)); - w.append(); - } - stars.commit(); - } - } - - @Test - public void testAggregateExpression() throws Exception { - assertThat("employeeId\tsum\tsum2\tx\n" + - "TGPGWFFYU\t97328\t-21968.018329648252\t75359.981670351760\n" + - "DEYYQEHBH\t95288\t-4394.647402081921\t90893.352597918080\n" + - "SRYRFBVTM\t96798\t1945.437433247252\t98743.437433247248\n" + - "GZSXUXIBB\t97026\t3710.011166965701\t100736.011166965712\n" + - "UEDRQQULO\t104395\t-5341.399618807004\t99053.600381192992\n" + - "FOWLPDXYS\t98350\t-25051.961159685804\t73298.038840314192\n" + - "FJGETJRSZ\t103481\t-5023.046150211212\t98457.953849788784\n" + - "BEOUOJSHR\t96459\t-7031.317012047984\t89427.682987952016\n" + - "YRXPEHNRX\t96407\t-5897.650745672292\t90509.349254327712\n" + - "VTJWCPSWH\t102802\t-15878.443493302174\t86923.556506697824\n", - "select employeeId, sum(productId) sum, sum(price) sum2, sum(price)+sum(productId) x from orders", true); - } - - @Test - public void testAvg() throws Exception { - assertThat("employeeId\tcol0\tcol1\tcol2\n" + - "TGPGWFFYU\t-22.347933193945\t1.0571239707599186E9\t0.497876154503\n" + - "DEYYQEHBH\t-4.416731057369\t1.0578515420281407E9\t0.493395281078\n" + - "SRYRFBVTM\t2.007675369708\t1.0974368837843137E9\t0.506477851617\n" + - "GZSXUXIBB\t3.736164317186\t1.099431249958711E9\t0.504398549131\n" + - "UEDRQQULO\t-5.160772578557\t1.1102616773748791E9\t0.498863287248\n" + - "FOWLPDXYS\t-25.305011272410\t1.096727898191919E9\t0.502265356225\n" + - "FJGETJRSZ\t-4.886231663630\t1.0819423916371596E9\t0.493707956565\n" + - "BEOUOJSHR\t-7.182141993920\t1.0689834824116446E9\t0.500621256716\n" + - "YRXPEHNRX\t-5.903554299972\t1.0714308772062062E9\t0.507052500028\n" + - "VTJWCPSWH\t-15.430946057631\t1.0903374433984451E9\t0.493997276119\n", - "select employeeId, avg(price), avg(quantity), avg(rate) from orders", true); - } - - @Test - public void testAvgConst() throws Exception { - assertThat("employeeId\tcol0\n" + - "TGPGWFFYU\t100.300000000002\n" + - "DEYYQEHBH\t100.300000000002\n" + - "SRYRFBVTM\t100.300000000002\n" + - "GZSXUXIBB\t100.300000000002\n" + - "UEDRQQULO\t100.300000000002\n" + - "FOWLPDXYS\t100.300000000002\n" + - "FJGETJRSZ\t100.300000000002\n" + - "BEOUOJSHR\t100.300000000002\n" + - "YRXPEHNRX\t100.300000000002\n" + - "VTJWCPSWH\t100.300000000002\n", - "select employeeId, avg(100.3) from orders", true); - } - - @Test - public void testAvgOverflow() throws Exception { - assertThat("0\t6.873337142147506E307\n" + - "1\t6.873164995098181E307\n" + - "2\t6.942020245747746E307\n" + - "8\t7.080135168048353E307\n" + - "4\t7.139261077288051E307\n" + - "5\t6.98887936996273E307\n" + - "7\t6.903112119100632E307\n" + - "9\t6.731706356699814E307\n" + - "6\t7.051044382735928E307\n" + - "3\t7.088674983313755E307\n", - "select galaxy, avg(diameter) d from stars"); - } - - @Test - public void testCount() throws Exception { - assertThat("TGPGWFFYU\t983\n" + - "DEYYQEHBH\t995\n" + - "SRYRFBVTM\t969\n" + - "GZSXUXIBB\t993\n" + - "UEDRQQULO\t1035\n" + - "FOWLPDXYS\t990\n" + - "FJGETJRSZ\t1028\n" + - "BEOUOJSHR\t979\n" + - "YRXPEHNRX\t999\n" + - "VTJWCPSWH\t1029\n", - "select employeeId, count() from orders"); - } - - @Test - public void testFirstDouble() throws Exception { - assertThat("TGPGWFFYU\t172.796875000000\n" + - "DEYYQEHBH\t424.828125000000\n" + - "SRYRFBVTM\t153.473033905029\n" + - "GZSXUXIBB\t632.921875000000\n" + - "UEDRQQULO\t0.000000009901\n" + - "FOWLPDXYS\t0.003103211522\n" + - "FJGETJRSZ\t1.229880273342\n" + - "BEOUOJSHR\t364.462486267090\n" + - "YRXPEHNRX\t0.000000261681\n" + - "VTJWCPSWH\t-144.421875000000\n", - "select employeeId, first(price) f from orders"); - } - - @Test - public void testFirstFloat() throws Exception { - assertThat("TGPGWFFYU\t0.5832\n" + - "DEYYQEHBH\t0.2858\n" + - "SRYRFBVTM\t0.3455\n" + - "GZSXUXIBB\t0.5619\n" + - "UEDRQQULO\t0.1498\n" + - "FOWLPDXYS\t0.2931\n" + - "FJGETJRSZ\t0.7276\n" + - "BEOUOJSHR\t0.2870\n" + - "YRXPEHNRX\t0.8434\n" + - "VTJWCPSWH\t0.5373\n", - "select employeeId, first(rate) f from orders"); - } - - @Test - public void testFirstInt() throws Exception { - assertThat("TGPGWFFYU\t1920890138\n" + - "DEYYQEHBH\t98924388\n" + - "SRYRFBVTM\t1876812930\n" + - "GZSXUXIBB\t572338288\n" + - "UEDRQQULO\t712702244\n" + - "FOWLPDXYS\t2060263242\n" + - "FJGETJRSZ\t544695670\n" + - "BEOUOJSHR\t923501161\n" + - "YRXPEHNRX\t230430837\n" + - "VTJWCPSWH\t1960168360\n", - "select employeeId, first(quantity) f from orders"); - } - - @Test - public void testFirstLong() throws Exception { - assertThat("TGPGWFFYU\t2014-05-04T10:30:10.000Z\n" + - "DEYYQEHBH\t2014-05-04T10:30:30.000Z\n" + - "SRYRFBVTM\t2014-05-04T10:30:40.000Z\n" + - "GZSXUXIBB\t2014-05-04T10:30:50.000Z\n" + - "UEDRQQULO\t2014-05-04T10:31:20.000Z\n" + - "FOWLPDXYS\t2014-05-04T10:31:30.000Z\n" + - "FJGETJRSZ\t2014-05-04T10:31:50.000Z\n" + - "BEOUOJSHR\t2014-05-04T10:32:50.000Z\n" + - "YRXPEHNRX\t2014-05-04T10:33:10.000Z\n" + - "VTJWCPSWH\t2014-05-04T10:34:10.000Z\n", - "select employeeId, toDate(first(orderDate)) f from orders"); - } - - @Test - public void testLSumInt() throws Exception { - assertThat("TGPGWFFYU\t1039152863257\t-229222375\n" + - "DEYYQEHBH\t1052562284318\t295296798\n" + - "SRYRFBVTM\t1063416340387\t-1735549021\n" + - "GZSXUXIBB\t1091735231209\t813538025\n" + - "UEDRQQULO\t1149120836083\t-1930399245\n" + - "FOWLPDXYS\t1085760619210\t-866106678\n" + - "FJGETJRSZ\t1112236778603\t-159751061\n" + - "BEOUOJSHR\t1046534829281\t-1437190943\n" + - "YRXPEHNRX\t1070359446329\t912589625\n" + - "VTJWCPSWH\t1121957229257\t970765001\n", - "select employeeId, lsum(quantity) s, sum(quantity) s2 from orders"); - - } - - @Test - public void testLastDouble() throws Exception { - assertThat("employeeId\tcol0\tcol1\tcol2\tcol3\tcol5\tcol6\n" + - "TGPGWFFYU\t0.005398272420\t0.4752\t1801096068\t2014-05-05T14:14:10.000Z\t2014-05-04T10:30:10.000Z\t2014-05-05T14:14:10.000Z\n" + - "DEYYQEHBH\t858.651367187500\t0.6052\t253116346\t2014-05-05T14:16:20.000Z\t2014-05-04T10:30:30.000Z\t2014-05-05T14:16:20.000Z\n" + - "SRYRFBVTM\t21.549713134766\t0.4888\t1518306371\t2014-05-05T14:14:50.000Z\t2014-05-04T10:30:40.000Z\t2014-05-05T14:14:50.000Z\n" + - "GZSXUXIBB\t328.000000000000\t0.5024\t1896175587\t2014-05-05T14:16:30.000Z\t2014-05-04T10:30:50.000Z\t2014-05-05T14:16:30.000Z\n" + - "UEDRQQULO\t-651.000000000000\t0.4547\t260995870\t2014-05-05T14:16:40.000Z\t2014-05-04T10:31:20.000Z\t2014-05-05T14:16:40.000Z\n" + - "FOWLPDXYS\t-727.085937500000\t0.4486\t2005631\t2014-05-05T14:16:10.000Z\t2014-05-04T10:31:30.000Z\t2014-05-05T14:16:10.000Z\n" + - "FJGETJRSZ\t116.035564422607\t0.6497\t987587702\t2014-05-05T14:13:20.000Z\t2014-05-04T10:31:50.000Z\t2014-05-05T14:13:20.000Z\n" + - "BEOUOJSHR\t-233.000000000000\t0.2665\t1504681377\t2014-05-05T14:14:30.000Z\t2014-05-04T10:32:50.000Z\t2014-05-05T14:14:30.000Z\n" + - "YRXPEHNRX\t0.000003891365\t0.6637\t1081845029\t2014-05-05T14:12:10.000Z\t2014-05-04T10:33:10.000Z\t2014-05-05T14:12:10.000Z\n" + - "VTJWCPSWH\t124.287727355957\t0.5628\t414901203\t2014-05-05T14:15:10.000Z\t2014-05-04T10:34:10.000Z\t2014-05-05T14:15:10.000Z\n", - "select employeeId, last(price), last(rate), last(quantity), toDate(dtol(last(orderDate))), min(orderDate), max(orderDate) from orders", - true); - - } - - @Test - public void testResampling() throws Exception { - assertThat("2014-05-04T00:00:00.000Z\tTGPGWFFYU\t-63.253453401381\t-63.253453401381\n" + - "2014-05-04T00:00:00.000Z\tDEYYQEHBH\t17.232482911526\t17.232482911526\n" + - "2014-05-04T00:00:00.000Z\tSRYRFBVTM\t-10.581027815832\t-10.581027815832\n" + - "2014-05-04T00:00:00.000Z\tGZSXUXIBB\t1.191841183028\t1.191841183028\n" + - "2014-05-04T00:00:00.000Z\tUEDRQQULO\t-25.284387331977\t-25.284387331977\n" + - "2014-05-04T00:00:00.000Z\tFOWLPDXYS\t-21.110275361914\t-21.110275361914\n" + - "2014-05-04T00:00:00.000Z\tFJGETJRSZ\t-12.327370360108\t-12.327370360108\n" + - "2014-05-04T00:00:00.000Z\tBEOUOJSHR\t3.586645530510\t3.586645530510\n" + - "2014-05-04T00:00:00.000Z\tYRXPEHNRX\t-10.131327938006\t-10.131327938006\n" + - "2014-05-04T00:00:00.000Z\tVTJWCPSWH\t-24.329569665466\t-24.329569665466\n" + - "2014-05-05T00:00:00.000Z\tDEYYQEHBH\t-30.963486961448\t-30.963486961448\n" + - "2014-05-05T00:00:00.000Z\tSRYRFBVTM\t13.422138958032\t13.422138958032\n" + - "2014-05-05T00:00:00.000Z\tVTJWCPSWH\t0.595780540587\t0.595780540587\n" + - "2014-05-05T00:00:00.000Z\tBEOUOJSHR\t-31.682205368795\t-31.682205368795\n" + - "2014-05-05T00:00:00.000Z\tFJGETJRSZ\t-31.906856870748\t-31.906856870748\n" + - "2014-05-05T00:00:00.000Z\tGZSXUXIBB\t7.870801180456\t7.870801180456\n" + - "2014-05-05T00:00:00.000Z\tFOWLPDXYS\t-11.860556414848\t-11.860556414848\n" + - "2014-05-05T00:00:00.000Z\tYRXPEHNRX\t-8.573401980346\t-8.573401980346\n" + - "2014-05-05T00:00:00.000Z\tUEDRQQULO\t16.987375521363\t16.987375521363\n" + - "2014-05-05T00:00:00.000Z\tTGPGWFFYU\t17.260132823173\t17.260132823173\n", - "select orderDate, employeeId, sum(price*quantity)/lsum(quantity), vwap(price, quantity) sum from orders sample by 1d"); - } - - @Test - public void testResampling2() throws Exception { - assertThat("2014-05-04T08:00:00.000Z\t-18.041874103485\n" + - "2014-05-04T16:00:00.000Z\t-12.148285354848\n" + - "2014-05-05T00:00:00.000Z\t-10.773253435499\n" + - "2014-05-05T08:00:00.000Z\t0.750778769143\n", - "select orderDate, vwap(price, quantity) from orders sample by 8h"); - } - - @Test - public void testResamplingAliasClash() { - try { - expectFailure("select dtoa4(orderDate) orderDate, sum(price*quantity)/lsum(quantity), vwap(price, quantity) sum from orders sample by 1d"); - } catch (ParserException e) { - Assert.assertEquals(24, QueryError.getPosition()); - } - } - - @Test - public void testResamplingNoAggregates() { - try { - expectFailure("select orderDate, price+quantity from orders sample by 8h"); - } catch (ParserException e) { - Assert.assertEquals(55, QueryError.getPosition()); - } - } - - @Test - public void testResamplingTimestampRename() throws Exception { - assertThat("2014-05-04T08:00:00.000Z\t-18.041874103485\n" + - "2014-05-04T16:00:00.000Z\t-12.148285354848\n" + - "2014-05-05T00:00:00.000Z\t-10.773253435499\n" + - "2014-05-05T08:00:00.000Z\t0.750778769143\n", - "select orderDate ts, vwap(price, quantity) from orders sample by 8h"); - } - - @Test - public void testRowIdCompliance() throws Exception { - assertRowId("select employeeId, sum(price*quantity)/lsum(quantity), vwap(price, quantity) sum from orders", "employeeId"); - } - - @Test - public void testStdDevOverflow() throws Exception { - assertThat("0\t1.9559640924336714E307\t4.4226282824059176E153\n" + - "1\t1.879534937588584E307\t4.335360351330191E153\n" + - "2\t1.9686634860114622E307\t4.436962346032995E153\n" + - "8\t2.0009174148155284E307\t4.473161538347937E153\n" + - "4\t2.0331647100026274E307\t4.5090627740170434E153\n" + - "5\t1.951822822449265E307\t4.417943891053015E153\n" + - "7\t1.931400940102605E307\t4.3947706881049034E153\n" + - "9\t1.841320042762572E307\t4.291060524815016E153\n" + - "6\t1.9512460199745866E307\t4.4172910476609834E153\n" + - "3\t1.9942851937157214E307\t4.4657420365665115E153\n", - "select galaxy, var(diameter), stddev(diameter) d from stars2"); - } - - @Test - public void testSumConst() throws Exception { - assertThat("employeeId\tsum\tcol0\tcol1\n" + - "TGPGWFFYU\t983\t10\t20\n" + - "DEYYQEHBH\t995\t10\t20\n" + - "SRYRFBVTM\t969\t10\t20\n" + - "GZSXUXIBB\t993\t10\t20\n" + - "UEDRQQULO\t1035\t10\t20\n" + - "FOWLPDXYS\t990\t10\t20\n" + - "FJGETJRSZ\t1028\t10\t20\n" + - "BEOUOJSHR\t979\t10\t20\n" + - "YRXPEHNRX\t999\t10\t20\n" + - "VTJWCPSWH\t1029\t10\t20\n", - "select employeeId, sum(1) sum, min(10), max(20) from orders", true); - } - - @Test - public void testSumDouble() throws Exception { - assertThat("employeeId\tsum\tcol0\tcol1\n" + - "TGPGWFFYU\t-21968.018329648252\t-1024.000000000000\t1017.000000000000\n" + - "DEYYQEHBH\t-4394.647402081921\t-1024.000000000000\t1014.750000000000\n" + - "SRYRFBVTM\t1945.437433247252\t-1024.000000000000\t1014.000000000000\n" + - "GZSXUXIBB\t3710.011166965701\t-1024.000000000000\t1000.750000000000\n" + - "UEDRQQULO\t-5341.399618807004\t-1024.000000000000\t1023.335937500000\n" + - "FOWLPDXYS\t-25051.961159685804\t-1024.000000000000\t1022.250000000000\n" + - "FJGETJRSZ\t-5023.046150211212\t-1024.000000000000\t1016.937500000000\n" + - "BEOUOJSHR\t-7031.317012047984\t-1024.000000000000\t1016.375000000000\n" + - "YRXPEHNRX\t-5897.650745672292\t-1024.000000000000\t1020.442382812500\n" + - "VTJWCPSWH\t-15878.443493302174\t-1024.000000000000\t1016.000000000000\n", - "select employeeId, sum(price) sum, min(price), max(price) from orders", true); - } - - @Test - public void testSumFloat() throws Exception { - assertThat("TGPGWFFYU\t489.412259876728\t0.017976403236\t0.994569778442\n" + - "DEYYQEHBH\t490.928304672241\t0.002583622932\t0.990825176239\n" + - "SRYRFBVTM\t490.777038216591\t0.015948891640\t0.996204674244\n" + - "GZSXUXIBB\t500.867759287357\t0.023229062557\t0.984000325203\n" + - "UEDRQQULO\t516.323502302170\t0.005706131458\t0.984908044338\n" + - "FOWLPDXYS\t497.242702662945\t0.020444750786\t0.967337131500\n" + - "FJGETJRSZ\t507.531779348850\t0.006864905357\t0.970933258533\n" + - "BEOUOJSHR\t490.108210325241\t0.014558494091\t0.981236577034\n" + - "YRXPEHNRX\t506.545447528362\t0.022396981716\t0.979304194450\n" + - "VTJWCPSWH\t508.323197126389\t0.015372276306\t0.997526228428\n", - "select employeeId, sum(rate), min(rate), max(rate) s from orders"); - - } - - @Test - public void testSumInt() throws Exception { - assertThat("employeeId\tsum\tcol0\tcol1\n" + - "TGPGWFFYU\t97328\t0\t199\n" + - "DEYYQEHBH\t95288\t0\t199\n" + - "SRYRFBVTM\t96798\t0\t199\n" + - "GZSXUXIBB\t97026\t0\t199\n" + - "UEDRQQULO\t104395\t0\t199\n" + - "FOWLPDXYS\t98350\t0\t199\n" + - "FJGETJRSZ\t103481\t0\t199\n" + - "BEOUOJSHR\t96459\t0\t199\n" + - "YRXPEHNRX\t96407\t0\t199\n" + - "VTJWCPSWH\t102802\t0\t199\n", - "select employeeId, sum(productId) sum, min(productId), max(productId) from orders", true); - } - - @Test - public void testVWapConst() throws Exception { - assertThat("TGPGWFFYU\t-21.643293565756\t10.000000000000\n" + - "DEYYQEHBH\t-6.467001028408\t10.000000000000\n" + - "SRYRFBVTM\t2.393438946531\t10.000000000000\n" + - "GZSXUXIBB\t4.741280909223\t10.000000000000\n" + - "UEDRQQULO\t-3.726755343047\t10.000000000000\n" + - "FOWLPDXYS\t-16.216304999514\t10.000000000000\n" + - "FJGETJRSZ\t-22.689574330892\t10.000000000000\n" + - "BEOUOJSHR\t-15.105882600563\t10.000000000000\n" + - "YRXPEHNRX\t-9.386559884214\t10.000000000000\n" + - "VTJWCPSWH\t-12.402215320133\t10.000000000000\n", - "select employeeId, sum(price*quantity)/lsum(quantity), vwap(10, 20) sum from orders"); - } - - @Test - public void testVWapDoubleDouble() throws Exception { - assertThat("TGPGWFFYU\t-21.643293565756\t-21.643293565756\n" + - "DEYYQEHBH\t-6.467001028408\t-6.467001028408\n" + - "SRYRFBVTM\t2.393438946531\t2.393438946531\n" + - "GZSXUXIBB\t4.741280909223\t4.741280909223\n" + - "UEDRQQULO\t-3.726755343047\t-3.726755343047\n" + - "FOWLPDXYS\t-16.216304999514\t-16.216304999514\n" + - "FJGETJRSZ\t-22.689574330892\t-22.689574330892\n" + - "BEOUOJSHR\t-15.105882600563\t-15.105882600563\n" + - "YRXPEHNRX\t-9.386559884214\t-9.386559884214\n" + - "VTJWCPSWH\t-12.402215320133\t-12.402215320133\n", - "select employeeId, sum(price*quantity)/lsum(quantity), vwap(price, quantity) sum from orders"); - } - - @Test - public void testVarianceOverflow() throws Exception { - assertThat("0\tNaN\n" + - "1\tNaN\n" + - "2\tNaN\n" + - "8\tNaN\n" + - "4\tNaN\n" + - "5\tNaN\n" + - "7\tNaN\n" + - "9\tNaN\n" + - "6\tNaN\n" + - "3\tNaN\n", - "select galaxy, var(diameter) d from stars"); - } - - @Test - public void testVarianceOverflow2() throws Exception { - assertThat("0\t1.9559640924336714E307\n" + - "1\t1.879534937588584E307\n" + - "2\t1.9686634860114622E307\n" + - "8\t2.0009174148155284E307\n" + - "4\t2.0331647100026274E307\n" + - "5\t1.951822822449265E307\n" + - "7\t1.931400940102605E307\n" + - "9\t1.841320042762572E307\n" + - "6\t1.9512460199745866E307\n" + - "3\t1.9942851937157214E307\n", - "select galaxy, var(diameter) d from stars2"); - } -} diff --git a/core/src/test/java/com/questdb/parser/sql/DateFunctionTest.java b/core/src/test/java/com/questdb/parser/sql/DateFunctionTest.java deleted file mode 100644 index 8e5f7e30b..000000000 --- a/core/src/test/java/com/questdb/parser/sql/DateFunctionTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.parser.sql; - -import com.questdb.ex.ParserException; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Test; - -public class DateFunctionTest extends AbstractOptimiserTest { - - @Test - public void testCannotParse() throws Exception { - assertThat("\n", "select toDate('2017', 'MM/y') from dual"); - assertThat("\n", "select TO_DATE('2017', 'MM/y') from dual"); - } - - @Test - public void testDefaultLocale() throws Exception { - assertThat("2017-03-01T00:00:00.000Z\n", "select toDate('03/2017', 'MM/y') from dual"); - assertThat("2017-03-01T00:00:00.000Z\n", "select TO_DATE('03/2017', 'MM/y') from dual"); - } - - @Test - public void testParseWithLocale() throws Exception { - assertThat("2017-04-01T00:00:00.000Z\n", "select toDate('Abril 2017', 'MMM y', 'es') from dual"); - assertThat("2017-04-01T00:00:00.000Z\n", "select TO_DATE('Abril 2017', 'MMM y', 'es') from dual"); - } - - @Test - public void testToChar() throws Exception { - assertThat("20-03-2015\n", "select TO_CHAR(TO_DATE('2015-03-20T15:25:40.567Z'), 'dd-MM-y') from dual"); - } - - @Test - public void testToCharTZ() throws Exception { - assertThat("20-03-2015 08:25:40.567 PDT\n", "select TO_CHAR(TO_DATE('2015-03-20T15:25:40.567Z'), 'dd-MM-y HH:mm:ss.SSS Z', 'PDT') from dual"); - assertThat("20-03-2015 21:25:40.567 +0600\n", "select TO_CHAR(TO_DATE('2015-03-20T15:25:40.567Z'), 'dd-MM-y HH:mm:ss.SSS Z', '+0600') from dual"); - } - - @Test - public void testToCharTZLocale() throws Exception { - assertThat("Пт, 20 мар 2015 08:25:40.567 PDT\n", "select TO_CHAR(TO_DATE('2015-03-20T15:25:40.567Z'), 'E, dd MMM y HH:mm:ss.SSS Z', 'PDT', 'ru') from dual"); - } - - @Test - public void testWrongLocale() { - try { - expectFailure("select toDate('Abril 2017', 'MMM y', 'wrong') from dual"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(37, QueryError.getPosition()); - TestUtils.assertEquals("Invalid locale", QueryError.getMessage()); - } - } -} diff --git a/core/src/test/java/com/questdb/parser/sql/ExprParserTest.java b/core/src/test/java/com/questdb/parser/sql/ExprParserTest.java deleted file mode 100644 index 9f4ad5cda..000000000 --- a/core/src/test/java/com/questdb/parser/sql/ExprParserTest.java +++ /dev/null @@ -1,168 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.parser.sql; - -import com.questdb.ex.ParserException; -import com.questdb.parser.sql.model.ExprNode; -import com.questdb.std.Lexer; -import com.questdb.std.ObjectPool; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class ExprParserTest { - - private final ObjectPool exprNodeObjectPool = new ObjectPool<>(ExprNode.FACTORY, 128); - private final Lexer lexer = new Lexer(); - private final ExprParser parser = new ExprParser(exprNodeObjectPool); - - @Before - public void setUp() { - exprNodeObjectPool.clear(); - ExprParser.configureLexer(lexer); - } - - @Test - public void testCommaExit() throws Exception { - x("abxybzc*+", "a + b * c(b(x,y),z),"); - } - - @Test - public void testComplexUnary1() throws Exception { - x("4xyc-^", "4^-c(x,y)"); - } - - @Test - public void testComplexUnary2() throws Exception { - x("ab^-", "-a^b"); - } - - @Test - public void testEqualPrecedence() throws Exception { - x("abc^^", "a^b^c"); - } - - @Test - public void testExprCompiler() throws Exception { - x("ac098dzf+1234x+", "a+f(c,d(0,9,8),z)+x(1,2,3,4)"); - } - - @Test - public void testIn() throws Exception { - x("abcin", "a in (b,c)"); - } - - @Test - public void testInOperator() throws Exception { - x("a10=bxyinand", "a = 10 and b in (x,y)"); - } - - @Test - public void testLambda() throws Exception { - x("a`blah blah`inyand", "a in (`blah blah`) and y"); - } - - @Test - public void testLiteralAndConstant() throws Exception { - x("'a b'x", "x 'a b'"); - } - - @Test - public void testLiteralExit() throws Exception { - x("abxybzc*+", "a + b * c(b(x,y),z) lit"); - } - - @Test - public void testMissingArgAtBraceError() { - try { - x("", "x * 4 + c(x,y,)"); - Assert.fail("Expected syntax exception"); - } catch (ParserException e) { - Assert.assertEquals(14, QueryError.getPosition()); - } - } - - @Test - public void testMissingArgError() { - try { - x("", "x * 4 + c(x,,y)"); - Assert.fail("Expected syntax exception"); - } catch (ParserException e) { - Assert.assertEquals(12, QueryError.getPosition()); - } - } - - @Test - public void testNestedFunctions() throws Exception { - x("48yfrz", "z(4, r(f(8,y)))"); - } - - @Test - public void testNestedOperator() throws Exception { - x("ac4*db+", "a + b( c * 4, d)"); - } - - @Test - public void testNoArgFunction() throws Exception { - x("ab4*+", "a+b()*4"); - } - - @Test - public void testSimple() throws Exception { - x("abxyc*2/+", "a + b * c(x,y)/2"); - } - - @Test - public void testSimpleLiteralExit() throws Exception { - x("a", "a lit"); - } - - @Test - public void testUnary() throws Exception { - x("4c-*", "4 * -c"); - } - - @Test - public void testUnbalancedLeftBrace() { - try { - x("", "a+b(5,c(x,y)"); - Assert.fail("Expected exception"); - } catch (ParserException e) { - Assert.assertEquals(3, QueryError.getPosition()); - } - } - - @Test - public void testUnbalancedRightBraceExit() throws Exception { - x("a5xycb+", "a+b(5,c(x,y)))"); - } - - private void x(CharSequence expectedRpn, String content) throws ParserException { - RpnBuilder r = new RpnBuilder(); - lexer.setContent(content); - parser.parseExpr(lexer, r); - TestUtils.assertEquals(expectedRpn, r.rpn()); - } -} diff --git a/core/src/test/java/com/questdb/parser/sql/IntervalCompilerTest.java b/core/src/test/java/com/questdb/parser/sql/IntervalCompilerTest.java deleted file mode 100644 index 69eb67648..000000000 --- a/core/src/test/java/com/questdb/parser/sql/IntervalCompilerTest.java +++ /dev/null @@ -1,324 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.parser.sql; - -import com.questdb.ex.ParserException; -import com.questdb.std.LongList; -import com.questdb.std.time.DateFormatUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class IntervalCompilerTest { - - private final LongList a = new LongList(); - private final LongList b = new LongList(); - private final LongList out = new LongList(); - - @Before - public void setUp() { - a.clear(); - b.clear(); - out.clear(); - } - - @Test - public void testIntersectContain2() throws Exception { - a.add(DateFormatUtils.parseDateTime("2016-03-10T10:00:00.000Z")); - a.add(DateFormatUtils.parseDateTime("2016-03-10T12:00:00.000Z")); - - b.add(DateFormatUtils.parseDateTime("2016-03-10T09:00:00.000Z")); - b.add(DateFormatUtils.parseDateTime("2016-03-10T13:30:00.000Z")); - - assertIntersect("[Interval{lo=2016-03-10T10:00:00.000Z, hi=2016-03-10T12:00:00.000Z}]"); - } - - @Test - public void testIntersectMergeOverlap() throws Exception { - a.add(DateFormatUtils.parseDateTime("2016-03-10T10:00:00.000Z")); - a.add(DateFormatUtils.parseDateTime("2016-03-10T12:00:00.000Z")); - - b.add(DateFormatUtils.parseDateTime("2016-03-10T11:00:00.000Z")); - b.add(DateFormatUtils.parseDateTime("2016-03-10T14:00:00.000Z")); - - assertIntersect("[Interval{lo=2016-03-10T11:00:00.000Z, hi=2016-03-10T12:00:00.000Z}]"); - } - - @Test - public void testIntersectMergeOverlap2() throws Exception { - a.add(DateFormatUtils.parseDateTime("2016-03-10T10:00:00.000Z")); - a.add(DateFormatUtils.parseDateTime("2016-03-10T12:00:00.000Z")); - - b.add(DateFormatUtils.parseDateTime("2016-03-10T11:00:00.000Z")); - b.add(DateFormatUtils.parseDateTime("2016-03-10T14:00:00.000Z")); - - assertIntersect("[Interval{lo=2016-03-10T11:00:00.000Z, hi=2016-03-10T12:00:00.000Z}]"); - } - - @Test - public void testIntersectNoOverlap() throws Exception { - a.add(DateFormatUtils.parseDateTime("2016-03-10T10:00:00.000Z")); - a.add(DateFormatUtils.parseDateTime("2016-03-10T12:00:00.000Z")); - a.add(DateFormatUtils.parseDateTime("2016-03-10T14:00:00.000Z")); - a.add(DateFormatUtils.parseDateTime("2016-03-10T16:00:00.000Z")); - - b.add(DateFormatUtils.parseDateTime("2016-03-10T13:00:00.000Z")); - b.add(DateFormatUtils.parseDateTime("2016-03-10T13:30:00.000Z")); - - assertIntersect("[]"); - } - - @Test - public void testIntersectSame() throws Exception { - a.add(DateFormatUtils.parseDateTime("2016-03-10T10:00:00.000Z")); - a.add(DateFormatUtils.parseDateTime("2016-03-10T12:00:00.000Z")); - - b.add(DateFormatUtils.parseDateTime("2016-03-10T10:00:00.000Z")); - b.add(DateFormatUtils.parseDateTime("2016-03-10T12:00:00.000Z")); - - assertIntersect("[Interval{lo=2016-03-10T10:00:00.000Z, hi=2016-03-10T12:00:00.000Z}]"); - } - - @Test - public void testIntersectTwoOverlapOne2() throws Exception { - a.add(DateFormatUtils.parseDateTime("2016-03-10T10:00:00.000Z")); - a.add(DateFormatUtils.parseDateTime("2016-03-10T12:00:00.000Z")); - - - a.add(DateFormatUtils.parseDateTime("2016-03-10T14:00:00.000Z")); - a.add(DateFormatUtils.parseDateTime("2016-03-10T16:00:00.000Z")); - - - b.add(DateFormatUtils.parseDateTime("2016-03-10T11:00:00.000Z")); - b.add(DateFormatUtils.parseDateTime("2016-03-10T15:00:00.000Z")); - - assertIntersect("[Interval{lo=2016-03-10T11:00:00.000Z, hi=2016-03-10T12:00:00.000Z},Interval{lo=2016-03-10T14:00:00.000Z, hi=2016-03-10T15:00:00.000Z}]"); - } - - @Test - public void testParseLongInterval22() throws Exception { - assertShortInterval("[Interval{lo=2015-03-12T10:00:00.000Z, hi=2015-03-12T10:05:00.999Z},Interval{lo=2015-03-12T10:30:00.000Z, hi=2015-03-12T10:35:00.999Z},Interval{lo=2015-03-12T11:00:00.000Z, hi=2015-03-12T11:05:00.999Z},Interval{lo=2015-03-12T11:30:00.000Z, hi=2015-03-12T11:35:00.999Z},Interval{lo=2015-03-12T12:00:00.000Z, hi=2015-03-12T12:05:00.999Z},Interval{lo=2015-03-12T12:30:00.000Z, hi=2015-03-12T12:35:00.999Z},Interval{lo=2015-03-12T13:00:00.000Z, hi=2015-03-12T13:05:00.999Z},Interval{lo=2015-03-12T13:30:00.000Z, hi=2015-03-12T13:35:00.999Z},Interval{lo=2015-03-12T14:00:00.000Z, hi=2015-03-12T14:05:00.999Z},Interval{lo=2015-03-12T14:30:00.000Z, hi=2015-03-12T14:35:00.999Z}]", - "2015-03-12T10:00:00;5m;30m;10"); - } - - @Test - public void testParseLongInterval32() throws Exception { - assertShortInterval("[Interval{lo=2016-03-21T00:00:00.000Z, hi=2021-03-21T23:59:59.999Z}]", "2016-03-21;3y;6M;5"); - } - - @Test - public void testParseShortDayErr() { - assertIntervalError("2016-02-30"); - } - - @Test - public void testParseShortDayErr2() { - assertIntervalError("2016-02-3"); - } - - @Test - public void testParseShortHourErr1() { - assertIntervalError("2016-02-15T1"); - } - - @Test - public void testParseShortHourErr2() { - assertIntervalError("2016-02-15T31"); - } - - @Test - public void testParseShortHourErr3() { - assertIntervalError("2016-02-15X1"); - } - - @Test - public void testParseShortInterval1() throws Exception { - assertShortInterval("[Interval{lo=2016-01-01T00:00:00.000Z, hi=2016-12-31T23:59:59.999Z}]", "2016"); - } - - @Test - public void testParseShortInterval2() throws Exception { - assertShortInterval("[Interval{lo=2016-03-01T00:00:00.000Z, hi=2016-03-31T23:59:59.999Z}]", "2016-03"); - } - - @Test - public void testParseShortInterval3() throws Exception { - assertShortInterval("[Interval{lo=2016-03-21T00:00:00.000Z, hi=2016-03-21T23:59:59.999Z}]", "2016-03-21"); - } - - @Test - public void testParseShortInterval32() throws Exception { - assertShortInterval("[Interval{lo=2016-03-21T00:00:00.000Z, hi=2016-03-21T23:59:59.999Z}]", "2016-03-21"); - } - - @Test - public void testParseShortInterval4() throws Exception { - assertShortInterval("[Interval{lo=2016-03-21T10:00:00.000Z, hi=2016-03-21T10:59:59.999Z}]", "2016-03-21T10"); - } - - @Test - public void testParseShortInterval5() throws Exception { - assertShortInterval("[Interval{lo=2016-03-21T10:30:00.000Z, hi=2016-03-21T10:30:59.999Z}]", "2016-03-21T10:30"); - } - - @Test - public void testParseShortInterval6() throws Exception { - assertShortInterval("[Interval{lo=2016-03-21T10:30:40.000Z, hi=2016-03-21T10:30:40.999Z}]", "2016-03-21T10:30:40"); - } - - @Test - public void testParseShortInterval7() throws Exception { - assertShortInterval("[Interval{lo=2016-03-21T10:30:40.100Z, hi=2016-03-21T10:30:40.100Z}]", "2016-03-21T10:30:40.100Z"); - } - - @Test - public void testParseShortMilliErr() { - assertIntervalError("2016-03-21T10:31:61.23"); - } - - @Test - public void testParseShortMinErr() { - assertIntervalError("2016-03-21T10:3"); - } - - @Test - public void testParseShortMinErr2() { - assertIntervalError("2016-03-21T10:69"); - } - - @Test - public void testParseShortMonthErr() { - assertIntervalError("2016-1"); - } - - @Test - public void testParseShortMonthErr2() { - assertIntervalError("2016x11"); - } - - @Test - public void testParseShortMonthRange() { - assertIntervalError("2016-66"); - } - - @Test - public void testParseShortSecErr() { - assertIntervalError("2016-03-21T10:31:61"); - } - - @Test - public void testParseShortSecErr1() { - assertIntervalError("2016-03-21T10:31:1"); - } - - @Test - public void testParseShortYearErr() { - assertIntervalError("201"); - } - - @Test - public void testSubtractClipNone() throws Exception { - a.add(DateFormatUtils.parseDateTime("2016-03-10T10:00:00.000Z")); - a.add(DateFormatUtils.parseDateTime("2016-03-10T12:00:00.000Z")); - - a.add(DateFormatUtils.parseDateTime("2016-03-10T14:00:00.000Z")); - a.add(DateFormatUtils.parseDateTime("2016-03-10T15:00:00.000Z")); - - b.add(DateFormatUtils.parseDateTime("2016-03-10T13:00:00.000Z")); - b.add(DateFormatUtils.parseDateTime("2016-03-10T13:30:00.000Z")); - - IntervalCompiler.subtract(a, b, out); - Assert.assertEquals("[Interval{lo=2016-03-10T10:00:00.000Z, hi=2016-03-10T12:00:00.000Z},Interval{lo=2016-03-10T14:00:00.000Z, hi=2016-03-10T15:00:00.000Z}]", - IntervalCompiler.asIntervalStr(out)); - } - - @Test - public void testSubtractClipTwo() throws Exception { - a.add(DateFormatUtils.parseDateTime("2016-03-10T10:00:00.000Z")); - a.add(DateFormatUtils.parseDateTime("2016-03-10T12:00:00.000Z")); - - a.add(DateFormatUtils.parseDateTime("2016-03-10T14:00:00.000Z")); - a.add(DateFormatUtils.parseDateTime("2016-03-10T15:00:00.000Z")); - - b.add(DateFormatUtils.parseDateTime("2016-03-10T11:00:00.000Z")); - b.add(DateFormatUtils.parseDateTime("2016-03-10T14:30:00.000Z")); - - IntervalCompiler.subtract(a, b, out); - Assert.assertEquals("[Interval{lo=2016-03-10T10:00:00.000Z, hi=2016-03-10T10:59:59.999Z},Interval{lo=2016-03-10T14:30:00.001Z, hi=2016-03-10T15:00:00.000Z}]", IntervalCompiler.asIntervalStr(out)); - } - - @Test - public void testSubtractConsume() throws Exception { - a.add(DateFormatUtils.parseDateTime("2016-03-10T11:00:00.000Z")); - a.add(DateFormatUtils.parseDateTime("2016-03-10T12:00:00.000Z")); - - b.add(DateFormatUtils.parseDateTime("2016-03-10T10:00:00.000Z")); - b.add(DateFormatUtils.parseDateTime("2016-03-10T14:00:00.000Z")); - - IntervalCompiler.subtract(a, b, out); - Assert.assertEquals("[]", IntervalCompiler.asIntervalStr(out)); - } - - @Test - public void testSubtractMakeHole() throws Exception { - a.add(DateFormatUtils.parseDateTime("2016-03-10T10:00:00.000Z")); - a.add(DateFormatUtils.parseDateTime("2016-03-10T12:00:00.000Z")); - b.add(DateFormatUtils.parseDateTime("2016-03-10T10:30:00.000Z")); - b.add(DateFormatUtils.parseDateTime("2016-03-10T11:30:00.000Z")); - - IntervalCompiler.subtract(a, b, out); - Assert.assertEquals("[Interval{lo=2016-03-10T10:00:00.000Z, hi=2016-03-10T10:29:59.999Z},Interval{lo=2016-03-10T11:30:00.001Z, hi=2016-03-10T12:00:00.000Z}]", IntervalCompiler.asIntervalStr(out)); - } - - @Test - public void testSubtractSame() throws Exception { - a.add(DateFormatUtils.parseDateTime("2016-03-10T10:00:00.000Z")); - a.add(DateFormatUtils.parseDateTime("2016-03-10T12:00:00.000Z")); - b.add(DateFormatUtils.parseDateTime("2016-03-10T10:00:00.000Z")); - b.add(DateFormatUtils.parseDateTime("2016-03-10T12:00:00.000Z")); - - IntervalCompiler.subtract(a, b, out); - Assert.assertEquals("[]", IntervalCompiler.asIntervalStr(out)); - } - - private static void assertShortInterval(String expected, String interval) throws ParserException { - LongList out = new LongList(); - IntervalCompiler.parseIntervalEx(interval, 0, interval.length(), 0, out); - Assert.assertEquals(expected, IntervalCompiler.asIntervalStr(out)); - } - - private void assertIntersect(String expected) { - IntervalCompiler.intersect(a, b, out); - Assert.assertEquals(expected, IntervalCompiler.asIntervalStr(out)); - } - - private void assertIntervalError(String interval) { - try { - IntervalCompiler.parseIntervalEx(interval, 0, interval.length(), 0, out); - Assert.fail(); - } catch (ParserException ignore) { - } - } - -} \ No newline at end of file diff --git a/core/src/test/java/com/questdb/parser/sql/InvertedBooleanOptimisationTest.java b/core/src/test/java/com/questdb/parser/sql/InvertedBooleanOptimisationTest.java deleted file mode 100644 index d4a14a411..000000000 --- a/core/src/test/java/com/questdb/parser/sql/InvertedBooleanOptimisationTest.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.parser.sql; - -import com.questdb.ex.ParserException; -import com.questdb.parser.sql.model.ExprNode; -import com.questdb.std.Lexer; -import com.questdb.std.ObjectPool; -import com.questdb.test.tools.AbstractTest; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class InvertedBooleanOptimisationTest extends AbstractTest { - - private final RpnBuilder rpn = new RpnBuilder(); - private final ObjectPool exprNodeObjectPool = new ObjectPool<>(ExprNode.FACTORY, 128); - private final Lexer lexer = new Lexer(); - private final ExprParser p = new ExprParser(exprNodeObjectPool); - private final ExprAstBuilder ast = new ExprAstBuilder(); - private final PostOrderTreeTraversalAlgo traversalAlgo = new PostOrderTreeTraversalAlgo(); - private final PostOrderTreeTraversalAlgo.Visitor rpnBuilderVisitor = rpn::onNode; - private final QueryCompiler compiler = new QueryCompiler(); - - @Before - public void setUp() { - exprNodeObjectPool.clear(); - ExprParser.configureLexer(lexer); - } - - @Test - public void testDoubleInversion() throws Exception { - assertOk("ba>", "not (not (a > b))"); - } - - @Test - public void testFunction() throws Exception { - assertOk("'b''a'ainnot", "not(a in ('a', 'b'))"); - } - - @Test - public void testInvertAnd() throws Exception { - assertOk("dc!=ba=or", "not (a != b and c = d)"); - } - - @Test - public void testInvertAnd2() throws Exception { - assertOk("'xyz'x~notdc!=ba=oror", "not (a != b and c = d and x ~ 'xyz')"); - } - - @Test - public void testInvertEquals() throws Exception { - assertOk("ba!=", "not (a = b)"); - } - - @Test - public void testInvertGreater() throws Exception { - assertOk("ba<=", "not (a > b)"); - } - - @Test - public void testInvertGreaterOrEqual() throws Exception { - assertOk("ba<", "not (a >= b)"); - } - - @Test - public void testInvertLess() throws Exception { - assertOk("ba>=", "not (a < b)"); - } - - @Test - public void testInvertLessOrEqual() throws Exception { - assertOk("ba>", "not (a <= b)"); - } - - @Test - public void testInvertNotEquals() throws Exception { - assertOk("ba=", "not (a != b)"); - } - - @Test - public void testInvertOr() throws Exception { - assertOk("dc<=ba<=and", "not (a > b or c > d)"); - } - - @Test - public void testInvertOrAndAnd() throws Exception { - assertOk("10c!=dc>ba<=andor", "not (a > b or not(c > d) and c = 10)"); - } - - @Test - public void testLiteral() throws Exception { - assertOk("anot", "not(a)"); - } - - @Test - public void testNoInversion() throws Exception { - assertOk("cb+a>", "(a > (b + c))"); - } - - private void assertOk(CharSequence expected, String expression) throws ParserException { - lexer.setContent(expression); - p.parseExpr(lexer, ast); - ExprNode n = compiler.optimiseInvertedBooleans(ast.poll(), false); - Assert.assertNotNull(n); - TestUtils.assertEquals(expected, toRpn(n)); - } - - private CharSequence toRpn(ExprNode node) throws ParserException { - rpn.reset(); - traversalAlgo.traverse(node, rpnBuilderVisitor); - return rpn.rpn(); - } -} diff --git a/core/src/test/java/com/questdb/parser/sql/JoinQueryTest.java b/core/src/test/java/com/questdb/parser/sql/JoinQueryTest.java deleted file mode 100644 index abd914ade..000000000 --- a/core/src/test/java/com/questdb/parser/sql/JoinQueryTest.java +++ /dev/null @@ -1,1920 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.parser.sql; - -import com.questdb.ex.ParserException; -import com.questdb.ql.NoRowIdRecordSource; -import com.questdb.ql.RecordSource; -import com.questdb.ql.join.HashJoinRecordSource; -import com.questdb.ql.map.RecordKeyCopierCompiler; -import com.questdb.std.*; -import com.questdb.std.ex.JournalException; -import com.questdb.std.time.DateFormatUtils; -import com.questdb.store.JournalEntryWriter; -import com.questdb.store.JournalWriter; -import com.questdb.store.MMappedSymbolTable; -import com.questdb.store.factory.configuration.JournalStructure; -import com.questdb.test.tools.TestUtils; -import org.junit.After; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -public class JoinQueryTest extends AbstractOptimiserTest { - - @BeforeClass - public static void setUpClass() throws Exception { - FACTORY_CONTAINER.getConfiguration().exists(""); - generateJoinData(); - } - - @After - public void tearDown() { - Assert.assertEquals(0, FACTORY_CONTAINER.getFactory().getBusyReaderCount()); - Assert.assertEquals(0, FACTORY_CONTAINER.getFactory().getBusyWriterCount()); - } - - @Test - public void testAggregationSymbolBehaviour() throws Exception { - assertSymbol("select country, max(customerId) from customers", 0); - } - - @Test - public void testAllOrdersForACustomers() throws Exception { - assertThat("32209860\t1\t1000\tMZPFIR\t2015-07-10T00:00:17.050Z\tOJXJCNBLYTOIYI\n" + - "1020826110\t1\t1884\tGRG\t2015-07-10T00:00:21.152Z\tQXOLEEXZ\n" + - "1921430865\t1\t1682\tXV\t2015-07-10T00:00:27.676Z\tMZCMZMHGTIQ\n" + - "355660772\t1\t1766\tOFN\t2015-07-10T00:00:33.004Z\tW\n" + - "1078912382\t1\t1296\tYBHPRQD\t2015-07-10T00:00:54.661Z\tYJZPHQDJKOM\n" + - "1173798559\t1\t387\t\t2015-07-10T00:01:00.700Z\tKZRCKS\n" + - "132190528\t1\t1088\t\t2015-07-10T00:01:07.110Z\tFBLGGTZEN\n" + - "385427654\t1\t1703\tXEMP\t2015-07-10T00:01:33.250Z\tMZCMZMHGTIQ\n", - "orders where customerId = 1 "); - } - - @Test - public void testAmbiguousColumn() { - try { - assertPlan2("", "orders join customers on customerId = customerId"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertEquals(25, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Ambiguous")); - } - } - - @Test - public void testAsOfJoinOrder() throws Exception { - assertPlan2("{\n" + - " \"op\": \"HashJoinRecordSource\",\n" + - " \"master\": {\n" + - " \"op\": \"AsOfPartitionedJoinRecordSource\",\n" + - " \"master\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"customers\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " },\n" + - " \"slave\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"employees\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " },\n" + - " \"masterTsIndex\": 7,\n" + - " \"slaveTsIndex\": 4\n" + - " },\n" + - " \"slave\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"orders\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " },\n" + - " \"joinOn\": [\n" + - " [\n" + - " \"customerId\"\n" + - " ],\n" + - " [\n" + - " \"customerId\"\n" + - " ]\n" + - " ]\n" + - "}", - "customers c" + - " asof join employees e on c.customerId = e.employeeId" + - " join orders o on c.customerId = o.customerId"); - } - - @Test - public void testAsOfJoinSubQuery() throws Exception { - assertPlan2("{\n" + - " \"op\": \"HashJoinRecordSource\",\n" + - " \"master\": {\n" + - " \"op\": \"FilteredRecordSource\",\n" + - " \"src\": {\n" + - " \"op\": \"AsOfPartitionedJoinRecordSource\",\n" + - " \"master\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"customers\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " },\n" + - " \"slave\": {\n" + - " \"op\": \"RBTreeSortedRecordSource\",\n" + - " \"byRowId\": true,\n" + - " \"src\": {\n" + - " \"op\": \"SelectedColumnsRecordSource\",\n" + - " \"src\": {\n" + - " \"op\": \"VirtualColumnRecordSource\",\n" + - " \"src\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"employees\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"FilteredRowSource\",\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - " },\n" + - " \"masterTsIndex\": 7,\n" + - " \"slaveTsIndex\": 3\n" + - " },\n" + - " \"filter\": \"e.blah \\u003d \\u0027y\\u0027\"\n" + - " },\n" + - " \"slave\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"orders\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " },\n" + - " \"joinOn\": [\n" + - " [\n" + - " \"customerId\"\n" + - " ],\n" + - " [\n" + - " \"customerId\"\n" + - " ]\n" + - " ]\n" + - "}", - "customers c" + - " asof join (select '1' blah, lastName, employeeId, timestamp from employees order by lastName) e on c.customerId = e.employeeId" + - " join orders o on c.customerId = o.customerId where e.lastName = 'x' and e.blah = 'y'"); - } - - @Test - public void testAsOfJoinSubQuerySimpleAlias() throws Exception { - assertPlan2("{\n" + - " \"op\": \"AsOfPartitionedJoinRecordSource\",\n" + - " \"master\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"customers\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " },\n" + - " \"slave\": {\n" + - " \"op\": \"RBTreeSortedRecordSource\",\n" + - " \"byRowId\": true,\n" + - " \"src\": {\n" + - " \"op\": \"SelectedColumnsRecordSource\",\n" + - " \"src\": {\n" + - " \"op\": \"VirtualColumnRecordSource\",\n" + - " \"src\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"employees\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - " },\n" + - " \"masterTsIndex\": 7,\n" + - " \"slaveTsIndex\": 3\n" + - "}", - "customers c" + - " asof join (select '1' blah, lastName, employeeId customerId, timestamp from employees order by lastName) a on (customerId)"); - } - - @Test - public void testAsOfJoinSubQuerySimpleNoAlias() throws Exception { - assertPlan2("{\n" + - " \"op\": \"AsOfPartitionedJoinRecordSource\",\n" + - " \"master\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"customers\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " },\n" + - " \"slave\": {\n" + - " \"op\": \"RBTreeSortedRecordSource\",\n" + - " \"byRowId\": true,\n" + - " \"src\": {\n" + - " \"op\": \"SelectedColumnsRecordSource\",\n" + - " \"src\": {\n" + - " \"op\": \"VirtualColumnRecordSource\",\n" + - " \"src\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"employees\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - " },\n" + - " \"masterTsIndex\": 7,\n" + - " \"slaveTsIndex\": 3\n" + - "}", - "customers c" + - " asof join (select '1' blah, lastName, employeeId customerId, timestamp from employees order by lastName) on (customerId)"); - } - - @Test - public void testAsOfJoinSymbolBehaviour() throws Exception { - assertSymbol("select c.customerId, country from customers c" + - " asof join employees e on c.customerId = e.employeeId" + - " join orders o on c.customerId = o.customerId", 1); - - } - - @Test - public void testCount() throws Exception { - assertThat("162\t1\n" + - "209\t1\n" + - "233\t1\n" + - "381\t1\n" + - "396\t1\n" + - "410\t1\n" + - "805\t1\n" + - "810\t1\n" + - "1162\t1\n" + - "1344\t1\n" + - "1406\t1\n" + - "1414\t1\n" + - "1422\t1\n" + - "1523\t1\n" + - "1567\t1\n" + - "1589\t1\n" + - "1689\t1\n" + - "1734\t1\n" + - "1913\t1\n" + - "2172\t1\n" + - "2312\t1\n" + - "2378\t1\n" + - "2385\t1\n" + - "2990\t1\n" + - "3036\t1\n" + - "3171\t1\n" + - "3213\t1\n" + - "3222\t1\n" + - "3226\t1\n" + - "3270\t1\n" + - "3383\t1\n" + - "3476\t1\n" + - "3478\t1\n" + - "3502\t1\n" + - "3589\t1\n" + - "3663\t1\n" + - "3703\t1\n" + - "3751\t1\n" + - "3891\t1\n" + - "3935\t1\n" + - "4041\t1\n" + - "4059\t1\n" + - "4132\t1\n" + - "4412\t1\n" + - "4432\t1\n" + - "4745\t1\n" + - "4839\t1\n" + - "4934\t1\n" + - "4963\t1\n" + - "4981\t1\n" + - "5207\t1\n" + - "5288\t1\n" + - "5387\t1\n" + - "5445\t1\n" + - "5653\t1\n" + - "5684\t1\n" + - "5956\t1\n" + - "6006\t1\n" + - "6039\t1\n" + - "6122\t1\n" + - "6468\t1\n" + - "6486\t1\n" + - "6678\t1\n" + - "6691\t1\n" + - "6728\t1\n" + - "6826\t1\n" + - "6926\t1\n" + - "7021\t1\n" + - "7053\t1\n" + - "7056\t1\n" + - "7122\t1\n" + - "7175\t1\n" + - "7262\t1\n" + - "7347\t1\n" + - "7473\t1\n" + - "7478\t1\n" + - "7497\t1\n" + - "7513\t1\n" + - "7644\t1\n" + - "7737\t1\n" + - "7911\t1\n" + - "7961\t1\n" + - "7968\t1\n" + - "7976\t1\n" + - "8074\t1\n" + - "8113\t1\n" + - "8121\t1\n" + - "8130\t1\n" + - "8199\t1\n" + - "8284\t1\n" + - "8320\t1\n" + - "8379\t1\n" + - "8532\t1\n" + - "8549\t1\n" + - "8567\t1\n" + - "8821\t1\n" + - "9021\t1\n" + - "9180\t1\n" + - "9752\t1\n" + - "9754\t1\n" + - "9782\t1\n" + - "9977\t1\n" + - "9992\t1\n", - "select c.customerId, count() from customers c" + - " outer join orders o on c.customerId = o.customerId " + - " where o.customerId = NaN"); - } - - @Test - public void testDuplicateAlias() { - try { - assertPlan2("", "customers a" + - " cross join orders a"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertEquals(30, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Duplicate")); - } - } - - @Test - public void testDuplicateJournals() throws Exception { - assertPlan2("{\n" + - " \"op\": \"CrossJoinRecordSource\",\n" + - " \"master\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"customers\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " },\n" + - " \"slave\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"customers\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " }\n" + - "}", - "customers" + - " cross join customers"); - } - - @Test - public void testEqualsConstantTransitivityLhs() throws Exception { - assertPlan("+ 0[ cross ] c (filter: 100 = c.customerId)\n" + - "+ 1[ outer ] o (filter: o.customerId = 100) ON o.customerId = c.customerId\n" + - "\n", - "customers c" + - " outer join orders o on c.customerId = o.customerId" + - " where 100 = c.customerId"); - } - - @Test - public void testEqualsConstantTransitivityRhs() throws Exception { - assertPlan("+ 0[ cross ] c (filter: c.customerId = 100)\n" + - "+ 1[ outer ] o (filter: o.customerId = 100) ON o.customerId = c.customerId\n" + - "\n", - "customers c" + - " outer join orders o on c.customerId = o.customerId" + - " where c.customerId = 100"); - } - - @Test - public void testExceptionOnIntLatestByWithoutFilter() throws Exception { - try { - assertThat("", "orders latest by customerId"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertEquals(17, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Only SYM columns")); - } - } - - @Test - public void testFilterOnSubquery() throws Exception { - assertEmpty("(select customerId, customerName, count() count from customers) c" + - " outer join orders o on c.customerId = o.customerId " + - " where o.orderId = NaN and c.customerId > 400 and c.customerId < 1200 and count > 1 order by c.customerId"); - } - - @Test - public void testGenericPreFilterPlacement() throws Exception { - assertPlan("+ 0[ cross ] customers (filter: customerName ~ 'WTBHZVPVZZ')\n" + - "+ 1[ inner ] orders ON orders.customerId = customers.customerId\n" + - "\n", - "select customerName, orderId, productId " + - "from customers join orders on customers.customerId = orders.customerId where customerName ~ 'WTBHZVPVZZ'"); - } - - @Test - public void testInnerJoin() throws Exception { - final String expected = "customerId\tcustomerName\tcontactName\taddress\tcity\tpostalCode\tcountry\ttimestamp\torderId\tcustomerId\tproductId\temployeeId\torderDate\tshipper\n" + - "9619\tWTBHZVPVZZ\tT\t\tBMUPYPIZEPQKHZNGZGBUWDS\tPNKVDJOF\tFLRBROMNXKU\t2015-07-10T00:00:09.619Z\t1605271283\t9619\t486\t\t2015-07-10T00:00:29.443Z\tYM\n" + - "9619\tWTBHZVPVZZ\tT\t\tBMUPYPIZEPQKHZNGZGBUWDS\tPNKVDJOF\tFLRBROMNXKU\t2015-07-10T00:00:09.619Z\t401073894\t9619\t1645\tDND\t2015-07-10T00:00:31.115Z\tFNMURHFGESODNWN\n" + - "9619\tWTBHZVPVZZ\tT\t\tBMUPYPIZEPQKHZNGZGBUWDS\tPNKVDJOF\tFLRBROMNXKU\t2015-07-10T00:00:09.619Z\t921021073\t9619\t1860\tSR\t2015-07-10T00:00:41.263Z\tOJXJCNBLYTOIYI\n" + - "9619\tWTBHZVPVZZ\tT\t\tBMUPYPIZEPQKHZNGZGBUWDS\tPNKVDJOF\tFLRBROMNXKU\t2015-07-10T00:00:09.619Z\t1986641415\t9619\t935\tUFUC\t2015-07-10T00:00:50.470Z\tFREQGOPJK\n" + - "9619\tWTBHZVPVZZ\tT\t\tBMUPYPIZEPQKHZNGZGBUWDS\tPNKVDJOF\tFLRBROMNXKU\t2015-07-10T00:00:09.619Z\t1635896684\t9619\t228\tRQLVWE\t2015-07-10T00:00:51.036Z\tMZCMZMHGTIQ\n" + - "9619\tWTBHZVPVZZ\tT\t\tBMUPYPIZEPQKHZNGZGBUWDS\tPNKVDJOF\tFLRBROMNXKU\t2015-07-10T00:00:09.619Z\t189633559\t9619\t830\tRQMR\t2015-07-10T00:01:20.166Z\tQPL\n" + - "9619\tWTBHZVPVZZ\tT\t\tBMUPYPIZEPQKHZNGZGBUWDS\tPNKVDJOF\tFLRBROMNXKU\t2015-07-10T00:00:09.619Z\t960875992\t9619\t960\t\t2015-07-10T00:01:29.735Z\tYJZPHQDJKOM\n"; - - assertThat(expected, "customers join orders on customers.customerId = orders.customerId where customerName ~ 'WTBHZVPVZZ'", true); - } - - @Test - public void testInnerJoinEqualsConstant() throws Exception { - final String expected = "9619\tWTBHZVPVZZ\tT\t\tBMUPYPIZEPQKHZNGZGBUWDS\tPNKVDJOF\tFLRBROMNXKU\t2015-07-10T00:00:09.619Z\t1605271283\t9619\t486\t\t2015-07-10T00:00:29.443Z\tYM\n" + - "9619\tWTBHZVPVZZ\tT\t\tBMUPYPIZEPQKHZNGZGBUWDS\tPNKVDJOF\tFLRBROMNXKU\t2015-07-10T00:00:09.619Z\t401073894\t9619\t1645\tDND\t2015-07-10T00:00:31.115Z\tFNMURHFGESODNWN\n" + - "9619\tWTBHZVPVZZ\tT\t\tBMUPYPIZEPQKHZNGZGBUWDS\tPNKVDJOF\tFLRBROMNXKU\t2015-07-10T00:00:09.619Z\t921021073\t9619\t1860\tSR\t2015-07-10T00:00:41.263Z\tOJXJCNBLYTOIYI\n" + - "9619\tWTBHZVPVZZ\tT\t\tBMUPYPIZEPQKHZNGZGBUWDS\tPNKVDJOF\tFLRBROMNXKU\t2015-07-10T00:00:09.619Z\t1986641415\t9619\t935\tUFUC\t2015-07-10T00:00:50.470Z\tFREQGOPJK\n" + - "9619\tWTBHZVPVZZ\tT\t\tBMUPYPIZEPQKHZNGZGBUWDS\tPNKVDJOF\tFLRBROMNXKU\t2015-07-10T00:00:09.619Z\t1635896684\t9619\t228\tRQLVWE\t2015-07-10T00:00:51.036Z\tMZCMZMHGTIQ\n" + - "9619\tWTBHZVPVZZ\tT\t\tBMUPYPIZEPQKHZNGZGBUWDS\tPNKVDJOF\tFLRBROMNXKU\t2015-07-10T00:00:09.619Z\t189633559\t9619\t830\tRQMR\t2015-07-10T00:01:20.166Z\tQPL\n" + - "9619\tWTBHZVPVZZ\tT\t\tBMUPYPIZEPQKHZNGZGBUWDS\tPNKVDJOF\tFLRBROMNXKU\t2015-07-10T00:00:09.619Z\t960875992\t9619\t960\t\t2015-07-10T00:01:29.735Z\tYJZPHQDJKOM\n"; - - assertThat(expected, "customers join orders on customers.customerId = orders.customerId where customerName = 'WTBHZVPVZZ'"); - assertString("customers join orders on customers.customerId = orders.customerId where customerName = 'WTBHZVPVZZ'", 1); - assertString("customers join orders on customers.customerId = orders.customerId where customerName = 'WTBHZVPVZZ'", 11); - } - - @Test - public void testInnerJoinEqualsConstantLhs() throws Exception { - final String expected = "9619\tWTBHZVPVZZ\tT\t\tBMUPYPIZEPQKHZNGZGBUWDS\tPNKVDJOF\tFLRBROMNXKU\t2015-07-10T00:00:09.619Z\t1605271283\t9619\t486\t\t2015-07-10T00:00:29.443Z\tYM\n" + - "9619\tWTBHZVPVZZ\tT\t\tBMUPYPIZEPQKHZNGZGBUWDS\tPNKVDJOF\tFLRBROMNXKU\t2015-07-10T00:00:09.619Z\t401073894\t9619\t1645\tDND\t2015-07-10T00:00:31.115Z\tFNMURHFGESODNWN\n" + - "9619\tWTBHZVPVZZ\tT\t\tBMUPYPIZEPQKHZNGZGBUWDS\tPNKVDJOF\tFLRBROMNXKU\t2015-07-10T00:00:09.619Z\t921021073\t9619\t1860\tSR\t2015-07-10T00:00:41.263Z\tOJXJCNBLYTOIYI\n" + - "9619\tWTBHZVPVZZ\tT\t\tBMUPYPIZEPQKHZNGZGBUWDS\tPNKVDJOF\tFLRBROMNXKU\t2015-07-10T00:00:09.619Z\t1986641415\t9619\t935\tUFUC\t2015-07-10T00:00:50.470Z\tFREQGOPJK\n" + - "9619\tWTBHZVPVZZ\tT\t\tBMUPYPIZEPQKHZNGZGBUWDS\tPNKVDJOF\tFLRBROMNXKU\t2015-07-10T00:00:09.619Z\t1635896684\t9619\t228\tRQLVWE\t2015-07-10T00:00:51.036Z\tMZCMZMHGTIQ\n" + - "9619\tWTBHZVPVZZ\tT\t\tBMUPYPIZEPQKHZNGZGBUWDS\tPNKVDJOF\tFLRBROMNXKU\t2015-07-10T00:00:09.619Z\t189633559\t9619\t830\tRQMR\t2015-07-10T00:01:20.166Z\tQPL\n" + - "9619\tWTBHZVPVZZ\tT\t\tBMUPYPIZEPQKHZNGZGBUWDS\tPNKVDJOF\tFLRBROMNXKU\t2015-07-10T00:00:09.619Z\t960875992\t9619\t960\t\t2015-07-10T00:01:29.735Z\tYJZPHQDJKOM\n"; - - assertThat(expected, "customers join orders on customers.customerId = orders.customerId where 'WTBHZVPVZZ' = customerName"); - } - - @Test - public void testInnerJoinSubQuery() throws Exception { - final String expected = - "WTBHZVPVZZ\tBOKHCKYDMWZ\t1605271283\n" + - "WTBHZVPVZZ\tKD\t401073894\n" + - "WTBHZVPVZZ\tBWJG\t921021073\n" + - "WTBHZVPVZZ\tK\t1986641415\n" + - "WTBHZVPVZZ\tBXWG\t1635896684\n" + - "WTBHZVPVZZ\tKRBCWYMNOQS\t189633559\n" + - "WTBHZVPVZZ\tFEOLY\t960875992\n"; - - assertThat(expected, "select customerName, productName, orderId from (" + - "select customerName, orderId, productId " + - "from customers join orders on customers.customerId = orders.customerId where customerName ~ 'WTBHZVPVZZ'" + - ") x" + - " join products p on p.productId = x.productId"); - - assertThat(expected, "select customerName, productName, orderId " + - " from customers join orders o on customers.customerId = o.customerId " + - " join products p on p.productId = o.productId" + - " where customerName ~ 'WTBHZVPVZZ'"); - } - - @Test - public void testInnerJoinSymbol() throws Exception { - assertSymbol("select country from customers join orders on customers.customerId = orders.customerId where customerName ~ 'WTBHZVPVZZ'", 0); - } - - @Test - public void testIntrinsicFalse() throws Exception { - assertEmpty("select customerName, productName, orderId " + - " from customers join orders o on customers.customerId = o.customerId " + - " join products p on p.productId = o.productId" + - " where customerName ~ 'WTBHZVPVZZ' and 1 > 1"); - } - - @Test - public void testInvalidAlias() { - try { - assertPlan2("", "orders join customers on orders.customerId = c.customerId"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertEquals(45, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "alias")); - } - } - - @Test - public void testInvalidColumn() { - try { - assertPlan2("", "orders join customers on customerIdx = customerId"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertEquals(25, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Invalid column")); - } - } - - @Test - public void testInvalidSelectColumn() { - try { - expectFailure("select c.customerId, orderIdx, o.productId from " + - "customers c " + - "join (" + - "orders latest by customerId where customerId in (`customers where customerName ~ 'PJFSREKEUNMKWOF'`)" + - ") o on c.customerId = o.customerId"); - } catch (ParserException e) { - Assert.assertEquals(21, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Invalid column")); - } - - try { - expectFailure("select c.customerId, orderId, o.productId2 from " + - "customers c " + - "join (" + - "orders latest by customerId where customerId in (`customers where customerName ~ 'PJFSREKEUNMKWOF'`)" + - ") o on c.customerId = o.customerId"); - } catch (ParserException e) { - Assert.assertEquals(30, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Invalid column")); - } - - try { - expectFailure("select c.customerId, orderId, o2.productId from " + - "customers c " + - "join (" + - "orders latest by customerId where customerId in (`customers where customerName ~ 'PJFSREKEUNMKWOF'`)" + - ") o on c.customerId = o.customerId"); - } catch (ParserException e) { - Assert.assertEquals(30, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Invalid column")); - } - } - - @Test - public void testInvalidTableName() { - try { - assertPlan2("", "orders join customer on customerId = customerId"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertEquals(12, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Journal does not exist")); - } - } - - @Test - public void testJoinColumnAlias() throws Exception { - assertThat("162\tNaN\t1\n" + - "209\tNaN\t1\n" + - "233\tNaN\t1\n" + - "381\tNaN\t1\n" + - "396\tNaN\t1\n" + - "410\tNaN\t1\n" + - "805\tNaN\t1\n" + - "810\tNaN\t1\n" + - "1162\tNaN\t1\n" + - "1344\tNaN\t1\n", - "select c.customerId, o.customerId kk, count() from customers c" + - " outer join orders o on c.customerId = o.customerId " + - " where kk = NaN limit 10"); - } - - @Test - public void testJoinCycle() throws Exception { - assertPlan("+ 0[ cross ] orders\n" + - "+ 1[ inner ] customers ON customers.customerId = orders.customerId\n" + - "+ 2[ inner ] d (filter: d.orderId = d.productId) ON d.productId = orders.orderId\n" + - "+ 3[ inner ] suppliers ON suppliers.supplier = orders.orderId\n" + - "+ 4[ inner ] products ON products.productId = orders.orderId and products.supplier = suppliers.supplier\n" + - "\n", - "orders" + - " join customers on orders.customerId = customers.customerId" + - " join orderDetails d on d.orderId = orders.orderId and orders.orderId = products.productId" + - " join suppliers on products.supplier = suppliers.supplier" + - " join products on d.productId = products.productId and orders.orderId = products.productId" + - " where orders.orderId = suppliers.supplier"); - } - - @Test - public void testJoinGroupBy() throws Exception { - assertThat("ZHCN\t2.541666666667\n" + - "ZEQGMPLUCFTL\t2.549034175334\n" + - "ZKX\t2.485995457986\n" + - "ZRPFMDVVG\t2.508350730689\n" + - "ZV\t2.485329103886\n" + - "ZEPIHVLTOVLJUM\t2.485179407176\n" + - "ZGKC\t2.525787965616\n" + - "ZHEI\t2.464574898785\n" + - "ZULIG\t2.471938775510\n" + - "ZMZV\t2.470260223048\n" + - "ZI\t2.508435582822\n" + - "ZYNPPBX\t2.454467353952\n" + - "ZEOCVFFKMEKPFOY\t2.414400000000\n", - - "select country, avg(quantity) from orders o " + - "join customers c on c.customerId = o.customerId " + - "join orderDetails d on o.orderId = d.orderId" + - " where country ~ '^Z'"); - - } - - @Test - public void testJoinGroupByFilter() throws Exception { - assertThat("ZHCN\t2.541666666667\n" + - "ZEQGMPLUCFTL\t2.549034175334\n" + - "ZKX\t2.485995457986\n" + - "ZRPFMDVVG\t2.508350730689\n" + - "ZV\t2.485329103886\n" + - "ZEPIHVLTOVLJUM\t2.485179407176\n" + - "ZGKC\t2.525787965616\n" + - "ZHEI\t2.464574898785\n" + - "ZULIG\t2.471938775510\n" + - "ZMZV\t2.470260223048\n" + - "ZI\t2.508435582822\n" + - "ZYNPPBX\t2.454467353952\n" + - "ZEOCVFFKMEKPFOY\t2.414400000000\n", - - "(select country, avg(quantity) avg from orders o " + - "join customers c on c.customerId = o.customerId " + - "join orderDetails d on o.orderId = d.orderId" + - " where country ~ '^Z') where avg > 2"); - - } - - @Test - public void testJoinImpliedCrosses() throws Exception { - assertPlan("+ 3[ cross ] products\n" + - "+ 4[ inner ] suppliers ON suppliers.supplier = products.supplier\n" + - "+ 0[ cross ] orders\n" + - "+ 1[ cross ] customers\n" + - "+ 2[ cross ] d\n" + - "\n", - "orders" + - " join customers on 1=1" + - " join orderDetails d on 2=2" + - " join products on 3=3" + - " join suppliers on products.supplier = suppliers.supplier"); - } - - @Test - public void testJoinMultipleFields() throws Exception { - assertPlan("+ 0[ cross ] orders\n" + - "+ 1[ inner ] customers ON customers.customerId = orders.customerId\n" + - "+ 2[ inner ] d (filter: d.productId = d.orderId) ON d.productId = customers.customerId and d.orderId = orders.orderId\n" + - "+ 3[ inner ] products ON products.productId = d.productId\n" + - "+ 4[ inner ] suppliers ON suppliers.supplier = products.supplier\n" + - "\n", - "orders" + - " join customers on orders.customerId = customers.customerId" + - " join orderDetails d on d.orderId = orders.orderId and d.productId = customers.customerId" + - " join products on d.productId = products.productId" + - " join suppliers on products.supplier = suppliers.supplier" + - " where d.productId = d.orderId"); - } - - @Test - public void testJoinNoRowid() throws Exception { - - final String expected = "100\tPJFSREKEUNMKWOF\tUVKWCCVTJSKMXVEGPIG\t\tVMY\tRT\tEYYPDVRGRQG\t2015-07-10T00:00:00.100Z\t104281903\t100\t1138\tKWK\t2015-07-10T00:00:14.518Z\tFBLGGTZEN\n" + - "100\tPJFSREKEUNMKWOF\tUVKWCCVTJSKMXVEGPIG\t\tVMY\tRT\tEYYPDVRGRQG\t2015-07-10T00:00:00.100Z\t1191623531\t100\t1210\tSR\t2015-07-10T00:00:18.175Z\tYM\n" + - "100\tPJFSREKEUNMKWOF\tUVKWCCVTJSKMXVEGPIG\t\tVMY\tRT\tEYYPDVRGRQG\t2015-07-10T00:00:00.100Z\t1662742408\t100\t1828\tQH\t2015-07-10T00:00:19.509Z\tEYBI\n" + - "100\tPJFSREKEUNMKWOF\tUVKWCCVTJSKMXVEGPIG\t\tVMY\tRT\tEYYPDVRGRQG\t2015-07-10T00:00:00.100Z\t220389\t100\t1293\tDGEEWB\t2015-07-10T00:00:56.196Z\tEYBI\n" + - "100\tPJFSREKEUNMKWOF\tUVKWCCVTJSKMXVEGPIG\t\tVMY\tRT\tEYYPDVRGRQG\t2015-07-10T00:00:00.100Z\t798408721\t100\t803\tZIHLGS\t2015-07-10T00:00:56.977Z\tVTNNKVOLHLLNN\n" + - "100\tPJFSREKEUNMKWOF\tUVKWCCVTJSKMXVEGPIG\t\tVMY\tRT\tEYYPDVRGRQG\t2015-07-10T00:00:00.100Z\t966974434\t100\t870\tJEOBQ\t2015-07-10T00:00:57.981Z\tW\n" + - "100\tPJFSREKEUNMKWOF\tUVKWCCVTJSKMXVEGPIG\t\tVMY\tRT\tEYYPDVRGRQG\t2015-07-10T00:00:00.100Z\t258318715\t100\t1036\tOPWOGS\t2015-07-10T00:01:00.608Z\tEYBI\n" + - "100\tPJFSREKEUNMKWOF\tUVKWCCVTJSKMXVEGPIG\t\tVMY\tRT\tEYYPDVRGRQG\t2015-07-10T00:00:00.100Z\t1528068156\t100\t400\tYBQE\t2015-07-10T00:01:20.643Z\tQXOLEEXZ\n" + - "100\tPJFSREKEUNMKWOF\tUVKWCCVTJSKMXVEGPIG\t\tVMY\tRT\tEYYPDVRGRQG\t2015-07-10T00:00:00.100Z\t1935884354\t100\t1503\tD\t2015-07-10T00:01:43.507Z\tRZVZJQRNYSRKZSJ\n"; - - final RecordSource m = compileSource("customers where customerName ~ 'PJFSREKEUNMKWOF'"); - final RecordSource s = new NoRowIdRecordSource().of(compileSource("orders")); - - RecordSource r = new HashJoinRecordSource( - m, - new IntList() {{ - add(m.getMetadata().getColumnIndex("customerId")); - }}, - s, - new IntList() {{ - add(s.getMetadata().getColumnIndex("customerId")); - }}, - false, - 4 * 1024 * 1024, - 4 * 1024 * 1024, - 1024 * 1024, - new RecordKeyCopierCompiler(new BytecodeAssembler()) - ); - sink.clear(); - printer.print(r, FACTORY_CONTAINER.getFactory()); - TestUtils.assertEquals(expected, sink); - assertThat(expected, "customers c join orders o on c.customerId = o.customerId where customerName ~ 'PJFSREKEUNMKWOF'"); - } - - @Test - public void testJoinOneFieldToTwo() throws Exception { - assertPlan("+ 0[ cross ] orders (filter: orders.customerId = orders.orderId)\n" + - "+ 1[ inner ] customers ON customers.customerId = orders.orderId\n" + - "+ 2[ inner ] d (filter: d.productId = d.orderId) ON d.orderId = customers.customerId\n" + - "+ 3[ inner ] products ON products.productId = d.productId\n" + - "+ 4[ inner ] suppliers ON suppliers.supplier = products.supplier\n" + - "\n", - "orders" + - " join customers on orders.customerId = customers.customerId" + - " join orderDetails d on d.orderId = orders.orderId and d.orderId = customers.customerId" + - " join products on d.productId = products.productId" + - " join suppliers on products.supplier = suppliers.supplier" + - " where d.productId = d.orderId"); - } - - @Test - public void testJoinOneFieldToTwoAcross() throws Exception { - assertPlan("+ 0[ cross ] orders (filter: orders.customerId = orders.orderId)\n" + - "+ 1[ inner ] customers ON customers.customerId = orders.orderId\n" + - "+ 2[ inner ] d (filter: d.productId = d.orderId) ON d.orderId = customers.customerId\n" + - "+ 3[ inner ] products ON products.productId = d.productId\n" + - "+ 4[ inner ] suppliers ON suppliers.supplier = products.supplier\n" + - "\n", - "orders" + - " join customers on orders.customerId = customers.customerId" + - " join orderDetails d on orders.orderId = d.orderId and d.orderId = customers.customerId" + - " join products on d.productId = products.productId" + - " join suppliers on products.supplier = suppliers.supplier" + - " where d.productId = d.orderId"); - } - - @Test - public void testJoinOneFieldToTwoAcross2() throws Exception { - assertPlan("+ 0[ cross ] orders (filter: orders.customerId = orders.orderId)\n" + - "+ 1[ inner ] customers ON customers.customerId = orders.orderId\n" + - "+ 2[ inner ] d (filter: d.productId = d.orderId) ON d.orderId = orders.orderId\n" + - "+ 3[ inner ] products ON products.productId = d.productId\n" + - "+ 4[ inner ] suppliers ON suppliers.supplier = products.supplier\n" + - "\n", - "orders" + - " join customers on orders.customerId = customers.customerId" + - " join orderDetails d on d.orderId = customers.customerId and orders.orderId = d.orderId" + - " join products on d.productId = products.productId" + - " join suppliers on products.supplier = suppliers.supplier" + - " where d.productId = d.orderId"); - } - - @Test - public void testJoinOneFieldToTwoReorder() throws Exception { - assertPlan("+ 0[ cross ] orders (filter: orders.orderId = orders.customerId)\n" + - "+ 1[ inner ] d (filter: d.productId = d.orderId) ON d.orderId = orders.customerId\n" + - "+ 2[ inner ] customers ON customers.customerId = orders.customerId\n" + - "+ 3[ inner ] products ON products.productId = d.productId\n" + - "+ 4[ inner ] suppliers ON suppliers.supplier = products.supplier\n" + - "\n", - "orders" + - " join orderDetails d on d.orderId = orders.orderId and d.orderId = customers.customerId" + - " join customers on orders.customerId = customers.customerId" + - " join products on d.productId = products.productId" + - " join suppliers on products.supplier = suppliers.supplier" + - " where d.productId = d.orderId"); - } - - @Test - public void testJoinReorder() throws Exception { - assertPlan("+ 0[ cross ] orders\n" + - "+ 2[ inner ] d (filter: d.productId = d.orderId) ON d.orderId = orders.orderId\n" + - "+ 1[ inner ] customers ON customers.customerId = d.productId\n" + - "+ 3[ inner ] products ON products.productId = d.productId\n" + - "+ 4[ inner ] suppliers ON suppliers.supplier = products.supplier\n" + - "\n", - "orders" + - " join customers on 1=1" + - " join orderDetails d on d.orderId = orders.orderId and d.productId = customers.customerId" + - " join products on d.productId = products.productId" + - " join suppliers on products.supplier = suppliers.supplier" + - " where d.productId = d.orderId"); - } - - @Test - public void testJoinReorder3() throws Exception { - assertPlan("+ 0[ cross ] orders\n" + - "+ 2[ inner ] shippers ON shippers.shipper = orders.orderId\n" + - "+ 3[ inner ] d (filter: d.productId = d.orderId) ON d.productId = shippers.shipper and d.orderId = orders.orderId\n" + - "+ 5[ inner ] products ON products.productId = d.productId\n" + - "+ 4[ inner ] suppliers ON suppliers.supplier = products.supplier\n" + - "+ 1[ cross ] customers\n" + - "\n", - "orders" + - " outer join customers on 1=1" + - " join shippers on shippers.shipper = orders.orderId" + - " join orderDetails d on d.orderId = orders.orderId and d.productId = shippers.shipper" + - " join suppliers on products.supplier = suppliers.supplier" + - " join products on d.productId = products.productId" + - " where d.productId = d.orderId"); - } - - @Test - public void testJoinReorderRoot() throws Exception { - assertPlan( - "+ 0[ cross ] customers\n" + - "+ 2[ inner ] d (filter: d.productId = d.orderId) ON d.productId = customers.customerId\n" + - "+ 1[ inner ] orders ON orders.orderId = d.orderId\n" + - "+ 3[ inner ] products ON products.productId = d.productId\n" + - "+ 4[ inner ] suppliers ON suppliers.supplier = products.supplier\n" + - "\n", - "customers" + - " cross join orders" + - " join orderDetails d on d.orderId = orders.orderId and d.productId = customers.customerId" + - " join products on d.productId = products.productId" + - " join suppliers on products.supplier = suppliers.supplier" + - " where d.productId = d.orderId"); - } - - @Test - public void testJoinReorderRoot2() throws Exception { - assertPlan("+ 0[ cross ] orders\n" + - "+ 2[ inner ] shippers ON shippers.shipper = orders.orderId\n" + - "+ 3[ inner ] d (filter: d.productId = d.orderId) ON d.productId = shippers.shipper and d.orderId = orders.orderId\n" + - "+ 4[ inner ] products ON products.productId = d.productId\n" + - "+ 5[ inner ] suppliers ON suppliers.supplier = products.supplier\n" + - "+ 1[ cross ] customers\n" + - "\n", - "orders" + - " outer join customers on 1=1" + - " join shippers on shippers.shipper = orders.orderId" + - " join orderDetails d on d.orderId = orders.orderId and d.productId = shippers.shipper" + - " join products on d.productId = products.productId" + - " join suppliers on products.supplier = suppliers.supplier" + - " where d.productId = d.orderId"); - } - - @Test - public void testJoinSubQuery() throws Exception { - assertPlan("+ 0[ cross ] orders\n" + - "+ 1[ inner ] {\n" + - " customers (filter: customerName ~ 'X')\n" + - "} ON customerName = orderId\n" + - "\n", - "orders" + - " cross join (select customerId, customerName from customers where customerName ~ 'X')" + - " where orderId = customerName"); - - } - - @Test - public void testJoinSymbolBehaviour() throws Exception { - assertSymbol("select customers.customerId, country from customers join orders on customers.customerId = orders.customerId where customerName ~ 'WTBHZVPVZZ'", 1); - } - - @Test - public void testJoinSymbolBehaviourOnSecondaryJournal() throws Exception { - assertSymbol("select customerName, productName, orderId, category from (" + - "select customerName, orderId, productId " + - "from customers join orders on customers.customerId = orders.customerId where customerName ~ 'WTBHZVPVZZ'" + - ") x" + - " join products p on p.productId = x.productId", 3); - } - - @Test - public void testJoinWithFilter() throws Exception { - assertPlan("+ 0[ cross ] customers\n" + - "+ 2[ inner ] d (filter: d.productId = d.orderId) ON d.productId = customers.customerId\n" + - "+ 1[ inner ] orders ON orders.orderId = d.orderId (post-filter: d.quantity < orders.orderId)\n" + - "+ 3[ inner ] products ON products.productId = d.productId (post-filter: products.price > d.quantity or d.orderId = orders.orderId)\n" + - "+ 4[ inner ] suppliers ON suppliers.supplier = products.supplier\n" + - "\n", - "customers" + - " cross join orders" + - " join orderDetails d on d.orderId = orders.orderId and d.productId = customers.customerId" + - " join products on d.productId = products.productId" + - " join suppliers on products.supplier = suppliers.supplier" + - " where d.productId = d.orderId" + - " and (products.price > d.quantity or d.orderId = orders.orderId) and d.quantity < orders.orderId"); - } - - @Test - public void testLambdaAmbiguousColumn() throws Exception { - try { - assertThat("", "orders latest by customerId where customerId in (`select customerName, city from customers where customerName ~ 'PJFSREKEUNMKWOF'`)"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertEquals(45, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Ambiguous")); - } - } - - @Test - public void testLambdaJoin() throws Exception { - final String expected = "100\t1935884354\t1503\n"; - assertThat(expected, "select c.customerId, orderId, o.productId from " + - "customers c " + - "join (" + - "orders o latest by customerId where customerId in (`customers where customerName ~ 'PJFSREKEUNMKWOF'`)" + - ") o on c.customerId = o.customerId"); - - assertThat(expected, "select c.customerId, orderId, productId from " + - "(" + - "orders latest by customerId where customerId in (`customers where customerName ~ 'PJFSREKEUNMKWOF'`)" + - ") o " + - "join customers c " + - "on c.customerId = o.customerId"); - } - - @Test - public void testLatestByAll() throws Exception { - final String expected = "MUOHOMFQCDD\t1608\tDOT\n" + - "KUTGTZHMB\t1643\tDPR\n" + - "PT\t1676\tFVUNIEULONLYL\n" + - "COX\t1699\tDSVJ\n" + - "UGSNVUPXB\t1706\tRQRGEVSIPBSFRYM\n" + - "IIKEBMITV\t1710\tIIIBVNVUJTHWQ\n" + - "UHSSLJ\t1729\tD\n" + - "JKNSQ\t1749\tDNSNKZB\n" + - "REDL\t1767\tCMLIBRH\n" + - "OH\t1776\tEGUJODLWDVJVX\n" + - "M\t1783\tQTUR\n" + - "JSZMYJJIBDSU\t1804\tG\n" + - "MG\t1807\tYGEHXEXM\n" + - "YOVV\t1811\tUUIVXRHT\n" + - "FO\t1821\tMNWSTEFB\n" + - "XCU\t1825\tWZECVHPTYUR\n" + - "GIP\t1827\tCUVSRL\n" + - "MNIKCUJZCRZGKS\t1828\tUOPESHYBD\n" + - "YCNDZMMOZCGUC\t1838\tIQEZNHNY\n" + - "MS\t1839\tLQKSGHFNX\n" + - "TDELODUR\t1854\tEFXWHJNIQID\n" + - "LKIRSRSPUZBBCEC\t1857\tMIRPINQNRWTCQS\n" + - "DXDCMGXTPLYG\t1858\tMHGTEG\n" + - "IDHRPVQMUXXUT\t1863\tOLLLGPDLQXH\n" + - "ZEMF\t1876\tBGCSFVFWNIHB\n" + - "DFPWOO\t1883\tEKHB\n" + - "YYCZINRXDDRNDYI\t1884\tKHB\n" + - "FUXEJFTGSLMCBRD\t1892\tBMFKMQVMISRBNY\n" + - "LKXJVOSTCS\t1893\tIONB\n" + - "GFYMHDPSOJRN\t1894\tBYVNBCLWIHEXQKD\n" + - "OWBWL\t1899\tRRGTYZCK\n" + - "VSQCTTQBVGX\t1902\tPDJKHSVTO\n" + - "IEDGIJKTTTRJ\t1907\tUCVMSJCIECUI\n" + - "OOUFTRGFOBQUP\t1908\tYL\n" + - "WPWKGPBPIHSBPJ\t1911\tXGNE\n" + - "WD\t1912\tDTOXEJHZ\n" + - "EYSOWXFLJQFTLN\t1914\t\n" + - "OZEZYTXUQLHDVC\t1915\tUYZZDUILRHK\n" + - "KXEFLBSJMNF\t1918\tBNCMT\n" + - "N\t1922\tVPZD\n" + - "F\t1927\tD\n" + - "LFQNDNRHKUHE\t1928\tN\n" + - "WN\t1929\tXFBBIQRKHEBQSTN\n" + - "TCHHKFDBOXM\t1930\tMGYVMSEPBBB\n" + - "LPLSXBYJGV\t1935\tWBDRRIS\n" + - "QZFCS\t1937\tX\n" + - "THTMCQK\t1939\tCFXMDHZ\n" + - "TYWWTQU\t1942\tBQQFDLT\n" + - "JZQXFVV\t1944\tIJDBKIPXC\n" + - "TBPHWXMBYPD\t1945\t\n" + - "GROTGCLGILNCXPT\t1946\tEOVGVPEHSZQJGNI\n" + - "FLDYOSB\t1947\tXIDPTECSRNIULZ\n" + - "ZZCPO\t1950\tBYYJGDD\n" + - "\t1951\tXV\n" + - "LH\t1952\tWLXTV\n" + - "YETNJDK\t1954\tPKNNWLYVDNKL\n" + - "GKXFPXPTF\t1955\tPXWIS\n" + - "BRLOQYMWFYXR\t1956\tYQMHJ\n" + - "EHGNU\t1957\tMMP\n" + - "XCGSWYUBPLZIJL\t1958\tZKCCOQKVQYJXWNN\n" + - "PIBVSPPGQB\t1960\tOKPMW\n" + - "GEH\t1961\t\n" + - "FMLZJIGGOB\t1962\tE\n" + - "EHQCMNSGOLUIYW\t1964\tSQCIDHXLLWYISI\n" + - "XMCKQC\t1965\tCQ\n" + - "YNMHE\t1966\tUPO\n" + - "XSDHPJYW\t1967\tK\n" + - "BSFFBELM\t1968\tUSEMYWS\n" + - "TCBNLUQQJENUFQ\t1969\tXRFZVXFB\n" + - "UQ\t1970\tLLMBHWNPHYKUSO\n" + - "VWSMJLRTLFSE\t1971\tQBYOW\n" + - "YEPEDZMXGGPQTII\t1976\tTCIG\n" + - "LR\t1977\tPGITMNW\n" + - "IEMVKIGGP\t1978\tGTQBME\n" + - "OQUNHZBRZUI\t1979\tEQYIBLXWRSNYPIP\n" + - "FTZVJOBSP\t1980\tBVNQH\n" + - "RNUP\t1981\tOJXCLDL\n" + - "TRTVIJESSO\t1982\tNCVTU\n" + - "TRG\t1983\tTWVBETYKOND\n" + - "DJSBQG\t1984\tTXOFKCYGYDEFOB\n" + - "XOIUNEHDUX\t1986\tRRFMGRBSVEPTB\n" + - "PR\t1988\tBE\n" + - "IONUQQEHIBISBCY\t1989\tKCDZDQYFLUCTFVB\n" + - "LKJB\t1991\tSNJ\n" + - "EWJW\t1992\tQIZYFCPJ\n" + - "CZGMSTWGT\t1993\tEQIGJH\n" + - "QNNJITVR\t1994\tGVEMJRFNNF\n" + - "MTRDCBLINP\t1995\tDOOJRCCWOILYMCF\n" + - "ZPZTFEXCNCWZU\t1996\tHFXCG\n" + - "EDXZVBDN\t1997\tUOG\n" + - "ZZKOWPSRXENWCD\t1998\tGT\n" + - "XCWMTXCFEOZVK\t1999\tRBVPSFMZUGSTDID\n"; - - assertThat(expected, "select supplier, productId, productName from products latest by supplier"); - } - - @Test - public void testLatestOrderForACustomers() throws Exception { - assertThat("385427654\t1\t1703\tXEMP\t2015-07-10T00:01:33.250Z\tMZCMZMHGTIQ\n", - "orders latest by customerId where customerId = 1 and employeeId = 'XEMP'"); - } - - @Test - public void testLatestOrderForACustomersNoFilter() throws Exception { - try { - assertThat("", "orders latest by customerId where employeeId = 'XEMP'"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertEquals(17, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Filter on int")); - } - } - - @Test - public void testLatestOrderForListOfCustomers() throws Exception { - assertThat("385427654\t1\t1703\tXEMP\t2015-07-10T00:01:33.250Z\tMZCMZMHGTIQ\n" + - "607937606\t2\t548\tOVU\t2015-07-10T00:01:49.101Z\tRZVZJQRNYSRKZSJ\n" + - "855411970\t3\t1829\tBRSYPN\t2015-07-10T00:01:51.990Z\tOJXJCNBLYTOIYI\n", - "orders latest by customerId where customerId in (1,2,3)"); - } - - @Test - public void testLimit() throws Exception { - assertThat("1406\tVQHYIIQL\tKJE\t\tDYQFLMPNGEJKKJCRCKNPUTHTVNYXM\tDFDISBFBRCCQDV\tXTGNJ\t2015-07-10T00:00:01.406Z\tNaN\tNaN\tNaN\t\t\t\n" + - "1414\tDHMTF\tRTGV\t\tHMDJSBGPXQTKPGGWFSTJSKSZSBEPDVNMFEVEMQCOHDBK\tJKBVDSERXZ\tOEENNEBQQEMXD\t2015-07-10T00:00:01.414Z\tNaN\tNaN\tNaN\t\t\t\n" + - "1422\tEKVFCZGGCKCHK\tEEGCRISJP\t\tILWBREVXDHHWPREIFCMLRXSWMFWEKIOTXUPRNGEPIJVNKTXHNKYITYG\tYYBJER\tCNSFFLTRY\t2015-07-10T00:00:01.422Z\tNaN\tNaN\tNaN\t\t\t\n" + - "1523\tV\tODSBTX\t\tECUZSRJCTRJLH\tVBNHX\tZHEI\t2015-07-10T00:00:01.523Z\tNaN\tNaN\tNaN\t\t\t\n" + - "1567\tBWPEIFNITZK\tBIJXCYTOHOQT\t\tYZMMSEZIPCOCZZUFYIVELTS\tFVPDDGSEK\tUN\t2015-07-10T00:00:01.567Z\tNaN\tNaN\tNaN\t\t\t\n", - "customers c" + - " outer join orders o on c.customerId = o.customerId " + - " where orderId = NaN" + - " limit 10,15"); - } - - @Test - public void testMultipleWithClauseReuse() throws Exception { - assertThat("1\t\tKZBSS\t2015-07-10T00:00:10.102Z\t1\t\tKZBSS\t2015-07-10T00:00:10.102Z\n" + - "1\t\tKZBSS\t2015-07-10T00:00:10.102Z\t1\t\tUBKVY\t2015-07-10T00:00:10.121Z\n" + - "1\t\tKZBSS\t2015-07-10T00:00:10.102Z\t1\t\tN\t2015-07-10T00:00:10.142Z\n" + - "1\t\tKZBSS\t2015-07-10T00:00:10.102Z\t1\t\tMTEVNUE\t2015-07-10T00:00:10.165Z\n" + - "1\t\tKZBSS\t2015-07-10T00:00:10.102Z\t1\t\tRKMLOG\t2015-07-10T00:00:10.168Z\n" + - "1\t\tUBKVY\t2015-07-10T00:00:10.121Z\t1\t\tKZBSS\t2015-07-10T00:00:10.102Z\n" + - "1\t\tUBKVY\t2015-07-10T00:00:10.121Z\t1\t\tUBKVY\t2015-07-10T00:00:10.121Z\n" + - "1\t\tUBKVY\t2015-07-10T00:00:10.121Z\t1\t\tN\t2015-07-10T00:00:10.142Z\n" + - "1\t\tUBKVY\t2015-07-10T00:00:10.121Z\t1\t\tMTEVNUE\t2015-07-10T00:00:10.165Z\n" + - "1\t\tUBKVY\t2015-07-10T00:00:10.121Z\t1\t\tRKMLOG\t2015-07-10T00:00:10.168Z\n" + - "1\t\tN\t2015-07-10T00:00:10.142Z\t1\t\tKZBSS\t2015-07-10T00:00:10.102Z\n" + - "1\t\tN\t2015-07-10T00:00:10.142Z\t1\t\tUBKVY\t2015-07-10T00:00:10.121Z\n" + - "1\t\tN\t2015-07-10T00:00:10.142Z\t1\t\tN\t2015-07-10T00:00:10.142Z\n" + - "1\t\tN\t2015-07-10T00:00:10.142Z\t1\t\tMTEVNUE\t2015-07-10T00:00:10.165Z\n" + - "1\t\tN\t2015-07-10T00:00:10.142Z\t1\t\tRKMLOG\t2015-07-10T00:00:10.168Z\n" + - "1\t\tMTEVNUE\t2015-07-10T00:00:10.165Z\t1\t\tKZBSS\t2015-07-10T00:00:10.102Z\n" + - "1\t\tMTEVNUE\t2015-07-10T00:00:10.165Z\t1\t\tUBKVY\t2015-07-10T00:00:10.121Z\n" + - "1\t\tMTEVNUE\t2015-07-10T00:00:10.165Z\t1\t\tN\t2015-07-10T00:00:10.142Z\n" + - "1\t\tMTEVNUE\t2015-07-10T00:00:10.165Z\t1\t\tMTEVNUE\t2015-07-10T00:00:10.165Z\n" + - "1\t\tMTEVNUE\t2015-07-10T00:00:10.165Z\t1\t\tRKMLOG\t2015-07-10T00:00:10.168Z\n" + - "1\t\tRKMLOG\t2015-07-10T00:00:10.168Z\t1\t\tKZBSS\t2015-07-10T00:00:10.102Z\n" + - "1\t\tRKMLOG\t2015-07-10T00:00:10.168Z\t1\t\tUBKVY\t2015-07-10T00:00:10.121Z\n" + - "1\t\tRKMLOG\t2015-07-10T00:00:10.168Z\t1\t\tN\t2015-07-10T00:00:10.142Z\n" + - "1\t\tRKMLOG\t2015-07-10T00:00:10.168Z\t1\t\tMTEVNUE\t2015-07-10T00:00:10.165Z\n" + - "1\t\tRKMLOG\t2015-07-10T00:00:10.168Z\t1\t\tRKMLOG\t2015-07-10T00:00:10.168Z\n", - "with o as (select '1' blah, lastName, employeeId customerId, timestamp from employees order by lastName limit 5)" + - "o cross join o"); - } - - @Test - public void testNullInsteadOfNaN() throws Exception { - assertThat("1406\tVQHYIIQL\tKJE\t\tDYQFLMPNGEJKKJCRCKNPUTHTVNYXM\tDFDISBFBRCCQDV\tXTGNJ\t2015-07-10T00:00:01.406Z\tNaN\tNaN\tNaN\t\t\t\n" + - "1414\tDHMTF\tRTGV\t\tHMDJSBGPXQTKPGGWFSTJSKSZSBEPDVNMFEVEMQCOHDBK\tJKBVDSERXZ\tOEENNEBQQEMXD\t2015-07-10T00:00:01.414Z\tNaN\tNaN\tNaN\t\t\t\n" + - "1422\tEKVFCZGGCKCHK\tEEGCRISJP\t\tILWBREVXDHHWPREIFCMLRXSWMFWEKIOTXUPRNGEPIJVNKTXHNKYITYG\tYYBJER\tCNSFFLTRY\t2015-07-10T00:00:01.422Z\tNaN\tNaN\tNaN\t\t\t\n" + - "1523\tV\tODSBTX\t\tECUZSRJCTRJLH\tVBNHX\tZHEI\t2015-07-10T00:00:01.523Z\tNaN\tNaN\tNaN\t\t\t\n" + - "1567\tBWPEIFNITZK\tBIJXCYTOHOQT\t\tYZMMSEZIPCOCZZUFYIVELTS\tFVPDDGSEK\tUN\t2015-07-10T00:00:01.567Z\tNaN\tNaN\tNaN\t\t\t\n", - "customers c" + - " outer join orders o on c.customerId = o.customerId " + - " where orderId = null" + - " limit 10,15"); - } - - @Test - public void testNullSymbol() throws Exception { - assertEmpty("select country, avg(quantity) from orders o " + - "join customers c on c.customerId = o.customerId " + - "join orderDetails d on o.orderId = d.orderId" + - " where country = null"); - } - - @Test - public void testOrderByOptimisation() throws Exception { - String expected = "410\tUWWBTOWPJTW\tPYZZYPFVTUDCCBOGCSHVQDTJSKFDF\t\tEIUHQZLPDWWIMMRZPZPTWDWXVFRNXZERBBG\tMNJVHP\tJSMK\t2015-07-10T00:00:00.410Z\tNaN\tNaN\tNaN\t\t\t\n" + - "805\tJDD\tPBJDTSRWFDYKFUKNSMFUREMGUGV\t\tGU\tYZ\tOEENNEBQQEMXD\t2015-07-10T00:00:00.805Z\tNaN\tNaN\tNaN\t\t\t\n" + - "810\tJNDVPITEWCB\tWWTURRWZVQXZZYDGZNZCTQYIXQRLRW\t\tWMXWFJFIKXWTHBJGUTVIXQIVZYEBZYP\tEOGVU\tL\t2015-07-10T00:00:00.810Z\tNaN\tNaN\tNaN\t\t\t\n" + - "1162\tZJSXCVDFRBBYP\tEDBFKPKBHQB\t\tZPNNILHNWDCKSHXQXKXOKTYNYTUISPYKRXNBGPIHZNDPRHNPHYIHGHKKZQID\tSJE\tTFSNSXH\t2015-07-10T00:00:01.162Z\tNaN\tNaN\tNaN\t\t\t\n"; - - String sql = "customers c" + - " outer join orders o on c.customerId = o.customerId " + - " where o.orderId = NaN and c.customerId > 400 and c.customerId < 1200 order by c.customerId"; - - assertThat(expected, sql); - assertPlan2("{\n" + - " \"op\": \"FilteredRecordSource\",\n" + - " \"src\": {\n" + - " \"op\": \"HashJoinRecordSource\",\n" + - " \"master\": {\n" + - " \"op\": \"RBTreeSortedRecordSource\",\n" + - " \"byRowId\": true,\n" + - " \"src\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"customers\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"FilteredRowSource\",\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " }\n" + - " }\n" + - " },\n" + - " \"slave\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"orders\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " },\n" + - " \"joinOn\": [\n" + - " [\n" + - " \"customerId\"\n" + - " ],\n" + - " [\n" + - " \"customerId\"\n" + - " ]\n" + - " ]\n" + - " },\n" + - " \"filter\": \"o.orderId \\u003d NaN\"\n" + - "}", sql); - } - - @Test - public void testOrderByOptimisation2() throws Exception { - String expected = "410\tUWWBTOWPJTW\tPYZZYPFVTUDCCBOGCSHVQDTJSKFDF\t\tEIUHQZLPDWWIMMRZPZPTWDWXVFRNXZERBBG\tMNJVHP\tJSMK\t2015-07-10T00:00:00.410Z\tNaN\tNaN\tNaN\t\t\t\n" + - "805\tJDD\tPBJDTSRWFDYKFUKNSMFUREMGUGV\t\tGU\tYZ\tOEENNEBQQEMXD\t2015-07-10T00:00:00.805Z\tNaN\tNaN\tNaN\t\t\t\n" + - "810\tJNDVPITEWCB\tWWTURRWZVQXZZYDGZNZCTQYIXQRLRW\t\tWMXWFJFIKXWTHBJGUTVIXQIVZYEBZYP\tEOGVU\tL\t2015-07-10T00:00:00.810Z\tNaN\tNaN\tNaN\t\t\t\n" + - "1162\tZJSXCVDFRBBYP\tEDBFKPKBHQB\t\tZPNNILHNWDCKSHXQXKXOKTYNYTUISPYKRXNBGPIHZNDPRHNPHYIHGHKKZQID\tSJE\tTFSNSXH\t2015-07-10T00:00:01.162Z\tNaN\tNaN\tNaN\t\t\t\n"; - - String sql = "customers c" + - " outer join orders o on c.customerId = o.customerId " + - " where o.orderId = NaN and c.customerId > 400 and c.customerId < 1200 order by o.customerId"; - - assertThat(expected, sql); - - assertPlan2("{\n" + - " \"op\": \"RBTreeSortedRecordSource\",\n" + - " \"byRowId\": false,\n" + - " \"src\": {\n" + - " \"op\": \"FilteredRecordSource\",\n" + - " \"src\": {\n" + - " \"op\": \"HashJoinRecordSource\",\n" + - " \"master\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"customers\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"FilteredRowSource\",\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " }\n" + - " },\n" + - " \"slave\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"orders\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " },\n" + - " \"joinOn\": [\n" + - " [\n" + - " \"customerId\"\n" + - " ],\n" + - " [\n" + - " \"customerId\"\n" + - " ]\n" + - " ]\n" + - " },\n" + - " \"filter\": \"o.orderId \\u003d NaN\"\n" + - " }\n" + - "}", sql); - } - - @Test - public void testOrderByOptimisation3() throws Exception { - String expected = "410\tUWWBTOWPJTW\n" + - "805\tJDD\n" + - "810\tJNDVPITEWCB\n" + - "1162\tZJSXCVDFRBBYP\n"; - - String sql = "select c.customerId x, c.customerName from customers c" + - " outer join orders o on c.customerId = o.customerId " + - " where o.orderId = NaN and c.customerId > 400 and c.customerId < 1200 order by x"; - - assertThat(expected, sql); - assertPlan2("{\n" + - " \"op\": \"SelectedColumnsRecordSource\",\n" + - " \"src\": {\n" + - " \"op\": \"FilteredRecordSource\",\n" + - " \"src\": {\n" + - " \"op\": \"HashJoinRecordSource\",\n" + - " \"master\": {\n" + - " \"op\": \"RBTreeSortedRecordSource\",\n" + - " \"byRowId\": true,\n" + - " \"src\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"customers\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"FilteredRowSource\",\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " }\n" + - " }\n" + - " },\n" + - " \"slave\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"orders\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " },\n" + - " \"joinOn\": [\n" + - " [\n" + - " \"customerId\"\n" + - " ],\n" + - " [\n" + - " \"customerId\"\n" + - " ]\n" + - " ]\n" + - " },\n" + - " \"filter\": \"o.orderId \\u003d NaN\"\n" + - " }\n" + - "}", sql); - } - - @Test - public void testOuterData() throws Exception { - final String expected = "162\tGMRIFLMITGDYEV\t\t\tSPEKZKSGOBNGGYCMQDTJB\tBL\tVFZF\t2015-07-10T00:00:00.162Z\tNaN\tNaN\tNaN\t\t\t\n" + - "209\tFBWP\tYENLEZTSMCKFERVG\t\tDZDUV\tCYYVYQ\tJSMK\t2015-07-10T00:00:00.209Z\tNaN\tNaN\tNaN\t\t\t\n" + - "233\tQWZMQEFI\tTDFXHNFPWKMILOGWL\t\tDHCYX\tCUYVUVQRY\tGIJYDVRV\t2015-07-10T00:00:00.233Z\tNaN\tNaN\tNaN\t\t\t\n" + - "381\tVYPDCYB\tBYTCJGCTLGGHVJXGRILSCO\t\tIGMKIOPKMYIHL\tVEMYSYSTQEL\tQHNOJIGFINKGQVZ\t2015-07-10T00:00:00.381Z\tNaN\tNaN\tNaN\t\t\t\n" + - "396\tKDNTVGUZLQQPM\tDHUJJIJMEXUJSTGUGVUKEWQPQUYC\t\tUZVVKSKZJOPLFKJDKGYWDVYCBRNKJOHMUUKV\tRTVTODMNWELRV\tBUYZVQ\t2015-07-10T00:00:00.396Z\tNaN\tNaN\tNaN\t\t\t\n" + - "410\tUWWBTOWPJTW\tPYZZYPFVTUDCCBOGCSHVQDTJSKFDF\t\tEIUHQZLPDWWIMMRZPZPTWDWXVFRNXZERBBG\tMNJVHP\tJSMK\t2015-07-10T00:00:00.410Z\tNaN\tNaN\tNaN\t\t\t\n" + - "805\tJDD\tPBJDTSRWFDYKFUKNSMFUREMGUGV\t\tGU\tYZ\tOEENNEBQQEMXD\t2015-07-10T00:00:00.805Z\tNaN\tNaN\tNaN\t\t\t\n" + - "810\tJNDVPITEWCB\tWWTURRWZVQXZZYDGZNZCTQYIXQRLRW\t\tWMXWFJFIKXWTHBJGUTVIXQIVZYEBZYP\tEOGVU\tL\t2015-07-10T00:00:00.810Z\tNaN\tNaN\tNaN\t\t\t\n" + - "1162\tZJSXCVDFRBBYP\tEDBFKPKBHQB\t\tZPNNILHNWDCKSHXQXKXOKTYNYTUISPYKRXNBGPIHZNDPRHNPHYIHGHKKZQID\tSJE\tTFSNSXH\t2015-07-10T00:00:01.162Z\tNaN\tNaN\tNaN\t\t\t\n" + - "1344\tZGY\tQN\t\tNROGZBSXJTNYED\tGGCOBQZUM\tBOQMYSSMP\t2015-07-10T00:00:01.344Z\tNaN\tNaN\tNaN\t\t\t\n" + - "1406\tVQHYIIQL\tKJE\t\tDYQFLMPNGEJKKJCRCKNPUTHTVNYXM\tDFDISBFBRCCQDV\tXTGNJ\t2015-07-10T00:00:01.406Z\tNaN\tNaN\tNaN\t\t\t\n" + - "1414\tDHMTF\tRTGV\t\tHMDJSBGPXQTKPGGWFSTJSKSZSBEPDVNMFEVEMQCOHDBK\tJKBVDSERXZ\tOEENNEBQQEMXD\t2015-07-10T00:00:01.414Z\tNaN\tNaN\tNaN\t\t\t\n" + - "1422\tEKVFCZGGCKCHK\tEEGCRISJP\t\tILWBREVXDHHWPREIFCMLRXSWMFWEKIOTXUPRNGEPIJVNKTXHNKYITYG\tYYBJER\tCNSFFLTRY\t2015-07-10T00:00:01.422Z\tNaN\tNaN\tNaN\t\t\t\n" + - "1523\tV\tODSBTX\t\tECUZSRJCTRJLH\tVBNHX\tZHEI\t2015-07-10T00:00:01.523Z\tNaN\tNaN\tNaN\t\t\t\n" + - "1567\tBWPEIFNITZK\tBIJXCYTOHOQT\t\tYZMMSEZIPCOCZZUFYIVELTS\tFVPDDGSEK\tUN\t2015-07-10T00:00:01.567Z\tNaN\tNaN\tNaN\t\t\t\n" + - "1589\tQJZGPSXOHTWXD\tEKVIBQFPUIPNFOGDPVUUUQ\t\tX\tBGDBEDEFD\tBCZIOLYLPG\t2015-07-10T00:00:01.589Z\tNaN\tNaN\tNaN\t\t\t\n" + - "1689\tWQ\tWZOHOOLBREWPFXYMVTDRBND\t\tGORYPTSTPHWOCVTZWOMURLEHZWCMOFQFYWNXDGNZKSFQUSMOVSWPCONS\tSWBCPLXVLMQ\tTOGM\t2015-07-10T00:00:01.689Z\tNaN\tNaN\tNaN\t\t\t\n" + - "1734\tPSBRCYXIJLGOC\tDNBEWBWJPMCRQBTOOJPMFWVCPYZVRK\t\tZNQJZSPFSMRNBSCSVJMGLUWTWYFNIKBBKL\tHEGJPSFHUWOTUIL\tOWLPDXYSBEOUOJ\t2015-07-10T00:00:01.734Z\tNaN\tNaN\tNaN\t\t\t\n" + - "1913\tBYYTTZDNBCBLR\tPXLCJNSUGIWGJWLYEQ\t\tCHUQVSFDBBLSEMNFVNGZMTYTMK\tIZTBCTJ\tGLHMLLEOY\t2015-07-10T00:00:01.913Z\tNaN\tNaN\tNaN\t\t\t\n" + - "2172\t\tSRXYONINGWNLG\t\tXYNFIBOCMCXCKDWDROMMCGKRWNNPZNKBELQJVSVGWUMYCKJFCBDBCVZPO\tWLZXCZYXJXQWZL\tMQH\t2015-07-10T00:00:02.172Z\tNaN\tNaN\tNaN\t\t\t\n" + - "2312\tZIBIM\tRINZFPZU\t\tKNPETVEWYFUGELZUNMEZVGRQJUYZSBETJSEDWFVROCMWRMLLHMVKXNGRIMPF\tZWWINRXPMIGS\tNIMYFF\t2015-07-10T00:00:02.312Z\tNaN\tNaN\tNaN\t\t\t\n" + - "2378\tLSKKQ\tSSULKFTWUSZQLMBPDRIOYBHT\t\tHWCEGCCJCFVKJFTPTTNVCZVMVQUOITXQWKSSOLGOZSQXWZT\tHSOQYCWEROZ\tPKLHTIIG\t2015-07-10T00:00:02.378Z\tNaN\tNaN\tNaN\t\t\t\n" + - "2385\tVJDLICNNECMY\tHMDUCFWCSXVFG\t\tEHBOTVVKOGHHKICBOPWMBHOKLPDCNX\tWUW\tZMZV\t2015-07-10T00:00:02.385Z\tNaN\tNaN\tNaN\t\t\t\n" + - "2990\tDJUPSVOGIUEDG\tGTMXBMRHDSULOUIHTKXHLONPZ\t\tVRYBNVGGYPCFCZFCOCVOULWXREBBQMWJMDT\tVESFSEMNXOUSI\tZEQGMPLUCFTL\t2015-07-10T00:00:02.990Z\tNaN\tNaN\tNaN\t\t\t\n" + - "3036\tNBOKZPH\tSOXIOEC\t\tPHVNUNBYMROWMLWTKZIOQIZHHWVCBYWRVY\tWOVJTL\tUZY\t2015-07-10T00:00:03.036Z\tNaN\tNaN\tNaN\t\t\t\n" + - "3171\tFJBUXYJCC\tFSCJELZPZCWRHKFRVIR\t\tXEWJYQDVHIPWPHDZKPEDGFYPNNNVPWLYLN\tJEOUSRULHULNDLC\tOZZVDZJMYIC\t2015-07-10T00:00:03.171Z\tNaN\tNaN\tNaN\t\t\t\n" + - "3213\tLCOTYSUBPNV\tEHIDIOWKZJQNRVBLWXFCHQVO\t\tTITHBMKLEOOKZFSYVZUCDXHDTJJYRHNVWIPVELVFQPXQDSHZIQQJFXMOFJRTOZ\tCMJSTVNPFNWPPBW\tUZY\t2015-07-10T00:00:03.213Z\tNaN\tNaN\tNaN\t\t\t\n" + - "3222\tLHXREYVN\tLKXQVJZUVWJIGUBKGBUGKRON\t\t\tHDRD\tOEZBRQ\t2015-07-10T00:00:03.222Z\tNaN\tNaN\tNaN\t\t\t\n" + - "3226\tKXZMMCGO\tQPW\t\tWKOLUQVELGJURZBQTWMSBSSSZYVCWIYKVQEFUZDBWJWTXGI\t\tQHNOJIGFINKGQVZ\t2015-07-10T00:00:03.226Z\tNaN\tNaN\tNaN\t\t\t\n" + - "3270\tNDRWGFXTNNTQB\tCGYIEZEQJEJPLPBHGFBVEBQYWCMG\t\tDOMUIZPVKDENO\tHXTNWWFVY\tTI\t2015-07-10T00:00:03.270Z\tNaN\tNaN\tNaN\t\t\t\n" + - "3383\tWMTZDJKNXCYCG\tFSUHTMXYEG\t\tEPFM\tXNMJINXIJM\tTOGM\t2015-07-10T00:00:03.383Z\tNaN\tNaN\tNaN\t\t\t\n" + - "3476\tDPCRPYJGXJPBUOD\tKITKUVSLNTJTPEFOTSPPQU\t\tWKTXNKOKJOJTLFNXTZTZZJPS\tRIWLMOI\tB\t2015-07-10T00:00:03.476Z\tNaN\tNaN\tNaN\t\t\t\n" + - "3478\tWTYRQ\tG\t\tVTDFWKVOOUSTQBWBNTZWMNCIWGZDWHKQYEODUUEMWWQBD\tXJ\tEYYPDVRGRQG\t2015-07-10T00:00:03.478Z\tNaN\tNaN\tNaN\t\t\t\n" + - "3502\tVWXXO\tSXJIBJXMHDTEJLKIIRELKZC\t\tSRSHKSEONQCYOFIMHBKGZKHMFE\tIQBSTDTCDNQE\tFNWGRMD\t2015-07-10T00:00:03.502Z\tNaN\tNaN\tNaN\t\t\t\n" + - "3589\tJOQQE\tKRUHSSEWMBELUIM\t\tEBMHCMDMDFSKYPDVYH\tYDMFRUNZIUXLB\tUHNBCCPM\t2015-07-10T00:00:03.589Z\tNaN\tNaN\tNaN\t\t\t\n" + - "3663\tUDX\tHXMRSDUZYTPYUYBC\t\tQDUTVPDLFNFHQZZGCELWJZIPRBSORVECERSVKCNGFWSDZHPDK\tWKOUXMRBLX\tHQQUW\t2015-07-10T00:00:03.663Z\tNaN\tNaN\tNaN\t\t\t\n" + - "3703\tUDRFDIXFY\tSGU\t\tRYFLDHPETQWIKEWYKDWQEX\tFQTJW\tEBNDCQCEHNO\t2015-07-10T00:00:03.703Z\tNaN\tNaN\tNaN\t\t\t\n" + - "3751\tEL\tTZXHXHPTEWHNUQWBYV\t\tHQGMTGIIZBMQPNMJMHFGLUXWJVHPXVXDYNSSDCBKOSUTN\tLHPWO\t\t2015-07-10T00:00:03.751Z\tNaN\tNaN\tNaN\t\t\t\n" + - "3891\tWMJFMFIY\tRELGTJVOIDJ\t\tXDQMLYFXJI\tNERDCGSGIWS\tWUVMBPSVEZDYHDH\t2015-07-10T00:00:03.891Z\tNaN\tNaN\tNaN\t\t\t\n" + - "3935\tMPPLRO\tPLFVGXOJQWZUVOOBRMGKCKMFTTINB\t\tTIMNMLWUZSMHNHYUYYRPKR\tDXWLZFL\tTI\t2015-07-10T00:00:03.935Z\tNaN\tNaN\tNaN\t\t\t\n" + - "4041\tHSNIJKWXG\tUJYWZE\t\tDVWYVDMCGKDCVRBVVZELVKOKJKYRXNQTFURDIBSZDNGWUJVNVUMVLJBI\tDOIKCLGLLTB\tTFSNSXH\t2015-07-10T00:00:04.041Z\tNaN\tNaN\tNaN\t\t\t\n" + - "4059\tULPIS\t\t\tWXPNLDBUVDW\tSBDCUXKKC\tBUYZVQ\t2015-07-10T00:00:04.059Z\tNaN\tNaN\tNaN\t\t\t\n" + - "4132\tBWHGDEXNZMBFKTH\tZNVYO\t\tMQKEHUWPEEKEHHNBUPRMSQIHBBJNOHRRBSXGYWU\tYBVJTLPSLKVXZNM\t\t2015-07-10T00:00:04.132Z\tNaN\tNaN\tNaN\t\t\t\n" + - "4412\tKSLZBHBGLU\tYJOWHLNKRGBMTYILPWINI\t\tSISKLWIGOZRWPSGZD\tPZEGSDJ\tPKLHTIIG\t2015-07-10T00:00:04.412Z\tNaN\tNaN\tNaN\t\t\t\n" + - "4432\tK\tPXOFTVRRDMQYG\t\tSQCZOONVRVXHDCUSRWWJVGEDCKYJMG\tCWRO\tLU\t2015-07-10T00:00:04.432Z\tNaN\tNaN\tNaN\t\t\t\n" + - "4745\tDYPIOX\t\t\tYUWUIQCFHKERXRUYHKIJRWGLEHMBURBIBHCLBHOPC\tFFREMYVLF\tIHYBTVZNCLN\t2015-07-10T00:00:04.745Z\tNaN\tNaN\tNaN\t\t\t\n" + - "4839\tFNJOWUJCQHYQ\tZTG\t\tTEIKMXBOWWEQBLZZZLEGWTFEVHZBHNEXBUWPSCS\tBCHPCUEDKSQ\tVRB\t2015-07-10T00:00:04.839Z\tNaN\tNaN\tNaN\t\t\t\n" + - "4934\tMHZTPC\tNFCFMZDOTVPXCFNOZJRWEQY\t\tYQEGLX\tVSVLHDNIKPWNOX\tMZCCYVBDMQEH\t2015-07-10T00:00:04.934Z\tNaN\tNaN\tNaN\t\t\t\n" + - "4963\tET\t\t\tLZTCYZKKVFOYHPGETSYSPFMKNULYMRISCWICQIOBWSPSMINXBYKXVZHKMRMYZ\tKCYKZDQ\tERSMKRZUDJGNNDE\t2015-07-10T00:00:04.963Z\tNaN\tNaN\tNaN\t\t\t\n" + - "4981\tOEGWN\tELCMYM\t\tUIOWZGCEXXZNBYPOXEUJCMIHBHKIRBDVOXUZMTVOQYUTUJL\tVSISP\tFNWGRMD\t2015-07-10T00:00:04.981Z\tNaN\tNaN\tNaN\t\t\t\n" + - "5207\tZNKCJHXBWEYN\tJEJEHFREXOVGPH\t\tEVCHKS\tXVQYLMJELWJLHS\t\t2015-07-10T00:00:05.207Z\tNaN\tNaN\tNaN\t\t\t\n" + - "5288\tIXH\tSLTVJIGLBMTCUXPMSWOEDT\t\tWYRNJECJSCPQDSHDJKTOTIUIPTNBYXTRZUMKGEZNPFLFTELYBSGI\tNOCZPXX\tHRI\t2015-07-10T00:00:05.288Z\tNaN\tNaN\tNaN\t\t\t\n" + - "5387\tSSPKDHERWUNX\tSGJMTMDPMSUPETCMIQE\t\tFBICHHGNEVNKVGJVI\tHFVYNKH\tINLKFNUH\t2015-07-10T00:00:05.387Z\tNaN\tNaN\tNaN\t\t\t\n" + - "5445\tR\tOJKCNJSMEQYCSKCKQRQWGEDD\t\tDQKRXXFOC\tGGSOBQQHR\tEJRMDIKDI\t2015-07-10T00:00:05.445Z\tNaN\tNaN\tNaN\t\t\t\n" + - "5653\tCE\tWPDTMIXZNQIIUVIXUNYECF\t\tLGOQPTMORXJFRXYOPEQXGERTXUTEIPJQJFCWKIITNBPOVKFQI\tXUOCLBYIB\tBBUKOJ\t2015-07-10T00:00:05.653Z\tNaN\tNaN\tNaN\t\t\t\n" + - "5684\t\tQJIDXPOCPTYYURUKSMCRMJMQQJB\t\tW\tISOXFJGEOHFCR\t\t2015-07-10T00:00:05.684Z\tNaN\tNaN\tNaN\t\t\t\n" + - "5956\tFPXYZW\tHWYQKHYTDVPVLLDYOPITHLLJG\t\tKFWQUXKKOTUIUHXELOOKDJIJROU\tSRCTDZS\tZYNPPBX\t2015-07-10T00:00:05.956Z\tNaN\tNaN\tNaN\t\t\t\n" + - "6006\tV\tMSKSWOFNYUKWNBKRFWOONIONILJJEMG\t\tCWHSYMVZMCDHWSSQTTEXRCVSKXCBYEYIHTXVMCJCPBOFIFKKXNGIEO\tTDVGHGKIVGU\tZHCN\t2015-07-10T00:00:06.006Z\tNaN\tNaN\tNaN\t\t\t\n" + - "6039\tFXNPVVURFMOLR\tOHBKYKVDMRSOSRCSEWEJKCFJJLXDQM\t\tNMZSWWPQUFIRDJOGGDZCIPYWLVPLYTWECLKE\tKCMOCZMMCDIL\tHSQSPZ\t2015-07-10T00:00:06.039Z\tNaN\tNaN\tNaN\t\t\t\n" + - "6122\tSRHNNUBREDEWYQL\tUNVYXEFBXLJUIBCIZUB\t\tHCPVXCIBOCQPPWQUPOBEEHTNDJQWFMPRTUQIXBORZXTYN\tZKHUJELJITS\tUN\t2015-07-10T00:00:06.122Z\tNaN\tNaN\tNaN\t\t\t\n" + - "6468\tSZTUTU\tQPXBOTFQLQXYDLW\t\tSLQTFNGHYIVHDSUWWNVTBBVYPHKIHVIEHTXPHIWSCWGLNEVPCIITFFCQI\tMSMIMLWZJCL\tJWCPSWHYRXPEHN\t2015-07-10T00:00:06.468Z\tNaN\tNaN\tNaN\t\t\t\n" + - "6486\tUXUCRDEQ\tCSOUCDKZHSFLLFMSJKCHTZKP\t\tLJKCIGNLIWJRFLMFDQBNIBZUQECN\tWTRPRCHCD\tHQQUW\t2015-07-10T00:00:06.486Z\tNaN\tNaN\tNaN\t\t\t\n" + - "6678\tTYJDHKUNEO\tCFZRMGKKQOMGMEGKMNVFVZSFQNIQUDO\t\tMIZDRNOJDELNJPNHVLTPFRTLVZUFNTSOGZZCNYBHSVWGNNIP\tNJDIVGC\tMRT\t2015-07-10T00:00:06.678Z\tNaN\tNaN\tNaN\t\t\t\n" + - "6691\tWGXLXNKO\tLBYMWEZCHRSNYPTCCXKRLQB\t\tDHBHVQPYOEDJSOKKDZTUNHRMZYQZWBHMBUXPN\tYSYUCK\tOUICWEKGHV\t2015-07-10T00:00:06.691Z\tNaN\tNaN\tNaN\t\t\t\n" + - "6728\tHSFLSXTYEWWWMD\tSXVIHKWQQBSUYEKLTRVMQFZO\t\tIGOQUCGCKOJSSRVJWBCPYYNEWTQKCTCERGHDDGWKLOXBFDEKPKRMDKKENJFN\tRZ\tZRPFMDVVG\t2015-07-10T00:00:06.728Z\tNaN\tNaN\tNaN\t\t\t\n" + - "6826\tVJDZ\tMGXBJXCFJHWCFDOTZLCPJSLFXTYIM\t\tTVPRLEMKQZZIIPCFGUKKKOBNTRPYVHMRUDUDSGZXTIFXWRFULWVWOHHJDZ\tCR\tVMC\t2015-07-10T00:00:06.826Z\tNaN\tNaN\tNaN\t\t\t\n" + - "6926\tZYESDDCGOGFUO\tWRDFOEFONJSPFGTUCKMIZWXIE\t\tVFJBNWHQVHMPJKSTXZXPQTOIMSJNCNRLUGQW\tIYFKD\tTI\t2015-07-10T00:00:06.926Z\tNaN\tNaN\tNaN\t\t\t\n" + - "7021\tNLKYHGO\tRHGHYBZOMJJBVLGGPHG\t\tFJQMODHRBKVLZWSJUWMLJFVUKIZJVZBBFNMXZOQJFWZDVYQCQXRUSBSDOIBLSS\tPQVCYTWYLEK\tOEZBRQ\t2015-07-10T00:00:07.021Z\tNaN\tNaN\tNaN\t\t\t\n" + - "7053\tWNSMHNXS\tOBSJHVQXMOJ\t\tEFVJTGURNJJZJIMUREPGMEJXDXDERDRXIMFZHYCZVKTDTBPYJQQPGYLIKPPBL\tPOWZIJQNISFYFN\tLPTYXYGY\t2015-07-10T00:00:07.053Z\tNaN\tNaN\tNaN\t\t\t\n" + - "7056\tGTLEUE\tQWBCXBXNDFRPOQLROOEXRSFPUSFN\t\tROFOTIRXJTZWT\tBVTVUBQ\tWUVMBPSVEZDYHDH\t2015-07-10T00:00:07.056Z\tNaN\tNaN\tNaN\t\t\t\n" + - "7122\tVCCO\tOJDYZWTUYNGWQNWEGOXYMJ\t\tPTWRSXZVZRNYUQDXLLOQVRMNLZUQRYIIYYJZBZGBKBRELDNPCM\tWCECUHSTCHICVIW\tIHZBWWXF\t2015-07-10T00:00:07.122Z\tNaN\tNaN\tNaN\t\t\t\n" + - "7175\t\tSMSPDCSPNTOUVUVWG\t\tMWVXGQOPEFIW\tRTCGYGSMWYFHIK\tUXI\t2015-07-10T00:00:07.175Z\tNaN\tNaN\tNaN\t\t\t\n" + - "7262\tVIXUVVWCWWTZVTT\tRHWJQEDZTDLZZODEC\t\tJMYKVBGFRCCVBPIYJFGUO\tZINNITZWLZJ\tLPTYXYGY\t2015-07-10T00:00:07.262Z\tNaN\tNaN\tNaN\t\t\t\n" + - "7347\tVJDIMVDXSZJGONW\tQEHBEOGUKYJKMDKXYVTB\t\tMKOZKMNYESGUFQEWJJONMJXZGYKDZOFNIYCVCIIBPDKRMFXJURGLV\tXKRKNOBFOHRVHHK\tHSQSPZ\t2015-07-10T00:00:07.347Z\tNaN\tNaN\tNaN\t\t\t\n" + - "7473\tEIZFIQOXKQTL\tRMTGUNFYICLTNRPOINOKISQR\t\tUTKENDEUCPB\tDDQ\tQXSPEPTTKIB\t2015-07-10T00:00:07.473Z\tNaN\tNaN\tNaN\t\t\t\n" + - "7478\tVKQEOSR\tCNBBUPHUEXWJURYENCJMSSZLDOUET\t\tDLEJKKEWPSMEVYFWRXFIISVPMQWCPJR\tXGXTKBZLML\tZYNPPBX\t2015-07-10T00:00:07.478Z\tNaN\tNaN\tNaN\t\t\t\n" + - "7497\tLFQGLDWFRXXG\tMOTZVCZZCSN\t\tPLZSQJTXPZBYGCNVCLJJYZWVCDLBEQOLFDGEQIHMGQKTXOEWYHEWVYXCOGWJMCU\tHUSKKOVGLEYFTS\tVELLKKHTWNWI\t2015-07-10T00:00:07.497Z\tNaN\tNaN\tNaN\t\t\t\n" + - "7513\tV\tNPKCEVYISMIEZ\t\tSHKVNSEIDEJZYBDRJXJXUHFWPHQDJGYGUBFWHHBPZXPTUZNZBZQM\t\tGSTEQODRZEIWFOQ\t2015-07-10T00:00:07.513Z\tNaN\tNaN\tNaN\t\t\t\n" + - "7644\tPGZGVZCOFMMUE\tDKDC\t\tQSTEVZPEHUZVOWSTSWXBTUWEGQQIPN\tSQQGPYG\tUOUIGENFELWWRSL\t2015-07-10T00:00:07.644Z\tNaN\tNaN\tNaN\t\t\t\n" + - "7737\tIXTXWXNRTEV\tOLMYQTMBOETE\t\tCSINBVKDS\tSVZXEVCRGW\tXGZMDJTHMHZN\t2015-07-10T00:00:07.737Z\tNaN\tNaN\tNaN\t\t\t\n" + - "7911\tB\tHBDFCVYUERTYMXRVDKJHWG\t\tUXZBGJRUXHSDUDRIOCUIICKOZSVXHDYXEKDDVFTPGRQWIZYIOBMZFMYHZH\tLNXNEFZQJYO\tJBF\t2015-07-10T00:00:07.911Z\tNaN\tNaN\tNaN\t\t\t\n" + - "7961\tFLBPTOLRBCSL\tXUE\t\tXGHYVHINXWPB\tYTMTUHYYRKUHLUQ\tVFZF\t2015-07-10T00:00:07.961Z\tNaN\tNaN\tNaN\t\t\t\n" + - "7968\tRXSC\tHGHZDQS\t\tEGRPGPPRXJUPJLGCRETXZNNHBPNWRFBBHEMODPJZLDYKWBY\tIK\tRGOONFCLTJCKFMQ\t2015-07-10T00:00:07.968Z\tNaN\tNaN\tNaN\t\t\t\n" + - "7976\tDEXNQWBDJQEHUM\tQIFWWFNVZUZJNJQ\t\tKOIY\tWV\tFSUWPNXHQUT\t2015-07-10T00:00:07.976Z\tNaN\tNaN\tNaN\t\t\t\n" + - "8074\tBFGSXPKVKURV\t\t\tTIGRLGDVMMCIMHXICXJWRWLPKCRQRQFIOTGHXHGVDIRMRUMV\tF\tPJEUKW\t2015-07-10T00:00:08.074Z\tNaN\tNaN\tNaN\t\t\t\n" + - "8113\tDDGFSZHOG\tPBV\t\tXFBTRICSWEOBKHUFDRSNFDEXDFTMEHBKQPKRRQFPTZKFRXRGJWE\tFTID\t\t2015-07-10T00:00:08.113Z\tNaN\tNaN\tNaN\t\t\t\n" + - "8121\tELZPVWLPQQO\tIJHLCIPMKJBHKRNYRRIBCWQTWHFMC\t\tJSCYBPOMOFRYEFHZNYNTTMLGFJHLLKIKMOMC\tLDGWBHIQNE\tINLKFNUH\t2015-07-10T00:00:08.121Z\tNaN\tNaN\tNaN\t\t\t\n" + - "8130\tSYGBYFSNQOT\tINUCPVCRKPQSKZOSNQQSLKDELFSVVDI\t\tXQGGHWGJZDKHLDCJSBQYKXZUMWQLHUOTDZCEJRZPF\tYXKQOIT\tZI\t2015-07-10T00:00:08.130Z\tNaN\tNaN\tNaN\t\t\t\n" + - "8199\tJWFODJS\tOMOIJIUGNUZMSXEK\t\tIFRCSLFUDRPRMLHTBXLFOVRZNTENWJMKFHOZEGVBX\tLFEQGRKKBPMI\tGSTEQODRZEIWFOQ\t2015-07-10T00:00:08.199Z\tNaN\tNaN\tNaN\t\t\t\n" + - "8284\t\tJKYMSFW\t\tFZQPSJETVHJVVOIZRITTFEPZMEJHDXYGHWDNUEIIEXCFVTV\tMRMRGTUFNZHXKQY\tFEVHK\t2015-07-10T00:00:08.284Z\tNaN\tNaN\tNaN\t\t\t\n" + - "8320\tWGCFDLNDIEW\tORDODPC\t\tTTHPTKYEYYP\tXOYOEMXIEGP\tOVFDBZWNI\t2015-07-10T00:00:08.320Z\tNaN\tNaN\tNaN\t\t\t\n" + - "8379\tQQPSQOPG\tVLSFYVGGHMGVPIGUJCBZS\t\tZCRHPDJMWNSLOMQZXPNFMHGZKLUNEUUDMYBXWRFYRPIFIRSSEEINLIHHXSHZEZZ\tEW\tWUVMBPSVEZDYHDH\t2015-07-10T00:00:08.379Z\tNaN\tNaN\tNaN\t\t\t\n" + - "8532\tCGOSJWM\tGZEFSMRLMUULNJDSOKJOR\t\t\tSHXMT\tHNZH\t2015-07-10T00:00:08.532Z\tNaN\tNaN\tNaN\t\t\t\n" + - "8549\tXKGGQNZPZXDWF\tNFEBNUVEQJOPWKHYEXVWEMHNQKD\t\tLQRZKJEGFWQIEHNDQNSLLEJKYHHGCEF\t\tJFRPXZSF\t2015-07-10T00:00:08.549Z\tNaN\tNaN\tNaN\t\t\t\n" + - "8567\tRUDDLZNHGVHZO\tKOZOOJWDDO\t\tRMJURFHFUWRFYYROGJUKEKJTIOKSOMWQCIGBXGTHJJBHFFFEUXJQPOGQL\tFFKJOOXKH\tRJUEBWV\t2015-07-10T00:00:08.567Z\tNaN\tNaN\tNaN\t\t\t\n" + - "8821\tZ\tHEDEUYVXYULDEDVOZTIXLRHX\t\tLBZKRTLMHHZQYJTHVKTHTQCZUTYNTSRIEFIVJIT\tBUOIOYPUMWUHEI\tTOGM\t2015-07-10T00:00:08.821Z\tNaN\tNaN\tNaN\t\t\t\n" + - "9021\tMSM\tMJWVDCOWPQFCDB\t\tEFTSFYICZHJLOPKNJTSKMGPBIZUTTXSZCIBKIMNHPEEX\tMIKOFVNI\tVFZF\t2015-07-10T00:00:09.021Z\tNaN\tNaN\tNaN\t\t\t\n" + - "9180\tDX\tLMHJXBDPMRECNYXZ\t\tTYDLLXJTKOFTUPQXUSEWRSQCLENIOMZPSW\tYS\t\t2015-07-10T00:00:09.180Z\tNaN\tNaN\tNaN\t\t\t\n" + - "9752\t\tKIJZZXFXHTCOEJPWMICBQOXQQQPBGF\t\tSWSMBCZIORTGCWCFVXSYKTLDCDLJQEKZLJVTLIJSLXH\tCSRXHZCODL\tGSTEQODRZEIWFOQ\t2015-07-10T00:00:09.752Z\tNaN\tNaN\tNaN\t\t\t\n" + - "9754\tVBUNKYVVGQLKQCD\tBOOFXUSIVEHEJIOTLOYTCCKIVVUHQ\t\tFGFXYRFCNLJEWVEQYHNESWJRBYQBQP\tIPEWMGFDPQH\tXLQLUUZIZKMFCKV\t2015-07-10T00:00:09.754Z\tNaN\tNaN\tNaN\t\t\t\n" + - "9782\tOIGUBDZRIHVSSH\tFKXP\t\tYCDPIVPZVGZOTUBFPLOVJRWTQLQW\tRVYMWKMJEYMFNNL\tEVQTQ\t2015-07-10T00:00:09.782Z\tNaN\tNaN\tNaN\t\t\t\n" + - "9977\tINDD\tMIRNGQQJMVOHKXHIYFMUMLXDGEQIEGT\t\tXULPFZVERXTYXHEIXXTUSJFKTHCHSXYTBLILZKTHJTFSFQPTUZHIURBOMPGHUR\tMUIYMRYE\tWLZKDMPVR\t2015-07-10T00:00:09.977Z\tNaN\tNaN\tNaN\t\t\t\n" + - "9992\tHTEOO\tFEVRVVUBNQZINQYGSBOXQGTVNRLXE\t\tHJBNFHODEFEMCKSVYWTQPMEVLLSJINDCHSPTIZDB\tDXIUYZNJ\tORD\t2015-07-10T00:00:09.992Z\tNaN\tNaN\tNaN\t\t\t\n"; - - assertThat(expected, "customers c" + - " outer join orders o on c.customerId = o.customerId " + - " where o.orderId = NaN"); - } - - @Test - public void testOuterExistence1() throws Exception { - assertPlan("+ 0[ cross ] c\n" + - "+ 1[ outer ] o ON o.customerId = c.customerId (post-filter: null = orderId)\n" + - "\n", - "customers c" + - " outer join orders o on c.customerId = o.customerId" + - " where null = orderId"); - } - - @Test - public void testOuterExistence2() throws Exception { - assertPlan("+ 0[ cross ] c\n" + - "+ 1[ outer ] o ON o.customerId = c.customerId (post-filter: orderId = null)\n" + - "\n", - "customers c" + - " outer join orders o on c.customerId = o.customerId" + - " where orderId = null"); - } - - @Test - public void testOuterExistence3() throws Exception { - assertPlan("+ 0[ cross ] c\n" + - "+ 1[ outer ] o ON o.customerId = c.customerId (post-filter: orderId = NaN)\n" + - "\n", - "customers c" + - " outer join orders o on c.customerId = o.customerId" + - " where orderId = NaN"); - } - - @Test - public void testOuterJoin() throws Exception { - assertThat("ZKX\tGZW\t857841416\t1083\n" + - "ZKX\tGZW\t1032890405\tNaN\n" + - "ZKX\tGZW\t783791714\t927\n" + - "ZKX\tGZW\t783791714\t586\n" + - "ZKX\tGZW\t783791714\t1065\n" + - "ZKX\tGZW\t1662033722\t542\n" + - "ZKX\tGZW\t1662033722\t389\n" + - "ZKX\tGZW\t337191226\t1472\n" + - "ZKX\tGZW\t337191226\t1577\n" + - "ZKX\tGZW\t337191226\t393\n" + - "ZKX\tGZW\t1360393259\t1615\n" + - "ZKX\tGZW\t1360393259\t778\n" + - "ZKX\tGZW\t163580596\t1256\n" + - "ZKX\tGZW\t163580596\t1017\n" + - "ZKX\tGZW\t163580596\t612\n" + - "ZKX\tGZW\t1569321724\t1464\n" + - "ZKX\tGZW\t115845726\t1922\n" + - "ZKX\tGZW\t115845726\t1360\n" + - "ZKX\tGZW\t115845726\t1192\n" + - "ZKX\tGZW\t115845726\t1485\n" + - "ZKX\tGZW\t1565417569\t1122\n" + - "ZKX\tGZW\t1565417569\t1803\n" + - "ZKX\tGZW\t1678218138\t1686\n" + - "ZKX\tGZW\t1678218138\t969\n" + - "ZKX\tGZW\t1315811593\t1398\n" + - "ZKX\tGZW\t1315811593\t25\n", - "select country, customerName, o.orderId, d.productId from orders o " + - "outer join customers c on c.customerId = o.customerId " + - "outer join (orderDetails where orderId != 1032890405) d on o.orderId = d.orderId" + - " where country ~ '^Z' and customerName = 'GZW'"); - } - - @Test - public void testRegexConstantTransitivityRhs() throws Exception { - assertPlan("+ 0[ cross ] c (filter: c.customerId ~ '100')\n" + - "+ 1[ outer ] o (filter: o.customerId ~ '100') ON o.customerId = c.customerId\n" + - "\n", - "customers c" + - " outer join orders o on c.customerId = o.customerId" + - " where c.customerId ~ '100'"); - } - - @Test - public void testSearchUnIndexedSymbol() throws Exception { - assertThat("DJSBQG\tDRNUY\tMJSMUTZN\tYHGWBYMZE\tTZ\tNYRZLCBDM\tTEMGDPQYTYUTOPS\t2015-07-10T00:00:12.100Z\n", "suppliers where supplier = 'DJSBQG'"); - } - - @Test - public void testSimpleIntLambda() throws Exception { - final String expected = "1935884354\t100\t1503\tD\t2015-07-10T00:01:43.507Z\tRZVZJQRNYSRKZSJ\n"; - assertThat(expected, "orders latest by customerId where customerId in (`customers where customerName ~ 'PJFSREKEUNMKWOF'`)"); - assertThat(expected, "orders latest by customerId where customerId = 100"); - } - - @Test - public void testSimpleStrToStrLambda() throws Exception { - assertThat("751505590\t9029\t1516\tFQP\t2015-07-10T00:01:52.290Z\tYGFSMEVDSIYC\n", - "orders latest by employeeId where employeeId in (`employees where firstName = 'DU'`)"); - } - - @Test - public void testSimpleStrToSymLambda() throws Exception { - assertThat("751505590\t9029\t1516\tFQP\t2015-07-10T00:01:52.290Z\tYGFSMEVDSIYC\n", - "orders latest by employeeId where employeeId in (`select _atos(employeeId) from employees where firstName = 'DU'`)"); - } - - @Test - public void testSimpleSymToStrLambda() throws Exception { - assertThat("1946\tEOVGVPEHSZQJGNI\tGROTGCLGILNCXPT\tCOHPFXH\t0.175451457500\t2015-07-10T00:00:14.146Z\n", - "products latest by supplier where supplier in (`select _stoa(supplier) from suppliers where contactName = 'PHT'`)"); - } - - @Test - public void testSimpleSymToSymLambda() throws Exception { - assertThat("1946\tEOVGVPEHSZQJGNI\tGROTGCLGILNCXPT\tCOHPFXH\t0.175451457500\t2015-07-10T00:00:14.146Z\n", - "products latest by supplier where supplier in (`suppliers where contactName = 'PHT'`)"); - } - - @Test - public void testSimpleSymToSymLambdaAliased() throws Exception { - assertThat("1946\tGROTGCLGILNCXPT\n", - "select productId, supplier s from products latest by s where s in (`suppliers where contactName = 'PHT'`)"); - } - - @Test - public void testSymRegex() { - try { - expectFailure("select country, avg(quantity) from orders o " + - "join customers c on c.customerId = o.customerId " + - "join orderDetails d on o.orderId = d.orderId" + - " where country ~ null"); - } catch (ParserException e) { - Assert.assertEquals(153, QueryError.getPosition()); - } - } - - @Test - public void testSymRegexSyntaxError() { - try { - expectFailure("select country, avg(quantity) from orders o join customers c on c.customerId = o.customerId join orderDetails d on o.orderId = d.orderId where country ~ '^Z)'"); - } catch (ParserException e) { - Assert.assertEquals(156, QueryError.getPosition()); - Assert.assertTrue(QueryError.getMessage().toString().contains("Regex syntax")); - } - } - - @Test - public void testThreeWayNoSelect() throws Exception { - assertThat("customerId\tcustomerName\tcontactName\taddress\tcity\tpostalCode\tcountry\ttimestamp\torderId\tcustomerId\tproductId\temployeeId\torderDate\tshipper\tproductId\tproductName\tsupplier\tcategory\tprice\ttimestamp\n" + - "2\tQELQ\tWQGMZBPHETSLOIMSUFXYIWEODDBH\t\tVGXYHJUXBWYWRLHUHJECIDLRBIDSTDTFBY\tS\tDCQSCMONRC\t2015-07-10T00:00:00.002Z\t1575627983\t2\t1923\t\t2015-07-10T00:00:31.796Z\tFBLGGTZEN\t1923\tVXZESTU\tLFQNDNRHKUHE\tDDKZCNBOGWTL\t992.000000000000\t2015-07-10T00:00:14.123Z\n" + - "2\tQELQ\tWQGMZBPHETSLOIMSUFXYIWEODDBH\t\tVGXYHJUXBWYWRLHUHJECIDLRBIDSTDTFBY\tS\tDCQSCMONRC\t2015-07-10T00:00:00.002Z\t1628627044\t2\t1881\tRIXTM\t2015-07-10T00:00:37.249Z\tYGFSMEVDSIYC\t1881\tDJHDQX\tFUXEJFTGSLMCBRD\tKFGXCKKLNVVIQ\t0.000000000000\t2015-07-10T00:00:14.081Z\n" + - "2\tQELQ\tWQGMZBPHETSLOIMSUFXYIWEODDBH\t\tVGXYHJUXBWYWRLHUHJECIDLRBIDSTDTFBY\tS\tDCQSCMONRC\t2015-07-10T00:00:00.002Z\t541627843\t2\t1216\tUJ\t2015-07-10T00:00:43.578Z\tQPL\t1216\tHZBDMUQLOTHMCHO\tZZCPO\tKSEOSRN\t-234.332031250000\t2015-07-10T00:00:13.416Z\n" + - "2\tQELQ\tWQGMZBPHETSLOIMSUFXYIWEODDBH\t\tVGXYHJUXBWYWRLHUHJECIDLRBIDSTDTFBY\tS\tDCQSCMONRC\t2015-07-10T00:00:00.002Z\t1502016981\t2\t516\tRK\t2015-07-10T00:00:48.192Z\tOJXJCNBLYTOIYI\t516\tBJUHPV\tUHSSLJ\tQR\t279.675109863281\t2015-07-10T00:00:12.716Z\n" + - "2\tQELQ\tWQGMZBPHETSLOIMSUFXYIWEODDBH\t\tVGXYHJUXBWYWRLHUHJECIDLRBIDSTDTFBY\tS\tDCQSCMONRC\t2015-07-10T00:00:00.002Z\t1370796605\t2\t1242\t\t2015-07-10T00:00:55.216Z\tYJZPHQDJKOM\t1242\tFLTGLC\tF\tSQDBRUMST\t0.000001773577\t2015-07-10T00:00:13.442Z\n", - "customers" + - " outer join orders o on customers.customerId = o.customerId " + - " join products p on o.productId = p.productId" + - " limit 25,30", true); - } - - @Test - public void testThreeWaySelectAlias() throws Exception { - assertThat("c.customerId\to.customerId\tp.productId\torderId\n" + - "2\t2\t1923\t1575627983\n" + - "2\t2\t1881\t1628627044\n" + - "2\t2\t1216\t541627843\n" + - "2\t2\t516\t1502016981\n" + - "2\t2\t1242\t1370796605\n", - "select c.customerId, o.customerId, p.productId, orderId " + - " from customers c" + - " outer join orders o on c.customerId = o.customerId " + - " join products p on o.productId = p.productId" + - " limit 25,30", true); - } - - @Test - public void testThreeWaySelectNoAlias() throws Exception { - assertThat("customers.customerId\to.customerId\tp.productId\torderId\n" + - "2\t2\t1923\t1575627983\n" + - "2\t2\t1881\t1628627044\n" + - "2\t2\t1216\t541627843\n" + - "2\t2\t516\t1502016981\n" + - "2\t2\t1242\t1370796605\n", - "select customers.customerId, o.customerId, p.productId, orderId " + - " from customers" + - " outer join orders o on customers.customerId = o.customerId " + - " join products p on o.productId = p.productId" + - " limit 25,30", true); - } - - @Test - public void testWithClauseErrorOffset() { - try { - expectFailure("with o as (select '1' blah, lastName, employeeId customerId, timestamp from employees where lastName ~ '(' order by lastName)," + - " a as (select '1' blah, lastName, employeeId customerId, timestamp from employees where lastName ~ 'UBB' order by lastName)" + - " select lastName from a x join o on (customerId)"); - } catch (ParserException e) { - Assert.assertEquals(106, QueryError.getPosition()); - } - } - - @Test - public void testWithClauseInJoin() throws Exception { - assertPlan2("{\n" + - " \"op\": \"AsOfPartitionedJoinRecordSource\",\n" + - " \"master\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"customers\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " },\n" + - " \"slave\": {\n" + - " \"op\": \"RBTreeSortedRecordSource\",\n" + - " \"byRowId\": true,\n" + - " \"src\": {\n" + - " \"op\": \"SelectedColumnsRecordSource\",\n" + - " \"src\": {\n" + - " \"op\": \"VirtualColumnRecordSource\",\n" + - " \"src\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"employees\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - " },\n" + - " \"masterTsIndex\": 7,\n" + - " \"slaveTsIndex\": 3\n" + - "}", - "with o as (select '1' blah, lastName, employeeId customerId, timestamp from employees order by lastName)" + - "customers c asof join o on (customerId)"); - } - - private static void generateJoinData() throws JournalException, NumericException { - try (JournalWriter customers = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("customers"). - $int("customerId"). - $str("customerName"). - $str("contactName"). - $str("address"). - $str("city"). - $str("postalCode"). - $sym("country"). - $ts() - )) { - - try (JournalWriter categories = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("categories"). - $sym("category").index().buckets(100). - $str("description"). - $ts() - )) { - - try (JournalWriter employees = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("employees"). - $str("employeeId").index().buckets(2048). - $str("firstName"). - $str("lastName"). - $date("birthday"). - $ts() - )) { - - try (JournalWriter orderDetails = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("orderDetails"). - $int("orderDetailId"). - $int("orderId"). - $int("productId"). - $int("quantity"). - $ts() - )) { - - try (JournalWriter orders = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("orders"). - $int("orderId"). - $int("customerId").index(). - $int("productId"). - $str("employeeId").index(). - $ts("orderDate"). - $sym("shipper"). - $() - )) { - - try (JournalWriter products = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("products"). - $int("productId"). - $str("productName"). - $sym("supplier").index().buckets(100). - $sym("category").index().buckets(100). - $double("price"). - $ts() - )) { - - - try (JournalWriter shippers = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("shippers"). - $sym("shipper"). - $str("phone"). - $ts() - )) { - - try (JournalWriter suppliers = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("suppliers"). - $sym("supplier").buckets(100). - $str("contactName"). - $str("address"). - $str("city"). - $str("postalCode"). - $sym("country").index(). - $str("phone"). - $ts() - )) { - - final Rnd rnd = new Rnd(); - long time = DateFormatUtils.parseDateTime("2015-07-10T00:00:00.000Z"); - - // statics - int countryCount = 196; - ObjList countries = new ObjList<>(); - for (int i = 0; i < countryCount; i++) { - countries.add(rnd.nextString(rnd.nextInt() & 15)); - } - - IntHashSet blackList = new IntHashSet(); - // customers - int customerCount = 10000; - for (int i = 0; i < customerCount; i++) { - - if (rnd.nextPositiveInt() % 100 == 0) { - blackList.add(i); - } - - JournalEntryWriter w = customers.entryWriter(); - w.putInt(0, i); - w.putStr(1, rnd.nextChars(rnd.nextInt() & 15)); - w.putStr(2, rnd.nextChars(rnd.nextInt() & 31)); - w.putStr(4, rnd.nextChars(rnd.nextInt() & 63)); - w.putStr(5, rnd.nextChars(rnd.nextInt() & 15)); - w.putSym(6, countries.getQuick(rnd.nextPositiveInt() % 196)); - w.putDate(7, time++); - w.append(); - } - customers.commit(); - - // categories - for (int i = 0; i < 100; i++) { - JournalEntryWriter w = categories.entryWriter(); - w.putSym(0, rnd.nextChars(rnd.nextInt() & 15)); - w.putStr(1, rnd.nextChars(rnd.nextInt() & 63)); - w.putDate(2, time++); - w.append(); - } - categories.commit(); - - // employees - int employeeCount = 2000; - for (int i = 0; i < employeeCount; i++) { - JournalEntryWriter w = employees.entryWriter(); - w.putStr(0, rnd.nextChars(rnd.nextInt() & 7)); - w.putStr(1, rnd.nextChars(rnd.nextInt() & 15)); - w.putStr(2, rnd.nextChars(rnd.nextInt() & 15)); - w.putDate(3, 0); - w.putDate(4, time++); - w.append(); - } - employees.commit(); - - // suppliers - for (int i = 0; i < 100; i++) { - JournalEntryWriter w = suppliers.entryWriter(); - w.putSym(0, rnd.nextChars(rnd.nextInt() & 15)); - w.putStr(1, rnd.nextChars(rnd.nextInt() & 15)); - w.putStr(2, rnd.nextChars(rnd.nextInt() & 15)); - w.putStr(3, rnd.nextChars(rnd.nextInt() & 15)); - w.putStr(4, rnd.nextChars(rnd.nextInt() & 7)); - w.putSym(5, countries.getQuick(rnd.nextPositiveInt() % countryCount)); - w.putStr(6, rnd.nextChars(rnd.nextInt() & 15)); - w.putDate(7, time++); - w.append(); - } - suppliers.commit(); - - MMappedSymbolTable categoryTab = categories.getSymbolTable("category"); - int categoryTabSize = categoryTab.size(); - MMappedSymbolTable supplierTab = suppliers.getSymbolTable("supplier"); - int supplierTabSize = supplierTab.size(); - - // products - int productCount = 2000; - for (int i = 0; i < productCount; i++) { - JournalEntryWriter w = products.entryWriter(); - w.putInt(0, i); - w.putStr(1, rnd.nextChars(rnd.nextInt() & 15)); - w.putSym(2, supplierTab.value(rnd.nextPositiveInt() % supplierTabSize)); - w.putSym(3, categoryTab.value(rnd.nextPositiveInt() % categoryTabSize)); - w.putDouble(4, rnd.nextDouble()); - w.putDate(5, time++); - w.append(); - } - products.commit(); - - // shippers - for (int i = 0; i < 20; i++) { - JournalEntryWriter w = shippers.entryWriter(); - w.putSym(0, rnd.nextChars(rnd.nextInt() & 15)); - w.putStr(1, rnd.nextChars(rnd.nextInt() & 7)); - w.append(); - } - shippers.commit(); - - MMappedSymbolTable shipperTab = shippers.getSymbolTable("shipper"); - int shipperTabSize = shipperTab.size(); - - int d = 0; - for (int i = 0; i < 100000; i++) { - int customerId = rnd.nextPositiveInt() % customerCount; - if (blackList.contains(customerId)) { - continue; - } - - int orderId = rnd.nextPositiveInt(); - JournalEntryWriter w = orders.entryWriter(time++); - - w.putInt(0, orderId); - w.putInt(1, customerId); - w.putInt(2, rnd.nextPositiveInt() % productCount); - w.putStr(3, employees.getPartition(0, true).getFlyweightStr(rnd.nextPositiveLong() % employeeCount, 0)); - w.putSym(5, shipperTab.value(rnd.nextPositiveInt() % shipperTabSize)); - w.append(); - - int k = (rnd.nextInt() & 3) + 1; - - for (int n = 0; n < k; n++) { - JournalEntryWriter dw = orderDetails.entryWriter(); - dw.putInt(0, ++d); - dw.putInt(1, orderId); - dw.putInt(2, rnd.nextPositiveInt() % productCount); - dw.putInt(3, (rnd.nextInt() & 3) + 1); - dw.append(); - } - } - orders.commit(); - orderDetails.commit(); - } - } - } - } - } - } - } - } - } -} diff --git a/core/src/test/java/com/questdb/parser/sql/LocalesTest.java b/core/src/test/java/com/questdb/parser/sql/LocalesTest.java deleted file mode 100644 index 31108289d..000000000 --- a/core/src/test/java/com/questdb/parser/sql/LocalesTest.java +++ /dev/null @@ -1,194 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.parser.sql; - -import org.junit.Test; - -public class LocalesTest extends AbstractOptimiserTest { - - @Test - public void testView() throws Exception { - assertThat("\n" + - "ar\n" + - "ar-AE\n" + - "ar-BH\n" + - "ar-DZ\n" + - "ar-EG\n" + - "ar-IQ\n" + - "ar-JO\n" + - "ar-KW\n" + - "ar-LB\n" + - "ar-LY\n" + - "ar-MA\n" + - "ar-OM\n" + - "ar-QA\n" + - "ar-SA\n" + - "ar-SD\n" + - "ar-SY\n" + - "ar-TN\n" + - "ar-YE\n" + - "be\n" + - "be-BY\n" + - "bg\n" + - "bg-BG\n" + - "ca\n" + - "ca-ES\n" + - "cs\n" + - "cs-CZ\n" + - "da\n" + - "da-DK\n" + - "de\n" + - "de-AT\n" + - "de-CH\n" + - "de-DE\n" + - "de-GR\n" + - "de-LU\n" + - "el\n" + - "el-CY\n" + - "el-GR\n" + - "en\n" + - "en-AU\n" + - "en-CA\n" + - "en-GB\n" + - "en-IE\n" + - "en-IN\n" + - "en-MT\n" + - "en-NZ\n" + - "en-PH\n" + - "en-SG\n" + - "en-US\n" + - "en-ZA\n" + - "es\n" + - "es-AR\n" + - "es-BO\n" + - "es-CL\n" + - "es-CO\n" + - "es-CR\n" + - "es-CU\n" + - "es-DO\n" + - "es-EC\n" + - "es-ES\n" + - "es-GT\n" + - "es-HN\n" + - "es-MX\n" + - "es-NI\n" + - "es-PA\n" + - "es-PE\n" + - "es-PR\n" + - "es-PY\n" + - "es-SV\n" + - "es-US\n" + - "es-UY\n" + - "es-VE\n" + - "et\n" + - "et-EE\n" + - "fi\n" + - "fi-FI\n" + - "fr\n" + - "fr-BE\n" + - "fr-CA\n" + - "fr-CH\n" + - "fr-FR\n" + - "fr-LU\n" + - "ga\n" + - "ga-IE\n" + - "he\n" + - "he-IL\n" + - "hi\n" + - "hi-IN\n" + - "hr\n" + - "hr-HR\n" + - "hu\n" + - "hu-HU\n" + - "id\n" + - "id-ID\n" + - "is\n" + - "is-IS\n" + - "it\n" + - "it-CH\n" + - "it-IT\n" + - "ja\n" + - "ja-JP\n" + - "ja-JP-u-ca-japanese-x-lvariant-JP\n" + - "ko\n" + - "ko-KR\n" + - "lt\n" + - "lt-LT\n" + - "lv\n" + - "lv-LV\n" + - "mk\n" + - "mk-MK\n" + - "ms\n" + - "ms-MY\n" + - "mt\n" + - "mt-MT\n" + - "nl\n" + - "nl-BE\n" + - "nl-NL\n" + - "nn-NO\n" + - "no\n" + - "no-NO\n" + - "pl\n" + - "pl-PL\n" + - "pt\n" + - "pt-BR\n" + - "pt-PT\n" + - "ro\n" + - "ro-RO\n" + - "ru\n" + - "ru-RU\n" + - "sk\n" + - "sk-SK\n" + - "sl\n" + - "sl-SI\n" + - "sq\n" + - "sq-AL\n" + - "sr\n" + - "sr-BA\n" + - "sr-CS\n" + - "sr-Latn\n" + - "sr-Latn-BA\n" + - "sr-Latn-ME\n" + - "sr-Latn-RS\n" + - "sr-ME\n" + - "sr-RS\n" + - "sv\n" + - "sv-SE\n" + - "th\n" + - "th-TH\n" + - "th-TH-u-nu-thai-x-lvariant-TH\n" + - "tr\n" + - "tr-TR\n" + - "uk\n" + - "uk-UA\n" + - "vi\n" + - "vi-VN\n" + - "zh\n" + - "zh-CN\n" + - "zh-HK\n" + - "zh-SG\n" + - "zh-TW\n", - "$locales order by tag"); - } -} diff --git a/core/src/test/java/com/questdb/parser/sql/NullAggregationTest.java b/core/src/test/java/com/questdb/parser/sql/NullAggregationTest.java deleted file mode 100644 index 7fa285b4c..000000000 --- a/core/src/test/java/com/questdb/parser/sql/NullAggregationTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.parser.sql; - -import com.questdb.std.NumericException; -import com.questdb.std.ObjHashSet; -import com.questdb.std.Rnd; -import com.questdb.std.ex.JournalException; -import com.questdb.std.time.DateFormatUtils; -import com.questdb.store.JournalEntryWriter; -import com.questdb.store.JournalWriter; -import com.questdb.store.factory.configuration.JournalStructure; -import org.junit.BeforeClass; -import org.junit.Test; - -public class NullAggregationTest extends AbstractOptimiserTest { - - @BeforeClass - public static void setUp() throws Exception { - createTabWithNaNs2(); - } - - @Test - public void testNanCount() throws Exception { - assertThat("NaN\tVEZDYHDHRFEVHKK\t5\n" + - "NaN\t\t99\n", "(select z, a, count() from tab) where z = NaN and (a ~ 'VE' or a = null)"); - } - - @Test - public void testNullStringCount() throws Exception { - assertThat("\t321\t4\n", "(select a, z, count() from tab) where z = 321 and a = null"); - } - - private static void createTabWithNaNs2() throws JournalException, NumericException { - try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("tab"). - $str("id"). - $double("x"). - $double("y"). - $long("z"). - $int("w"). - $str("a"). - $ts() - - )) { - - Rnd rnd = new Rnd(); - int n = 128; - ObjHashSet names = getNames(rnd, n); - - int mask = n - 1; - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - - for (int i = 0; i < 10000; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putStr(0, names.get(rnd.nextInt() & mask)); - ew.putDouble(1, rnd.nextDouble()); - if (rnd.nextPositiveInt() % 10 == 0) { - ew.putNull(2); - } else { - ew.putDouble(2, rnd.nextDouble()); - } - if (rnd.nextPositiveInt() % 10 == 0) { - ew.putNull(3); - } else { - ew.putLong(3, rnd.nextLong() % 500); - } - if (rnd.nextPositiveInt() % 10 == 0) { - ew.putNull(4); - } else { - ew.putInt(4, rnd.nextInt() % 500); - } - - if (rnd.nextPositiveInt() % 10 == 0) { - ew.putNull(5); - } else { - ew.putStr(5, names.get(rnd.nextInt() & mask)); - } - - ew.putDate(6, t += (60 * 60 * 1000)); - ew.append(); - } - w.commit(); - } - } - - private static ObjHashSet getNames(Rnd r, int n) { - ObjHashSet names = new ObjHashSet<>(); - for (int i = 0; i < n; i++) { - names.add(r.nextString(15)); - } - return names; - } - -} diff --git a/core/src/test/java/com/questdb/parser/sql/NullCountingTest.java b/core/src/test/java/com/questdb/parser/sql/NullCountingTest.java deleted file mode 100644 index f9f9b3595..000000000 --- a/core/src/test/java/com/questdb/parser/sql/NullCountingTest.java +++ /dev/null @@ -1,161 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.parser.sql; - -import com.questdb.std.Numbers; -import com.questdb.std.Rnd; -import com.questdb.std.time.DateFormatUtils; -import com.questdb.store.JournalEntryWriter; -import com.questdb.store.JournalWriter; -import com.questdb.store.factory.configuration.JournalStructure; -import org.junit.BeforeClass; -import org.junit.Test; - -public class NullCountingTest extends AbstractOptimiserTest { - - @BeforeClass - public static void setUp() throws Exception { - int recordCount = 10000; - int productCount = 200; - int employeeCount = 10; - try (JournalWriter orders = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("orders"). - $int("orderId"). - $int("customerId"). - $str("productId"). - $sym("employeeId"). - $ts("orderDate"). - $int("quantity"). - $double("price"). - $float("rate"). - $long("x"). - recordCountHint(recordCount). - $() - )) { - - Rnd rnd = new Rnd(); - - String[] employees = new String[employeeCount]; - for (int i = 0; i < employees.length; i++) { - if (rnd.nextPositiveInt() % 10 == 0) { - employees[i] = null; - } else { - employees[i] = rnd.nextString(9); - } - } - - String[] productId = new String[productCount]; - for (int i = 0; i < productId.length; i++) { - if (rnd.nextPositiveInt() % 30 == 0) { - productId[i] = null; - } else { - productId[i] = rnd.nextString(9); - } - } - - long timestamp = DateFormatUtils.parseDateTime("2014-05-04T10:30:00.000Z"); - int tsIncrement = 10000; - - int orderId = 0; - for (int i = 0; i < recordCount; i++) { - JournalEntryWriter w = orders.entryWriter(); - w.putInt(0, ++orderId); - w.putInt(1, rnd.nextPositiveInt() % 500); - w.putStr(2, productId[rnd.nextPositiveInt() % productCount]); - w.putSym(3, employees[rnd.nextPositiveInt() % employeeCount]); - w.putDate(4, timestamp += tsIncrement); - w.putInt(5, rnd.nextPositiveInt() % 10 == 0 ? Numbers.INT_NaN : rnd.nextPositiveInt()); - w.putDouble(6, rnd.nextPositiveInt() % 10 == 0 ? Double.NaN : rnd.nextDouble()); - w.putFloat(7, rnd.nextPositiveInt() % 10 == 0 ? Float.NaN : rnd.nextFloat()); - w.putLong(8, rnd.nextPositiveInt() % 10 == 0 ? Numbers.LONG_NaN : rnd.nextLong()); - w.append(); - } - orders.commit(); - } - } - - @Test - public void testCountDouble() throws Exception { - assertThat("customerId\tcol0\tc\n" + - "437\t24\t2\n", - "select customerId, count(), count() - count(price) c from orders where customerId = 437", true); - } - - @Test - public void testCountFloat() throws Exception { - assertThat("customerId\tcol0\tc\n" + - "437\t24\t5\n", - "select customerId, count(), count() - count(rate) c from orders where customerId = 437", true); - } - - @Test - public void testCountInt() throws Exception { - assertThat("customerId\tcol0\tc\n" + - "437\t24\t4\n", - "select customerId, count(), count() - count(quantity) c from orders where customerId = 437", true); - } - - @Test - public void testCountLong() throws Exception { - assertThat("customerId\tcol0\tc\n" + - "437\t24\t3\n", - "select customerId, count(), count() - count(x) c from orders where customerId = 437", true); - } - - @Test - public void testCountStr() throws Exception { - assertThat("customerId\tcol0\tc\n" + - "437\t24\t1\n", - "select customerId, count(), count() - count(productId) c from orders where customerId = 437", true); - } - - @Test - public void testCountSym() throws Exception { - assertThat("customerId\tcol0\tc\n" + - "437\t24\t3\n", - "select customerId, count(), count() - count(employeeId) c from orders where customerId = 437", true); - } - - @Test - public void testStrConcat() throws Exception { - assertThat("customerId\tcol0\n" + - "437\tx-\n", - "select customerId, 'x'+productId+'-' from orders where customerId = 437 and productId = null", true); - } - - @Test - public void testStrNotEqSym() throws Exception { - assertThat("col0\n" + - "6327\n", - "select count() from orders " + - "where productId != null " + - "and employeeId != null " + - "and quantity != NaN " + - "and price != NaN " + - "and x != NaN " + - "and productId != 'FCLTJCKFM' " + - "and quantity != 12570116270 " + - "and x != 2454524639747643470", true); - } -} diff --git a/core/src/test/java/com/questdb/parser/sql/QueryDateTest.java b/core/src/test/java/com/questdb/parser/sql/QueryDateTest.java deleted file mode 100644 index 24c9e9727..000000000 --- a/core/src/test/java/com/questdb/parser/sql/QueryDateTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.parser.sql; - -import com.questdb.std.NumericException; -import com.questdb.std.Rnd; -import com.questdb.std.ex.JournalException; -import com.questdb.std.time.DateFormatUtils; -import com.questdb.store.JournalEntryWriter; -import com.questdb.store.JournalWriter; -import com.questdb.store.factory.configuration.JournalStructure; -import org.junit.Test; - -public class QueryDateTest extends AbstractOptimiserTest { - @Test - public void testName() throws Exception { - createTab(); - assertThat("10000\n", "select count() from tab where w = NaN"); - } - - private void createTab() throws JournalException, NumericException { - try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("tab"). - $str("id"). - $double("x"). - $double("y"). - $date("z"). - $date("w"). - $ts() - - )) { - - Rnd rnd = new Rnd(); - - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - long time1 = DateFormatUtils.parseDateTime("2015-10-03T00:00:00.000Z"); - - for (int i = 0; i < 10000; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putStr(0, rnd.nextChars(15)); - ew.putDouble(1, rnd.nextDouble()); - if (rnd.nextPositiveInt() % 10 == 0) { - ew.putNull(2); - } else { - ew.putDouble(2, rnd.nextDouble()); - } - if (rnd.nextPositiveInt() % 10 == 0) { - ew.putNull(3); - } else { - ew.putDate(3, time1 + rnd.nextLong() % 5000000); - } - ew.putDate(5, t += 10); - ew.append(); - } - w.commit(); - } - } -} diff --git a/core/src/test/java/com/questdb/parser/sql/QueryFilterAnalyserTest.java b/core/src/test/java/com/questdb/parser/sql/QueryFilterAnalyserTest.java deleted file mode 100644 index aaed144f1..000000000 --- a/core/src/test/java/com/questdb/parser/sql/QueryFilterAnalyserTest.java +++ /dev/null @@ -1,883 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.parser.sql; - -import com.questdb.ex.ParserException; -import com.questdb.model.Quote; -import com.questdb.parser.sql.model.ExprNode; -import com.questdb.parser.sql.model.IntrinsicModel; -import com.questdb.parser.sql.model.IntrinsicValue; -import com.questdb.std.Chars; -import com.questdb.std.Lexer; -import com.questdb.std.ObjectPool; -import com.questdb.store.JournalWriter; -import com.questdb.test.tools.AbstractTest; -import com.questdb.test.tools.TestUtils; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class QueryFilterAnalyserTest extends AbstractTest { - - private final RpnBuilder rpn = new RpnBuilder(); - private final ObjectPool exprNodeObjectPool = new ObjectPool<>(ExprNode.FACTORY, 128); - private final Lexer lexer = new Lexer(); - private final ExprParser p = new ExprParser(exprNodeObjectPool); - private final ExprAstBuilder ast = new ExprAstBuilder(); - private final QueryFilterAnalyser e = new QueryFilterAnalyser(); - private final PostOrderTreeTraversalAlgo traversalAlgo = new PostOrderTreeTraversalAlgo(); - private final PostOrderTreeTraversalAlgo.Visitor rpnBuilderVisitor = rpn::onNode; - private JournalWriter w; - - @Before - public void setUp() throws Exception { - w = getFactory().writer(Quote.class); - exprNodeObjectPool.clear(); - ExprParser.configureLexer(lexer); - } - - @After - public void tearDown() { - w.close(); - } - - @Test - public void testAndBranchWithNonIndexedField() throws Exception { - IntrinsicModel m = modelOf("timestamp in (\"2014-01-01T12:30:00.000Z\", \"2014-01-02T12:30:00.000Z\") and bid > 100"); - Assert.assertEquals("[Interval{lo=2014-01-01T12:30:00.000Z, hi=2014-01-02T12:30:00.000Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - assertFilter(m, "100bid>"); - } - - @Test - public void testBadCountInInterval() { - try { - modelOf("timestamp = '2015-02-23T10:00:55.000Z;30m;10;z'"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(12, QueryError.getPosition()); - } - } - - @Test - public void testBadDate() { - try { - modelOf("timestamp = '2015-02-23T10:00:55.00z;30m'"); - Assert.fail(); - } catch (ParserException e1) { - Assert.assertEquals(12, QueryError.getPosition()); - } - } - - @Test - public void testBadDateInGreater() { - try { - modelOf("'2014-0x-01T12:30:00.000Z' > timestamp"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(0, QueryError.getPosition()); - } - } - - @Test - public void testBadDateInGreater2() { - try { - modelOf("timestamp > '2014-0x-01T12:30:00.000Z'"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(12, QueryError.getPosition()); - } - } - - @Test - public void testBadDateInInterval() { - try { - modelOf("timestamp = '2014-0x-01T12:30:00.000Z'"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(12, QueryError.getPosition()); - } - } - - @Test - public void testBadDateInLess1() { - try { - modelOf("timestamp < '2014-0x-01T12:30:00.000Z'"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(12, QueryError.getPosition()); - } - } - - @Test - public void testBadDateInLess2() { - try { - modelOf("'2014-0x-01T12:30:00.000Z' < timestamp"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(0, QueryError.getPosition()); - } - } - - @Test - public void testBadEndDate() { - try { - modelOf("timestamp in (\"2014-01-02T12:30:00.000Z\", \"2014-01Z\")"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Unknown date format")); - } - } - - @Test - public void testBadOperators() { - testBadOperator(">"); - testBadOperator(">="); - testBadOperator("<"); - testBadOperator("<="); - testBadOperator("="); - testBadOperator("!="); - } - - @Test - public void testBadPeriodInInterval() { - try { - modelOf("timestamp = '2015-02-23T10:00:55.000Z;30m;x;5'"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(12, QueryError.getPosition()); - } - } - - @Test - public void testBadPeriodInInterval2() { - try { - modelOf("timestamp = '2015-02-23T10:00:55.000Z;30m;10x;5'"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(12, QueryError.getPosition()); - } - } - - @Test - public void testBadRangeInInterval() { - try { - modelOf("timestamp = '2014-03-01T12:30:00.000Z;x'"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(12, QueryError.getPosition()); - } - } - - @Test - public void testBadStartDate() { - try { - modelOf("timestamp in (\"2014-01Z\", \"2014-01-02T12:30:00.000Z\")"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Unknown date format")); - } - } - - @Test - public void testComplexInterval1() throws Exception { - IntrinsicModel m = modelOf("timestamp = '2015-02-23T10:00;2d'"); - Assert.assertEquals("[Interval{lo=2015-02-23T10:00:00.000Z, hi=2015-02-25T10:00:59.999Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - Assert.assertEquals("IntrinsicModel{keyValues=[], keyColumn='null', filter=null}", m.toString()); - } - - @Test - public void testComplexInterval2() throws Exception { - IntrinsicModel m = modelOf("timestamp = '2015-02-23T10:00:55.000Z;7d'"); - Assert.assertEquals("[Interval{lo=2015-02-23T10:00:55.000Z, hi=2015-03-02T10:00:55.000Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - Assert.assertEquals("IntrinsicModel{keyValues=[], keyColumn='null', filter=null}", m.toString()); - } - - @Test - public void testComplexInterval3() throws Exception { - IntrinsicModel m = modelOf("timestamp = '2015-02-23T10:00:55.000Z;15s'"); - Assert.assertEquals("[Interval{lo=2015-02-23T10:00:55.000Z, hi=2015-02-23T10:01:10.000Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - Assert.assertEquals("IntrinsicModel{keyValues=[], keyColumn='null', filter=null}", m.toString()); - } - - @Test - public void testComplexInterval4() throws Exception { - IntrinsicModel m = modelOf("timestamp = '2015-02-23T10:00:55.000Z;30m'"); - Assert.assertEquals("[Interval{lo=2015-02-23T10:00:55.000Z, hi=2015-02-23T10:30:55.000Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - Assert.assertEquals("IntrinsicModel{keyValues=[], keyColumn='null', filter=null}", m.toString()); - } - - @Test - public void testComplexInterval5() throws Exception { - IntrinsicModel m = modelOf("timestamp = '2015-02-23T10:00:55.000Z;30m' and timestamp != '2015-02-23T10:10:00.000Z'"); - Assert.assertEquals("[Interval{lo=2015-02-23T10:00:55.000Z, hi=2015-02-23T10:09:59.999Z},Interval{lo=2015-02-23T10:10:00.001Z, hi=2015-02-23T10:30:55.000Z}]", - IntervalCompiler.asIntervalStr(m.intervals)); - Assert.assertEquals("IntrinsicModel{keyValues=[], keyColumn='null', filter=null}", m.toString()); - } - - @Test - public void testConstVsLambda() throws Exception { - IntrinsicModel m = modelOf("ex in (1,2) and sym in (`xyz`)"); - Assert.assertEquals("sym", m.keyColumn); - Assert.assertEquals(1, m.keyValues.size()); - Assert.assertEquals("xyz", m.keyValues.get(0)); - Assert.assertTrue(m.keyValuesIsLambda); - Assert.assertNotNull(m.filter); - Assert.assertEquals("ex12in", TestUtils.toRpn(m.filter)); - } - - @Test - public void testConstVsLambda2() throws Exception { - IntrinsicModel m = modelOf("sym in (1,2) and sym in (`xyz`)"); - Assert.assertEquals("sym", m.keyColumn); - Assert.assertEquals(1, m.keyValues.size()); - Assert.assertEquals("xyz", m.keyValues.get(0)); - Assert.assertTrue(m.keyValuesIsLambda); - Assert.assertNotNull(m.filter); - Assert.assertEquals("sym12in", TestUtils.toRpn(m.filter)); - } - - @Test - public void testContradictingNullSearch() throws Exception { - IntrinsicModel m = modelOf("sym = null and sym != null and ex != 'blah'"); - Assert.assertEquals(IntrinsicValue.FALSE, m.intrinsicValue); - assertFilter(m, "'blah'ex!="); - Assert.assertEquals("[]", m.keyValues.toString()); - Assert.assertEquals("[]", m.keyValuePositions.toString()); - } - - @Test - public void testDubiousEquals() throws Exception { - IntrinsicModel m = modelOf("sum(ts) = sum(ts)"); - Assert.assertNull(m.filter); - } - - @Test - public void testDubiousGreater() throws Exception { - IntrinsicModel m = modelOf("ts > ts"); - Assert.assertEquals(IntrinsicValue.FALSE, m.intrinsicValue); - } - - @Test - public void testDubiousLess() throws Exception { - IntrinsicModel m = modelOf("ts < ts"); - Assert.assertEquals(IntrinsicValue.FALSE, m.intrinsicValue); - } - - @Test - public void testDubiousNotEquals() throws Exception { - IntrinsicModel m = modelOf("ts != ts"); - Assert.assertEquals(IntrinsicValue.FALSE, m.intrinsicValue); - } - - @Test - public void testEqualsChoiceOfColumns() throws Exception { - IntrinsicModel m = modelOf("sym = 'X' and ex = 'Y'"); - assertFilter(m, "'Y'ex="); - Assert.assertEquals("sym", m.keyColumn); - Assert.assertEquals("[X]", m.keyValues.toString()); - } - - @Test - public void testEqualsChoiceOfColumns2() throws Exception { - IntrinsicModel m = modelOf("ex = 'Y' and sym = 'X'"); - assertFilter(m, "'Y'ex="); - Assert.assertEquals("sym", m.keyColumn); - Assert.assertEquals("[X]", m.keyValues.toString()); - } - - @Test - public void testEqualsIndexedSearach() throws Exception { - IntrinsicModel m = modelOf("sym ='X' and bid > 100.05"); - assertFilter(m, "100.05bid>"); - Assert.assertEquals("sym", m.keyColumn); - Assert.assertEquals("[X]", m.keyValues.toString()); - } - - @Test - public void testEqualsInvalidColumn() { - try { - modelOf("sym = 'X' and x = 'Y'"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertEquals(14, QueryError.getPosition()); - } - } - - @Test - public void testEqualsNull() throws Exception { - IntrinsicModel m = modelOf("sym = null"); - Assert.assertEquals("sym", m.keyColumn); - Assert.assertEquals("[null]", m.keyValues.toString()); - } - - @Test - public void testEqualsOverlapWithIn() throws Exception { - IntrinsicModel m = modelOf("sym in ('x','y') and sym = 'y'"); - Assert.assertNull(m.filter); - Assert.assertEquals("[y]", m.keyValues.toString()); - Assert.assertEquals("[12]", m.keyValuePositions.toString()); - } - - @Test - public void testEqualsOverlapWithIn2() throws Exception { - IntrinsicModel m = modelOf("sym = 'y' and sym in ('x','y')"); - Assert.assertNull(m.filter); - Assert.assertEquals("[y]", m.keyValues.toString()); - } - - @Test - public void testEqualsZeroOverlapWithIn() throws Exception { - IntrinsicModel m = modelOf("sym in ('x','y') and sym = 'z'"); - Assert.assertEquals(IntrinsicValue.FALSE, m.intrinsicValue); - } - - @Test - public void testEqualsZeroOverlapWithIn2() throws Exception { - IntrinsicModel m = modelOf("sym = 'z' and sym in ('x','y')"); - Assert.assertEquals(IntrinsicValue.FALSE, m.intrinsicValue); - } - - @Test - public void testExactDate() throws Exception { - IntrinsicModel m = modelOf("timestamp = '2015-05-10T15:03:10.000Z' and timestamp < '2015-05-11T08:00:55.000Z'"); - Assert.assertEquals("[Interval{lo=2015-05-10T15:03:10.000Z, hi=2015-05-10T15:03:10.000Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - Assert.assertNull(m.filter); - } - - @Test - public void testExactDateVsInterval() throws Exception { - IntrinsicModel m = modelOf("timestamp = '2015-05-10T15:03:10.000Z' and timestamp = '2015-05-11'"); - Assert.assertEquals(IntrinsicValue.FALSE, m.intrinsicValue); - Assert.assertNull(m.filter); - } - - @Test - public void testFilterAndInterval() throws Exception { - IntrinsicModel m = modelOf("bid > 100 and timestamp in (\"2014-01-01T12:30:00.000Z\", \"2014-01-02T12:30:00.000Z\")"); - Assert.assertEquals("[Interval{lo=2014-01-01T12:30:00.000Z, hi=2014-01-02T12:30:00.000Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - assertFilter(m, "100bid>"); - } - - @Test - public void testFilterMultipleKeysAndInterval() throws Exception { - IntrinsicModel m = modelOf("sym in (\"a\", \"b\", \"c\") and timestamp in (\"2014-01-01T12:30:00.000Z\", \"2014-01-02T12:30:00.000Z\")"); - Assert.assertEquals("[Interval{lo=2014-01-01T12:30:00.000Z, hi=2014-01-02T12:30:00.000Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - Assert.assertEquals("sym", m.keyColumn); - Assert.assertEquals("[a,b,c]", m.keyValues.toString()); - Assert.assertEquals("[8,13,18]", m.keyValuePositions.toString()); - Assert.assertNull(m.filter); - } - - @Test - public void testFilterOnIndexedFieldAndInterval() throws Exception { - IntrinsicModel m = modelOf("sym in ('a') and timestamp in (\"2014-01-01T12:30:00.000Z\", \"2014-01-02T12:30:00.000Z\")"); - Assert.assertEquals("[Interval{lo=2014-01-01T12:30:00.000Z, hi=2014-01-02T12:30:00.000Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - Assert.assertEquals("sym", m.keyColumn); - Assert.assertEquals("[a]", m.keyValues.toString()); - Assert.assertNull(m.filter); - } - - @Test - public void testFilterOrInterval() throws Exception { - IntrinsicModel m = modelOf("bid > 100 or timestamp in (\"2014-01-01T12:30:00.000Z\", \"2014-01-02T12:30:00.000Z\")"); - Assert.assertNull(m.intervals); - assertFilter(m, "\"2014-01-02T12:30:00.000Z\"\"2014-01-01T12:30:00.000Z\"timestampin100bid>or"); - } - - @Test - public void testInNull() throws Exception { - IntrinsicModel m = modelOf("sym in ('X', null, 'Y')"); - Assert.assertEquals("sym", m.keyColumn); - Assert.assertEquals("[X,null,Y]", m.keyValues.toString()); - } - - @Test - public void testInVsEqualInterval() throws Exception { - IntrinsicModel m = modelOf("timestamp in ('2014-01-01T12:30:00.000Z', '2014-01-02T12:30:00.000Z') and timestamp = '2014-01-01'"); - Assert.assertNull(m.filter); - Assert.assertEquals("[Interval{lo=2014-01-01T12:30:00.000Z, hi=2014-01-01T23:59:59.999Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - } - - @Test - public void testIndexedFieldTooFewArgs2() throws Exception { - assertFilter(modelOf("sym in (x)"), "xsymin"); - } - - @Test - public void testIndexedFieldTooFewArgs3() { - try { - modelOf("sym in ()"); - Assert.fail("exception expected"); - } catch (ParserException e) { - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Too few arguments")); - } - } - - @Test - public void testIntervalGreater1() throws Exception { - IntrinsicModel m = modelOf("timestamp in ('2014-01-01T12:30:00.000Z', '2014-01-02T12:30:00.000Z') and timestamp > '2014-01-01T15:30:00.000Z'"); - Assert.assertEquals("[Interval{lo=2014-01-01T15:30:00.001Z, hi=2014-01-02T12:30:00.000Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - } - - @Test - public void testIntervalGreater2() throws Exception { - IntrinsicModel m = modelOf("timestamp > '2014-01-01T15:30:00.000Z' and timestamp in ('2014-01-01T12:30:00.000Z', '2014-01-02T12:30:00.000Z')"); - Assert.assertEquals("[Interval{lo=2014-01-01T15:30:00.001Z, hi=2014-01-02T12:30:00.000Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - } - - @Test - public void testIntervalGreaterOrEq1() throws Exception { - IntrinsicModel m = modelOf("timestamp in ('2014-01-01T12:30:00.000Z', '2014-01-02T12:30:00.000Z') and timestamp >= '2014-01-01T15:30:00.000Z'"); - Assert.assertEquals("[Interval{lo=2014-01-01T15:30:00.000Z, hi=2014-01-02T12:30:00.000Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - } - - @Test - public void testIntervalGreaterOrEq2() throws Exception { - IntrinsicModel m = modelOf("timestamp >= '2014-01-01T15:30:00.000Z' and timestamp in ('2014-01-01T12:30:00.000Z', '2014-01-02T12:30:00.000Z')"); - Assert.assertEquals("[Interval{lo=2014-01-01T15:30:00.000Z, hi=2014-01-02T12:30:00.000Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - } - - @Test - public void testIntervalSourceDay() throws Exception { - IntrinsicModel m = modelOf("timestamp = '2015-02-23T10:00:55.000Z;30m;2d;5'"); - Assert.assertEquals("[Interval{lo=2015-02-23T10:00:55.000Z, hi=2015-02-23T10:30:55.000Z},Interval{lo=2015-02-25T10:00:55.000Z, hi=2015-02-25T10:30:55.000Z},Interval{lo=2015-02-27T10:00:55.000Z, hi=2015-02-27T10:30:55.000Z},Interval{lo=2015-03-01T10:00:55.000Z, hi=2015-03-01T10:30:55.000Z},Interval{lo=2015-03-03T10:00:55.000Z, hi=2015-03-03T10:30:55.000Z}]", - IntervalCompiler.asIntervalStr(m.intervals)); - } - - @Test - public void testIntervalSourceHour() throws Exception { - IntrinsicModel m = modelOf("timestamp = '2015-02-23T10:00:55.000Z;10m;3h;10'"); - final String expected = "[Interval{lo=2015-02-23T10:00:55.000Z, hi=2015-02-23T10:10:55.000Z}," + - "Interval{lo=2015-02-23T13:00:55.000Z, hi=2015-02-23T13:10:55.000Z}," + - "Interval{lo=2015-02-23T16:00:55.000Z, hi=2015-02-23T16:10:55.000Z}," + - "Interval{lo=2015-02-23T19:00:55.000Z, hi=2015-02-23T19:10:55.000Z}," + - "Interval{lo=2015-02-23T22:00:55.000Z, hi=2015-02-23T22:10:55.000Z}," + - "Interval{lo=2015-02-24T01:00:55.000Z, hi=2015-02-24T01:10:55.000Z}," + - "Interval{lo=2015-02-24T04:00:55.000Z, hi=2015-02-24T04:10:55.000Z}," + - "Interval{lo=2015-02-24T07:00:55.000Z, hi=2015-02-24T07:10:55.000Z}," + - "Interval{lo=2015-02-24T10:00:55.000Z, hi=2015-02-24T10:10:55.000Z}," + - "Interval{lo=2015-02-24T13:00:55.000Z, hi=2015-02-24T13:10:55.000Z}]"; - - Assert.assertEquals(expected, IntervalCompiler.asIntervalStr(m.intervals)); - } - - @Test - public void testIntervalSourceMin() throws Exception { - IntrinsicModel m = modelOf("timestamp = '2015-02-23T10:00:55.000Z;15s;15m;5'"); - final String expected = "[Interval{lo=2015-02-23T10:00:55.000Z, hi=2015-02-23T10:01:10.000Z}," + - "Interval{lo=2015-02-23T10:15:55.000Z, hi=2015-02-23T10:16:10.000Z}," + - "Interval{lo=2015-02-23T10:30:55.000Z, hi=2015-02-23T10:31:10.000Z}," + - "Interval{lo=2015-02-23T10:45:55.000Z, hi=2015-02-23T10:46:10.000Z}," + - "Interval{lo=2015-02-23T11:00:55.000Z, hi=2015-02-23T11:01:10.000Z}]"; - Assert.assertEquals(expected, IntervalCompiler.asIntervalStr(m.intervals)); - } - - @Test - public void testIntervalSourceMonth() throws Exception { - IntrinsicModel m = modelOf("timestamp = '2015-02-23T10:00:55.000Z;2h;2M;3'"); - final String expected = "[Interval{lo=2015-02-23T10:00:55.000Z, hi=2015-02-23T12:00:55.000Z}," + - "Interval{lo=2015-04-23T10:00:55.000Z, hi=2015-04-23T12:00:55.000Z}," + - "Interval{lo=2015-06-23T10:00:55.000Z, hi=2015-06-23T12:00:55.000Z}]"; - - Assert.assertEquals(expected, IntervalCompiler.asIntervalStr(m.intervals)); - } - - @Test - public void testIntervalSourceSec() throws Exception { - IntrinsicModel m = modelOf("timestamp = '2015-02-23T10:00:55.000Z;5s;30s;5'"); - final String expected = "[Interval{lo=2015-02-23T10:00:55.000Z, hi=2015-02-23T10:01:00.000Z}," + - "Interval{lo=2015-02-23T10:01:25.000Z, hi=2015-02-23T10:01:30.000Z}," + - "Interval{lo=2015-02-23T10:01:55.000Z, hi=2015-02-23T10:02:00.000Z}," + - "Interval{lo=2015-02-23T10:02:25.000Z, hi=2015-02-23T10:02:30.000Z}," + - "Interval{lo=2015-02-23T10:02:55.000Z, hi=2015-02-23T10:03:00.000Z}]"; - - Assert.assertEquals(expected, IntervalCompiler.asIntervalStr(m.intervals)); - } - - @Test - public void testIntervalSourceYear() throws Exception { - IntrinsicModel m = modelOf("timestamp = '2015-02-23T10:00:55.000Z;1d;1y;5'"); - final String expected = "[Interval{lo=2015-02-23T10:00:55.000Z, hi=2015-02-24T10:00:55.000Z}," + - "Interval{lo=2016-02-23T10:00:55.000Z, hi=2016-02-24T10:00:55.000Z}," + - "Interval{lo=2017-02-23T10:00:55.000Z, hi=2017-02-24T10:00:55.000Z}," + - "Interval{lo=2018-02-23T10:00:55.000Z, hi=2018-02-24T10:00:55.000Z}," + - "Interval{lo=2019-02-23T10:00:55.000Z, hi=2019-02-24T10:00:55.000Z}]"; - - Assert.assertEquals(expected, IntervalCompiler.asIntervalStr(m.intervals)); - } - - @Test - public void testIntervalTooFewArgs() { - try { - modelOf("timestamp in (\"2014-01-01T12:30:00.000Z\")"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Too few arg")); - } - } - - @Test - public void testIntervalTooFewArgs2() { - try { - modelOf("timestamp in ()"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Too few arg")); - } - } - - @Test - public void testIntervalTooManyArgs() { - try { - modelOf("timestamp in (\"2014-01-01T12:30:00.000Z\", \"2014-01-02T12:30:00.000Z\", \"2014-01-03T12:30:00.000Z\")"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Too many arg")); - } - } - - @Test - public void testIntrinsicPickup() throws Exception { - assertFilter(modelOf("timestamp = '2014-06-20T13:25:00.000Z;10m;2d;4' and sym in ('A', 'B') or ex = 'D'"), "'D'ex='B''A'symin'2014-06-20T13:25:00.000Z;10m;2d;4'timestamp=andor"); - assertFilter(modelOf("timestamp = '2014-06-20T13:25:00.000Z;10m;2d;4' or ex = 'D' and sym in ('A', 'B')"), "'D'ex='2014-06-20T13:25:00.000Z;10m;2d;4'timestamp=or"); - } - - @Test(expected = ParserException.class) - public void testInvalidIntervalSource1() throws Exception { - modelOf("timestamp = '2014-06-20T13:25:00.000Z;10m;2d'"); - } - - @Test(expected = ParserException.class) - public void testInvalidIntervalSource2() throws Exception { - modelOf("timestamp = '2014-06-20T13:25:00.000Z;10m;2d;4;4'"); - } - - @Test - public void testLambdaVsConst() throws Exception { - IntrinsicModel m = modelOf("sym in (`xyz`) and ex in (1,2)"); - Assert.assertEquals("sym", m.keyColumn); - Assert.assertEquals(1, m.keyValues.size()); - Assert.assertEquals("xyz", m.keyValues.get(0)); - Assert.assertTrue(m.keyValuesIsLambda); - Assert.assertNotNull(m.filter); - Assert.assertEquals("ex12in", TestUtils.toRpn(m.filter)); - } - - @Test - public void testListOfValuesNegativeOverlap() throws Exception { - IntrinsicModel m = modelOf("timestamp in ('2014-01-01T12:30:00.000Z', '2014-01-02T12:30:00.000Z') and sym in ('a', 'z') and sym in ('c')"); - Assert.assertEquals(IntrinsicValue.FALSE, m.intrinsicValue); - } - - @Test - public void testListOfValuesOverlapWithNotClause() throws Exception { - IntrinsicModel m = modelOf("timestamp in ('2014-01-01T12:30:00.000Z', '2014-01-02T12:30:00.000Z') and sym in ('a', 'z') and not (sym in ('c', 'd', 'e'))"); - Assert.assertEquals("[a,z]", m.keyValues.toString()); - Assert.assertNull(m.filter); - Assert.assertEquals(IntrinsicValue.UNDEFINED, m.intrinsicValue); - } - - @Test - public void testListOfValuesOverlapWithNotClause2() throws Exception { - IntrinsicModel m = modelOf("timestamp in ('2014-01-01T12:30:00.000Z', '2014-01-02T12:30:00.000Z') and sym in ('a', 'z') and not (sym in ('a', 'd', 'e'))"); - Assert.assertNull(m.filter); - Assert.assertEquals("[z]", m.keyValues.toString()); - Assert.assertEquals(IntrinsicValue.UNDEFINED, m.intrinsicValue); - } - - @Test - public void testListOfValuesPositiveOverlap() throws Exception { - IntrinsicModel m = modelOf("timestamp in ('2014-01-01T12:30:00.000Z', '2014-01-02T12:30:00.000Z') and sym in ('a', 'z') and sym in ('z')"); - Assert.assertNull(m.filter); - Assert.assertEquals(IntrinsicValue.UNDEFINED, m.intrinsicValue); - Assert.assertEquals("[z]", m.keyValues.toString()); - } - - @Test - public void testListOfValuesPositiveOverlapQuoteIndifference() throws Exception { - IntrinsicModel m = modelOf("timestamp in ('2014-01-01T12:30:00.000Z', '2014-01-02T12:30:00.000Z') and sym in ('a', \"z\") and sym in ('z')"); - Assert.assertNull(m.filter); - Assert.assertEquals(IntrinsicValue.UNDEFINED, m.intrinsicValue); - Assert.assertEquals("[z]", m.keyValues.toString()); - } - - @Test - public void testLiteralInInterval() throws Exception { - IntrinsicModel m = modelOf("timestamp in (\"2014-01-01T12:30:00.000Z\", c)"); - Assert.assertNull(m.intervals); - assertFilter(m, "c\"2014-01-01T12:30:00.000Z\"timestampin"); - } - - @Test - public void testLiteralInListOfValues() throws Exception { - IntrinsicModel m = modelOf("sym in (\"a\", z) and timestamp in (\"2014-01-01T12:30:00.000Z\", \"2014-01-02T12:30:00.000Z\")"); - Assert.assertEquals("[Interval{lo=2014-01-01T12:30:00.000Z, hi=2014-01-02T12:30:00.000Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - Assert.assertNull(m.keyColumn); - assertFilter(m, "z\"a\"symin"); - } - - @Test - public void testLiteralInListOfValuesInvalidColumn() { - try { - modelOf("timestamp in ('2014-01-01T12:30:00.000Z', '2014-01-02T12:30:00.000Z') and x in ('a', z)"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertEquals(74, QueryError.getPosition()); - } - } - - @Test - public void testManualInterval() throws Exception { - IntrinsicModel m = modelOf("timestamp >= '2014-01-01T15:30:00.000Z' and timestamp < '2014-01-02T12:30:00.000Z'"); - Assert.assertEquals("[Interval{lo=2014-01-01T15:30:00.000Z, hi=2014-01-02T12:29:59.999Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - } - - @Test - public void testManualIntervalInverted() throws Exception { - IntrinsicModel m = modelOf("'2014-01-02T12:30:00.000Z' > timestamp and '2014-01-01T15:30:00.000Z' <= timestamp "); - Assert.assertEquals("[Interval{lo=2014-01-01T15:30:00.000Z, hi=2014-01-02T12:29:59.999Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - } - - @Test - public void testMultipleAnds() throws Exception { - IntrinsicModel m = modelOf("a > 10 and b > 20 and (c > 100 and d < 20 and bid = 30)"); - assertFilter(m, "30bid=20d<100c>andand20b>10a>andand"); - } - - @Test - public void testNestedFunctionTest() throws Exception { - IntrinsicModel m = modelOf("substr(parse(x, 1, 3), 2, 4)"); - Assert.assertNull(m.intervals); - assertFilter(m, "4231xparsesubstr"); - } - - @Test - public void testNoIntrinsics() throws Exception { - IntrinsicModel m = modelOf("a > 10 or b > 20"); - Assert.assertNull(m.intervals); - Assert.assertNull(m.keyColumn); - assertFilter(m, "20b>10a>or"); - } - - @Test - public void testNonLiteralColumn() { - try { - modelOf("10 in (\"2014-01-01T12:30:00.000Z\", \"2014-01-02T12:30:00.000Z\")"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Column name expected")); - } - } - - @Test - public void testNotEqualsDoesNotOverlapWithIn() throws Exception { - IntrinsicModel m = modelOf("sym in ('x','y') and sym != 'z' and ex != 'blah'"); - assertFilter(m, "'blah'ex!="); - Assert.assertEquals("[x,y]", m.keyValues.toString()); - Assert.assertEquals("[8,12]", m.keyValuePositions.toString()); - } - - @Test - public void testNotEqualsOverlapWithIn() throws Exception { - IntrinsicModel m = modelOf("sym in ('x','y') and sym != 'y' and ex != 'blah'"); - assertFilter(m, "'blah'ex!="); - Assert.assertEquals("[x]", m.keyValues.toString()); - Assert.assertEquals("[8]", m.keyValuePositions.toString()); - } - - @Test - public void testOr() throws Exception { - IntrinsicModel m = modelOf("(sym = 'X' or sym = 'Y') and bid > 10"); - Assert.assertEquals(IntrinsicValue.UNDEFINED, m.intrinsicValue); - assertFilter(m, "10bid>'Y'sym='X'sym=orand"); - } - - @Test - public void testOrNullSearch() throws Exception { - IntrinsicModel m = modelOf("sym = null or sym != null and ex != 'blah'"); - Assert.assertEquals(IntrinsicValue.UNDEFINED, m.intrinsicValue); - assertFilter(m, "'blah'ex!=nullsym!=nullsym=orand"); - Assert.assertEquals("[]", m.keyValues.toString()); - Assert.assertEquals("[]", m.keyValuePositions.toString()); - } - - @Test - public void testPreferredColumn() throws Exception { - IntrinsicModel m; - m = modelOf("sym in ('a', 'b') and ex in ('c') and timestamp in ('2014-01-01T12:30:00.000Z', '2014-01-02T12:30:00.000Z') and bid > 100 and ask < 110", "ex"); - assertFilter(m, "110ask<100bid>'b''a'syminandand"); - Assert.assertEquals("ex", m.keyColumn); - Assert.assertEquals("[c]", m.keyValues.toString()); - Assert.assertEquals("[Interval{lo=2014-01-01T12:30:00.000Z, hi=2014-01-02T12:30:00.000Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - } - - @Test - public void testPreferredColumn2() throws Exception { - IntrinsicModel m; - m = modelOf("ex in ('c') and sym in ('a', 'b') and timestamp in ('2014-01-01T12:30:00.000Z', '2014-01-02T12:30:00.000Z') and bid > 100 and ask < 110", "ex"); - assertFilter(m, "110ask<100bid>'b''a'syminandand"); - Assert.assertEquals("ex", m.keyColumn); - Assert.assertEquals("[c]", m.keyValues.toString()); - Assert.assertEquals("[Interval{lo=2014-01-01T12:30:00.000Z, hi=2014-01-02T12:30:00.000Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - } - - @Test - public void testPreferredColumn3() throws Exception { - IntrinsicModel m; - m = modelOf("sym in ('a', 'b') and timestamp in ('2014-01-01T12:30:00.000Z', '2014-01-02T12:30:00.000Z') and bid > 100 and ask < 110", "ex"); - assertFilter(m, "110ask<100bid>'b''a'syminandand"); - Assert.assertNull(m.keyColumn); - Assert.assertEquals("[Interval{lo=2014-01-01T12:30:00.000Z, hi=2014-01-02T12:30:00.000Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - } - - @Test - public void testSimpleInterval() throws Exception { - IntrinsicModel m = modelOf("timestamp in (\"2014-01-01T12:30:00.000Z\", \"2014-01-02T12:30:00.000Z\")"); - Assert.assertEquals("[Interval{lo=2014-01-01T12:30:00.000Z, hi=2014-01-02T12:30:00.000Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - Assert.assertNull(m.filter); - } - - @Test - public void testSimpleLambda() throws Exception { - IntrinsicModel m = modelOf("sym in (`xyz`)"); - Assert.assertEquals("xyz", m.keyValues.get(0)); - Assert.assertTrue(m.keyValuesIsLambda); - } - - @Test - public void testSingleQuoteInterval() throws Exception { - IntrinsicModel m = modelOf("timestamp in ('2014-01-01T12:30:00.000Z', '2014-01-02T12:30:00.000Z')"); - Assert.assertEquals("[Interval{lo=2014-01-01T12:30:00.000Z, hi=2014-01-02T12:30:00.000Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - Assert.assertNull(m.filter); - } - - @Test - public void testThreeIntrinsics() throws Exception { - IntrinsicModel m; - m = modelOf("sym in ('a', 'b') and ex in ('c') and timestamp in ('2014-01-01T12:30:00.000Z', '2014-01-02T12:30:00.000Z') and bid > 100 and ask < 110"); - assertFilter(m, "110ask<100bid>'c'exinandand"); - Assert.assertEquals("sym", m.keyColumn); - Assert.assertEquals("[a,b]", m.keyValues.toString()); - Assert.assertEquals("[Interval{lo=2014-01-01T12:30:00.000Z, hi=2014-01-02T12:30:00.000Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - } - - @Test - public void testThreeIntrinsics2() throws Exception { - IntrinsicModel m; - m = modelOf("ex in ('c') and sym in ('a', 'b') and timestamp in ('2014-01-01T12:30:00.000Z', '2014-01-02T12:30:00.000Z') and bid > 100 and ask < 110"); - assertFilter(m, "110ask<100bid>'c'exinandand"); - Assert.assertEquals("sym", m.keyColumn); - Assert.assertEquals("[a,b]", m.keyValues.toString()); - Assert.assertEquals("[Interval{lo=2014-01-01T12:30:00.000Z, hi=2014-01-02T12:30:00.000Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - } - - @Test - public void testTwoDiffColLambdas() throws Exception { - IntrinsicModel m = modelOf("sym in (`xyz`) and ex in (`kkk`)"); - Assert.assertEquals("sym", m.keyColumn); - Assert.assertEquals(1, m.keyValues.size()); - Assert.assertEquals("xyz", m.keyValues.get(0)); - Assert.assertTrue(m.keyValuesIsLambda); - Assert.assertNotNull(m.filter); - Assert.assertEquals(ExprNode.LAMBDA, m.filter.rhs.type); - } - - @Test - public void testTwoExactMatchDifferentDates() throws Exception { - IntrinsicModel m = modelOf("timestamp = '2015-05-10T15:03:10.000Z' and timestamp = '2015-05-11T15:03:10.000Z' and timestamp = '2015-05-11'"); - Assert.assertEquals("[]", IntervalCompiler.asIntervalStr(m.intervals)); - Assert.assertNull(m.filter); - Assert.assertEquals(IntrinsicValue.FALSE, m.intrinsicValue); - } - - @Test - public void testTwoExactSameDates() throws Exception { - IntrinsicModel m = modelOf("timestamp = '2015-05-10T15:03:10.000Z' and timestamp = '2015-05-10T15:03:10.000Z' and timestamp = '2015-05-11'"); - Assert.assertEquals("[]", IntervalCompiler.asIntervalStr(m.intervals)); - Assert.assertNull(m.filter); - Assert.assertEquals(IntrinsicValue.FALSE, m.intrinsicValue); - } - - @Test - public void testTwoIntervalSources() throws Exception { - IntrinsicModel m = modelOf("timestamp = '2014-06-20T13:25:00.000Z;10m;2d;5' and timestamp = '2015-06-20T13:25:00.000Z;10m;2d;5'"); - Assert.assertEquals("[]", IntervalCompiler.asIntervalStr(m.intervals)); - } - - @Test - public void testTwoIntervals() throws Exception { - IntrinsicModel m = modelOf("bid > 100 and timestamp in (\"2014-01-01T12:30:00.000Z\", \"2014-01-02T12:30:00.000Z\") and timestamp in (\"2014-01-01T16:30:00.000Z\", \"2014-01-05T12:30:00.000Z\")"); - Assert.assertEquals("[Interval{lo=2014-01-01T16:30:00.000Z, hi=2014-01-02T12:30:00.000Z}]", IntervalCompiler.asIntervalStr(m.intervals)); - } - - @Test - public void testTwoSameColLambdas() { - try { - modelOf("sym in (`xyz`) and sym in (`kkk`)"); - Assert.fail("exception expected"); - } catch (ParserException e) { - Assert.assertEquals(4, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Multiple lambda")); - } - } - - private void assertFilter(IntrinsicModel m, CharSequence expected) throws ParserException { - Assert.assertNotNull(m.filter); - TestUtils.assertEquals(expected, toRpn(m.filter)); - } - - private IntrinsicModel modelOf(CharSequence seq) throws ParserException { - return modelOf(seq, null); - } - - private IntrinsicModel modelOf(CharSequence seq, String preferredColumn) throws ParserException { - lexer.setContent(seq); - p.parseExpr(lexer, ast); - return e.extract(column -> column, ast.poll(), w.getMetadata(), preferredColumn, w.getMetadata().getTimestampIndex()); - } - - private void testBadOperator(String op) { - try { - modelOf("sum(ts) " + op); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(8, QueryError.getPosition()); - } - - try { - modelOf(op + " sum(ts)"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(0, QueryError.getPosition()); - } - - } - - private CharSequence toRpn(ExprNode node) throws ParserException { - rpn.reset(); - traversalAlgo.traverse(node, rpnBuilderVisitor); - return rpn.rpn(); - } -} diff --git a/core/src/test/java/com/questdb/parser/sql/QueryParserTest.java b/core/src/test/java/com/questdb/parser/sql/QueryParserTest.java deleted file mode 100644 index 1985360f0..000000000 --- a/core/src/test/java/com/questdb/parser/sql/QueryParserTest.java +++ /dev/null @@ -1,738 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.parser.sql; - -import com.questdb.ex.ParserException; -import com.questdb.parser.sql.model.AnalyticColumn; -import com.questdb.parser.sql.model.ExprNode; -import com.questdb.parser.sql.model.QueryModel; -import com.questdb.std.Chars; -import com.questdb.test.tools.AbstractTest; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Test; - -public class QueryParserTest extends AbstractTest { - private final QueryParser parser = new QueryParser(); - - @Test - public void testAliasWithSpace() throws Exception { - QueryModel statement = (QueryModel) parser.parse("x 'b a' where x > 1"); - Assert.assertEquals("b a", statement.getAlias().token); - } - - @Test - public void testAliasWithSpace2() throws Exception { - QueryModel statement = (QueryModel) parser.parse("(x where a > 1) 'b a' where x > 1"); - Assert.assertEquals("b a", statement.getAlias().token); - } - - @Test - public void testAliasWithSpacex() { - try { - parser.parse("from x 'a b' where x > 1"); - } catch (ParserException e) { - Assert.assertEquals(7, QueryError.getPosition()); - } - } - - @Test - public void testAliasedAnalyticColumn() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select a,b, f(c) my over (partition by b order by ts) from xyz"); - Assert.assertEquals(3, statement.getColumns().size()); - - AnalyticColumn col = (AnalyticColumn) statement.getColumns().get(2); - Assert.assertEquals("my", col.getAlias()); - Assert.assertEquals(ExprNode.FUNCTION, col.getAst().type); - Assert.assertEquals(1, col.getPartitionBy().size()); - Assert.assertEquals("b", col.getPartitionBy().get(0).token); - - Assert.assertEquals(1, col.getOrderBy().size()); - Assert.assertEquals("ts", col.getOrderBy().get(0).token); - } - - @Test - public void testAnalyticOrderDirection() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select a,b, f(c) my over (partition by b order by ts desc, x asc, y) from xyz"); - Assert.assertEquals(3, statement.getColumns().size()); - - AnalyticColumn col = (AnalyticColumn) statement.getColumns().get(2); - Assert.assertEquals("my", col.getAlias()); - Assert.assertEquals(ExprNode.FUNCTION, col.getAst().type); - Assert.assertEquals(1, col.getPartitionBy().size()); - Assert.assertEquals("b", col.getPartitionBy().get(0).token); - - Assert.assertEquals(3, col.getOrderBy().size()); - Assert.assertEquals("ts", col.getOrderBy().get(0).token); - Assert.assertEquals(QueryModel.ORDER_DIRECTION_DESCENDING, col.getOrderByDirection().get(0)); - Assert.assertEquals("x", col.getOrderBy().get(1).token); - Assert.assertEquals(QueryModel.ORDER_DIRECTION_ASCENDING, col.getOrderByDirection().get(1)); - Assert.assertEquals("y", col.getOrderBy().get(2).token); - Assert.assertEquals(QueryModel.ORDER_DIRECTION_ASCENDING, col.getOrderByDirection().get(2)); - } - - @Test - public void testCrossJoin() { - try { - parser.parse("select x from a a cross join b on b.x = a.x"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertEquals(31, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "cannot")); - } - } - - @Test - public void testCrossJoin2() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select x from a a cross join b z"); - Assert.assertNotNull(statement); - Assert.assertEquals("a", statement.getAlias().token); - Assert.assertEquals(2, statement.getJoinModels().size()); - Assert.assertEquals(QueryModel.JOIN_CROSS, statement.getJoinModels().getQuick(1).getJoinType()); - Assert.assertNull(statement.getJoinModels().getQuick(1).getJoinCriteria()); - } - - @Test - public void testCrossJoin3() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select x from a a " + - "cross join b z " + - "join c on a.x = c.x"); - Assert.assertNotNull(statement); - Assert.assertEquals("a", statement.getAlias().token); - Assert.assertEquals(3, statement.getJoinModels().size()); - Assert.assertEquals(QueryModel.JOIN_CROSS, statement.getJoinModels().getQuick(1).getJoinType()); - Assert.assertNull(statement.getJoinModels().getQuick(1).getJoinCriteria()); - Assert.assertEquals(QueryModel.JOIN_INNER, statement.getJoinModels().getQuick(2).getJoinType()); - Assert.assertNotNull(statement.getJoinModels().getQuick(2).getJoinCriteria()); - } - - @Test - public void testCrossJoinNoAlias() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select x from a a " + - "cross join b " + - "join c on a.x = c.x"); - Assert.assertNotNull(statement); - Assert.assertEquals("a", statement.getAlias().token); - Assert.assertEquals(3, statement.getJoinModels().size()); - Assert.assertEquals(QueryModel.JOIN_CROSS, statement.getJoinModels().getQuick(1).getJoinType()); - Assert.assertNull(statement.getJoinModels().getQuick(1).getJoinCriteria()); - Assert.assertEquals(QueryModel.JOIN_INNER, statement.getJoinModels().getQuick(2).getJoinType()); - Assert.assertNotNull(statement.getJoinModels().getQuick(2).getJoinCriteria()); - } - - @Test - public void testEmptyGroupBy() { - try { - parser.parse("select x, y from tab sample by"); - Assert.fail("Expected exception"); - } catch (ParserException e) { - Assert.assertEquals(28, QueryError.getPosition()); - } - } - - @Test - public void testEmptyOrderBy() { - try { - parser.parse("select x, y from tab order by"); - Assert.fail("Expected exception"); - } catch (ParserException e) { - Assert.assertEquals(27, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "end of input")); - } - } - - @Test - public void testExtraComma2OrderByInAnalyticFunction() { - try { - parser.parse("select a,b, f(c) my over (partition by b order by ts,) from xyz"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(53, QueryError.getPosition()); - } - } - - @Test - public void testExtraCommaOrderByInAnalyticFunction() { - try { - parser.parse("select a,b, f(c) my over (partition by b order by ,ts) from xyz"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(50, QueryError.getPosition()); - } - } - - @Test - public void testExtraCommaPartitionByInAnalyticFunction() { - try { - parser.parse("select a,b, f(c) my over (partition by b, order by ts) from xyz"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(48, QueryError.getPosition()); - } - } - - @Test - public void testInnerJoin() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select x from a a inner join b on b.x = a.x"); - Assert.assertNotNull(statement); - Assert.assertEquals("a", statement.getAlias().token); - Assert.assertEquals(2, statement.getJoinModels().size()); - Assert.assertEquals(QueryModel.JOIN_INNER, statement.getJoinModels().getQuick(1).getJoinType()); - Assert.assertEquals("b.xa.x=", TestUtils.toRpn(statement.getJoinModels().getQuick(1).getJoinCriteria())); - } - - @Test - public void testInvalidGroupBy1() { - try { - parser.parse("select x, y from tab sample by x,"); - Assert.fail("Expected exception"); - } catch (ParserException e) { - Assert.assertEquals(32, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Unexpected")); - } - } - - @Test - public void testInvalidGroupBy2() { - try { - parser.parse("select x, y from (tab sample by x,)"); - Assert.fail("Expected exception"); - } catch (ParserException e) { - Assert.assertEquals(33, QueryError.getPosition()); - } - } - - @Test - public void testInvalidGroupBy3() { - try { - parser.parse("select x, y from tab sample by x, order by y"); - Assert.fail("Expected exception"); - } catch (ParserException e) { - Assert.assertEquals(32, QueryError.getPosition()); - } - } - - @Test - public void testInvalidInnerJoin1() { - try { - parser.parse("select x from a a inner join b z"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertEquals(31, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "'on'")); - } - } - - @Test - public void testInvalidInnerJoin2() { - try { - parser.parse("select x from a a inner join b z on"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertEquals(33, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Expression")); - } - } - - @Test - public void testInvalidOrderBy1() { - try { - parser.parse("select x, y from tab order by x,"); - Assert.fail("Expected exception"); - } catch (ParserException e) { - Assert.assertEquals(31, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "end of input")); - } - } - - @Test - public void testInvalidOrderBy2() { - try { - parser.parse("select x, y from (tab order by x,)"); - Assert.fail("Expected exception"); - } catch (ParserException e) { - Assert.assertEquals(33, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Expression expected")); - } - } - - @Test - public void testInvalidOuterJoin1() { - try { - parser.parse("select x from a a outer join b z"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertEquals(31, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "'on'")); - } - } - - @Test - public void testInvalidOuterJoin2() { - try { - parser.parse("select x from a a outer join b z on"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertEquals(33, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Expression")); - } - } - - @Test - public void testInvalidSubQuery() { - try { - parser.parse("select x,y from (tab where x = 100) latest by x"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertEquals(36, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "latest")); - } - - } - - @Test - public void testJoin1() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select x, y from (select x from tab t2 latest by x where x > 100) t1 " + - "join tab2 xx2 on tab2.x = t1.x " + - "join tab3 on xx2.x > tab3.b " + - "join (select x,y from tab4 latest by z where a > b) x4 on x4.x = t1.y " + - "where y > 0"); - - Assert.assertEquals("t1", statement.getAlias().token); - Assert.assertEquals(4, statement.getJoinModels().size()); - Assert.assertNotNull(statement.getNestedModel()); - Assert.assertNull(statement.getJournalName()); - Assert.assertEquals("y0>", TestUtils.toRpn(statement.getWhereClause())); - Assert.assertEquals("tab", TestUtils.toRpn(statement.getNestedModel().getJournalName())); - Assert.assertEquals("t2", statement.getNestedModel().getAlias().token); - Assert.assertEquals(1, statement.getNestedModel().getJoinModels().size()); - - Assert.assertEquals("xx2", statement.getJoinModels().getQuick(1).getAlias().token); - Assert.assertNull(statement.getJoinModels().getQuick(2).getAlias()); - Assert.assertEquals("x4", statement.getJoinModels().getQuick(3).getAlias().token); - Assert.assertNotNull(statement.getJoinModels().getQuick(3).getNestedModel()); - - Assert.assertEquals("tab2", TestUtils.toRpn(statement.getJoinModels().getQuick(1).getJournalName())); - Assert.assertEquals("tab3", TestUtils.toRpn(statement.getJoinModels().getQuick(2).getJournalName())); - Assert.assertNull(statement.getJoinModels().getQuick(3).getJournalName()); - - Assert.assertEquals("tab2.xt1.x=", TestUtils.toRpn(statement.getJoinModels().getQuick(1).getJoinCriteria())); - Assert.assertEquals("xx2.xtab3.b>", TestUtils.toRpn(statement.getJoinModels().getQuick(2).getJoinCriteria())); - Assert.assertEquals("x4.xt1.y=", TestUtils.toRpn(statement.getJoinModels().getQuick(3).getJoinCriteria())); - - Assert.assertEquals("ab>", TestUtils.toRpn(statement.getJoinModels().getQuick(3).getNestedModel().getWhereClause())); - Assert.assertEquals("z", TestUtils.toRpn(statement.getJoinModels().getQuick(3).getNestedModel().getLatestBy())); - } - - @Test - public void testJoin2() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select x from ((tab join tab2 on tab.x=tab2.x) join tab3 on tab3.x = tab2.x)"); - Assert.assertNotNull(statement); - Assert.assertEquals(1, statement.getJoinModels().size()); - Assert.assertNotNull(statement.getNestedModel()); - Assert.assertEquals(2, statement.getNestedModel().getJoinModels().size()); - Assert.assertEquals("tab3", TestUtils.toRpn(statement.getNestedModel().getJoinModels().getQuick(1).getJournalName())); - Assert.assertEquals("tab3.xtab2.x=", TestUtils.toRpn(statement.getNestedModel().getJoinModels().getQuick(1).getJoinCriteria())); - Assert.assertEquals(0, statement.getNestedModel().getColumns().size()); - Assert.assertNotNull(statement.getNestedModel().getNestedModel()); - Assert.assertEquals("tab", TestUtils.toRpn(statement.getNestedModel().getNestedModel().getJournalName())); - Assert.assertEquals(2, statement.getNestedModel().getNestedModel().getJoinModels().size()); - Assert.assertEquals("tab2", TestUtils.toRpn(statement.getNestedModel().getNestedModel().getJoinModels().getQuick(1).getJournalName())); - Assert.assertEquals("tab.xtab2.x=", TestUtils.toRpn(statement.getNestedModel().getNestedModel().getJoinModels().getQuick(1).getJoinCriteria())); - } - - @Test - public void testLexerReset() { - - for (int i = 0; i < 10; i++) { - try { - parser.parse("select \n" + - "-- ltod(Date)\n" + - "count() \n" + - "-- from acc\n" + - "from acc(Date) sample by 1d\n" + - "-- where x = 10\n"); - Assert.fail(); - } catch (ParserException e) { - TestUtils.assertEquals("Unexpected token: Date", QueryError.getMessage()); - } - } - } - - @Test - public void testMissingWhere() { - try { - parser.parse("select id, x + 10, x from tab id ~ 'HBRO'"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertEquals(33, QueryError.getPosition()); - } - } - - @Test - public void testMixedFieldsSubQuery() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select x, y from (select z from tab t2 latest by x where x > 100) t1 " + - "where y > 0"); - Assert.assertNotNull(statement); - Assert.assertNotNull(statement.getNestedModel()); - Assert.assertNull(statement.getJournalName()); - Assert.assertEquals("t1", statement.getAlias().token); - - Assert.assertEquals("tab", TestUtils.toRpn(statement.getNestedModel().getJournalName())); - Assert.assertEquals("t2", statement.getNestedModel().getAlias().token); - Assert.assertEquals("x100>", TestUtils.toRpn(statement.getNestedModel().getWhereClause())); - Assert.assertEquals("x", TestUtils.toRpn(statement.getNestedModel().getLatestBy())); - Assert.assertEquals(2, statement.getColumns().size()); - Assert.assertEquals("x", statement.getColumns().get(0).getAst().token); - Assert.assertEquals("y", statement.getColumns().get(1).getAst().token); - Assert.assertEquals(1, statement.getNestedModel().getColumns().size()); - Assert.assertEquals("z", statement.getNestedModel().getColumns().get(0).getAst().token); - } - - @Test - public void testMostRecentWhereClause() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select a+b*c x, sum(z)+25 ohoh from zyzy latest by x where a in (x,y) and b = 10"); - - // journal name - Assert.assertEquals("zyzy", statement.getJournalName().token); - // columns - Assert.assertEquals(2, statement.getColumns().size()); - Assert.assertEquals("x", statement.getColumns().get(0).getAlias()); - Assert.assertEquals("ohoh", statement.getColumns().get(1).getAlias()); - // where - Assert.assertEquals("axyinb10=and", TestUtils.toRpn(statement.getWhereClause())); - // latest by - Assert.assertEquals("x", TestUtils.toRpn(statement.getLatestBy())); - } - - @Test - public void testMultipleExpressions() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select a+b*c x, sum(z)+25 ohoh from zyzy"); - Assert.assertNotNull(statement); - Assert.assertEquals("zyzy", statement.getJournalName().token); - Assert.assertEquals(2, statement.getColumns().size()); - Assert.assertEquals("x", statement.getColumns().get(0).getAlias()); - Assert.assertEquals("ohoh", statement.getColumns().get(1).getAlias()); - } - - @Test - public void testOneAnalyticColumn() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select a,b, f(c) over (partition by b order by ts) from xyz"); - Assert.assertEquals(3, statement.getColumns().size()); - - AnalyticColumn col = (AnalyticColumn) statement.getColumns().get(2); - - Assert.assertEquals(ExprNode.FUNCTION, col.getAst().type); - Assert.assertEquals(1, col.getPartitionBy().size()); - Assert.assertEquals("b", col.getPartitionBy().get(0).token); - - Assert.assertEquals(1, col.getOrderBy().size()); - Assert.assertEquals("ts", col.getOrderBy().get(0).token); - } - - @Test - public void testOptionalSelect() throws Exception { - QueryModel statement = (QueryModel) parser.parse("tab t2 latest by x where x > 100"); - Assert.assertNotNull(statement); - Assert.assertEquals("tab", TestUtils.toRpn(statement.getJournalName())); - Assert.assertEquals("t2", statement.getAlias().token); - Assert.assertEquals("x100>", TestUtils.toRpn(statement.getWhereClause())); - Assert.assertEquals(0, statement.getColumns().size()); - Assert.assertEquals("x", TestUtils.toRpn(statement.getLatestBy())); - } - - @Test - public void testOrderBy1() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select x,y from tab order by x,y,z"); - Assert.assertNotNull(statement); - Assert.assertEquals(3, statement.getOrderBy().size()); - Assert.assertEquals("x", TestUtils.toRpn(statement.getOrderBy().getQuick(0))); - Assert.assertEquals("y", TestUtils.toRpn(statement.getOrderBy().getQuick(1))); - Assert.assertEquals("z", TestUtils.toRpn(statement.getOrderBy().getQuick(2))); - } - - @Test - public void testOrderByExpression() { - try { - parser.parse("select x, y from tab order by x+y"); - Assert.fail("Expected exception"); - } catch (ParserException e) { - Assert.assertEquals(31, QueryError.getPosition()); - } - } - - @Test - public void testOuterJoin() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select x from a a outer join b on b.x = a.x"); - Assert.assertNotNull(statement); - Assert.assertEquals("a", statement.getAlias().token); - Assert.assertEquals(2, statement.getJoinModels().size()); - Assert.assertEquals(QueryModel.JOIN_OUTER, statement.getJoinModels().getQuick(1).getJoinType()); - Assert.assertEquals("b.xa.x=", TestUtils.toRpn(statement.getJoinModels().getQuick(1).getJoinCriteria())); - } - - @Test - public void testSampleBy1() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select x,y from tab sample by 2m"); - Assert.assertNotNull(statement); - Assert.assertEquals("2m", statement.getSampleBy().token); - } - - @Test - public void testSelectPlainColumns() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select a,b,c from t"); - - Assert.assertNotNull(statement); - Assert.assertEquals("t", statement.getJournalName().token); - Assert.assertEquals(3, statement.getColumns().size()); - for (int i = 0; i < 3; i++) { - Assert.assertEquals(ExprNode.LITERAL, statement.getColumns().get(i).getAst().type); - } - } - - @Test - public void testSelectSingleExpression() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select a+b*c x from t"); - Assert.assertNotNull(statement); - Assert.assertEquals(1, statement.getColumns().size()); - Assert.assertEquals("x", statement.getColumns().get(0).getAlias()); - Assert.assertEquals("+", statement.getColumns().get(0).getAst().token); - Assert.assertEquals("t", statement.getJournalName().token); - } - - @Test - public void testSimpleSubquery() throws Exception { - QueryModel statement = (QueryModel) parser.parse("(x) where x > 1"); - Assert.assertNotNull(statement.getNestedModel()); - Assert.assertEquals("x", statement.getNestedModel().getJournalName().token); - } - - @Test - public void testSingleJournalLimit() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select x x, y y from tab where x > z limit 100"); - // journal name - Assert.assertEquals("tab", statement.getJournalName().token); - // columns - Assert.assertEquals(2, statement.getColumns().size()); - Assert.assertEquals("x", statement.getColumns().get(0).getAlias()); - Assert.assertEquals("y", statement.getColumns().get(1).getAlias()); - // where - Assert.assertEquals("xz>", TestUtils.toRpn(statement.getWhereClause())); - // limit - Assert.assertEquals("100", TestUtils.toRpn(statement.getLimitLo())); - } - - @Test - public void testSingleJournalLimitLoHi() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select x x, y y from tab where x > z limit 100,200"); - // journal name - Assert.assertEquals("tab", statement.getJournalName().token); - // columns - Assert.assertEquals(2, statement.getColumns().size()); - Assert.assertEquals("x", statement.getColumns().get(0).getAlias()); - Assert.assertEquals("y", statement.getColumns().get(1).getAlias()); - // where - Assert.assertEquals("xz>", TestUtils.toRpn(statement.getWhereClause())); - // limit - Assert.assertEquals("100", TestUtils.toRpn(statement.getLimitLo())); - Assert.assertEquals("200", TestUtils.toRpn(statement.getLimitHi())); - } - - @Test - public void testSingleJournalLimitLoHiExtraToken() { - try { - parser.parse("select x x, y y from tab where x > z limit 100,200 b"); - } catch (ParserException e) { - Assert.assertEquals(51, QueryError.getPosition()); - } - } - - @Test - public void testSingleJournalNoWhereLimit() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select x x, y y from tab limit 100"); - // journal name - Assert.assertEquals("tab", statement.getJournalName().token); - // columns - Assert.assertEquals(2, statement.getColumns().size()); - Assert.assertEquals("x", statement.getColumns().get(0).getAlias()); - Assert.assertEquals("y", statement.getColumns().get(1).getAlias()); - // limit - Assert.assertEquals("100", TestUtils.toRpn(statement.getLimitLo())); - } - - @Test - public void testSubQuery() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select x, y from (select x from tab t2 latest by x where x > 100) t1 " + - "where y > 0"); - Assert.assertNotNull(statement); - Assert.assertNotNull(statement.getNestedModel()); - Assert.assertNull(statement.getJournalName()); - Assert.assertEquals("t1", statement.getAlias().token); - - Assert.assertEquals("tab", TestUtils.toRpn(statement.getNestedModel().getJournalName())); - Assert.assertEquals("t2", statement.getNestedModel().getAlias().token); - Assert.assertEquals("x100>", TestUtils.toRpn(statement.getNestedModel().getWhereClause())); - Assert.assertEquals("x", TestUtils.toRpn(statement.getNestedModel().getLatestBy())); - } - - @Test - public void testSubqueryLimitLoHi() throws Exception { - QueryModel statement = (QueryModel) parser.parse("(select x x, y y from tab where x > z limit 100,200) where x = y limit 150"); - // journal name - Assert.assertEquals("tab", statement.getNestedModel().getJournalName().token); - // columns - Assert.assertEquals(2, statement.getNestedModel().getColumns().size()); - Assert.assertEquals("x", statement.getNestedModel().getColumns().get(0).getAlias()); - Assert.assertEquals("y", statement.getNestedModel().getColumns().get(1).getAlias()); - // where - Assert.assertEquals("xz>", TestUtils.toRpn(statement.getNestedModel().getWhereClause())); - // limit - Assert.assertEquals("100", TestUtils.toRpn(statement.getNestedModel().getLimitLo())); - Assert.assertEquals("200", TestUtils.toRpn(statement.getNestedModel().getLimitHi())); - - Assert.assertEquals("150", TestUtils.toRpn(statement.getLimitLo())); - Assert.assertNull(statement.getLimitHi()); - } - - @Test - public void testTimestampOnJournal() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select x from a b timestamp(x) where x > y"); - Assert.assertEquals("x", statement.getTimestamp().token); - Assert.assertEquals("b", statement.getAlias().token); - Assert.assertNotNull(statement.getWhereClause()); - } - - @Test - public void testTimestampOnSubquery() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select x from (a b) timestamp(x) where x > y"); - Assert.assertEquals("x", statement.getTimestamp().token); - Assert.assertNotNull(statement.getNestedModel()); - Assert.assertNotNull(statement.getWhereClause()); - } - - @Test - public void testTooManyColumnsEdgeInOrderBy() throws Exception { - StringBuilder b = new StringBuilder(); - b.append("x order by "); - for (int i = 0; i < QueryParser.MAX_ORDER_BY_COLUMNS - 1; i++) { - if (i > 0) { - b.append(','); - } - b.append('f').append(i); - } - QueryModel st = (QueryModel) parser.parse(b); - Assert.assertEquals(QueryParser.MAX_ORDER_BY_COLUMNS - 1, st.getOrderBy().size()); - } - - @Test - public void testTooManyColumnsInOrderBy() { - StringBuilder b = new StringBuilder(); - b.append("x order by "); - for (int i = 0; i < QueryParser.MAX_ORDER_BY_COLUMNS; i++) { - if (i > 0) { - b.append(','); - } - b.append('f').append(i); - } - try { - parser.parse(b); - } catch (ParserException e) { - TestUtils.assertEquals("Too many columns", QueryError.getMessage()); - } - } - - @Test - public void testTwoAnalyticColumns() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select a,b, f(c) my over (partition by b order by ts), d(c) over() from xyz"); - Assert.assertEquals(4, statement.getColumns().size()); - - AnalyticColumn col = (AnalyticColumn) statement.getColumns().get(2); - Assert.assertEquals("my", col.getAlias()); - Assert.assertEquals(ExprNode.FUNCTION, col.getAst().type); - Assert.assertEquals(1, col.getPartitionBy().size()); - Assert.assertEquals("b", col.getPartitionBy().get(0).token); - Assert.assertEquals(1, col.getOrderBy().size()); - Assert.assertEquals("ts", col.getOrderBy().get(0).token); - - col = (AnalyticColumn) statement.getColumns().get(3); - Assert.assertEquals("d", col.getAst().token); - Assert.assertNull(col.getAlias()); - Assert.assertEquals(0, col.getPartitionBy().size()); - Assert.assertEquals(0, col.getOrderBy().size()); - } - - @Test - public void testUnbalancedBracketInSubQuery() { - try { - parser.parse("select x from (tab where x > 10 t1"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertEquals(32, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "expected")); - } - } - - @Test - public void testUnderTerminatedOver() { - try { - parser.parse("select a,b, f(c) my over (partition by b order by ts from xyz"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(53, QueryError.getPosition()); - } - } - - @Test - public void testUnderTerminatedOver2() { - try { - parser.parse("select a,b, f(c) my over (partition by b order by ts"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(50, QueryError.getPosition()); - } - } - - @Test - public void testUnexpectedTokenInAnalyticFunction() { - try { - parser.parse("select a,b, f(c) my over (by b order by ts) from xyz"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(26, QueryError.getPosition()); - } - } - - @Test - public void testWhereClause() throws Exception { - QueryModel statement = (QueryModel) parser.parse("select a+b*c x, sum(z)+25 ohoh from zyzy where a in (x,y) and b = 10"); - // journal name - Assert.assertEquals("zyzy", statement.getJournalName().token); - // columns - Assert.assertEquals(2, statement.getColumns().size()); - Assert.assertEquals("x", statement.getColumns().get(0).getAlias()); - Assert.assertEquals("ohoh", statement.getColumns().get(1).getAlias()); - // where - Assert.assertEquals("axyinb10=and", TestUtils.toRpn(statement.getWhereClause())); - } -} diff --git a/core/src/test/java/com/questdb/parser/sql/ResamplingTest.java b/core/src/test/java/com/questdb/parser/sql/ResamplingTest.java deleted file mode 100644 index bdb7e856a..000000000 --- a/core/src/test/java/com/questdb/parser/sql/ResamplingTest.java +++ /dev/null @@ -1,323 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.parser.sql; - -import com.questdb.ex.ParserException; -import com.questdb.std.Rnd; -import com.questdb.std.time.DateFormatUtils; -import com.questdb.store.JournalEntryWriter; -import com.questdb.store.JournalWriter; -import com.questdb.store.factory.configuration.JournalStructure; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -public class ResamplingTest extends AbstractOptimiserTest { - - @BeforeClass - public static void setUp() throws Exception { - int recordCount = 10000; - int employeeCount = 10; - try (JournalWriter orders = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("orders"). - $int("orderId"). - $int("customerId"). - $int("productId"). - $str("employeeId"). - $date("orderDate"). - $int("quantity"). - $double("price"). - $float("rate"). - recordCountHint(recordCount). - $() - )) { - - Rnd rnd = new Rnd(); - - String[] employees = new String[employeeCount]; - for (int i = 0; i < employees.length; i++) { - employees[i] = rnd.nextString(9); - } - - long timestamp = DateFormatUtils.parseDateTime("2014-05-04T10:30:00.000Z"); - int tsIncrement = 10000; - - int orderId = 0; - for (int i = 0; i < recordCount; i++) { - JournalEntryWriter w = orders.entryWriter(); - w.putInt(0, ++orderId); - w.putInt(1, rnd.nextPositiveInt() % 500); - w.putInt(2, rnd.nextPositiveInt() % 200); - w.putStr(3, employees[rnd.nextPositiveInt() % employeeCount]); - w.putDate(4, timestamp += tsIncrement); - w.putInt(5, rnd.nextPositiveInt()); - w.putDouble(6, rnd.nextDouble()); - w.putFloat(7, rnd.nextFloat()); - w.append(); - } - orders.commit(); - } - - try (JournalWriter orders2 = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("orders2"). - $int("orderId"). - $int("customerId"). - $int("productId"). - $str("employeeId"). - $date("orderDate"). - $int("quantity"). - $double("price"). - $float("rate"). - $date("basketDate"). - recordCountHint(recordCount). - $() - )) { - - Rnd rnd = new Rnd(); - - String[] employees = new String[employeeCount]; - for (int i = 0; i < employees.length; i++) { - employees[i] = rnd.nextString(9); - } - - long timestamp = DateFormatUtils.parseDateTime("2014-05-04T10:30:00.000Z"); - long timestamp2 = DateFormatUtils.parseDateTime("2014-05-03T00:15:00.000Z"); - int tsIncrement = 10000; - - int orderId = 0; - for (int i = 0; i < recordCount; i++) { - JournalEntryWriter w = orders2.entryWriter(); - w.putInt(0, ++orderId); - w.putInt(1, rnd.nextPositiveInt() % 500); - w.putInt(2, rnd.nextPositiveInt() % 200); - w.putStr(3, employees[rnd.nextPositiveInt() % employeeCount]); - w.putDate(4, timestamp += tsIncrement); - w.putInt(5, rnd.nextPositiveInt()); - w.putDouble(6, rnd.nextDouble()); - w.putFloat(7, rnd.nextFloat()); - w.putDate(8, timestamp2 + tsIncrement); - w.append(); - } - orders2.commit(); - } - - try (JournalWriter orders2 = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("orders4"). - $int("orderId"). - $int("customerId"). - $int("productId"). - $sym("employeeId"). - $date("orderDate"). - $int("quantity"). - $double("price"). - $float("rate"). - $ts("basketDate"). - recordCountHint(recordCount). - $() - )) { - - Rnd rnd = new Rnd(); - - String[] employees = new String[employeeCount]; - for (int i = 0; i < employees.length; i++) { - employees[i] = rnd.nextString(9); - } - - long timestamp = DateFormatUtils.parseDateTime("2014-05-04T10:30:00.000Z"); - long timestamp2 = DateFormatUtils.parseDateTime("2014-05-03T00:15:00.000Z"); - int tsIncrement = 10000; - - int orderId = 0; - for (int i = 0; i < recordCount; i++) { - JournalEntryWriter w = orders2.entryWriter(); - w.putInt(0, ++orderId); - w.putInt(1, rnd.nextPositiveInt() % 500); - w.putInt(2, rnd.nextPositiveInt() % 200); - w.putSym(3, employees[rnd.nextPositiveInt() % employeeCount]); - w.putDate(4, timestamp += tsIncrement); - w.putInt(5, rnd.nextPositiveInt()); - w.putDouble(6, rnd.nextDouble()); - w.putFloat(7, rnd.nextFloat()); - w.putDate(8, timestamp2 + tsIncrement); - w.append(); - } - orders2.commit(); - } - - JournalWriter orders3 = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("orders3"). - $int("orderId"). - $int("customerId"). - $int("productId"). - $str("employeeId"). - $int("quantity"). - $double("price"). - $float("rate"). - recordCountHint(recordCount). - $() - ); - orders3.close(); - } - - @Test - public void testResampling2() throws Exception { - assertThat("2014-05-04T08:00:00.000Z\t-18.041874103485\n" + - "2014-05-04T16:00:00.000Z\t-12.148285354848\n" + - "2014-05-05T00:00:00.000Z\t-10.773253435499\n" + - "2014-05-05T08:00:00.000Z\t0.750778769143\n", - "select orderDate, vwap(price, quantity) from orders timestamp (orderDate) sample by 8h"); - } - - @Test - public void testResamplingAmbiguousTimestamp() throws Exception { - try { - assertThat("", "select orderDate, employeeId, sum(price*quantity)/lsum(quantity), vwap(price, quantity) sum from orders2 sample by 1d"); - } catch (ParserException e) { - Assert.assertEquals(97, QueryError.getPosition()); - } - } - - @Test - public void testResamplingAutoTimestamp() throws Exception { - assertThat("2014-05-04T00:00:00.000Z\tTGPGWFFYU\t-63.253453401381\t-63.253453401381\n" + - "2014-05-04T00:00:00.000Z\tDEYYQEHBH\t17.232482911526\t17.232482911526\n" + - "2014-05-04T00:00:00.000Z\tSRYRFBVTM\t-10.581027815832\t-10.581027815832\n" + - "2014-05-04T00:00:00.000Z\tGZSXUXIBB\t1.191841183028\t1.191841183028\n" + - "2014-05-04T00:00:00.000Z\tUEDRQQULO\t-25.284387331977\t-25.284387331977\n" + - "2014-05-04T00:00:00.000Z\tFOWLPDXYS\t-21.110275361914\t-21.110275361914\n" + - "2014-05-04T00:00:00.000Z\tFJGETJRSZ\t-12.327370360108\t-12.327370360108\n" + - "2014-05-04T00:00:00.000Z\tBEOUOJSHR\t3.586645530510\t3.586645530510\n" + - "2014-05-04T00:00:00.000Z\tYRXPEHNRX\t-10.131327938006\t-10.131327938006\n" + - "2014-05-04T00:00:00.000Z\tVTJWCPSWH\t-24.329569665466\t-24.329569665466\n" + - "2014-05-05T00:00:00.000Z\tDEYYQEHBH\t-30.963486961448\t-30.963486961448\n" + - "2014-05-05T00:00:00.000Z\tSRYRFBVTM\t13.422138958032\t13.422138958032\n" + - "2014-05-05T00:00:00.000Z\tVTJWCPSWH\t0.595780540587\t0.595780540587\n" + - "2014-05-05T00:00:00.000Z\tBEOUOJSHR\t-31.682205368795\t-31.682205368795\n" + - "2014-05-05T00:00:00.000Z\tFJGETJRSZ\t-31.906856870748\t-31.906856870748\n" + - "2014-05-05T00:00:00.000Z\tGZSXUXIBB\t7.870801180456\t7.870801180456\n" + - "2014-05-05T00:00:00.000Z\tFOWLPDXYS\t-11.860556414848\t-11.860556414848\n" + - "2014-05-05T00:00:00.000Z\tYRXPEHNRX\t-8.573401980346\t-8.573401980346\n" + - "2014-05-05T00:00:00.000Z\tUEDRQQULO\t16.987375521363\t16.987375521363\n" + - "2014-05-05T00:00:00.000Z\tTGPGWFFYU\t17.260132823173\t17.260132823173\n", - "select orderDate, employeeId, sum(price*quantity)/lsum(quantity), vwap(price, quantity) sum from orders timestamp (orderDate) sample by 1d"); - } - - @Test - public void testResamplingAvg() throws Exception { - assertThat("2014-05-04T00:00:00.000Z\tTGPGWFFYU\t-41.304426677644\t-41.304426677644\n" + - "2014-05-04T00:00:00.000Z\tDEYYQEHBH\t7.372452128965\t7.372452128965\n" + - "2014-05-04T00:00:00.000Z\tSRYRFBVTM\t-12.203630788820\t-12.203630788820\n" + - "2014-05-04T00:00:00.000Z\tGZSXUXIBB\t4.115922051504\t4.115922051504\n" + - "2014-05-04T00:00:00.000Z\tUEDRQQULO\t-24.365014628709\t-24.365014628709\n" + - "2014-05-04T00:00:00.000Z\tFOWLPDXYS\t-29.996629348333\t-29.996629348333\n" + - "2014-05-04T00:00:00.000Z\tFJGETJRSZ\t-4.318969422717\t-4.318969422717\n" + - "2014-05-04T00:00:00.000Z\tBEOUOJSHR\t7.502717136654\t7.502717136654\n" + - "2014-05-04T00:00:00.000Z\tYRXPEHNRX\t0.601852660663\t0.601852660663\n" + - "2014-05-04T00:00:00.000Z\tVTJWCPSWH\t-9.734968411374\t-9.734968411374\n" + - "2014-05-05T00:00:00.000Z\tDEYYQEHBH\t-16.135037390878\t-16.135037390878\n" + - "2014-05-05T00:00:00.000Z\tSRYRFBVTM\t14.227762047291\t14.227762047291\n" + - "2014-05-05T00:00:00.000Z\tVTJWCPSWH\t-21.138005372460\t-21.138005372460\n" + - "2014-05-05T00:00:00.000Z\tBEOUOJSHR\t-20.797434613016\t-20.797434613016\n" + - "2014-05-05T00:00:00.000Z\tFJGETJRSZ\t-5.417172028476\t-5.417172028476\n" + - "2014-05-05T00:00:00.000Z\tGZSXUXIBB\t3.389333554052\t3.389333554052\n" + - "2014-05-05T00:00:00.000Z\tFOWLPDXYS\t-21.249544800002\t-21.249544800002\n" + - "2014-05-05T00:00:00.000Z\tYRXPEHNRX\t-12.965791501497\t-12.965791501497\n" + - "2014-05-05T00:00:00.000Z\tUEDRQQULO\t12.717803509177\t12.717803509177\n" + - "2014-05-05T00:00:00.000Z\tTGPGWFFYU\t-4.258237623021\t-4.258237623021\n", - "select orderDate, employeeId, sum(price)/count(), avg(price) sum from orders2 timestamp(orderDate) sample by 1d"); - } - - @Test - public void testResamplingBySymbol() throws Exception { - assertSymbol("select employeeId, vwap(price, quantity) sum from orders4 sample by 1d", 0); - } - - @Test - public void testResamplingExplicitTimestamp() throws Exception { - assertThat("2014-05-04T00:00:00.000Z\tTGPGWFFYU\t-63.253453401381\t-63.253453401381\n" + - "2014-05-04T00:00:00.000Z\tDEYYQEHBH\t17.232482911526\t17.232482911526\n" + - "2014-05-04T00:00:00.000Z\tSRYRFBVTM\t-10.581027815832\t-10.581027815832\n" + - "2014-05-04T00:00:00.000Z\tGZSXUXIBB\t1.191841183028\t1.191841183028\n" + - "2014-05-04T00:00:00.000Z\tUEDRQQULO\t-25.284387331977\t-25.284387331977\n" + - "2014-05-04T00:00:00.000Z\tFOWLPDXYS\t-21.110275361914\t-21.110275361914\n" + - "2014-05-04T00:00:00.000Z\tFJGETJRSZ\t-12.327370360108\t-12.327370360108\n" + - "2014-05-04T00:00:00.000Z\tBEOUOJSHR\t3.586645530510\t3.586645530510\n" + - "2014-05-04T00:00:00.000Z\tYRXPEHNRX\t-10.131327938006\t-10.131327938006\n" + - "2014-05-04T00:00:00.000Z\tVTJWCPSWH\t-24.329569665466\t-24.329569665466\n" + - "2014-05-05T00:00:00.000Z\tDEYYQEHBH\t-30.963486961448\t-30.963486961448\n" + - "2014-05-05T00:00:00.000Z\tSRYRFBVTM\t13.422138958032\t13.422138958032\n" + - "2014-05-05T00:00:00.000Z\tVTJWCPSWH\t0.595780540587\t0.595780540587\n" + - "2014-05-05T00:00:00.000Z\tBEOUOJSHR\t-31.682205368795\t-31.682205368795\n" + - "2014-05-05T00:00:00.000Z\tFJGETJRSZ\t-31.906856870748\t-31.906856870748\n" + - "2014-05-05T00:00:00.000Z\tGZSXUXIBB\t7.870801180456\t7.870801180456\n" + - "2014-05-05T00:00:00.000Z\tFOWLPDXYS\t-11.860556414848\t-11.860556414848\n" + - "2014-05-05T00:00:00.000Z\tYRXPEHNRX\t-8.573401980346\t-8.573401980346\n" + - "2014-05-05T00:00:00.000Z\tUEDRQQULO\t16.987375521363\t16.987375521363\n" + - "2014-05-05T00:00:00.000Z\tTGPGWFFYU\t17.260132823173\t17.260132823173\n", - "select orderDate, employeeId, sum(price*quantity)/lsum(quantity), vwap(price, quantity) sum from orders2 timestamp(orderDate) sample by 1d"); - } - - @Test - public void testResamplingExplicitTimestampAsFunc() { - try { - expectFailure("select orderDate, employeeId, sum(price*quantity)/lsum(quantity), vwap(price, quantity) sum from orders2 timestamp(orderDate()) sample by 1d"); - } catch (ParserException e) { - Assert.assertEquals(124, QueryError.getPosition()); - } - } - - @Test - public void testResamplingNoTimestamp() throws Exception { - try { - assertThat("", "select employeeId, sum(price*quantity)/lsum(quantity), vwap(price, quantity) sum from orders3 sample by 1d"); - } catch (ParserException e) { - Assert.assertEquals(86, QueryError.getPosition()); - } - } - - @Test - public void testResamplingVariance() throws Exception { - assertThat("2014-05-04T00:00:00.000Z\tTGPGWFFYU\t-41.304426677644\t-41.304426677644\t172487.097492439040\n" + - "2014-05-04T00:00:00.000Z\tDEYYQEHBH\t7.372452128965\t7.372452128965\t148077.744860982304\n" + - "2014-05-04T00:00:00.000Z\tSRYRFBVTM\t-12.203630788820\t-12.203630788820\t152042.353099020448\n" + - "2014-05-04T00:00:00.000Z\tGZSXUXIBB\t4.115922051504\t4.115922051504\t170953.021239990592\n" + - "2014-05-04T00:00:00.000Z\tUEDRQQULO\t-24.365014628709\t-24.365014628709\t151426.976280038816\n" + - "2014-05-04T00:00:00.000Z\tFOWLPDXYS\t-29.996629348333\t-29.996629348333\t138923.565569592720\n" + - "2014-05-04T00:00:00.000Z\tFJGETJRSZ\t-4.318969422717\t-4.318969422717\t152689.615652833824\n" + - "2014-05-04T00:00:00.000Z\tBEOUOJSHR\t7.502717136654\t7.502717136654\t151309.114422499264\n" + - "2014-05-04T00:00:00.000Z\tYRXPEHNRX\t0.601852660663\t0.601852660663\t164631.084324245504\n" + - "2014-05-04T00:00:00.000Z\tVTJWCPSWH\t-9.734968411374\t-9.734968411374\t163121.713218006048\n" + - "2014-05-05T00:00:00.000Z\tDEYYQEHBH\t-16.135037390878\t-16.135037390878\t157609.841614984256\n" + - "2014-05-05T00:00:00.000Z\tSRYRFBVTM\t14.227762047291\t14.227762047291\t158581.383371555040\n" + - "2014-05-05T00:00:00.000Z\tVTJWCPSWH\t-21.138005372460\t-21.138005372460\t159404.705680565472\n" + - "2014-05-05T00:00:00.000Z\tBEOUOJSHR\t-20.797434613016\t-20.797434613016\t168784.531816107744\n" + - "2014-05-05T00:00:00.000Z\tFJGETJRSZ\t-5.417172028476\t-5.417172028476\t159768.386499879616\n" + - "2014-05-05T00:00:00.000Z\tGZSXUXIBB\t3.389333554052\t3.389333554052\t149853.540099657824\n" + - "2014-05-05T00:00:00.000Z\tFOWLPDXYS\t-21.249544800002\t-21.249544800002\t153228.686138200064\n" + - "2014-05-05T00:00:00.000Z\tYRXPEHNRX\t-12.965791501497\t-12.965791501497\t174696.469778044480\n" + - "2014-05-05T00:00:00.000Z\tUEDRQQULO\t12.717803509177\t12.717803509177\t167741.670910154976\n" + - "2014-05-05T00:00:00.000Z\tTGPGWFFYU\t-4.258237623021\t-4.258237623021\t159549.212283462016\n", - "select orderDate, employeeId, sum(price)/count(), avg(price), var(price) sum from orders2 timestamp(orderDate) sample by 1d"); - } -} diff --git a/core/src/test/java/com/questdb/parser/sql/RpnBuilder.java b/core/src/test/java/com/questdb/parser/sql/RpnBuilder.java deleted file mode 100644 index 306440de6..000000000 --- a/core/src/test/java/com/questdb/parser/sql/RpnBuilder.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.parser.sql; - -import com.questdb.parser.sql.model.ExprNode; -import com.questdb.std.str.StringSink; - -public class RpnBuilder implements ExprListener { - private final StringSink sink = new StringSink(); - - @Override - public void onNode(ExprNode node) { - sink.put(node.token); - } - - public void reset() { - sink.clear(); - } - - public final CharSequence rpn() { - return sink; - } -} diff --git a/core/src/test/java/com/questdb/parser/sql/SignatureTest.java b/core/src/test/java/com/questdb/parser/sql/SignatureTest.java deleted file mode 100644 index 054ead8f5..000000000 --- a/core/src/test/java/com/questdb/parser/sql/SignatureTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.parser.sql; - -import com.questdb.ql.ops.Signature; -import com.questdb.std.ObjObjHashMap; -import com.questdb.store.ColumnType; -import org.junit.Assert; -import org.junit.Test; - -import java.util.Arrays; - -public class SignatureTest { - @Test - public void testMapBehaviour() { - ObjObjHashMap sigs = new ObjObjHashMap() {{ - - put(new Signature().setName("-").setParamCount(1).paramType(0, ColumnType.INT, false), "sig1"); - // overload - put(new Signature().setName("-").setParamCount(1).paramType(0, ColumnType.DOUBLE, false), "sig2"); - // overload 2 - put(new Signature().setName("-").setParamCount(2).paramType(0, ColumnType.INT, false).paramType(1, ColumnType.INT, false), "sig3"); - // dupe - put(new Signature().setName("-").setParamCount(1).paramType(0, ColumnType.INT, false), "sig4"); - put(new Signature().setName("-").setParamCount(1).paramType(0, ColumnType.INT, true), "sig5"); - }}; - - Assert.assertEquals(4, sigs.size()); - String[] expected = new String[]{"sig2", "sig3", "sig4", "sig5"}; - String[] actual = new String[sigs.size()]; - - int k = 0; - for (ObjObjHashMap.Entry e : sigs) { - actual[k++] = e.value; - } - - Arrays.sort(actual); - Assert.assertArrayEquals(expected, actual); - } -} diff --git a/core/src/test/java/com/questdb/parser/sql/SingleJournalQueryTest.java b/core/src/test/java/com/questdb/parser/sql/SingleJournalQueryTest.java deleted file mode 100644 index 4a258e8e7..000000000 --- a/core/src/test/java/com/questdb/parser/sql/SingleJournalQueryTest.java +++ /dev/null @@ -1,4441 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.parser.sql; - -import com.questdb.ex.ParserException; -import com.questdb.ex.UndefinedParameterException; -import com.questdb.model.Quote; -import com.questdb.ql.RecordSource; -import com.questdb.std.*; -import com.questdb.std.ex.JournalException; -import com.questdb.std.str.StringSink; -import com.questdb.std.time.DateFormatUtils; -import com.questdb.std.time.Dates; -import com.questdb.store.JournalEntryWriter; -import com.questdb.store.JournalRuntimeException; -import com.questdb.store.JournalWriter; -import com.questdb.store.factory.configuration.JournalStructure; -import com.questdb.test.tools.AbstractTest; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Test; - -import java.io.IOException; - -public class SingleJournalQueryTest extends AbstractTest { - - @Test - public void testAddDoubleAndIntConst() throws Exception { - createTabWithNaNs(); - final String expected = "KIWIHBROKZKUTIQ\t10.000003940208\t0.000003940208\n" + - "KIWIHBROKZKUTIQ\t10.000241351052\t0.000241351052\n" + - "KIWIHBROKZKUTIQ\t10.000000436641\t0.000000436641\n" + - "KIWIHBROKZKUTIQ\t10.000000004652\t0.000000004652\n" + - "KIWIHBROKZKUTIQ\t10.000000923917\t0.000000923917\n" + - "KIWIHBROKZKUTIQ\t10.000029283142\t0.000029283142\n" + - "KIWIHBROKZKUTIQ\t10.000274364982\t0.000274364982\n" + - "KIWIHBROKZKUTIQ\t10.001289066189\t0.001289066189\n" + - "KIWIHBROKZKUTIQ\t10.000000006491\t0.000000006491\n" + - "KIWIHBROKZKUTIQ\t10.000000005004\t0.000000005004\n" + - "KIWIHBROKZKUTIQ\t10.002742654004\t0.002742654004\n" + - "KIWIHBROKZKUTIQ\t10.000000019003\t0.000000019003\n" + - "KIWIHBROKZKUTIQ\t10.000001821820\t0.000001821820\n" + - "KIWIHBROKZKUTIQ\t10.002185028803\t0.002185028803\n" + - "KIWIHBROKZKUTIQ\t10.000000106593\t0.000000106593\n" + - "KIWIHBROKZKUTIQ\t10.004314885940\t0.004314885940\n" + - "KIWIHBROKZKUTIQ\t10.000000902759\t0.000000902759\n" + - "KIWIHBROKZKUTIQ\t10.758562207222\t0.758562207222\n" + - "KIWIHBROKZKUTIQ\t10.000022764745\t0.000022764745\n" + - "KIWIHBROKZKUTIQ\t10.000000003658\t0.000000003658\n" + - "KIWIHBROKZKUTIQ\t10.000409294655\t0.000409294655\n" + - "KIWIHBROKZKUTIQ\t10.000000000000\t0.000000000000\n" + - "KIWIHBROKZKUTIQ\t10.000000028044\t0.000000028044\n" + - "KIWIHBROKZKUTIQ\t10.000000017631\t0.000000017631\n" + - "KIWIHBROKZKUTIQ\t10.001603563025\t0.001603563025\n" + - "KIWIHBROKZKUTIQ\t10.149615820497\t0.149615820497\n" + - "KIWIHBROKZKUTIQ\t10.000000073341\t0.000000073341\n" + - "KIWIHBROKZKUTIQ\t10.141415018588\t0.141415018588\n" + - "KIWIHBROKZKUTIQ\t10.000002008458\t0.000002008458\n" + - "KIWIHBROKZKUTIQ\t10.000013604858\t0.000013604858\n" + - "KIWIHBROKZKUTIQ\t10.000000313020\t0.000000313020\n" + - "KIWIHBROKZKUTIQ\t10.098757246509\t0.098757246509\n" + - "KIWIHBROKZKUTIQ\t10.220758058131\t0.220758058131\n"; - - assertThat(expected, "select id, x + 10, x from tab where x >= 0 and x <= 1 and id ~ 'HBRO'"); - } - - @Test - public void testAddInt() throws Exception { - createTabWithNaNs(); - final String expected = "CLLERSMKRZUDJGN\t-416\t-436\n" + - "CLLERSMKRZUDJGN\t-434\t-454\n" + - "CLLERSMKRZUDJGN\t-183\t-203\n" + - "CLLERSMKRZUDJGN\t-280\t-300\n" + - "CLLERSMKRZUDJGN\t-194\t-214\n" + - "CLLERSMKRZUDJGN\t-419\t-439\n" + - "CLLERSMKRZUDJGN\t-410\t-430\n" + - "CLLERSMKRZUDJGN\t-247\t-267\n" + - "CLLERSMKRZUDJGN\t-406\t-426\n" + - "CLLERSMKRZUDJGN\t-389\t-409\n" + - "CLLERSMKRZUDJGN\t-371\t-391\n" + - "CLLERSMKRZUDJGN\t-188\t-208\n" + - "CLLERSMKRZUDJGN\t-316\t-336\n" + - "CLLERSMKRZUDJGN\t-291\t-311\n" + - "CLLERSMKRZUDJGN\t-290\t-310\n" + - "CLLERSMKRZUDJGN\t-478\t-498\n" + - "CLLERSMKRZUDJGN\t-369\t-389\n" + - "CLLERSMKRZUDJGN\t-335\t-355\n" + - "CLLERSMKRZUDJGN\t-407\t-427\n" + - "CLLERSMKRZUDJGN\t-339\t-359\n" + - "CLLERSMKRZUDJGN\t-254\t-274\n" + - "CLLERSMKRZUDJGN\t-464\t-484\n" + - "CLLERSMKRZUDJGN\t-196\t-216\n" + - "CLLERSMKRZUDJGN\t-282\t-302\n" + - "CLLERSMKRZUDJGN\t-357\t-377\n" + - "CLLERSMKRZUDJGN\t-337\t-357\n" + - "CLLERSMKRZUDJGN\t-352\t-372\n" + - "CLLERSMKRZUDJGN\t-436\t-456\n"; - - assertThat(expected, "select id, w + 20, w from tab where id ~ 'LLER' and w < -200"); - - final String expected2 = "CLLERSMKRZUDJGN\t17.552673339844\t-436\t433.552673339844\n" + - "CLLERSMKRZUDJGN\t261.817749023438\t-454\t695.817749023438\n" + - "CLLERSMKRZUDJGN\t219.212882995605\t-203\t402.212882995606\n" + - "CLLERSMKRZUDJGN\t230.619750976563\t-300\t510.619750976563\n" + - "CLLERSMKRZUDJGN\t-193.999999997492\t-214\t0.000000002508\n" + - "CLLERSMKRZUDJGN\t93.000000000000\t-439\t512.000000000000\n" + - "CLLERSMKRZUDJGN\t-409.025098264217\t-430\t0.974901735783\n" + - "CLLERSMKRZUDJGN\t-435.000000000000\t-267\t-188.000000000000\n" + - "CLLERSMKRZUDJGN\t-405.874753475189\t-426\t0.125246524811\n" + - "CLLERSMKRZUDJGN\t379.000000000000\t-409\t768.000000000000\n" + - "CLLERSMKRZUDJGN\t-370.985364873894\t-391\t0.014635126106\n" + - "CLLERSMKRZUDJGN\t-187.999999994615\t-208\t0.000000005385\n" + - "CLLERSMKRZUDJGN\t-246.611997604370\t-336\t69.388002395630\n" + - "CLLERSMKRZUDJGN\t-843.457031250000\t-311\t-552.457031250000\n" + - "CLLERSMKRZUDJGN\t-964.750000000000\t-310\t-674.750000000000\n" + - "CLLERSMKRZUDJGN\t-477.999999974712\t-498\t0.000000025288\n" + - "CLLERSMKRZUDJGN\t-368.993329117890\t-389\t0.006670882110\n" + - "CLLERSMKRZUDJGN\t-290.455463409424\t-355\t44.544536590576\n" + - "CLLERSMKRZUDJGN\t-384.206546306610\t-427\t22.793453693390\n" + - "CLLERSMKRZUDJGN\t-338.969897582196\t-359\t0.030102417804\n" + - "CLLERSMKRZUDJGN\t-116.773674011230\t-274\t137.226325988770\n" + - "CLLERSMKRZUDJGN\t-976.000000000000\t-484\t-512.000000000000\n" + - "CLLERSMKRZUDJGN\t-189.609647154808\t-216\t6.390352845192\n" + - "CLLERSMKRZUDJGN\t-881.211730957031\t-302\t-599.211730957031\n" + - "CLLERSMKRZUDJGN\t-335.414469718933\t-377\t21.585530281067\n" + - "CLLERSMKRZUDJGN\t-336.999599984134\t-357\t0.000400015866\n" + - "CLLERSMKRZUDJGN\t-351.999999861198\t-372\t0.000000138802\n" + - "CLLERSMKRZUDJGN\t255.250000000000\t-456\t691.250000000000\n"; - - assertThat(expected2, "select id, x+(w + 20), w, x from tab where id ~ 'LLER' and w < -200"); - final String expected3 = "CLLERSMKRZUDJGN\t-343\t-436\t73\n" + - "CLLERSMKRZUDJGN\t-267\t-454\t167\n" + - "CLLERSMKRZUDJGN\t112\t-203\t295\n" + - "CLLERSMKRZUDJGN\t-6\t-300\t274\n" + - "CLLERSMKRZUDJGN\t-164\t-214\t30\n" + - "CLLERSMKRZUDJGN\t-709\t-439\t-290\n" + - "CLLERSMKRZUDJGN\t-408\t-430\t2\n" + - "CLLERSMKRZUDJGN\t-716\t-267\t-469\n" + - "CLLERSMKRZUDJGN\t-636\t-426\t-230\n" + - "CLLERSMKRZUDJGN\tNaN\t-409\tNaN\n" + - "CLLERSMKRZUDJGN\t-614\t-391\t-243\n" + - "CLLERSMKRZUDJGN\tNaN\t-208\tNaN\n" + - "CLLERSMKRZUDJGN\t-369\t-336\t-53\n" + - "CLLERSMKRZUDJGN\t-593\t-311\t-302\n" + - "CLLERSMKRZUDJGN\t-227\t-310\t63\n" + - "CLLERSMKRZUDJGN\t-51\t-498\t427\n" + - "CLLERSMKRZUDJGN\t-253\t-389\t116\n" + - "CLLERSMKRZUDJGN\t-557\t-355\t-222\n" + - "CLLERSMKRZUDJGN\t-83\t-427\t324\n" + - "CLLERSMKRZUDJGN\tNaN\t-359\tNaN\n" + - "CLLERSMKRZUDJGN\t-189\t-274\t65\n" + - "CLLERSMKRZUDJGN\tNaN\t-484\tNaN\n" + - "CLLERSMKRZUDJGN\t273\t-216\t469\n" + - "CLLERSMKRZUDJGN\t-92\t-302\t190\n" + - "CLLERSMKRZUDJGN\tNaN\t-377\tNaN\n" + - "CLLERSMKRZUDJGN\t-614\t-357\t-277\n" + - "CLLERSMKRZUDJGN\t121\t-372\t473\n" + - "CLLERSMKRZUDJGN\t-340\t-456\t96\n"; - - assertThat(expected3, "select id, z+(w + 20), w, z from tab where id ~ 'LLER' and w < -200"); - } - - @Test - public void testAddLong() throws Exception { - createTabWithNaNs(); - final String expected = "BROMNXKUIZULIGY\t506\t256\n" + - "BROMNXKUIZULIGY\t652\t402\n" + - "BROMNXKUIZULIGY\t668\t418\n" + - "BROMNXKUIZULIGY\t688\t438\n" + - "BROMNXKUIZULIGY\t706\t456\n" + - "BROMNXKUIZULIGY\t650\t400\n" + - "BROMNXKUIZULIGY\t531\t281\n" + - "BROMNXKUIZULIGY\t591\t341\n" + - "BROMNXKUIZULIGY\t514\t264\n" + - "BROMNXKUIZULIGY\t672\t422\n" + - "BROMNXKUIZULIGY\t590\t340\n" + - "BROMNXKUIZULIGY\t738\t488\n" + - "BROMNXKUIZULIGY\t627\t377\n" + - "BROMNXKUIZULIGY\t655\t405\n" + - "BROMNXKUIZULIGY\t550\t300\n" + - "BROMNXKUIZULIGY\t723\t473\n" + - "BROMNXKUIZULIGY\t737\t487\n" + - "BROMNXKUIZULIGY\t734\t484\n"; - - assertThat(expected, "select id, z + 250, z from tab where z >= 250 and id ~ 'ULIGY'"); - - final String expected2 = "BROMNXKUIZULIGY\t-59.255371093750\t221\t-290.255371093750\n" + - "BROMNXKUIZULIGY\t267.535586595535\t256\t1.535586595535\n" + - "BROMNXKUIZULIGY\t412.000018740170\t402\t0.000018740170\n" + - "BROMNXKUIZULIGY\t1211.500000000000\t418\t783.500000000000\n" + - "BROMNXKUIZULIGY\t-958.000000000000\t56\t-1024.000000000000\n" + - "BROMNXKUIZULIGY\t660.000000000000\t438\t212.000000000000\n" + - "BROMNXKUIZULIGY\tNaN\tNaN\t0.000006116291\n" + - "BROMNXKUIZULIGY\tNaN\tNaN\t0.000010187643\n" + - "BROMNXKUIZULIGY\t466.000153154480\t456\t0.000153154480\n" + - "BROMNXKUIZULIGY\t195.474104791880\t185\t0.474104791880\n" + - "BROMNXKUIZULIGY\t410.001604365563\t400\t0.001604365563\n" + - "BROMNXKUIZULIGY\t418.070312500000\t281\t127.070312500000\n" + - "BROMNXKUIZULIGY\t-677.000000000000\t-455\t-232.000000000000\n" + - "BROMNXKUIZULIGY\t-479.999999985485\t-490\t0.000000014515\n" + - "BROMNXKUIZULIGY\t768.000000000000\t-50\t808.000000000000\n" + - "BROMNXKUIZULIGY\t-117.999999720194\t-128\t0.000000279806\n" + - "BROMNXKUIZULIGY\t-277.361108899117\t-289\t1.638891100883\n" + - "BROMNXKUIZULIGY\tNaN\tNaN\t0.000251280326\n" + - "BROMNXKUIZULIGY\t-308.999952732278\t-319\t0.000047267722\n" + - "BROMNXKUIZULIGY\t26.000149987023\t16\t0.000149987023\n" + - "BROMNXKUIZULIGY\t-423.956409015693\t-434\t0.043590984307\n" + - "BROMNXKUIZULIGY\t-781.000000000000\t-279\t-512.000000000000\n" + - "BROMNXKUIZULIGY\tNaN\tNaN\t76.327049255371\n" + - "BROMNXKUIZULIGY\t607.000000000000\t341\t256.000000000000\n" + - "BROMNXKUIZULIGY\t138.000000000000\t128\t0.000000000000\n" + - "BROMNXKUIZULIGY\t398.000000000000\t-92\t480.000000000000\n" + - "BROMNXKUIZULIGY\t626.569580078125\t17\t599.569580078125\n" + - "BROMNXKUIZULIGY\t116.143798828125\t-50\t156.143798828125\n" + - "BROMNXKUIZULIGY\tNaN\tNaN\t0.000720751763\n" + - "BROMNXKUIZULIGY\t274.000144880152\t264\t0.000144880152\n" + - "BROMNXKUIZULIGY\t-34.999607196361\t-45\t0.000392803639\n" + - "BROMNXKUIZULIGY\t226.648437500000\t-299\t515.648437500000\n" + - "BROMNXKUIZULIGY\t432.003766982234\t422\t0.003766982234\n" + - "BROMNXKUIZULIGY\t487.326309204102\t60\t417.326309204102\n" + - "BROMNXKUIZULIGY\t516.000000000000\t-134\t640.000000000000\n" + - "BROMNXKUIZULIGY\tNaN\tNaN\t-664.000000000000\n" + - "BROMNXKUIZULIGY\t194.359175443649\t179\t5.359175443649\n" + - "BROMNXKUIZULIGY\t66.252536773682\t48\t8.252536773682\n" + - "BROMNXKUIZULIGY\t3.425781250000\t53\t-59.574218750000\n" + - "BROMNXKUIZULIGY\t-452.999999995122\t-463\t0.000000004878\n" + - "BROMNXKUIZULIGY\tNaN\tNaN\t0.010744831059\n" + - "BROMNXKUIZULIGY\t-40.999999992162\t-51\t0.000000007838\n" + - "BROMNXKUIZULIGY\t-848.431396484375\t29\t-887.431396484375\n" + - "BROMNXKUIZULIGY\t-290.999999830891\t-301\t0.000000169109\n" + - "BROMNXKUIZULIGY\t122.000168943778\t112\t0.000168943778\n" + - "BROMNXKUIZULIGY\t339.000000000000\t-183\t512.000000000000\n" + - "BROMNXKUIZULIGY\tNaN\tNaN\t7.454445600510\n" + - "BROMNXKUIZULIGY\t240.001445442904\t230\t0.001445442904\n" + - "BROMNXKUIZULIGY\t249.375976562500\t-261\t500.375976562500\n" + - "BROMNXKUIZULIGY\t-819.500000000000\t0\t-829.500000000000\n" + - "BROMNXKUIZULIGY\t-364.999998135639\t-375\t0.000001864361\n" + - "BROMNXKUIZULIGY\t92.284413337708\t81\t1.284413337708\n" + - "BROMNXKUIZULIGY\t-908.812500000000\t-272\t-646.812500000000\n" + - "BROMNXKUIZULIGY\t-218.879174321890\t-229\t0.120825678110\n" + - "BROMNXKUIZULIGY\t350.000097934379\t340\t0.000097934379\n" + - "BROMNXKUIZULIGY\t8.000360143276\t-2\t0.000360143276\n" + - "BROMNXKUIZULIGY\tNaN\tNaN\t736.000000000000\n" + - "BROMNXKUIZULIGY\t498.000020276546\t488\t0.000020276546\n" + - "BROMNXKUIZULIGY\t-24.999999978179\t-35\t0.000000021821\n" + - "BROMNXKUIZULIGY\t486.000000000000\t220\t256.000000000000\n" + - "BROMNXKUIZULIGY\t-188.975300276652\t-199\t0.024699723348\n" + - "BROMNXKUIZULIGY\t-135.999999362280\t-146\t0.000000637720\n" + - "BROMNXKUIZULIGY\t65.700256347656\t-393\t448.700256347656\n" + - "BROMNXKUIZULIGY\t-1011.250000000000\t-499\t-522.250000000000\n" + - "BROMNXKUIZULIGY\t-384.984375000000\t45\t-439.984375000000\n" + - "BROMNXKUIZULIGY\t-147.000000000000\t-249\t92.000000000000\n" + - "BROMNXKUIZULIGY\t-330.999999834806\t-341\t0.000000165194\n" + - "BROMNXKUIZULIGY\t-960.312500000000\t-241\t-729.312500000000\n" + - "BROMNXKUIZULIGY\tNaN\tNaN\t384.000000000000\n" + - "BROMNXKUIZULIGY\t-208.853453457356\t-220\t1.146546542645\n" + - "BROMNXKUIZULIGY\t398.924531459808\t377\t11.924531459808\n" + - "BROMNXKUIZULIGY\t415.000000109825\t405\t0.000000109825\n" + - "BROMNXKUIZULIGY\t-69.875890344381\t-80\t0.124109655619\n" + - "BROMNXKUIZULIGY\t232.000052321986\t222\t0.000052321986\n" + - "BROMNXKUIZULIGY\t-202.054351806641\t300\t-512.054351806641\n" + - "BROMNXKUIZULIGY\t483.000926071953\t473\t0.000926071953\n" + - "BROMNXKUIZULIGY\t497.681155398488\t487\t0.681155398488\n" + - "BROMNXKUIZULIGY\t84.000002542528\t74\t0.000002542528\n" + - "BROMNXKUIZULIGY\t226.000292068784\t216\t0.000292068784\n" + - "BROMNXKUIZULIGY\t99.032178618945\t89\t0.032178618945\n" + - "BROMNXKUIZULIGY\t256.000000000000\t-10\t256.000000000000\n" + - "BROMNXKUIZULIGY\t494.000000013356\t484\t0.000000013356\n" + - "BROMNXKUIZULIGY\t587.446777343750\t-58\t635.446777343750\n" + - "BROMNXKUIZULIGY\t43.634443283081\t-23\t56.634443283081\n"; - - assertThat(expected2, "select id, (z + 10) + x, z, x from tab where id ~ 'ULIGY'"); - } - - @Test - public void testAddMillis() throws Exception { - createTabWithNaNs2(); - assertThat("2015-03-18T09:00:00.000Z\t2015-03-18T10:00:00.000Z\n" + - "2015-03-25T20:00:00.000Z\t2015-03-25T21:00:00.000Z\n" + - "2015-04-13T07:00:00.000Z\t2015-04-13T08:00:00.000Z\n" + - "2015-04-15T18:00:00.000Z\t2015-04-15T19:00:00.000Z\n" + - "2015-04-16T14:00:00.000Z\t2015-04-16T15:00:00.000Z\n", - "select timestamp, timestamp + 60*60*1000L incr from tab where id ~ 'BHE' limit 5"); - - } - - @Test - public void testAliasInWhere() throws Exception { - createTabWithNaNs(); - final String expected = "BROMNXKUIZULIGY\t506\t256\n" + - "BROMNXKUIZULIGY\t531\t281\n" + - "BROMNXKUIZULIGY\t591\t341\n" + - "BROMNXKUIZULIGY\t514\t264\n" + - "BROMNXKUIZULIGY\t590\t340\n" + - "BROMNXKUIZULIGY\t550\t300\n"; - - assertThat(expected, "(select id k, z + 250 u, z from tab where z >= 250 and k ~ 'BROM') where u < 600 "); - } - - @Test - public void testAliasInWhere2() throws Exception { - createTabWithNaNs(); - final String expected = "BROMNXKUIZULIGY\t506\t256\n" + - "BROMNXKUIZULIGY\t652\t402\n" + - "BROMNXKUIZULIGY\t668\t418\n" + - "BROMNXKUIZULIGY\t688\t438\n" + - "BROMNXKUIZULIGY\t706\t456\n" + - "BROMNXKUIZULIGY\t650\t400\n" + - "BROMNXKUIZULIGY\t531\t281\n" + - "BROMNXKUIZULIGY\t591\t341\n" + - "BROMNXKUIZULIGY\t514\t264\n" + - "BROMNXKUIZULIGY\t672\t422\n" + - "BROMNXKUIZULIGY\t590\t340\n" + - "BROMNXKUIZULIGY\t738\t488\n" + - "BROMNXKUIZULIGY\t627\t377\n" + - "BROMNXKUIZULIGY\t655\t405\n" + - "BROMNXKUIZULIGY\t550\t300\n" + - "BROMNXKUIZULIGY\t723\t473\n" + - "BROMNXKUIZULIGY\t737\t487\n" + - "BROMNXKUIZULIGY\t734\t484\n"; - - assertThat(expected, "select id k, z + 250 u, z from tab where z >= 250 and k ~ 'BROM'"); - } - - @Test - public void testAndArgCheck() { - // missing left arg on 'and' - try { - expectFailure("select id,w,x,z,x + -w, z+-w from tab where and id = 'FYXPVKNCBWLNLRH'"); - } catch (ParserException e) { - Assert.assertEquals(44, QueryError.getPosition()); - } - } - - @Test - public void testAndArgCheck2() { - // missing left arg on 'and' - try { - expectFailure("select id,w,x,z,x + -w, z+-w from tab where id = 'FYXPVKNCBWLNLRH' and "); - } catch (ParserException e) { - Assert.assertEquals(67, QueryError.getPosition()); - } - } - - @Test - public void testAtoI() throws Exception { - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab").$str("intC").$() - )) { - - StringSink sink = new StringSink(); - Rnd rnd = new Rnd(); - for (int i = 0; i < 30; i++) { - sink.clear(); - Numbers.append(sink, rnd.nextInt()); - CharSequence cs = rnd.nextChars(4); - JournalEntryWriter ew = w.entryWriter(); - ew.putStr(0, rnd.nextBoolean() ? cs : sink); - ew.append(); - } - w.commit(); - - - final String expected = "-1148479920\t-1148479920\n" + - "1326447242\t1326447242\n" + - "-1436881714\t-1436881714\n" + - "-409854405\t-409854405\n" + - "1125579207\t1125579207\n" + - "-1844391305\t-1844391305\n" + - "-1125169127\t-1125169127\n" + - "-2119387831\t-2119387831\n" + - "-422941535\t-422941535\n" + - "-2132716300\t-2132716300\n" + - "-483853667\t-483853667\n" + - "NaN\tQQUL\n" + - "-1418341054\t-1418341054\n" + - "936627841\t936627841\n" + - "NaN\tFBVT\n" + - "-1515787781\t-1515787781\n" + - "-1538602195\t-1538602195\n" + - "-10505757\t-10505757\n" + - "NaN\tICWE\n" + - "1876812930\t1876812930\n" + - "NaN\tOTSE\n" + - "-916132123\t-916132123\n" + - "NaN\tLYXW\n" + - "NaN\tYLSU\n" + - "-1768335227\t-1768335227\n" + - "-876466531\t-876466531\n" + - "NaN\tQBZX\n" + - "NaN\tVIKJ\n" + - "-2088317486\t-2088317486\n" + - "614536941\t614536941\n"; - assertThat(expected, "select atoi(intC), intC from tab"); - - - assertThat("-1.14847992E9\t-1148479920\n" + - "1.326447242E9\t1326447242\n" + - "-1.436881714E9\t-1436881714\n" + - "-4.09854405E8\t-409854405\n" + - "1.125579207E9\t1125579207\n" + - "-1.844391305E9\t-1844391305\n" + - "-1.125169127E9\t-1125169127\n" + - "-2.119387831E9\t-2119387831\n" + - "-4.22941535E8\t-422941535\n" + - "-2.1327163E9\t-2132716300\n" + - "-4.83853667E8\t-483853667\n" + - "NaN\tQQUL\n" + - "-1.418341054E9\t-1418341054\n" + - "9.36627841E8\t936627841\n" + - "NaN\tFBVT\n" + - "-1.515787781E9\t-1515787781\n" + - "-1.538602195E9\t-1538602195\n" + - "-1.0505757E7\t-10505757\n" + - "NaN\tICWE\n" + - "1.87681293E9\t1876812930\n" + - "NaN\tOTSE\n" + - "-9.16132123E8\t-916132123\n" + - "NaN\tLYXW\n" + - "NaN\tYLSU\n" + - "-1.768335227E9\t-1768335227\n" + - "-8.76466531E8\t-876466531\n" + - "NaN\tQBZX\n" + - "NaN\tVIKJ\n" + - "-2.088317486E9\t-2088317486\n" + - "6.14536941E8\t614536941\n", - "select atod(intC), intC from tab"); - } - } - - @Test - public void testColumnAliases() throws Exception { - createTabWithNaNs2(); - - assertThat("a\tb\n" + - "1014.000000000000\tNaN\n" + - "1008.553894042969\tNaN\n" + - "1017.000000000000\tNaN\n", - "select x a, y b from tab where y = NaN and x > 1000", true); - } - - @Test - public void testConstantCondition1() throws Exception { - createTab(); - assertPlan("{\"op\":\"SelectedColumnsRecordSource\",\"src\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"NoOpJournalPartitionSource\",\"journal\":\"tab\"},\"rsrc\":{\"op\":\"AllRowSource\"}}}", - "select id, x, y from tab where x > 0 and 1 > 1"); - } - - @Test - public void testConstantCondition2() throws Exception { - createTab(); - assertPlan("{\"op\":\"SelectedColumnsRecordSource\",\"src\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"JournalPartitionSource\",\"journal\":\"tab\"},\"rsrc\":{\"op\":\"AllRowSource\"}}}", - "select id, x, y from tab where x > 0 or 1 = 1"); - } - - @Test - public void testConstantCondition3() throws Exception { - createTab(); - assertPlan("{\"op\":\"SelectedColumnsRecordSource\",\"src\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"NoOpJournalPartitionSource\",\"journal\":\"tab\"},\"rsrc\":{\"op\":\"AllRowSource\"}}}", - "select id, x, y from tab where 1 > 1 or 2 > 2"); - } - - @Test - public void testConstants() throws Exception { - createTabWithNaNs2(); - assertThat("FLOAT\tDOUBLE\tINT\tLONG\n", "select typeOf(123.34f), typeOf(123.34), typeOf(1234), typeOf(1234L) from tab limit 1"); - assertSymbol("select typeOf(123.34f), typeOf(123.34), typeOf(1234), typeOf(1234L) from tab limit 1"); - } - - @Test - public void testDateEquals() throws Exception { - createTabWithSymbol(); - final String expected = "FLRJLIUCZXHEPGK\tPZDYLPYJJP\t802.000000000000\t0.000000003518\t2015-03-12T00:01:39.630Z\n"; - assertThat(expected, "tab where timestamp = toDate('2015-03-12T00:01:39.630Z')"); - assertThat(expected, "tab where timestamp = '2015-03-12T00:01:39.630Z'"); - } - - @Test - public void testDateGreater() throws Exception { - createTabWithSymbol(); - final String expected = "OUZBRTJQZFHPYNJ\tEUIMIKBLKD\t16.000000000000\t936.000000000000\t2015-03-12T00:01:39.640Z\n" + - "YCFIBRUTIIPOFZO\tLGUBNTLOBY\t0.000000204810\t11.203086614609\t2015-03-12T00:01:39.650Z\n" + - "WMNVMFFLSQTWPRT\tSRSQCLKJVK\t0.000000218690\t384.000000000000\t2015-03-12T00:01:39.660Z\n" + - "EOHBGLBYXFGYIBH\tFHCHIFIPHZ\t5.323504686356\t0.000191266379\t2015-03-12T00:01:39.670Z\n" + - "ZMEOUEPFSZEYDNM\tCWOFRMJORR\t0.000001766383\t-82.781250000000\t2015-03-12T00:01:39.680Z\n" + - "FHZNVQJXWNXHJWR\tDLQJBVVTTV\t640.000000000000\t0.000000007695\t2015-03-12T00:01:39.690Z\n" + - "QLDGLOGIFOUSZMZ\tCHJNLZOOYL\t110.375000000000\t987.000000000000\t2015-03-12T00:01:39.700Z\n" + - "DLRBIDSTDTFBYHS\tSXXBMBBOGG\t-957.750000000000\t0.110677853227\t2015-03-12T00:01:39.710Z\n" + - "UZIZKMFCKVHMRTG\tTETQNSQTYO\t800.000000000000\t0.523283928633\t2015-03-12T00:01:39.720Z\n" + - "VFZFKWZLUOGXHFV\tIBNOKWHVKP\t0.000003309520\t-845.750000000000\t2015-03-12T00:01:39.730Z\n" + - "IUNJPYZVOJBTYGL\tGLONQBVNJQ\t406.359375000000\t-889.875000000000\t2015-03-12T00:01:39.740Z\n" + - "PFZPXRHMUJOGWMJ\tUSGCNKKKGI\t0.000885035086\t918.488769531250\t2015-03-12T00:01:39.750Z\n" + - "ZHVJFPVRMUBLILX\tPLUQPOKPIW\t-320.000000000000\t709.773437500000\t2015-03-12T00:01:39.760Z\n" + - "GEUBDFBTXXGWQFT\tNFDSBMBZFB\t11.990052223206\t560.000000000000\t2015-03-12T00:01:39.770Z\n" + - "BELCSCIUZMCFUWY\tSRSQCLKJVK\t0.007322372403\t276.781250000000\t2015-03-12T00:01:39.780Z\n" + - "TEHIOFKMQPUNEUD\tSXXBMBBOGG\t290.000000000000\t0.000000062047\t2015-03-12T00:01:39.790Z\n" + - "YNLERUGEWULQWLN\tCJCNMPYSJF\t439.851211547852\t0.000417203366\t2015-03-12T00:01:39.800Z\n" + - "OIBUGYXIMDIDNRO\tMRFPKLNWQL\t0.000245904943\t0.049118923023\t2015-03-12T00:01:39.810Z\n" + - "XXTPBXNCJEDGPLH\tDLQJBVVTTV\t58.250000000000\t0.191959321499\t2015-03-12T00:01:39.820Z\n" + - "ZNIFDRPHNGTNJJP\tKIWPCXCIGW\t666.264648437500\t0.000283217822\t2015-03-12T00:01:39.830Z\n" + - "ONIJMVFQFDBOMQB\tEDBVUVMLSX\t0.000000120621\t-694.250000000000\t2015-03-12T00:01:39.840Z\n" + - "UCSOZSLOQGPOHIM\tOJPOHDOWSK\t29.429825782776\t-13.079589843750\t2015-03-12T00:01:39.850Z\n" + - "VVOFHXMMEJXJNRD\tVZQSGLLZQG\t-384.000000000000\t0.006880680798\t2015-03-12T00:01:39.860Z\n" + - "WDDZKIFCBRMKKRH\tMERDPIDQGJ\t387.875000000000\t0.000000007496\t2015-03-12T00:01:39.870Z\n" + - "UPJFSREKEUNMKWO\tCWOFRMJORR\t642.000000000000\t1.016614258289\t2015-03-12T00:01:39.880Z\n" + - "TMIWHRQISSCIGXL\tRULHMZROYY\t-736.000000000000\t0.000000238132\t2015-03-12T00:01:39.890Z\n" + - "WJWZBSMWXQOFNRO\tDZDUVNCYYV\t9.389577388763\t8.453002452850\t2015-03-12T00:01:39.900Z\n" + - "IFBEPWLUTGRGEIW\tMUTSHRDWCI\t681.700683593750\t0.000765276010\t2015-03-12T00:01:39.910Z\n" + - "MBJEIRSSGXDDXKD\tUSGCNKKKGI\t0.000001004210\t-1024.000000000000\t2015-03-12T00:01:39.920Z\n" + - "LXGRVRKVTIFXRLE\tVGYEPKGPSJ\t-860.750000000000\t-210.259765625000\t2015-03-12T00:01:39.930Z\n" + - "DEPQDCICIZUYOGK\tWVJFWXNHTG\t-227.859375000000\t-236.156250000000\t2015-03-12T00:01:39.940Z\n" + - "XCHCUBYPMDFJZYJ\tWYCLIXTWVG\t0.000409339424\t-175.941406250000\t2015-03-12T00:01:39.950Z\n" + - "TPCOITVXSGCPELN\tHTIWQZBCZV\t-420.375000000000\t0.005818145582\t2015-03-12T00:01:39.960Z\n" + - "QJMRPDXTXOMBKZY\tSMCKFERVGM\t10.221145391464\t512.000000000000\t2015-03-12T00:01:39.970Z\n" + - "UHHRIRJGLQNMETN\tELYYIFISZU\t375.230987548828\t0.121945030987\t2015-03-12T00:01:39.980Z\n" + - "SDRLMSHKFZJJECT\tCJCNMPYSJF\t384.000000000000\t0.000000000000\t2015-03-12T00:01:39.990Z\n" + - "MTLSJOWYLNEDVLL\tIPVOKGQWDX\t2.619887888432\t-477.522460937500\t2015-03-12T00:01:40.000Z\n"; - - assertThat(expected, "tab where timestamp > toDate('2015-03-12T00:01:39.630Z')"); - assertThat(expected, "tab where timestamp > '2015-03-12T00:01:39.630Z'"); - } - - @Test - public void testDateGreaterOrEqual() throws Exception { - createTabWithSymbol(); - final String expected = "FLRJLIUCZXHEPGK\tPZDYLPYJJP\t802.000000000000\t0.000000003518\t2015-03-12T00:01:39.630Z\n" + - "OUZBRTJQZFHPYNJ\tEUIMIKBLKD\t16.000000000000\t936.000000000000\t2015-03-12T00:01:39.640Z\n" + - "YCFIBRUTIIPOFZO\tLGUBNTLOBY\t0.000000204810\t11.203086614609\t2015-03-12T00:01:39.650Z\n" + - "WMNVMFFLSQTWPRT\tSRSQCLKJVK\t0.000000218690\t384.000000000000\t2015-03-12T00:01:39.660Z\n" + - "EOHBGLBYXFGYIBH\tFHCHIFIPHZ\t5.323504686356\t0.000191266379\t2015-03-12T00:01:39.670Z\n" + - "ZMEOUEPFSZEYDNM\tCWOFRMJORR\t0.000001766383\t-82.781250000000\t2015-03-12T00:01:39.680Z\n" + - "FHZNVQJXWNXHJWR\tDLQJBVVTTV\t640.000000000000\t0.000000007695\t2015-03-12T00:01:39.690Z\n" + - "QLDGLOGIFOUSZMZ\tCHJNLZOOYL\t110.375000000000\t987.000000000000\t2015-03-12T00:01:39.700Z\n" + - "DLRBIDSTDTFBYHS\tSXXBMBBOGG\t-957.750000000000\t0.110677853227\t2015-03-12T00:01:39.710Z\n" + - "UZIZKMFCKVHMRTG\tTETQNSQTYO\t800.000000000000\t0.523283928633\t2015-03-12T00:01:39.720Z\n" + - "VFZFKWZLUOGXHFV\tIBNOKWHVKP\t0.000003309520\t-845.750000000000\t2015-03-12T00:01:39.730Z\n" + - "IUNJPYZVOJBTYGL\tGLONQBVNJQ\t406.359375000000\t-889.875000000000\t2015-03-12T00:01:39.740Z\n" + - "PFZPXRHMUJOGWMJ\tUSGCNKKKGI\t0.000885035086\t918.488769531250\t2015-03-12T00:01:39.750Z\n" + - "ZHVJFPVRMUBLILX\tPLUQPOKPIW\t-320.000000000000\t709.773437500000\t2015-03-12T00:01:39.760Z\n" + - "GEUBDFBTXXGWQFT\tNFDSBMBZFB\t11.990052223206\t560.000000000000\t2015-03-12T00:01:39.770Z\n" + - "BELCSCIUZMCFUWY\tSRSQCLKJVK\t0.007322372403\t276.781250000000\t2015-03-12T00:01:39.780Z\n" + - "TEHIOFKMQPUNEUD\tSXXBMBBOGG\t290.000000000000\t0.000000062047\t2015-03-12T00:01:39.790Z\n" + - "YNLERUGEWULQWLN\tCJCNMPYSJF\t439.851211547852\t0.000417203366\t2015-03-12T00:01:39.800Z\n" + - "OIBUGYXIMDIDNRO\tMRFPKLNWQL\t0.000245904943\t0.049118923023\t2015-03-12T00:01:39.810Z\n" + - "XXTPBXNCJEDGPLH\tDLQJBVVTTV\t58.250000000000\t0.191959321499\t2015-03-12T00:01:39.820Z\n" + - "ZNIFDRPHNGTNJJP\tKIWPCXCIGW\t666.264648437500\t0.000283217822\t2015-03-12T00:01:39.830Z\n" + - "ONIJMVFQFDBOMQB\tEDBVUVMLSX\t0.000000120621\t-694.250000000000\t2015-03-12T00:01:39.840Z\n" + - "UCSOZSLOQGPOHIM\tOJPOHDOWSK\t29.429825782776\t-13.079589843750\t2015-03-12T00:01:39.850Z\n" + - "VVOFHXMMEJXJNRD\tVZQSGLLZQG\t-384.000000000000\t0.006880680798\t2015-03-12T00:01:39.860Z\n" + - "WDDZKIFCBRMKKRH\tMERDPIDQGJ\t387.875000000000\t0.000000007496\t2015-03-12T00:01:39.870Z\n" + - "UPJFSREKEUNMKWO\tCWOFRMJORR\t642.000000000000\t1.016614258289\t2015-03-12T00:01:39.880Z\n" + - "TMIWHRQISSCIGXL\tRULHMZROYY\t-736.000000000000\t0.000000238132\t2015-03-12T00:01:39.890Z\n" + - "WJWZBSMWXQOFNRO\tDZDUVNCYYV\t9.389577388763\t8.453002452850\t2015-03-12T00:01:39.900Z\n" + - "IFBEPWLUTGRGEIW\tMUTSHRDWCI\t681.700683593750\t0.000765276010\t2015-03-12T00:01:39.910Z\n" + - "MBJEIRSSGXDDXKD\tUSGCNKKKGI\t0.000001004210\t-1024.000000000000\t2015-03-12T00:01:39.920Z\n" + - "LXGRVRKVTIFXRLE\tVGYEPKGPSJ\t-860.750000000000\t-210.259765625000\t2015-03-12T00:01:39.930Z\n" + - "DEPQDCICIZUYOGK\tWVJFWXNHTG\t-227.859375000000\t-236.156250000000\t2015-03-12T00:01:39.940Z\n" + - "XCHCUBYPMDFJZYJ\tWYCLIXTWVG\t0.000409339424\t-175.941406250000\t2015-03-12T00:01:39.950Z\n" + - "TPCOITVXSGCPELN\tHTIWQZBCZV\t-420.375000000000\t0.005818145582\t2015-03-12T00:01:39.960Z\n" + - "QJMRPDXTXOMBKZY\tSMCKFERVGM\t10.221145391464\t512.000000000000\t2015-03-12T00:01:39.970Z\n" + - "UHHRIRJGLQNMETN\tELYYIFISZU\t375.230987548828\t0.121945030987\t2015-03-12T00:01:39.980Z\n" + - "SDRLMSHKFZJJECT\tCJCNMPYSJF\t384.000000000000\t0.000000000000\t2015-03-12T00:01:39.990Z\n" + - "MTLSJOWYLNEDVLL\tIPVOKGQWDX\t2.619887888432\t-477.522460937500\t2015-03-12T00:01:40.000Z\n"; - - assertThat(expected, "tab where timestamp >= toDate('2015-03-12T00:01:39.630Z')"); - assertThat(expected, "tab where timestamp >= '2015-03-12T00:01:39.630Z'"); - } - - @Test - public void testDateLess() throws Exception { - createTabWithSymbol(); - final String expected = "LTISIRJQLWPWDVI\tQJLOQQWWRQ\t0.001847213891\t782.780761718750\t2015-03-12T00:00:00.010Z\n" + - "KKHXEFMRDTNMZXQ\tOJPOHDOWSK\t280.588867187500\t26.110730648041\t2015-03-12T00:00:00.020Z\n" + - "IFELSVFCLLTKNRI\tIPVOKGQWDX\t730.000000000000\t0.000000215277\t2015-03-12T00:00:00.030Z\n" + - "BVBDTCLGEJBYBSJ\tTETQNSQTYO\t-1024.000000000000\t0.906509011984\t2015-03-12T00:00:00.040Z\n" + - "UWOUBDHXHUWGRJY\tTKMQLRBSEN\t265.834960937500\t389.984191894531\t2015-03-12T00:00:00.050Z\n" + - "XPNKGQELQDWQGMZ\tKIWPCXCIGW\t0.000000175463\t0.085401995108\t2015-03-12T00:00:00.060Z\n" + - "WRWFCYOPVEICZCC\tNYSEHQIFHZ\t0.000025559940\t152.464843750000\t2015-03-12T00:00:00.070Z\n" + - "WJGLDUTMUGDVOVL\tQUIXCJQBRM\t-927.687500000000\t-202.000000000000\t2015-03-12T00:00:00.080Z\n" + - "GOJNELWTYCFNLUF\tMRFPKLNWQL\t512.000000000000\t0.000000709136\t2015-03-12T00:00:00.090Z\n" + - "PXQEPFERZKBFFKK\tOJPOHDOWSK\t23.054984092712\t2.820306181908\t2015-03-12T00:00:00.100Z\n" + - "OPWOLFQBXZICTJN\tPLUQPOKPIW\t-498.000000000000\t0.000131426888\t2015-03-12T00:00:00.110Z\n"; - - assertThat(expected, "tab where timestamp < toDate('2015-03-12T00:00:00.120Z')"); - assertThat(expected, "tab where timestamp < '2015-03-12T00:00:00.120Z'"); - } - - @Test - public void testDateLessOrEqual() throws Exception { - createTabWithSymbol(); - final String expected = "LTISIRJQLWPWDVI\tQJLOQQWWRQ\t0.001847213891\t782.780761718750\t2015-03-12T00:00:00.010Z\n" + - "KKHXEFMRDTNMZXQ\tOJPOHDOWSK\t280.588867187500\t26.110730648041\t2015-03-12T00:00:00.020Z\n" + - "IFELSVFCLLTKNRI\tIPVOKGQWDX\t730.000000000000\t0.000000215277\t2015-03-12T00:00:00.030Z\n" + - "BVBDTCLGEJBYBSJ\tTETQNSQTYO\t-1024.000000000000\t0.906509011984\t2015-03-12T00:00:00.040Z\n" + - "UWOUBDHXHUWGRJY\tTKMQLRBSEN\t265.834960937500\t389.984191894531\t2015-03-12T00:00:00.050Z\n" + - "XPNKGQELQDWQGMZ\tKIWPCXCIGW\t0.000000175463\t0.085401995108\t2015-03-12T00:00:00.060Z\n" + - "WRWFCYOPVEICZCC\tNYSEHQIFHZ\t0.000025559940\t152.464843750000\t2015-03-12T00:00:00.070Z\n" + - "WJGLDUTMUGDVOVL\tQUIXCJQBRM\t-927.687500000000\t-202.000000000000\t2015-03-12T00:00:00.080Z\n" + - "GOJNELWTYCFNLUF\tMRFPKLNWQL\t512.000000000000\t0.000000709136\t2015-03-12T00:00:00.090Z\n" + - "PXQEPFERZKBFFKK\tOJPOHDOWSK\t23.054984092712\t2.820306181908\t2015-03-12T00:00:00.100Z\n" + - "OPWOLFQBXZICTJN\tPLUQPOKPIW\t-498.000000000000\t0.000131426888\t2015-03-12T00:00:00.110Z\n" + - "PFZGUJBKNTPYXUB\tKIWPCXCIGW\t0.000006574179\t222.422851562500\t2015-03-12T00:00:00.120Z\n"; - - assertThat(expected, "tab where timestamp <= toDate('2015-03-12T00:00:00.120Z')"); - assertThat(expected, "tab where timestamp <= '2015-03-12T00:00:00.120Z'"); - } - - @Test - public void testDateMultInterval() throws Exception { - createTabWithSymbol(); - final String expected = "QRZCGENVSOFKRKE\tOJPOHDOWSK\t0.026915318333\t108.585937500000\t2015-03-12T00:01:11.120Z\n" + - "YSLYCGDGJVDWMTP\tFHCHIFIPHZ\t-168.000000000000\t-1024.000000000000\t2015-03-12T00:01:11.230Z\n" + - "QRZCGENVSOFKRKE\tPLUQPOKPIW\t0.002588719828\t1012.000000000000\t2015-03-12T00:01:11.740Z\n" + - "OQDHZTECGRBEFYC\tTETQNSQTYO\t0.000003892420\t0.002290764009\t2015-03-12T00:01:30.300Z\n" + - "JODBFRSHPSQECGJ\tIBNOKWHVKP\t0.000000000000\t720.000000000000\t2015-03-12T00:01:30.880Z\n"; - - assertThat(expected, "tab where id ~ 'CG' and timestamp = '2015' and (timestamp = '2015-03-12T00:01:11' or timestamp = '2015-03-12T00:01:30')"); - } - - @Test - public void testDateMultInterval2() throws Exception { - createTabWithSymbol(); - final String expected = "BVBDTCLGEJBYBSJ\tTETQNSQTYO\t-1024.000000000000\t0.906509011984\t2015-03-12T00:00:00.040Z\n" + - "BVBDTCLGEJBYBSJ\tPZDYLPYJJP\t0.000007882405\t0.064732506871\t2015-03-12T00:00:00.540Z\n" + - "WQTBDTSJOVQJYLZ\tIPVOKGQWDX\t598.000000000000\t0.000005879177\t2015-03-12T00:00:12.340Z\n" + - "BVBDTCLGEJBYBSJ\tJMCPJCLCWV\t86.466068267822\t768.000000000000\t2015-03-12T00:00:21.910Z\n" + - "BVBDTCLGEJBYBSJ\tWWLCPSOEVR\t-827.000000000000\t0.376058250666\t2015-03-12T00:00:25.520Z\n" + - "BVBDTCLGEJBYBSJ\tNYSEHQIFHZ\t0.000139812866\t0.657814309001\t2015-03-12T00:00:32.540Z\n" + - "WQTBDTSJOVQJYLZ\tQJLOQQWWRQ\t-764.964843750000\t0.000750026142\t2015-03-12T00:00:39.670Z\n" + - "BVBDTCLGEJBYBSJ\tVEEIXOZZFN\t0.012393638026\t20.759119987488\t2015-03-12T00:00:40.170Z\n" + - "BVBDTCLGEJBYBSJ\tMRFPKLNWQL\t928.000000000000\t0.024308424909\t2015-03-12T00:00:40.770Z\n" + - "WQTBDTSJOVQJYLZ\tCWOFRMJORR\t0.000000017971\t0.000013092605\t2015-03-12T00:00:41.090Z\n" + - "BVBDTCLGEJBYBSJ\tWOIJWXOIOT\t0.000000007575\t0.001671805512\t2015-03-12T00:00:44.060Z\n" + - "WQTBDTSJOVQJYLZ\tEUIMIKBLKD\t0.028749017045\t0.000000224847\t2015-03-12T00:00:47.200Z\n" + - "WQTBDTSJOVQJYLZ\tSXXBMBBOGG\t71.453750610352\t0.000343156316\t2015-03-12T00:00:48.080Z\n" + - "BVBDTCLGEJBYBSJ\tKJNBLQHSHH\t0.000000000000\t-384.000000000000\t2015-03-12T00:00:52.550Z\n" + - "WQTBDTSJOVQJYLZ\tWYCLIXTWVG\t2.525636672974\t-370.000000000000\t2015-03-12T00:00:59.050Z\n" + - "WQTBDTSJOVQJYLZ\tBVMFXSKVMS\t0.017297931015\t0.011041654274\t2015-03-12T00:01:00.940Z\n" + - "BVBDTCLGEJBYBSJ\tDBEHZQPMTN\t196.375000000000\t755.625000000000\t2015-03-12T00:01:07.790Z\n" + - "WQTBDTSJOVQJYLZ\tWVJFWXNHTG\t25.559150695801\t-512.000000000000\t2015-03-12T00:01:15.940Z\n" + - "WQTBDTSJOVQJYLZ\tRULHMZROYY\t-140.000000000000\t0.000005934012\t2015-03-12T00:01:18.040Z\n" + - "WQTBDTSJOVQJYLZ\tKPOZXJTBMM\t0.000000011937\t-704.000000000000\t2015-03-12T00:01:35.440Z\n" + - "BVBDTCLGEJBYBSJ\tJMCPJCLCWV\t-696.050415039063\t512.000000000000\t2015-03-12T00:01:36.900Z\n" + - "WQTBDTSJOVQJYLZ\tIPCBXJGYRN\t5.286757946014\t210.500000000000\t2015-03-12T00:01:37.510Z\n"; - - assertThat(expected, "tab where timestamp = '2015;1d;1y;2' and timestamp = '2015-03-11;1d;1d;2' and id ~ 'BDT'"); - } - - @Test - public void testDateNotEqual() throws Exception { - createTabWithSymbol(); - final String expected = "LTISIRJQLWPWDVI\tQJLOQQWWRQ\t0.001847213891\t782.780761718750\t2015-03-12T00:00:00.010Z\n" + - "KKHXEFMRDTNMZXQ\tOJPOHDOWSK\t280.588867187500\t26.110730648041\t2015-03-12T00:00:00.020Z\n" + - "IFELSVFCLLTKNRI\tIPVOKGQWDX\t730.000000000000\t0.000000215277\t2015-03-12T00:00:00.030Z\n" + - "BVBDTCLGEJBYBSJ\tTETQNSQTYO\t-1024.000000000000\t0.906509011984\t2015-03-12T00:00:00.040Z\n" + - "UWOUBDHXHUWGRJY\tTKMQLRBSEN\t265.834960937500\t389.984191894531\t2015-03-12T00:00:00.050Z\n" + - "WRWFCYOPVEICZCC\tNYSEHQIFHZ\t0.000025559940\t152.464843750000\t2015-03-12T00:00:00.070Z\n" + - "WJGLDUTMUGDVOVL\tQUIXCJQBRM\t-927.687500000000\t-202.000000000000\t2015-03-12T00:00:00.080Z\n" + - "GOJNELWTYCFNLUF\tMRFPKLNWQL\t512.000000000000\t0.000000709136\t2015-03-12T00:00:00.090Z\n" + - "PXQEPFERZKBFFKK\tOJPOHDOWSK\t23.054984092712\t2.820306181908\t2015-03-12T00:00:00.100Z\n" + - "OPWOLFQBXZICTJN\tPLUQPOKPIW\t-498.000000000000\t0.000131426888\t2015-03-12T00:00:00.110Z\n" + - "PFZGUJBKNTPYXUB\tKIWPCXCIGW\t0.000006574179\t222.422851562500\t2015-03-12T00:00:00.120Z\n"; - - assertThat(expected, "tab where timestamp <= toDate('2015-03-12T00:00:00.120Z') and timestamp != toDate('2015-03-12T00:00:00.060Z')"); - assertThat(expected, "tab where timestamp <= '2015-03-12T00:00:00.120Z' and timestamp != '2015-03-12T00:00:00.060Z'"); - } - - @Test - public void testDateNotIn() throws Exception { - createTabWithSymbol(); - final String expected = "OUZBRTJQZFHPYNJ\tEUIMIKBLKD\t16.000000000000\t936.000000000000\t2015-03-12T00:01:39.640Z\n" + - "YCFIBRUTIIPOFZO\tLGUBNTLOBY\t0.000000204810\t11.203086614609\t2015-03-12T00:01:39.650Z\n" + - "WMNVMFFLSQTWPRT\tSRSQCLKJVK\t0.000000218690\t384.000000000000\t2015-03-12T00:01:39.660Z\n" + - "EOHBGLBYXFGYIBH\tFHCHIFIPHZ\t5.323504686356\t0.000191266379\t2015-03-12T00:01:39.670Z\n" + - "ZMEOUEPFSZEYDNM\tCWOFRMJORR\t0.000001766383\t-82.781250000000\t2015-03-12T00:01:39.680Z\n" + - "FHZNVQJXWNXHJWR\tDLQJBVVTTV\t640.000000000000\t0.000000007695\t2015-03-12T00:01:39.690Z\n" + - "QLDGLOGIFOUSZMZ\tCHJNLZOOYL\t110.375000000000\t987.000000000000\t2015-03-12T00:01:39.700Z\n" + - "DLRBIDSTDTFBYHS\tSXXBMBBOGG\t-957.750000000000\t0.110677853227\t2015-03-12T00:01:39.710Z\n" + - "UZIZKMFCKVHMRTG\tTETQNSQTYO\t800.000000000000\t0.523283928633\t2015-03-12T00:01:39.720Z\n" + - "VFZFKWZLUOGXHFV\tIBNOKWHVKP\t0.000003309520\t-845.750000000000\t2015-03-12T00:01:39.730Z\n" + - "IUNJPYZVOJBTYGL\tGLONQBVNJQ\t406.359375000000\t-889.875000000000\t2015-03-12T00:01:39.740Z\n" + - "PFZPXRHMUJOGWMJ\tUSGCNKKKGI\t0.000885035086\t918.488769531250\t2015-03-12T00:01:39.750Z\n" + - "ZHVJFPVRMUBLILX\tPLUQPOKPIW\t-320.000000000000\t709.773437500000\t2015-03-12T00:01:39.760Z\n" + - "GEUBDFBTXXGWQFT\tNFDSBMBZFB\t11.990052223206\t560.000000000000\t2015-03-12T00:01:39.770Z\n" + - "BELCSCIUZMCFUWY\tSRSQCLKJVK\t0.007322372403\t276.781250000000\t2015-03-12T00:01:39.780Z\n" + - "TEHIOFKMQPUNEUD\tSXXBMBBOGG\t290.000000000000\t0.000000062047\t2015-03-12T00:01:39.790Z\n" + - "IFBEPWLUTGRGEIW\tMUTSHRDWCI\t681.700683593750\t0.000765276010\t2015-03-12T00:01:39.910Z\n" + - "MBJEIRSSGXDDXKD\tUSGCNKKKGI\t0.000001004210\t-1024.000000000000\t2015-03-12T00:01:39.920Z\n" + - "LXGRVRKVTIFXRLE\tVGYEPKGPSJ\t-860.750000000000\t-210.259765625000\t2015-03-12T00:01:39.930Z\n" + - "DEPQDCICIZUYOGK\tWVJFWXNHTG\t-227.859375000000\t-236.156250000000\t2015-03-12T00:01:39.940Z\n" + - "XCHCUBYPMDFJZYJ\tWYCLIXTWVG\t0.000409339424\t-175.941406250000\t2015-03-12T00:01:39.950Z\n" + - "TPCOITVXSGCPELN\tHTIWQZBCZV\t-420.375000000000\t0.005818145582\t2015-03-12T00:01:39.960Z\n" + - "QJMRPDXTXOMBKZY\tSMCKFERVGM\t10.221145391464\t512.000000000000\t2015-03-12T00:01:39.970Z\n" + - "UHHRIRJGLQNMETN\tELYYIFISZU\t375.230987548828\t0.121945030987\t2015-03-12T00:01:39.980Z\n" + - "SDRLMSHKFZJJECT\tCJCNMPYSJF\t384.000000000000\t0.000000000000\t2015-03-12T00:01:39.990Z\n" + - "MTLSJOWYLNEDVLL\tIPVOKGQWDX\t2.619887888432\t-477.522460937500\t2015-03-12T00:01:40.000Z\n"; - - assertThat(expected, "tab where timestamp > '2015-03-12T00:01:39.630Z' and not(timestamp in ('2015-03-12T00:01:39.800Z','2015-03-12T00:01:39.900Z'))"); - } - - @Test - public void testDoubleEquals() throws Exception { - createTabWithNaNs2(); - final String expected = "512.000000000000\t512.000000000000\n" + - "-512.000000000000\t-512.000000000000\n" + - "-512.000000000000\t-512.000000000000\n" + - "0.000000000000\t0.000000000000\n"; - - assertThat(expected, "select x,y from tab where x=y"); - - } - - @Test - public void testDoubleEqualsNaN() throws Exception { - createTabWithNaNs(); - final String expected4 = "SCJOUOUIGENFELW\tNaN\tNaN\t67\n" + - "LLEYMIWTCWLFORG\tNaN\tNaN\t19\n" + - "NSXHHDILELRUMMZ\tNaN\tNaN\t35\n" + - "MQMUDDCIHCNPUGJ\tNaN\tNaN\t55\n" + - "PDHHGGIWHPZRHHM\tNaN\tNaN\t19\n" + - "UWZOOVPPLIPRMDB\tNaN\tNaN\t24\n"; - - assertThat(expected4, "select id, y, z, w from tab where y = NaN and z = NaN and w > 0 and w < 100"); - } - - @Test - public void testDoubleGreaterThanLong() throws Exception { - createTabNoNaNs(); - final String expected2 = "ELLKKHTWNWIFFLR\t297.791748046875\t-3667808512242035601\n" + - "ELLKKHTWNWIFFLR\t-128.000000000000\t-2480561350807009780\n" + - "ELLKKHTWNWIFFLR\t0.000000039690\t-1353669656981228147\n" + - "ELLKKHTWNWIFFLR\t574.872116088867\t-3672802971292736086\n" + - "ELLKKHTWNWIFFLR\t0.042308801785\t-8211394673630614539\n" + - "ELLKKHTWNWIFFLR\t559.121917724609\t-8480545405650604184\n" + - "ELLKKHTWNWIFFLR\t238.864746093750\t-8379531572046504130\n" + - "ELLKKHTWNWIFFLR\t54.359863281250\t-3428995636807101867\n" + - "ELLKKHTWNWIFFLR\t0.882504612207\t-6849499820684489569\n" + - "ELLKKHTWNWIFFLR\t-763.598632812500\t-8452913288971477984\n" + - "ELLKKHTWNWIFFLR\t0.000000210756\t-6068564420724880784\n" + - "ELLKKHTWNWIFFLR\t0.000016662992\t-7248871158761080358\n" + - "ELLKKHTWNWIFFLR\t15.427758693695\t-8228471787113332608\n" + - "ELLKKHTWNWIFFLR\t257.875000000000\t-9035530510236235549\n" + - "ELLKKHTWNWIFFLR\t0.000000017807\t-7942345008044734492\n" + - "ELLKKHTWNWIFFLR\t0.000000004254\t-6954754049368371082\n" + - "ELLKKHTWNWIFFLR\t166.464355468750\t-7951399573747427375\n" + - "ELLKKHTWNWIFFLR\t-592.000000000000\t-6347971497010040712\n" + - "ELLKKHTWNWIFFLR\t0.553697407246\t-6066174730230152205\n" + - "ELLKKHTWNWIFFLR\t-523.500000000000\t-8348983847397851938\n" + - "ELLKKHTWNWIFFLR\t4.989529609680\t-8069522251723029044\n" + - "ELLKKHTWNWIFFLR\t0.000054070339\t-8854203718260377704\n" + - "ELLKKHTWNWIFFLR\t0.000041724121\t-7422008773883138925\n" + - "ELLKKHTWNWIFFLR\t15.229828834534\t-9067189034165407096\n" + - "ELLKKHTWNWIFFLR\t1.147946476936\t-6173082243678285767\n" + - "ELLKKHTWNWIFFLR\t0.002029277734\t-6870496635654489557\n" + - "ELLKKHTWNWIFFLR\t0.962346389890\t-7210334357949030384\n" + - "ELLKKHTWNWIFFLR\t-1003.000000000000\t-8466817036372362690\n" + - "ELLKKHTWNWIFFLR\t769.317382812500\t-4163745463633062001\n" + - "ELLKKHTWNWIFFLR\t5.615920782089\t-5893035837620611936\n" + - "ELLKKHTWNWIFFLR\t0.000002686209\t-6412588441789765608\n" + - "ELLKKHTWNWIFFLR\t886.468750000000\t-8988986703954297491\n" + - "ELLKKHTWNWIFFLR\t480.000000000000\t-3204352031405525466\n" + - "ELLKKHTWNWIFFLR\t0.000000062803\t-7378155554311656758\n" + - "ELLKKHTWNWIFFLR\t-1005.500000000000\t-6124707786689761772\n" + - "ELLKKHTWNWIFFLR\t0.440555199981\t-1389821736495367122\n" + - "ELLKKHTWNWIFFLR\t266.759155273438\t-5786884395180365909\n" + - "ELLKKHTWNWIFFLR\t-477.012908935547\t-8007008358829053694\n" + - "ELLKKHTWNWIFFLR\t0.000251047953\t-1192005720958947897\n" + - "ELLKKHTWNWIFFLR\t0.000171783307\t-3215580874046433001\n" + - "ELLKKHTWNWIFFLR\t351.105468750000\t-7851460397851196709\n" + - "ELLKKHTWNWIFFLR\t740.000000000000\t-9134741907814147811\n" + - "ELLKKHTWNWIFFLR\t-880.000000000000\t-8365335649241205979\n" + - "ELLKKHTWNWIFFLR\t-912.937500000000\t-8833078844097231375\n" + - "ELLKKHTWNWIFFLR\t-442.691406250000\t-7785098153707841074\n" + - "ELLKKHTWNWIFFLR\t0.001473797718\t-9127159587821404289\n" + - "ELLKKHTWNWIFFLR\t0.083041120321\t-8675132201476021699\n" + - "ELLKKHTWNWIFFLR\t3.126584589481\t-7476947810350851317\n" + - "ELLKKHTWNWIFFLR\t229.976379394531\t-7315094745979069439\n" + - "ELLKKHTWNWIFFLR\t255.432174682617\t-3735628027815901806\n"; - - assertThat(expected2, "select id,x,z from tab where x > z and id ~ 'LLK'"); - } - - @Test - public void testDoubleLessOrEqual() throws Exception { - createTabWithNaNs(); - - final String expected = "ZKDMPVRHWUVMBPS\t0.000000782469\t-0.000000782469\t0.000001559133\n" + - "ZKDMPVRHWUVMBPS\t992.000000000000\t-992.000000000000\t-964.568237304688\n" + - "ZKDMPVRHWUVMBPS\t1.501749962568\t-1.501749962568\t0.000000363599\n" + - "ZKDMPVRHWUVMBPS\t0.000000029045\t-0.000000029045\t672.000000000000\n" + - "ZKDMPVRHWUVMBPS\t705.327758789063\t-705.327758789063\t940.560058593750\n" + - "ZKDMPVRHWUVMBPS\t776.500000000000\t-776.500000000000\t0.477167338133\n" + - "ZKDMPVRHWUVMBPS\t0.000000011066\t-0.000000011066\t2.694594800472\n" + - "ZKDMPVRHWUVMBPS\t238.082031250000\t-238.082031250000\t690.500000000000\n" + - "ZKDMPVRHWUVMBPS\t0.056706264615\t-0.056706264615\t149.757812500000\n" + - "ZKDMPVRHWUVMBPS\t0.000010041330\t-0.000010041330\t0.226926967502\n" + - "ZKDMPVRHWUVMBPS\t810.505126953125\t-810.505126953125\t0.000000073849\n" + - "ZKDMPVRHWUVMBPS\t0.000000100292\t-0.000000100292\t492.164550781250\n" + - "ZKDMPVRHWUVMBPS\t0.000000005093\t-0.000000005093\t0.140176177025\n" + - "ZKDMPVRHWUVMBPS\t0.000000009899\t-0.000000009899\t0.002363841981\n" + - "ZKDMPVRHWUVMBPS\t0.163436520845\t-0.163436520845\t0.000000003471\n" + - "ZKDMPVRHWUVMBPS\t-362.312500000000\t362.312500000000\t695.000000000000\n" + - "ZKDMPVRHWUVMBPS\t440.015625000000\t-440.015625000000\t96.000000000000\n" + - "ZKDMPVRHWUVMBPS\t244.125000000000\t-244.125000000000\t592.000000000000\n" + - "ZKDMPVRHWUVMBPS\t-653.000000000000\t653.000000000000\t899.097412109375\n" + - "ZKDMPVRHWUVMBPS\t0.000029481607\t-0.000029481607\t531.110839843750\n" + - "ZKDMPVRHWUVMBPS\t3.174971699715\t-3.174971699715\t742.000000000000\n" + - "ZKDMPVRHWUVMBPS\t0.001115875493\t-0.001115875493\t0.000040224068\n" + - "ZKDMPVRHWUVMBPS\t0.236538611352\t-0.236538611352\t606.500000000000\n" + - "ZKDMPVRHWUVMBPS\t188.476562500000\t-188.476562500000\t0.202657476068\n" + - "ZKDMPVRHWUVMBPS\t1.538488507271\t-1.538488507271\t0.000005232169\n" + - "ZKDMPVRHWUVMBPS\t0.000000342807\t-0.000000342807\t375.093750000000\n" + - "ZKDMPVRHWUVMBPS\t0.000031970392\t-0.000031970392\t1.120753705502\n" + - "ZKDMPVRHWUVMBPS\t177.562500000000\t-177.562500000000\t0.606957197189\n" + - "ZKDMPVRHWUVMBPS\t0.000002141734\t-0.000002141734\t0.434345155954\n" + - "ZKDMPVRHWUVMBPS\t50.848601341248\t-50.848601341248\t0.075392298400\n" + - "ZKDMPVRHWUVMBPS\t0.929583758116\t-0.929583758116\t0.000000009447\n" + - "ZKDMPVRHWUVMBPS\t57.289062500000\t-57.289062500000\t0.000001145164\n" + - "ZKDMPVRHWUVMBPS\t0.000000030220\t-0.000000030220\t0.000000004784\n" + - "ZKDMPVRHWUVMBPS\t0.461020886898\t-0.461020886898\t0.001043495402\n" + - "ZKDMPVRHWUVMBPS\t0.000082285467\t-0.000082285467\t0.000000000000\n" + - "ZKDMPVRHWUVMBPS\t748.596679687500\t-748.596679687500\t0.066894590855\n" + - "ZKDMPVRHWUVMBPS\t24.985045433044\t-24.985045433044\t0.000000010769\n" + - "ZKDMPVRHWUVMBPS\t0.000000164400\t-0.000000164400\t0.000000440414\n" + - "ZKDMPVRHWUVMBPS\t0.000245498741\t-0.000245498741\t32.000000000000\n" + - "ZKDMPVRHWUVMBPS\t2.650694251060\t-2.650694251060\t0.000000044308\n" + - "ZKDMPVRHWUVMBPS\t0.000123091359\t-0.000123091359\t0.000007164070\n" + - "ZKDMPVRHWUVMBPS\t0.000326511123\t-0.000326511123\t0.000377249235\n"; - - assertThat(expected, "select id, x, -x, y from tab where -x <= y and id ~ 'MBP'"); - } - - @Test - public void testDoubleOrderBy() throws Exception { - createTabWithNaNs2(); - - final String expected = "-807.692016601563\tNaN\tNaN\tNaN\n" + - "-612.000000000000\t72\t108.000000000000\t360\n" + - "-512.000000000000\t-51\t-1022.000000000000\t-255\n" + - "-481.765014648438\t-11\t-591.765014648438\t-55\n" + - "-436.000000000000\t-27\t-706.000000000000\t-135\n" + - "-338.665039062500\tNaN\tNaN\tNaN\n" + - "-256.000000000000\t57\t314.000000000000\t285\n" + - "0.000000136839\t-73\t-729.999999863161\t-365\n" + - "0.000000343896\t12\t120.000000343896\t60\n" + - "0.000001200607\t53\t530.000001200607\t265\n" + - "0.000013659448\t-57\t-569.999986340552\t-285\n" + - "0.000183005621\tNaN\tNaN\tNaN\n" + - "0.003575030481\t2\t20.003575030481\t10\n" + - "0.036795516498\tNaN\tNaN\tNaN\n" + - "0.059096898884\tNaN\tNaN\tNaN\n" + - "5.404115438461\t-79\t-784.595884561539\t-395\n" + - "5.540870904922\t-14\t-134.459129095078\t-70\n" + - "35.019264221191\t39\t425.019264221191\t195\n" + - "240.000000000000\tNaN\tNaN\tNaN\n" + - "384.000000000000\tNaN\tNaN\tNaN\n"; - - assertThat(expected, "select x,z,x+(z*10),z*5 from tab where id~'KKUSI' and ((z > -100 and z < 100) or z = NaN) order by x"); - } - - @Test - public void testDoubleOrderByNaN() throws Exception { - createTabWithNaNs2(); - - final String expected = "-338.665039062500\tNaN\tNaN\tNaN\n" + - "0.000183005621\tNaN\tNaN\tNaN\n" + - "-807.692016601563\tNaN\tNaN\tNaN\n" + - "384.000000000000\tNaN\tNaN\tNaN\n" + - "240.000000000000\tNaN\tNaN\tNaN\n" + - "0.059096898884\tNaN\tNaN\tNaN\n" + - "0.036795516498\tNaN\tNaN\tNaN\n" + - "5.404115438461\t-79\t-784.595884561539\t-395\n" + - "0.000000136839\t-73\t-729.999999863161\t-365\n" + - "0.000013659448\t-57\t-569.999986340552\t-285\n" + - "-512.000000000000\t-51\t-1022.000000000000\t-255\n" + - "-436.000000000000\t-27\t-706.000000000000\t-135\n" + - "5.540870904922\t-14\t-134.459129095078\t-70\n" + - "-481.765014648438\t-11\t-591.765014648438\t-55\n" + - "0.003575030481\t2\t20.003575030481\t10\n" + - "0.000000343896\t12\t120.000000343896\t60\n" + - "35.019264221191\t39\t425.019264221191\t195\n" + - "0.000001200607\t53\t530.000001200607\t265\n" + - "-256.000000000000\t57\t314.000000000000\t285\n" + - "-612.000000000000\t72\t108.000000000000\t360\n"; - - assertThat(expected, "select x,z,x+(z*10),z*5 from tab where id~'KKUSI' and ((z > -100 and z < 100) or z = NaN) order by z"); - } - - @Test - public void testInAsColumn() throws Exception { - try (JournalWriter w = getFactory().writer(Quote.class, "q")) { - TestUtils.generateQuoteData(w, 3600 * 24, DateFormatUtils.parseDateTime("2015-02-12T03:00:00.000Z"), Dates.SECOND_MILLIS); - w.commit(); - } - - final String expected = "BP.L\t0.000000253226\t1022.955993652344\t2015-02-13T02:59:34.000Z\ttrue\n" + - "GKN.L\t688.000000000000\t256.000000000000\t2015-02-13T02:59:50.000Z\tfalse\n"; - - assertThat(expected, "select sym, bid, ask, timestamp, sym in ('BP.L', 'TLW.L', 'ABF.L') from q latest by sym where sym in ('GKN.L', 'BP.L') and ask > 100"); - } - - @Test - public void testInAsColumnAliased() throws Exception { - try (JournalWriter w = getFactory().writer(Quote.class, "q")) { - TestUtils.generateQuoteData(w, 3600 * 24, DateFormatUtils.parseDateTime("2015-02-12T03:00:00.000Z"), Dates.SECOND_MILLIS); - w.commit(); - } - - final String expected = "BP.L\t0.000000253226\t1022.955993652344\t2015-02-13T02:59:34.000Z\ttrue\n" + - "GKN.L\t688.000000000000\t256.000000000000\t2015-02-13T02:59:50.000Z\tfalse\n"; - - assertThat(expected, "select sym, bid, ask, timestamp, sym in ('BP.L', 'TLW.L', 'ABF.L') from q a latest by sym where a.sym in ('GKN.L', 'BP.L') and a.ask > 100"); - } - - @Test - public void testIntComparison() throws Exception { - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab"). - $sym("id").index().buckets(128). - $double("x"). - $double("y"). - $int("i1"). - $int("i2"). - $ts() - - )) { - - Rnd rnd = new Rnd(); - ObjHashSet names = getNames(rnd, 128); - - int mask = 127; - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - - for (int i = 0; i < 10000; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putSym(0, names.get(rnd.nextInt() & mask)); - ew.putDouble(1, rnd.nextDouble()); - ew.putDouble(2, rnd.nextDouble()); - ew.putInt(3, rnd.nextInt() & 63); - ew.putInt(4, rnd.nextInt() & 63); - ew.putDate(5, t += 10); - ew.append(); - } - w.commit(); - } - - final String expected1 = "XSPEPTTKIBWFCKD\t290.742401123047\t0.000001862155\t2\t1\n" + - "XSPEPTTKIBWFCKD\t294.856933593750\t-539.875854492188\t55\t42\n" + - "XSPEPTTKIBWFCKD\t422.000000000000\t0.000001386965\t58\t54\n"; - - assertThat(expected1, "select id,x,y,i1,i2 from tab where i1 >= i2 and x>=y and x>=i1 and id = 'XSPEPTTKIBWFCKD'"); - - final String expected2 = "XSPEPTTKIBWFCKD\t0.007556580706\t-444.759765625000\t14\t20\n" + - "XSPEPTTKIBWFCKD\t0.002191273379\t-587.421875000000\t1\t33\n" + - "XSPEPTTKIBWFCKD\t0.000000050401\t-873.569183349609\t34\t41\n" + - "XSPEPTTKIBWFCKD\t0.000000002468\t-1009.435546875000\t7\t35\n" + - "XSPEPTTKIBWFCKD\t0.000000134022\t0.000000010189\t38\t44\n" + - "XSPEPTTKIBWFCKD\t0.053807163611\t0.000000005584\t18\t40\n" + - "XSPEPTTKIBWFCKD\t307.605468750000\t0.000000032526\t5\t49\n" + - "XSPEPTTKIBWFCKD\t588.000000000000\t0.000029410815\t42\t62\n" + - "XSPEPTTKIBWFCKD\t102.474868774414\t-704.000000000000\t61\t63\n" + - "XSPEPTTKIBWFCKD\t0.000166006441\t-400.250000000000\t23\t49\n" + - "XSPEPTTKIBWFCKD\t0.006018321496\t0.000000163838\t21\t55\n" + - "XSPEPTTKIBWFCKD\t82.432384490967\t0.000043923766\t36\t45\n" + - "XSPEPTTKIBWFCKD\t256.000000000000\t-648.000000000000\t12\t46\n" + - "XSPEPTTKIBWFCKD\t384.875000000000\t0.000049836333\t23\t46\n" + - "XSPEPTTKIBWFCKD\t0.000000883287\t-844.890625000000\t4\t24\n" + - "XSPEPTTKIBWFCKD\t0.103299163282\t0.000076360289\t16\t54\n" + - "XSPEPTTKIBWFCKD\t0.003647925099\t0.000000019679\t15\t38\n" + - "XSPEPTTKIBWFCKD\t0.000589750460\t0.000000023659\t4\t39\n"; - - assertThat(expected2, "select id,x,y,i1,i2 from tab where i1 < i2 and x>=y and y z and w > 0 and id ~ '^YY'"); - } - - @Test - public void testIntLessOrEqual() throws Exception { - createTabWithNaNs2(); - - final String expected = "GWFFYUDEYYQEHBH\t99\ttrue\n" + - "ZVRLPTYXYGYFUXC\t100\ttrue\n" + - "BROMNXKUIZULIGY\t98\ttrue\n" + - "QZVKHTLQZSLQVFG\t96\ttrue\n" + - "NWDSWLUVDRHFBCZ\t100\ttrue\n" + - "NKGQVZWEVQTQOZK\t96\ttrue\n" + - "RQLGYDONNLITWGL\t94\ttrue\n" + - "KFIJZZYNPPBXBHV\t94\ttrue\n" + - "HYBTVZNCLNXFSUW\t100\ttrue\n" + - "WSWSRGOONFCLTJC\t98\ttrue\n" + - "KUNRDCWNPQYTEWH\t93\ttrue\n" + - "VCVUYGMBMKSCPWL\t94\ttrue\n" + - "KIWIHBROKZKUTIQ\t90\ttrue\n" + - "SJOJIPHZEPIHVLT\t93\ttrue\n" + - "ZSFXUNYQXTGNJJI\t95\ttrue\n" + - "YUHNBCCPMOOUHWU\t93\ttrue\n" + - "UGGLNYRZLCBDMIG\t94\ttrue\n" + - "NZVDJIGSYLXGYTE\t93\ttrue\n" + - "PDHHGGIWHPZRHHM\t99\ttrue\n" + - "FUUTOMFUIOXLQLU\t100\ttrue\n" + - "BHLNEJRMDIKDISG\t100\ttrue\n" + - "IOLYLPGZHITQJLK\t95\ttrue\n" + - "WCCNGTNLEGPUHHI\t91\ttrue\n" + - "PPRGSXBHYSBQYMI\t90\ttrue\n" + - "CMONRCXNUZFNWHF\t97\ttrue\n" + - "KBBQFNPOYNNCTFS\t92\ttrue\n" + - "KUNRDCWNPQYTEWH\t92\ttrue\n" + - "NMUREIJUHCLQCMZ\t94\ttrue\n" + - "THMHZNVZHCNXZEQ\t100\ttrue\n" + - "SNGIZRPFMDVVGSV\t93\ttrue\n" + - "UXBWYWRLHUHJECI\t96\ttrue\n" + - "BHLNEJRMDIKDISG\t94\ttrue\n" + - "CIWXCYXGDHUWEPV\t97\ttrue\n" + - "KFMQNTOGMXUKLGM\t100\ttrue\n" + - "ZJSVTNPIWZNFKPE\t97\ttrue\n" + - "YUHNBCCPMOOUHWU\t96\ttrue\n" + - "UMKUBKXPMSXQSTV\t95\ttrue\n" + - "PXMKJSMKIXEYVTU\t96\ttrue\n" + - "KOJSOLDYRODIPUN\t90\ttrue\n" + - "FOWLPDXYSBEOUOJ\t91\ttrue\n" + - "BHLNEJRMDIKDISG\t93\ttrue\n" + - "PNXHQUTZODWKOCP\t99\ttrue\n" + - "NZVDJIGSYLXGYTE\t91\ttrue\n" + - "RZUPVQFULMERTPI\t100\ttrue\n" + - "PNXHQUTZODWKOCP\t95\ttrue\n" + - "HOLNVTIQBZXIOVI\t100\ttrue\n" + - "XSLUQDYOPHNIMYF\t98\ttrue\n" + - "VTJWCPSWHYRXPEH\t95\ttrue\n" + - "STYSWHLSWPFHXDB\t100\ttrue\n" + - "NWDSWLUVDRHFBCZ\t90\ttrue\n" + - "DLRBIDSTDTFBYHS\t98\ttrue\n" + - "JUEBWVLOMPBETTT\t97\ttrue\n" + - "CCYVBDMQEHDHQHK\t95\ttrue\n" + - "HBXOWVYUVVRDPCH\t96\ttrue\n" + - "NWDSWLUVDRHFBCZ\t97\ttrue\n" + - "VFZFKWZLUOGXHFV\t100\ttrue\n" + - "SCJOUOUIGENFELW\t93\ttrue\n" + - "CNGZTOYTOXRSFPV\t93\ttrue\n" + - "GZJYYFLSVIHDWWL\t100\ttrue\n" + - "IWEODDBHEVGXYHJ\t97\ttrue\n" + - "PDHHGGIWHPZRHHM\t96\ttrue\n" + - "WSWSRGOONFCLTJC\t100\ttrue\n" + - "YSSMPGLUOHNZHZS\t96\ttrue\n" + - "BHLNEJRMDIKDISG\t97\ttrue\n" + - "NRXGZSXUXIBBTGP\t100\ttrue\n" + - "FIEVMKPYVGPYKKB\t96\ttrue\n" + - "KOJSOLDYRODIPUN\t91\ttrue\n" + - "XWCKYLSUWDSWUGS\t92\ttrue\n" + - "YYVSYYEQBORDTQH\t97\ttrue\n" + - "JWIMGPLRQUJJFGQ\t96\ttrue\n" + - "XZOUICWEKGHVUVS\t97\ttrue\n" + - "KBBQFNPOYNNCTFS\t95\ttrue\n" + - "IFGZUFEVTEROCBP\t92\ttrue\n" + - "VFZFKWZLUOGXHFV\t95\ttrue\n" + - "KJSMSSUQSRLTKVV\t90\ttrue\n" + - "VMCGFNWGRMDGGIJ\t95\ttrue\n" + - "YSSMPGLUOHNZHZS\t98\ttrue\n" + - "KIWIHBROKZKUTIQ\t92\ttrue\n" + - "YYPDVRGRQGKNPHK\t99\ttrue\n" + - "SHRUEDRQQULOFJG\t96\ttrue\n" + - "VFZFKWZLUOGXHFV\t94\ttrue\n" + - "NMUREIJUHCLQCMZ\t96\ttrue\n" + - "PPRGSXBHYSBQYMI\t98\ttrue\n" + - "KOJSOLDYRODIPUN\t95\ttrue\n" + - "QFNIZOSBOSEPGIU\t94\ttrue\n" + - "PNXHQUTZODWKOCP\t92\ttrue\n" + - "PNXHQUTZODWKOCP\t93\ttrue\n" + - "PXMKJSMKIXEYVTU\t96\ttrue\n" + - "NZVDJIGSYLXGYTE\t94\ttrue\n" + - "JCTIZKYFLUHZQSN\t99\ttrue\n" + - "EEHRUGPBMBTKVSB\t95\ttrue\n" + - "TRDLVSYLMSRHGKR\t97\ttrue\n" + - "MQMUDDCIHCNPUGJ\t100\ttrue\n" + - "KIWIHBROKZKUTIQ\t90\ttrue\n" + - "EDNKRCGKSQDCMUM\t95\ttrue\n" + - "NZVDJIGSYLXGYTE\t96\ttrue\n" + - "SNGIZRPFMDVVGSV\t97\ttrue\n" + - "NZVDJIGSYLXGYTE\t90\ttrue\n" + - "WSWSRGOONFCLTJC\t99\ttrue\n" + - "BSQCNSFFLTRYZUZ\t94\ttrue\n" + - "ETJRSZSRYRFBVTM\t100\ttrue\n" + - "QZVKHTLQZSLQVFG\t91\ttrue\n" + - "DVIKRPCFECGPVRB\t93\ttrue\n"; - - assertThat(expected, "select id, w, w <= 100 from tab where w <= 100 and w >= 90"); - - final String expected2 = "QBUYZVQQHSQSPZP\tNaN\tfalse\n" + - "QBUYZVQQHSQSPZP\tNaN\tfalse\n" + - "QBUYZVQQHSQSPZP\tNaN\tfalse\n" + - "QBUYZVQQHSQSPZP\tNaN\tfalse\n" + - "QBUYZVQQHSQSPZP\tNaN\tfalse\n" + - "QBUYZVQQHSQSPZP\tNaN\tfalse\n" + - "QBUYZVQQHSQSPZP\tNaN\tfalse\n" + - "QBUYZVQQHSQSPZP\tNaN\tfalse\n" + - "QBUYZVQQHSQSPZP\tNaN\tfalse\n" + - "QBUYZVQQHSQSPZP\tNaN\tfalse\n" + - "QBUYZVQQHSQSPZP\tNaN\tfalse\n" + - "QBUYZVQQHSQSPZP\tNaN\tfalse\n" + - "QBUYZVQQHSQSPZP\tNaN\tfalse\n" + - "QBUYZVQQHSQSPZP\tNaN\tfalse\n"; - - assertThat(expected2, "select id, w, w <= 100 from tab where w = NaN and id ~ 'SQS'"); - } - - @Test - public void testIntMultiplication() throws Exception { - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab"). - $int("x"). - $int("y"). - $str("z"). - $ts() - - )) { - - Rnd rnd = new Rnd(); - - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - - for (int i = 0; i < 1000; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putInt(0, rnd.nextInt() & 255); - ew.putInt(1, rnd.nextInt() & 255); - ew.putStr(2, rnd.nextString(4)); - ew.putDate(3, t += 10); - ew.append(); - } - w.commit(); - } - - final String expected1 = "29512\t-129\t119\t248\tCBJF\t2015-03-12T00:00:01.370Z\n" + - "30906\t49\t202\t153\tCJZJ\t2015-03-12T00:00:07.470Z\n" + - "2508\t113\t132\t19\tCGCJ\t2015-03-12T00:00:09.070Z\n"; - - assertThat(expected1, "select x * y, x - y, x, y, z, timestamp from tab where z ~ '^C.*J+'"); - } - - @Test - public void testIntervalAndIndexHeapSearch() throws Exception { - try (JournalWriter w = getFactory().writer(Quote.class, "q")) { - TestUtils.generateQuoteData(w, 3600 * 24 * 10, DateFormatUtils.parseDateTime("2015-02-12T03:00:00.000Z"), Dates.SECOND_MILLIS); - w.commit(); - } - - final String expected = - "ADM.L\t837.343750000000\t0.061431560665\t2015-02-12T10:00:04.000Z\n" + - "BP.L\t564.425537109375\t0.000000003711\t2015-02-12T10:00:40.000Z\n" + - "WTB.L\t646.000000000000\t512.000000000000\t2015-02-12T10:00:55.000Z\n" + - "WTB.L\t1024.000000000000\t0.000036626770\t2015-02-12T10:01:02.000Z\n" + - "WTB.L\t676.215667724609\t0.000000047206\t2015-02-12T10:01:09.000Z\n" + - "BP.L\t768.000000000000\t0.000000011709\t2015-02-12T10:01:18.000Z\n" + - "BP.L\t512.000000000000\t74.948242187500\t2015-02-12T10:01:31.000Z\n" + - "WTB.L\t784.000000000000\t320.000000000000\t2015-02-12T10:01:36.000Z\n" + - "BP.L\t980.000000000000\t133.570312500000\t2015-02-12T10:02:14.000Z\n" + - "ADM.L\t768.000000000000\t296.109375000000\t2015-02-12T10:02:35.000Z\n" + - "WTB.L\t1024.000000000000\t0.000000055754\t2015-02-12T10:02:38.000Z\n" + - "BP.L\t807.750000000000\t705.548904418945\t2015-02-12T10:02:49.000Z\n" + - "BP.L\t949.156250000000\t63.068359375000\t2015-02-12T10:02:53.000Z\n" + - "WTB.L\t505.468750000000\t1024.000000000000\t2015-02-12T10:03:09.000Z\n" + - "ADM.L\t768.000000000000\t0.000047940810\t2015-02-12T10:03:19.000Z\n" + - "BP.L\t968.953491210938\t0.029868379235\t2015-02-12T10:03:21.000Z\n" + - "ADM.L\t512.000000000000\t0.000000000000\t2015-02-12T10:03:31.000Z\n" + - "WTB.L\t1024.000000000000\t0.001693658938\t2015-02-12T10:03:32.000Z\n" + - "WTB.L\t642.662750244141\t1008.000000000000\t2015-02-12T10:03:53.000Z\n" + - "BP.L\t512.000000000000\t0.000000318310\t2015-02-12T10:03:56.000Z\n" + - "BP.L\t788.000000000000\t55.569427490234\t2015-02-12T10:04:02.000Z\n" + - "BP.L\t768.000000000000\t924.000000000000\t2015-02-12T10:04:04.000Z\n" + - "ADM.L\t718.848632812500\t907.609375000000\t2015-02-12T10:04:13.000Z\n" + - "ADM.L\t965.062500000000\t0.000000591804\t2015-02-12T10:04:22.000Z\n" + - "ADM.L\t696.000000000000\t9.672361135483\t2015-02-12T10:04:25.000Z\n" + - "BP.L\t992.000000000000\t0.750000000000\t2015-02-12T10:04:27.000Z\n" + - "WTB.L\t813.869140625000\t0.000338987120\t2015-02-12T10:04:31.000Z\n" + - "BP.L\t518.117187500000\t765.889160156250\t2015-02-12T10:04:33.000Z\n" + - "WTB.L\t824.867187500000\t350.810546875000\t2015-02-12T10:04:40.000Z\n"; - - assertThat(expected, "select sym, bid, ask, timestamp from q where timestamp = '2015-02-12T10:00:00;5m' and sym in ('BP.L','ADM.L', 'WTB.L') and bid > 500"); - } - - @Test - public void testIntervalAndIndexSearch() throws Exception { - try (JournalWriter w = getFactory().writer(Quote.class, "q")) { - TestUtils.generateQuoteData(w, 3600 * 24 * 10, DateFormatUtils.parseDateTime("2015-02-12T03:00:00.000Z"), Dates.SECOND_MILLIS); - w.commit(); - - final String expected = "ADM.L\t837.343750000000\t0.061431560665\t2015-02-12T10:00:04.000Z\n" + - "BP.L\t564.425537109375\t0.000000003711\t2015-02-12T10:00:40.000Z\n" + - "BP.L\t768.000000000000\t0.000000011709\t2015-02-12T10:01:18.000Z\n" + - "BP.L\t512.000000000000\t74.948242187500\t2015-02-12T10:01:31.000Z\n" + - "BP.L\t980.000000000000\t133.570312500000\t2015-02-12T10:02:14.000Z\n" + - "ADM.L\t768.000000000000\t296.109375000000\t2015-02-12T10:02:35.000Z\n" + - "BP.L\t807.750000000000\t705.548904418945\t2015-02-12T10:02:49.000Z\n" + - "BP.L\t949.156250000000\t63.068359375000\t2015-02-12T10:02:53.000Z\n" + - "ADM.L\t768.000000000000\t0.000047940810\t2015-02-12T10:03:19.000Z\n" + - "BP.L\t968.953491210938\t0.029868379235\t2015-02-12T10:03:21.000Z\n" + - "ADM.L\t512.000000000000\t0.000000000000\t2015-02-12T10:03:31.000Z\n" + - "BP.L\t512.000000000000\t0.000000318310\t2015-02-12T10:03:56.000Z\n" + - "BP.L\t788.000000000000\t55.569427490234\t2015-02-12T10:04:02.000Z\n" + - "BP.L\t768.000000000000\t924.000000000000\t2015-02-12T10:04:04.000Z\n" + - "ADM.L\t718.848632812500\t907.609375000000\t2015-02-12T10:04:13.000Z\n" + - "ADM.L\t965.062500000000\t0.000000591804\t2015-02-12T10:04:22.000Z\n" + - "ADM.L\t696.000000000000\t9.672361135483\t2015-02-12T10:04:25.000Z\n" + - "BP.L\t992.000000000000\t0.750000000000\t2015-02-12T10:04:27.000Z\n" + - "BP.L\t518.117187500000\t765.889160156250\t2015-02-12T10:04:33.000Z\n"; - assertThat(expected, "select sym, bid, ask, timestamp from q where timestamp = '2015-02-12T10:00:00;5m' and sym in ('BP.L','ADM.L') and bid > 500"); - } - } - - @Test - public void testIntervalIntrinsicFalse() throws Exception { - try (JournalWriter w = getFactory().writer(Quote.class, "q")) { - TestUtils.generateQuoteData(w, 3600 * 24 * 10, DateFormatUtils.parseDateTime("2015-02-12T03:00:00.000Z"), Dates.SECOND_MILLIS); - w.commit(); - assertEmpty("select sym, bid, ask, timestamp from q where timestamp = '2015-02-12T10:00:00' and timestamp = '2015-02-12T12:00:00'"); - } - } - - @Test - public void testIntrinsicFalseModel() throws Exception { - createTabWithNaNs2(); - assertEmpty("(select timestamp+1 ts, sum(y) from tab sample by 1d) timestamp(ts) where ts != ts"); - } - - @Test - public void testIntrinsicGreater() throws Exception { - createTabWithSymbol(); - final String expected = "YNLERUGEWULQWLN\tCJCNMPYSJF\t439.851211547852\t0.000417203366\t2015-03-12T00:01:39.800Z\n" + - "OIBUGYXIMDIDNRO\tMRFPKLNWQL\t0.000245904943\t0.049118923023\t2015-03-12T00:01:39.810Z\n" + - "XXTPBXNCJEDGPLH\tDLQJBVVTTV\t58.250000000000\t0.191959321499\t2015-03-12T00:01:39.820Z\n" + - "ZNIFDRPHNGTNJJP\tKIWPCXCIGW\t666.264648437500\t0.000283217822\t2015-03-12T00:01:39.830Z\n" + - "ONIJMVFQFDBOMQB\tEDBVUVMLSX\t0.000000120621\t-694.250000000000\t2015-03-12T00:01:39.840Z\n" + - "UCSOZSLOQGPOHIM\tOJPOHDOWSK\t29.429825782776\t-13.079589843750\t2015-03-12T00:01:39.850Z\n" + - "VVOFHXMMEJXJNRD\tVZQSGLLZQG\t-384.000000000000\t0.006880680798\t2015-03-12T00:01:39.860Z\n" + - "WDDZKIFCBRMKKRH\tMERDPIDQGJ\t387.875000000000\t0.000000007496\t2015-03-12T00:01:39.870Z\n" + - "UPJFSREKEUNMKWO\tCWOFRMJORR\t642.000000000000\t1.016614258289\t2015-03-12T00:01:39.880Z\n" + - "TMIWHRQISSCIGXL\tRULHMZROYY\t-736.000000000000\t0.000000238132\t2015-03-12T00:01:39.890Z\n" + - "WJWZBSMWXQOFNRO\tDZDUVNCYYV\t9.389577388763\t8.453002452850\t2015-03-12T00:01:39.900Z\n"; - - assertThat(expected, "tab where timestamp > '2015-03-12T00:01:39.630Z' and timestamp in ('2015-03-12T00:01:39.800Z','2015-03-12T00:01:39.900Z')"); - assertThat(expected, "tab where timestamp >= '2015-03-12T00:01:39.630Z' and timestamp in ('2015-03-12T00:01:39.800Z','2015-03-12T00:01:39.900Z')"); - } - - @Test - public void testIntrinsicLess() throws Exception { - createTabWithSymbol(); - final String expected = "YNLERUGEWULQWLN\tCJCNMPYSJF\t439.851211547852\t0.000417203366\t2015-03-12T00:01:39.800Z\n" + - "OIBUGYXIMDIDNRO\tMRFPKLNWQL\t0.000245904943\t0.049118923023\t2015-03-12T00:01:39.810Z\n" + - "XXTPBXNCJEDGPLH\tDLQJBVVTTV\t58.250000000000\t0.191959321499\t2015-03-12T00:01:39.820Z\n" + - "ZNIFDRPHNGTNJJP\tKIWPCXCIGW\t666.264648437500\t0.000283217822\t2015-03-12T00:01:39.830Z\n" + - "ONIJMVFQFDBOMQB\tEDBVUVMLSX\t0.000000120621\t-694.250000000000\t2015-03-12T00:01:39.840Z\n" + - "UCSOZSLOQGPOHIM\tOJPOHDOWSK\t29.429825782776\t-13.079589843750\t2015-03-12T00:01:39.850Z\n" + - "VVOFHXMMEJXJNRD\tVZQSGLLZQG\t-384.000000000000\t0.006880680798\t2015-03-12T00:01:39.860Z\n" + - "WDDZKIFCBRMKKRH\tMERDPIDQGJ\t387.875000000000\t0.000000007496\t2015-03-12T00:01:39.870Z\n" + - "UPJFSREKEUNMKWO\tCWOFRMJORR\t642.000000000000\t1.016614258289\t2015-03-12T00:01:39.880Z\n" + - "TMIWHRQISSCIGXL\tRULHMZROYY\t-736.000000000000\t0.000000238132\t2015-03-12T00:01:39.890Z\n" + - "WJWZBSMWXQOFNRO\tDZDUVNCYYV\t9.389577388763\t8.453002452850\t2015-03-12T00:01:39.900Z\n"; - - assertThat(expected, "tab where timestamp < '2015-03-12T00:01:40.000Z' and timestamp in ('2015-03-12T00:01:39.800Z','2015-03-12T00:01:39.900Z')"); - assertThat(expected, "tab where timestamp <= '2015-03-12T00:01:40.000Z' and timestamp in ('2015-03-12T00:01:39.800Z','2015-03-12T00:01:39.900Z')"); - } - - @Test - public void testInvalidInterval() throws Exception { - createTabWithNaNs2(); - try { - expectFailure("select id, z from (tab where not(id in 'GMPLUCFTLNKYTSZ') and timestamp = '2015-12T10:00:00;5m;30m;10') where timestamp = '2015-03-12T10:00:00' and timestamp = '2015-03-12T14:00:00'"); - } catch (ParserException e) { - Assert.assertEquals(74, QueryError.getPosition()); - } - } - - @Test - public void testInvalidLatestByColumn1() throws Exception { - getFactory().writer(Quote.class, "q").close(); - try { - expectFailure("select sym, bid, ask, timestamp from q latest by symx where sym in ('GKN.L') and ask > 100"); - } catch (ParserException e) { - Assert.assertEquals(49, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "nvalid column")); - } - } - - @Test - public void testInvalidLatestByColumn2() throws Exception { - getFactory().writer(Quote.class, "q").close(); - try { - expectFailure("select sym, bid, ask, timestamp from q latest by ask where sym in ('GKN.L') and ask > 100"); - } catch (ParserException e) { - Assert.assertEquals(49, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "symbol, string, int or long column")); - } - } - - @Test - public void testInvalidLatestByColumn3() throws Exception { - getFactory().writer(Quote.class, "q").close(); - try { - expectFailure("select sym, bid, ask, timestamp from q latest by mode where sym in ('GKN.L') and ask > 100"); - } catch (ParserException e) { - Assert.assertEquals(49, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "not indexed")); - } - } - - @Test - public void testInvalidLiteralColumn() throws Exception { - getFactory().writer(Quote.class, "q").close(); - try { - expectFailure("select sym, bid, ask, timestamp1 from q latest by sym where sym in ('GKN.L') and ask > 100"); - } catch (ParserException e) { - Assert.assertEquals(22, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "nvalid column")); - } - } - - @Test - public void testInvalidTimestamp() throws Exception { - createTabWithNaNs2(); - try { - expectFailure("(select timestamp+1 ts, sum(y) from tab sample by 1d) timestamp(ts1) where ts != ts"); - } catch (ParserException e) { - Assert.assertEquals(64, QueryError.getPosition()); - } - } - - @Test - public void testInvalidVirtualColumn() throws Exception { - getFactory().writer(Quote.class, "q").close(); - try { - expectFailure("select sym, (bid+ask2)/2, timestamp from q latest by sym where sym in ('GKN.L') and ask > 100"); - } catch (ParserException e) { - Assert.assertEquals(17, QueryError.getPosition()); - } - } - - @Test - public void testInvalidWhereColumn1() throws Exception { - getFactory().writer(Quote.class, "q").close(); - try { - expectFailure("select sym, bid, ask, timestamp from q where sym2 in ('GKN.L') and ask > 100"); - } catch (ParserException e) { - Assert.assertEquals(45, QueryError.getPosition()); - } - } - - @Test - public void testInvalidWhereColumn2() throws Exception { - getFactory().writer(Quote.class, "q").close(); - try { - expectFailure("select sym, bid, ask, timestamp from q where sym in ('GKN.L') and ask2 > 100"); - } catch (ParserException e) { - Assert.assertEquals(66, QueryError.getPosition()); - } - } - - @Test - public void testJournalDoesNotExist() { - try { - expectFailure("select id, x, y, timestamp from q where id = "); - } catch (ParserException e) { - Assert.assertEquals(32, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "does not exist")); - } - } - - @Test - public void testJournalRefresh() throws Exception { - createTabWithNaNs(); - assertThat("10000\n", "select count() from tab"); - try (JournalWriter w = getFactory().writer("tab")) { - w.setSequentialAccess(true); - appendNaNs(w, DateFormatUtils.parseDateTime("2015-10-12T00:00:00.000Z")); - } - assertThat("20000\n", "select count() from tab"); - } - - @Test - public void testLatestByStr() throws Exception { - - createIndexedTab(); - - final String expected = "BVUDTGKDFEPWZYM\t0.000039040189\t-1024.000000000000\t2015-03-12T00:01:04.890Z\n" + - "COPMLLOUWWZXQEL\t0.000000431389\t0.046957752667\t2015-03-12T00:01:10.010Z\n"; - - assertThat(expected, "select id, x, y, timestamp from tab latest by id where id in ('COPMLLOUWWZXQEL', 'BVUDTGKDFEPWZYM')"); - } - - @Test - public void testLatestByStrFilterOnSym() throws Exception { - createTabWithSymbol(); - final String expected = "TEHIOFKMQPUNEUD\tMRFPKLNWQL\t0.020352731459\t0.165701057762\t2015-03-12T00:01:22.640Z\n"; - assertThat(expected, "select id, sym, x, y, timestamp from tab latest by id where id = 'TEHIOFKMQPUNEUD' and sym in ('MRFPKLNWQL')"); - assertThat(expected, "select id, sym, x, y, timestamp from tab latest by id where id = 'TEHIOFKMQPUNEUD' and sym = ('MRFPKLNWQL')"); - assertThat(expected, "select id, sym, x, y, timestamp from tab latest by id where id = 'TEHIOFKMQPUNEUD' and 'MRFPKLNWQL' = sym"); - } - - @Test - public void testLatestByStrIrrelevantFilter() throws Exception { - createIndexedTab(); - try { - expectFailure("select id, x, y, timestamp from tab latest by id where x > y"); - } catch (ParserException e) { - Assert.assertEquals(46, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "column expected")); - } - } - - @Test - public void testLatestByStrNoFilter() throws Exception { - createIndexedTab(); - try { - expectFailure("select id, x, y, timestamp from tab latest by id"); - } catch (ParserException e) { - Assert.assertEquals(46, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Only SYM columns")); - } - } - - @Test - public void testLatestBySym() throws Exception { - try (JournalWriter w = getFactory().writer(Quote.class, "q")) { - TestUtils.generateQuoteData(w, 3600 * 24, DateFormatUtils.parseDateTime("2015-02-12T03:00:00.000Z"), Dates.SECOND_MILLIS); - w.commit(); - } - - final String expected = "TLW.L\t0.000000000000\t0.000000048727\t2015-02-13T02:58:41.000Z\n" + - "ADM.L\t0.000000106175\t0.102090202272\t2015-02-13T02:58:59.000Z\n" + - "ABF.L\t0.000701488039\t382.432617187500\t2015-02-13T02:59:25.000Z\n" + - "RRS.L\t161.155059814453\t809.607971191406\t2015-02-13T02:59:26.000Z\n" + - "BP.L\t0.000003149229\t0.000005004517\t2015-02-13T02:59:40.000Z\n" + - "GKN.L\t0.101824980229\t1024.000000000000\t2015-02-13T02:59:48.000Z\n" + - "AGK.L\t0.905496925116\t72.000000000000\t2015-02-13T02:59:53.000Z\n" + - "WTB.L\t0.006673692260\t348.000000000000\t2015-02-13T02:59:57.000Z\n" + - "BT-A.L\t0.000000500809\t0.000879329862\t2015-02-13T02:59:58.000Z\n" + - "LLOY.L\t0.000000328173\t288.000000000000\t2015-02-13T02:59:59.000Z\n"; - - assertThat(expected, "select sym, bid, ask, timestamp from q latest by sym where bid < ask"); - } - - @Test - public void testLatestBySymList() throws Exception { - try (JournalWriter w = getFactory().writer(Quote.class, "q")) { - TestUtils.generateQuoteData(w, 3600 * 24, DateFormatUtils.parseDateTime("2015-02-12T03:00:00.000Z"), Dates.SECOND_MILLIS); - w.commit(); - } - - final String expected = "BP.L\t0.000000253226\t1022.955993652344\t2015-02-13T02:59:34.000Z\n" + - "GKN.L\t688.000000000000\t256.000000000000\t2015-02-13T02:59:50.000Z\n"; - assertThat(expected, "select sym, bid, ask, timestamp from q latest by sym where sym in ('GKN.L', 'BP.L') and ask > 100"); - } - - @Test - public void testLatestBySymNoFilter() throws Exception { - try (JournalWriter w = getFactory().writer(Quote.class, "q")) { - TestUtils.generateQuoteData(w, 3600 * 24, DateFormatUtils.parseDateTime("2015-02-12T03:00:00.000Z"), Dates.SECOND_MILLIS); - w.commit(); - } - - final String expected = "RRS.L\t946.798400878906\t0.012493257411\t2015-02-13T02:59:43.000Z\n" + - "ABF.L\t800.000000000000\t0.000625604152\t2015-02-13T02:59:46.000Z\n" + - "GKN.L\t688.000000000000\t256.000000000000\t2015-02-13T02:59:50.000Z\n" + - "AGK.L\t0.905496925116\t72.000000000000\t2015-02-13T02:59:53.000Z\n" + - "ADM.L\t62.812500000000\t1.050346195698\t2015-02-13T02:59:54.000Z\n" + - "TLW.L\t584.000000000000\t0.004887015559\t2015-02-13T02:59:55.000Z\n" + - "BP.L\t512.000000000000\t0.000000007648\t2015-02-13T02:59:56.000Z\n" + - "WTB.L\t0.006673692260\t348.000000000000\t2015-02-13T02:59:57.000Z\n" + - "BT-A.L\t0.000000500809\t0.000879329862\t2015-02-13T02:59:58.000Z\n" + - "LLOY.L\t0.000000328173\t288.000000000000\t2015-02-13T02:59:59.000Z\n"; - - assertThat(expected, "select sym, bid, ask, timestamp from q latest by sym"); - } - - @Test - public void testLongConstant() throws Exception { - createTabWithNaNs2(); - final String expected = "YPHRIPZIMNZZRMF\t-99547.129409790032\t452.870590209961\n" + - "YPHRIPZIMNZZRMF\t-99208.047485351568\t791.952514648438\n" + - "YPHRIPZIMNZZRMF\t-99562.298080444336\t437.701919555664\n" + - "YPHRIPZIMNZZRMF\t-99115.172851562496\t884.827148437500\n" + - "YPHRIPZIMNZZRMF\t-99069.638671875008\t930.361328125000\n" + - "YPHRIPZIMNZZRMF\t-99116.000000000000\t884.000000000000\n" + - "YPHRIPZIMNZZRMF\t-99488.000000000000\t512.000000000000\n" + - "YPHRIPZIMNZZRMF\t-99575.083465576176\t424.916534423828\n" + - "YPHRIPZIMNZZRMF\t-99455.000000000000\t545.000000000000\n" + - "YPHRIPZIMNZZRMF\t-99385.928710937504\t614.071289062500\n" + - "YPHRIPZIMNZZRMF\t-99200.000000000000\t800.000000000000\n" + - "YPHRIPZIMNZZRMF\t-99463.482421875008\t536.517578125000\n" + - "YPHRIPZIMNZZRMF\t-99590.147300720208\t409.852699279785\n" + - "YPHRIPZIMNZZRMF\t-99592.000000000000\t408.000000000000\n" + - "YPHRIPZIMNZZRMF\t-99104.000000000000\t896.000000000000\n"; - - assertThat(expected, "select id, x - (100000000000/1000000),x from tab where x > 400 and id~'MNZ'"); - - final String expected2 = "YPHRIPZIMNZZRMF\tNaN\t0.000065929848\n" + - "YPHRIPZIMNZZRMF\tNaN\t0.000014064731\n" + - "YPHRIPZIMNZZRMF\tNaN\t0.826377153397\n" + - "YPHRIPZIMNZZRMF\tNaN\t0.000185413708\n" + - "YPHRIPZIMNZZRMF\tNaN\t884.827148437500\n" + - "YPHRIPZIMNZZRMF\tNaN\t930.361328125000\n" + - "YPHRIPZIMNZZRMF\tNaN\t884.000000000000\n" + - "YPHRIPZIMNZZRMF\tNaN\t0.205070361495\n" + - "YPHRIPZIMNZZRMF\tNaN\t0.003745394410\n" + - "YPHRIPZIMNZZRMF\tNaN\t0.000000001150\n" + - "YPHRIPZIMNZZRMF\tNaN\t614.071289062500\n" + - "YPHRIPZIMNZZRMF\tNaN\t-355.753906250000\n" + - "YPHRIPZIMNZZRMF\tNaN\t0.000002353352\n" + - "YPHRIPZIMNZZRMF\tNaN\t-290.875000000000\n" + - "YPHRIPZIMNZZRMF\tNaN\t256.000000000000\n"; - - assertThat(expected2, "select id, y - (100000000000/1000000),x from tab where y = NaN and id~'MNZ'"); - - - final String expected3 = "YPHRIPZIMNZZRMF\t100000000307\t307\n" + - "YPHRIPZIMNZZRMF\tNaN\tNaN\n" + - "YPHRIPZIMNZZRMF\t100000000135\t135\n" + - "YPHRIPZIMNZZRMF\t100000000334\t334\n" + - "YPHRIPZIMNZZRMF\t99999999962\t-38\n" + - "YPHRIPZIMNZZRMF\t99999999636\t-364\n" + - "YPHRIPZIMNZZRMF\t100000000459\t459\n" + - "YPHRIPZIMNZZRMF\t99999999925\t-75\n" + - "YPHRIPZIMNZZRMF\t99999999780\t-220\n" + - "YPHRIPZIMNZZRMF\t100000000428\t428\n" + - "YPHRIPZIMNZZRMF\t99999999793\t-207\n" + - "YPHRIPZIMNZZRMF\t99999999640\t-360\n" + - "YPHRIPZIMNZZRMF\t99999999782\t-218\n" + - "YPHRIPZIMNZZRMF\t100000000358\t358\n" + - "YPHRIPZIMNZZRMF\t99999999878\t-122\n" + - "YPHRIPZIMNZZRMF\t99999999703\t-297\n" + - "YPHRIPZIMNZZRMF\t100000000418\t418\n" + - "YPHRIPZIMNZZRMF\t100000000099\t99\n" + - "YPHRIPZIMNZZRMF\t100000000246\t246\n" + - "YPHRIPZIMNZZRMF\t100000000453\t453\n" + - "YPHRIPZIMNZZRMF\t99999999769\t-231\n" + - "YPHRIPZIMNZZRMF\t99999999815\t-185\n" + - "YPHRIPZIMNZZRMF\t100000000180\t180\n" + - "YPHRIPZIMNZZRMF\t100000000427\t427\n" + - "YPHRIPZIMNZZRMF\t99999999905\t-95\n" + - "YPHRIPZIMNZZRMF\t100000000078\t78\n" + - "YPHRIPZIMNZZRMF\t99999999909\t-91\n" + - "YPHRIPZIMNZZRMF\t100000000379\t379\n" + - "YPHRIPZIMNZZRMF\t99999999975\t-25\n" + - "YPHRIPZIMNZZRMF\t99999999626\t-374\n" + - "YPHRIPZIMNZZRMF\t100000000117\t117\n" + - "YPHRIPZIMNZZRMF\t100000000447\t447\n" + - "YPHRIPZIMNZZRMF\tNaN\tNaN\n" + - "YPHRIPZIMNZZRMF\t100000000255\t255\n" + - "YPHRIPZIMNZZRMF\tNaN\tNaN\n" + - "YPHRIPZIMNZZRMF\t100000000022\t22\n" + - "YPHRIPZIMNZZRMF\t99999999640\t-360\n" + - "YPHRIPZIMNZZRMF\t100000000025\t25\n" + - "YPHRIPZIMNZZRMF\t100000000252\t252\n" + - "YPHRIPZIMNZZRMF\t100000000105\t105\n" + - "YPHRIPZIMNZZRMF\t100000000290\t290\n" + - "YPHRIPZIMNZZRMF\t100000000346\t346\n" + - "YPHRIPZIMNZZRMF\t100000000203\t203\n" + - "YPHRIPZIMNZZRMF\t100000000446\t446\n" + - "YPHRIPZIMNZZRMF\tNaN\tNaN\n" + - "YPHRIPZIMNZZRMF\t100000000236\t236\n" + - "YPHRIPZIMNZZRMF\t99999999805\t-195\n" + - "YPHRIPZIMNZZRMF\t99999999552\t-448\n" + - "YPHRIPZIMNZZRMF\t100000000397\t397\n" + - "YPHRIPZIMNZZRMF\t100000000399\t399\n" + - "YPHRIPZIMNZZRMF\t99999999566\t-434\n" + - "YPHRIPZIMNZZRMF\tNaN\tNaN\n" + - "YPHRIPZIMNZZRMF\t100000000270\t270\n" + - "YPHRIPZIMNZZRMF\t100000000137\t137\n" + - "YPHRIPZIMNZZRMF\t100000000119\t119\n" + - "YPHRIPZIMNZZRMF\tNaN\tNaN\n" + - "YPHRIPZIMNZZRMF\t100000000246\t246\n" + - "YPHRIPZIMNZZRMF\t99999999969\t-31\n" + - "YPHRIPZIMNZZRMF\t99999999966\t-34\n" + - "YPHRIPZIMNZZRMF\t99999999656\t-344\n" + - "YPHRIPZIMNZZRMF\t99999999654\t-346\n" + - "YPHRIPZIMNZZRMF\t100000000055\t55\n" + - "YPHRIPZIMNZZRMF\t100000000487\t487\n" + - "YPHRIPZIMNZZRMF\t100000000217\t217\n" + - "YPHRIPZIMNZZRMF\t100000000242\t242\n" + - "YPHRIPZIMNZZRMF\t100000000468\t468\n" + - "YPHRIPZIMNZZRMF\t99999999656\t-344\n" + - "YPHRIPZIMNZZRMF\t100000000242\t242\n" + - "YPHRIPZIMNZZRMF\t99999999829\t-171\n" + - "YPHRIPZIMNZZRMF\t100000000407\t407\n" + - "YPHRIPZIMNZZRMF\t100000000262\t262\n" + - "YPHRIPZIMNZZRMF\t99999999836\t-164\n" + - "YPHRIPZIMNZZRMF\t100000000179\t179\n" + - "YPHRIPZIMNZZRMF\t100000000306\t306\n" + - "YPHRIPZIMNZZRMF\t99999999831\t-169\n" + - "YPHRIPZIMNZZRMF\t99999999884\t-116\n" + - "YPHRIPZIMNZZRMF\t100000000379\t379\n" + - "YPHRIPZIMNZZRMF\t99999999613\t-387\n" + - "YPHRIPZIMNZZRMF\t99999999822\t-178\n" + - "YPHRIPZIMNZZRMF\t99999999928\t-72\n" + - "YPHRIPZIMNZZRMF\t100000000428\t428\n" + - "YPHRIPZIMNZZRMF\t99999999713\t-287\n" + - "YPHRIPZIMNZZRMF\t99999999725\t-275\n" + - "YPHRIPZIMNZZRMF\tNaN\tNaN\n" + - "YPHRIPZIMNZZRMF\t100000000161\t161\n" + - "YPHRIPZIMNZZRMF\t100000000233\t233\n"; - - assertThat(expected3, "select id, z + 100000000000, z from tab where id~'MNZ'"); - } - - @Test - public void testLongEqualsInt() throws Exception { - createTabWithNaNs(); - final String expected2 = "XWCKYLSUWDSWUGS\t-392\t-392\n" + - "BHLNEJRMDIKDISG\t-168\t-168\n" + - "NZVDJIGSYLXGYTE\t345\t345\n" + - "NWDSWLUVDRHFBCZ\t316\t316\n" + - "XWCKYLSUWDSWUGS\t-276\t-276\n" + - "GZJYYFLSVIHDWWL\t-366\t-366\n" + - "DKDWOMDXCBJFRPX\t262\t262\n" + - "ZSFXUNYQXTGNJJI\t-270\t-270\n" + - "KJSMSSUQSRLTKVV\t161\t161\n" + - "WRSLBMQHGJBFQBB\t316\t316\n"; - - assertThat(expected2, "select id,z,w from tab where z = w"); - } - - @Test - public void testLongEqualsNaN() throws Exception { - createTabWithNaNs(); - final String expected = "SNGIZRPFMDVVGSV\tNaN\t928.000000000000\n" + - "QCHNDCWOJHGBBSR\tNaN\t901.750000000000\n" + - "QZVKHTLQZSLQVFG\tNaN\t1016.000000000000\n" + - "VEZDYHDHRFEVHKK\tNaN\t907.000000000000\n" + - "VEZDYHDHRFEVHKK\tNaN\t1023.510437011719\n" + - "FIEVMKPYVGPYKKB\tNaN\t1012.000000000000\n" + - "UMKUBKXPMSXQSTV\tNaN\t960.000000000000\n" + - "WRSLBMQHGJBFQBB\tNaN\t1008.655456542969\n" + - "OPJEUKWMDNZZBBU\tNaN\t969.453125000000\n" + - "UXBWYWRLHUHJECI\tNaN\t1010.221679687500\n" + - "GZJYYFLSVIHDWWL\tNaN\t1010.000000000000\n" + - "IFGZUFEVTEROCBP\tNaN\t942.821411132813\n" + - "UWZOOVPPLIPRMDB\tNaN\t1020.000000000000\n" + - "VQEBNDCQCEHNOMV\tNaN\t960.000000000000\n" + - "SNGIZRPFMDVVGSV\tNaN\t960.000000000000\n"; - - assertThat(expected, "select id, z, x from tab where z = NaN and x > 900.0"); - } - - @Test - public void testLongGreaterThanDouble() throws Exception { - createTabNoNaNs(); - final String expected3 = "KKUSIMYDXUUSKCX\t669.826049804688\t3875444123502462003\n" + - "IZKMDCXYTRVYQNF\t824.000000000000\t4688034729252126306\n" + - "CMONRCXNUZFNWHF\t615.089355468750\t7085454771022142397\n" + - "NDESHYUMEUKVZIE\t640.000000000000\t2356466624879708775\n" + - "KFMQNTOGMXUKLGM\t864.392089843750\t3177032506931624144\n" + - "IZKMDCXYTRVYQNF\t671.903076171875\t6407332390825116324\n" + - "KFMQNTOGMXUKLGM\t1016.000000000000\t4608254594945758594\n" + - "CMONRCXNUZFNWHF\t849.250000000000\t3877410618142302179\n" + - "IZKMDCXYTRVYQNF\t846.882812500000\t7942734211642082207\n" + - "IZKMDCXYTRVYQNF\t676.031250000000\t6484041992063172141\n" + - "CMONRCXNUZFNWHF\t819.046875000000\t6452582387942072011\n" + - "NDESHYUMEUKVZIE\t997.767562866211\t8812402360346018824\n" + - "NDESHYUMEUKVZIE\t736.000000000000\t4675380837596017832\n" + - "NDESHYUMEUKVZIE\t688.000000000000\t5659765607113344347\n" + - "IZKMDCXYTRVYQNF\t694.064636230469\t6468084771677377095\n" + - "KFMQNTOGMXUKLGM\t848.000000000000\t9090383113270985873\n" + - "IZKMDCXYTRVYQNF\t608.000000000000\t5070419589855070673\n" + - "KFMQNTOGMXUKLGM\t720.000000000000\t9038465588369926344\n" + - "IZKMDCXYTRVYQNF\t699.865692138672\t6213877979563893210\n" + - "KKUSIMYDXUUSKCX\t766.381103515625\t3188305102325147634\n" + - "KKUSIMYDXUUSKCX\t861.750000000000\t8337682751207954574\n"; - - assertThat(expected3, "select id,x,z from tab where z > x and id ~ 'UK|CX' and x > 600"); - } - - @Test - public void testLongIndexSearch() throws Exception { - createTabWithNaNs3(); - - assertThat("z\tw\ta\tb\n" + - "414\t-436\t0.000080571304\t-565.593750000000\n" + - "414\t-393\t352.000000000000\t-800.000000000000\n" + - "414\t136\t0.000316714002\t-742.543395996094\n" + - "414\t486\t873.480468750000\t0.000000064994\n" + - "414\t454\t-760.938842773438\t736.375000000000\n" + - "414\t-335\t0.000000009145\tNaN\n" + - "414\t126\t8.567796945572\t864.000000000000\n" + - "414\tNaN\t905.000000000000\t578.125000000000\n", - "select z, w, x a, y b from tab where z = 414", true); - - assertPlan("{\"op\":\"SelectedColumnsRecordSource\",\"src\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"JournalPartitionSource\",\"journal\":\"tab\"},\"rsrc\":{\"op\":\"KvIndexIntLookupRowSource\",\"column\":\"z\"\"value\":414}}}", - "select z, w, x a, y b from tab where z = 414"); - } - - @Test - public void testLongIndexSearch2() throws Exception { - createTabWithNaNs3(); - - assertThat("z\tw\ta\tb\n" + - "414\t-436\t0.000080571304\t-565.593750000000\n" + - "414\t-393\t352.000000000000\t-800.000000000000\n" + - "414\t136\t0.000316714002\t-742.543395996094\n" + - "414\t486\t873.480468750000\t0.000000064994\n" + - "212\t257\t0.000120815996\t-789.000000000000\n" + - "212\tNaN\t896.000000000000\t0.000287486248\n" + - "212\t-422\t0.000008381868\t928.000000000000\n" + - "212\tNaN\t0.408159479499\t-332.593750000000\n" + - "212\t-97\t0.000004313318\t1.753653943539\n" + - "212\t-112\t59.650172233582\t12.106574058533\n" + - "212\t-42\t798.500000000000\t-972.920440673828\n" + - "414\t454\t-760.938842773438\t736.375000000000\n" + - "212\t-495\t251.654296875000\t384.000000000000\n" + - "414\t-335\t0.000000009145\tNaN\n" + - "212\t252\t-520.000000000000\t182.464950561523\n" + - "414\t126\t8.567796945572\t864.000000000000\n" + - "212\t111\t0.000000037987\t256.000000000000\n" + - "212\t-428\t0.357973538339\t0.000000019578\n" + - "414\tNaN\t905.000000000000\t578.125000000000\n", - "select z, w, x a, y b from tab where z in (414,212) ", true); - - assertPlan("{\"op\":\"SelectedColumnsRecordSource\",\"src\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"JournalPartitionSource\",\"journal\":\"tab\"},\"rsrc\":{\"op\":\"KvIndexIntLookupRowSource\",\"column\":\"z\"\"value\":414}}}", - "select z, w, x a, y b from tab where z = 414"); - } - - @Test - public void testLongIndexSearch3() throws Exception { - createTabWithNaNs3(); - assertThat("z\tw\ta\tb\n" + - "212\t-428\t0.357973538339\t0.000000019578\n" + - "414\tNaN\t905.000000000000\t578.125000000000\n", - "select z, w, x a, y b from tab latest by z where z in (414,212) ", true); - } - - @Test - public void testLongLessOrEqual() throws Exception { - createTabWithNaNs2(); - final String expected = "FYXPVKNCBWLNLRH\ttrue\t-417\n" + - "FYXPVKNCBWLNLRH\ttrue\t-285\n" + - "FYXPVKNCBWLNLRH\tfalse\t425\n" + - "FYXPVKNCBWLNLRH\tfalse\tNaN\n" + - "FYXPVKNCBWLNLRH\ttrue\t-130\n" + - "FYXPVKNCBWLNLRH\ttrue\t36\n" + - "FYXPVKNCBWLNLRH\tfalse\t242\n" + - "FYXPVKNCBWLNLRH\ttrue\t-201\n" + - "FYXPVKNCBWLNLRH\ttrue\t58\n" + - "FYXPVKNCBWLNLRH\ttrue\t-181\n" + - "FYXPVKNCBWLNLRH\tfalse\t282\n" + - "FYXPVKNCBWLNLRH\tfalse\t180\n" + - "FYXPVKNCBWLNLRH\tfalse\tNaN\n" + - "FYXPVKNCBWLNLRH\tfalse\t129\n" + - "FYXPVKNCBWLNLRH\ttrue\t-106\n" + - "FYXPVKNCBWLNLRH\tfalse\t214\n" + - "FYXPVKNCBWLNLRH\tfalse\tNaN\n" + - "FYXPVKNCBWLNLRH\ttrue\t-432\n" + - "FYXPVKNCBWLNLRH\ttrue\t-82\n" + - "FYXPVKNCBWLNLRH\tfalse\tNaN\n" + - "FYXPVKNCBWLNLRH\tfalse\t156\n" + - "FYXPVKNCBWLNLRH\tfalse\t188\n" + - "FYXPVKNCBWLNLRH\tfalse\tNaN\n" + - "FYXPVKNCBWLNLRH\ttrue\t-297\n" + - "FYXPVKNCBWLNLRH\tfalse\t152\n" + - "FYXPVKNCBWLNLRH\ttrue\t-408\n" + - "FYXPVKNCBWLNLRH\tfalse\tNaN\n" + - "FYXPVKNCBWLNLRH\ttrue\t-427\n" + - "FYXPVKNCBWLNLRH\tfalse\tNaN\n" + - "FYXPVKNCBWLNLRH\tfalse\tNaN\n" + - "FYXPVKNCBWLNLRH\ttrue\t-319\n" + - "FYXPVKNCBWLNLRH\ttrue\t-139\n" + - "FYXPVKNCBWLNLRH\ttrue\t-198\n" + - "FYXPVKNCBWLNLRH\tfalse\t456\n" + - "FYXPVKNCBWLNLRH\ttrue\t-371\n" + - "FYXPVKNCBWLNLRH\ttrue\t-385\n" + - "FYXPVKNCBWLNLRH\tfalse\t452\n" + - "FYXPVKNCBWLNLRH\tfalse\t433\n" + - "FYXPVKNCBWLNLRH\ttrue\t75\n" + - "FYXPVKNCBWLNLRH\ttrue\t-57\n" + - "FYXPVKNCBWLNLRH\ttrue\t-71\n" + - "FYXPVKNCBWLNLRH\ttrue\t-56\n" + - "FYXPVKNCBWLNLRH\tfalse\t381\n" + - "FYXPVKNCBWLNLRH\tfalse\tNaN\n" + - "FYXPVKNCBWLNLRH\tfalse\t270\n" + - "FYXPVKNCBWLNLRH\ttrue\t-143\n" + - "FYXPVKNCBWLNLRH\ttrue\t-78\n" + - "FYXPVKNCBWLNLRH\ttrue\t-352\n" + - "FYXPVKNCBWLNLRH\tfalse\tNaN\n" + - "FYXPVKNCBWLNLRH\ttrue\t-494\n" + - "FYXPVKNCBWLNLRH\tfalse\t308\n" + - "FYXPVKNCBWLNLRH\ttrue\t-287\n" + - "FYXPVKNCBWLNLRH\ttrue\t79\n" + - "FYXPVKNCBWLNLRH\ttrue\t-47\n" + - "FYXPVKNCBWLNLRH\tfalse\t234\n" + - "FYXPVKNCBWLNLRH\tfalse\tNaN\n" + - "FYXPVKNCBWLNLRH\ttrue\t-207\n" + - "FYXPVKNCBWLNLRH\ttrue\t-431\n" + - "FYXPVKNCBWLNLRH\ttrue\t-415\n" + - "FYXPVKNCBWLNLRH\ttrue\t-279\n" + - "FYXPVKNCBWLNLRH\tfalse\t129\n" + - "FYXPVKNCBWLNLRH\ttrue\t-470\n" + - "FYXPVKNCBWLNLRH\ttrue\t-36\n" + - "FYXPVKNCBWLNLRH\tfalse\t113\n" + - "FYXPVKNCBWLNLRH\ttrue\t-351\n" + - "FYXPVKNCBWLNLRH\tfalse\t258\n" + - "FYXPVKNCBWLNLRH\tfalse\t250\n" + - "FYXPVKNCBWLNLRH\ttrue\t-457\n" + - "FYXPVKNCBWLNLRH\ttrue\t-332\n" + - "FYXPVKNCBWLNLRH\tfalse\t278\n" + - "FYXPVKNCBWLNLRH\ttrue\t-32\n" + - "FYXPVKNCBWLNLRH\tfalse\t328\n" + - "FYXPVKNCBWLNLRH\tfalse\t173\n" + - "FYXPVKNCBWLNLRH\tfalse\t266\n" + - "FYXPVKNCBWLNLRH\ttrue\t-419\n" + - "FYXPVKNCBWLNLRH\ttrue\t79\n" + - "FYXPVKNCBWLNLRH\tfalse\tNaN\n" + - "FYXPVKNCBWLNLRH\ttrue\t-416\n" + - "FYXPVKNCBWLNLRH\ttrue\t71\n" + - "FYXPVKNCBWLNLRH\tfalse\t269\n" + - "FYXPVKNCBWLNLRH\tfalse\t489\n" + - "FYXPVKNCBWLNLRH\ttrue\t91\n" + - "FYXPVKNCBWLNLRH\ttrue\t-387\n" + - "FYXPVKNCBWLNLRH\tfalse\t249\n" + - "FYXPVKNCBWLNLRH\ttrue\t1\n" + - "FYXPVKNCBWLNLRH\tfalse\tNaN\n" + - "FYXPVKNCBWLNLRH\ttrue\t61\n" + - "FYXPVKNCBWLNLRH\ttrue\t-265\n" + - "FYXPVKNCBWLNLRH\ttrue\t52\n" + - "FYXPVKNCBWLNLRH\ttrue\t-125\n" + - "FYXPVKNCBWLNLRH\tfalse\tNaN\n" + - "FYXPVKNCBWLNLRH\ttrue\t-29\n" + - "FYXPVKNCBWLNLRH\ttrue\t-178\n" + - "FYXPVKNCBWLNLRH\ttrue\t-349\n" + - "FYXPVKNCBWLNLRH\ttrue\t74\n" + - "FYXPVKNCBWLNLRH\ttrue\t-319\n" + - "FYXPVKNCBWLNLRH\ttrue\t-166\n" + - "FYXPVKNCBWLNLRH\tfalse\tNaN\n" + - "FYXPVKNCBWLNLRH\ttrue\t-187\n" + - "FYXPVKNCBWLNLRH\ttrue\t-163\n" + - "FYXPVKNCBWLNLRH\ttrue\t95\n"; - - assertThat(expected, "select id, z <= 100, z from tab where id = 'FYXPVKNCBWLNLRH'"); - } - - @Test - public void testLongLessThanInt() throws Exception { - createTabWithNaNs(); - final String expected3 = "OWBVDEGHLXGZMDJ\t391\t454\n" + - "OWBVDEGHLXGZMDJ\t98\t303\n" + - "OWBVDEGHLXGZMDJ\t-47\t326\n" + - "OWBVDEGHLXGZMDJ\t-232\t-37\n" + - "OWBVDEGHLXGZMDJ\t-312\t172\n" + - "OWBVDEGHLXGZMDJ\t253\t423\n" + - "OWBVDEGHLXGZMDJ\t40\t408\n" + - "OWBVDEGHLXGZMDJ\t-268\t230\n" + - "OWBVDEGHLXGZMDJ\t48\t335\n" + - "OWBVDEGHLXGZMDJ\t-283\t153\n" + - "OWBVDEGHLXGZMDJ\t183\t470\n" + - "OWBVDEGHLXGZMDJ\t-62\t359\n" + - "OWBVDEGHLXGZMDJ\t-133\t-22\n" + - "OWBVDEGHLXGZMDJ\t-166\t439\n" + - "OWBVDEGHLXGZMDJ\t339\t467\n" + - "OWBVDEGHLXGZMDJ\t-80\t367\n" + - "OWBVDEGHLXGZMDJ\t414\t491\n" + - "OWBVDEGHLXGZMDJ\t-171\t303\n" + - "OWBVDEGHLXGZMDJ\t-292\t270\n" + - "OWBVDEGHLXGZMDJ\t-323\t-105\n" + - "OWBVDEGHLXGZMDJ\t-480\t142\n" + - "OWBVDEGHLXGZMDJ\t-346\t460\n" + - "OWBVDEGHLXGZMDJ\t318\t447\n" + - "OWBVDEGHLXGZMDJ\t-257\t-93\n" + - "OWBVDEGHLXGZMDJ\t268\t326\n" + - "OWBVDEGHLXGZMDJ\t226\t388\n" + - "OWBVDEGHLXGZMDJ\t142\t256\n" + - "OWBVDEGHLXGZMDJ\t-140\t-11\n" + - "OWBVDEGHLXGZMDJ\t-199\t-31\n" + - "OWBVDEGHLXGZMDJ\t-229\t401\n" + - "OWBVDEGHLXGZMDJ\t315\t420\n" + - "OWBVDEGHLXGZMDJ\t13\t449\n" + - "OWBVDEGHLXGZMDJ\t-417\t-77\n" + - "OWBVDEGHLXGZMDJ\t-100\t97\n" + - "OWBVDEGHLXGZMDJ\t-194\t386\n"; - - assertThat(expected3, "select id, z, w from tab where z < w and id = 'OWBVDEGHLXGZMDJ'"); - } - - @Test - public void testLongNegative() throws Exception { - createTabWithNaNs2(); - - final String expected = "KKUSIMYDXUUSKCX\tNaN\tNaN\t-338.665039062500\tNaN\n" + - "KKUSIMYDXUUSKCX\t-11\t11\t-481.765014648438\t-470.765014648438\n" + - "KKUSIMYDXUUSKCX\tNaN\tNaN\t0.000183005621\tNaN\n" + - "KKUSIMYDXUUSKCX\t-79\t79\t5.404115438461\t84.404115438461\n" + - "KKUSIMYDXUUSKCX\t-27\t27\t-436.000000000000\t-409.000000000000\n" + - "KKUSIMYDXUUSKCX\tNaN\tNaN\t-807.692016601563\tNaN\n" + - "KKUSIMYDXUUSKCX\t-57\t57\t0.000013659448\t57.000013659448\n" + - "KKUSIMYDXUUSKCX\tNaN\tNaN\t384.000000000000\tNaN\n" + - "KKUSIMYDXUUSKCX\t2\t-2\t0.003575030481\t-1.996424969519\n" + - "KKUSIMYDXUUSKCX\t39\t-39\t35.019264221191\t-3.980735778809\n" + - "KKUSIMYDXUUSKCX\t-51\t51\t-512.000000000000\t-461.000000000000\n" + - "KKUSIMYDXUUSKCX\t57\t-57\t-256.000000000000\t-313.000000000000\n" + - "KKUSIMYDXUUSKCX\tNaN\tNaN\t240.000000000000\tNaN\n" + - "KKUSIMYDXUUSKCX\t72\t-72\t-612.000000000000\t-684.000000000000\n" + - "KKUSIMYDXUUSKCX\t12\t-12\t0.000000343896\t-11.999999656104\n" + - "KKUSIMYDXUUSKCX\tNaN\tNaN\t0.059096898884\tNaN\n" + - "KKUSIMYDXUUSKCX\tNaN\tNaN\t0.036795516498\tNaN\n" + - "KKUSIMYDXUUSKCX\t-73\t73\t0.000000136839\t73.000000136839\n" + - "KKUSIMYDXUUSKCX\t53\t-53\t0.000001200607\t-52.999998799393\n" + - "KKUSIMYDXUUSKCX\t-14\t14\t5.540870904922\t19.540870904922\n"; - - assertThat(expected, "select id, z, -z, x, x+-z from tab where id~'KKUSI' and ((z > -100 and z < 100) or z = NaN)"); - } - - @Test - public void testMinusInt() throws Exception { - createTabWithNaNs2(); - - final String expected = "KKUSIMYDXUUSKCX\t2\t-338.665039062500\tNaN\t-320.665039062500\tNaN\n" + - "KKUSIMYDXUUSKCX\t-485\t-481.765014648438\t-11\t23.234985351563\t-526\n" + - "KKUSIMYDXUUSKCX\t17\t0.000183005621\tNaN\t3.000183005621\tNaN\n" + - "KKUSIMYDXUUSKCX\t-229\t5.404115438461\t-79\t254.404115438461\t-338\n" + - "KKUSIMYDXUUSKCX\t237\t-436.000000000000\t-27\t-653.000000000000\t180\n" + - "KKUSIMYDXUUSKCX\t-71\t-807.692016601563\tNaN\t-716.692016601563\tNaN\n" + - "KKUSIMYDXUUSKCX\t-189\t0.000013659448\t-57\t209.000013659448\t-276\n" + - "KKUSIMYDXUUSKCX\t-397\t384.000000000000\tNaN\t801.000000000000\tNaN\n" + - "KKUSIMYDXUUSKCX\tNaN\t0.003575030481\t2\tNaN\tNaN\n" + - "KKUSIMYDXUUSKCX\t-276\t35.019264221191\t39\t331.019264221191\t-267\n" + - "KKUSIMYDXUUSKCX\t262\t-512.000000000000\t-51\t-754.000000000000\t181\n" + - "KKUSIMYDXUUSKCX\t258\t-256.000000000000\t57\t-494.000000000000\t285\n" + - "KKUSIMYDXUUSKCX\t-379\t240.000000000000\tNaN\t639.000000000000\tNaN\n" + - "KKUSIMYDXUUSKCX\tNaN\t-612.000000000000\t72\tNaN\tNaN\n" + - "KKUSIMYDXUUSKCX\t-111\t0.000000343896\t12\t131.000000343896\t-129\n" + - "KKUSIMYDXUUSKCX\t-16\t0.059096898884\tNaN\t36.059096898884\tNaN\n" + - "KKUSIMYDXUUSKCX\t-313\t0.036795516498\tNaN\t333.036795516498\tNaN\n" + - "KKUSIMYDXUUSKCX\t141\t0.000000136839\t-73\t-120.999999863161\t38\n" + - "KKUSIMYDXUUSKCX\t149\t0.000001200607\t53\t-128.999998799393\t172\n" + - "KKUSIMYDXUUSKCX\t-126\t5.540870904922\t-14\t151.540870904923\t-170\n"; - - assertThat(expected, "select id, w, x, z, x - (w-20), z + (w-30) from tab where id~'KKUSI' and ((z > -100 and z < 100) or z = NaN)"); - } - - @Test - public void testMinusLong() throws Exception { - createTabWithNaNs2(); - final String expected = "KKUSIMYDXUUSKCX\t-338.665039062500\tNaN\tNaN\tNaN\n" + - "KKUSIMYDXUUSKCX\t-481.765014648438\t-11\t-111\t-512.765014648438\n" + - "KKUSIMYDXUUSKCX\t0.000183005621\tNaN\tNaN\tNaN\n" + - "KKUSIMYDXUUSKCX\t5.404115438461\t-79\t-179\t-93.595884561539\n" + - "KKUSIMYDXUUSKCX\t-436.000000000000\t-27\t-127\t-483.000000000000\n" + - "KKUSIMYDXUUSKCX\t-807.692016601563\tNaN\tNaN\tNaN\n" + - "KKUSIMYDXUUSKCX\t0.000013659448\t-57\t-157\t-76.999986340552\n" + - "KKUSIMYDXUUSKCX\t384.000000000000\tNaN\tNaN\tNaN\n" + - "KKUSIMYDXUUSKCX\t0.003575030481\t2\t-98\t-17.996424969519\n" + - "KKUSIMYDXUUSKCX\t35.019264221191\t39\t-61\t54.019264221191\n" + - "KKUSIMYDXUUSKCX\t-512.000000000000\t-51\t-151\t-583.000000000000\n" + - "KKUSIMYDXUUSKCX\t-256.000000000000\t57\t-43\t-219.000000000000\n" + - "KKUSIMYDXUUSKCX\t240.000000000000\tNaN\tNaN\tNaN\n" + - "KKUSIMYDXUUSKCX\t-612.000000000000\t72\t-28\t-560.000000000000\n" + - "KKUSIMYDXUUSKCX\t0.000000343896\t12\t-88\t-7.999999656104\n" + - "KKUSIMYDXUUSKCX\t0.059096898884\tNaN\tNaN\tNaN\n" + - "KKUSIMYDXUUSKCX\t0.036795516498\tNaN\tNaN\tNaN\n" + - "KKUSIMYDXUUSKCX\t0.000000136839\t-73\t-173\t-92.999999863161\n" + - "KKUSIMYDXUUSKCX\t0.000001200607\t53\t-47\t33.000001200607\n" + - "KKUSIMYDXUUSKCX\t5.540870904922\t-14\t-114\t-28.459129095078\n"; - - assertThat(expected, "select id, x, z, z-100, x + (z-20) from tab where id~'KKUSI' and ((z > -100 and z < 100) or z = NaN)"); - } - - @Test - public void testMissingColumnInSelect() throws Exception { - createTabWithNaNs2(); - try { - expectFailure("select id, , z from (tab where z = NaN) where id = 'KKUSIMYDXUUSKCX'"); - } catch (ParserException e) { - Assert.assertEquals(11, QueryError.getPosition()); - } - } - - @Test - public void testMissingEqualsArgument() throws Exception { - getFactory().writer(Quote.class, "q").close(); - try { - expectFailure("select id, x, y, timestamp from q where id = "); - } catch (ParserException e) { - Assert.assertEquals(43, QueryError.getPosition()); - } - } - - @Test - public void testMultDouble() throws Exception { - createTabWithNaNs2(); - - final String expected = "-338.665039062500\t9.986581325531\t-3382.105954711791\n" + - "-481.765014648438\t0.000194547960\t-0.093726400720\n" + - "0.000183005621\t0.216939434409\t0.000039701136\n" + - "5.404115438461\t8.854092121124\t47.848535925326\n" + - "-436.000000000000\t-811.000000000000\t353596.000000000000\n" + - "-807.692016601563\t1.505146384239\t-1215.694718366707\n" + - "0.000013659448\t0.000006695827\t0.000000000091\n" + - "384.000000000000\t638.000000000000\t244992.000000000000\n" + - "0.003575030481\t0.000002332791\t0.000000008340\n" + - "35.019264221191\t89.257812500000\t3125.742919743061\n" + - "-512.000000000000\t-278.166625976563\t142421.312500000000\n" + - "-256.000000000000\t0.000000168164\t-0.000043050055\n" + - "240.000000000000\t0.000415830291\t0.099799269810\n" + - "-612.000000000000\t0.000000004888\t-0.000002991690\n" + - "0.000000343896\tNaN\tNaN\n" + - "0.059096898884\t0.000015207836\t0.000000898736\n" + - "0.036795516498\tNaN\tNaN\n" + - "0.000000136839\t-560.000000000000\t-0.000076629905\n" + - "0.000001200607\tNaN\tNaN\n" + - "5.540870904922\t0.000076783974\t0.000425450086\n"; - - assertThat(expected, "select x, y, x*y from tab where id~'KKUSI' and ((z > -100 and z < 100) or z = NaN)"); - } - - @Test - public void testMultInt() throws Exception { - createTabWithNaNs2(); - - final String expected = "-338.665039062500\t2\tNaN\t-330.665039062500\tNaN\n" + - "-481.765014648438\t-485\t-11\t-2421.765014648438\t959\n" + - "0.000183005621\t17\tNaN\t68.000183005621\tNaN\n" + - "5.404115438461\t-229\t-79\t-910.595884561539\t379\n" + - "-436.000000000000\t237\t-27\t512.000000000000\t-501\n" + - "-807.692016601563\t-71\tNaN\t-1091.692016601563\tNaN\n" + - "0.000013659448\t-189\t-57\t-755.999986340552\t321\n" + - "384.000000000000\t-397\tNaN\t-1204.000000000000\tNaN\n" + - "0.003575030481\tNaN\t2\tNaN\tNaN\n" + - "35.019264221191\t-276\t39\t-1068.980735778809\t591\n" + - "-512.000000000000\t262\t-51\t536.000000000000\t-575\n" + - "-256.000000000000\t258\t57\t776.000000000000\t-459\n" + - "240.000000000000\t-379\tNaN\t-1276.000000000000\tNaN\n" + - "-612.000000000000\tNaN\t72\tNaN\tNaN\n" + - "0.000000343896\t-111\t12\t-443.999999656104\t234\n" + - "0.059096898884\t-16\tNaN\t-63.940903101116\tNaN\n" + - "0.036795516498\t-313\tNaN\t-1251.963204483502\tNaN\n" + - "0.000000136839\t141\t-73\t564.000000136839\t-355\n" + - "0.000001200607\t149\t53\t596.000001200607\t-245\n" + - "5.540870904922\t-126\t-14\t-498.459129095078\t238\n"; - - assertThat(expected, "select x,w,z, x + (w * 4), z - (w*2) from tab where id~'KKUSI' and ((z > -100 and z < 100) or z = NaN)"); - - } - - @Test - public void testMultLong() throws Exception { - createTabWithNaNs2(); - - final String expected = "-338.665039062500\tNaN\tNaN\tNaN\n" + - "-481.765014648438\t-11\t-591.765014648438\t-55\n" + - "0.000183005621\tNaN\tNaN\tNaN\n" + - "5.404115438461\t-79\t-784.595884561539\t-395\n" + - "-436.000000000000\t-27\t-706.000000000000\t-135\n" + - "-807.692016601563\tNaN\tNaN\tNaN\n" + - "0.000013659448\t-57\t-569.999986340552\t-285\n" + - "384.000000000000\tNaN\tNaN\tNaN\n" + - "0.003575030481\t2\t20.003575030481\t10\n" + - "35.019264221191\t39\t425.019264221191\t195\n" + - "-512.000000000000\t-51\t-1022.000000000000\t-255\n" + - "-256.000000000000\t57\t314.000000000000\t285\n" + - "240.000000000000\tNaN\tNaN\tNaN\n" + - "-612.000000000000\t72\t108.000000000000\t360\n" + - "0.000000343896\t12\t120.000000343896\t60\n" + - "0.059096898884\tNaN\tNaN\tNaN\n" + - "0.036795516498\tNaN\tNaN\tNaN\n" + - "0.000000136839\t-73\t-729.999999863161\t-365\n" + - "0.000001200607\t53\t530.000001200607\t265\n" + - "5.540870904922\t-14\t-134.459129095078\t-70\n"; - - assertThat(expected, "select x,z,x+(z*10),z*5 from tab where id~'KKUSI' and ((z > -100 and z < 100) or z = NaN)"); - } - - @Test - public void testMultipleStrIdSearch() throws Exception { - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab"). - $str("id").index().buckets(32). - $double("x"). - $double("y"). - $ts() - - )) { - - Rnd rnd = new Rnd(); - ObjHashSet names = getNames(rnd, 1024); - - int mask = 1023; - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - - - for (int i = 0; i < 10000; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putStr(0, names.get(rnd.nextInt() & mask)); - ew.putDouble(1, rnd.nextDouble()); - ew.putDouble(2, rnd.nextDouble()); - ew.putDate(3, t += 10); - ew.append(); - } - w.commit(); - } - - final String expected = "UHUTMTRRNGCIPFZ\t0.000006506322\t-261.000000000000\t2015-03-12T00:00:00.220Z\n" + - "FZICFOQEVPXJYQR\t0.000000166602\t367.625000000000\t2015-03-12T00:00:00.260Z\n" + - "FZICFOQEVPXJYQR\t57.308933258057\t28.255742073059\t2015-03-12T00:00:09.750Z\n" + - "UHUTMTRRNGCIPFZ\t0.000005319798\t-727.000000000000\t2015-03-12T00:00:10.060Z\n" + - "FZICFOQEVPXJYQR\t-432.500000000000\t0.013725134078\t2015-03-12T00:00:13.470Z\n" + - "FZICFOQEVPXJYQR\t-247.761962890625\t768.000000000000\t2015-03-12T00:00:15.170Z\n" + - "UHUTMTRRNGCIPFZ\t438.929687500000\t0.000031495110\t2015-03-12T00:00:18.300Z\n" + - "FZICFOQEVPXJYQR\t264.789741516113\t0.033011944033\t2015-03-12T00:00:19.630Z\n" + - "FZICFOQEVPXJYQR\t6.671853065491\t1.936547994614\t2015-03-12T00:00:20.620Z\n" + - "UHUTMTRRNGCIPFZ\t864.000000000000\t-1024.000000000000\t2015-03-12T00:00:25.970Z\n" + - "UHUTMTRRNGCIPFZ\t0.002082723950\t0.000000001586\t2015-03-12T00:00:26.760Z\n" + - "UHUTMTRRNGCIPFZ\t-976.561523437500\t0.446909941733\t2015-03-12T00:00:29.530Z\n" + - "UHUTMTRRNGCIPFZ\t0.001273257891\t1.239676237106\t2015-03-12T00:00:31.270Z\n" + - "UHUTMTRRNGCIPFZ\t-287.234375000000\t236.000000000000\t2015-03-12T00:00:33.720Z\n" + - "FZICFOQEVPXJYQR\t1.589631736279\t128.217994689941\t2015-03-12T00:00:34.580Z\n" + - "UHUTMTRRNGCIPFZ\t32.605212211609\t0.000000182797\t2015-03-12T00:00:35.120Z\n" + - "UHUTMTRRNGCIPFZ\t0.000029479873\t11.629675865173\t2015-03-12T00:00:35.710Z\n" + - "UHUTMTRRNGCIPFZ\t269.668342590332\t0.000553555525\t2015-03-12T00:00:35.990Z\n" + - "UHUTMTRRNGCIPFZ\t0.000461809614\t64.250000000000\t2015-03-12T00:00:37.140Z\n" + - "FZICFOQEVPXJYQR\t-572.296875000000\t0.000020149632\t2015-03-12T00:00:37.190Z\n" + - "UHUTMTRRNGCIPFZ\t512.000000000000\t49.569551467896\t2015-03-12T00:00:40.250Z\n" + - "FZICFOQEVPXJYQR\t0.000005206652\t0.272554814816\t2015-03-12T00:00:49.770Z\n" + - "FZICFOQEVPXJYQR\t0.001125814480\t0.105613868684\t2015-03-12T00:01:06.100Z\n" + - "UHUTMTRRNGCIPFZ\t704.000000000000\t44.546960830688\t2015-03-12T00:01:06.420Z\n" + - "UHUTMTRRNGCIPFZ\t258.500000000000\t0.263136833906\t2015-03-12T00:01:07.450Z\n" + - "FZICFOQEVPXJYQR\t192.000000000000\t-380.804687500000\t2015-03-12T00:01:08.610Z\n" + - "FZICFOQEVPXJYQR\t56.567952156067\t0.086345635355\t2015-03-12T00:01:13.980Z\n" + - "UHUTMTRRNGCIPFZ\t0.000097790253\t0.000000006182\t2015-03-12T00:01:17.060Z\n" + - "FZICFOQEVPXJYQR\t128.000000000000\t469.091918945313\t2015-03-12T00:01:19.730Z\n" + - "FZICFOQEVPXJYQR\t-592.000000000000\t0.000000797945\t2015-03-12T00:01:20.410Z\n" + - "FZICFOQEVPXJYQR\t519.500000000000\t0.049629654735\t2015-03-12T00:01:22.360Z\n" + - "FZICFOQEVPXJYQR\t24.736416816711\t92.901168823242\t2015-03-12T00:01:22.830Z\n" + - "FZICFOQEVPXJYQR\t336.000000000000\t0.000000089523\t2015-03-12T00:01:26.920Z\n" + - "FZICFOQEVPXJYQR\t0.044912695885\t64.000000000000\t2015-03-12T00:01:37.820Z\n"; - - assertThat(expected, "select id, x, y, timestamp from tab where id in ('FZICFOQEVPXJYQR', 'UHUTMTRRNGCIPFZ')"); - } - - @Test - public void testMultipleStrIdSearchUsingHeapMerge() throws Exception { - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab"). - $str("id").index().buckets(32). - $double("x"). - $double("y"). - $ts() - - )) { - - Rnd rnd = new Rnd(); - ObjHashSet names = getNames(rnd, 1024); - - int mask = 1023; - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - - - for (int i = 0; i < 10000; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putStr(0, names.get(rnd.nextInt() & mask)); - ew.putDouble(1, rnd.nextDouble()); - ew.putDouble(2, rnd.nextDouble()); - ew.putDate(3, t += 10); - ew.append(); - } - w.commit(); - } - - final String expected = - "UHUTMTRRNGCIPFZ\t0.000006506322\t-261.000000000000\t2015-03-12T00:00:00.220Z\n" + - "FZICFOQEVPXJYQR\t0.000000166602\t367.625000000000\t2015-03-12T00:00:00.260Z\n" + - "KJSMSSUQSRLTKVV\t0.000000000000\t696.000000000000\t2015-03-12T00:00:01.200Z\n" + - "FZICFOQEVPXJYQR\t57.308933258057\t28.255742073059\t2015-03-12T00:00:09.750Z\n" + - "UHUTMTRRNGCIPFZ\t0.000005319798\t-727.000000000000\t2015-03-12T00:00:10.060Z\n" + - "KJSMSSUQSRLTKVV\t-512.000000000000\t12.906219482422\t2015-03-12T00:00:11.190Z\n" + - "FZICFOQEVPXJYQR\t-432.500000000000\t0.013725134078\t2015-03-12T00:00:13.470Z\n" + - "FZICFOQEVPXJYQR\t-247.761962890625\t768.000000000000\t2015-03-12T00:00:15.170Z\n" + - "UHUTMTRRNGCIPFZ\t438.929687500000\t0.000031495110\t2015-03-12T00:00:18.300Z\n" + - "FZICFOQEVPXJYQR\t264.789741516113\t0.033011944033\t2015-03-12T00:00:19.630Z\n" + - "FZICFOQEVPXJYQR\t6.671853065491\t1.936547994614\t2015-03-12T00:00:20.620Z\n" + - "KJSMSSUQSRLTKVV\t664.132812500000\t512.000000000000\t2015-03-12T00:00:25.960Z\n" + - "UHUTMTRRNGCIPFZ\t864.000000000000\t-1024.000000000000\t2015-03-12T00:00:25.970Z\n" + - "UHUTMTRRNGCIPFZ\t0.002082723950\t0.000000001586\t2015-03-12T00:00:26.760Z\n" + - "KJSMSSUQSRLTKVV\t0.000000078358\t-1024.000000000000\t2015-03-12T00:00:27.350Z\n" + - "UHUTMTRRNGCIPFZ\t-976.561523437500\t0.446909941733\t2015-03-12T00:00:29.530Z\n" + - "KJSMSSUQSRLTKVV\t192.000000000000\t984.000000000000\t2015-03-12T00:00:30.260Z\n" + - "UHUTMTRRNGCIPFZ\t0.001273257891\t1.239676237106\t2015-03-12T00:00:31.270Z\n" + - "UHUTMTRRNGCIPFZ\t-287.234375000000\t236.000000000000\t2015-03-12T00:00:33.720Z\n" + - "FZICFOQEVPXJYQR\t1.589631736279\t128.217994689941\t2015-03-12T00:00:34.580Z\n" + - "UHUTMTRRNGCIPFZ\t32.605212211609\t0.000000182797\t2015-03-12T00:00:35.120Z\n" + - "UHUTMTRRNGCIPFZ\t0.000029479873\t11.629675865173\t2015-03-12T00:00:35.710Z\n" + - "UHUTMTRRNGCIPFZ\t269.668342590332\t0.000553555525\t2015-03-12T00:00:35.990Z\n" + - "UHUTMTRRNGCIPFZ\t0.000461809614\t64.250000000000\t2015-03-12T00:00:37.140Z\n" + - "FZICFOQEVPXJYQR\t-572.296875000000\t0.000020149632\t2015-03-12T00:00:37.190Z\n" + - "UHUTMTRRNGCIPFZ\t512.000000000000\t49.569551467896\t2015-03-12T00:00:40.250Z\n" + - "FZICFOQEVPXJYQR\t0.000005206652\t0.272554814816\t2015-03-12T00:00:49.770Z\n" + - "FZICFOQEVPXJYQR\t0.001125814480\t0.105613868684\t2015-03-12T00:01:06.100Z\n" + - "UHUTMTRRNGCIPFZ\t704.000000000000\t44.546960830688\t2015-03-12T00:01:06.420Z\n" + - "UHUTMTRRNGCIPFZ\t258.500000000000\t0.263136833906\t2015-03-12T00:01:07.450Z\n" + - "FZICFOQEVPXJYQR\t192.000000000000\t-380.804687500000\t2015-03-12T00:01:08.610Z\n" + - "FZICFOQEVPXJYQR\t56.567952156067\t0.086345635355\t2015-03-12T00:01:13.980Z\n" + - "KJSMSSUQSRLTKVV\t595.603515625000\t0.000000033307\t2015-03-12T00:01:15.060Z\n" + - "UHUTMTRRNGCIPFZ\t0.000097790253\t0.000000006182\t2015-03-12T00:01:17.060Z\n" + - "FZICFOQEVPXJYQR\t128.000000000000\t469.091918945313\t2015-03-12T00:01:19.730Z\n" + - "FZICFOQEVPXJYQR\t-592.000000000000\t0.000000797945\t2015-03-12T00:01:20.410Z\n" + - "FZICFOQEVPXJYQR\t519.500000000000\t0.049629654735\t2015-03-12T00:01:22.360Z\n" + - "FZICFOQEVPXJYQR\t24.736416816711\t92.901168823242\t2015-03-12T00:01:22.830Z\n" + - "FZICFOQEVPXJYQR\t336.000000000000\t0.000000089523\t2015-03-12T00:01:26.920Z\n" + - "KJSMSSUQSRLTKVV\t0.091930281371\t482.941406250000\t2015-03-12T00:01:30.760Z\n" + - "KJSMSSUQSRLTKVV\t539.789093017578\t396.667968750000\t2015-03-12T00:01:35.470Z\n" + - "FZICFOQEVPXJYQR\t0.044912695885\t64.000000000000\t2015-03-12T00:01:37.820Z\n" + - "KJSMSSUQSRLTKVV\t10.140126943588\t0.000004704022\t2015-03-12T00:01:38.600Z\n"; - - assertThat(expected, "select id, x, y, timestamp from tab where id in ('FZICFOQEVPXJYQR', 'UHUTMTRRNGCIPFZ', 'KJSMSSUQSRLTKVV')"); - } - - @Test - public void testNegativeInt() throws Exception { - createTabWithNaNs2(); - - final String expected = "FYXPVKNCBWLNLRH\t118\t0.001198394399\t-417\t-117.998801605601\t-535\n" + - "FYXPVKNCBWLNLRH\t-344\t859.375000000000\t-285\t1203.375000000000\t59\n" + - "FYXPVKNCBWLNLRH\t31\t-664.590087890625\t425\t-695.590087890625\t394\n" + - "FYXPVKNCBWLNLRH\t-56\t0.000000020402\tNaN\t56.000000020402\tNaN\n" + - "FYXPVKNCBWLNLRH\t-293\t-864.000000000000\t-130\t-571.000000000000\t163\n" + - "FYXPVKNCBWLNLRH\tNaN\t0.000007512215\t36\tNaN\tNaN\n" + - "FYXPVKNCBWLNLRH\t165\t0.000000697772\t242\t-164.999999302228\t77\n" + - "FYXPVKNCBWLNLRH\t133\t-1024.000000000000\t-201\t-1157.000000000000\t-334\n" + - "FYXPVKNCBWLNLRH\t-399\t47.056144714355\t58\t446.056144714356\t457\n" + - "FYXPVKNCBWLNLRH\tNaN\t928.000000000000\t-181\tNaN\tNaN\n" + - "FYXPVKNCBWLNLRH\t-329\t-591.000000000000\t282\t-262.000000000000\t611\n" + - "FYXPVKNCBWLNLRH\t246\t0.000000042973\t180\t-245.999999957027\t-66\n" + - "FYXPVKNCBWLNLRH\t338\t689.625000000000\tNaN\t351.625000000000\tNaN\n" + - "FYXPVKNCBWLNLRH\t185\t74.610691070557\t129\t-110.389308929443\t-56\n" + - "FYXPVKNCBWLNLRH\tNaN\t0.000001833725\t-106\tNaN\tNaN\n" + - "FYXPVKNCBWLNLRH\t-492\t0.213398203254\t214\t492.213398203254\t706\n" + - "FYXPVKNCBWLNLRH\t196\t0.000000005970\tNaN\t-195.999999994030\tNaN\n" + - "FYXPVKNCBWLNLRH\t-268\t-872.000000000000\t-432\t-604.000000000000\t-164\n" + - "FYXPVKNCBWLNLRH\tNaN\t-761.250000000000\t-82\tNaN\tNaN\n" + - "FYXPVKNCBWLNLRH\t407\t0.000000101970\tNaN\t-406.999999898030\tNaN\n" + - "FYXPVKNCBWLNLRH\t445\t0.006385272485\t156\t-444.993614727515\t-289\n" + - "FYXPVKNCBWLNLRH\t161\t-228.232543945313\t188\t-389.232543945313\t27\n" + - "FYXPVKNCBWLNLRH\t219\t304.000000000000\tNaN\t85.000000000000\tNaN\n" + - "FYXPVKNCBWLNLRH\t112\t0.000007125924\t-297\t-111.999992874077\t-409\n" + - "FYXPVKNCBWLNLRH\t22\t410.000000000000\t152\t388.000000000000\t130\n" + - "FYXPVKNCBWLNLRH\t-27\t-719.250000000000\t-408\t-692.250000000000\t-381\n" + - "FYXPVKNCBWLNLRH\t-263\t-1024.000000000000\tNaN\t-761.000000000000\tNaN\n" + - "FYXPVKNCBWLNLRH\t-223\t0.035682333633\t-427\t223.035682333633\t-204\n" + - "FYXPVKNCBWLNLRH\t310\t-310.000000000000\tNaN\t-620.000000000000\tNaN\n" + - "FYXPVKNCBWLNLRH\t261\t-185.000000000000\tNaN\t-446.000000000000\tNaN\n" + - "FYXPVKNCBWLNLRH\t-484\t69.323999404907\t-319\t553.323999404907\t165\n" + - "FYXPVKNCBWLNLRH\t330\t0.000002720652\t-139\t-329.999997279348\t-469\n" + - "FYXPVKNCBWLNLRH\t488\t737.581054687500\t-198\t249.581054687500\t-686\n" + - "FYXPVKNCBWLNLRH\t-445\t189.171875000000\t456\t634.171875000000\t901\n" + - "FYXPVKNCBWLNLRH\t201\t-34.500000000000\t-371\t-235.500000000000\t-572\n" + - "FYXPVKNCBWLNLRH\t-22\t0.007598446216\t-385\t22.007598446216\t-363\n" + - "FYXPVKNCBWLNLRH\t196\t0.000004923836\t452\t-195.999995076164\t256\n" + - "FYXPVKNCBWLNLRH\tNaN\t0.000064058751\t433\tNaN\tNaN\n" + - "FYXPVKNCBWLNLRH\tNaN\t0.000673567469\t75\tNaN\tNaN\n" + - "FYXPVKNCBWLNLRH\t402\t0.000097944039\t-57\t-401.999902055961\t-459\n" + - "FYXPVKNCBWLNLRH\t-130\t-651.024291992188\t-71\t-521.024291992188\t59\n" + - "FYXPVKNCBWLNLRH\t-311\t858.582031250000\t-56\t1169.582031250000\t255\n" + - "FYXPVKNCBWLNLRH\t306\t0.000003057669\t381\t-305.999996942331\t75\n" + - "FYXPVKNCBWLNLRH\t-85\t0.000110899655\tNaN\t85.000110899655\tNaN\n" + - "FYXPVKNCBWLNLRH\tNaN\t103.183797836304\t270\tNaN\tNaN\n" + - "FYXPVKNCBWLNLRH\t493\t0.000000000000\t-143\t-493.000000000000\t-636\n" + - "FYXPVKNCBWLNLRH\t114\t-825.000000000000\t-78\t-939.000000000000\t-192\n" + - "FYXPVKNCBWLNLRH\t74\t718.767578125000\t-352\t644.767578125000\t-426\n" + - "FYXPVKNCBWLNLRH\t-387\t0.000007173486\tNaN\t387.000007173486\tNaN\n" + - "FYXPVKNCBWLNLRH\t161\t0.097649306059\t-494\t-160.902350693941\t-655\n" + - "FYXPVKNCBWLNLRH\t289\t507.500000000000\t308\t218.500000000000\t19\n" + - "FYXPVKNCBWLNLRH\t280\t0.082590892911\t-287\t-279.917409107089\t-567\n" + - "FYXPVKNCBWLNLRH\t-228\t0.000081144792\t79\t228.000081144792\t307\n" + - "FYXPVKNCBWLNLRH\t190\t73.875000000000\t-47\t-116.125000000000\t-237\n" + - "FYXPVKNCBWLNLRH\t-8\t0.000000007061\t234\t8.000000007061\t242\n" + - "FYXPVKNCBWLNLRH\t-315\t0.000074375428\tNaN\t315.000074375428\tNaN\n" + - "FYXPVKNCBWLNLRH\t447\t0.030170871876\t-207\t-446.969829128124\t-654\n" + - "FYXPVKNCBWLNLRH\t335\t338.981475830078\t-431\t3.981475830078\t-766\n" + - "FYXPVKNCBWLNLRH\t325\t11.184396266937\t-415\t-313.815603733063\t-740\n" + - "FYXPVKNCBWLNLRH\t336\t-534.500000000000\t-279\t-870.500000000000\t-615\n" + - "FYXPVKNCBWLNLRH\t-211\t254.718750000000\t129\t465.718750000000\t340\n" + - "FYXPVKNCBWLNLRH\t159\t0.000000478142\t-470\t-158.999999521858\t-629\n" + - "FYXPVKNCBWLNLRH\tNaN\t-489.500000000000\t-36\tNaN\tNaN\n" + - "FYXPVKNCBWLNLRH\t409\t-832.000000000000\t113\t-1241.000000000000\t-296\n" + - "FYXPVKNCBWLNLRH\tNaN\t0.000095694279\t-351\tNaN\tNaN\n" + - "FYXPVKNCBWLNLRH\t-440\t0.006677458994\t258\t440.006677458994\t698\n" + - "FYXPVKNCBWLNLRH\t490\t-796.328125000000\t250\t-1286.328125000000\t-240\n" + - "FYXPVKNCBWLNLRH\t-87\t311.858428955078\t-457\t398.858428955078\t-370\n" + - "FYXPVKNCBWLNLRH\tNaN\t0.003459116502\t-332\tNaN\tNaN\n" + - "FYXPVKNCBWLNLRH\tNaN\t0.000000003561\t278\tNaN\tNaN\n" + - "FYXPVKNCBWLNLRH\t245\t441.697952270508\t-32\t196.697952270508\t-277\n" + - "FYXPVKNCBWLNLRH\t-187\t0.041321944445\t328\t187.041321944445\t515\n" + - "FYXPVKNCBWLNLRH\t-329\t-977.315917968750\t173\t-648.315917968750\t502\n" + - "FYXPVKNCBWLNLRH\t-403\t-128.000000000000\t266\t275.000000000000\t669\n" + - "FYXPVKNCBWLNLRH\t-43\t0.000015625721\t-419\t43.000015625721\t-376\n" + - "FYXPVKNCBWLNLRH\t-276\t0.000000734143\t79\t276.000000734143\t355\n" + - "FYXPVKNCBWLNLRH\t456\t0.002172315610\tNaN\t-455.997827684390\tNaN\n" + - "FYXPVKNCBWLNLRH\t-110\t768.000000000000\t-416\t878.000000000000\t-306\n" + - "FYXPVKNCBWLNLRH\t-79\t0.000031115842\t71\t79.000031115842\t150\n" + - "FYXPVKNCBWLNLRH\t-347\t-854.062500000000\t269\t-507.062500000000\t616\n" + - "FYXPVKNCBWLNLRH\t309\t0.000000414023\t489\t-308.999999585977\t180\n" + - "FYXPVKNCBWLNLRH\t239\t-107.854492187500\t91\t-346.854492187500\t-148\n" + - "FYXPVKNCBWLNLRH\t-75\t95.421875000000\t-387\t170.421875000000\t-312\n" + - "FYXPVKNCBWLNLRH\t356\t983.109375000000\t249\t627.109375000000\t-107\n" + - "FYXPVKNCBWLNLRH\t340\t0.000000013920\t1\t-339.999999986080\t-339\n" + - "FYXPVKNCBWLNLRH\t-132\t-512.421875000000\tNaN\t-380.421875000000\tNaN\n" + - "FYXPVKNCBWLNLRH\t-318\t939.000000000000\t61\t1257.000000000000\t379\n" + - "FYXPVKNCBWLNLRH\tNaN\t65.913402557373\t-265\tNaN\tNaN\n" + - "FYXPVKNCBWLNLRH\t-270\t240.000000000000\t52\t510.000000000000\t322\n" + - "FYXPVKNCBWLNLRH\t227\t768.000000000000\t-125\t541.000000000000\t-352\n" + - "FYXPVKNCBWLNLRH\tNaN\t0.000042232014\tNaN\tNaN\tNaN\n" + - "FYXPVKNCBWLNLRH\t190\t0.000000044001\t-29\t-189.999999955999\t-219\n" + - "FYXPVKNCBWLNLRH\t-52\t-663.138671875000\t-178\t-611.138671875000\t-126\n" + - "FYXPVKNCBWLNLRH\t71\t0.013041995466\t-349\t-70.986958004534\t-420\n" + - "FYXPVKNCBWLNLRH\t-333\t0.000000001181\t74\t333.000000001181\t407\n" + - "FYXPVKNCBWLNLRH\t-102\t-767.203125000000\t-319\t-665.203125000000\t-217\n" + - "FYXPVKNCBWLNLRH\t-4\t-296.000000000000\t-166\t-292.000000000000\t-162\n" + - "FYXPVKNCBWLNLRH\t-227\t240.000000000000\tNaN\t467.000000000000\tNaN\n" + - "FYXPVKNCBWLNLRH\t222\t-980.000000000000\t-187\t-1202.000000000000\t-409\n" + - "FYXPVKNCBWLNLRH\t309\t13.880827903748\t-163\t-295.119172096252\t-472\n" + - "FYXPVKNCBWLNLRH\t-308\t161.783554077148\t95\t469.783554077148\t403\n"; - - assertThat(expected, "select id,w,x,z,x + -w, z+-w from tab where id = 'FYXPVKNCBWLNLRH'"); - } - - @Test - public void testNewLine() throws Exception { - createTabWithNaNs2(); - final String expected = "YDVRVNGSTEQODRZ\t-99\n"; - assertThat(expected, "select id, z from (tab where not (id in 'GMPLUCFTLNKYTSZ')) \n limit 1"); - } - - @Test - public void testNewLine2() throws Exception { - createTabWithNaNs2(); - final String expected = "YDVRVNGSTEQODRZ\t-513.075195312500\tNaN\t-99\t7\t2015-03-12T01:00:00.000Z\n"; - assertThat(expected, "tab where not(id in 'GMPLUCFTLNKYTSZ') \n limit 1"); - } - - @Test - public void testNewLine3() throws Exception { - createTabWithNaNs2(); - final String expected = "1\t2\n"; - assertThat(expected, "select 1 col, 2 col2 from tab\nlimit 1"); - } - - @Test - public void testNoColumns() throws Exception { - createTabWithNaNs2(); - - final String expected = "KKUSIMYDXUUSKCX\t0.000000001306\t-524.334808349609\t-163\t-214\t2015-03-14T23:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t-338.665039062500\t9.986581325531\tNaN\t2\t2015-03-21T01:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t-481.765014648438\t0.000194547960\t-11\t-485\t2015-05-17T03:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.000000010163\t334.607933044434\t425\t487\t2015-06-03T04:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t-1024.000000000000\t0.281865596771\t421\t407\t2015-06-08T04:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.000183005621\t0.216939434409\tNaN\t17\t2015-06-15T09:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t-397.171875000000\t303.623046875000\t-102\t-310\t2015-06-16T04:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.000025275158\t0.000012965906\t-320\tNaN\t2015-06-19T18:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.000005719630\t56.000000000000\t262\t-230\t2015-06-19T19:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t245.200160980225\t-720.000000000000\t393\tNaN\t2015-06-26T18:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t314.000000000000\t0.006269838428\t204\t332\t2015-07-07T21:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t-975.423828125000\t0.000010835186\t370\t-436\t2015-07-11T15:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t512.000000000000\t-352.000000000000\t-384\t306\t2015-07-13T10:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t5.404115438461\t8.854092121124\t-79\t-229\t2015-07-14T11:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t-436.000000000000\t-811.000000000000\t-27\t237\t2015-07-14T16:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t-687.623046875000\t-794.699401855469\t488\t162\t2015-07-19T12:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t-288.000000000000\t69.312500000000\t341\t-290\t2015-07-25T20:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t-807.692016601563\t1.505146384239\tNaN\t-71\t2015-08-10T06:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.944997668266\t-719.970214843750\t-116\t-82\t2015-08-10T18:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.000013659448\t0.000006695827\t-57\t-189\t2015-08-12T13:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.000845499017\t-576.000000000000\t-466\t179\t2015-08-12T14:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t238.849365234375\t0.000000004954\t202\t-22\t2015-08-13T14:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t-1024.000000000000\t0.000000000000\t329\t-18\t2015-08-14T01:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t-1024.000000000000\t-496.000000000000\t273\tNaN\t2015-08-16T18:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t384.000000000000\t638.000000000000\tNaN\t-397\t2015-08-17T14:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t320.248397827148\t0.099960185587\t169\tNaN\t2015-08-21T06:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.000065215048\t-781.699218750000\t-484\t136\t2015-08-25T17:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t1.377335935831\t-512.000000000000\t-391\t340\t2015-09-07T00:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.000158194605\t95.681182861328\t-447\t250\t2015-09-14T11:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t-768.000000000000\t0.656211644411\t190\t-174\t2015-09-19T17:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t107.280467987061\t-830.501251220703\t-352\t-15\t2015-09-28T17:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t17.522465705872\t0.001122028742\t367\t26\t2015-09-30T11:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t712.062500000000\t-722.000000000000\t-188\t-474\t2015-10-07T07:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.003575030481\t0.000002332791\t2\tNaN\t2015-10-09T03:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.000000012474\t764.072387695313\t453\t-401\t2015-10-09T12:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t35.019264221191\t89.257812500000\t39\t-276\t2015-10-11T05:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.000000369906\t0.000000267083\t432\t-20\t2015-10-13T14:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.000007178878\t0.007157569751\t-412\t-33\t2015-10-23T20:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.025878265500\t0.063682073727\t150\t145\t2015-10-29T02:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t84.000000000000\t0.000084220943\t-346\t213\t2015-11-12T04:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t9.068818807602\t21.524306297302\t494\t191\t2015-12-01T04:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t-327.500000000000\tNaN\t130\t-92\t2015-12-02T20:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t-512.000000000000\t-278.166625976563\t-51\t262\t2015-12-09T23:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t-256.000000000000\t0.000000168164\t57\t258\t2015-12-10T05:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t-267.936401367188\tNaN\t-346\tNaN\t2015-12-11T08:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t978.937500000000\t0.001185453089\t-326\t-325\t2015-12-18T19:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t2.489773750305\t104.570877075195\t108\t467\t2015-12-23T02:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t240.000000000000\t0.000415830291\tNaN\t-379\t2015-12-25T13:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.000000005017\tNaN\t-138\tNaN\t2015-12-25T17:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t896.000000000000\t4.382300496101\t-103\tNaN\t2015-12-30T01:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t-612.000000000000\t0.000000004888\t72\tNaN\t2016-01-06T14:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.000188779795\t0.000268302101\t-275\t117\t2016-01-07T00:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t1005.438659667969\t-286.437500000000\t-145\t364\t2016-01-09T15:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.000000343896\tNaN\t12\t-111\t2016-01-11T14:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.000000002748\t0.000000013812\t-171\t-358\t2016-01-13T09:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t358.500000000000\t0.000074812062\t-334\t379\t2016-01-22T03:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.059096898884\t0.000015207836\tNaN\t-16\t2016-01-24T07:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t-442.187500000000\t704.000000000000\t466\t206\t2016-01-26T06:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.000000192925\tNaN\t-424\t-9\t2016-02-08T16:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t748.446655273438\t571.218750000000\t-354\t177\t2016-02-10T10:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t11.142787933350\t0.000000077990\t-485\t357\t2016-02-19T06:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.036795516498\tNaN\tNaN\t-313\t2016-02-23T01:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t642.199157714844\t0.000001014604\t-310\tNaN\t2016-02-26T18:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.035430195741\tNaN\t424\t266\t2016-03-11T00:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.000000136839\t-560.000000000000\t-73\t141\t2016-03-13T04:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.000546713796\t131.358078002930\t-447\t183\t2016-03-23T07:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t-209.717956542969\t10.917424678802\t-451\t312\t2016-03-26T11:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.000001200607\tNaN\t53\t149\t2016-04-01T04:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.000000606306\t560.000000000000\t295\t115\t2016-04-01T08:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.010378313251\t225.566406250000\t341\t-82\t2016-04-03T09:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t-894.284301757813\t0.271541014314\t-371\t189\t2016-04-15T22:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t77.797851562500\t683.051757812500\t-206\t389\t2016-04-22T23:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t176.000000000000\t0.038123233244\t-247\t334\t2016-04-28T04:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t5.540870904922\t0.000076783974\t-14\t-126\t2016-04-29T10:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.000000193413\t405.375000000000\t441\t345\t2016-04-30T13:00:00.000Z\n"; - - assertThat(expected, "tab where id = 'KKUSIMYDXUUSKCX'"); - } - - @Test - public void testOrArgCheck() { - // missing left arg on 'and' - try { - expectFailure("select id,w,x,z,x + -w, z+-w from tab where or id = 'FYXPVKNCBWLNLRH'"); - } catch (ParserException e) { - Assert.assertEquals(44, QueryError.getPosition()); - } - } - - @Test - public void testOrArgCheck2() { - // missing left arg on 'and' - try { - expectFailure("select id,w,x,z,x + -w, z+-w from tab where id = 'FYXPVKNCBWLNLRH' or"); - } catch (ParserException e) { - Assert.assertEquals(67, QueryError.getPosition()); - } - } - - @Test - public void testOrderByReplace() throws Exception { - tabOfDates(); - assertThat("x\ttimestamp\n" + - "2016, Oct 10\t2016-10-10T00:00:00.000Z\n" + - "2016, Oct 11\t2016-10-11T00:00:00.000Z\n" + - "2016, Oct 12\t2016-10-12T00:00:00.000Z\n" + - "2016, Oct 13\t2016-10-13T00:00:00.000Z\n" + - "2016, Oct 14\t2016-10-14T00:00:00.000Z\n" + - "2016, Oct 15\t2016-10-15T00:00:00.000Z\n" + - "2016, Oct 16\t2016-10-16T00:00:00.000Z\n" + - "2016, Oct 17\t2016-10-17T00:00:00.000Z\n" + - "2016, Oct 18\t2016-10-18T00:00:00.000Z\n" + - "2016, Oct 19\t2016-10-19T00:00:00.000Z\n", - "select replace('(.+) (.+)$', '$2, $1', dtoa4(timestamp)) x, timestamp from tab order by x asc limit 10", true); - } - - @Test - public void testParamInLimit() throws Exception { - createTabWithNaNs2(); - - final String expected = "YDVRVNGSTEQODRZ\t-99\n" + - "RIIYMHOWKCDNZNL\t-397\n" + - "XZOUICWEKGHVUVS\t367\n" + - "FDTNPHFLPBNHGZW\t356\n" + - "MQMUDDCIHCNPUGJ\t304\n" + - "HYBTVZNCLNXFSUW\t-276\n" + - "UMKUBKXPMSXQSTV\t-100\n" + - "KJSMSSUQSRLTKVV\t345\n" + - "HOLNVTIQBZXIOVI\t112\n" + - "ZSFXUNYQXTGNJJI\t-162\n"; - - sink.clear(); - try (RecordSource src = compile("select id, z from tab limit :xyz")) { - src.getParam(":xyz").set(10L); - printer.print(src, getFactory(), false); - TestUtils.assertEquals(expected, sink); - } - - // and one more time - sink.clear(); - try (RecordSource src = compile("select id, z from tab limit :xyz")) { - src.getParam(":xyz").set(10L); - printer.print(src, getFactory(), false); - TestUtils.assertEquals(expected, sink); - } - - // and now change parameter - sink.clear(); - try (RecordSource src = compile("select id, z from tab limit :xyz")) { - src.getParam(":xyz").set(5L); - printer.print(src, getFactory(), false); - - final String expected2 = "YDVRVNGSTEQODRZ\t-99\n" + - "RIIYMHOWKCDNZNL\t-397\n" + - "XZOUICWEKGHVUVS\t367\n" + - "FDTNPHFLPBNHGZW\t356\n" + - "MQMUDDCIHCNPUGJ\t304\n"; - TestUtils.assertEquals(expected2, sink); - } - } - - @Test - public void testParamInQuery() throws Exception { - createTabWithNaNs2(); - - final String expected = "NDESHYUMEUKVZIE\t485\n" + - "LLEYMIWTCWLFORG\t456\n" + - "EOCVFFKMEKPFOYM\t481\n" + - "NZVDJIGSYLXGYTE\t489\n" + - "KIWIHBROKZKUTIQ\t498\n" + - "IWEODDBHEVGXYHJ\t463\n" + - "WCCNGTNLEGPUHHI\t452\n" + - "EENNEBQQEMXDKXE\t492\n" + - "BSQCNSFFLTRYZUZ\t494\n" + - "QBUYZVQQHSQSPZP\t452\n"; - - sink.clear(); - try (RecordSource src = compile("select id, z from tab where z > :min limit :lim")) { - src.getParam(":min").set(450); - src.getParam(":lim").set(10L); - printer.print(src, getFactory(), false); - } - - sink.clear(); - try (RecordSource src = compile("select id, z from tab where :min < z limit :lim")) { - src.getParam(":min").set(450); - src.getParam(":lim").set(10L); - printer.print(src, getFactory(), false); - TestUtils.assertEquals(expected, sink); - } - } - - @Test(expected = JournalRuntimeException.class) - public void testParamNotFound() throws Exception { - createTabWithNaNs2(); - try (RecordSource src = compile("select id, z from tab where z > :min limit :lim")) { - src.getParam(":xyz"); - } - } - - @Test(expected = UndefinedParameterException.class) - public void testParamNotSet() throws Exception { - createTabWithNaNs2(); - sink.clear(); - try (RecordSource src = compile("select id, z from tab where z > :min limit :lim")) { - printer.print(src, getFactory(), false); - } - } - - @Test - public void testPluck() throws Exception { - createTabWithNaNs(); - assertThat("BROMNXKUIZULIGY\tM\n" + - "BROMNXKUIZULIGY\tM\n" + - "BROMNXKUIZULIGY\tM\n" + - "BROMNXKUIZULIGY\tM\n" + - "BROMNXKUIZULIGY\tM\n" + - "BROMNXKUIZULIGY\tM\n" + - "BROMNXKUIZULIGY\tM\n" + - "BROMNXKUIZULIGY\tM\n" + - "BROMNXKUIZULIGY\tM\n" + - "BROMNXKUIZULIGY\tM\n" + - "BROMNXKUIZULIGY\tM\n" + - "BROMNXKUIZULIGY\tM\n" + - "BROMNXKUIZULIGY\tM\n" + - "BROMNXKUIZULIGY\tM\n" + - "BROMNXKUIZULIGY\tM\n" + - "BROMNXKUIZULIGY\tM\n" + - "BROMNXKUIZULIGY\tM\n" + - "BROMNXKUIZULIGY\tM\n", - "select id, pluck('(?<=^.{3})(.)',id) from tab where z >= 250 and id ~ 'ULIGY'"); - } - - @Test - public void testRegexNull() throws Exception { - createTabWithNullsAndTime(); - assertThat("IBBTGPGWFFYUDEYYQEHBHF\t19:36\t2015-03-12T00:00:00.000Z\n", "tab where id ~ 'BT'"); - } - - @Test - public void testRegexSyntaxError() throws Exception { - createTabWithNaNs2(); - try { - expectFailure("select id, w from tab where id ~ 'SQS)'"); - } catch (ParserException e) { - Assert.assertEquals(37, QueryError.getPosition()); - } - } - - @Test - public void testReplace1() throws Exception { - createTabWithNaNs(); - assertThat("col0\n" + - "10 03 2015 x\n" + - "10 03 2015 x\n", - "select replace('(.+)-(.+)-(.+)$', '$3 $2 $1 x', '2015-03-10') from tab limit 2", true); - } - - @Test - public void testReplace2() throws Exception { - createTabWithNaNs(); - assertThat("col0\n" + - "10 03 2015\n" + - "10 03 2015\n", - "select replace('(.+)-(.+)-(.+)$', '$3 $2 $1', '2015-03-10') from tab limit 2", true); - - - } - - @Test - public void testReplace3() throws Exception { - createTabWithNaNs(); - assertThat("col0\n" + - "10 03 \n" + - "10 03 \n", - "select replace('(.+)-(.+)-(.+)$', '$3 $2 $10', '2015-03-10') from tab limit 2", true); - } - - @Test - public void testReplaceMissingIndexInside() throws Exception { - createTabWithNaNs(); - try { - expectFailure("select replace('(.+)-(.+)-(.+)$', '$3 $ $1', '2015-03-10') from tab limit 2"); - } catch (ParserException e) { - Assert.assertEquals(38, QueryError.getPosition()); - } - } - - @Test - public void testReplaceMissingIndexOnEdge() throws Exception { - createTabWithNaNs(); - try { - expectFailure("select replace('(.+)-(.+)-(.+)$', '$3 $2 $', '2015-03-10') from tab limit 2"); - } catch (ParserException e) { - Assert.assertEquals(41, QueryError.getPosition()); - } - } - - @Test - public void testReplaceNomatch() throws Exception { - tabOfDates(); - assertThat("col0\n" + - ", \n" + - ", \n" + - ", \n" + - ", \n" + - ", \n" + - ", \n" + - ", \n" + - ", \n" + - ", \n" + - ", \n", - "select replace('(.+)-(.+)$', '$2, $1', dtoa4(timestamp)) from tab limit 10", true); - } - - @Test - public void testReplaceNullPattern() throws Exception { - createTabWithNaNs(); - try { - expectFailure("select replace('x', null, '2015-03-10') from tab limit 2"); - } catch (ParserException e) { - Assert.assertEquals(20, QueryError.getPosition()); - } - } - - @Test - public void testReplaceNullRegex() throws Exception { - createTabWithNaNs(); - try { - expectFailure("select replace(null, '$3 $ $1', '2015-03-10') from tab limit 2"); - } catch (ParserException e) { - Assert.assertEquals(15, QueryError.getPosition()); - } - } - - @Test - public void testReplaceOnlyGroup() throws Exception { - tabOfDates(); - assertThat("col0\n" + - "8\n" + - "9\n" + - "10\n" + - "11\n" + - "12\n" + - "13\n" + - "14\n" + - "15\n" + - "16\n" + - "17\n", - "select replace(' ([0-9]+) ', '$1', dtoa4(timestamp)) from tab limit 10", true); - } - - @Test - public void testReplaceSimple() throws Exception { - tabOfDates(); - assertThat("col0\n" + - "x2016\n" + - "x2016\n" + - "x2016\n" + - "x2016\n" + - "x2016\n" + - "x2016\n" + - "x2016\n" + - "x2016\n" + - "x2016\n" + - "x2016\n", - "select replace('(.+) ', 'x', dtoa4(timestamp)) from tab limit 10", true); - } - - @Test - public void testReplaceSimpleNoFound() throws Exception { - tabOfDates(); - assertThat("col0\n" + - "Oct 8 2016\n" + - "Oct 9 2016\n" + - "Oct 10 2016\n" + - "Oct 11 2016\n" + - "Oct 12 2016\n" + - "Oct 13 2016\n" + - "Oct 14 2016\n" + - "Oct 15 2016\n" + - "Oct 16 2016\n" + - "Oct 17 2016\n", - "select replace('2017', 'x', dtoa4(timestamp)) from tab limit 10", true); - } - - @Test - public void testReplaceSimpleWithEmpty() throws Exception { - tabOfDates(); - assertThat("col0\n" + - "2016\n" + - "2016\n" + - "2016\n" + - "2016\n" + - "2016\n" + - "2016\n" + - "2016\n" + - "2016\n" + - "2016\n" + - "2016\n", - "select replace('(.+) ', '', dtoa4(timestamp)) from tab limit 10", true); - } - - @Test - public void testReplaceVar() throws Exception { - tabOfDates(); - assertThat("col0\n" + - "2016, Oct 8\n" + - "2016, Oct 9\n" + - "2016, Oct 10\n" + - "2016, Oct 11\n" + - "2016, Oct 12\n" + - "2016, Oct 13\n" + - "2016, Oct 14\n" + - "2016, Oct 15\n" + - "2016, Oct 16\n" + - "2016, Oct 17\n", - "select replace('(.+) (.+)$', '$2, $1', dtoa4(timestamp)) from tab limit 10", true); - } - - @Test - public void testScaledDoubleComparison() throws Exception { - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab"). - $sym("id").index().buckets(128). - $double("x"). - $double("y"). - $int("i1"). - $int("i2"). - $ts() - - )) { - - Rnd rnd = new Rnd(); - ObjHashSet names = getNames(rnd, 128); - - int mask = 127; - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - - for (int i = 0; i < 10000; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putSym(0, names.get(rnd.nextInt() & mask)); - ew.putDouble(1, rnd.nextDouble()); - ew.putDouble(2, rnd.nextDouble()); - ew.putInt(3, rnd.nextInt() & 63); - ew.putInt(4, rnd.nextInt() & 63); - ew.putDate(5, t += 10); - ew.append(); - } - w.commit(); - } - - final String expected = "YYVSYYEQBORDTQH\t0.000000012344\t0.000000017585\n" + - "OXPKRGIIHYHBOQM\t0.000000042571\t0.000000046094\n" + - "FUUTOMFUIOXLQLU\t0.000000009395\t0.000000017129\n" + - "SCJOUOUIGENFELW\t0.000000000000\t0.000000003106\n" + - "KIWIHBROKZKUTIQ\t0.000000001343\t0.000000006899\n" + - "KBBQFNPOYNNCTFS\t0.000000001643\t0.000000010727\n" + - "CIWXCYXGDHUWEPV\t0.000000000000\t0.000000007289\n" + - "KFIJZZYNPPBXBHV\t0.000000007000\t0.000000009292\n" + - "HBXOWVYUVVRDPCH\t0.000000000000\t0.000000005734\n" + - "XWCKYLSUWDSWUGS\t0.000000010381\t0.000000020362\n" + - "KJSMSSUQSRLTKVV\t0.000000003479\t0.000000006929\n" + - "CNGZTOYTOXRSFPV\t0.000000000000\t0.000000000000\n" + - "NMUREIJUHCLQCMZ\t0.000000001398\t0.000000004552\n" + - "KJSMSSUQSRLTKVV\t0.000000004057\t0.000000009300\n" + - "YSSMPGLUOHNZHZS\t0.000000003461\t0.000000005232\n" + - "TRDLVSYLMSRHGKR\t0.000000001688\t0.000000005004\n" + - "EOCVFFKMEKPFOYM\t0.000000002913\t0.000000000653\n" + - "JUEBWVLOMPBETTT\t0.000000000000\t0.000000001650\n" + - "VQEBNDCQCEHNOMV\t0.000000017353\t0.000000020155\n" + - "JUEBWVLOMPBETTT\t0.000000120419\t0.000000111959\n" + - "EIWFOQKYHQQUWQO\t0.000000080895\t0.000000081903\n" + - "EVMLKCJBEVLUHLI\t0.000000005365\t0.000000003773\n" + - "NZVDJIGSYLXGYTE\t0.000000022596\t0.000000017758\n" + - "EOCVFFKMEKPFOYM\t0.000000011711\t0.000000006505\n" + - "STYSWHLSWPFHXDB\t512.000000000000\t512.000000000000\n" + - "IWEODDBHEVGXYHJ\t0.000000000773\t0.000000009342\n" + - "KIWIHBROKZKUTIQ\t128.000000000000\t128.000000000000\n" + - "VQEBNDCQCEHNOMV\t0.000000003251\t0.000000000000\n" + - "BSQCNSFFLTRYZUZ\t-1024.000000000000\t-1024.000000000000\n" + - "OPJEUKWMDNZZBBU\t-1024.000000000000\t-1024.000000000000\n" + - "DOTSEDYYCTGQOLY\t0.000000004748\t0.000000004680\n" + - "CMONRCXNUZFNWHF\t0.000000000000\t0.000000003728\n" + - "HYBTVZNCLNXFSUW\t-1024.000000000000\t-1024.000000000000\n" + - "EGMITINLKFNUHNR\t0.000000017782\t0.000000023362\n" + - "UXBWYWRLHUHJECI\t0.000000009297\t0.000000009220\n" + - "HBXOWVYUVVRDPCH\t-512.000000000000\t-512.000000000000\n"; - - assertThat(expected, "select id, x, y from tab where eq(x, y, 0.00000001)"); - } - - @Test - public void testSearchByIntIdUnindexed() throws Exception { - - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab"). - $int("id"). - $double("x"). - $double("y"). - $ts() - - )) { - - Rnd rnd = new Rnd(); - int[] ids = new int[4096]; - for (int i = 0; i < ids.length; i++) { - ids[i] = rnd.nextPositiveInt(); - } - - int mask = ids.length - 1; - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - - - for (int i = 0; i < 100000; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putInt(0, ids[rnd.nextInt() & mask]); - ew.putDouble(1, rnd.nextDouble()); - ew.putDouble(2, rnd.nextDouble()); - ew.putDate(3, t += 10); - ew.append(); - } - w.commit(); - } - - final String expected = "1148688404\t19.165769577026\t0.002435457427\t2015-03-12T00:00:10.150Z\n" + - "1148688404\t0.000000444469\t2.694594800472\t2015-03-12T00:00:28.400Z\n" + - "1148688404\t-640.000000000000\t-1024.000000000000\t2015-03-12T00:01:06.260Z\n" + - "1148688404\t0.000000009509\t320.000000000000\t2015-03-12T00:01:26.010Z\n" + - "1148688404\t0.000107977266\t362.467056274414\t2015-03-12T00:01:57.750Z\n" + - "1148688404\t0.000000022366\t-451.815429687500\t2015-03-12T00:02:32.560Z\n" + - "1148688404\t0.000003631694\t152.575393676758\t2015-03-12T00:02:35.210Z\n" + - "1148688404\t-458.523437500000\t0.003299130592\t2015-03-12T00:03:09.590Z\n" + - "1148688404\t-576.000000000000\t0.000000005352\t2015-03-12T00:03:15.080Z\n" + - "1148688404\t0.000000010009\t0.000000336123\t2015-03-12T00:03:33.830Z\n" + - "1148688404\t0.012756480370\t0.191264979541\t2015-03-12T00:03:56.200Z\n" + - "1148688404\t-793.000000000000\t6.048339843750\t2015-03-12T00:04:01.350Z\n" + - "1148688404\t0.000144788552\t10.723476886749\t2015-03-12T00:04:48.380Z\n" + - "1148688404\t-467.990722656250\t5.262818336487\t2015-03-12T00:04:52.710Z\n" + - "1148688404\t0.031378546730\t149.346038818359\t2015-03-12T00:05:01.020Z\n" + - "1148688404\t0.000741893891\t-27.789062500000\t2015-03-12T00:05:19.110Z\n" + - "1148688404\t0.000000032685\t0.000000002490\t2015-03-12T00:05:26.610Z\n" + - "1148688404\t0.652305364609\t0.000000029041\t2015-03-12T00:06:56.860Z\n" + - "1148688404\t-894.000000000000\t51.695074081421\t2015-03-12T00:08:46.620Z\n" + - "1148688404\t695.000000000000\t0.145211979747\t2015-03-12T00:09:22.390Z\n" + - "1148688404\t-334.488891601563\t0.000000393977\t2015-03-12T00:09:29.860Z\n" + - "1148688404\t7.933303117752\t0.000516850792\t2015-03-12T00:10:13.730Z\n" + - "1148688404\t435.498107910156\t1.287820875645\t2015-03-12T00:10:30.240Z\n" + - "1148688404\t961.880340576172\t0.000168625862\t2015-03-12T00:10:41.190Z\n" + - "1148688404\t-84.978515625000\t0.051617769524\t2015-03-12T00:10:46.200Z\n" + - "1148688404\t0.000000544715\t0.000328194423\t2015-03-12T00:10:52.510Z\n" + - "1148688404\t512.000000000000\t875.250000000000\t2015-03-12T00:11:46.390Z\n" + - "1148688404\t0.000000010856\t0.028837248683\t2015-03-12T00:12:15.140Z\n" + - "1148688404\t0.000027862162\t-896.000000000000\t2015-03-12T00:12:28.700Z\n" + - "1148688404\t0.000000003071\t0.000025084717\t2015-03-12T00:12:36.370Z\n" + - "1148688404\t0.000040687404\t0.007985642878\t2015-03-12T00:12:42.940Z\n" + - "1148688404\t-961.937500000000\t-849.000000000000\t2015-03-12T00:12:49.940Z\n" + - "1148688404\t0.000384466533\t87.682281494141\t2015-03-12T00:14:11.980Z\n" + - "1148688404\t0.000000309420\t448.000000000000\t2015-03-12T00:15:38.730Z\n" + - "1148688404\t29.022820472717\t-123.758422851563\t2015-03-12T00:16:30.770Z\n"; - assertThat(expected, "select id, x, y, timestamp from tab where id = 1148688404"); - } - - @Test - public void testSearchByStringIdInUnindexed() throws Exception { - - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab"). - $str("id"). - $double("x"). - $double("y"). - $ts() - - )) { - - Rnd rnd = new Rnd(); - int n = 4 * 1024; - ObjHashSet names = getNames(rnd, n); - - int mask = n - 1; - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - - for (int i = 0; i < 100000; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putStr(0, names.get(rnd.nextInt() & mask)); - ew.putDouble(1, rnd.nextDouble()); - ew.putDouble(2, rnd.nextDouble()); - ew.putDate(3, t += 10); - ew.append(); - } - w.commit(); - } - - final String expected = "VEGPIGSVMYWRTXV\t0.000015968965\t675.997558593750\n" + - "VEGPIGSVMYWRTXV\t86.369699478149\t0.000017492367\n" + - "JKEQQKQWPJVCFKV\t-141.875000000000\t2.248494863510\n" + - "JKEQQKQWPJVCFKV\t-311.641113281250\t-398.023437500000\n" + - "VEGPIGSVMYWRTXV\t3.659749031067\t0.000001526956\n" + - "VEGPIGSVMYWRTXV\t-87.500000000000\t-778.964843750000\n" + - "JKEQQKQWPJVCFKV\t0.000000000841\t0.000000048359\n" + - "JKEQQKQWPJVCFKV\t4.028919816017\t576.000000000000\n" + - "VEGPIGSVMYWRTXV\t896.000000000000\t0.000000293617\n" + - "VEGPIGSVMYWRTXV\t-1024.000000000000\t0.000001939648\n" + - "VEGPIGSVMYWRTXV\t0.000019246366\t-1024.000000000000\n" + - "VEGPIGSVMYWRTXV\t410.933593750000\t0.000000039558\n" + - "JKEQQKQWPJVCFKV\t0.057562204078\t0.052935207263\n" + - "VEGPIGSVMYWRTXV\t0.000000001681\t0.000000007821\n" + - "VEGPIGSVMYWRTXV\t-1024.000000000000\t-921.363525390625\n" + - "JKEQQKQWPJVCFKV\t0.000003027280\t43.346537590027\n" + - "VEGPIGSVMYWRTXV\t0.000000009230\t99.335662841797\n" + - "JKEQQKQWPJVCFKV\t266.000000000000\t0.000033699243\n" + - "VEGPIGSVMYWRTXV\t5.966133117676\t0.000019340443\n" + - "VEGPIGSVMYWRTXV\t0.000001273319\t0.000020025251\n" + - "JKEQQKQWPJVCFKV\t0.007589547429\t0.016206960194\n" + - "JKEQQKQWPJVCFKV\t-256.000000000000\t213.664222717285\n" + - "VEGPIGSVMYWRTXV\t5.901823043823\t0.226934209466\n" + - "VEGPIGSVMYWRTXV\t0.000033694661\t0.036246776581\n" + - "JKEQQKQWPJVCFKV\t22.610988616943\t0.000000000000\n" + - "VEGPIGSVMYWRTXV\t0.000000600285\t896.000000000000\n" + - "JKEQQKQWPJVCFKV\t0.000030440875\t0.000000002590\n" + - "VEGPIGSVMYWRTXV\t-612.819580078125\t-768.000000000000\n" + - "VEGPIGSVMYWRTXV\t652.960937500000\t-163.895019531250\n" + - "JKEQQKQWPJVCFKV\t0.000001019223\t0.000861373846\n" + - "VEGPIGSVMYWRTXV\t0.000000237054\t855.149673461914\n" + - "JKEQQKQWPJVCFKV\t384.625000000000\t-762.664184570313\n" + - "VEGPIGSVMYWRTXV\t0.000000003865\t269.064453125000\n" + - "VEGPIGSVMYWRTXV\t1.651362478733\t640.000000000000\n" + - "JKEQQKQWPJVCFKV\t0.772825062275\t701.435363769531\n" + - "JKEQQKQWPJVCFKV\t191.932769775391\t0.000013081920\n" + - "JKEQQKQWPJVCFKV\t416.812500000000\t0.000000003177\n" + - "JKEQQKQWPJVCFKV\t0.000003838093\t810.968750000000\n" + - "VEGPIGSVMYWRTXV\t0.042331939563\t368.000000000000\n" + - "VEGPIGSVMYWRTXV\t0.038675817661\t-69.960937500000\n" + - "VEGPIGSVMYWRTXV\t0.154417395592\t0.000000005908\n" + - "JKEQQKQWPJVCFKV\t0.041989765130\t728.000000000000\n" + - "JKEQQKQWPJVCFKV\t0.000000000000\t-89.843750000000\n" + - "VEGPIGSVMYWRTXV\t-224.000000000000\t247.625000000000\n"; - - assertThat(expected, "select id, x,y from tab where id in ('JKEQQKQWPJVCFKV', 'VEGPIGSVMYWRTXV')"); - } - - @Test - public void testSearchByStringIdInUnindexed2() throws Exception { - - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab"). - $str("id"). - $double("x"). - $double("y"). - $ts() - - )) { - Rnd rnd = new Rnd(); - int n = 4 * 1024; - ObjHashSet names = getNames(rnd, n); - - int mask = n - 1; - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - - for (int i = 0; i < 100000; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putStr(0, names.get(rnd.nextInt() & mask)); - ew.putDouble(1, rnd.nextDouble()); - ew.putDouble(2, rnd.nextDouble()); - ew.putDate(3, t += 10); - ew.append(); - } - w.commit(); - } - - final String expected = "JKEQQKQWPJVCFKV\t-141.875000000000\t2.248494863510\n" + - "JKEQQKQWPJVCFKV\t-311.641113281250\t-398.023437500000\n" + - "JKEQQKQWPJVCFKV\t0.000000000841\t0.000000048359\n" + - "JKEQQKQWPJVCFKV\t4.028919816017\t576.000000000000\n" + - "JKEQQKQWPJVCFKV\t0.057562204078\t0.052935207263\n" + - "JKEQQKQWPJVCFKV\t0.000003027280\t43.346537590027\n" + - "JKEQQKQWPJVCFKV\t266.000000000000\t0.000033699243\n" + - "JKEQQKQWPJVCFKV\t0.007589547429\t0.016206960194\n" + - "JKEQQKQWPJVCFKV\t-256.000000000000\t213.664222717285\n" + - "JKEQQKQWPJVCFKV\t22.610988616943\t0.000000000000\n" + - "JKEQQKQWPJVCFKV\t0.000030440875\t0.000000002590\n" + - "JKEQQKQWPJVCFKV\t0.000001019223\t0.000861373846\n" + - "JKEQQKQWPJVCFKV\t384.625000000000\t-762.664184570313\n" + - "JKEQQKQWPJVCFKV\t0.772825062275\t701.435363769531\n" + - "JKEQQKQWPJVCFKV\t191.932769775391\t0.000013081920\n" + - "JKEQQKQWPJVCFKV\t416.812500000000\t0.000000003177\n" + - "JKEQQKQWPJVCFKV\t0.000003838093\t810.968750000000\n" + - "JKEQQKQWPJVCFKV\t0.041989765130\t728.000000000000\n" + - "JKEQQKQWPJVCFKV\t0.000000000000\t-89.843750000000\n"; - - assertThat(expected, "select id, x,y from tab where id in ('JKEQQKQWPJVCFKV')"); - } - - @Test - public void testSearchByStringIdIndexed() throws Exception { - - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab"). - $str("id").index().buckets(32). - $double("x"). - $double("y"). - $ts() - - )) { - - Rnd rnd = new Rnd(); - ObjHashSet names = getNames(rnd, 1024); - - int mask = 1023; - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - - - for (int i = 0; i < 100000; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putStr(0, names.get(rnd.nextInt() & mask)); - ew.putDouble(1, rnd.nextDouble()); - ew.putDouble(2, rnd.nextDouble()); - ew.putDate(3, t += 10); - ew.append(); - } - w.commit(); - } - - final String expected = "XTPNHTDCEBYWXBB\t-292.000000000000\t0.000000006354\t2015-03-12T00:00:02.290Z\n" + - "XTPNHTDCEBYWXBB\t7.197236061096\t2.818476676941\t2015-03-12T00:00:27.340Z\n" + - "XTPNHTDCEBYWXBB\t0.000005481412\t1.312383592129\t2015-03-12T00:00:29.610Z\n" + - "XTPNHTDCEBYWXBB\t446.081878662109\t0.000000051478\t2015-03-12T00:00:31.780Z\n" + - "XTPNHTDCEBYWXBB\t-809.625000000000\t0.000000104467\t2015-03-12T00:00:33.860Z\n" + - "XTPNHTDCEBYWXBB\t560.000000000000\t0.526266053319\t2015-03-12T00:00:37.440Z\n" + - "XTPNHTDCEBYWXBB\t0.000000004619\t0.000028377840\t2015-03-12T00:00:46.630Z\n" + - "XTPNHTDCEBYWXBB\t-510.983673095703\t-512.000000000000\t2015-03-12T00:00:55.090Z\n" + - "XTPNHTDCEBYWXBB\t0.000000527720\t760.000000000000\t2015-03-12T00:01:03.780Z\n" + - "XTPNHTDCEBYWXBB\t0.012854952831\t-292.297058105469\t2015-03-12T00:01:09.350Z\n" + - "XTPNHTDCEBYWXBB\t0.082818411291\t2.386151432991\t2015-03-12T00:01:10.310Z\n" + - "XTPNHTDCEBYWXBB\t330.293212890625\t-268.000000000000\t2015-03-12T00:01:12.810Z\n" + - "XTPNHTDCEBYWXBB\t278.125000000000\t0.077817678452\t2015-03-12T00:01:16.670Z\n" + - "XTPNHTDCEBYWXBB\t-448.000000000000\t0.000001829988\t2015-03-12T00:02:02.260Z\n" + - "XTPNHTDCEBYWXBB\t0.238381892443\t-935.843750000000\t2015-03-12T00:02:33.540Z\n" + - "XTPNHTDCEBYWXBB\t0.097852131352\t-120.312500000000\t2015-03-12T00:02:41.600Z\n" + - "XTPNHTDCEBYWXBB\t0.034327778034\t0.000000076055\t2015-03-12T00:02:41.860Z\n" + - "XTPNHTDCEBYWXBB\t0.016777765006\t1.525665938854\t2015-03-12T00:02:47.630Z\n" + - "XTPNHTDCEBYWXBB\t0.000000245470\t0.000000012355\t2015-03-12T00:03:21.880Z\n" + - "XTPNHTDCEBYWXBB\t38.482372283936\t156.359012603760\t2015-03-12T00:03:25.470Z\n" + - "XTPNHTDCEBYWXBB\t960.000000000000\t-561.500000000000\t2015-03-12T00:03:52.790Z\n" + - "XTPNHTDCEBYWXBB\t0.000048914401\t0.000535350249\t2015-03-12T00:03:53.420Z\n" + - "XTPNHTDCEBYWXBB\t0.315786086023\t-544.000000000000\t2015-03-12T00:04:02.560Z\n" + - "XTPNHTDCEBYWXBB\t-512.000000000000\t512.000000000000\t2015-03-12T00:04:09.410Z\n" + - "XTPNHTDCEBYWXBB\t0.000469007500\t0.000000003315\t2015-03-12T00:04:29.330Z\n" + - "XTPNHTDCEBYWXBB\t473.774108886719\t0.005739651737\t2015-03-12T00:04:49.240Z\n" + - "XTPNHTDCEBYWXBB\t77.079637527466\t-68.750000000000\t2015-03-12T00:04:54.540Z\n" + - "XTPNHTDCEBYWXBB\t1017.250000000000\t256.000000000000\t2015-03-12T00:04:59.980Z\n" + - "XTPNHTDCEBYWXBB\t979.558593750000\t0.034476440400\t2015-03-12T00:05:00.400Z\n" + - "XTPNHTDCEBYWXBB\t0.080838434398\t0.000240437294\t2015-03-12T00:05:16.590Z\n" + - "XTPNHTDCEBYWXBB\t837.343750000000\t0.000000003163\t2015-03-12T00:05:22.150Z\n" + - "XTPNHTDCEBYWXBB\t-708.738037109375\t12.065711975098\t2015-03-12T00:05:23.960Z\n" + - "XTPNHTDCEBYWXBB\t73.905494689941\t968.143554687500\t2015-03-12T00:05:30.160Z\n" + - "XTPNHTDCEBYWXBB\t858.125000000000\t0.004347450798\t2015-03-12T00:06:06.300Z\n" + - "XTPNHTDCEBYWXBB\t191.156250000000\t692.151489257813\t2015-03-12T00:06:07.380Z\n" + - "XTPNHTDCEBYWXBB\t0.000000350446\t0.001085809752\t2015-03-12T00:06:14.550Z\n" + - "XTPNHTDCEBYWXBB\t877.107116699219\t0.073764367029\t2015-03-12T00:06:26.310Z\n" + - "XTPNHTDCEBYWXBB\t4.980149984360\t0.000000005301\t2015-03-12T00:06:33.470Z\n" + - "XTPNHTDCEBYWXBB\t0.000937165081\t-204.000000000000\t2015-03-12T00:06:54.810Z\n" + - "XTPNHTDCEBYWXBB\t756.876586914063\t-572.703125000000\t2015-03-12T00:06:56.120Z\n" + - "XTPNHTDCEBYWXBB\t0.000000022885\t0.689865306020\t2015-03-12T00:06:57.920Z\n" + - "XTPNHTDCEBYWXBB\t723.500000000000\t-592.817382812500\t2015-03-12T00:07:17.570Z\n" + - "XTPNHTDCEBYWXBB\t-285.125000000000\t-448.250000000000\t2015-03-12T00:07:20.480Z\n" + - "XTPNHTDCEBYWXBB\t4.877287983894\t-870.000000000000\t2015-03-12T00:07:36.830Z\n" + - "XTPNHTDCEBYWXBB\t-638.750000000000\t-859.125000000000\t2015-03-12T00:07:38.910Z\n" + - "XTPNHTDCEBYWXBB\t757.085937500000\t-128.000000000000\t2015-03-12T00:07:45.970Z\n" + - "XTPNHTDCEBYWXBB\t0.000024196771\t44.254640579224\t2015-03-12T00:07:56.400Z\n" + - "XTPNHTDCEBYWXBB\t0.000002050660\t113.433692932129\t2015-03-12T00:08:25.690Z\n" + - "XTPNHTDCEBYWXBB\t0.001966100186\t401.331298828125\t2015-03-12T00:08:31.180Z\n" + - "XTPNHTDCEBYWXBB\t134.605468750000\t0.000778750400\t2015-03-12T00:08:34.070Z\n" + - "XTPNHTDCEBYWXBB\t304.000000000000\t170.421752929688\t2015-03-12T00:08:36.400Z\n" + - "XTPNHTDCEBYWXBB\t0.000000029559\t0.000033108370\t2015-03-12T00:08:42.110Z\n" + - "XTPNHTDCEBYWXBB\t0.064763752744\t-384.000000000000\t2015-03-12T00:08:49.670Z\n" + - "XTPNHTDCEBYWXBB\t0.000000000000\t0.016534221359\t2015-03-12T00:09:01.010Z\n" + - "XTPNHTDCEBYWXBB\t0.060663623735\t0.377497851849\t2015-03-12T00:09:03.830Z\n" + - "XTPNHTDCEBYWXBB\t0.000001439460\t0.000000291427\t2015-03-12T00:09:05.960Z\n" + - "XTPNHTDCEBYWXBB\t0.000660118021\t0.000000001520\t2015-03-12T00:09:14.030Z\n" + - "XTPNHTDCEBYWXBB\t394.622238159180\t0.245789200068\t2015-03-12T00:09:35.320Z\n" + - "XTPNHTDCEBYWXBB\t-1024.000000000000\t0.002625804045\t2015-03-12T00:10:04.300Z\n" + - "XTPNHTDCEBYWXBB\t0.021761201322\t-805.171875000000\t2015-03-12T00:10:10.920Z\n" + - "XTPNHTDCEBYWXBB\t18.621844291687\t0.003388853336\t2015-03-12T00:10:24.380Z\n" + - "XTPNHTDCEBYWXBB\t-514.108642578125\t66.830410003662\t2015-03-12T00:10:30.510Z\n" + - "XTPNHTDCEBYWXBB\t1.720549345016\t0.000006926386\t2015-03-12T00:10:37.250Z\n" + - "XTPNHTDCEBYWXBB\t-715.183959960938\t22.427126884460\t2015-03-12T00:10:39.680Z\n" + - "XTPNHTDCEBYWXBB\t0.000000000000\t0.629212051630\t2015-03-12T00:10:44.310Z\n" + - "XTPNHTDCEBYWXBB\t257.433593750000\t0.000087903414\t2015-03-12T00:11:03.210Z\n" + - "XTPNHTDCEBYWXBB\t0.000000070390\t-270.520019531250\t2015-03-12T00:11:18.280Z\n" + - "XTPNHTDCEBYWXBB\t-439.250000000000\t0.000000093325\t2015-03-12T00:11:25.080Z\n" + - "XTPNHTDCEBYWXBB\t256.000000000000\t760.565032958984\t2015-03-12T00:11:35.220Z\n" + - "XTPNHTDCEBYWXBB\t634.375000000000\t0.000000033359\t2015-03-12T00:11:55.300Z\n" + - "XTPNHTDCEBYWXBB\t0.000031026852\t0.000000000000\t2015-03-12T00:11:58.680Z\n" + - "XTPNHTDCEBYWXBB\t90.977296829224\t0.000000124888\t2015-03-12T00:12:06.190Z\n" + - "XTPNHTDCEBYWXBB\t0.845079660416\t0.000001311144\t2015-03-12T00:12:12.980Z\n" + - "XTPNHTDCEBYWXBB\t-0.500000000000\t216.805793762207\t2015-03-12T00:12:28.700Z\n" + - "XTPNHTDCEBYWXBB\t0.021825334989\t0.000000003128\t2015-03-12T00:12:29.420Z\n" + - "XTPNHTDCEBYWXBB\t0.307688817382\t516.472656250000\t2015-03-12T00:12:36.300Z\n" + - "XTPNHTDCEBYWXBB\t43.792731285095\t0.000372541021\t2015-03-12T00:12:42.040Z\n" + - "XTPNHTDCEBYWXBB\t-782.687500000000\t252.748397827148\t2015-03-12T00:12:48.780Z\n" + - "XTPNHTDCEBYWXBB\t137.645996093750\t808.000000000000\t2015-03-12T00:13:09.280Z\n" + - "XTPNHTDCEBYWXBB\t0.002546578180\t17.097163200378\t2015-03-12T00:13:27.120Z\n" + - "XTPNHTDCEBYWXBB\t-264.875000000000\t-419.750000000000\t2015-03-12T00:13:40.020Z\n" + - "XTPNHTDCEBYWXBB\t0.000221305789\t53.479209899902\t2015-03-12T00:13:40.660Z\n" + - "XTPNHTDCEBYWXBB\t0.030516586266\t-612.226562500000\t2015-03-12T00:13:50.440Z\n" + - "XTPNHTDCEBYWXBB\t-1024.000000000000\t17.896668434143\t2015-03-12T00:13:53.350Z\n" + - "XTPNHTDCEBYWXBB\t0.000000091829\t0.000000000000\t2015-03-12T00:14:06.090Z\n" + - "XTPNHTDCEBYWXBB\t0.000164877347\t0.000000009079\t2015-03-12T00:14:15.960Z\n" + - "XTPNHTDCEBYWXBB\t0.000000276606\t512.000000000000\t2015-03-12T00:14:31.890Z\n" + - "XTPNHTDCEBYWXBB\t0.000000034906\t-1024.000000000000\t2015-03-12T00:15:19.540Z\n" + - "XTPNHTDCEBYWXBB\t478.680068969727\t0.000058549787\t2015-03-12T00:15:19.790Z\n" + - "XTPNHTDCEBYWXBB\t430.000000000000\t639.000000000000\t2015-03-12T00:15:33.890Z\n" + - "XTPNHTDCEBYWXBB\t0.000000236331\t-960.000000000000\t2015-03-12T00:15:38.790Z\n" + - "XTPNHTDCEBYWXBB\t81.210937500000\t0.000056687957\t2015-03-12T00:15:43.330Z\n" + - "XTPNHTDCEBYWXBB\t648.112548828125\t0.000010239995\t2015-03-12T00:16:30.740Z\n"; - assertThat(expected, "select id, x, y, timestamp from tab where id in ('XTPNHTDCEBYWXBB')"); - } - - @Test - public void testSearchByStringIdUnindexed() throws Exception { - - createTab(); - - final String expected = "XTPNHTDCEBYWXBB\t-292.000000000000\t0.000000006354\t2015-03-12T00:00:02.290Z\n" + - "XTPNHTDCEBYWXBB\t7.197236061096\t2.818476676941\t2015-03-12T00:00:27.340Z\n" + - "XTPNHTDCEBYWXBB\t0.000005481412\t1.312383592129\t2015-03-12T00:00:29.610Z\n" + - "XTPNHTDCEBYWXBB\t446.081878662109\t0.000000051478\t2015-03-12T00:00:31.780Z\n" + - "XTPNHTDCEBYWXBB\t-809.625000000000\t0.000000104467\t2015-03-12T00:00:33.860Z\n" + - "XTPNHTDCEBYWXBB\t560.000000000000\t0.526266053319\t2015-03-12T00:00:37.440Z\n" + - "XTPNHTDCEBYWXBB\t0.000000004619\t0.000028377840\t2015-03-12T00:00:46.630Z\n" + - "XTPNHTDCEBYWXBB\t-510.983673095703\t-512.000000000000\t2015-03-12T00:00:55.090Z\n" + - "XTPNHTDCEBYWXBB\t0.000000527720\t760.000000000000\t2015-03-12T00:01:03.780Z\n" + - "XTPNHTDCEBYWXBB\t0.012854952831\t-292.297058105469\t2015-03-12T00:01:09.350Z\n" + - "XTPNHTDCEBYWXBB\t0.082818411291\t2.386151432991\t2015-03-12T00:01:10.310Z\n" + - "XTPNHTDCEBYWXBB\t330.293212890625\t-268.000000000000\t2015-03-12T00:01:12.810Z\n" + - "XTPNHTDCEBYWXBB\t278.125000000000\t0.077817678452\t2015-03-12T00:01:16.670Z\n" + - "XTPNHTDCEBYWXBB\t-448.000000000000\t0.000001829988\t2015-03-12T00:02:02.260Z\n" + - "XTPNHTDCEBYWXBB\t0.238381892443\t-935.843750000000\t2015-03-12T00:02:33.540Z\n" + - "XTPNHTDCEBYWXBB\t0.097852131352\t-120.312500000000\t2015-03-12T00:02:41.600Z\n" + - "XTPNHTDCEBYWXBB\t0.034327778034\t0.000000076055\t2015-03-12T00:02:41.860Z\n" + - "XTPNHTDCEBYWXBB\t0.016777765006\t1.525665938854\t2015-03-12T00:02:47.630Z\n" + - "XTPNHTDCEBYWXBB\t0.000000245470\t0.000000012355\t2015-03-12T00:03:21.880Z\n" + - "XTPNHTDCEBYWXBB\t38.482372283936\t156.359012603760\t2015-03-12T00:03:25.470Z\n" + - "XTPNHTDCEBYWXBB\t960.000000000000\t-561.500000000000\t2015-03-12T00:03:52.790Z\n" + - "XTPNHTDCEBYWXBB\t0.000048914401\t0.000535350249\t2015-03-12T00:03:53.420Z\n" + - "XTPNHTDCEBYWXBB\t0.315786086023\t-544.000000000000\t2015-03-12T00:04:02.560Z\n" + - "XTPNHTDCEBYWXBB\t-512.000000000000\t512.000000000000\t2015-03-12T00:04:09.410Z\n" + - "XTPNHTDCEBYWXBB\t0.000469007500\t0.000000003315\t2015-03-12T00:04:29.330Z\n" + - "XTPNHTDCEBYWXBB\t473.774108886719\t0.005739651737\t2015-03-12T00:04:49.240Z\n" + - "XTPNHTDCEBYWXBB\t77.079637527466\t-68.750000000000\t2015-03-12T00:04:54.540Z\n" + - "XTPNHTDCEBYWXBB\t1017.250000000000\t256.000000000000\t2015-03-12T00:04:59.980Z\n" + - "XTPNHTDCEBYWXBB\t979.558593750000\t0.034476440400\t2015-03-12T00:05:00.400Z\n" + - "XTPNHTDCEBYWXBB\t0.080838434398\t0.000240437294\t2015-03-12T00:05:16.590Z\n" + - "XTPNHTDCEBYWXBB\t837.343750000000\t0.000000003163\t2015-03-12T00:05:22.150Z\n" + - "XTPNHTDCEBYWXBB\t-708.738037109375\t12.065711975098\t2015-03-12T00:05:23.960Z\n" + - "XTPNHTDCEBYWXBB\t73.905494689941\t968.143554687500\t2015-03-12T00:05:30.160Z\n" + - "XTPNHTDCEBYWXBB\t858.125000000000\t0.004347450798\t2015-03-12T00:06:06.300Z\n" + - "XTPNHTDCEBYWXBB\t191.156250000000\t692.151489257813\t2015-03-12T00:06:07.380Z\n" + - "XTPNHTDCEBYWXBB\t0.000000350446\t0.001085809752\t2015-03-12T00:06:14.550Z\n" + - "XTPNHTDCEBYWXBB\t877.107116699219\t0.073764367029\t2015-03-12T00:06:26.310Z\n" + - "XTPNHTDCEBYWXBB\t4.980149984360\t0.000000005301\t2015-03-12T00:06:33.470Z\n" + - "XTPNHTDCEBYWXBB\t0.000937165081\t-204.000000000000\t2015-03-12T00:06:54.810Z\n" + - "XTPNHTDCEBYWXBB\t756.876586914063\t-572.703125000000\t2015-03-12T00:06:56.120Z\n" + - "XTPNHTDCEBYWXBB\t0.000000022885\t0.689865306020\t2015-03-12T00:06:57.920Z\n" + - "XTPNHTDCEBYWXBB\t723.500000000000\t-592.817382812500\t2015-03-12T00:07:17.570Z\n" + - "XTPNHTDCEBYWXBB\t-285.125000000000\t-448.250000000000\t2015-03-12T00:07:20.480Z\n" + - "XTPNHTDCEBYWXBB\t4.877287983894\t-870.000000000000\t2015-03-12T00:07:36.830Z\n" + - "XTPNHTDCEBYWXBB\t-638.750000000000\t-859.125000000000\t2015-03-12T00:07:38.910Z\n" + - "XTPNHTDCEBYWXBB\t757.085937500000\t-128.000000000000\t2015-03-12T00:07:45.970Z\n" + - "XTPNHTDCEBYWXBB\t0.000024196771\t44.254640579224\t2015-03-12T00:07:56.400Z\n" + - "XTPNHTDCEBYWXBB\t0.000002050660\t113.433692932129\t2015-03-12T00:08:25.690Z\n" + - "XTPNHTDCEBYWXBB\t0.001966100186\t401.331298828125\t2015-03-12T00:08:31.180Z\n" + - "XTPNHTDCEBYWXBB\t134.605468750000\t0.000778750400\t2015-03-12T00:08:34.070Z\n" + - "XTPNHTDCEBYWXBB\t304.000000000000\t170.421752929688\t2015-03-12T00:08:36.400Z\n" + - "XTPNHTDCEBYWXBB\t0.000000029559\t0.000033108370\t2015-03-12T00:08:42.110Z\n" + - "XTPNHTDCEBYWXBB\t0.064763752744\t-384.000000000000\t2015-03-12T00:08:49.670Z\n" + - "XTPNHTDCEBYWXBB\t0.000000000000\t0.016534221359\t2015-03-12T00:09:01.010Z\n" + - "XTPNHTDCEBYWXBB\t0.060663623735\t0.377497851849\t2015-03-12T00:09:03.830Z\n" + - "XTPNHTDCEBYWXBB\t0.000001439460\t0.000000291427\t2015-03-12T00:09:05.960Z\n" + - "XTPNHTDCEBYWXBB\t0.000660118021\t0.000000001520\t2015-03-12T00:09:14.030Z\n" + - "XTPNHTDCEBYWXBB\t394.622238159180\t0.245789200068\t2015-03-12T00:09:35.320Z\n" + - "XTPNHTDCEBYWXBB\t-1024.000000000000\t0.002625804045\t2015-03-12T00:10:04.300Z\n" + - "XTPNHTDCEBYWXBB\t0.021761201322\t-805.171875000000\t2015-03-12T00:10:10.920Z\n" + - "XTPNHTDCEBYWXBB\t18.621844291687\t0.003388853336\t2015-03-12T00:10:24.380Z\n" + - "XTPNHTDCEBYWXBB\t-514.108642578125\t66.830410003662\t2015-03-12T00:10:30.510Z\n" + - "XTPNHTDCEBYWXBB\t1.720549345016\t0.000006926386\t2015-03-12T00:10:37.250Z\n" + - "XTPNHTDCEBYWXBB\t-715.183959960938\t22.427126884460\t2015-03-12T00:10:39.680Z\n" + - "XTPNHTDCEBYWXBB\t0.000000000000\t0.629212051630\t2015-03-12T00:10:44.310Z\n" + - "XTPNHTDCEBYWXBB\t257.433593750000\t0.000087903414\t2015-03-12T00:11:03.210Z\n" + - "XTPNHTDCEBYWXBB\t0.000000070390\t-270.520019531250\t2015-03-12T00:11:18.280Z\n" + - "XTPNHTDCEBYWXBB\t-439.250000000000\t0.000000093325\t2015-03-12T00:11:25.080Z\n" + - "XTPNHTDCEBYWXBB\t256.000000000000\t760.565032958984\t2015-03-12T00:11:35.220Z\n" + - "XTPNHTDCEBYWXBB\t634.375000000000\t0.000000033359\t2015-03-12T00:11:55.300Z\n" + - "XTPNHTDCEBYWXBB\t0.000031026852\t0.000000000000\t2015-03-12T00:11:58.680Z\n" + - "XTPNHTDCEBYWXBB\t90.977296829224\t0.000000124888\t2015-03-12T00:12:06.190Z\n" + - "XTPNHTDCEBYWXBB\t0.845079660416\t0.000001311144\t2015-03-12T00:12:12.980Z\n" + - "XTPNHTDCEBYWXBB\t-0.500000000000\t216.805793762207\t2015-03-12T00:12:28.700Z\n" + - "XTPNHTDCEBYWXBB\t0.021825334989\t0.000000003128\t2015-03-12T00:12:29.420Z\n" + - "XTPNHTDCEBYWXBB\t0.307688817382\t516.472656250000\t2015-03-12T00:12:36.300Z\n" + - "XTPNHTDCEBYWXBB\t43.792731285095\t0.000372541021\t2015-03-12T00:12:42.040Z\n" + - "XTPNHTDCEBYWXBB\t-782.687500000000\t252.748397827148\t2015-03-12T00:12:48.780Z\n" + - "XTPNHTDCEBYWXBB\t137.645996093750\t808.000000000000\t2015-03-12T00:13:09.280Z\n" + - "XTPNHTDCEBYWXBB\t0.002546578180\t17.097163200378\t2015-03-12T00:13:27.120Z\n" + - "XTPNHTDCEBYWXBB\t-264.875000000000\t-419.750000000000\t2015-03-12T00:13:40.020Z\n" + - "XTPNHTDCEBYWXBB\t0.000221305789\t53.479209899902\t2015-03-12T00:13:40.660Z\n" + - "XTPNHTDCEBYWXBB\t0.030516586266\t-612.226562500000\t2015-03-12T00:13:50.440Z\n" + - "XTPNHTDCEBYWXBB\t-1024.000000000000\t17.896668434143\t2015-03-12T00:13:53.350Z\n" + - "XTPNHTDCEBYWXBB\t0.000000091829\t0.000000000000\t2015-03-12T00:14:06.090Z\n" + - "XTPNHTDCEBYWXBB\t0.000164877347\t0.000000009079\t2015-03-12T00:14:15.960Z\n" + - "XTPNHTDCEBYWXBB\t0.000000276606\t512.000000000000\t2015-03-12T00:14:31.890Z\n" + - "XTPNHTDCEBYWXBB\t0.000000034906\t-1024.000000000000\t2015-03-12T00:15:19.540Z\n" + - "XTPNHTDCEBYWXBB\t478.680068969727\t0.000058549787\t2015-03-12T00:15:19.790Z\n" + - "XTPNHTDCEBYWXBB\t430.000000000000\t639.000000000000\t2015-03-12T00:15:33.890Z\n" + - "XTPNHTDCEBYWXBB\t0.000000236331\t-960.000000000000\t2015-03-12T00:15:38.790Z\n" + - "XTPNHTDCEBYWXBB\t81.210937500000\t0.000056687957\t2015-03-12T00:15:43.330Z\n" + - "XTPNHTDCEBYWXBB\t648.112548828125\t0.000010239995\t2015-03-12T00:16:30.740Z\n"; - assertThat(expected, "select id, x, y, timestamp from tab where id = 'XTPNHTDCEBYWXBB'"); - } - - @Test - public void testSearchIndexedStrNull() throws Exception { - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab"). - $str("id").index().buckets(128). - $double("x"). - $double("y"). - $ts() - - )) { - - Rnd rnd = new Rnd(); - ObjHashSet names = new ObjHashSet<>(); - for (int i = 0; i < 128; i++) { - names.add(rnd.nextString(15)); - } - - int mask = 127; - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - - for (int i = 0; i < 10000; i++) { - JournalEntryWriter ew = w.entryWriter(); - if ((rnd.nextPositiveInt() % 10) == 0) { - ew.putNull(0); - } else { - ew.putStr(0, names.get(rnd.nextInt() & mask)); - } - ew.putDouble(1, rnd.nextDouble()); - ew.putDouble(2, rnd.nextDouble()); - ew.putDate(3, t += 10); - ew.append(); - } - w.commit(); - } - assertNullSearch(); - } - - @Test - public void testSearchIndexedSymNull() throws Exception { - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab"). - $sym("id").index().buckets(128). - $double("x"). - $double("y"). - $ts() - - )) { - - Rnd rnd = new Rnd(); - ObjHashSet names = getNames(rnd, 128); - - int mask = 127; - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - - for (int i = 0; i < 10000; i++) { - JournalEntryWriter ew = w.entryWriter(); - if ((rnd.nextPositiveInt() % 10) == 0) { - ew.putNull(0); - } else { - ew.putSym(0, names.get(rnd.nextInt() & mask)); - } - ew.putDouble(1, rnd.nextDouble()); - ew.putDouble(2, rnd.nextDouble()); - ew.putDate(3, t += 10); - ew.append(); - } - w.commit(); - } - - assertNullSearch(); - } - - @Test - public void testSearchUnindexedStrNull() throws Exception { - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab"). - $str("id"). - $double("x"). - $double("y"). - $ts() - - )) { - - Rnd rnd = new Rnd(); - ObjHashSet names = new ObjHashSet<>(); - for (int i = 0; i < 128; i++) { - names.add(rnd.nextString(15)); - } - - int mask = 127; - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - - for (int i = 0; i < 10000; i++) { - JournalEntryWriter ew = w.entryWriter(); - if ((rnd.nextPositiveInt() % 10) == 0) { - ew.putNull(0); - } else { - ew.putStr(0, names.get(rnd.nextInt() & mask)); - } - ew.putDouble(1, rnd.nextDouble()); - ew.putDouble(2, rnd.nextDouble()); - ew.putDate(3, t += 10); - ew.append(); - } - w.commit(); - } - - assertNullSearch(); - } - - @Test - public void testSearchUnindexedSymNull() throws Exception { - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab"). - $sym("id"). - $double("x"). - $double("y"). - $ts() - - )) { - - Rnd rnd = new Rnd(); - ObjHashSet names = getNames(rnd, 128); - - int mask = 127; - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - - for (int i = 0; i < 10000; i++) { - JournalEntryWriter ew = w.entryWriter(); - if ((rnd.nextPositiveInt() % 10) == 0) { - ew.putNull(0); - } else { - ew.putSym(0, names.get(rnd.nextInt() & mask)); - } - ew.putDouble(1, rnd.nextDouble()); - ew.putDouble(2, rnd.nextDouble()); - ew.putDate(3, t += 10); - ew.append(); - } - w.commit(); - } - - assertNullSearch(); - } - - @Test - public void testSigLookupError() throws Exception { - createTabWithNaNs2(); - try { - expectFailure("select x,y from tab where x~0"); - } catch (ParserException e) { - Assert.assertEquals(27, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "No such function")); - } - } - - @Test - public void testStrConcat() throws Exception { - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab"). - $str("x"). - $str("y"). - $int("z"). - $ts() - - )) { - - Rnd rnd = new Rnd(); - - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - - for (int i = 0; i < 1000; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putStr(0, rnd.nextString(4)); - ew.putStr(1, rnd.nextString(2)); - ew.putInt(2, rnd.nextInt()); - ew.putDate(3, t += 10); - ew.append(); - } - w.commit(); - } - - final String expected = "CJOU-OU\n" + - "CQJS-HG\n" + - "CEJF-PB\n" + - "CSJK-PY\n" + - "CJHU-JY\n"; - - assertThat(expected, "select x + '-' + y from tab where x ~ '^C.*J+'"); - } - - @Test - public void testStrConcat2() throws Exception { - createTabWithNaNs2(); - - final String expected = "KKUSIMYDXUUSKCX\t-338.665039062500\n" + - "KKUSIMYDXUUSKCX\t-481.765014648438\n" + - "KKUSIMYDXUUSKCX\t0.000183005621\n" + - "KKUSIMYDXUUSKCX\t5.404115438461\n" + - "KKUSIMYDXUUSKCX\t-436.000000000000\n" + - "KKUSIMYDXUUSKCX\t-807.692016601563\n" + - "KKUSIMYDXUUSKCX\t0.000013659448\n" + - "KKUSIMYDXUUSKCX\t384.000000000000\n" + - "KKUSIMYDXUUSKCX\t0.003575030481\n" + - "KKUSIMYDXUUSKCX\t35.019264221191\n" + - "KKUSIMYDXUUSKCX\t-512.000000000000\n" + - "KKUSIMYDXUUSKCX\t-256.000000000000\n" + - "KKUSIMYDXUUSKCX\t240.000000000000\n" + - "KKUSIMYDXUUSKCX\t-612.000000000000\n" + - "KKUSIMYDXUUSKCX\t0.000000343896\n" + - "KKUSIMYDXUUSKCX\t0.059096898884\n" + - "KKUSIMYDXUUSKCX\t0.036795516498\n" + - "KKUSIMYDXUUSKCX\t0.000000136839\n" + - "KKUSIMYDXUUSKCX\t0.000001200607\n" + - "KKUSIMYDXUUSKCX\t5.540870904922\n"; - - assertThat(expected, "select id, x from tab where id+'-BLAH'='KKUSIMYDXUUSKCX-BLAH' and ((z > -100 and z < 100) or z = NaN)"); - } - - @Test - public void testStrEqualsNull() throws Exception { - createTabWithNullsAndTime(); - String expected = "RQ\t20:54\t2015-03-12T00:00:00.000Z\n"; - assertThat(expected, "tab where id = 'RQ'"); - assertThat(expected, "tab where 'RQ' = id"); - } - - @Test - public void testStrNotEqualsNull() throws Exception { - createTabWithNullsAndTime(); - String expected = "JWCPSWHYRXPEHNRXGZ\t19:27\t2015-03-12T00:00:00.000Z\n" + - "IBBTGPGWFFYUDEYYQEHBHF\t19:36\t2015-03-12T00:00:00.000Z\n" + - "\t2:52\t2015-03-12T00:00:00.000Z\n" + - "\t5:22\t2015-03-12T00:00:00.000Z\n" + - "OUO\t8:47\t2015-03-12T00:00:00.000Z\n" + - "\t0:14\t2015-03-12T00:00:00.000Z\n" + - "\t15:34\t2015-03-12T00:00:00.000Z\n" + - "ETJRS\t13:27\t2015-03-12T00:00:00.000Z\n" + - "RFBVTMHGOOZZVDZJMYICCXZ\t12:9\t2015-03-12T00:00:00.000Z\n" + - "W\t8:19\t2015-03-12T00:00:00.000Z\n" + - "\t9:5\t2015-03-12T00:00:00.000Z\n" + - "SDOTSEDYYCTGQOLYXWCK\t9:40\t2015-03-12T00:00:00.000Z\n" + - "WDSWUGSHOLNVTIQBZXI\t4:10\t2015-03-12T00:00:00.000Z\n" + - "\t11:43\t2015-03-12T00:00:00.000Z\n" + - "\t14:7\t2015-03-12T00:00:00.000Z\n" + - "QSRLTKVVSJOJIPHZEPI\t14:15\t2015-03-12T00:00:00.000Z\n" + - "OVLJUMLGLHMLLEOYPH\t22:22\t2015-03-12T00:00:00.000Z\n" + - "\t19:32\t2015-03-12T00:00:00.000Z\n" + - "\t21:49\t2015-03-12T00:00:00.000Z\n" + - "\t7:16\t2015-03-12T00:00:00.000Z\n" + - "BEZGHWVDKFL\t15:19\t2015-03-12T00:00:00.000Z\n" + - "XPKRGIIHYHBOQ\t22:48\t2015-03-12T00:00:00.000Z\n" + - "\t16:16\t2015-03-12T00:00:00.000Z\n" + - "\t14:40\t2015-03-12T00:00:00.000Z\n" + - "HNZHZSQLDGLOG\t12:44\t2015-03-12T00:00:00.000Z\n" + - "SZMZVQEBNDCQCEHNOMV\t2:30\t2015-03-12T00:00:00.000Z\n" + - "\t5:59\t2015-03-12T00:00:00.000Z\n" + - "WNWIFFLRBROMNXKUIZ\t23:25\t2015-03-12T00:00:00.000Z\n" + - "YVFZF\t11:46\t2015-03-12T00:00:00.000Z\n" + - "\t0:14\t2015-03-12T00:00:00.000Z\n" + - "\t6:47\t2015-03-12T00:00:00.000Z\n" + - "VWSW\t1:36\t2015-03-12T00:00:00.000Z\n" + - "ONFCLTJCKFMQN\t21:23\t2015-03-12T00:00:00.000Z\n" + - "XUKLGMXSLUQ\t15:38\t2015-03-12T00:00:00.000Z\n" + - "\t20:26\t2015-03-12T00:00:00.000Z\n" + - "MYFFDTN\t12:56\t2015-03-12T00:00:00.000Z\n" + - "PBNHGZWWCC\t15:25\t2015-03-12T00:00:00.000Z\n" + - "LEGPUHHIUGGL\t14:43\t2015-03-12T00:00:00.000Z\n" + - "LCBDMIGQZVKHTLQZSLQVFGPP\t21:45\t2015-03-12T00:00:00.000Z\n" + - "BHYSBQYMIZJSVTNPIWZNFK\t13:23\t2015-03-12T00:00:00.000Z\n" + - "\t2:41\t2015-03-12T00:00:00.000Z\n" + - "\t8:57\t2015-03-12T00:00:00.000Z\n" + - "\t12:16\t2015-03-12T00:00:00.000Z\n" + - "\t14:20\t2015-03-12T00:00:00.000Z\n" + - "JYDVRVN\t11:57\t2015-03-12T00:00:00.000Z\n" + - "\t18:45\t2015-03-12T00:00:00.000Z\n" + - "\t17:31\t2015-03-12T00:00:00.000Z\n" + - "IWF\t11:20\t2015-03-12T00:00:00.000Z\n" + - "HQQUWQOEENNEBQQEMXDKXEJ\t22:48\t2015-03-12T00:00:00.000Z\n" + - "KYFLUHZQSNPXMKJSMKIXEYVT\t19:44\t2015-03-12T00:00:00.000Z\n" + - "HGGIWH\t16:4\t2015-03-12T00:00:00.000Z\n" + - "\t15:11\t2015-03-12T00:00:00.000Z\n" + - "\t6:29\t2015-03-12T00:00:00.000Z\n" + - "\t18:13\t2015-03-12T00:00:00.000Z\n" + - "SVIHDWWLEV\t16:40\t2015-03-12T00:00:00.000Z\n" + - "\t9:38\t2015-03-12T00:00:00.000Z\n" + - "VLU\t11:45\t2015-03-12T00:00:00.000Z\n" + - "\t2:33\t2015-03-12T00:00:00.000Z\n" + - "\t5:25\t2015-03-12T00:00:00.000Z\n" + - "CLNXFSUWPNXH\t22:39\t2015-03-12T00:00:00.000Z\n" + - "ODWKOCPFYXPVKNCBWLNLRHWQ\t14:48\t2015-03-12T00:00:00.000Z\n" + - "VFDBZWNIJEEHR\t19:25\t2015-03-12T00:00:00.000Z\n" + - "\t17:16\t2015-03-12T00:00:00.000Z\n" + - "\t2:4\t2015-03-12T00:00:00.000Z\n" + - "BEGMITINLKFNUHNRJ\t12:13\t2015-03-12T00:00:00.000Z\n" + - "\t21:50\t2015-03-12T00:00:00.000Z\n" + - "MPBETTTKRIVOC\t15:50\t2015-03-12T00:00:00.000Z\n" + - "\t16:22\t2015-03-12T00:00:00.000Z\n" + - "IVQF\t6:52\t2015-03-12T00:00:00.000Z\n" + - "SBOSEPGIUQZHE\t1:27\t2015-03-12T00:00:00.000Z\n" + - "\t12:12\t2015-03-12T00:00:00.000Z\n" + - "\t16:52\t2015-03-12T00:00:00.000Z\n" + - "INKG\t18:25\t2015-03-12T00:00:00.000Z\n" + - "EVQTQOZKXTPNHTDCEBYWX\t3:10\t2015-03-12T00:00:00.000Z\n" + - "RLPTYXYGYFUXCDKDWOMD\t0:26\t2015-03-12T00:00:00.000Z\n" + - "FRPXZSFX\t16:37\t2015-03-12T00:00:00.000Z\n" + - "XTGNJJILLEYMIWT\t15:46\t2015-03-12T00:00:00.000Z\n" + - "\t14:8\t2015-03-12T00:00:00.000Z\n" + - "FIEVM\t2:29\t2015-03-12T00:00:00.000Z\n" + - "GPYKKBMQMUDDCIHCNPUG\t23:38\t2015-03-12T00:00:00.000Z\n" + - "\t1:58\t2015-03-12T00:00:00.000Z\n" + - "\t10:56\t2015-03-12T00:00:00.000Z\n" + - "\t7:57\t2015-03-12T00:00:00.000Z\n" + - "BBUKOJSOLDYRODIPUNRPSMIF\t21:8\t2015-03-12T00:00:00.000Z\n" + - "KO\t14:49\t2015-03-12T00:00:00.000Z\n" + - "QSQJGDIHHNSSTCRZ\t19:39\t2015-03-12T00:00:00.000Z\n" + - "FULMERTPIQBUYZV\t16:30\t2015-03-12T00:00:00.000Z\n" + - "QSPZPBHLNEJRMDIKD\t15:22\t2015-03-12T00:00:00.000Z\n" + - "\t12:49\t2015-03-12T00:00:00.000Z\n" + - "PZGPZNYVLTPKBBQ\t9:57\t2015-03-12T00:00:00.000Z\n" + - "YNNCTFSNSXHHD\t0:50\t2015-03-12T00:00:00.000Z\n" + - "RUMMZSCJOU\t2:14\t2015-03-12T00:00:00.000Z\n" + - "ENFEL\t4:46\t2015-03-12T00:00:00.000Z\n" + - "\t11:40\t2015-03-12T00:00:00.000Z\n" + - "QHGJBFQBBKF\t19:3\t2015-03-12T00:00:00.000Z\n" + - "\t5:18\t2015-03-12T00:00:00.000Z\n" + - "\t5:14\t2015-03-12T00:00:00.000Z\n" + - "BHVRIIYMHOWKCDNZNLCNGZ\t14:48\t2015-03-12T00:00:00.000Z\n" + - "OXRSFPVRQLGYDONNLI\t20:1\t2015-03-12T00:00:00.000Z\n"; - assertThat(expected, "tab where id != 'RQ'"); - assertThat(expected, "tab where 'RQ' != id"); - } - - @Test - public void testStrRegex() throws Exception { - createTab(); - final String expecte = "KEQMMKDFIPNZVZR\t0.000000001530\t2015-03-12T00:00:03.470Z\n" + - "KEQMMKDFIPNZVZR\t-832.000000000000\t2015-03-12T00:00:04.650Z\n" + - "KEQMMKDFIPNZVZR\t446.187500000000\t2015-03-12T00:00:05.460Z\n" + - "KEQMMKDFIPNZVZR\t0.000000005636\t2015-03-12T00:00:24.210Z\n" + - "KEQMMKDFIPNZVZR\t0.129930097610\t2015-03-12T00:00:52.220Z\n" + - "KEQMMKDFIPNZVZR\t-677.094238281250\t2015-03-12T00:00:54.020Z\n" + - "KEQMMKDFIPNZVZR\t-167.187500000000\t2015-03-12T00:00:58.090Z\n" + - "KEQMMKDFIPNZVZR\t-512.000000000000\t2015-03-12T00:01:11.790Z\n" + - "KEQMMKDFIPNZVZR\t0.055018983781\t2015-03-12T00:01:19.340Z\n" + - "KEQMMKDFIPNZVZR\t-862.500000000000\t2015-03-12T00:01:24.430Z\n" + - "KEQMMKDFIPNZVZR\t883.730468750000\t2015-03-12T00:01:28.870Z\n" + - "KEQMMKDFIPNZVZR\t193.875000000000\t2015-03-12T00:01:39.320Z\n" + - "KEQMMKDFIPNZVZR\t-608.000000000000\t2015-03-12T00:01:42.440Z\n" + - "KEQMMKDFIPNZVZR\t-193.003417968750\t2015-03-12T00:01:47.820Z\n" + - "KEQMMKDFIPNZVZR\t0.000002046971\t2015-03-12T00:01:55.420Z\n" + - "KEQMMKDFIPNZVZR\t0.037930097431\t2015-03-12T00:01:55.790Z\n" + - "KEQMMKDFIPNZVZR\t0.160599559546\t2015-03-12T00:02:08.830Z\n" + - "KEQMMKDFIPNZVZR\t91.000000000000\t2015-03-12T00:02:19.120Z\n" + - "KEQMMKDFIPNZVZR\t-1000.000000000000\t2015-03-12T00:02:22.680Z\n" + - "KEQMMKDFIPNZVZR\t0.000015199104\t2015-03-12T00:02:23.520Z\n" + - "KEQMMKDFIPNZVZR\t-480.000000000000\t2015-03-12T00:02:29.060Z\n" + - "KEQMMKDFIPNZVZR\t0.000000224731\t2015-03-12T00:02:31.260Z\n" + - "KEQMMKDFIPNZVZR\t0.043443457223\t2015-03-12T00:02:40.400Z\n" + - "KEQMMKDFIPNZVZR\t-554.125000000000\t2015-03-12T00:02:45.230Z\n" + - "KEQMMKDFIPNZVZR\t0.418899938464\t2015-03-12T00:02:52.550Z\n" + - "KEQMMKDFIPNZVZR\t0.000002813213\t2015-03-12T00:03:34.680Z\n" + - "KEQMMKDFIPNZVZR\t-750.970703125000\t2015-03-12T00:03:43.830Z\n" + - "KEQMMKDFIPNZVZR\t202.477161407471\t2015-03-12T00:03:59.950Z\n" + - "KEQMMKDFIPNZVZR\t0.000296119222\t2015-03-12T00:04:06.200Z\n" + - "KEQMMKDFIPNZVZR\t-1001.109375000000\t2015-03-12T00:04:12.750Z\n" + - "KEQMMKDFIPNZVZR\t-350.539062500000\t2015-03-12T00:04:17.920Z\n" + - "KEQMMKDFIPNZVZR\t0.270242959261\t2015-03-12T00:04:30.780Z\n" + - "KEQMMKDFIPNZVZR\t640.000000000000\t2015-03-12T00:04:36.000Z\n" + - "KEQMMKDFIPNZVZR\t242.000000000000\t2015-03-12T00:04:37.360Z\n" + - "KEQMMKDFIPNZVZR\t354.109191894531\t2015-03-12T00:04:43.560Z\n" + - "KEQMMKDFIPNZVZR\t608.000000000000\t2015-03-12T00:05:03.070Z\n" + - "KEQMMKDFIPNZVZR\t-209.281250000000\t2015-03-12T00:05:18.460Z\n" + - "KEQMMKDFIPNZVZR\t0.000000009506\t2015-03-12T00:05:39.720Z\n" + - "KEQMMKDFIPNZVZR\t0.000000018168\t2015-03-12T00:05:40.690Z\n" + - "KEQMMKDFIPNZVZR\t0.000000002177\t2015-03-12T00:05:41.820Z\n" + - "KEQMMKDFIPNZVZR\t0.000375485601\t2015-03-12T00:05:49.480Z\n" + - "KEQMMKDFIPNZVZR\t0.000000039768\t2015-03-12T00:05:55.150Z\n" + - "KEQMMKDFIPNZVZR\t0.269348338246\t2015-03-12T00:06:09.200Z\n" + - "KEQMMKDFIPNZVZR\t-671.500000000000\t2015-03-12T00:06:26.130Z\n" + - "KEQMMKDFIPNZVZR\t0.001258826785\t2015-03-12T00:06:28.910Z\n" + - "KEQMMKDFIPNZVZR\t0.978091150522\t2015-03-12T00:06:33.330Z\n" + - "KEQMMKDFIPNZVZR\t44.780708312988\t2015-03-12T00:06:43.700Z\n" + - "KEQMMKDFIPNZVZR\t-767.601562500000\t2015-03-12T00:06:44.600Z\n" + - "KEQMMKDFIPNZVZR\t-890.500000000000\t2015-03-12T00:06:59.620Z\n" + - "KEQMMKDFIPNZVZR\t0.000173775785\t2015-03-12T00:07:01.460Z\n" + - "KEQMMKDFIPNZVZR\t0.000192599509\t2015-03-12T00:07:04.160Z\n" + - "KEQMMKDFIPNZVZR\t18.733582496643\t2015-03-12T00:07:23.720Z\n" + - "KEQMMKDFIPNZVZR\t31.429724693298\t2015-03-12T00:07:38.140Z\n" + - "KEQMMKDFIPNZVZR\t0.000390803711\t2015-03-12T00:07:39.260Z\n" + - "KEQMMKDFIPNZVZR\t0.000000044603\t2015-03-12T00:07:49.970Z\n" + - "KEQMMKDFIPNZVZR\t-881.380859375000\t2015-03-12T00:07:55.910Z\n" + - "KEQMMKDFIPNZVZR\t-128.000000000000\t2015-03-12T00:08:00.360Z\n" + - "KEQMMKDFIPNZVZR\t891.539062500000\t2015-03-12T00:08:14.330Z\n" + - "KEQMMKDFIPNZVZR\t508.000000000000\t2015-03-12T00:08:21.190Z\n" + - "KEQMMKDFIPNZVZR\t0.002558049746\t2015-03-12T00:08:31.860Z\n" + - "KEQMMKDFIPNZVZR\t-736.000000000000\t2015-03-12T00:08:57.430Z\n" + - "KEQMMKDFIPNZVZR\t-968.859375000000\t2015-03-12T00:09:27.030Z\n" + - "KEQMMKDFIPNZVZR\t0.000000008169\t2015-03-12T00:09:27.200Z\n" + - "KEQMMKDFIPNZVZR\t399.000000000000\t2015-03-12T00:09:45.580Z\n" + - "KEQMMKDFIPNZVZR\t0.000239236899\t2015-03-12T00:09:53.250Z\n" + - "KEQMMKDFIPNZVZR\t-104.871093750000\t2015-03-12T00:10:01.070Z\n" + - "KEQMMKDFIPNZVZR\t15.412450790405\t2015-03-12T00:10:04.140Z\n" + - "KEQMMKDFIPNZVZR\t0.185059137642\t2015-03-12T00:10:15.850Z\n" + - "KEQMMKDFIPNZVZR\t5.659068346024\t2015-03-12T00:10:26.050Z\n" + - "KEQMMKDFIPNZVZR\t3.807189881802\t2015-03-12T00:10:59.590Z\n" + - "KEQMMKDFIPNZVZR\t0.000000677441\t2015-03-12T00:11:01.530Z\n" + - "KEQMMKDFIPNZVZR\t61.405685424805\t2015-03-12T00:11:03.130Z\n" + - "KEQMMKDFIPNZVZR\t-1024.000000000000\t2015-03-12T00:11:18.220Z\n" + - "KEQMMKDFIPNZVZR\t641.500000000000\t2015-03-12T00:11:25.040Z\n" + - "KEQMMKDFIPNZVZR\t0.000001824081\t2015-03-12T00:11:34.740Z\n" + - "KEQMMKDFIPNZVZR\t0.000056925237\t2015-03-12T00:11:39.260Z\n" + - "KEQMMKDFIPNZVZR\t128.000000000000\t2015-03-12T00:11:40.030Z\n" + - "KEQMMKDFIPNZVZR\t0.000168198319\t2015-03-12T00:11:42.890Z\n" + - "KEQMMKDFIPNZVZR\t0.000002674703\t2015-03-12T00:11:54.620Z\n" + - "KEQMMKDFIPNZVZR\t0.001482222520\t2015-03-12T00:12:40.320Z\n" + - "KEQMMKDFIPNZVZR\t56.829874038696\t2015-03-12T00:12:42.760Z\n" + - "KEQMMKDFIPNZVZR\t41.603179931641\t2015-03-12T00:13:16.840Z\n" + - "KEQMMKDFIPNZVZR\t164.312500000000\t2015-03-12T00:13:35.470Z\n" + - "KEQMMKDFIPNZVZR\t-457.061523437500\t2015-03-12T00:13:45.640Z\n" + - "KEQMMKDFIPNZVZR\t-512.000000000000\t2015-03-12T00:13:46.040Z\n" + - "KEQMMKDFIPNZVZR\t0.000027407084\t2015-03-12T00:13:51.600Z\n" + - "KEQMMKDFIPNZVZR\t-473.760742187500\t2015-03-12T00:13:57.560Z\n" + - "KEQMMKDFIPNZVZR\t-512.000000000000\t2015-03-12T00:13:58.830Z\n" + - "KEQMMKDFIPNZVZR\t74.750000000000\t2015-03-12T00:14:32.610Z\n" + - "KEQMMKDFIPNZVZR\t982.715270996094\t2015-03-12T00:14:33.480Z\n" + - "KEQMMKDFIPNZVZR\t0.235923126340\t2015-03-12T00:14:36.540Z\n" + - "KEQMMKDFIPNZVZR\t0.000000003422\t2015-03-12T00:14:48.360Z\n" + - "KEQMMKDFIPNZVZR\t0.000304762289\t2015-03-12T00:15:01.280Z\n" + - "KEQMMKDFIPNZVZR\t0.000188905338\t2015-03-12T00:15:08.640Z\n" + - "KEQMMKDFIPNZVZR\t256.000000000000\t2015-03-12T00:15:09.740Z\n" + - "KEQMMKDFIPNZVZR\t0.000000017417\t2015-03-12T00:15:17.910Z\n" + - "KEQMMKDFIPNZVZR\t75.859375000000\t2015-03-12T00:15:32.280Z\n" + - "KEQMMKDFIPNZVZR\t0.091820014641\t2015-03-12T00:15:34.560Z\n" + - "KEQMMKDFIPNZVZR\t0.000044015695\t2015-03-12T00:15:45.650Z\n" + - "KEQMMKDFIPNZVZR\t0.000000003026\t2015-03-12T00:15:48.030Z\n" + - "KEQMMKDFIPNZVZR\t-963.317260742188\t2015-03-12T00:15:49.270Z\n" + - "KEQMMKDFIPNZVZR\t0.001303359750\t2015-03-12T00:16:08.870Z\n" + - "KEQMMKDFIPNZVZR\t0.005202150205\t2015-03-12T00:16:14.750Z\n"; - - assertThat(expecte, "select id, x, timestamp from tab where id ~ '^KE.*'"); - } - - @Test - public void testSubQuery1() throws Exception { - createTabWithNaNs2(); - - final String expected = "KKUSIMYDXUUSKCX\t-338.665039062500\t9.986581325531\tNaN\t2\t2015-03-21T01:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.000183005621\t0.216939434409\tNaN\t17\t2015-06-15T09:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t-807.692016601563\t1.505146384239\tNaN\t-71\t2015-08-10T06:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t384.000000000000\t638.000000000000\tNaN\t-397\t2015-08-17T14:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t240.000000000000\t0.000415830291\tNaN\t-379\t2015-12-25T13:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.059096898884\t0.000015207836\tNaN\t-16\t2016-01-24T07:00:00.000Z\n" + - "KKUSIMYDXUUSKCX\t0.036795516498\tNaN\tNaN\t-313\t2016-02-23T01:00:00.000Z\n"; - - assertThat(expected, "(tab where z = NaN) where id = 'KKUSIMYDXUUSKCX'"); - } - - @Test - public void testSubQuery2() throws Exception { - createTabWithNaNs2(); - - final String expected = "KKUSIMYDXUUSKCX\tNaN\n" + - "KKUSIMYDXUUSKCX\tNaN\n" + - "KKUSIMYDXUUSKCX\tNaN\n" + - "KKUSIMYDXUUSKCX\tNaN\n" + - "KKUSIMYDXUUSKCX\tNaN\n" + - "KKUSIMYDXUUSKCX\tNaN\n" + - "KKUSIMYDXUUSKCX\tNaN\n"; - - assertThat(expected, "select id, z from (tab where z = NaN) where id = 'KKUSIMYDXUUSKCX'"); - } - - @Test - public void testSubQuery3() throws Exception { - createTabWithNaNs2(); - try { - expectFailure("select id, z from (select id from tab where z = NaN) where id = 'KKUSIMYDXUUSKCX'"); - } catch (ParserException e) { - Assert.assertEquals(11, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Invalid column")); - } - } - - @Test - public void testSubQuery4() throws Exception { - createTabWithNaNs2(); - - final String expected = "ZSFXUNYQXTGNJJI\t-162\n" + - "BHLNEJRMDIKDISG\t-458\n" + - "YYVSYYEQBORDTQH\t-227\n"; - - assertThat(expected, "select id, z from (tab where not(id in 'GMPLUCFTLNKYTSZ')) where timestamp = '2015-03-12T10:00:00;5m;30m;10'"); - } - - @Test - public void testSubQuery5() throws Exception { - createTabWithNaNs2(); - - final String expected = "ZSFXUNYQXTGNJJI\t-162\n" + - "BHLNEJRMDIKDISG\t-458\n" + - "YYVSYYEQBORDTQH\t-227\n"; - - assertThat(expected, "select id, z from (tab where not(id in 'GMPLUCFTLNKYTSZ') and timestamp = '2015-03-12T10:00:00;5m;30m;10')"); - } - - @Test - public void testSubQuery7() throws Exception { - createTabWithNaNs2(); - assertEmpty("select id, z from (tab where not(id in 'GMPLUCFTLNKYTSZ') and timestamp = '2015-03-12T10:00:00;5m;30m;10') where 10 < 3"); - } - - @Test - public void testSubQueryConstantTrueWhere() throws Exception { - createTabWithNaNs2(); - final String expected = "ZSFXUNYQXTGNJJI\t-162\n" + - "BHLNEJRMDIKDISG\t-458\n" + - "YYVSYYEQBORDTQH\t-227\n"; - - assertThat(expected, "select id, z from (tab where not(id in 'GMPLUCFTLNKYTSZ') and timestamp = '2015-03-12T10:00:00;5m;30m;10') where 10 > 3"); - } - - @Test - public void testSubQueryFalseModel() throws Exception { - createTabWithNaNs2(); - assertEmpty("select id, z from (tab where not(id in 'GMPLUCFTLNKYTSZ') and timestamp = '2015-03-12T10:00:00;5m;30m;10') where timestamp = '2015-03-12T10:00:00' and timestamp = '2015-03-12T14:00:00'"); - } - - @Test - public void testSubQueryIntervalSearch() throws Exception { - createTabWithNaNs2(); - assertThat("2015-03-18T00:00:00.000Z\t662.930252075195\n" + - "2015-03-18T01:00:00.000Z\t0.000001096262\n" + - "2015-03-18T02:00:00.000Z\t0.000001078617\n" + - "2015-03-18T03:00:00.000Z\t-119.000000000000\n" + - "2015-03-18T04:00:00.000Z\t-290.255371093750\n" + - "2015-03-18T05:00:00.000Z\t-50.148437500000\n" + - "2015-03-18T06:00:00.000Z\t0.002493287437\n" + - "2015-03-18T07:00:00.000Z\t222.294685363770\n" + - "2015-03-18T08:00:00.000Z\tNaN\n" + - "2015-03-18T09:00:00.000Z\t58.412302017212\n" + - "2015-03-18T10:00:00.000Z\t-948.394042968750\n" + - "2015-03-18T11:00:00.000Z\t960.000000000000\n" + - "2015-03-18T12:00:00.000Z\t467.771606445313\n" + - "2015-03-18T13:00:00.000Z\t-384.000000000000\n" + - "2015-03-18T14:00:00.000Z\t0.000034461837\n" + - "2015-03-18T15:00:00.000Z\t-1024.000000000000\n" + - "2015-03-18T16:00:00.000Z\t61.995271682739\n" + - "2015-03-18T17:00:00.000Z\t0.000000780048\n" + - "2015-03-18T18:00:00.000Z\t0.000000773129\n" + - "2015-03-18T19:00:00.000Z\t-560.250000000000\n" + - "2015-03-18T20:00:00.000Z\t0.000000963666\n" + - "2015-03-18T21:00:00.000Z\t52.090820312500\n" + - "2015-03-18T22:00:00.000Z\t445.687500000000\n" + - "2015-03-18T23:00:00.000Z\tNaN\n", - "(select timestamp+1 ts, sum(y) sum_y from tab sample by 1d) timestamp(ts) where ts = '2015-03-18'"); - } - - @Test - public void testSubQueryIntervalSearch2() throws Exception { - createTabWithNaNs2(); - assertThat("2015-03-18T01:00:00.000Z\t0.000001096262\n" + - "2015-03-18T02:00:00.000Z\t0.000001078617\n", - "(select timestamp+1 ts, sum(y) from tab sample by 1d) timestamp(ts) where ts = '2015-03-18T01;1h'"); - - } - - @Test - public void testSubQueryIntervalSearch3() throws Exception { - createTabWithNaNs2(); - assertThat("2015-03-18T01:00:00.000Z\t0.000001096262\n" + - "2015-03-18T02:00:00.000Z\t0.000001078617\n", - "(select 1+timestamp ts, sum(y) from tab sample by 1d) timestamp(ts) where ts = '2015-03-18T01;1h'"); - - } - - @Test - public void testSymRegex() throws Exception { - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab"). - $sym("id").index().buckets(128). - $double("x"). - $double("y"). - $ts() - - )) { - - Rnd rnd = new Rnd(); - ObjHashSet names = getNames(rnd, 128); - - int mask = 127; - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - - for (int i = 0; i < 10000; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putSym(0, names.get(rnd.nextInt() & mask)); - ew.putDouble(1, rnd.nextDouble()); - ew.putDouble(2, rnd.nextDouble()); - ew.putDate(3, t += 10); - ew.append(); - } - w.commit(); - } - - final String expected = "EENNEBQQEMXDKXE\t0.005532926181\t2015-03-12T00:01:38.290Z\n" + - "EDNKRCGKSQDCMUM\t201.500000000000\t2015-03-12T00:01:38.780Z\n" + - "EVMLKCJBEVLUHLI\t-224.000000000000\t2015-03-12T00:01:39.040Z\n" + - "EEHRUGPBMBTKVSB\t640.000000000000\t2015-03-12T00:01:39.140Z\n" + - "EOCVFFKMEKPFOYM\t0.001286557002\t2015-03-12T00:01:39.260Z\n" + - "ETJRSZSRYRFBVTM\t0.146399393678\t2015-03-12T00:01:39.460Z\n" + - "ELLKKHTWNWIFFLR\t236.634628295898\t2015-03-12T00:01:39.600Z\n" + - "EGMITINLKFNUHNR\t53.349147796631\t2015-03-12T00:01:39.850Z\n" + - "EIWFOQKYHQQUWQO\t-617.734375000000\t2015-03-12T00:01:40.000Z\n"; - - assertThat(expected, "select id, y, timestamp from tab latest by id where id ~ '^E.*'"); - } - - @Test - public void testSymbolInIntervalSource() throws Exception { - createTabWithSymbol(); - assertSymbol("(select sym, timestamp+1 ts, sum(y) from tab sample by 1d) timestamp(ts) where ts = '2015-03-13T00:01:39'"); - } - - @Test - public void testTime24() throws Exception { - createTabWithNullsAndTime(); - assertThat("\t2015-03-12T00:00:00.000Z\t2:52\t2015-03-12T02:52:00.000Z\n" + - "\t2015-03-12T00:00:00.000Z\t5:22\t2015-03-12T05:22:00.000Z\n" + - "\t2015-03-12T00:00:00.000Z\t0:14\t2015-03-12T00:14:00.000Z\n" + - "\t2015-03-12T00:00:00.000Z\t15:34\t2015-03-12T15:34:00.000Z\n" + - "\t2015-03-12T00:00:00.000Z\t9:5\t2015-03-12T09:05:00.000Z\n" + - "\t2015-03-12T00:00:00.000Z\t11:43\t2015-03-12T11:43:00.000Z\n" + - "\t2015-03-12T00:00:00.000Z\t14:7\t2015-03-12T14:07:00.000Z\n" + - "\t2015-03-12T00:00:00.000Z\t19:32\t2015-03-12T19:32:00.000Z\n" + - "\t2015-03-12T00:00:00.000Z\t21:49\t2015-03-12T21:49:00.000Z\n" + - "\t2015-03-12T00:00:00.000Z\t7:16\t2015-03-12T07:16:00.000Z\n", - "select id, date, time, date + toDate(time, 'H:m') from tab where id = null limit 10"); - } - - @Test - public void testTimestampOverride() throws Exception { - createTabWithNaNs2(); - - assertThat("2015-03-18T00:00:00.000Z\t662.930253171457\n" + - "2015-03-18T02:00:00.000Z\t-118.999998921383\n" + - "2015-03-18T04:00:00.000Z\t-340.403808593750\n" + - "2015-03-18T06:00:00.000Z\t222.297178651206\n" + - "2015-03-18T08:00:00.000Z\tNaN\n" + - "2015-03-18T10:00:00.000Z\t11.605957031250\n" + - "2015-03-18T12:00:00.000Z\t83.771606445313\n" + - "2015-03-18T14:00:00.000Z\t-1023.999965538164\n" + - "2015-03-18T16:00:00.000Z\t61.995272462788\n" + - "2015-03-18T18:00:00.000Z\t-560.249999226871\n" + - "2015-03-18T20:00:00.000Z\t52.090821276166\n" + - "2015-03-18T22:00:00.000Z\tNaN\n", - "select ts, sum(sum_y) from ((select timestamp+1 ts, sum(y) sum_y from tab sample by 1d) timestamp(ts) where ts = '2015-03-18') sample by 2h"); - } - - @Test - public void testUnindexedIntNaN() throws Exception { - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab"). - $int("id"). - $double("x"). - $double("y"). - $ts() - - )) { - - Rnd rnd = new Rnd(); - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - for (int i = 0; i < 10000; i++) { - JournalEntryWriter ew = w.entryWriter(); - if (rnd.nextPositiveInt() % 10 == 0) { - ew.putNull(0); - } else { - ew.putInt(0, rnd.nextInt()); - } - ew.putDouble(1, rnd.nextDouble()); - ew.putDouble(2, rnd.nextDouble()); - ew.putDate(3, t += 10); - ew.append(); - } - w.commit(); - } - - final String expected = "NaN\t768.000000000000\t-408.000000000000\n" + - "NaN\t256.000000000000\t-455.750000000000\n" + - "NaN\t525.287368774414\t-470.171875000000\n" + - "NaN\t512.000000000000\t-425.962463378906\n" + - "NaN\t553.796875000000\t-620.062500000000\n" + - "NaN\t512.000000000000\t-958.144531250000\n" + - "NaN\t304.062500000000\t-1024.000000000000\n" + - "NaN\t600.000000000000\t-934.000000000000\n" + - "NaN\t475.619140625000\t-431.078125000000\n" + - "NaN\t864.000000000000\t-480.723571777344\n" + - "NaN\t512.000000000000\t-585.500000000000\n" + - "NaN\t183.876594543457\t-512.000000000000\n" + - "NaN\t204.021038055420\t-453.903320312500\n" + - "NaN\t272.363739013672\t-1024.000000000000\n" + - "NaN\t973.989135742188\t-444.000000000000\n" + - "NaN\t768.000000000000\t-1024.000000000000\n" + - "NaN\t290.253906250000\t-960.000000000000\n" + - "NaN\t263.580390930176\t-960.000000000000\n" + - "NaN\t756.500000000000\t-1024.000000000000\n" + - "NaN\t461.884765625000\t-921.996948242188\n" + - "NaN\t512.000000000000\t-536.000000000000\n" + - "NaN\t213.152450561523\t-811.783691406250\n" + - "NaN\t121.591918945313\t-874.921630859375\n" + - "NaN\t920.625000000000\t-512.000000000000\n"; - - assertThat(expected, "select id, x, y from tab where id = NaN and x > 120 and y < -400"); - } - - @Test - public void testVirtualColumnQuery() throws Exception { - try (JournalWriter w = getFactory().writer(Quote.class, "q")) { - TestUtils.generateQuoteData(w, 100); - } - - final String expected = "BT-A.L\t0.474883438625\t0.000001189157\t1.050231933594\n" + - "ADM.L\t-51.014269662148\t104.021850585938\t0.006688738358\n" + - "AGK.L\t-686.961853027344\t879.117187500000\t496.806518554688\n" + - "ABF.L\t-383.000010317080\t768.000000000000\t0.000020634160\n" + - "ABF.L\t-127.000000017899\t256.000000000000\t0.000000035797\n" + - "WTB.L\t-459.332875207067\t920.625000000000\t0.040750414133\n" + - "AGK.L\t-703.000000000000\t512.000000000000\t896.000000000000\n" + - "RRS.L\t-5.478123126552\t12.923866510391\t0.032379742712\n" + - "BT-A.L\t0.996734812157\t0.006530375686\t0.000000000000\n" + - "ABF.L\t-359.000000008662\t0.000000017324\t720.000000000000\n" + - "AGK.L\t-191.000000009850\t384.000000000000\t0.000000019700\n" + - "ABF.L\t0.999416386211\t0.001165474765\t0.000001752813\n" + - "RRS.L\t-347.652348756790\t1.507822513580\t695.796875000000\n" + - "ADM.L\t-86.378168493509\t172.796875000000\t1.959461987019\n" + - "RRS.L\t-470.449707034291\t0.000000006081\t942.899414062500\n" + - "BP.L\t-723.414062500000\t424.828125000000\t1024.000000000000\n" + - "HSBA.L\t-75.736694544117\t153.473033905029\t0.000355183205\n" + - "RRS.L\t-489.548828125000\t632.921875000000\t348.175781250000\n" + - "BT-A.L\t-92.000010057318\t186.000000000000\t0.000020114637\n" + - "RRS.L\t-334.728804341285\t0.015470010694\t671.442138671875\n" + - "HSBA.L\t0.969581946437\t0.000000009901\t0.060836097226\n" + - "GKN.L\t-134.846217133105\t0.003103211522\t271.689331054688\n" + - "BP.L\t-384.179687507322\t770.359375000000\t0.000000014643\n" + - "LLOY.L\t-2.041434317827\t1.229880273342\t4.852988362312\n" + - "TLW.L\t-382.690430340427\t0.000001305853\t767.380859375000\n" + - "HSBA.L\t0.999757577623\t0.000000776007\t0.000484068747\n" + - "RRS.L\t-291.082599617541\t583.609375000000\t0.555824235082\n" + - "BP.L\t-234.659652709961\t296.544433593750\t174.774871826172\n" + - "WTB.L\t-470.000000000000\t842.000000000000\t100.000000000000\n" + - "RRS.L\t-181.231244396825\t364.462486267090\t0.000002526560\n" + - "GKN.L\t0.999684159173\t0.000603844470\t0.000027837185\n" + - "TLW.L\t-175.000000130841\t0.000000261681\t352.000000000000\n" + - "GKN.L\t0.999937448983\t0.000125102033\t0.000000000000\n" + - "AGK.L\t0.999129234003\t0.000000194258\t0.001741337735\n" + - "ADM.L\t-108.185731784076\t218.371459960938\t0.000003607215\n" + - "LLOY.L\t-527.821648597717\t1024.000000000000\t33.643297195435\n" + - "BP.L\t-127.000587929302\t256.000000000000\t0.001175858604\n" + - "HSBA.L\t-71.210969042524\t144.421875000000\t0.000063085048\n" + - "BP.L\t-127.000000016025\t256.000000000000\t0.000000032050\n" + - "GKN.L\t-415.000040076207\t0.000080152415\t832.000000000000\n" + - "AGK.L\t-289.957031250000\t512.000000000000\t69.914062500000\n" + - "AGK.L\t-450.494251251221\t768.000000000000\t134.988502502441\n" + - "LLOY.L\t-293.859375000936\t0.000000001871\t589.718750000000\n" + - "GKN.L\t-367.000001976696\t736.000000000000\t0.000003953393\n" + - "AGK.L\t0.999999992240\t0.000000001374\t0.000000014146\n" + - "LLOY.L\t-1.005833093077\t0.115072973073\t3.896593213081\n" + - "BT-A.L\t-192.421875002549\t386.843750000000\t0.000000005098\n" + - "LLOY.L\t-5.999457120895\t5.590153217316\t8.408761024475\n" + - "GKN.L\t-4.042319541496\t0.000000248992\t10.084638834000\n" + - "HSBA.L\t-81.109376058324\t0.000002116648\t164.218750000000\n" + - "WTB.L\t0.999989964510\t0.000005107453\t0.000014963527\n" + - "BT-A.L\t-468.790763854981\t629.480468750000\t310.101058959961\n" + - "TLW.L\t0.694377524342\t0.000000049302\t0.611244902015\n" + - "AGK.L\t-338.896525263786\t672.000000000000\t7.793050527573\n" + - "TLW.L\t0.260076059727\t0.018715771381\t1.461132109165\n" + - "ADM.L\t-352.977539062500\t655.625000000000\t52.330078125000\n" + - "BP.L\t-59.514666617196\t0.000036359392\t121.029296875000\n" + - "LLOY.L\t-131.905826912553\t265.807006835938\t0.004646989168\n" + - "GKN.L\t-48.381265968084\t0.971607863903\t97.790924072266\n" + - "LLOY.L\t-175.841796875000\t0.000000000000\t353.683593750000\n" + - "LLOY.L\t-7.008397817612\t8.039016723633\t7.977778911591\n" + - "ABF.L\t-318.007048395928\t638.000000000000\t0.014096791856\n" + - "HSBA.L\t-409.112306014912\t0.000002654824\t820.224609375000\n" + - "HSBA.L\t-149.046875020149\t300.093750000000\t0.000000040298\n" + - "HSBA.L\t0.997081416281\t0.005052038119\t0.000785129319\n" + - "BT-A.L\t0.936320396314\t0.127358488739\t0.000000718634\n" + - "ADM.L\t0.999999965448\t0.000000009919\t0.000000059185\n" + - "GKN.L\t0.979669743518\t0.040659694001\t0.000000818963\n" + - "TLW.L\t-1.819448314155\t0.000012560774\t5.638884067535\n" + - "BP.L\t-499.354459762573\t873.000000000000\t127.708919525146\n" + - "HSBA.L\t-724.575195312500\t939.150390625000\t512.000000000000\n" + - "ABF.L\t-488.316503390990\t978.632812500000\t0.000194281980\n" + - "AGK.L\t-444.362694263458\t844.000000000000\t46.725388526917\n" + - "HSBA.L\t-228.500000000000\t31.000000000000\t428.000000000000\n" + - "ADM.L\t-36.921404135436\t75.842805862427\t0.000002408446\n" + - "GKN.L\t-580.579162597656\t283.158325195313\t880.000000000000\n" + - "ABF.L\t-481.575685286397\t0.000003385293\t965.151367187500\n" + - "TLW.L\t0.804228177760\t0.031326758675\t0.360216885805\n" + - "GKN.L\t-637.187500000000\t508.375000000000\t768.000000000000\n" + - "ADM.L\t-5.150909269229\t12.290055274963\t0.011763263494\n" + - "GKN.L\t-1.684180170298\t4.111308574677\t1.257051765919\n" + - "RRS.L\t-113.000794559603\t0.000002205143\t228.001586914063\n" + - "LLOY.L\t0.994362744171\t0.000000129186\t0.011274382472\n" + - "ADM.L\t-8.878542166360\t19.756743907928\t0.000340424791\n" + - "GKN.L\t0.999909967674\t0.000180012023\t0.000000052629\n" + - "BT-A.L\t-252.331054687500\t400.000000000000\t106.662109375000\n" + - "RRS.L\t-223.239476203918\t68.043695449829\t380.435256958008\n" + - "ADM.L\t0.997952489638\t0.004094106262\t0.000000914462\n" + - "BP.L\t-253.937500000000\t64.000000000000\t445.875000000000\n" + - "WTB.L\t-2.006443221466\t0.000000157150\t6.012886285782\n" + - "HSBA.L\t-303.487510681152\t497.000000000000\t111.975021362305\n" + - "HSBA.L\t-282.980148315430\t549.125503540039\t18.834793090820\n" + - "TLW.L\t-205.000000075030\t0.000000150060\t412.000000000000\n" + - "RRS.L\t-19.750000003584\t0.000000007168\t41.500000000000\n" + - "GKN.L\t-446.143188476563\t354.286376953125\t540.000000000000\n" + - "GKN.L\t-185.000005207851\t0.000010415702\t372.000000000000\n" + - "ADM.L\t-370.770515203476\t728.300781250000\t15.240249156952\n" + - "RRS.L\t-223.348431229591\t448.000000000000\t0.696862459183\n" + - "AGK.L\t-511.009589326801\t0.019178653602\t1024.000000000000\n" + - "BP.L\t-705.000000000000\t1021.000000000000\t391.000000000000\n"; - - assertThat(expected, "select sym, 1-(bid+ask)/2 mid, bid, ask from q"); - } - - private void appendNaNs(JournalWriter w, long t) throws JournalException { - Rnd rnd = new Rnd(); - int n = 128; - ObjHashSet names = getNames(rnd, n); - - int mask = n - 1; - - for (int i = 0; i < 10000; i++) { - JournalEntryWriter ew = w.entryWriter(t); - ew.putStr(0, names.get(rnd.nextInt() & mask)); - ew.putDouble(1, rnd.nextDouble()); - if (rnd.nextPositiveInt() % 10 == 0) { - ew.putNull(2); - } else { - ew.putDouble(2, rnd.nextDouble()); - } - if (rnd.nextPositiveInt() % 10 == 0) { - ew.putNull(3); - } else { - ew.putLong(3, rnd.nextLong() % 500); - } - ew.putInt(4, rnd.nextInt() % 500); - ew.putDate(5, t += 10); - ew.append(); - } - w.commit(); - } - - private void assertNullSearch() throws ParserException, IOException { - final String expected = "\t256.000000000000\t-455.750000000000\n" + - "\t525.287368774414\t-470.171875000000\n" + - "\t512.000000000000\t-425.962463378906\n" + - "\t553.796875000000\t-620.062500000000\n" + - "\t512.000000000000\t-958.144531250000\n" + - "\t304.062500000000\t-1024.000000000000\n" + - "\t600.000000000000\t-934.000000000000\n" + - "\t475.619140625000\t-431.078125000000\n" + - "\t864.000000000000\t-480.723571777344\n" + - "\t512.000000000000\t-585.500000000000\n" + - "\t183.876594543457\t-512.000000000000\n" + - "\t204.021038055420\t-453.903320312500\n" + - "\t272.363739013672\t-1024.000000000000\n" + - "\t973.989135742188\t-444.000000000000\n" + - "\t768.000000000000\t-1024.000000000000\n" + - "\t290.253906250000\t-960.000000000000\n" + - "\t263.580390930176\t-960.000000000000\n" + - "\t756.500000000000\t-1024.000000000000\n" + - "\t461.884765625000\t-921.996948242188\n" + - "\t512.000000000000\t-536.000000000000\n" + - "\t213.152450561523\t-811.783691406250\n" + - "\t121.591918945313\t-874.921630859375\n" + - "\t920.625000000000\t-512.000000000000\n" + - "\t256.000000000000\t-488.625000000000\n" + - "\t361.391540527344\t-1024.000000000000\n"; - - assertThat(expected, "select id, x, y from tab where id = null and x > 120 and y < -400"); - } - - private void createIndexedTab() throws JournalException, NumericException { - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab"). - $str("id").index().buckets(16). - $double("x"). - $double("y"). - $ts() - - )) { - - Rnd rnd = new Rnd(); - ObjHashSet names = getNames(rnd, 1024); - - int mask = 1023; - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - - for (int i = 0; i < 10000; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putStr(0, names.get(rnd.nextInt() & mask)); - ew.putDouble(1, rnd.nextDouble()); - ew.putDouble(2, rnd.nextDouble()); - ew.putDate(3, t += 10); - ew.append(); - } - w.commit(); - } - } - - private void createTab() throws JournalException, NumericException { - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab"). - $str("id"). - $double("x"). - $double("y"). - $ts() - - )) { - - Rnd rnd = new Rnd(); - ObjHashSet names = getNames(rnd, 1024); - - int mask = 1023; - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - - for (int i = 0; i < 100000; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putStr(0, names.get(rnd.nextInt() & mask)); - ew.putDouble(1, rnd.nextDouble()); - ew.putDouble(2, rnd.nextDouble()); - ew.putDate(3, t += 10); - ew.append(); - } - w.commit(); - } - } - - private void createTabNoNaNs() throws JournalException, NumericException { - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab"). - $str("id"). - $double("x"). - $double("y"). - $long("z"). - $int("w"). - $ts() - - )) { - - Rnd rnd = new Rnd(); - int n = 128; - ObjHashSet names = getNames(rnd, n); - - int mask = n - 1; - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - - for (int i = 0; i < 10000; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putStr(0, names.get(rnd.nextInt() & mask)); - ew.putDouble(1, rnd.nextDouble()); - ew.putDouble(2, rnd.nextDouble()); - ew.putLong(3, rnd.nextLong()); - ew.putInt(4, rnd.nextInt()); - ew.putDate(5, t += 10); - ew.append(); - } - w.commit(); - } - } - - private void createTabWithNaNs() throws JournalException, NumericException { - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab"). - $str("id"). - $double("x"). - $double("y"). - $long("z"). - $int("w"). - $ts() - - )) { - appendNaNs(w, DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z")); - } - } - - private void createTabWithNaNs2() throws JournalException, NumericException { - createTabWithNaNs20(new JournalStructure("tab"). - $str("id"). - $double("x"). - $double("y"). - $long("z"). - $int("w"). - $ts() - ); - } - - private void createTabWithNaNs20(JournalStructure struct) throws JournalException, NumericException { - try (JournalWriter w = getFactory().writer(struct)) { - - Rnd rnd = new Rnd(); - int n = 128; - ObjHashSet names = getNames(rnd, n); - - int mask = n - 1; - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - - for (int i = 0; i < 10000; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putStr(0, names.get(rnd.nextInt() & mask)); - ew.putDouble(1, rnd.nextDouble()); - if (rnd.nextPositiveInt() % 10 == 0) { - ew.putNull(2); - } else { - ew.putDouble(2, rnd.nextDouble()); - } - if (rnd.nextPositiveInt() % 10 == 0) { - ew.putNull(3); - } else { - ew.putLong(3, rnd.nextLong() % 500); - } - if (rnd.nextPositiveInt() % 10 == 0) { - ew.putNull(4); - } else { - ew.putInt(4, rnd.nextInt() % 500); - } - ew.putDate(5, t += (60 * 60 * 1000)); - ew.append(); - } - w.commit(); - } - } - - private void createTabWithNaNs3() throws JournalException, NumericException { - createTabWithNaNs20(new JournalStructure("tab"). - $str("id").index(). - $double("x"). - $double("y"). - $long("z").index(). - $int("w").index(). - $ts() - ); - } - - private void createTabWithNullsAndTime() throws JournalException, NumericException { - try (JournalWriter w = getFactory().writer(new JournalStructure("tab"). - $str("id").index(). - $str("time"). - $date("date"))) { - Rnd rnd = new Rnd(); - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - for (int i = 0; i < 100; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putStr(0, rnd.nextBoolean() ? null : rnd.nextChars(rnd.nextPositiveInt() % 25)); - ew.putStr(1, rnd.nextPositiveInt() % 24 + ":" + rnd.nextPositiveInt() % 60); - ew.putDate(2, t); - ew.append(); - } - w.commit(); - } - } - - private void createTabWithSymbol() throws JournalException, NumericException { - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab"). - $str("id").index().buckets(16). - $sym("sym"). - $double("x"). - $double("y"). - $ts() - - )) { - - Rnd rnd = new Rnd(); - ObjHashSet names = getNames(rnd, 1024); - - ObjHashSet syms = new ObjHashSet<>(); - for (int i = 0; i < 64; i++) { - syms.add(rnd.nextString(10)); - } - - int mask = 1023; - long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z"); - - for (int i = 0; i < 10000; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putStr(0, names.get(rnd.nextInt() & mask)); - ew.putDouble(2, rnd.nextDouble()); - ew.putDouble(3, rnd.nextDouble()); - ew.putDate(4, t += 10); - ew.putSym(1, syms.get(rnd.nextInt() & 63)); - ew.append(); - } - w.commit(); - } - } - - private ObjHashSet getNames(Rnd r, int n) { - ObjHashSet names = new ObjHashSet<>(); - for (int i = 0; i < n; i++) { - names.add(r.nextString(15)); - } - return names; - } - - private void tabOfDates() throws JournalException, NumericException { - long t = DateFormatUtils.parseDateTime("2016-10-08T00:00:00.000Z"); - try (JournalWriter w = getFactory().writer( - new JournalStructure("tab"). - $ts(). - recordCountHint(100) - - )) { - for (int i = 0; i < 100; i++) { - JournalEntryWriter ew = w.entryWriter(t); - ew.append(); - t += 1000 * 60 * 60 * 24; - } - w.commit(); - } - } -} diff --git a/core/src/test/java/com/questdb/ql/AbstractAllTypeTest.java b/core/src/test/java/com/questdb/ql/AbstractAllTypeTest.java deleted file mode 100644 index 0c3109a0a..000000000 --- a/core/src/test/java/com/questdb/ql/AbstractAllTypeTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql; - -import com.questdb.parser.sql.AbstractOptimiserTest; -import com.questdb.std.Rnd; -import com.questdb.std.time.Dates; -import com.questdb.store.JournalEntryWriter; -import com.questdb.store.JournalWriter; -import com.questdb.store.factory.configuration.JournalStructure; -import org.junit.BeforeClass; - -public abstract class AbstractAllTypeTest extends AbstractOptimiserTest { - - @BeforeClass - public static void setUp() throws Exception { - - // this does thread local allocations that - // should not be accounted for while - // measuring query allocations and de-allocations - FACTORY_CONTAINER.getFactory().getConfiguration().exists(""); - - try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("xyz") - .$int("i") - .$str("str") - .$ts() - .$())) { - int n = 100;//100; - String[] sym = {"AX", "XX", "BZ", "KK"}; - Rnd rnd = new Rnd(); - - long t = Dates.toMillis(2016, 5, 1, 10, 20); - for (int i = 0; i < n; i++) { - JournalEntryWriter ew = w.entryWriter(t += 60000); - ew.putInt(0, rnd.nextInt()); - ew.putStr(1, sym[rnd.nextPositiveInt() % sym.length]); - ew.append(); - } - w.commit(); - } - - - try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("abc") - .$int("i") - .$double("d") - .$float("f") - .$byte("b") - .$long("l") - .$str("str") - .$bool("boo") - .$sym("sym") - .$short("sho") - .$date("date") - .$ts() - .$())) { - int n = 20; - String[] sym = {"AX", "XX", "BZ", "KK"}; - Rnd rnd = new Rnd(); - - long t = Dates.toMillis(2016, 5, 1, 10, 20); - for (int i = 0; i < n; i++) { - JournalEntryWriter ew = w.entryWriter(t += 60000); - ew.putInt(0, rnd.nextInt()); - ew.putDouble(1, rnd.nextDouble()); - ew.putFloat(2, rnd.nextFloat()); - ew.put(3, (byte) rnd.nextInt()); - ew.putLong(4, rnd.nextLong()); - ew.putStr(5, sym[rnd.nextPositiveInt() % sym.length]); - ew.putBool(6, rnd.nextBoolean()); - ew.putSym(7, sym[rnd.nextPositiveInt() % sym.length]); - ew.putShort(8, (short) rnd.nextInt()); - ew.putDate(9, rnd.nextLong()); - ew.append(); - } - w.commit(); - } - } -} \ No newline at end of file diff --git a/core/src/test/java/com/questdb/ql/AsOfPartitionedJoinRecordSourceTest.java b/core/src/test/java/com/questdb/ql/AsOfPartitionedJoinRecordSourceTest.java deleted file mode 100644 index e308ad028..000000000 --- a/core/src/test/java/com/questdb/ql/AsOfPartitionedJoinRecordSourceTest.java +++ /dev/null @@ -1,529 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql; - -import com.questdb.ex.ParserException; -import com.questdb.parser.sql.AbstractOptimiserTest; -import com.questdb.parser.sql.QueryError; -import com.questdb.ql.join.AsOfJoinRecordSource; -import com.questdb.ql.join.AsOfPartitionedJoinRecordSource; -import com.questdb.ql.map.RecordKeyCopierCompiler; -import com.questdb.std.*; -import com.questdb.std.str.StringSink; -import com.questdb.std.time.DateFormatUtils; -import com.questdb.store.JournalEntryWriter; -import com.questdb.store.JournalWriter; -import com.questdb.store.Record; -import com.questdb.store.RecordCursor; -import com.questdb.store.factory.configuration.JournalStructure; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -public class AsOfPartitionedJoinRecordSourceTest extends AbstractOptimiserTest { - - private static final CharSequenceHashSet keys = new CharSequenceHashSet(); - private static final RecordKeyCopierCompiler cc = new RecordKeyCopierCompiler(new BytecodeAssembler()); - - - @BeforeClass - public static void setUpClass() throws Exception { - - FACTORY_CONTAINER.getFactory().getConfiguration().exists(""); - - int xcount = 100; - int ycount = 10; - try (JournalWriter xw = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("x") - .$ts() - .$sym("ccy") - .$double("rate") - .$double("amount") - .$str("trader") - .$sym("contra") - .$float("fl") - .$short("sh") - .$long("ln") - .$bool("b") - .recordCountHint(xcount) - .$() - )) { - - try (JournalWriter yw = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("y") - .$ts() - .$sym("ccy") - .$double("amount") - .$str("trader") - .recordCountHint(ycount) - .$() - )) { - - Rnd rnd = new Rnd(); - - String[] ccy = new String[3]; - for (int i = 0; i < ccy.length; i++) { - ccy[i] = rnd.nextChars(6).toString(); - } - - long ts = DateFormatUtils.parseDateTime("2015-03-10T00:00:00.000Z"); - - for (int i = 0; i < xcount; i++) { - JournalEntryWriter w = xw.entryWriter(); - w.putDate(0, ts += 10000); - w.putSym(1, ccy[rnd.nextPositiveInt() % ccy.length]); - w.putDouble(2, rnd.nextDouble()); - w.putDouble(3, rnd.nextDouble()); - if (rnd.nextBoolean()) { - w.putStr(4, rnd.nextChars(rnd.nextPositiveInt() % 128)); - } else { - w.putNull(4); - } - w.putSym(5, ccy[rnd.nextPositiveInt() % ccy.length]); - w.putFloat(6, rnd.nextFloat()); - w.putShort(7, (short) rnd.nextInt()); - w.putLong(8, rnd.nextLong()); - w.putBool(9, rnd.nextBoolean()); - w.append(); - } - xw.commit(); - - ts = DateFormatUtils.parseDateTime("2015-03-10T00:00:00.000Z"); - for (int i = 0; i < ycount; i++) { - JournalEntryWriter w = yw.entryWriter(); - w.putDate(0, ts += 60000); - w.putSym(1, ccy[rnd.nextPositiveInt() % ccy.length]); - w.putDouble(2, rnd.nextDouble()); - if (rnd.nextBoolean()) { - w.putStr(3, rnd.nextChars(rnd.nextPositiveInt() % 128)); - } else { - w.putNull(3); - } - w.append(); - } - yw.commit(); - - // records for adjacent join test - - try (JournalWriter jwa = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("a") - .$ts() - .$sym("ccy") - .$double("rate") - .$() - )) { - - try (JournalWriter jwb = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("b") - .$ts() - .$sym("ccy") - .$double("amount") - .$() - )) { - - JournalEntryWriter ewa; - - ewa = jwa.entryWriter(); - ewa.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:30:00.000Z")); - ewa.putSym(1, "X"); - ewa.putDouble(2, 0.538); - ewa.append(); - - ewa = jwa.entryWriter(); - ewa.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:35:00.000Z")); - ewa.putSym(1, "Y"); - ewa.putDouble(2, 1.35); - ewa.append(); - - ewa = jwa.entryWriter(); - ewa.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:37:00.000Z")); - ewa.putSym(1, "Y"); - ewa.putDouble(2, 1.41); - ewa.append(); - - ewa = jwa.entryWriter(); - ewa.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:39:00.000Z")); - ewa.putSym(1, "X"); - ewa.putDouble(2, 0.601); - ewa.append(); - - ewa = jwa.entryWriter(); - ewa.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:40:00.000Z")); - ewa.putSym(1, "Y"); - ewa.putDouble(2, 1.26); - ewa.append(); - - ewa = jwa.entryWriter(); - ewa.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:43:00.000Z")); - ewa.putSym(1, "Y"); - ewa.putDouble(2, 1.29); - ewa.append(); - - jwa.commit(); - - JournalEntryWriter ewb; - - ewb = jwb.entryWriter(); - ewb.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:27:00.000Z")); - ewb.putSym(1, "X"); - ewb.putDouble(2, 1100); - ewb.append(); - - ewb = jwb.entryWriter(); - ewb.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:28:00.000Z")); - ewb.putSym(1, "X"); - ewb.putDouble(2, 1200); - ewb.append(); - - ewb = jwb.entryWriter(); - ewb.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:29:00.000Z")); - ewb.putSym(1, "X"); - ewb.putDouble(2, 1500); - ewb.append(); - - ewb = jwb.entryWriter(); - ewb.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:34:50.000Z")); - ewb.putSym(1, "Y"); - ewb.putDouble(2, 130); - ewb.append(); - - ewb = jwb.entryWriter(); - ewb.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:36:00.000Z")); - ewb.putSym(1, "Y"); - ewb.putDouble(2, 150); - ewb.append(); - - ewb = jwb.entryWriter(); - ewb.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:41:00.000Z")); - ewb.putSym(1, "Y"); - ewb.putDouble(2, 12000); - ewb.append(); - - jwb.commit(); - } - } - } - } - } - - @Before - public void setUp() { - sink.clear(); - } - - @Test - public void testAdjacentRecordJoin() throws Exception { - assertThat("timestamp\tccy\trate\ttimestamp\tccy\tamount\n" + - "2014-03-12T10:30:00.000Z\tX\t0.538000000000\t2014-03-12T10:29:00.000Z\tX\t1500.000000000000\n" + - "2014-03-12T10:35:00.000Z\tY\t1.350000000000\t2014-03-12T10:34:50.000Z\tY\t130.000000000000\n" + - "2014-03-12T10:37:00.000Z\tY\t1.410000000000\t2014-03-12T10:36:00.000Z\tY\t150.000000000000\n" + - "2014-03-12T10:39:00.000Z\tX\t0.601000000000\t\t\tNaN\n" + - "2014-03-12T10:40:00.000Z\tY\t1.260000000000\t\t\tNaN\n" + - "2014-03-12T10:43:00.000Z\tY\t1.290000000000\t2014-03-12T10:41:00.000Z\tY\t12000.000000000000\n", - "a asof join b on a.ccy = b.ccy", true); - } - - @Test - public void testAmbiguousColumn() { - try { - expectFailure("select timestamp from y asof join x on x.ccy = y.ccy"); - } catch (ParserException e) { - Assert.assertEquals(7, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Ambiguous")); - } - } - - @Test - public void testAmbiguousColumnInFunc() { - try { - expectFailure("select sum(timestamp) from y asof join x on x.ccy = y.ccy"); - } catch (ParserException e) { - Assert.assertEquals(11, QueryError.getPosition()); - Assert.assertTrue(Chars.contains(QueryError.getMessage(), "Ambiguous")); - } - } - - @Test - public void testAnonymousSubqueriesFunc() { - try { - expectFailure("select sum(timestamp) from (y) asof join (x) on x.ccy = y.ccy"); - } catch (ParserException e) { - Assert.assertEquals(48, QueryError.getPosition()); - TestUtils.assertEquals("Invalid journal name/alias", QueryError.getMessage()); - } - } - - @Test - public void testFixJoin() throws Exception { - final String expected = "2015-03-10T00:01:00.000Z\tSWHYRX\t9.986581325531\tDHM\t2015-03-10T00:00:40.000Z\tSWHYRX\t671.442138671875\t0.015470010694\tVTJWCP\t-7995393784734742820\t0.1341\t-20409\ttrue\n" + - "2015-03-10T00:02:00.000Z\tVTJWCP\t0.000000022642\tHBEKCGJOZWRXKMTFXRYPHFPUYWNLBVVHN\t2015-03-10T00:01:40.000Z\tVTJWCP\t386.843750000000\t1.195545256138\tVTJWCP\t1669226447966988582\t0.3845\t10793\tfalse\n" + - "2015-03-10T00:03:00.000Z\tVTJWCP\t0.000000012344\tRTLXHBHDHIMFYOJREFUTMSGUYXLXWLUKSXSCMGFCDFGVDKHCZIUISSCBVCLYMFERSXQCHTKLTNYILMDTHTXDEHNVMEVIJQRJMLJKFYHZXH\t2015-03-10T00:02:50.000Z\tVTJWCP\t-353.683593750000\t0.000000000000\tPEHNRX\t6436453824498875972\t0.4737\t21824\tfalse\n" + - "2015-03-10T00:04:00.000Z\tPEHNRX\t0.000000006259\tGOVGNCFYDU\t2015-03-10T00:03:50.000Z\tPEHNRX\t25.839271545410\t0.360216885805\tPEHNRX\t-3290351886406648039\t0.3296\t27881\tfalse\n" + - "2015-03-10T00:05:00.000Z\tSWHYRX\t-1024.000000000000\tZJBFLWWXEBZTZYTHPWGBNPIIFNYPCBTIOJYWUIYFQPXWVETMPCONIJMVFQFDBOMQBLBVQHLSYJUEGYZYOOMNSZVWS\t2015-03-10T00:03:40.000Z\tSWHYRX\t0.003415559302\t640.000000000000\tSWHYRX\t4092568845903588572\t0.5955\t15059\tfalse\n" + - "2015-03-10T00:06:00.000Z\tVTJWCP\t800.000000000000\tEBNYHKWBXMYTZSUXQSWVRVUOSTZQBMERYZ\t2015-03-10T00:05:50.000Z\tVTJWCP\t12.456869840622\t55.575583457947\tPEHNRX\t-8698821645604291033\t0.4353\t2237\tfalse\n" + - "2015-03-10T00:07:00.000Z\tPEHNRX\t0.000000057413\t\t2015-03-10T00:06:30.000Z\tPEHNRX\t-519.289062500000\t0.082934856415\tVTJWCP\t595100009874933367\t0.0227\t-17193\tfalse\n" + - "2015-03-10T00:08:00.000Z\tSWHYRX\t0.897577673197\t\t2015-03-10T00:07:20.000Z\tSWHYRX\t0.000009224671\t-642.406250000000\tSWHYRX\t7862014913865467812\t0.9481\t-22377\tfalse\n" + - "2015-03-10T00:09:00.000Z\tPEHNRX\t797.375000000000\tKXQHOKXHXYWTYFMYVYBVUBHMYQRVVMKMIPOVRTZDGOG\t2015-03-10T00:08:30.000Z\tPEHNRX\t0.033667386509\t64.000000000000\tPEHNRX\t6581120496001202966\t0.6449\t8754\tfalse\n" + - "2015-03-10T00:10:00.000Z\tVTJWCP\t0.000456069203\t\t2015-03-10T00:09:40.000Z\tVTJWCP\t316.796386718750\t0.000000002997\tVTJWCP\t6490952371245756954\t0.4218\t-13242\tfalse\n"; - - long memUsed = Unsafe.getMemUsed(); - try (AsOfPartitionedJoinRecordSource source = new AsOfPartitionedJoinRecordSource( - compileSource("y") - , 0 - , new NoRowIdRecordSource().of(compileSource("select timestamp, ccy, rate, amount, contra, ln, fl, sh, b from x")) - , 0 - , keys - , keys - , 128 - , 128 - , 128 - , cc - )) { - assertThat(expected, source); - } - Assert.assertEquals(memUsed, Unsafe.getMemUsed()); - } - - @Test - public void testFixNonPartitionedJoin() throws Exception { - final String expected = "2015-03-10T00:01:00.000Z\tSWHYRX\t9.986581325531\tDHM\t2015-03-10T00:00:50.000Z\tPEHNRX\t0.299514681101\t768.000000000000\tSWHYRX\t-5710210982977201267\t0.0955\t-29572\ttrue\n" + - "2015-03-10T00:02:00.000Z\tVTJWCP\t0.000000022642\tHBEKCGJOZWRXKMTFXRYPHFPUYWNLBVVHN\t2015-03-10T00:01:50.000Z\tSWHYRX\t0.000036501544\t0.000000036384\tVTJWCP\t8810110521992874823\t0.5159\t28877\tfalse\n" + - "2015-03-10T00:03:00.000Z\tVTJWCP\t0.000000012344\tRTLXHBHDHIMFYOJREFUTMSGUYXLXWLUKSXSCMGFCDFGVDKHCZIUISSCBVCLYMFERSXQCHTKLTNYILMDTHTXDEHNVMEVIJQRJMLJKFYHZXH\t2015-03-10T00:02:50.000Z\tVTJWCP\t-353.683593750000\t0.000000000000\tPEHNRX\t6436453824498875972\t0.4737\t21824\tfalse\n" + - "2015-03-10T00:04:00.000Z\tPEHNRX\t0.000000006259\tGOVGNCFYDU\t2015-03-10T00:03:50.000Z\tPEHNRX\t25.839271545410\t0.360216885805\tPEHNRX\t-3290351886406648039\t0.3296\t27881\tfalse\n" + - "2015-03-10T00:05:00.000Z\tSWHYRX\t-1024.000000000000\tZJBFLWWXEBZTZYTHPWGBNPIIFNYPCBTIOJYWUIYFQPXWVETMPCONIJMVFQFDBOMQBLBVQHLSYJUEGYZYOOMNSZVWS\t2015-03-10T00:04:50.000Z\tPEHNRX\t70.810325622559\t0.000005221712\tSWHYRX\t6904166490726350488\t0.3863\t11305\tfalse\n" + - "2015-03-10T00:06:00.000Z\tVTJWCP\t800.000000000000\tEBNYHKWBXMYTZSUXQSWVRVUOSTZQBMERYZ\t2015-03-10T00:05:50.000Z\tVTJWCP\t12.456869840622\t55.575583457947\tPEHNRX\t-8698821645604291033\t0.4353\t2237\tfalse\n" + - "2015-03-10T00:07:00.000Z\tPEHNRX\t0.000000057413\t\t2015-03-10T00:06:50.000Z\tVTJWCP\t-384.000000000000\t19.552153110504\tVTJWCP\t-3269323743905958237\t0.6822\t11402\ttrue\n" + - "2015-03-10T00:08:00.000Z\tSWHYRX\t0.897577673197\t\t2015-03-10T00:07:50.000Z\tPEHNRX\t272.870239257813\t-128.000000000000\tPEHNRX\t-5016390518489182614\t0.6254\t-8459\tfalse\n" + - "2015-03-10T00:09:00.000Z\tPEHNRX\t797.375000000000\tKXQHOKXHXYWTYFMYVYBVUBHMYQRVVMKMIPOVRTZDGOG\t2015-03-10T00:08:50.000Z\tVTJWCP\t0.004611001699\t0.000000023394\tVTJWCP\t8649805687735202371\t0.7444\t-20513\ttrue\n" + - "2015-03-10T00:10:00.000Z\tVTJWCP\t0.000456069203\t\t2015-03-10T00:09:50.000Z\tSWHYRX\t552.831069946289\t0.013248343952\tPEHNRX\t-9141139959474635253\t0.5255\t19898\ttrue\n"; - - long memUsed = Unsafe.getMemUsed(); - try (AsOfJoinRecordSource source = new AsOfJoinRecordSource( - compileSource("y") - , 0 - , new NoRowIdRecordSource().of(compileSource("select timestamp, ccy, rate, amount, contra, ln, fl, sh, b from x")) - , 0 - )) { - assertThat(expected, source); - } - - Assert.assertEquals(memUsed, Unsafe.getMemUsed()); - } - - @Test - public void testNonPartitionedQuery() throws Exception { - String expected = "2015-03-10T00:01:00.000Z\tSWHYRX\t9.986581325531\tDHM\t2015-03-10T00:00:50.000Z\tPEHNRX\t0.299514681101\t768.000000000000\t\tSWHYRX\t0.0955\t-29572\t-5710210982977201267\ttrue\n" + - "2015-03-10T00:02:00.000Z\tVTJWCP\t0.000000022642\tHBEKCGJOZWRXKMTFXRYPHFPUYWNLBVVHN\t2015-03-10T00:01:50.000Z\tSWHYRX\t0.000036501544\t0.000000036384\tHFVWSWSRGOO\tVTJWCP\t0.5159\t28877\t8810110521992874823\tfalse\n" + - "2015-03-10T00:03:00.000Z\tVTJWCP\t0.000000012344\tRTLXHBHDHIMFYOJREFUTMSGUYXLXWLUKSXSCMGFCDFGVDKHCZIUISSCBVCLYMFERSXQCHTKLTNYILMDTHTXDEHNVMEVIJQRJMLJKFYHZXH\t2015-03-10T00:02:50.000Z\tVTJWCP\t-353.683593750000\t0.000000000000\t\tPEHNRX\t0.4737\t21824\t6436453824498875972\tfalse\n" + - "2015-03-10T00:04:00.000Z\tPEHNRX\t0.000000006259\tGOVGNCFYDU\t2015-03-10T00:03:50.000Z\tPEHNRX\t25.839271545410\t0.360216885805\tZKYFLUHZQSNPXMKJSMKIXEYVTUPDHHGGIWHPZRHHMGZJYYFLSVIHDWWLEVMLKCJBEVLUHLIHYBTVZNCLN\tPEHNRX\t0.3296\t27881\t-3290351886406648039\tfalse\n" + - "2015-03-10T00:05:00.000Z\tSWHYRX\t-1024.000000000000\tZJBFLWWXEBZTZYTHPWGBNPIIFNYPCBTIOJYWUIYFQPXWVETMPCONIJMVFQFDBOMQBLBVQHLSYJUEGYZYOOMNSZVWS\t2015-03-10T00:04:50.000Z\tPEHNRX\t70.810325622559\t0.000005221712\tXCDKDWOMDXCBJFRPXZSFXUNYQXTGNJJILLEYMIWTCWLFORGFIEVMKPYVGPYKKBMQMUDDCIHCNPUGJOPJEUKWMDNZZBBUKOJSOLDYRODIPUNRPSMIFDYPDK\tSWHYRX\t0.3863\t11305\t6904166490726350488\tfalse\n" + - "2015-03-10T00:06:00.000Z\tVTJWCP\t800.000000000000\tEBNYHKWBXMYTZSUXQSWVRVUOSTZQBMERYZ\t2015-03-10T00:05:50.000Z\tVTJWCP\t12.456869840622\t55.575583457947\tDILELRUMMZSCJOUOUIGENFELWWRSLBMQHGJBFQBBKFIJZZYNPPB\tPEHNRX\t0.4353\t2237\t-8698821645604291033\tfalse\n" + - "2015-03-10T00:07:00.000Z\tPEHNRX\t0.000000057413\t\t2015-03-10T00:06:50.000Z\tVTJWCP\t-384.000000000000\t19.552153110504\tRHGKRKKUSIMYDXUUSKCXNMUREIJUHCLQCMZCCYVBDMQEHDHQHKSNGIZRPFM\tVTJWCP\t0.6822\t11402\t-3269323743905958237\ttrue\n" + - "2015-03-10T00:08:00.000Z\tSWHYRX\t0.897577673197\t\t2015-03-10T00:07:50.000Z\tPEHNRX\t272.870239257813\t-128.000000000000\t\tPEHNRX\t0.6254\t-8459\t-5016390518489182614\tfalse\n" + - "2015-03-10T00:09:00.000Z\tPEHNRX\t797.375000000000\tKXQHOKXHXYWTYFMYVYBVUBHMYQRVVMKMIPOVRTZDGOG\t2015-03-10T00:08:50.000Z\tVTJWCP\t0.004611001699\t0.000000023394\tUMKUBKXPMSXQSTVSTYSWHLSWPFHXDBXPNKGQELQDWQGMZBPHETSLOIMSUFXYIWE\tVTJWCP\t0.7444\t-20513\t8649805687735202371\ttrue\n" + - "2015-03-10T00:10:00.000Z\tVTJWCP\t0.000456069203\t\t2015-03-10T00:09:50.000Z\tSWHYRX\t552.831069946289\t0.013248343952\t\tPEHNRX\t0.5255\t19898\t-9141139959474635253\ttrue\n"; - assertThat(expected, "y asof join x"); - } - - @Test - public void testPartitionedQuery() throws Exception { - final String expected = "2015-03-10T00:01:00.000Z\tSWHYRX\t9.986581325531\tDHM\t2015-03-10T00:00:40.000Z\tSWHYRX\t671.442138671875\t0.015470010694\t\tVTJWCP\t0.1341\t-20409\t-7995393784734742820\ttrue\n" + - "2015-03-10T00:02:00.000Z\tVTJWCP\t0.000000022642\tHBEKCGJOZWRXKMTFXRYPHFPUYWNLBVVHN\t2015-03-10T00:01:40.000Z\tVTJWCP\t386.843750000000\t1.195545256138\t\tVTJWCP\t0.3845\t10793\t1669226447966988582\tfalse\n" + - "2015-03-10T00:03:00.000Z\tVTJWCP\t0.000000012344\tRTLXHBHDHIMFYOJREFUTMSGUYXLXWLUKSXSCMGFCDFGVDKHCZIUISSCBVCLYMFERSXQCHTKLTNYILMDTHTXDEHNVMEVIJQRJMLJKFYHZXH\t2015-03-10T00:02:50.000Z\tVTJWCP\t-353.683593750000\t0.000000000000\t\tPEHNRX\t0.4737\t21824\t6436453824498875972\tfalse\n" + - "2015-03-10T00:04:00.000Z\tPEHNRX\t0.000000006259\tGOVGNCFYDU\t2015-03-10T00:03:50.000Z\tPEHNRX\t25.839271545410\t0.360216885805\tZKYFLUHZQSNPXMKJSMKIXEYVTUPDHHGGIWHPZRHHMGZJYYFLSVIHDWWLEVMLKCJBEVLUHLIHYBTVZNCLN\tPEHNRX\t0.3296\t27881\t-3290351886406648039\tfalse\n" + - "2015-03-10T00:05:00.000Z\tSWHYRX\t-1024.000000000000\tZJBFLWWXEBZTZYTHPWGBNPIIFNYPCBTIOJYWUIYFQPXWVETMPCONIJMVFQFDBOMQBLBVQHLSYJUEGYZYOOMNSZVWS\t2015-03-10T00:03:40.000Z\tSWHYRX\t0.003415559302\t640.000000000000\t\tSWHYRX\t0.5955\t15059\t4092568845903588572\tfalse\n" + - "2015-03-10T00:06:00.000Z\tVTJWCP\t800.000000000000\tEBNYHKWBXMYTZSUXQSWVRVUOSTZQBMERYZ\t2015-03-10T00:05:50.000Z\tVTJWCP\t12.456869840622\t55.575583457947\tDILELRUMMZSCJOUOUIGENFELWWRSLBMQHGJBFQBBKFIJZZYNPPB\tPEHNRX\t0.4353\t2237\t-8698821645604291033\tfalse\n" + - "2015-03-10T00:07:00.000Z\tPEHNRX\t0.000000057413\t\t2015-03-10T00:06:30.000Z\tPEHNRX\t-519.289062500000\t0.082934856415\t\tVTJWCP\t0.0227\t-17193\t595100009874933367\tfalse\n" + - "2015-03-10T00:08:00.000Z\tSWHYRX\t0.897577673197\t\t2015-03-10T00:07:20.000Z\tSWHYRX\t0.000009224671\t-642.406250000000\tIEBSQCNSFFLTRYZUZYJIHZBWWXFQDCQSC\tSWHYRX\t0.9481\t-22377\t7862014913865467812\tfalse\n" + - "2015-03-10T00:09:00.000Z\tPEHNRX\t797.375000000000\tKXQHOKXHXYWTYFMYVYBVUBHMYQRVVMKMIPOVRTZDGOG\t2015-03-10T00:08:30.000Z\tPEHNRX\t0.033667386509\t64.000000000000\tDSWXYYYVSYYEQBORDTQHVCVUYGMBMKSCPWLZKDMPVRHW\tPEHNRX\t0.6449\t8754\t6581120496001202966\tfalse\n" + - "2015-03-10T00:10:00.000Z\tVTJWCP\t0.000456069203\t\t2015-03-10T00:09:40.000Z\tVTJWCP\t316.796386718750\t0.000000002997\tMCIYIXGHRQQTKOJEDNKRCGKSQDCMUMKNJGSPETBBQDSRDJWIMGPLRQUJJFGQIZKMDCXYTRVYQNFPGSQIXMIIFSWXSDDJSPKSHRIH\tVTJWCP\t0.4218\t-13242\t6490952371245756954\tfalse\n"; - assertThat(expected, "y asof join x on x.ccy = y.ccy"); - } - - @Test - public void testPartitionedQuerySimplifiedJoin() throws Exception { - final String expected = "2015-03-10T00:01:00.000Z\tSWHYRX\t9.986581325531\tDHM\t2015-03-10T00:00:40.000Z\tSWHYRX\t671.442138671875\t0.015470010694\t\tVTJWCP\t0.1341\t-20409\t-7995393784734742820\ttrue\n" + - "2015-03-10T00:02:00.000Z\tVTJWCP\t0.000000022642\tHBEKCGJOZWRXKMTFXRYPHFPUYWNLBVVHN\t2015-03-10T00:01:40.000Z\tVTJWCP\t386.843750000000\t1.195545256138\t\tVTJWCP\t0.3845\t10793\t1669226447966988582\tfalse\n" + - "2015-03-10T00:03:00.000Z\tVTJWCP\t0.000000012344\tRTLXHBHDHIMFYOJREFUTMSGUYXLXWLUKSXSCMGFCDFGVDKHCZIUISSCBVCLYMFERSXQCHTKLTNYILMDTHTXDEHNVMEVIJQRJMLJKFYHZXH\t2015-03-10T00:02:50.000Z\tVTJWCP\t-353.683593750000\t0.000000000000\t\tPEHNRX\t0.4737\t21824\t6436453824498875972\tfalse\n" + - "2015-03-10T00:04:00.000Z\tPEHNRX\t0.000000006259\tGOVGNCFYDU\t2015-03-10T00:03:50.000Z\tPEHNRX\t25.839271545410\t0.360216885805\tZKYFLUHZQSNPXMKJSMKIXEYVTUPDHHGGIWHPZRHHMGZJYYFLSVIHDWWLEVMLKCJBEVLUHLIHYBTVZNCLN\tPEHNRX\t0.3296\t27881\t-3290351886406648039\tfalse\n" + - "2015-03-10T00:05:00.000Z\tSWHYRX\t-1024.000000000000\tZJBFLWWXEBZTZYTHPWGBNPIIFNYPCBTIOJYWUIYFQPXWVETMPCONIJMVFQFDBOMQBLBVQHLSYJUEGYZYOOMNSZVWS\t2015-03-10T00:03:40.000Z\tSWHYRX\t0.003415559302\t640.000000000000\t\tSWHYRX\t0.5955\t15059\t4092568845903588572\tfalse\n" + - "2015-03-10T00:06:00.000Z\tVTJWCP\t800.000000000000\tEBNYHKWBXMYTZSUXQSWVRVUOSTZQBMERYZ\t2015-03-10T00:05:50.000Z\tVTJWCP\t12.456869840622\t55.575583457947\tDILELRUMMZSCJOUOUIGENFELWWRSLBMQHGJBFQBBKFIJZZYNPPB\tPEHNRX\t0.4353\t2237\t-8698821645604291033\tfalse\n" + - "2015-03-10T00:07:00.000Z\tPEHNRX\t0.000000057413\t\t2015-03-10T00:06:30.000Z\tPEHNRX\t-519.289062500000\t0.082934856415\t\tVTJWCP\t0.0227\t-17193\t595100009874933367\tfalse\n" + - "2015-03-10T00:08:00.000Z\tSWHYRX\t0.897577673197\t\t2015-03-10T00:07:20.000Z\tSWHYRX\t0.000009224671\t-642.406250000000\tIEBSQCNSFFLTRYZUZYJIHZBWWXFQDCQSC\tSWHYRX\t0.9481\t-22377\t7862014913865467812\tfalse\n" + - "2015-03-10T00:09:00.000Z\tPEHNRX\t797.375000000000\tKXQHOKXHXYWTYFMYVYBVUBHMYQRVVMKMIPOVRTZDGOG\t2015-03-10T00:08:30.000Z\tPEHNRX\t0.033667386509\t64.000000000000\tDSWXYYYVSYYEQBORDTQHVCVUYGMBMKSCPWLZKDMPVRHW\tPEHNRX\t0.6449\t8754\t6581120496001202966\tfalse\n" + - "2015-03-10T00:10:00.000Z\tVTJWCP\t0.000456069203\t\t2015-03-10T00:09:40.000Z\tVTJWCP\t316.796386718750\t0.000000002997\tMCIYIXGHRQQTKOJEDNKRCGKSQDCMUMKNJGSPETBBQDSRDJWIMGPLRQUJJFGQIZKMDCXYTRVYQNFPGSQIXMIIFSWXSDDJSPKSHRIH\tVTJWCP\t0.4218\t-13242\t6490952371245756954\tfalse\n"; - assertThat(expected, "y asof join x on (ccy)"); - } - - @Test - public void testRowidJoin() throws Exception { - final String expected = "timestamp\tccy\tamount\ttrader\ttimestamp\tccy\trate\tamount\ttrader\tcontra\tfl\tsh\tln\tb\n" + - "2015-03-10T00:01:00.000Z\tSWHYRX\t9.986581325531\tDHM\t2015-03-10T00:00:40.000Z\tSWHYRX\t671.442138671875\t0.015470010694\t\tVTJWCP\t0.1341\t-20409\t-7995393784734742820\ttrue\n" + - "2015-03-10T00:02:00.000Z\tVTJWCP\t0.000000022642\tHBEKCGJOZWRXKMTFXRYPHFPUYWNLBVVHN\t2015-03-10T00:01:40.000Z\tVTJWCP\t386.843750000000\t1.195545256138\t\tVTJWCP\t0.3845\t10793\t1669226447966988582\tfalse\n" + - "2015-03-10T00:03:00.000Z\tVTJWCP\t0.000000012344\tRTLXHBHDHIMFYOJREFUTMSGUYXLXWLUKSXSCMGFCDFGVDKHCZIUISSCBVCLYMFERSXQCHTKLTNYILMDTHTXDEHNVMEVIJQRJMLJKFYHZXH\t2015-03-10T00:02:50.000Z\tVTJWCP\t-353.683593750000\t0.000000000000\t\tPEHNRX\t0.4737\t21824\t6436453824498875972\tfalse\n" + - "2015-03-10T00:04:00.000Z\tPEHNRX\t0.000000006259\tGOVGNCFYDU\t2015-03-10T00:03:50.000Z\tPEHNRX\t25.839271545410\t0.360216885805\tZKYFLUHZQSNPXMKJSMKIXEYVTUPDHHGGIWHPZRHHMGZJYYFLSVIHDWWLEVMLKCJBEVLUHLIHYBTVZNCLN\tPEHNRX\t0.3296\t27881\t-3290351886406648039\tfalse\n" + - "2015-03-10T00:05:00.000Z\tSWHYRX\t-1024.000000000000\tZJBFLWWXEBZTZYTHPWGBNPIIFNYPCBTIOJYWUIYFQPXWVETMPCONIJMVFQFDBOMQBLBVQHLSYJUEGYZYOOMNSZVWS\t2015-03-10T00:03:40.000Z\tSWHYRX\t0.003415559302\t640.000000000000\t\tSWHYRX\t0.5955\t15059\t4092568845903588572\tfalse\n" + - "2015-03-10T00:06:00.000Z\tVTJWCP\t800.000000000000\tEBNYHKWBXMYTZSUXQSWVRVUOSTZQBMERYZ\t2015-03-10T00:05:50.000Z\tVTJWCP\t12.456869840622\t55.575583457947\tDILELRUMMZSCJOUOUIGENFELWWRSLBMQHGJBFQBBKFIJZZYNPPB\tPEHNRX\t0.4353\t2237\t-8698821645604291033\tfalse\n" + - "2015-03-10T00:07:00.000Z\tPEHNRX\t0.000000057413\t\t2015-03-10T00:06:30.000Z\tPEHNRX\t-519.289062500000\t0.082934856415\t\tVTJWCP\t0.0227\t-17193\t595100009874933367\tfalse\n" + - "2015-03-10T00:08:00.000Z\tSWHYRX\t0.897577673197\t\t2015-03-10T00:07:20.000Z\tSWHYRX\t0.000009224671\t-642.406250000000\tIEBSQCNSFFLTRYZUZYJIHZBWWXFQDCQSC\tSWHYRX\t0.9481\t-22377\t7862014913865467812\tfalse\n" + - "2015-03-10T00:09:00.000Z\tPEHNRX\t797.375000000000\tKXQHOKXHXYWTYFMYVYBVUBHMYQRVVMKMIPOVRTZDGOG\t2015-03-10T00:08:30.000Z\tPEHNRX\t0.033667386509\t64.000000000000\tDSWXYYYVSYYEQBORDTQHVCVUYGMBMKSCPWLZKDMPVRHW\tPEHNRX\t0.6449\t8754\t6581120496001202966\tfalse\n" + - "2015-03-10T00:10:00.000Z\tVTJWCP\t0.000456069203\t\t2015-03-10T00:09:40.000Z\tVTJWCP\t316.796386718750\t0.000000002997\tMCIYIXGHRQQTKOJEDNKRCGKSQDCMUMKNJGSPETBBQDSRDJWIMGPLRQUJJFGQIZKMDCXYTRVYQNFPGSQIXMIIFSWXSDDJSPKSHRIH\tVTJWCP\t0.4218\t-13242\t6490952371245756954\tfalse\n"; - - try (AsOfPartitionedJoinRecordSource source = new AsOfPartitionedJoinRecordSource( - compileSource("y") - , 0 - , compileSource("x") - , 0 - , keys - , keys - , 512 - , 512 - , 512 - , cc - )) { - assertThat(expected, source, true); - } - } - - @Test - public void testRowidNonPartitioned() throws Exception { - - AsOfJoinRecordSource source = new AsOfJoinRecordSource( - compileSource("y") - , 0 - , compileSource("x") - , 0 - ); - - String expected = "2015-03-10T00:01:00.000Z\tSWHYRX\t9.986581325531\tDHM\t2015-03-10T00:00:50.000Z\tPEHNRX\t0.299514681101\t768.000000000000\t\tSWHYRX\t0.0955\t-29572\t-5710210982977201267\ttrue\n" + - "2015-03-10T00:02:00.000Z\tVTJWCP\t0.000000022642\tHBEKCGJOZWRXKMTFXRYPHFPUYWNLBVVHN\t2015-03-10T00:01:50.000Z\tSWHYRX\t0.000036501544\t0.000000036384\tHFVWSWSRGOO\tVTJWCP\t0.5159\t28877\t8810110521992874823\tfalse\n" + - "2015-03-10T00:03:00.000Z\tVTJWCP\t0.000000012344\tRTLXHBHDHIMFYOJREFUTMSGUYXLXWLUKSXSCMGFCDFGVDKHCZIUISSCBVCLYMFERSXQCHTKLTNYILMDTHTXDEHNVMEVIJQRJMLJKFYHZXH\t2015-03-10T00:02:50.000Z\tVTJWCP\t-353.683593750000\t0.000000000000\t\tPEHNRX\t0.4737\t21824\t6436453824498875972\tfalse\n" + - "2015-03-10T00:04:00.000Z\tPEHNRX\t0.000000006259\tGOVGNCFYDU\t2015-03-10T00:03:50.000Z\tPEHNRX\t25.839271545410\t0.360216885805\tZKYFLUHZQSNPXMKJSMKIXEYVTUPDHHGGIWHPZRHHMGZJYYFLSVIHDWWLEVMLKCJBEVLUHLIHYBTVZNCLN\tPEHNRX\t0.3296\t27881\t-3290351886406648039\tfalse\n" + - "2015-03-10T00:05:00.000Z\tSWHYRX\t-1024.000000000000\tZJBFLWWXEBZTZYTHPWGBNPIIFNYPCBTIOJYWUIYFQPXWVETMPCONIJMVFQFDBOMQBLBVQHLSYJUEGYZYOOMNSZVWS\t2015-03-10T00:04:50.000Z\tPEHNRX\t70.810325622559\t0.000005221712\tXCDKDWOMDXCBJFRPXZSFXUNYQXTGNJJILLEYMIWTCWLFORGFIEVMKPYVGPYKKBMQMUDDCIHCNPUGJOPJEUKWMDNZZBBUKOJSOLDYRODIPUNRPSMIFDYPDK\tSWHYRX\t0.3863\t11305\t6904166490726350488\tfalse\n" + - "2015-03-10T00:06:00.000Z\tVTJWCP\t800.000000000000\tEBNYHKWBXMYTZSUXQSWVRVUOSTZQBMERYZ\t2015-03-10T00:05:50.000Z\tVTJWCP\t12.456869840622\t55.575583457947\tDILELRUMMZSCJOUOUIGENFELWWRSLBMQHGJBFQBBKFIJZZYNPPB\tPEHNRX\t0.4353\t2237\t-8698821645604291033\tfalse\n" + - "2015-03-10T00:07:00.000Z\tPEHNRX\t0.000000057413\t\t2015-03-10T00:06:50.000Z\tVTJWCP\t-384.000000000000\t19.552153110504\tRHGKRKKUSIMYDXUUSKCXNMUREIJUHCLQCMZCCYVBDMQEHDHQHKSNGIZRPFM\tVTJWCP\t0.6822\t11402\t-3269323743905958237\ttrue\n" + - "2015-03-10T00:08:00.000Z\tSWHYRX\t0.897577673197\t\t2015-03-10T00:07:50.000Z\tPEHNRX\t272.870239257813\t-128.000000000000\t\tPEHNRX\t0.6254\t-8459\t-5016390518489182614\tfalse\n" + - "2015-03-10T00:09:00.000Z\tPEHNRX\t797.375000000000\tKXQHOKXHXYWTYFMYVYBVUBHMYQRVVMKMIPOVRTZDGOG\t2015-03-10T00:08:50.000Z\tVTJWCP\t0.004611001699\t0.000000023394\tUMKUBKXPMSXQSTVSTYSWHLSWPFHXDBXPNKGQELQDWQGMZBPHETSLOIMSUFXYIWE\tVTJWCP\t0.7444\t-20513\t8649805687735202371\ttrue\n" + - "2015-03-10T00:10:00.000Z\tVTJWCP\t0.000456069203\t\t2015-03-10T00:09:50.000Z\tSWHYRX\t552.831069946289\t0.013248343952\t\tPEHNRX\t0.5255\t19898\t-9141139959474635253\ttrue\n"; - assertThat(expected, source); - } - - @Test - public void testStrings() throws Exception { - try (AsOfPartitionedJoinRecordSource source = new AsOfPartitionedJoinRecordSource( - compileSource("y") - , 0 - , new NoRowIdRecordSource().of(compileSource("x")) - , 0 - , keys - , keys - , 512 - , 512 - , 512 - , cc - )) { - StringSink testSink = new StringSink(); - int idx = source.getMetadata().getColumnIndex("trader"); - RecordCursor cursor = source.prepareCursor(FACTORY_CONTAINER.getFactory()); - try { - for (Record r : cursor) { - testSink.clear(); - r.getStr(idx, testSink); - - if (r.getFlyweightStr(idx) == null) { - Assert.assertEquals(0, testSink.length()); - } else { - TestUtils.assertEquals(r.getFlyweightStr(idx), testSink); - } - TestUtils.assertEquals(r.getFlyweightStr(idx), r.getFlyweightStr(idx)); - } - } finally { - cursor.releaseCursor(); - } - } - } - - @Test - public void testVarJoin() throws Exception { - final String expected = "timestamp\tccy\tamount\ttrader\ttimestamp\tccy\trate\tamount\ttrader\tcontra\tfl\tsh\tln\tb\n" + - "2015-03-10T00:01:00.000Z\tSWHYRX\t9.986581325531\tDHM\t2015-03-10T00:00:40.000Z\tSWHYRX\t671.442138671875\t0.015470010694\t\tVTJWCP\t0.1341\t-20409\t-7995393784734742820\ttrue\n" + - "2015-03-10T00:02:00.000Z\tVTJWCP\t0.000000022642\tHBEKCGJOZWRXKMTFXRYPHFPUYWNLBVVHN\t2015-03-10T00:01:40.000Z\tVTJWCP\t386.843750000000\t1.195545256138\t\tVTJWCP\t0.3845\t10793\t1669226447966988582\tfalse\n" + - "2015-03-10T00:03:00.000Z\tVTJWCP\t0.000000012344\tRTLXHBHDHIMFYOJREFUTMSGUYXLXWLUKSXSCMGFCDFGVDKHCZIUISSCBVCLYMFERSXQCHTKLTNYILMDTHTXDEHNVMEVIJQRJMLJKFYHZXH\t2015-03-10T00:02:50.000Z\tVTJWCP\t-353.683593750000\t0.000000000000\t\tPEHNRX\t0.4737\t21824\t6436453824498875972\tfalse\n" + - "2015-03-10T00:04:00.000Z\tPEHNRX\t0.000000006259\tGOVGNCFYDU\t2015-03-10T00:03:50.000Z\tPEHNRX\t25.839271545410\t0.360216885805\tZKYFLUHZQSNPXMKJSMKIXEYVTUPDHHGGIWHPZRHHMGZJYYFLSVIHDWWLEVMLKCJBEVLUHLIHYBTVZNCLN\tPEHNRX\t0.3296\t27881\t-3290351886406648039\tfalse\n" + - "2015-03-10T00:05:00.000Z\tSWHYRX\t-1024.000000000000\tZJBFLWWXEBZTZYTHPWGBNPIIFNYPCBTIOJYWUIYFQPXWVETMPCONIJMVFQFDBOMQBLBVQHLSYJUEGYZYOOMNSZVWS\t2015-03-10T00:03:40.000Z\tSWHYRX\t0.003415559302\t640.000000000000\t\tSWHYRX\t0.5955\t15059\t4092568845903588572\tfalse\n" + - "2015-03-10T00:06:00.000Z\tVTJWCP\t800.000000000000\tEBNYHKWBXMYTZSUXQSWVRVUOSTZQBMERYZ\t2015-03-10T00:05:50.000Z\tVTJWCP\t12.456869840622\t55.575583457947\tDILELRUMMZSCJOUOUIGENFELWWRSLBMQHGJBFQBBKFIJZZYNPPB\tPEHNRX\t0.4353\t2237\t-8698821645604291033\tfalse\n" + - "2015-03-10T00:07:00.000Z\tPEHNRX\t0.000000057413\t\t2015-03-10T00:06:30.000Z\tPEHNRX\t-519.289062500000\t0.082934856415\t\tVTJWCP\t0.0227\t-17193\t595100009874933367\tfalse\n" + - "2015-03-10T00:08:00.000Z\tSWHYRX\t0.897577673197\t\t2015-03-10T00:07:20.000Z\tSWHYRX\t0.000009224671\t-642.406250000000\tIEBSQCNSFFLTRYZUZYJIHZBWWXFQDCQSC\tSWHYRX\t0.9481\t-22377\t7862014913865467812\tfalse\n" + - "2015-03-10T00:09:00.000Z\tPEHNRX\t797.375000000000\tKXQHOKXHXYWTYFMYVYBVUBHMYQRVVMKMIPOVRTZDGOG\t2015-03-10T00:08:30.000Z\tPEHNRX\t0.033667386509\t64.000000000000\tDSWXYYYVSYYEQBORDTQHVCVUYGMBMKSCPWLZKDMPVRHW\tPEHNRX\t0.6449\t8754\t6581120496001202966\tfalse\n" + - "2015-03-10T00:10:00.000Z\tVTJWCP\t0.000456069203\t\t2015-03-10T00:09:40.000Z\tVTJWCP\t316.796386718750\t0.000000002997\tMCIYIXGHRQQTKOJEDNKRCGKSQDCMUMKNJGSPETBBQDSRDJWIMGPLRQUJJFGQIZKMDCXYTRVYQNFPGSQIXMIIFSWXSDDJSPKSHRIH\tVTJWCP\t0.4218\t-13242\t6490952371245756954\tfalse\n"; - - try (AsOfPartitionedJoinRecordSource source = new AsOfPartitionedJoinRecordSource( - compileSource("y") - , 0 - , new NoRowIdRecordSource().of(compileSource("x")) - , 0 - , keys - , keys - , 512 - , 512 - , 512 - , cc - )) { - assertThat(expected, source, true); - } - } - - @Test - public void testVarNonPartitioned() throws Exception { - - try (AsOfJoinRecordSource source = new AsOfJoinRecordSource( - compileSource("y") - , 0 - , new NoRowIdRecordSource().of(compileSource("x")) - , 0 - )) { - - String expected = "2015-03-10T00:01:00.000Z\tSWHYRX\t9.986581325531\tDHM\t2015-03-10T00:00:50.000Z\tPEHNRX\t0.299514681101\t768.000000000000\t\tSWHYRX\t0.0955\t-29572\t-5710210982977201267\ttrue\n" + - "2015-03-10T00:02:00.000Z\tVTJWCP\t0.000000022642\tHBEKCGJOZWRXKMTFXRYPHFPUYWNLBVVHN\t2015-03-10T00:01:50.000Z\tSWHYRX\t0.000036501544\t0.000000036384\tHFVWSWSRGOO\tVTJWCP\t0.5159\t28877\t8810110521992874823\tfalse\n" + - "2015-03-10T00:03:00.000Z\tVTJWCP\t0.000000012344\tRTLXHBHDHIMFYOJREFUTMSGUYXLXWLUKSXSCMGFCDFGVDKHCZIUISSCBVCLYMFERSXQCHTKLTNYILMDTHTXDEHNVMEVIJQRJMLJKFYHZXH\t2015-03-10T00:02:50.000Z\tVTJWCP\t-353.683593750000\t0.000000000000\t\tPEHNRX\t0.4737\t21824\t6436453824498875972\tfalse\n" + - "2015-03-10T00:04:00.000Z\tPEHNRX\t0.000000006259\tGOVGNCFYDU\t2015-03-10T00:03:50.000Z\tPEHNRX\t25.839271545410\t0.360216885805\tZKYFLUHZQSNPXMKJSMKIXEYVTUPDHHGGIWHPZRHHMGZJYYFLSVIHDWWLEVMLKCJBEVLUHLIHYBTVZNCLN\tPEHNRX\t0.3296\t27881\t-3290351886406648039\tfalse\n" + - "2015-03-10T00:05:00.000Z\tSWHYRX\t-1024.000000000000\tZJBFLWWXEBZTZYTHPWGBNPIIFNYPCBTIOJYWUIYFQPXWVETMPCONIJMVFQFDBOMQBLBVQHLSYJUEGYZYOOMNSZVWS\t2015-03-10T00:04:50.000Z\tPEHNRX\t70.810325622559\t0.000005221712\tXCDKDWOMDXCBJFRPXZSFXUNYQXTGNJJILLEYMIWTCWLFORGFIEVMKPYVGPYKKBMQMUDDCIHCNPUGJOPJEUKWMDNZZBBUKOJSOLDYRODIPUNRPSMIFDYPDK\tSWHYRX\t0.3863\t11305\t6904166490726350488\tfalse\n" + - "2015-03-10T00:06:00.000Z\tVTJWCP\t800.000000000000\tEBNYHKWBXMYTZSUXQSWVRVUOSTZQBMERYZ\t2015-03-10T00:05:50.000Z\tVTJWCP\t12.456869840622\t55.575583457947\tDILELRUMMZSCJOUOUIGENFELWWRSLBMQHGJBFQBBKFIJZZYNPPB\tPEHNRX\t0.4353\t2237\t-8698821645604291033\tfalse\n" + - "2015-03-10T00:07:00.000Z\tPEHNRX\t0.000000057413\t\t2015-03-10T00:06:50.000Z\tVTJWCP\t-384.000000000000\t19.552153110504\tRHGKRKKUSIMYDXUUSKCXNMUREIJUHCLQCMZCCYVBDMQEHDHQHKSNGIZRPFM\tVTJWCP\t0.6822\t11402\t-3269323743905958237\ttrue\n" + - "2015-03-10T00:08:00.000Z\tSWHYRX\t0.897577673197\t\t2015-03-10T00:07:50.000Z\tPEHNRX\t272.870239257813\t-128.000000000000\t\tPEHNRX\t0.6254\t-8459\t-5016390518489182614\tfalse\n" + - "2015-03-10T00:09:00.000Z\tPEHNRX\t797.375000000000\tKXQHOKXHXYWTYFMYVYBVUBHMYQRVVMKMIPOVRTZDGOG\t2015-03-10T00:08:50.000Z\tVTJWCP\t0.004611001699\t0.000000023394\tUMKUBKXPMSXQSTVSTYSWHLSWPFHXDBXPNKGQELQDWQGMZBPHETSLOIMSUFXYIWE\tVTJWCP\t0.7444\t-20513\t8649805687735202371\ttrue\n" + - "2015-03-10T00:10:00.000Z\tVTJWCP\t0.000456069203\t\t2015-03-10T00:09:50.000Z\tSWHYRX\t552.831069946289\t0.013248343952\t\tPEHNRX\t0.5255\t19898\t-9141139959474635253\ttrue\n"; - printer.print(source, FACTORY_CONTAINER.getFactory()); - TestUtils.assertEquals(expected, sink); - } - } - - private void assertThat(String expected, RecordSource source) throws IOException { - assertThat(expected, source, false); - } - - static { - keys.add("ccy"); - } -} diff --git a/core/src/test/java/com/questdb/ql/DDLTests.java b/core/src/test/java/com/questdb/ql/DDLTests.java deleted file mode 100644 index b837203bf..000000000 --- a/core/src/test/java/com/questdb/ql/DDLTests.java +++ /dev/null @@ -1,1253 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql; - -import com.questdb.ex.ParserException; -import com.questdb.parser.sql.QueryCompiler; -import com.questdb.parser.sql.QueryError; -import com.questdb.std.ByteBuffers; -import com.questdb.std.DirectInputStream; -import com.questdb.std.Rnd; -import com.questdb.std.Unsafe; -import com.questdb.std.ex.JournalException; -import com.questdb.std.time.DateFormatUtils; -import com.questdb.std.time.Dates; -import com.questdb.store.*; -import com.questdb.store.factory.configuration.JournalMetadata; -import com.questdb.test.tools.AbstractTest; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Test; - -import java.io.File; -import java.nio.ByteBuffer; - -public class DDLTests extends AbstractTest { - - private static final QueryCompiler compiler = new QueryCompiler(); - - @Test - public void testBadIntBuckets() throws Exception { - try { - exec("create table x (a INT index buckets -1, b BYTE, t TIMESTAMP, x SYMBOL) partition by MONTH"); - Assert.fail(); - } catch (ParserException ignore) { - // good, pass - } - } - - public void testCast(int from, int to) throws Exception { - int n = 100; - try (JournalWriter w1 = compiler.createWriter(getFactory(), "create table y (a " + ColumnType.nameOf(from) + ") record hint 100")) { - Rnd rnd = new Rnd(); - for (int i = 0; i < n; i++) { - JournalEntryWriter ew = w1.entryWriter(); - switch (from) { - case ColumnType.INT: - ew.putInt(0, rnd.nextInt()); - break; - case ColumnType.LONG: - ew.putLong(0, rnd.nextLong()); - break; - case ColumnType.DATE: - ew.putDate(0, rnd.nextLong()); - break; - case ColumnType.BYTE: - ew.put(0, rnd.nextByte()); - break; - case ColumnType.SHORT: - ew.putShort(0, rnd.nextShort()); - break; - case ColumnType.FLOAT: - ew.putFloat(0, rnd.nextFloat()); - break; - case ColumnType.DOUBLE: - ew.putDouble(0, rnd.nextDouble()); - break; - case ColumnType.SYMBOL: - ew.putSym(0, rnd.nextChars(10)); - break; - case ColumnType.STRING: - ew.putStr(0, rnd.nextChars(10)); - break; - default: - break; - } - ew.append(); - } - w1.commit(); - } - - exec("create table x as (y), cast(a as " + ColumnType.nameOf(to) + ") record hint 100"); - - try (RecordSource rs = compiler.compile(getFactory(), "x")) { - Rnd rnd = new Rnd(); - Assert.assertEquals(to, rs.getMetadata().getColumnQuick(0).getType()); - RecordCursor cursor = rs.prepareCursor(getFactory()); - try { - while (cursor.hasNext()) { - switch (from) { - case ColumnType.INT: - switch (to) { - case ColumnType.SHORT: - Assert.assertEquals((short) rnd.nextInt(), cursor.next().getShort(0)); - break; - case ColumnType.LONG: - Assert.assertEquals((long) rnd.nextInt(), cursor.next().getLong(0)); - break; - case ColumnType.BYTE: - Assert.assertEquals((byte) rnd.nextInt(), cursor.next().getByte(0)); - break; - case ColumnType.FLOAT: - Assert.assertEquals((float) rnd.nextInt(), cursor.next().getFloat(0), 0.000000001f); - break; - case ColumnType.DOUBLE: - Assert.assertEquals((double) rnd.nextInt(), cursor.next().getDouble(0), 0.000000001); - break; - case ColumnType.DATE: - Assert.assertEquals((long) rnd.nextInt(), cursor.next().getDate(0)); - break; - case ColumnType.INT: - Assert.assertEquals(rnd.nextInt(), cursor.next().getInt(0)); - break; - default: - break; - } - break; - case ColumnType.LONG: - case ColumnType.DATE: - switch (to) { - case ColumnType.SHORT: - Assert.assertEquals((short) rnd.nextLong(), cursor.next().getShort(0)); - break; - case ColumnType.LONG: - Assert.assertEquals(rnd.nextLong(), cursor.next().getLong(0)); - break; - case ColumnType.BYTE: - Assert.assertEquals((byte) rnd.nextLong(), cursor.next().getByte(0)); - break; - case ColumnType.FLOAT: - Assert.assertEquals((float) rnd.nextLong(), cursor.next().getFloat(0), 0.000000001f); - break; - case ColumnType.DOUBLE: - Assert.assertEquals((double) rnd.nextLong(), cursor.next().getDouble(0), 0.000000001); - break; - case ColumnType.DATE: - Assert.assertEquals(rnd.nextLong(), cursor.next().getDate(0)); - break; - case ColumnType.INT: - Assert.assertEquals((int) rnd.nextLong(), cursor.next().getInt(0)); - break; - default: - break; - } - break; - case ColumnType.BYTE: - switch (to) { - case ColumnType.SHORT: - Assert.assertEquals((short) rnd.nextByte(), cursor.next().getShort(0)); - break; - case ColumnType.LONG: - Assert.assertEquals((long) rnd.nextByte(), cursor.next().getLong(0)); - break; - case ColumnType.BYTE: - Assert.assertEquals(rnd.nextByte(), cursor.next().getByte(0)); - break; - case ColumnType.FLOAT: - Assert.assertEquals((float) rnd.nextByte(), cursor.next().getFloat(0), 0.000000001f); - break; - case ColumnType.DOUBLE: - Assert.assertEquals((double) rnd.nextByte(), cursor.next().getDouble(0), 0.000000001); - break; - case ColumnType.DATE: - Assert.assertEquals((long) rnd.nextByte(), cursor.next().getDate(0)); - break; - case ColumnType.INT: - Assert.assertEquals((int) rnd.nextByte(), cursor.next().getInt(0)); - break; - default: - break; - } - break; - case ColumnType.SHORT: - switch (to) { - case ColumnType.SHORT: - Assert.assertEquals(rnd.nextShort(), cursor.next().getShort(0)); - break; - case ColumnType.LONG: - Assert.assertEquals((long) rnd.nextShort(), cursor.next().getLong(0)); - break; - case ColumnType.BYTE: - Assert.assertEquals((byte) rnd.nextShort(), cursor.next().getByte(0)); - break; - case ColumnType.FLOAT: - Assert.assertEquals((float) rnd.nextShort(), cursor.next().getFloat(0), 0.000000001f); - break; - case ColumnType.DOUBLE: - Assert.assertEquals((double) rnd.nextShort(), cursor.next().getDouble(0), 0.000000001); - break; - case ColumnType.DATE: - Assert.assertEquals((long) rnd.nextShort(), cursor.next().getDate(0)); - break; - case ColumnType.INT: - Assert.assertEquals((int) rnd.nextShort(), cursor.next().getInt(0)); - break; - default: - break; - } - break; - case ColumnType.FLOAT: - switch (to) { - case ColumnType.SHORT: - Assert.assertEquals((short) rnd.nextFloat(), cursor.next().getShort(0)); - break; - case ColumnType.LONG: - Assert.assertEquals((long) rnd.nextFloat(), cursor.next().getLong(0)); - break; - case ColumnType.BYTE: - Assert.assertEquals((byte) rnd.nextFloat(), cursor.next().getByte(0)); - break; - case ColumnType.FLOAT: - Assert.assertEquals(rnd.nextFloat(), cursor.next().getFloat(0), 0.000000001f); - break; - case ColumnType.DOUBLE: - Assert.assertEquals((double) rnd.nextFloat(), cursor.next().getDouble(0), 0.000000001); - break; - case ColumnType.DATE: - Assert.assertEquals((long) rnd.nextFloat(), cursor.next().getDate(0)); - break; - case ColumnType.INT: - Assert.assertEquals((int) rnd.nextFloat(), cursor.next().getInt(0)); - break; - default: - break; - } - break; - case ColumnType.DOUBLE: - switch (to) { - case ColumnType.SHORT: - Assert.assertEquals((short) rnd.nextDouble(), cursor.next().getShort(0)); - break; - case ColumnType.LONG: - Assert.assertEquals((long) rnd.nextDouble(), cursor.next().getLong(0)); - break; - case ColumnType.BYTE: - Assert.assertEquals((byte) rnd.nextDouble(), cursor.next().getByte(0)); - break; - case ColumnType.FLOAT: - Assert.assertEquals((float) rnd.nextDouble(), cursor.next().getFloat(0), 0.000000001f); - break; - case ColumnType.DOUBLE: - Assert.assertEquals(rnd.nextDouble(), cursor.next().getDouble(0), 0.000000001); - break; - case ColumnType.DATE: - Assert.assertEquals((long) rnd.nextDouble(), cursor.next().getDate(0)); - break; - case ColumnType.INT: - Assert.assertEquals((int) rnd.nextDouble(), cursor.next().getInt(0)); - break; - default: - break; - } - break; - case ColumnType.STRING: - switch (to) { - case ColumnType.SYMBOL: - TestUtils.assertEquals(rnd.nextChars(10), cursor.next().getSym(0)); - break; - default: - TestUtils.assertEquals(rnd.nextChars(10), cursor.next().getFlyweightStr(0)); - break; - } - break; - case ColumnType.SYMBOL: - switch (to) { - case ColumnType.STRING: - TestUtils.assertEquals(rnd.nextChars(10), cursor.next().getFlyweightStr(0)); - break; - default: - TestUtils.assertEquals(rnd.nextChars(10), cursor.next().getSym(0)); - break; - } - break; - default: - break; - } - } - } finally { - cursor.releaseCursor(); - } - } - } - - @Test - public void testCastByteAsByte() throws Exception { - testCast(ColumnType.BYTE, ColumnType.BYTE); - } - - @Test - public void testCastByteAsDate() throws Exception { - testCast(ColumnType.BYTE, ColumnType.DATE); - } - - @Test - public void testCastByteAsDouble() throws Exception { - testCast(ColumnType.BYTE, ColumnType.DOUBLE); - } - - @Test - public void testCastByteAsFloat() throws Exception { - testCast(ColumnType.BYTE, ColumnType.FLOAT); - } - - @Test - public void testCastByteAsInt() throws Exception { - testCast(ColumnType.BYTE, ColumnType.INT); - } - - @Test - public void testCastByteAsLong() throws Exception { - testCast(ColumnType.BYTE, ColumnType.LONG); - } - - @Test - public void testCastByteAsShort() throws Exception { - testCast(ColumnType.BYTE, ColumnType.SHORT); - } - - @Test - public void testCastDateAsByte() throws Exception { - testCast(ColumnType.DATE, ColumnType.BYTE); - } - - @Test - public void testCastDateAsDate() throws Exception { - testCast(ColumnType.DATE, ColumnType.DATE); - } - - @Test - public void testCastDateAsDouble() throws Exception { - testCast(ColumnType.DATE, ColumnType.DOUBLE); - } - - @Test - public void testCastDateAsFloat() throws Exception { - testCast(ColumnType.DATE, ColumnType.FLOAT); - } - - @Test - public void testCastDateAsInt() throws Exception { - testCast(ColumnType.DATE, ColumnType.INT); - } - - @Test - public void testCastDateAsLong() throws Exception { - testCast(ColumnType.DATE, ColumnType.LONG); - } - - @Test - public void testCastDateAsShort() throws Exception { - testCast(ColumnType.DATE, ColumnType.SHORT); - } - - @Test - public void testCastDoubleAsByte() throws Exception { - testCast(ColumnType.DOUBLE, ColumnType.BYTE); - } - - @Test - public void testCastDoubleAsDate() throws Exception { - testCast(ColumnType.DOUBLE, ColumnType.DATE); - } - - @Test - public void testCastDoubleAsDouble() throws Exception { - testCast(ColumnType.DOUBLE, ColumnType.DOUBLE); - } - - @Test - public void testCastDoubleAsFloat() throws Exception { - testCast(ColumnType.DOUBLE, ColumnType.FLOAT); - } - - @Test - public void testCastDoubleAsInt() throws Exception { - testCast(ColumnType.DOUBLE, ColumnType.INT); - } - - @Test - public void testCastDoubleAsLong() throws Exception { - testCast(ColumnType.DOUBLE, ColumnType.LONG); - } - - @Test - public void testCastDoubleAsShort() throws Exception { - testCast(ColumnType.DOUBLE, ColumnType.SHORT); - } - - @Test - public void testCastFloatAsByte() throws Exception { - testCast(ColumnType.FLOAT, ColumnType.BYTE); - } - - @Test - public void testCastFloatAsDate() throws Exception { - testCast(ColumnType.FLOAT, ColumnType.DATE); - } - - @Test - public void testCastFloatAsDouble() throws Exception { - testCast(ColumnType.FLOAT, ColumnType.DOUBLE); - } - - @Test - public void testCastFloatAsFloat() throws Exception { - testCast(ColumnType.FLOAT, ColumnType.FLOAT); - } - - @Test - public void testCastFloatAsInt() throws Exception { - testCast(ColumnType.FLOAT, ColumnType.INT); - } - - @Test - public void testCastFloatAsLong() throws Exception { - testCast(ColumnType.FLOAT, ColumnType.LONG); - } - - @Test - public void testCastFloatAsShort() throws Exception { - testCast(ColumnType.FLOAT, ColumnType.SHORT); - } - - @Test - public void testCastIntAsByte() throws Exception { - testCast(ColumnType.INT, ColumnType.BYTE); - } - - @Test - public void testCastIntAsDate() throws Exception { - testCast(ColumnType.INT, ColumnType.DATE); - } - - @Test - public void testCastIntAsDouble() throws Exception { - testCast(ColumnType.INT, ColumnType.DOUBLE); - } - - @Test - public void testCastIntAsFloat() throws Exception { - testCast(ColumnType.INT, ColumnType.FLOAT); - } - - @Test - public void testCastIntAsInt() throws Exception { - testCast(ColumnType.INT, ColumnType.INT); - } - - @Test - public void testCastIntAsLong() throws Exception { - testCast(ColumnType.INT, ColumnType.LONG); - } - - @Test - public void testCastIntAsShort() throws Exception { - testCast(ColumnType.INT, ColumnType.SHORT); - } - - @Test - public void testCastLongAsByte() throws Exception { - testCast(ColumnType.LONG, ColumnType.BYTE); - } - - @Test - public void testCastLongAsDate() throws Exception { - testCast(ColumnType.LONG, ColumnType.DATE); - } - - @Test - public void testCastLongAsDouble() throws Exception { - testCast(ColumnType.LONG, ColumnType.DOUBLE); - } - - @Test - public void testCastLongAsFloat() throws Exception { - testCast(ColumnType.LONG, ColumnType.FLOAT); - } - - @Test - public void testCastLongAsInt() throws Exception { - testCast(ColumnType.LONG, ColumnType.INT); - } - - @Test - public void testCastLongAsLong() throws Exception { - testCast(ColumnType.LONG, ColumnType.LONG); - } - - @Test - public void testCastLongAsShort() throws Exception { - testCast(ColumnType.LONG, ColumnType.SHORT); - } - - @Test - public void testCastShortAsByte() throws Exception { - testCast(ColumnType.SHORT, ColumnType.BYTE); - } - - @Test - public void testCastShortAsDate() throws Exception { - testCast(ColumnType.SHORT, ColumnType.DATE); - } - - @Test - public void testCastShortAsDouble() throws Exception { - testCast(ColumnType.SHORT, ColumnType.DOUBLE); - } - - @Test - public void testCastShortAsFloat() throws Exception { - testCast(ColumnType.SHORT, ColumnType.FLOAT); - } - - @Test - public void testCastShortAsInt() throws Exception { - testCast(ColumnType.SHORT, ColumnType.INT); - } - - @Test - public void testCastShortAsLong() throws Exception { - testCast(ColumnType.SHORT, ColumnType.LONG); - } - - @Test - public void testCastShortAsShort() throws Exception { - testCast(ColumnType.SHORT, ColumnType.SHORT); - } - - @Test - public void testCastStrAsStr() throws Exception { - testCast(ColumnType.STRING, ColumnType.STRING); - } - - @Test - public void testCastStrAsSym() throws Exception { - testCast(ColumnType.STRING, ColumnType.SYMBOL); - } - - @Test - public void testCastSymAsStr() throws Exception { - testCast(ColumnType.SYMBOL, ColumnType.STRING); - } - - @Test - public void testCastSymAsSym() throws Exception { - testCast(ColumnType.SYMBOL, ColumnType.SYMBOL); - } - - @Test - public void testCreateAllFieldTypes() throws Exception { - exec("create table x (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING, y BOOLEAN) timestamp(t) partition by MONTH record hint 100"); - - // validate journal - try (Journal r = getFactory().reader("x")) { - Assert.assertNotNull(r); - JournalMetadata m = r.getMetadata(); - Assert.assertEquals(12, m.getColumnCount()); - Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType()); - Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType()); - - Assert.assertEquals(ColumnType.SHORT, m.getColumn("c").getType()); - Assert.assertEquals(ColumnType.LONG, m.getColumn("d").getType()); - Assert.assertEquals(ColumnType.FLOAT, m.getColumn("e").getType()); - Assert.assertEquals(ColumnType.DOUBLE, m.getColumn("f").getType()); - Assert.assertEquals(ColumnType.DATE, m.getColumn("g").getType()); - Assert.assertEquals(ColumnType.BINARY, m.getColumn("h").getType()); - Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType()); - Assert.assertEquals(ColumnType.SYMBOL, m.getColumn("x").getType()); - Assert.assertEquals(ColumnType.STRING, m.getColumn("z").getType()); - Assert.assertEquals(ColumnType.BOOLEAN, m.getColumn("y").getType()); - - Assert.assertEquals(8, m.getTimestampIndex()); - Assert.assertEquals(PartitionBy.MONTH, m.getPartitionBy()); - } - } - - @Test - public void testCreateAsSelect() throws Exception { - exec("create table y (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING) timestamp(t) partition by YEAR record hint 100"); - try (JournalWriter w = compiler.createWriter(getFactory(), "create table x as (y order by t)")) { - JournalMetadata m = w.getMetadata(); - Assert.assertEquals(11, m.getColumnCount()); - Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType()); - Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType()); - - Assert.assertEquals(ColumnType.SHORT, m.getColumn("c").getType()); - Assert.assertEquals(ColumnType.LONG, m.getColumn("d").getType()); - Assert.assertEquals(ColumnType.FLOAT, m.getColumn("e").getType()); - Assert.assertEquals(ColumnType.DOUBLE, m.getColumn("f").getType()); - Assert.assertEquals(ColumnType.DATE, m.getColumn("g").getType()); - Assert.assertEquals(ColumnType.BINARY, m.getColumn("h").getType()); - Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType()); - Assert.assertEquals(ColumnType.SYMBOL, m.getColumn("x").getType()); - Assert.assertEquals(ColumnType.STRING, m.getColumn("z").getType()); - Assert.assertEquals(8, m.getTimestampIndex()); - Assert.assertEquals(PartitionBy.NONE, m.getPartitionBy()); - } - } - - @Test - public void testCreateAsSelectAll() throws Exception { - int N = 50; - try (JournalWriter w = compiler.createWriter(getFactory(), "create table x (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING, y BOOLEAN) timestamp(t) record hint 100")) { - Rnd rnd = new Rnd(); - - long t = DateFormatUtils.parseDateTime("2016-01-10T00:00:00.000Z"); - - for (int i = 0; i < N; i++) { - JournalEntryWriter ew = w.entryWriter(t += Dates.DAY_MILLIS); - ew.putInt(0, i); - ew.put(1, (byte) rnd.nextInt()); - ew.putShort(2, (short) rnd.nextInt()); - ew.putLong(3, rnd.nextLong()); - ew.putFloat(4, rnd.nextFloat()); - ew.putDouble(5, rnd.nextDouble()); - ew.putDate(6, rnd.nextLong()); - ew.putNull(7); - ew.putSym(9, rnd.nextChars(1)); - ew.putStr(10, rnd.nextChars(10)); - ew.putBool(11, rnd.nextBoolean()); - ew.append(); - } - w.commit(); - } - - exec("create table y as (x) partition by MONTH"); - - try (Journal r = getFactory().reader("y")) { - Assert.assertEquals(2, r.getPartitionCount()); - } - - int count = 0; - try (RecordSource rs = compiler.compile(getFactory(), "y")) { - RecordCursor cursor = rs.prepareCursor(getFactory()); - - try { - Rnd rnd = new Rnd(); - while (cursor.hasNext()) { - Record rec = cursor.next(); - Assert.assertEquals(count, rec.getInt(0)); - Assert.assertEquals((byte) rnd.nextInt(), rec.getByte(1)); - Assert.assertEquals((short) rnd.nextInt(), rec.getShort(2)); - Assert.assertEquals(rnd.nextLong(), rec.getLong(3)); - Assert.assertEquals(rnd.nextFloat(), rec.getFloat(4), 0.00001f); - Assert.assertEquals(rnd.nextDouble(), rec.getDouble(5), 0.00000000001); - Assert.assertEquals(rnd.nextLong(), rec.getDate(6)); - Assert.assertNull(rec.getBin(7)); - TestUtils.assertEquals(rnd.nextChars(1), rec.getSym(9)); - TestUtils.assertEquals(rnd.nextChars(10), rec.getFlyweightStr(10)); - Assert.assertEquals(rnd.nextBoolean(), rec.getBool(11)); - count++; - } - } finally { - cursor.releaseCursor(); - } - } - } - - @Test - public void testCreateAsSelectBadHint() throws Exception { - exec("create table y (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING) record hint 100"); - try { - exec("create table x as (y order by t) record hint 1000000000000000000000000000"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(45, QueryError.getPosition()); - } - } - - @Test - public void testCreateAsSelectBadIndex() throws Exception { - exec("create table y (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING) record hint 100"); - try { - exec("create table x as (y order by t), index(e) record hint 100"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(40, QueryError.getPosition()); - } - } - - @Test - public void testCreateAsSelectBadIndex2() throws Exception { - exec("create table y (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING) record hint 100"); - try { - exec("create table x as (y order by t), index(e2) record hint 100"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(40, QueryError.getPosition()); - } - } - - @Test - public void testCreateAsSelectBadTimestamp() throws Exception { - exec("create table y (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING) record hint 100"); - try { - exec("create table x as (y order by t) timestamp(c) partition by MONTH record hint 100"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(43, QueryError.getPosition()); - } - } - - @Test - public void testCreateAsSelectBadTimestamp2() throws Exception { - exec("create table y (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING) record hint 100"); - try { - exec("create table x as (y order by t) timestamp(c2) partition by MONTH record hint 100"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(43, QueryError.getPosition()); - } - } - - @Test - public void testCreateAsSelectBin() throws Exception { - int N = 10000; - int SZ = 4096; - ByteBuffer buf = ByteBuffer.allocateDirect(SZ); - try { - long addr = ByteBuffers.getAddress(buf); - try (JournalWriter w = compiler.createWriter(getFactory(), "create table x (a INT, b BINARY)")) { - Rnd rnd = new Rnd(); - - for (int i = 0; i < N; i++) { - long p = addr; - int n = (rnd.nextPositiveInt() % (SZ - 1)) / 8; - for (int j = 0; j < n; j++) { - Unsafe.getUnsafe().putLong(p, rnd.nextLong()); - p += 8; - } - - buf.limit(n * 8); - JournalEntryWriter ew = w.entryWriter(); - ew.putInt(0, i); - ew.putBin(1, buf); - ew.append(); - buf.clear(); - } - w.commit(); - } - - exec("create table y as (x)"); - - int count = 0; - try (RecordSource rs = compiler.compile(getFactory(), "y")) { - RecordCursor cursor = rs.prepareCursor(getFactory()); - - try { - Rnd rnd = new Rnd(); - while (cursor.hasNext()) { - Record rec = cursor.next(); - Assert.assertEquals(count, rec.getInt(0)); - - long len = rec.getBinLen(1); - DirectInputStream is = rec.getBin(1); - is.copyTo(addr, 0, len); - - long p = addr; - int n = (rnd.nextPositiveInt() % (SZ - 1)) / 8; - for (int j = 0; j < n; j++) { - Assert.assertEquals(rnd.nextLong(), Unsafe.getUnsafe().getLong(p)); - p += 8; - } - count++; - } - } finally { - cursor.releaseCursor(); - } - } - Assert.assertEquals(N, count); - } finally { - ByteBuffers.release(buf); - } - } - - @Test - public void testCreateAsSelectCastInconvertible() throws Exception { - exec("create table y (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING) timestamp(t) partition by YEAR record hint 100"); - try { - compiler.createWriter(getFactory(), "create table x as (y order by t), cast(a as SYMBOL), cast(b as INT)"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(44, QueryError.getPosition()); - } - } - - @Test - public void testCreateAsSelectCastInconvertible2() throws Exception { - exec("create table y (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING) timestamp(t) partition by YEAR record hint 100"); - try { - compiler.createWriter(getFactory(), "create table x as (y order by t), cast(h as INT), cast(b as INT)"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(44, QueryError.getPosition()); - } - } - - @Test - public void testCreateAsSelectCastMultipleWrong() throws Exception { - exec("create table y (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING) timestamp(t) partition by YEAR record hint 100"); - try { - compiler.createWriter(getFactory(), "create table x as (y order by t), cast(a as LONG), cast(bz as INT)"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(56, QueryError.getPosition()); - } - } - - @Test - public void testCreateAsSelectCastWrongColumn() throws Exception { - exec("create table y (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING) timestamp(t) partition by YEAR record hint 100"); - try { - compiler.createWriter(getFactory(), "create table x as (y order by t), cast(ab as LONG)"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(39, QueryError.getPosition()); - } - } - - @Test - public void testCreateAsSelectCastWrongType() throws Exception { - exec("create table y (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING) timestamp(t) partition by YEAR record hint 100"); - try { - compiler.createWriter(getFactory(), "create table x as (y order by t), cast(a as LONGI)"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(44, QueryError.getPosition()); - } - } - - @Test - public void testCreateAsSelectIndexes() throws Exception { - exec("create table y (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING) timestamp(t) partition by YEAR record hint 100"); - try (JournalWriter w = compiler.createWriter(getFactory(), "create table x as (y order by t), index (a), index(x), index(z)")) { - JournalMetadata m = w.getMetadata(); - Assert.assertEquals(11, m.getColumnCount()); - Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType()); - Assert.assertTrue(m.getColumn("a").isIndexed()); - Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType()); - - Assert.assertEquals(ColumnType.SHORT, m.getColumn("c").getType()); - Assert.assertEquals(ColumnType.LONG, m.getColumn("d").getType()); - Assert.assertEquals(ColumnType.FLOAT, m.getColumn("e").getType()); - Assert.assertEquals(ColumnType.DOUBLE, m.getColumn("f").getType()); - Assert.assertEquals(ColumnType.DATE, m.getColumn("g").getType()); - Assert.assertEquals(ColumnType.BINARY, m.getColumn("h").getType()); - Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType()); - Assert.assertEquals(ColumnType.SYMBOL, m.getColumn("x").getType()); - Assert.assertTrue(m.getColumn("x").isIndexed()); - Assert.assertEquals(ColumnType.STRING, m.getColumn("z").getType()); - Assert.assertTrue(m.getColumn("z").isIndexed()); - Assert.assertEquals(8, m.getTimestampIndex()); - Assert.assertEquals(PartitionBy.NONE, m.getPartitionBy()); - } - } - - @Test - public void testCreateAsSelectLongIndex() throws Exception { - exec("create table y (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING) record hint 100"); - exec("create table x as (y order by t), index(d) record hint 100"); - } - - @Test - public void testCreateAsSelectPartitionBy() throws Exception { - exec("create table y (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING) timestamp(t) partition by YEAR record hint 100"); - try (JournalWriter w = compiler.createWriter(getFactory(), "create table x as (y order by t) partition by MONTH record hint 100")) { - JournalMetadata m = w.getMetadata(); - Assert.assertEquals(11, m.getColumnCount()); - Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType()); - Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType()); - - Assert.assertEquals(ColumnType.SHORT, m.getColumn("c").getType()); - Assert.assertEquals(ColumnType.LONG, m.getColumn("d").getType()); - Assert.assertEquals(ColumnType.FLOAT, m.getColumn("e").getType()); - Assert.assertEquals(ColumnType.DOUBLE, m.getColumn("f").getType()); - Assert.assertEquals(ColumnType.DATE, m.getColumn("g").getType()); - Assert.assertEquals(ColumnType.BINARY, m.getColumn("h").getType()); - Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType()); - Assert.assertEquals(ColumnType.SYMBOL, m.getColumn("x").getType()); - Assert.assertEquals(ColumnType.STRING, m.getColumn("z").getType()); - Assert.assertEquals(8, m.getTimestampIndex()); - Assert.assertEquals(PartitionBy.MONTH, m.getPartitionBy()); - } - } - - @Test - public void testCreateAsSelectPartitioned() throws Exception { - exec("create table y (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING) timestamp(t) partition by YEAR record hint 100"); - try (JournalWriter w = compiler.createWriter(getFactory(), "create table x as (y order by t) partition by MONTH record hint 100")) { - JournalMetadata m = w.getMetadata(); - Assert.assertEquals(11, m.getColumnCount()); - Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType()); - Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType()); - - Assert.assertEquals(ColumnType.SHORT, m.getColumn("c").getType()); - Assert.assertEquals(ColumnType.LONG, m.getColumn("d").getType()); - Assert.assertEquals(ColumnType.FLOAT, m.getColumn("e").getType()); - Assert.assertEquals(ColumnType.DOUBLE, m.getColumn("f").getType()); - Assert.assertEquals(ColumnType.DATE, m.getColumn("g").getType()); - Assert.assertEquals(ColumnType.BINARY, m.getColumn("h").getType()); - Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType()); - Assert.assertEquals(ColumnType.SYMBOL, m.getColumn("x").getType()); - Assert.assertEquals(ColumnType.STRING, m.getColumn("z").getType()); - Assert.assertEquals(8, m.getTimestampIndex()); - Assert.assertEquals(PartitionBy.MONTH, m.getPartitionBy()); - } - } - - @Test - public void testCreateAsSelectPartitionedMixedCase() throws Exception { - exec("create table y (a INT, b byte, c Short, d long, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING) timestamp(t) partition by YEAR record hint 100"); - try (JournalWriter w = compiler.createWriter(getFactory(), "create table x as (y order by t) partition by MONTH record hint 100")) { - JournalMetadata m = w.getMetadata(); - Assert.assertEquals(11, m.getColumnCount()); - Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType()); - Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType()); - - Assert.assertEquals(ColumnType.SHORT, m.getColumn("c").getType()); - Assert.assertEquals(ColumnType.LONG, m.getColumn("d").getType()); - Assert.assertEquals(ColumnType.FLOAT, m.getColumn("e").getType()); - Assert.assertEquals(ColumnType.DOUBLE, m.getColumn("f").getType()); - Assert.assertEquals(ColumnType.DATE, m.getColumn("g").getType()); - Assert.assertEquals(ColumnType.BINARY, m.getColumn("h").getType()); - Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType()); - Assert.assertEquals(ColumnType.SYMBOL, m.getColumn("x").getType()); - Assert.assertEquals(ColumnType.STRING, m.getColumn("z").getType()); - Assert.assertEquals(8, m.getTimestampIndex()); - Assert.assertEquals(PartitionBy.MONTH, m.getPartitionBy()); - } - } - - @Test - public void testCreateAsSelectPartitionedNoTimestamp() throws Exception { - exec("create table y (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING) record hint 100"); - try { - exec("create table x as (y order by t) partition by MONTH record hint 100"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(46, QueryError.getPosition()); - } - } - - @Test - public void testCreateAsSelectSymbolCount() throws Exception { - exec("create table y (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING) timestamp(t) partition by YEAR record hint 100"); - try (JournalWriter w = compiler.createWriter(getFactory(), "create table x as (y order by t), cast(x as SYMBOL count 33), cast(b as INT)")) { - Assert.assertEquals(ColumnType.SYMBOL, w.getMetadata().getColumn("x").getType()); - Assert.assertEquals(63, w.getMetadata().getColumn("x").getBucketCount()); - } - } - - @Test - public void testCreateAsSelectSymbolCountError() throws Exception { - exec("create table y (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING) timestamp(t) partition by YEAR record hint 100"); - try { - exec("create table x as (y order by t), cast(x as SYMBOL 33), cast(b as INT)"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(51, QueryError.getPosition()); - } - } - - @Test - public void testCreateDefaultPartitionBy() throws Exception { - exec("create table x (a INT index, b BYTE, t DATE, z STRING index buckets 40, l LONG index buckets 500) record hint 100"); - // validate journal - try (Journal r = getFactory().reader("x")) { - Assert.assertNotNull(r); - JournalMetadata m = r.getMetadata(); - Assert.assertEquals(5, m.getColumnCount()); - Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType()); - Assert.assertTrue(m.getColumn("a").isIndexed()); - // bucket is ceilPow2(value) - 1 - Assert.assertEquals(1, m.getColumn("a").getBucketCount()); - - Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType()); - Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType()); - Assert.assertEquals(ColumnType.STRING, m.getColumn("z").getType()); - Assert.assertTrue(m.getColumn("z").isIndexed()); - // bucket is ceilPow2(value) - 1 - Assert.assertEquals(63, m.getColumn("z").getBucketCount()); - - Assert.assertEquals(ColumnType.LONG, m.getColumn("l").getType()); - Assert.assertTrue(m.getColumn("l").isIndexed()); - // bucket is ceilPow2(value) - 1 - Assert.assertEquals(511, m.getColumn("l").getBucketCount()); - - Assert.assertEquals(-1, m.getTimestampIndex()); - Assert.assertEquals(PartitionBy.NONE, m.getPartitionBy()); - } - } - - @Test - public void testCreateExistingTable() throws Exception { - exec("create table x (a INT index buckets 25, b BYTE, t DATE, x SYMBOL index) timestamp(t) partition by MONTH"); - try { - exec("create table x (a INT index buckets 25, b BYTE, t DATE, x SYMBOL index) timestamp(t) partition by MONTH"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(13, QueryError.getPosition()); - } - } - - @Test - public void testCreateFromDefPartitionNoTimestamp() throws Exception { - try { - exec("create table x (a INT, b BYTE, x SYMBOL), index(a buckets 25), index(x) partition by YEAR record hint 100"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(85, QueryError.getPosition()); - } - } - - @Test - public void testCreateIndexWithSuffix() throws Exception { - exec("create table x (a INT, b BYTE, t DATE, x SYMBOL), index(a buckets 25), index(x) timestamp(t) partition by YEAR record hint 100"); - // validate journal - try (Journal r = getFactory().reader("x")) { - Assert.assertNotNull(r); - JournalMetadata m = r.getMetadata(); - Assert.assertEquals(4, m.getColumnCount()); - Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType()); - Assert.assertTrue(m.getColumn("a").isIndexed()); - // bucket is ceilPow2(value) - 1 - Assert.assertEquals(31, m.getColumn("a").getBucketCount()); - - Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType()); - Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType()); - Assert.assertEquals(ColumnType.SYMBOL, m.getColumn("x").getType()); - Assert.assertTrue(m.getColumn("x").isIndexed()); - - Assert.assertEquals(2, m.getTimestampIndex()); - Assert.assertEquals(PartitionBy.YEAR, m.getPartitionBy()); - } - } - - @Test - public void testCreateIndexWithSuffixDefaultPartition() throws Exception { - exec("create table x (a INT, b BYTE, t DATE, x SYMBOL), index(a buckets 25), index(x) timestamp(t) record hint 100"); - // validate journal - try (Journal r = getFactory().reader("x")) { - Assert.assertNotNull(r); - JournalMetadata m = r.getMetadata(); - Assert.assertEquals(4, m.getColumnCount()); - Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType()); - Assert.assertTrue(m.getColumn("a").isIndexed()); - // bucket is ceilPow2(value) - 1 - Assert.assertEquals(31, m.getColumn("a").getBucketCount()); - - Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType()); - Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType()); - Assert.assertEquals(ColumnType.SYMBOL, m.getColumn("x").getType()); - Assert.assertTrue(m.getColumn("x").isIndexed()); - - Assert.assertEquals(2, m.getTimestampIndex()); - Assert.assertEquals(PartitionBy.NONE, m.getPartitionBy()); - } - } - - @Test - public void testCreateIndexedInt() throws Exception { - exec("create table x (a INT index buckets 25, b BYTE, t DATE, x SYMBOL) timestamp(t) partition by MONTH record hint 100"); - // validate journal - try (Journal r = getFactory().reader("x")) { - Assert.assertNotNull(r); - JournalMetadata m = r.getMetadata(); - Assert.assertEquals(4, m.getColumnCount()); - Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType()); - Assert.assertTrue(m.getColumn("a").isIndexed()); - // bucket is ceilPow2(value) - 1 - Assert.assertEquals(31, m.getColumn("a").getBucketCount()); - - Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType()); - Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType()); - Assert.assertEquals(ColumnType.SYMBOL, m.getColumn("x").getType()); - Assert.assertEquals(2, m.getTimestampIndex()); - Assert.assertEquals(PartitionBy.MONTH, m.getPartitionBy()); - } - } - - @Test - public void testCreateIndexedIntDefaultBuckets() throws Exception { - exec("create table x (a INT index, b BYTE, t DATE, x SYMBOL) timestamp(t) partition by MONTH record hint 100"); - // validate journal - try (Journal r = getFactory().reader("x")) { - Assert.assertNotNull(r); - JournalMetadata m = r.getMetadata(); - Assert.assertEquals(4, m.getColumnCount()); - Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType()); - Assert.assertTrue(m.getColumn("a").isIndexed()); - // bucket is ceilPow2(value) - 1 - Assert.assertEquals(1, m.getColumn("a").getBucketCount()); - - Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType()); - Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType()); - Assert.assertEquals(ColumnType.SYMBOL, m.getColumn("x").getType()); - Assert.assertEquals(2, m.getTimestampIndex()); - Assert.assertEquals(PartitionBy.MONTH, m.getPartitionBy()); - } - } - - @Test - public void testCreateIndexedString() throws Exception { - exec("create table x (a INT index, b BYTE, t DATE, z STRING index buckets 40) timestamp(t) partition by MONTH record hint 100"); - // validate journal - try (Journal r = getFactory().reader("x")) { - Assert.assertNotNull(r); - JournalMetadata m = r.getMetadata(); - Assert.assertEquals(4, m.getColumnCount()); - Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType()); - Assert.assertTrue(m.getColumn("a").isIndexed()); - // bucket is ceilPow2(value) - 1 - Assert.assertEquals(1, m.getColumn("a").getBucketCount()); - - Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType()); - Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType()); - Assert.assertEquals(ColumnType.STRING, m.getColumn("z").getType()); - Assert.assertTrue(m.getColumn("z").isIndexed()); - // bucket is ceilPow2(value) - 1 - Assert.assertEquals(63, m.getColumn("z").getBucketCount()); - - Assert.assertEquals(2, m.getTimestampIndex()); - Assert.assertEquals(PartitionBy.MONTH, m.getPartitionBy()); - } - } - - @Test - public void testCreateIndexedSymbol() throws Exception { - exec("create table x (a INT index buckets 25, b BYTE, t DATE, x SYMBOL index) timestamp(t) partition by MONTH"); - // validate journal - try (Journal r = getFactory().reader("x")) { - Assert.assertNotNull(r); - JournalMetadata m = r.getMetadata(); - Assert.assertEquals(4, m.getColumnCount()); - Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType()); - Assert.assertTrue(m.getColumn("a").isIndexed()); - // bucket is ceilPow2(value) - 1 - Assert.assertEquals(31, m.getColumn("a").getBucketCount()); - - Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType()); - Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType()); - Assert.assertEquals(ColumnType.SYMBOL, m.getColumn("x").getType()); - Assert.assertTrue(m.getColumn("x").isIndexed()); - Assert.assertEquals(2, m.getTimestampIndex()); - Assert.assertEquals(PartitionBy.MONTH, m.getPartitionBy()); - } - } - - @Test - public void testCreateQuotedName() throws Exception { - exec("create table 'a b' (a INT index, b BYTE, t DATE, z STRING index buckets 40, l LONG index buckets 500) record hint 100"); - // validate journal - try (Journal r = getFactory().reader("a b")) { - Assert.assertNotNull(r); - JournalMetadata m = r.getMetadata(); - Assert.assertEquals(5, m.getColumnCount()); - Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType()); - Assert.assertTrue(m.getColumn("a").isIndexed()); - // bucket is ceilPow2(value) - 1 - Assert.assertEquals(1, m.getColumn("a").getBucketCount()); - - Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType()); - Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType()); - Assert.assertEquals(ColumnType.STRING, m.getColumn("z").getType()); - Assert.assertTrue(m.getColumn("z").isIndexed()); - // bucket is ceilPow2(value) - 1 - Assert.assertEquals(63, m.getColumn("z").getBucketCount()); - - Assert.assertEquals(ColumnType.LONG, m.getColumn("l").getType()); - Assert.assertTrue(m.getColumn("l").isIndexed()); - // bucket is ceilPow2(value) - 1 - Assert.assertEquals(511, m.getColumn("l").getBucketCount()); - - Assert.assertEquals(-1, m.getTimestampIndex()); - Assert.assertEquals(PartitionBy.NONE, m.getPartitionBy()); - } - } - - @Test - public void testCreateReservedName() throws Exception { - Files.mkDirsOrException(new File(getFactory().getConfiguration().getJournalBase(), "x")); - try { - exec("create table x (a INT, b BYTE, t DATE, x SYMBOL) partition by MONTH"); - } catch (ParserException e) { - TestUtils.assertContains(QueryError.getMessage(), "reserved"); - Assert.assertEquals(13, QueryError.getPosition()); - } - } - - @Test - public void testCreateSymbolWithCount1() throws Exception { - try { - exec("create table x (a INT, x SYMBOL count 20, z STRING, y BOOLEAN) timestamp(t) partition by MONTH record hint 100"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(32, QueryError.getPosition()); - } - } - - @Test - public void testInvalidPartitionBy() throws Exception { - try { - exec("create table x (a INT index, b BYTE, t DATE, z STRING index buckets 40) partition by x record hint 100"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(85, QueryError.getPosition()); - } - } - - @Test - public void testInvalidPartitionBy2() throws Exception { - try { - exec("create table x (a INT index, b BYTE, t DATE, z STRING index buckets 40) partition by 1 record hint 100"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(85, QueryError.getPosition()); - } - } - - @Test - public void testUnsupportedTypeForIndex() throws Exception { - try { - exec("create table x (a INT, b BYTE, t DATE, x SYMBOL), index(t) partition by YEAR"); - Assert.fail(); - } catch (ParserException ignored) { - // pass - } - } - - private void exec(String ddl) throws JournalException, ParserException { - compiler.execute(getFactory(), ddl); - } -} diff --git a/core/src/test/java/com/questdb/ql/HashJoinRecordSourceTest.java b/core/src/test/java/com/questdb/ql/HashJoinRecordSourceTest.java deleted file mode 100644 index e076af086..000000000 --- a/core/src/test/java/com/questdb/ql/HashJoinRecordSourceTest.java +++ /dev/null @@ -1,209 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql; - -import com.questdb.model.Album; -import com.questdb.model.Band; -import com.questdb.ql.join.HashJoinRecordSource; -import com.questdb.ql.map.RecordKeyCopierCompiler; -import com.questdb.ql.select.SelectedColumnsRecordSource; -import com.questdb.std.BytecodeAssembler; -import com.questdb.std.IntList; -import com.questdb.std.ObjList; -import com.questdb.std.str.StringSink; -import com.questdb.store.JournalWriter; -import com.questdb.store.factory.Factory; -import com.questdb.store.factory.configuration.JournalConfigurationBuilder; -import com.questdb.test.tools.FactoryContainer; -import org.junit.*; - -public class HashJoinRecordSourceTest { - @Rule - public final FactoryContainer factoryContainer = new FactoryContainer(new JournalConfigurationBuilder() {{ - $(Band.class).$ts(); - $(Album.class).$ts("releaseDate"); - - }}); - - private JournalWriter bw; - private JournalWriter aw; - - @Before - public void setUp() throws Exception { - bw = getFactory().writer(Band.class); - aw = getFactory().writer(Album.class); - } - - @After - public void tearDown() { - bw.close(); - aw.close(); - - Assert.assertEquals(0, getFactory().getBusyWriterCount()); - Assert.assertEquals(0, getFactory().getBusyReaderCount()); - } - - @Test - public void testHashJoinJournalRecordSource() throws Exception { - bw.append(new Band().setName("band1").setType("rock").setUrl("http://band1.com")); - bw.append(new Band().setName("band2").setType("blues").setUrl("http://band2.com")); - bw.append(new Band().setName("band3").setType("jazz").setUrl("http://band3.com")); - bw.append(new Band().setName("band1").setType("jazz").setUrl("http://new.band1.com")); - - bw.commit(); - - aw.append(new Album().setName("album X").setBand("band1").setGenre("pop")); - aw.append(new Album().setName("album Y").setBand("band3").setGenre("metal")); - aw.append(new Album().setName("album BZ").setBand("band1").setGenre("rock")); - - aw.commit(); - - StringSink sink = new StringSink(); - RecordSourcePrinter p = new RecordSourcePrinter(sink); - RecordSource joinResult = new SelectedColumnsRecordSource( - new HashJoinRecordSource( - new JournalRecordSource(new JournalPartitionSource(bw.getMetadata(), false), new AllRowSource()), - new IntList() {{ - add(bw.getMetadata().getColumnIndex("name")); - }}, - new JournalRecordSource(new JournalPartitionSource(aw.getMetadata(), false), new AllRowSource()), - new IntList() {{ - add(aw.getMetadata().getColumnIndex("band")); - }}, - false, - 4 * 1024 * 1024, - 4 * 1024 * 1024, - 1024 * 1024, - new RecordKeyCopierCompiler(new BytecodeAssembler()) - ), - new ObjList() {{ - add("genre"); - }} - ); - p.print(joinResult, getFactory()); - Assert.assertEquals("pop\n" + - "rock\n" + - "metal\n" + - "pop\n" + - "rock\n", sink.toString()); - } - - @Test - public void testHashJoinRecordSource() throws Exception { - bw.append(new Band().setName("band1").setType("rock").setUrl("http://band1.com")); - bw.append(new Band().setName("band2").setType("blues").setUrl("http://band2.com")); - bw.append(new Band().setName("band3").setType("jazz").setUrl("http://band3.com")); - bw.append(new Band().setName("band1").setType("jazz").setUrl("http://new.band1.com")); - - bw.commit(); - - aw.append(new Album().setName("album X").setBand("band1").setGenre("pop")); - aw.append(new Album().setName("album Y").setBand("band3").setGenre("metal")); - aw.append(new Album().setName("album BZ").setBand("band1").setGenre("rock")); - - aw.commit(); - - StringSink sink = new StringSink(); - RecordSourcePrinter p = new RecordSourcePrinter(sink); - RecordSource joinResult = new SelectedColumnsRecordSource( - new HashJoinRecordSource( - new JournalRecordSource(new JournalPartitionSource(bw.getMetadata(), false), new AllRowSource()), - new IntList() {{ - add(bw.getMetadata().getColumnIndex("name")); - }}, - new JournalRecordSource(new JournalPartitionSource(aw.getMetadata(), false), new AllRowSource()), - new IntList() {{ - add(aw.getMetadata().getColumnIndex("band")); - }}, - false, - 4 * 1024 * 1024, - 4 * 1024 * 1024, - 1024 * 1024, - new RecordKeyCopierCompiler(new BytecodeAssembler()) - ), - new ObjList() {{ - add("genre"); - }} - ); - p.print(joinResult, getFactory()); - Assert.assertEquals("pop\n" + - "rock\n" + - "metal\n" + - "pop\n" + - "rock\n", sink.toString()); - } - - @Test - public void testOuterHashJoin() throws Exception { - bw.append(new Band().setName("band1").setType("rock").setUrl("http://band1.com")); - bw.append(new Band().setName("band2").setType("blues").setUrl("http://band2.com")); - bw.append(new Band().setName("band3").setType("jazz").setUrl("http://band3.com")); - bw.append(new Band().setName("band1").setType("jazz").setUrl("http://new.band1.com")); - bw.append(new Band().setName("band5").setType("jazz").setUrl("http://new.band5.com")); - - bw.commit(); - - aw.append(new Album().setName("album X").setBand("band1").setGenre("pop")); - aw.append(new Album().setName("album Y").setBand("band3").setGenre("metal")); - aw.append(new Album().setName("album BZ").setBand("band1").setGenre("rock")); - - aw.commit(); - - StringSink sink = new StringSink(); - RecordSourcePrinter p = new RecordSourcePrinter(sink); - RecordSource joinResult = new SelectedColumnsRecordSource( - new HashJoinRecordSource( - new JournalRecordSource(new JournalPartitionSource(bw.getMetadata(), false), new AllRowSource()), - new IntList() {{ - add(bw.getMetadata().getColumnIndex("name")); - }}, - new JournalRecordSource(new JournalPartitionSource(aw.getMetadata(), false), new AllRowSource()), - new IntList() {{ - add(aw.getMetadata().getColumnIndex("band")); - }}, - true, - 4 * 1024 * 1024, - 4 * 1024 * 1024, - 1024 * 1024, - new RecordKeyCopierCompiler(new BytecodeAssembler()) - ), - new ObjList() {{ - add("genre"); - add("url"); - }} - ); - p.print(joinResult, getFactory()); - Assert.assertEquals("pop\thttp://band1.com\n" + - "rock\thttp://band1.com\n" + - "\thttp://band2.com\n" + - "metal\thttp://band3.com\n" + - "pop\thttp://new.band1.com\n" + - "rock\thttp://new.band1.com\n" + - "\thttp://new.band5.com\n", sink.toString()); - } - - private Factory getFactory() { - return factoryContainer.getFactory(); - } -} diff --git a/core/src/test/java/com/questdb/ql/JoinStringToSymbolTest.java b/core/src/test/java/com/questdb/ql/JoinStringToSymbolTest.java deleted file mode 100644 index 6f594acdb..000000000 --- a/core/src/test/java/com/questdb/ql/JoinStringToSymbolTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql; - -import com.questdb.model.Album; -import com.questdb.model.Band; -import com.questdb.ql.join.CrossJoinRecordSource; -import com.questdb.std.str.StringSink; -import com.questdb.store.JournalWriter; -import com.questdb.store.factory.Factory; -import com.questdb.store.factory.configuration.JournalConfigurationBuilder; -import com.questdb.test.tools.FactoryContainer; -import com.questdb.test.tools.TestUtils; -import org.junit.*; - -public class JoinStringToSymbolTest { - @Rule - public final FactoryContainer factoryContainer = new FactoryContainer(new JournalConfigurationBuilder() {{ - $(Band.class) - .$sym("name").index() - .$sym("type") - .$bin("image") - .$ts() - ; - - $(Album.class) - .$str("band").index() - .$sym("name").index() - .$ts("releaseDate"); - - }}); - private JournalWriter bw; - private JournalWriter aw; - - @Before - public void setUp() throws Exception { - bw = getFactory().writer(Band.class); - aw = getFactory().writer(Album.class); - } - - @After - public void tearDown() { - aw.close(); - bw.close(); - - Assert.assertEquals(0, getFactory().getBusyWriterCount()); - Assert.assertEquals(0, getFactory().getBusyReaderCount()); - } - - @Test - public void testCrossJoin() throws Exception { - bw.append(new Band().setName("band1").setType("rock").setUrl("http://band1.com")); - bw.append(new Band().setName("band2").setType("hiphop").setUrl("http://band2.com")); - bw.append(new Band().setName("band3").setType("jazz").setUrl("http://band3.com")); - bw.append(new Band().setName("band1").setType("jazz").setUrl("http://new.band1.com")); - - bw.commit(); - - aw.append(new Album().setName("album X").setBand("band1").setGenre("pop")); - aw.append(new Album().setName("album BZ").setBand("band1").setGenre("rock")); - aw.append(new Album().setName("album Y").setBand("band3").setGenre("metal")); - - aw.commit(); - - StringSink sink = new StringSink(); - RecordSourcePrinter p = new RecordSourcePrinter(sink); - try (RecordSource rs = new CrossJoinRecordSource(new JournalRecordSource( - new JournalPartitionSource(aw.getMetadata(), false), new AllRowSource()), new JournalRecordSource( - new JournalPartitionSource(bw.getMetadata(), false), new AllRowSource()))) { - p.print(rs, getFactory()); - } - - final String expected = "band1\talbum X\tpop\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband1\thttp://band1.com\trock\t\n" + - "band1\talbum X\tpop\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband2\thttp://band2.com\thiphop\t\n" + - "band1\talbum X\tpop\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband3\thttp://band3.com\tjazz\t\n" + - "band1\talbum X\tpop\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband1\thttp://new.band1.com\tjazz\t\n" + - "band1\talbum BZ\trock\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband1\thttp://band1.com\trock\t\n" + - "band1\talbum BZ\trock\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband2\thttp://band2.com\thiphop\t\n" + - "band1\talbum BZ\trock\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband3\thttp://band3.com\tjazz\t\n" + - "band1\talbum BZ\trock\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband1\thttp://new.band1.com\tjazz\t\n" + - "band3\talbum Y\tmetal\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband1\thttp://band1.com\trock\t\n" + - "band3\talbum Y\tmetal\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband2\thttp://band2.com\thiphop\t\n" + - "band3\talbum Y\tmetal\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband3\thttp://band3.com\tjazz\t\n" + - "band3\talbum Y\tmetal\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband1\thttp://new.band1.com\tjazz\t\n"; - - TestUtils.assertEquals(expected, sink); - } - - private Factory getFactory() { - return factoryContainer.getFactory(); - } -} diff --git a/core/src/test/java/com/questdb/ql/JournalRecordSourceTest.java b/core/src/test/java/com/questdb/ql/JournalRecordSourceTest.java deleted file mode 100644 index 53b081e78..000000000 --- a/core/src/test/java/com/questdb/ql/JournalRecordSourceTest.java +++ /dev/null @@ -1,195 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql; - -import com.questdb.parser.sql.AbstractOptimiserTest; -import com.questdb.std.Rnd; -import com.questdb.std.time.Dates; -import com.questdb.store.JournalEntryWriter; -import com.questdb.store.JournalWriter; -import com.questdb.store.PartitionBy; -import com.questdb.store.factory.configuration.JournalStructure; -import org.junit.BeforeClass; -import org.junit.Test; - -public class JournalRecordSourceTest extends AbstractOptimiserTest { - @BeforeClass - public static void setUp() throws Exception { - try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("parent") - .$int("i") - .$double("d") - .$float("f") - .$byte("b") - .$long("l") - .$str("str") - .$bool("boo") - .$sym("sym") - .$short("sho") - .$date("date") - .$ts() - .partitionBy(PartitionBy.DAY) - .$())) { - - - Rnd rnd = new Rnd(); - int n = 24 * 3; // number of records - int timestep = 60 * 60 * 1000; // time stepping 1hr - String[] sym = {"AX", "XX", "BZ", "KK", "PP", "UX", "LK"}; - String[] str = new String[16]; - for (int i = 0; i < str.length; i++) { - str[i] = rnd.nextString(rnd.nextPositiveInt() % 10); - } - - long t = Dates.toMillis(2016, 5, 1, 10, 20); - for (int i = 0; i < n; i++) { - JournalEntryWriter ew = w.entryWriter(t += timestep); - ew.putInt(0, rnd.nextInt() % 15); - ew.putDouble(1, rnd.nextDouble()); - ew.putFloat(2, rnd.nextFloat()); - ew.put(3, (byte) rnd.nextInt()); - ew.putLong(4, rnd.nextLong() % 30); - ew.putStr(5, str[rnd.nextPositiveInt() % str.length]); - ew.putBool(6, rnd.nextBoolean()); - ew.putSym(7, sym[rnd.nextPositiveInt() % sym.length]); - ew.putShort(8, (short) (rnd.nextInt() % 20)); - ew.putDate(9, rnd.nextLong()); - ew.append(); - } - w.commit(); - } - } - - @Test - public void testFilterRowId() throws Exception { - assertRowId("parent where sym = 'KK'", "date"); - } - - @Test - public void testIntervalRowId() throws Exception { - assertRowId("parent where timestamp = '2016-05-01T23;1h'", "date"); - } - - @Test - public void testOrderRowId() throws Exception { - assertRowId("parent order by date", "timestamp"); - } - - @Test - public void testSelect() throws Exception { - final String expected = "5\t0.047392679378\t0.3350\t-127\t3\tHRUEDRQ\ttrue\tUX\t18\t-279216330-12-02T14:28:07.160Z\t2016-05-01T11:20:00.000Z\n" + - "-14\t-284.232421875000\t0.4112\t-48\t17\t\tfalse\tLK\t4\t258937948-03-11T22:24:08.944Z\t2016-05-01T12:20:00.000Z\n" + - "-10\t-512.000000000000\t0.7163\t-79\t12\tHRUEDRQ\ttrue\tBZ\t-2\t185889770-02-23T18:31:09.514Z\t2016-05-01T13:20:00.000Z\n" + - "-3\t424.828125000000\t0.2858\t55\t-2\tGZSXUXI\ttrue\tAX\t-5\t201963330-01-06T09:59:49.837Z\t2016-05-01T14:20:00.000Z\n" + - "5\t0.000000009480\t0.8258\t-61\t23\tEYYQEHB\ttrue\tPP\t-3\t258454748-03-10T09:05:26.575Z\t2016-05-01T15:20:00.000Z\n" + - "8\t557.000000000000\t0.5172\t-41\t-21\tF\tfalse\tAX\t-4\t47692444-11-24T00:16:53.191Z\t2016-05-01T16:20:00.000Z\n" + - "-10\t0.060836097226\t0.6644\t-123\t1\t\ttrue\tLK\t2\t29025895-08-22T23:29:37.949Z\t2016-05-01T17:20:00.000Z\n" + - "-3\t300.163238525391\t0.5051\t-109\t-22\t\tfalse\tUX\t-17\t-172370722-08-30T13:59:33.528Z\t2016-05-01T18:20:00.000Z\n" + - "-13\t0.107344331220\t0.4957\t-69\t-22\t\tfalse\tXX\t4\t-282363803-02-23T22:07:48.466Z\t2016-05-01T19:20:00.000Z\n" + - "12\t0.248532287776\t0.4957\t-88\t23\tXY\tfalse\tPP\t13\t-259642767-03-23T05:28:26.667Z\t2016-05-01T20:20:00.000Z\n" + - "12\t-583.609375000000\t0.6253\t56\t-15\tEYYQEHB\ttrue\tKK\t0\t-156780555-03-14T20:51:19.305Z\t2016-05-01T21:20:00.000Z\n" + - "8\t-864.392822265625\t0.7237\t-62\t19\tEYYQEHB\tfalse\tPP\t-6\t147076965-11-19T02:54:29.993Z\t2016-05-01T22:20:00.000Z\n" + - "0\t-119.000000000000\t0.3158\t-55\t-23\tHRUEDRQ\tfalse\tXX\t14\t253798344-05-11T01:48:28.243Z\t2016-05-01T23:20:00.000Z\n" + - "-2\t-352.000000000000\t0.5488\t29\t-9\t\tfalse\tPP\t5\t-285016098-11-30T04:17:15.224Z\t2016-05-02T00:20:00.000Z\n" + - "9\t134.663085937500\t0.5315\t-91\t-16\tGZSXUXI\tfalse\tPP\t-3\t245893755-08-11T03:30:38.709Z\t2016-05-02T01:20:00.000Z\n" + - "3\t0.010311927646\t0.4648\t68\t17\tGPGWFFYU\ttrue\tKK\t-16\t-226689458-05-22T21:25:17.104Z\t2016-05-02T02:20:00.000Z\n" + - "-11\t0.000000032913\t0.3010\t98\t-4\t\ttrue\tBZ\t-9\t75525295-09-06T22:11:27.250Z\t2016-05-02T03:20:00.000Z\n" + - "-10\t-144.421875000000\t0.5373\t46\t8\tGPGWFFYU\tfalse\tXX\t0\t-256539251-11-26T13:36:52.642Z\t2016-05-02T04:20:00.000Z\n" + - "7\t0.000000064758\t0.4588\t44\t14\tUOJ\tfalse\tBZ\t-12\t223665704-03-23T09:36:06.226Z\t2016-05-02T05:20:00.000Z\n" + - "-11\t-911.000000000000\t0.3472\t39\t-15\tLOFJ\ttrue\tLK\t-10\t-260012340-07-11T16:21:52.892Z\t2016-05-02T06:20:00.000Z\n" + - "13\t-589.718750000000\t0.0314\t12\t26\tXPEHNR\ttrue\tBZ\t9\t219842116-11-17T17:57:00.303Z\t2016-05-02T07:20:00.000Z\n" + - "-11\t1.167305707932\t0.5309\t-128\t3\t\tfalse\tAX\t6\t-141025066-04-05T08:09:18.874Z\t2016-05-02T08:20:00.000Z\n" + - "-11\t15.713242053986\t0.5207\t58\t10\tUOJ\tfalse\tAX\t19\t63572238-04-24T11:00:13.287Z\t2016-05-02T09:20:00.000Z\n" + - "-12\t296.611343383789\t0.2628\t-48\t17\tGPGWFFYU\tfalse\tAX\t14\t-216113547-08-09T23:21:50.616Z\t2016-05-02T10:20:00.000Z\n" + - "-14\t0.000000248992\t0.5233\t92\t28\t\tfalse\tKK\t-16\t121072971-06-08T04:40:57.855Z\t2016-05-02T11:20:00.000Z\n" + - "-6\t0.000014454320\t0.5999\t-77\t-6\tHRUEDRQ\tfalse\tPP\t8\t214009105-03-25T03:32:20.665Z\t2016-05-02T12:20:00.000Z\n" + - "-14\t0.000000119284\t0.2506\t-12\t-15\tLOFJ\tfalse\tPP\t-12\t119515869-09-19T20:43:31.509Z\t2016-05-02T13:20:00.000Z\n" + - "-14\t7.793050527573\t0.3849\t-109\t-15\tWLP\ttrue\tUX\t-7\t-234459915-01-31T17:49:54.678Z\t2016-05-02T14:20:00.000Z\n" + - "-3\t0.001914593857\t0.2802\t46\t-6\tGPGWFFYU\tfalse\tLK\t-17\t-271112442-06-04T20:33:53.536Z\t2016-05-02T15:20:00.000Z\n" + - "-12\t0.000000001910\t0.3988\t-79\t-8\tWLP\ttrue\tPP\t15\t183931713-08-27T07:01:08.360Z\t2016-05-02T16:20:00.000Z\n" + - "6\t0.000000000000\t0.3820\t-49\t5\tGZSXUXI\tfalse\tBZ\t-18\t-197160329-04-12T04:43:10.644Z\t2016-05-02T17:20:00.000Z\n" + - "4\t0.000000000000\t0.4107\t-5\t19\t\tfalse\tLK\t2\t262468290-01-10T09:15:31.151Z\t2016-05-02T18:20:00.000Z\n" + - "-11\t0.000001089423\t0.2162\t-43\t15\tLOFJ\tfalse\tPP\t0\t209089147-12-19T04:29:10.493Z\t2016-05-02T19:20:00.000Z\n" + - "0\t0.000289257550\t0.4044\t42\t0\tHRUEDRQ\tfalse\tAX\t10\t-161826133-09-07T07:28:50.913Z\t2016-05-02T20:20:00.000Z\n" + - "-9\t0.000785129319\t0.6467\t91\t-27\tLOFJ\tfalse\tBZ\t-6\t148897812-12-15T01:00:11.703Z\t2016-05-02T21:20:00.000Z\n" + - "7\t356.000000000000\t0.5397\t85\t6\tHRUEDRQ\ttrue\tKK\t10\t52555995-12-26T23:37:05.955Z\t2016-05-02T22:20:00.000Z\n" + - "-2\t0.043181171641\t0.3539\t13\t26\tWLP\tfalse\tAX\t3\t-113384166-10-23T20:22:54.045Z\t2016-05-02T23:20:00.000Z\n" + - "11\t544.000000000000\t0.4989\t53\t-11\tUOJ\ttrue\tKK\t2\t260185350-01-17T23:00:05.032Z\t2016-05-03T00:20:00.000Z\n" + - "0\t-939.150390625000\t0.9357\t14\t9\t\tfalse\tXX\t15\t127995020-08-13T16:59:35.695Z\t2016-05-03T01:20:00.000Z\n" + - "-3\t-512.000000000000\t0.7342\t-113\t5\tLOFJ\ttrue\tAX\t-6\t-178979734-11-09T01:51:12.126Z\t2016-05-03T02:20:00.000Z\n" + - "8\t-608.000000000000\t0.2735\t32\t-29\tBE\ttrue\tBZ\t-15\t-254265260-02-23T17:20:11.048Z\t2016-05-03T03:20:00.000Z\n" + - "13\t880.000000000000\t0.8617\t5\t25\tUOJ\ttrue\tBZ\t-1\t129690313-12-24T17:39:48.572Z\t2016-05-03T04:20:00.000Z\n" + - "2\t0.000000073780\t0.3799\t117\t-2\t\tfalse\tKK\t4\t-121722446-07-08T23:56:05.720Z\t2016-05-03T05:20:00.000Z\n" + - "4\t203.186584472656\t0.2607\t71\t0\tLOFJ\ttrue\tUX\t17\t-181325686-09-13T22:04:02.927Z\t2016-05-03T06:20:00.000Z\n" + - "-14\t786.767028808594\t0.3143\t-5\t-17\tHRUEDRQ\tfalse\tAX\t0\t259740121-07-30T21:53:22.027Z\t2016-05-03T07:20:00.000Z\n" + - "-4\t0.000002205143\t0.5756\t118\t2\t\tfalse\tXX\t-1\t-276921280-04-04T14:11:20.192Z\t2016-05-03T08:20:00.000Z\n" + - "-4\t-5.687500000000\t0.7677\t-54\t10\tJWCPSWHY\ttrue\tUX\t-13\t54012480-01-02T08:46:17.912Z\t2016-05-03T09:20:00.000Z\n" + - "0\t-1018.312500000000\t0.5689\t31\t11\tLOFJ\ttrue\tPP\t18\t-180052650-09-21T11:14:15.944Z\t2016-05-03T10:20:00.000Z\n" + - "1\t380.435256958008\t0.5316\t-34\t24\tJWCPSWHY\tfalse\tUX\t-4\t-278219096-06-15T21:56:31.179Z\t2016-05-03T11:20:00.000Z\n" + - "0\t-435.875000000000\t0.7209\t-119\t-5\tHRUEDRQ\tfalse\tUX\t6\t242195152-12-20T13:33:39.965Z\t2016-05-03T12:20:00.000Z\n" + - "7\t128.000000000000\t0.4951\t25\t29\tGZSXUXI\tfalse\tKK\t16\t-278797166-01-17T22:56:32.254Z\t2016-05-03T13:20:00.000Z\n" + - "-9\t-1024.000000000000\t0.1471\t-13\t-29\tGPGWFFYU\ttrue\tAX\t-9\t-236718510-11-07T19:13:46.659Z\t2016-05-03T14:20:00.000Z\n" + - "8\t0.000000150060\t0.1841\t117\t22\tGZSXUXI\tfalse\tAX\t15\t-238642470-10-13T04:15:24.913Z\t2016-05-03T15:20:00.000Z\n" + - "0\t0.397523656487\t0.6872\t-47\t28\t\tfalse\tXX\t5\t-111732737-02-13T23:35:39.795Z\t2016-05-03T16:20:00.000Z\n" + - "-7\t0.000000000000\t0.6077\t55\t5\t\ttrue\tAX\t11\t-203338876-03-18T12:38:49.911Z\t2016-05-03T17:20:00.000Z\n" + - "4\t0.696862459183\t0.8342\t100\t-25\tXY\ttrue\tBZ\t2\t-225801370-11-22T17:26:22.000Z\t2016-05-03T18:20:00.000Z\n" + - "-3\t630.071426391602\t0.5040\t-104\t22\tGZSXUXI\ttrue\tLK\t19\t-245698050-05-09T18:07:37.692Z\t2016-05-03T19:20:00.000Z\n" + - "9\t0.000011650457\t0.4842\t-10\t-26\tHRUEDRQ\ttrue\tLK\t10\t155429843-10-22T12:20:05.600Z\t2016-05-03T20:20:00.000Z\n" + - "13\t-486.985961914063\t0.8112\t17\t1\tUOJ\ttrue\tUX\t-1\t-164973600-12-07T08:29:03.419Z\t2016-05-03T21:20:00.000Z\n" + - "-5\t0.000001392326\t0.4775\t70\t-1\tF\tfalse\tBZ\t19\t264185326-08-05T15:17:03.075Z\t2016-05-03T22:20:00.000Z\n" + - "0\t0.000115693385\t0.4571\t-80\t27\tF\tfalse\tAX\t-3\t111350393-05-07T05:03:18.261Z\t2016-05-03T23:20:00.000Z\n" + - "13\t199.865051269531\t0.5774\t99\t-24\tUOJ\ttrue\tXX\t-17\t275828192-06-05T06:47:48.447Z\t2016-05-04T00:20:00.000Z\n" + - "5\t342.142333984375\t0.9537\t-120\t-24\tEYYQEHB\tfalse\tAX\t-12\t-241419347-05-01T23:17:30.016Z\t2016-05-04T01:20:00.000Z\n" + - "-10\t0.000001694924\t0.2260\t-75\t9\tBE\ttrue\tPP\t15\t184914589-01-19T15:23:59.555Z\t2016-05-04T02:20:00.000Z\n" + - "14\t-590.250000000000\t0.3742\t-87\t-21\tLOFJ\ttrue\tAX\t11\t276709641-11-28T08:14:52.412Z\t2016-05-04T03:20:00.000Z\n" + - "0\t-966.000000000000\t0.1861\t-13\t-10\tEYYQEHB\ttrue\tXX\t-15\t251111747-04-16T12:15:33.296Z\t2016-05-04T04:20:00.000Z\n" + - "-13\t796.500000000000\t0.3671\t126\t-28\tF\tfalse\tLK\t-1\t199133769-08-08T06:18:53.598Z\t2016-05-04T05:20:00.000Z\n" + - "14\t0.000002621292\t0.4290\t-77\t11\tF\ttrue\tAX\t-3\t-39201740-06-25T17:21:59.836Z\t2016-05-04T06:20:00.000Z\n" + - "1\t-930.523193359375\t0.3797\t-3\t-28\tXPEHNR\ttrue\tBZ\t8\t149043763-10-24T00:17:04.693Z\t2016-05-04T07:20:00.000Z\n" + - "-12\t312.000000000000\t0.3777\t34\t-17\tEYYQEHB\tfalse\tBZ\t-18\t151109554-01-30T23:07:51.066Z\t2016-05-04T08:20:00.000Z\n" + - "6\t0.000000032774\t0.5188\t-41\t-28\tWLP\ttrue\tBZ\t-11\t283662573-06-19T09:19:02.551Z\t2016-05-04T09:20:00.000Z\n" + - "9\t19.849394798279\t0.7422\t63\t-18\tWLP\tfalse\tPP\t15\t218146413-06-27T17:36:19.271Z\t2016-05-04T10:20:00.000Z\n"; - - assertThat(expected, "parent"); - } - - @Test - public void testSelectedColumnsRowId() throws Exception { - assertRowId("select date, sym from parent", "date"); - } - - @Test - public void testTopRowId() throws Exception { - assertRowId("parent limit 0,10", "timestamp"); - } - - @Test - public void testVanillaRowId() throws Exception { - assertRowId("parent", "date"); - } - - @Test - public void testVirtualColumnRowId() throws Exception { - assertRowId("select date, d + f from parent", "date"); - } -} \ No newline at end of file diff --git a/core/src/test/java/com/questdb/ql/MergingRowSourceTest.java b/core/src/test/java/com/questdb/ql/MergingRowSourceTest.java deleted file mode 100644 index ba8026e80..000000000 --- a/core/src/test/java/com/questdb/ql/MergingRowSourceTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql; - -import com.questdb.model.Quote; -import com.questdb.ql.latest.HeapMergingRowSource; -import com.questdb.ql.latest.KvIndexSymLookupRowSource; -import com.questdb.ql.latest.MergingRowSource; -import com.questdb.std.NumericException; -import com.questdb.std.ex.JournalException; -import com.questdb.std.time.DateFormatUtils; -import com.questdb.store.JournalWriter; -import com.questdb.store.RecordCursor; -import com.questdb.test.tools.AbstractTest; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Test; - -public class MergingRowSourceTest extends AbstractTest { - @Test - public void testHeapMerge() throws JournalException, NumericException { - try (JournalWriter w = getFactory().writer(Quote.class)) { - TestUtils.generateQuoteData(w, 100000, DateFormatUtils.parseDateTime("2014-02-11T00:00:00.000Z"), 10); - - RowSource srcA = new KvIndexSymLookupRowSource("sym", "BP.L", true); - RowSource srcB = new KvIndexSymLookupRowSource("sym", "WTB.L", true); - - RecordSource rs = new JournalRecordSource(new JournalPartitionSource(w.getMetadata(), true), new HeapMergingRowSource(srcA, srcB)); - - long last = 0; - RecordCursor c = rs.prepareCursor(getFactory()); - try { - int ts = rs.getMetadata().getColumnIndex("timestamp"); - while (c.hasNext()) { - long r = c.next().getDate(ts); - Assert.assertTrue(r > last); - last = r; - } - } finally { - c.releaseCursor(); - } - } - } - - @Test - public void testMerge() throws JournalException, NumericException { - try (JournalWriter w = getFactory().writer(Quote.class)) { - TestUtils.generateQuoteData(w, 100000, DateFormatUtils.parseDateTime("2014-02-11T00:00:00.000Z"), 10); - - RowSource srcA = new KvIndexSymLookupRowSource("sym", "BP.L", true); - RowSource srcB = new KvIndexSymLookupRowSource("sym", "WTB.L", true); - - try (RecordSource rs = new JournalRecordSource(new JournalPartitionSource(w.getMetadata(), true), new MergingRowSource(srcA, srcB))) { - - long last = 0; - RecordCursor c = rs.prepareCursor(getFactory()); - try { - int ts = rs.getMetadata().getColumnIndex("timestamp"); - while (c.hasNext()) { - long r = c.next().getDate(ts); - Assert.assertTrue(r > last); - last = r; - } - } finally { - c.releaseCursor(); - } - } - } - } - -} diff --git a/core/src/test/java/com/questdb/ql/MultiIntervalPartitionSourceTest.java b/core/src/test/java/com/questdb/ql/MultiIntervalPartitionSourceTest.java deleted file mode 100644 index ed33c9108..000000000 --- a/core/src/test/java/com/questdb/ql/MultiIntervalPartitionSourceTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql; - -import com.questdb.model.Quote; -import com.questdb.ql.interval.MultiIntervalPartitionSource; -import com.questdb.std.LongList; -import com.questdb.std.str.StringSink; -import com.questdb.std.time.DateFormatUtils; -import com.questdb.std.time.Dates; -import com.questdb.store.JournalWriter; -import com.questdb.test.tools.AbstractTest; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Test; - -public class MultiIntervalPartitionSourceTest extends AbstractTest { - - @Test - public void testIntervalMerge() throws Exception { - StringSink sink = new StringSink(); - - try (JournalWriter w = getFactory().writer(Quote.class)) { - TestUtils.generateQuoteData(w, 600, DateFormatUtils.parseDateTime("2014-03-10T02:00:00.000Z"), Dates.MINUTE_MILLIS); - w.commit(); - - RecordSourcePrinter p = new RecordSourcePrinter(sink); - - LongList intervals = new LongList(); - intervals.add(DateFormatUtils.parseDateTime("2014-03-10T07:00:00.000Z")); - intervals.add(DateFormatUtils.parseDateTime("2014-03-10T07:15:00.000Z")); - - p.print( - new JournalRecordSource( - new MultiIntervalPartitionSource( - new JournalPartitionSource(w.getMetadata(), true), - intervals - ), - new AllRowSource() - ), getFactory() - ); - } - - final String expected = "2014-03-10T07:00:00.000Z\tGKN.L\t290.000000000000\t320.000000000000\t1070060020\t627764827\tFast trading\tLXE\n" + - "2014-03-10T07:01:00.000Z\tLLOY.L\t0.001271238521\t0.000000010817\t855783502\t444545168\tFast trading\tLXE\n" + - "2014-03-10T07:02:00.000Z\tRRS.L\t0.000010917804\t272.000000000000\t1212565949\t1829154977\tFast trading\tLXE\n" + - "2014-03-10T07:03:00.000Z\tTLW.L\t245.300086975098\t363.160156250000\t1722093204\t448833342\tFast trading\tLXE\n" + - "2014-03-10T07:04:00.000Z\tTLW.L\t0.025095539168\t0.000000122058\t1703832336\t180642477\tFast trading\tLXE\n" + - "2014-03-10T07:05:00.000Z\tADM.L\t902.500000000000\t24.333267211914\t781438951\t502201118\tFast trading\tLXE\n" + - "2014-03-10T07:06:00.000Z\tAGK.L\t144.695419311523\t0.000039814179\t639071723\t1848238665\tFast trading\tLXE\n" + - "2014-03-10T07:07:00.000Z\tLLOY.L\t0.000035416079\t15.248794555664\t1987214795\t856360285\tFast trading\tLXE\n" + - "2014-03-10T07:08:00.000Z\tAGK.L\t0.207015849650\t0.199165701866\t1090730005\t1076974002\tFast trading\tLXE\n" + - "2014-03-10T07:09:00.000Z\tLLOY.L\t447.510742187500\t209.001678466797\t136979290\t653726755\tFast trading\tLXE\n" + - "2014-03-10T07:10:00.000Z\tBT-A.L\t662.032958984375\t0.000000007138\t1140333902\t1156896957\tFast trading\tLXE\n" + - "2014-03-10T07:11:00.000Z\tAGK.L\t512.000000000000\t33.973937988281\t1723438228\t349327821\tFast trading\tLXE\n" + - "2014-03-10T07:12:00.000Z\tWTB.L\t384.000000000000\t0.000000832384\t2145991300\t1388483923\tFast trading\tLXE\n" + - "2014-03-10T07:13:00.000Z\tTLW.L\t0.000000093063\t0.000071085584\t1186156647\t1143726003\tFast trading\tLXE\n" + - "2014-03-10T07:14:00.000Z\tAGK.L\t0.006215140224\t0.000000004051\t2086874501\t1272052914\tFast trading\tLXE\n" + - "2014-03-10T07:15:00.000Z\tBP.L\t642.189208984375\t148.932441711426\t1552494421\t348870719\tFast trading\tLXE\n"; - - Assert.assertEquals(expected, sink.toString()); - - } -} \ No newline at end of file diff --git a/core/src/test/java/com/questdb/ql/OperatorTest.java b/core/src/test/java/com/questdb/ql/OperatorTest.java deleted file mode 100644 index d750ebf6d..000000000 --- a/core/src/test/java/com/questdb/ql/OperatorTest.java +++ /dev/null @@ -1,669 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql; - -import com.questdb.ex.ParserException; -import com.questdb.parser.sql.AbstractOptimiserTest; -import com.questdb.parser.sql.QueryError; -import com.questdb.std.Numbers; -import com.questdb.std.Rnd; -import com.questdb.std.time.Dates; -import com.questdb.store.JournalEntryWriter; -import com.questdb.store.JournalWriter; -import com.questdb.store.factory.configuration.JournalStructure; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -public class OperatorTest extends AbstractOptimiserTest { - - @BeforeClass - public static void setUp() throws Exception { - - // this does thread local allocations that - // should not be accounted for while - // measuring query allocations and de-allocations - FACTORY_CONTAINER.getFactory().getConfiguration().exists(""); - - try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("abc") - .$int("i") - .$double("d") - .$float("f") - .$byte("b") - .$long("l") - .$str("str") - .$bool("boo") - .$sym("sym") - .$short("sho") - .$date("date") - .$ts() - .$())) { - int n = 1000; - String[] sym = {"AX", "XX", "BZ", "KK"}; - Rnd rnd = new Rnd(); - - long t = Dates.toMillis(2016, 5, 1, 10, 20); - long d = Dates.toMillis(2016, 5, 1, 10, 20); - for (int i = 0; i < n; i++) { - JournalEntryWriter ew = w.entryWriter(t += 60000); - ew.putInt(0, (rnd.nextPositiveInt() & 15) == 0 ? Numbers.INT_NaN : rnd.nextInt()); - ew.putDouble(1, (rnd.nextPositiveInt() & 15) == 0 ? Double.NaN : rnd.nextDouble()); - ew.putFloat(2, (rnd.nextPositiveInt() & 15) == 0 ? Float.NaN : rnd.nextFloat()); - ew.put(3, (byte) rnd.nextInt()); - ew.putLong(4, (rnd.nextPositiveInt() & 15) == 0 ? Numbers.LONG_NaN : rnd.nextLong()); - ew.putStr(5, (rnd.nextPositiveInt() & 15) == 0 ? null : sym[rnd.nextPositiveInt() % sym.length]); - ew.putBool(6, rnd.nextBoolean()); - ew.putSym(7, (rnd.nextPositiveInt() & 15) == 0 ? null : sym[rnd.nextPositiveInt() % sym.length]); - ew.putShort(8, (short) rnd.nextInt()); - d += 45000; - ew.putDate(9, (rnd.nextPositiveInt() & 15) == 0 ? Numbers.LONG_NaN : d); - ew.append(); - } - w.commit(); - } - } - - @Test - public void testByteIn() throws Exception { - assertThat("-117\t2016-05-01T10:41:00.000Z\n" + - "-117\t2016-05-01T10:43:00.000Z\n" + - "-40\t2016-05-01T18:56:00.000Z\n" + - "-117\t2016-05-01T23:08:00.000Z\n", - "select b, timestamp from abc where b in (-40, -117)"); - } - - @Test - public void testDateEqualStr() throws Exception { - assertThat("2016-05-01T10:22:15.000Z\t2016-05-01T10:23:00.000Z\n", - "select date, timestamp from abc where date = '2016-05-01T10:22:15.000Z'"); - } - - @Test - public void testDateGreaterOrEqualDate() throws Exception { - assertThat("2016-05-01T11:14:00.000Z\tXX\n" + - "2016-05-01T11:14:45.000Z\tXX\n" + - "2016-05-01T11:15:30.000Z\tKK\n" + - "2016-05-01T11:16:15.000Z\tXX\n" + - "2016-05-01T11:17:00.000Z\tKK\n", - "select date, sym from abc where date >= '2016-05-01T11:14:00.000Z' limit 5"); - } - - @Test - public void testDateGreaterOrEqualNull() throws Exception { - assertEmpty("select date, sym from abc where date >= null"); - } - - @Test - public void testDateGreaterOrEqualStr() throws Exception { - assertThat("2016-05-01T11:14:00.000Z\tXX\n" + - "2016-05-01T11:14:45.000Z\tXX\n" + - "2016-05-01T11:15:30.000Z\tKK\n" + - "2016-05-01T11:16:15.000Z\tXX\n" + - "2016-05-01T11:17:00.000Z\tKK\n", - "select date, sym from abc where date >= '2016-05-01T11:14:00.000Z' limit 5"); - } - - @Test - public void testDateGreaterThan() throws Exception { - assertThat("2016-05-01T10:21:00.000Z\t2016-05-01T10:20:45.000Z\n" + - "2016-05-01T10:22:00.000Z\t2016-05-01T10:21:30.000Z\n" + - "2016-05-01T10:23:00.000Z\t2016-05-01T10:22:15.000Z\n" + - "2016-05-01T10:24:00.000Z\t2016-05-01T10:23:00.000Z\n" + - "2016-05-01T10:25:00.000Z\t2016-05-01T10:23:45.000Z\n", - "select timestamp, date from abc where timestamp > date limit 5"); - } - - @Test - public void testDateGreaterThanNonConstStr() { - try { - expectFailure("select timestamp, date from abc where timestamp > str limit 5"); - } catch (ParserException e) { - Assert.assertEquals(48, QueryError.getPosition()); - } - } - - @Test - public void testDateGreaterThanNull() throws Exception { - assertEmpty("select timestamp, date from abc where date > null limit 5"); - } - - @Test - public void testDateGreaterThanStr() throws Exception { - assertThat("2016-05-01T10:25:00.000Z\t2016-05-01T10:23:45.000Z\n" + - "2016-05-01T10:26:00.000Z\t2016-05-01T10:24:30.000Z\n" + - "2016-05-01T10:27:00.000Z\t2016-05-01T10:25:15.000Z\n" + - "2016-05-01T10:28:00.000Z\t2016-05-01T10:26:00.000Z\n" + - "2016-05-01T10:29:00.000Z\t2016-05-01T10:26:45.000Z\n", - "select timestamp, date from abc where date > '2016-05-01T10:23:00.000Z' limit 5"); - } - - @Test - public void testDateIn() throws Exception { - assertThat("2016-05-01T10:25:15.000Z\t2016-05-01T10:27:00.000Z\t0.3180\n" + - "2016-05-01T10:26:00.000Z\t2016-05-01T10:28:00.000Z\t0.2358\n" + - "2016-05-01T10:26:45.000Z\t2016-05-01T10:29:00.000Z\t0.1341\n" + - "2016-05-01T10:27:30.000Z\t2016-05-01T10:30:00.000Z\t0.6746\n", - "select date, timestamp, f from abc where date in ('2016-05-01T10:25:15.000Z', '2016-05-01T10:27:30.000Z')"); - } - - @Test - public void testDateInNulls() { - try { - expectFailure("select date, timestamp, f from abc where date in ('2016-05-01T10:25:15.000Z', null)"); - } catch (ParserException e) { - Assert.assertEquals(78, QueryError.getPosition()); - } - } - - @Test - public void testDateInTooFewArgs() { - try { - expectFailure("select date, timestamp, f from abc where date in ('2016-05-01T10:25:15.000Z')"); - } catch (ParserException e) { - Assert.assertEquals(46, QueryError.getPosition()); - } - } - - @Test - public void testDateInTooManyArgs() { - try { - expectFailure("select date, timestamp, f from abc where date in ('2016-05-01T10:25:15.000Z', '2016-05-01T10:27:30.000Z','2016-05-01T10:27:30.000Z')"); - } catch (ParserException e) { - Assert.assertEquals(105, QueryError.getPosition()); - } - } - - @Test - public void testDateInWrongArgs() { - try { - expectFailure("select date, timestamp, f from abc where date in ('2016-05-01T10:25:15.000Z', 10)"); - } catch (ParserException e) { - Assert.assertEquals(78, QueryError.getPosition()); - } - } - - @Test - public void testDateLessOrEqualDate() throws Exception { - assertThat("2016-05-01T10:20:45.000Z\t2016-05-01T10:21:00.000Z\n" + - "2016-05-01T10:21:30.000Z\t2016-05-01T10:22:00.000Z\n" + - "2016-05-01T10:22:15.000Z\t2016-05-01T10:23:00.000Z\n" + - "2016-05-01T10:23:00.000Z\t2016-05-01T10:24:00.000Z\n" + - "2016-05-01T10:23:45.000Z\t2016-05-01T10:25:00.000Z\n", - "select date, timestamp from abc where date <= timestamp limit 5"); - } - - @Test - public void testDateLessOrEqualNull() throws Exception { - assertEmpty("select date, timestamp from abc where date <= null"); - } - - @Test - public void testDateLessOrEqualStr() throws Exception { - assertThat("2016-05-01T10:20:45.000Z\t2016-05-01T10:21:00.000Z\n" + - "2016-05-01T10:21:30.000Z\t2016-05-01T10:22:00.000Z\n" + - "2016-05-01T10:22:15.000Z\t2016-05-01T10:23:00.000Z\n" + - "2016-05-01T10:23:00.000Z\t2016-05-01T10:24:00.000Z\n" + - "2016-05-01T10:23:45.000Z\t2016-05-01T10:25:00.000Z\n" + - "2016-05-01T10:24:30.000Z\t2016-05-01T10:26:00.000Z\n", - "select date, timestamp from abc where date <= '2016-05-01T10:24:30.000Z'"); - } - - @Test - public void testDateLessThanDate() throws Exception { - assertThat("2016-05-01T10:20:45.000Z\t2016-05-01T10:21:00.000Z\n" + - "2016-05-01T10:21:30.000Z\t2016-05-01T10:22:00.000Z\n" + - "2016-05-01T10:22:15.000Z\t2016-05-01T10:23:00.000Z\n" + - "2016-05-01T10:23:00.000Z\t2016-05-01T10:24:00.000Z\n" + - "2016-05-01T10:23:45.000Z\t2016-05-01T10:25:00.000Z\n", - "select date, timestamp from abc where date < timestamp limit 5"); - } - - @Test - public void testDateLessThanNull() throws Exception { - assertEmpty("select date, timestamp from abc where date < null"); - } - - @Test - public void testDateLessThanStr() throws Exception { - assertThat("2016-05-01T10:20:45.000Z\t2016-05-01T10:21:00.000Z\n" + - "2016-05-01T10:21:30.000Z\t2016-05-01T10:22:00.000Z\n" + - "2016-05-01T10:22:15.000Z\t2016-05-01T10:23:00.000Z\n" + - "2016-05-01T10:23:00.000Z\t2016-05-01T10:24:00.000Z\n" + - "2016-05-01T10:23:45.000Z\t2016-05-01T10:25:00.000Z\n" + - "2016-05-01T10:24:30.000Z\t2016-05-01T10:26:00.000Z\n", - "select date, timestamp from abc where date < '2016-05-01T10:25:00.000Z'"); - } - - @Test - public void testDateNotEqualStr() throws Exception { - assertThat("2016-05-01T10:20:45.000Z\t2016-05-01T10:21:00.000Z\n" + - "2016-05-01T10:21:30.000Z\t2016-05-01T10:22:00.000Z\n" + - "2016-05-01T10:22:15.000Z\t2016-05-01T10:23:00.000Z\n" + - "2016-05-01T10:23:00.000Z\t2016-05-01T10:24:00.000Z\n" + - "2016-05-01T10:23:45.000Z\t2016-05-01T10:25:00.000Z\n" + - "2016-05-01T10:24:30.000Z\t2016-05-01T10:26:00.000Z\n" + - "2016-05-01T10:26:00.000Z\t2016-05-01T10:28:00.000Z\n" + - "2016-05-01T10:26:45.000Z\t2016-05-01T10:29:00.000Z\n" + - "2016-05-01T10:27:30.000Z\t2016-05-01T10:30:00.000Z\n" + - "2016-05-01T10:28:15.000Z\t2016-05-01T10:31:00.000Z\n", - "select date, timestamp from abc where date != '2016-05-01T10:25:15.000Z' limit 10"); - } - - @Test - public void testInInt() throws Exception { - assertThat("NaN\t2016-05-01T10:21:00.000Z\n" + - "724677640\t2016-05-01T10:47:00.000Z\n" + - "NaN\t2016-05-01T10:52:00.000Z\n" + - "NaN\t2016-05-01T10:55:00.000Z\n" + - "NaN\t2016-05-01T10:57:00.000Z\n" + - "NaN\t2016-05-01T11:07:00.000Z\n" + - "NaN\t2016-05-01T11:26:00.000Z\n" + - "NaN\t2016-05-01T11:33:00.000Z\n" + - "NaN\t2016-05-01T11:38:00.000Z\n" + - "NaN\t2016-05-01T11:54:00.000Z\n" + - "NaN\t2016-05-01T11:59:00.000Z\n" + - "NaN\t2016-05-01T12:27:00.000Z\n" + - "NaN\t2016-05-01T12:41:00.000Z\n" + - "NaN\t2016-05-01T12:59:00.000Z\n" + - "NaN\t2016-05-01T13:02:00.000Z\n" + - "NaN\t2016-05-01T13:07:00.000Z\n" + - "NaN\t2016-05-01T13:28:00.000Z\n" + - "NaN\t2016-05-01T13:50:00.000Z\n" + - "NaN\t2016-05-01T14:04:00.000Z\n" + - "NaN\t2016-05-01T15:04:00.000Z\n", - "select i, timestamp from abc where i in (724677640, NaN) limit 20"); - } - - @Test - public void testIntInNonConst() { - try { - expectFailure("select i, timestamp from abc where i in (1978144263, l) limit 20"); - } catch (ParserException e) { - Assert.assertEquals(53, QueryError.getPosition()); - } - } - - @Test - public void testIntInWrongType() { - try { - expectFailure("select i, timestamp from abc where i in (1978144263L, NaN) limit 20"); - } catch (ParserException e) { - Assert.assertEquals(41, QueryError.getPosition()); - } - } - - @Test - public void testLongIn() throws Exception { - assertThat("-2653407051020864006\t2016-05-01T10:21:00.000Z\n" + - "NaN\t2016-05-01T10:53:00.000Z\n" + - "NaN\t2016-05-01T11:11:00.000Z\n" + - "NaN\t2016-05-01T11:31:00.000Z\n" + - "NaN\t2016-05-01T11:54:00.000Z\n" + - "NaN\t2016-05-01T12:10:00.000Z\n" + - "NaN\t2016-05-01T12:37:00.000Z\n" + - "NaN\t2016-05-01T12:52:00.000Z\n" + - "NaN\t2016-05-01T12:59:00.000Z\n" + - "NaN\t2016-05-01T13:13:00.000Z\n", - "select l, timestamp from abc where l in (NaN, -2653407051020864006L) limit 10"); - } - - @Test - public void testLongInMixArg() throws Exception { - assertThat("8000176386900538697\t2016-05-01T10:23:00.000Z\n" + - "NaN\t2016-05-01T10:53:00.000Z\n" + - "NaN\t2016-05-01T11:11:00.000Z\n" + - "NaN\t2016-05-01T11:31:00.000Z\n" + - "NaN\t2016-05-01T11:54:00.000Z\n" + - "NaN\t2016-05-01T12:10:00.000Z\n" + - "NaN\t2016-05-01T12:37:00.000Z\n" + - "NaN\t2016-05-01T12:52:00.000Z\n" + - "NaN\t2016-05-01T12:59:00.000Z\n" + - "NaN\t2016-05-01T13:13:00.000Z\n", - "select l, timestamp from abc where l in (NaN, 8000176386900538697L, 3) limit 10"); - } - - @Test - public void testLongInWrongType() { - try { - expectFailure("select l, timestamp from abc where l in ('NaN', 9036423629723776443L, 3) limit 10"); - } catch (ParserException e) { - Assert.assertEquals(41, QueryError.getPosition()); - } - } - - @Test - public void testNullGreaterOrEqualDate() throws Exception { - assertEmpty("select date, sym from abc where null >= date"); - } - - @Test - public void testNullGreaterThanDate() throws Exception { - assertEmpty("select timestamp, date from abc where null > date"); - } - - @Test - public void testParserErrorOnNegativeNumbers() throws Exception { - assertThat("NaN\t2016-05-01T10:21:00.000Z\n" + - "-1271909747\t2016-05-01T10:24:00.000Z\n" + - "NaN\t2016-05-01T10:52:00.000Z\n" + - "NaN\t2016-05-01T10:55:00.000Z\n" + - "NaN\t2016-05-01T10:57:00.000Z\n" + - "NaN\t2016-05-01T11:07:00.000Z\n" + - "NaN\t2016-05-01T11:26:00.000Z\n" + - "NaN\t2016-05-01T11:33:00.000Z\n" + - "NaN\t2016-05-01T11:38:00.000Z\n" + - "NaN\t2016-05-01T11:54:00.000Z\n", - "select i, timestamp from abc where i in (-1271909747, NaN) limit 10"); - } - - @Test - public void testPrevWithNull() throws Exception { - assertThat("XX\tAX\t\t2016-05-01T10:23:00.000Z\n" + - "XX\tKK\t\t2016-05-01T10:25:00.000Z\n" + - "XX\tBZ\t\t2016-05-01T10:27:00.000Z\n" + - "XX\tBZ\tXX\t2016-05-01T10:36:00.000Z\n" + - "XX\tBZ\tXX\t2016-05-01T10:39:00.000Z\n" + - "\tAX\tXX\t2016-05-01T10:41:00.000Z\n" + - "XX\t\t\t2016-05-01T10:42:00.000Z\n" + - "XX\tKK\tXX\t2016-05-01T10:43:00.000Z\n" + - "XX\tBZ\tXX\t2016-05-01T10:49:00.000Z\n" + - "XX\tAX\t\t2016-05-01T10:53:00.000Z\n" + - "XX\tKK\tXX\t2016-05-01T10:57:00.000Z\n" + - "XX\tKK\tXX\t2016-05-01T10:59:00.000Z\n" + - "XX\tXX\t\t2016-05-01T11:00:00.000Z\n" + - "\tKK\tXX\t2016-05-01T11:01:00.000Z\n" + - "XX\tAX\tXX\t2016-05-01T11:02:00.000Z\n" + - "XX\tAX\tXX\t2016-05-01T11:03:00.000Z\n" + - "XX\tKK\t\t2016-05-01T11:05:00.000Z\n" + - "XX\tBZ\tXX\t2016-05-01T11:08:00.000Z\n" + - "XX\tBZ\tXX\t2016-05-01T11:20:00.000Z\n" + - "XX\tAX\tXX\t2016-05-01T11:25:00.000Z\n", - "select str, sym, prev(str) p over(partition by sym), timestamp from '*!*abc' where str in (null, 'XX') limit 20"); - } - - @Test - public void testShortGreater() throws Exception { - assertThat("215.009567260742\t-32679\n" + - "-190.000000000000\t-7374\n", - "select d, sho from abc where d > sho limit 2"); - - assertThat("8000176386900538697\t27809\n" + - "7709707078566863064\t-7374\n", - "select l, sho from abc where l > sho limit 2"); - - assertThat("0.4836\t-32679\n" + - "0.6755\t-7374\n", - "select f, sho from abc where f > sho limit 2"); - - assertThat("1573662097\t21781\n" + - "1404198\t27809\n", - "select i, sho from abc where i > sho limit 2"); - - assertThat("21781\t27\n" + - "27809\t54\n", - "select sho, b from abc where sho > b limit 2"); - - } - - @Test - public void testShortGreaterOrEqualDouble() throws Exception { - assertThat("21781\t0.293202951550\n" + - "27809\t0.040750414133\n" + - "22298\t109.355468750000\n" + - "10633\t0.000002968513\n" + - "8010\t0.000156438433\n", - "select sho, d from abc where sho >= d limit 5"); - } - - @Test - public void testShortIn() throws Exception { - assertThat("-7374\t2016-05-01T10:24:00.000Z\n" + - "-1605\t2016-05-01T10:30:00.000Z\n", - "select sho, timestamp from abc where sho in (-7374,-1605)"); - } - - @Test - public void testStrEqualsDate() throws Exception { - assertThat("2016-05-01T10:22:15.000Z\t2016-05-01T10:23:00.000Z\n", - "select date, timestamp from abc where '2016-05-01T10:22:15.000Z' = date"); - } - - @Test - public void testStrGreaterOrEqualDate() throws Exception { - assertThat("2016-05-01T10:20:45.000Z\tKK\n" + - "2016-05-01T10:21:30.000Z\tXX\n" + - "2016-05-01T10:22:15.000Z\tAX\n" + - "2016-05-01T10:23:00.000Z\tBZ\n" + - "2016-05-01T10:23:45.000Z\tKK\n", - "select date, sym from abc where '2016-05-01T10:23:45.000Z' >= date"); - } - - @Test - public void testStrGreaterThanDate() throws Exception { - assertThat("2016-05-01T10:21:00.000Z\t2016-05-01T10:20:45.000Z\n" + - "2016-05-01T10:22:00.000Z\t2016-05-01T10:21:30.000Z\n" + - "2016-05-01T10:23:00.000Z\t2016-05-01T10:22:15.000Z\n", - "select timestamp, date from abc where '2016-05-01T10:23:00.000Z' > date"); - } - - @Test - public void testStrIn() throws Exception { - assertThat("XX\t2016-05-01T10:23:00.000Z\n" + - "XX\t2016-05-01T10:25:00.000Z\n" + - "XX\t2016-05-01T10:27:00.000Z\n" + - "BZ\t2016-05-01T10:31:00.000Z\n" + - "BZ\t2016-05-01T10:33:00.000Z\n" + - "XX\t2016-05-01T10:36:00.000Z\n" + - "XX\t2016-05-01T10:39:00.000Z\n" + - "BZ\t2016-05-01T10:40:00.000Z\n" + - "XX\t2016-05-01T10:42:00.000Z\n" + - "XX\t2016-05-01T10:43:00.000Z\n", - "select str, timestamp from abc where str in ('BZ', 'XX') limit 10"); - } - - @Test - public void testStrInAsEq() throws Exception { - assertThat("XX\t2016-05-01T10:23:00.000Z\n" + - "XX\t2016-05-01T10:25:00.000Z\n" + - "XX\t2016-05-01T10:27:00.000Z\n" + - "XX\t2016-05-01T10:36:00.000Z\n" + - "XX\t2016-05-01T10:39:00.000Z\n" + - "XX\t2016-05-01T10:42:00.000Z\n" + - "XX\t2016-05-01T10:43:00.000Z\n" + - "XX\t2016-05-01T10:49:00.000Z\n" + - "XX\t2016-05-01T10:53:00.000Z\n" + - "XX\t2016-05-01T10:57:00.000Z\n" + - "XX\t2016-05-01T10:59:00.000Z\n" + - "XX\t2016-05-01T11:00:00.000Z\n" + - "XX\t2016-05-01T11:02:00.000Z\n" + - "XX\t2016-05-01T11:03:00.000Z\n" + - "XX\t2016-05-01T11:05:00.000Z\n" + - "XX\t2016-05-01T11:08:00.000Z\n" + - "XX\t2016-05-01T11:20:00.000Z\n" + - "XX\t2016-05-01T11:25:00.000Z\n" + - "XX\t2016-05-01T11:26:00.000Z\n" + - "XX\t2016-05-01T11:34:00.000Z\n", - "select str, timestamp from abc where str in ('XX') limit 20"); - } - - @Test - public void testStrInNonConst() { - try { - expectFailure("select str, timestamp from abc where str in ('X', sym) limit 20"); - } catch (ParserException e) { - Assert.assertEquals(50, QueryError.getPosition()); - } - } - - @Test - public void testStrInNull() throws Exception { - assertThat("XX\t2016-05-01T10:23:00.000Z\n" + - "XX\t2016-05-01T10:25:00.000Z\n" + - "XX\t2016-05-01T10:27:00.000Z\n" + - "XX\t2016-05-01T10:36:00.000Z\n" + - "XX\t2016-05-01T10:39:00.000Z\n" + - "\t2016-05-01T10:41:00.000Z\n" + - "XX\t2016-05-01T10:42:00.000Z\n" + - "XX\t2016-05-01T10:43:00.000Z\n" + - "XX\t2016-05-01T10:49:00.000Z\n" + - "XX\t2016-05-01T10:53:00.000Z\n" + - "XX\t2016-05-01T10:57:00.000Z\n" + - "XX\t2016-05-01T10:59:00.000Z\n" + - "XX\t2016-05-01T11:00:00.000Z\n" + - "\t2016-05-01T11:01:00.000Z\n" + - "XX\t2016-05-01T11:02:00.000Z\n" + - "XX\t2016-05-01T11:03:00.000Z\n" + - "XX\t2016-05-01T11:05:00.000Z\n" + - "XX\t2016-05-01T11:08:00.000Z\n" + - "XX\t2016-05-01T11:20:00.000Z\n" + - "XX\t2016-05-01T11:25:00.000Z\n", - "select str, timestamp from abc where str in (null, 'XX') limit 20"); - } - - @Test - public void testStrInWrongType() { - try { - expectFailure("select str, timestamp from abc where str in (10) limit 20"); - } catch (ParserException e) { - Assert.assertEquals(45, QueryError.getPosition()); - } - } - - @Test - public void testStrLessOrEqualDate() throws Exception { - assertThat("2016-05-01T10:25:15.000Z\t2016-05-01T10:27:00.000Z\n" + - "2016-05-01T10:26:00.000Z\t2016-05-01T10:28:00.000Z\n" + - "2016-05-01T10:26:45.000Z\t2016-05-01T10:29:00.000Z\n" + - "2016-05-01T10:27:30.000Z\t2016-05-01T10:30:00.000Z\n" + - "2016-05-01T10:28:15.000Z\t2016-05-01T10:31:00.000Z\n", - "select date, timestamp from abc where '2016-05-01T10:25:15.000Z' <= date limit 5"); - } - - @Test - public void testStrLessThanDate() throws Exception { - assertThat("2016-05-01T10:25:15.000Z\t2016-05-01T10:27:00.000Z\n" + - "2016-05-01T10:26:00.000Z\t2016-05-01T10:28:00.000Z\n" + - "2016-05-01T10:26:45.000Z\t2016-05-01T10:29:00.000Z\n" + - "2016-05-01T10:27:30.000Z\t2016-05-01T10:30:00.000Z\n" + - "2016-05-01T10:28:15.000Z\t2016-05-01T10:31:00.000Z\n", - "select date, timestamp from abc where '2016-05-01T10:25:00.000Z' < date limit 5"); - } - - @Test - public void testStrNotEqualDate() throws Exception { - assertThat("2016-05-01T10:20:45.000Z\t2016-05-01T10:21:00.000Z\n" + - "2016-05-01T10:21:30.000Z\t2016-05-01T10:22:00.000Z\n" + - "2016-05-01T10:22:15.000Z\t2016-05-01T10:23:00.000Z\n" + - "2016-05-01T10:23:00.000Z\t2016-05-01T10:24:00.000Z\n" + - "2016-05-01T10:23:45.000Z\t2016-05-01T10:25:00.000Z\n" + - "2016-05-01T10:24:30.000Z\t2016-05-01T10:26:00.000Z\n" + - "2016-05-01T10:26:00.000Z\t2016-05-01T10:28:00.000Z\n" + - "2016-05-01T10:26:45.000Z\t2016-05-01T10:29:00.000Z\n" + - "2016-05-01T10:27:30.000Z\t2016-05-01T10:30:00.000Z\n" + - "2016-05-01T10:28:15.000Z\t2016-05-01T10:31:00.000Z\n", - "select date, timestamp from abc where '2016-05-01T10:25:15.000Z' != date limit 10"); - } - - @Test - public void testSymIn() throws Exception { - assertThat("KK\t2016-05-01T10:21:00.000Z\n" + - "XX\t2016-05-01T10:22:00.000Z\n" + - "KK\t2016-05-01T10:25:00.000Z\n" + - "KK\t2016-05-01T10:29:00.000Z\n" + - "KK\t2016-05-01T10:30:00.000Z\n" + - "XX\t2016-05-01T10:31:00.000Z\n" + - "KK\t2016-05-01T10:33:00.000Z\n" + - "KK\t2016-05-01T10:38:00.000Z\n" + - "KK\t2016-05-01T10:43:00.000Z\n" + - "XX\t2016-05-01T10:44:00.000Z\n" + - "KK\t2016-05-01T10:46:00.000Z\n" + - "XX\t2016-05-01T10:54:00.000Z\n" + - "KK\t2016-05-01T10:56:00.000Z\n" + - "KK\t2016-05-01T10:57:00.000Z\n" + - "XX\t2016-05-01T10:58:00.000Z\n" + - "KK\t2016-05-01T10:59:00.000Z\n" + - "XX\t2016-05-01T11:00:00.000Z\n" + - "KK\t2016-05-01T11:01:00.000Z\n" + - "KK\t2016-05-01T11:04:00.000Z\n" + - "KK\t2016-05-01T11:05:00.000Z\n", - "select sym, timestamp from abc where sym in ('KK','XX') limit 20"); - } - - @Test - public void testSymInAsEq() throws Exception { - assertThat("KK\t2016-05-01T10:21:00.000Z\n" + - "KK\t2016-05-01T10:25:00.000Z\n" + - "KK\t2016-05-01T10:29:00.000Z\n" + - "KK\t2016-05-01T10:30:00.000Z\n" + - "KK\t2016-05-01T10:33:00.000Z\n" + - "KK\t2016-05-01T10:38:00.000Z\n" + - "KK\t2016-05-01T10:43:00.000Z\n" + - "KK\t2016-05-01T10:46:00.000Z\n" + - "KK\t2016-05-01T10:56:00.000Z\n" + - "KK\t2016-05-01T10:57:00.000Z\n" + - "KK\t2016-05-01T10:59:00.000Z\n" + - "KK\t2016-05-01T11:01:00.000Z\n" + - "KK\t2016-05-01T11:04:00.000Z\n" + - "KK\t2016-05-01T11:05:00.000Z\n" + - "KK\t2016-05-01T11:07:00.000Z\n" + - "KK\t2016-05-01T11:11:00.000Z\n" + - "KK\t2016-05-01T11:16:00.000Z\n" + - "KK\t2016-05-01T11:18:00.000Z\n" + - "KK\t2016-05-01T11:23:00.000Z\n" + - "KK\t2016-05-01T11:24:00.000Z\n", - "select sym, timestamp from abc where sym in ('KK') limit 20"); - } - - @Test - public void testSymInNull() throws Exception { - assertThat("KK\t2016-05-01T10:21:00.000Z\n" + - "KK\t2016-05-01T10:25:00.000Z\n" + - "KK\t2016-05-01T10:29:00.000Z\n" + - "KK\t2016-05-01T10:30:00.000Z\n" + - "KK\t2016-05-01T10:33:00.000Z\n" + - "\t2016-05-01T10:35:00.000Z\n" + - "KK\t2016-05-01T10:38:00.000Z\n" + - "\t2016-05-01T10:42:00.000Z\n" + - "KK\t2016-05-01T10:43:00.000Z\n" + - "KK\t2016-05-01T10:46:00.000Z\n" + - "\t2016-05-01T10:55:00.000Z\n" + - "KK\t2016-05-01T10:56:00.000Z\n" + - "KK\t2016-05-01T10:57:00.000Z\n" + - "KK\t2016-05-01T10:59:00.000Z\n" + - "KK\t2016-05-01T11:01:00.000Z\n" + - "KK\t2016-05-01T11:04:00.000Z\n" + - "KK\t2016-05-01T11:05:00.000Z\n" + - "KK\t2016-05-01T11:07:00.000Z\n" + - "KK\t2016-05-01T11:11:00.000Z\n" + - "\t2016-05-01T11:14:00.000Z\n", - "select sym, timestamp from abc where sym in (null, 'KK') limit 20"); - } - - @Test - public void testVirtualColumnDateFilter() throws Exception { - assertThat("2015-07-06T06:51:36.000Z\n" + - "2015-07-06T06:51:36.000Z\n", - "(select toDate('1970-01-01T00:00:00.000Z') + 1436165496*1000L x from abc) where x = '2015-07-06T06:51:36.000Z' limit 2"); - } -} diff --git a/core/src/test/java/com/questdb/ql/OrderByOptimiserTest.java b/core/src/test/java/com/questdb/ql/OrderByOptimiserTest.java deleted file mode 100644 index 918951648..000000000 --- a/core/src/test/java/com/questdb/ql/OrderByOptimiserTest.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql; - -import com.questdb.ex.ParserException; -import com.questdb.parser.sql.AbstractOptimiserTest; -import com.questdb.parser.sql.QueryError; -import com.questdb.store.JournalWriter; -import com.questdb.store.factory.configuration.JournalStructure; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class OrderByOptimiserTest extends AbstractOptimiserTest { - - @BeforeClass - public static void setUpClass() throws Exception { - JournalWriter w = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("tab"). - $sym("id").index().buckets(128). - $double("x"). - $double("y"). - $int("i1"). - $int("i2"). - $ts() - ); - w.close(); - - w = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("tex"). - $sym("id").index().buckets(128). - $double("amount"). - $ts() - ); - - w.close(); - - FACTORY_CONTAINER.getFactory().getConfiguration().exists(""); - } - - @Before - public void setUp() { - sink.clear(); - } - - @Test - public void testLiteralAnalysis() { - try { - expectFailure("select x,count() from tab order by timestamp"); - } catch (ParserException e) { - Assert.assertEquals(35, QueryError.getPosition()); - TestUtils.assertEquals("Invalid column: timestamp", QueryError.getMessage()); - } - } - - @Test - public void testOrderOnOneLevelSubQuery() throws Exception { - sink.put(compileSource("select x,count() from (tab order by timestamp)")); - TestUtils.assertEquals("{\"op\":\"SelectedColumnsRecordSource\",\"src\":{\"op\":\"AggregatedRecordSource\",\"src\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"JournalPartitionSource\",\"journal\":\"tab\"},\"rsrc\":{\"op\":\"AllRowSource\"}}}}", sink); - } - - @Test - public void testOrderOverride() throws Exception { - sink.put(compileSource("select x,count() from ((tab order by y) order by timestamp)")); - TestUtils.assertEquals("{\"op\":\"SelectedColumnsRecordSource\",\"src\":{\"op\":\"AggregatedRecordSource\",\"src\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"JournalPartitionSource\",\"journal\":\"tab\"},\"rsrc\":{\"op\":\"AllRowSource\"}}}}", sink); - } - - @Test - public void testRegularOrder() throws Exception { - sink.put(compileSource("select x,y from ((tab order by y) order by timestamp)")); - TestUtils.assertEquals("{\"op\":\"SelectedColumnsRecordSource\",\"src\":{\"op\":\"RBTreeSortedRecordSource\",\"byRowId\":true,\"src\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"JournalPartitionSource\",\"journal\":\"tab\"},\"rsrc\":{\"op\":\"AllRowSource\"}}}}", sink); - } - - @Test - public void testSampleByBackout() throws Exception { - sink.put(compileSource("(select x,count() from (select y, x, count() from (tab order by timestamp) sample by 1M order by y)) where x = 100")); - TestUtils.assertEquals("{\"op\":\"SelectedColumnsRecordSource\",\"src\":{\"op\":\"AggregatedRecordSource\",\"src\":{\"op\":\"RBTreeSortedRecordSource\",\"byRowId\":false,\"src\":{\"op\":\"SelectedColumnsRecordSource\",\"src\":{\"op\":\"ResampledRecordSource\",\"src\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"JournalPartitionSource\",\"journal\":\"tab\"},\"rsrc\":{\"op\":\"FilteredRowSource\",\"rsrc\":{\"op\":\"AllRowSource\"}}},\"sampler\":{\"op\":\"MonthsSampler\",\"buckets\":1}}}}}}", sink); - } -} diff --git a/core/src/test/java/com/questdb/ql/ParameterTest.java b/core/src/test/java/com/questdb/ql/ParameterTest.java deleted file mode 100644 index 7d6dacbe2..000000000 --- a/core/src/test/java/com/questdb/ql/ParameterTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql; - -import com.questdb.ex.ParserException; -import org.junit.Test; - -import java.io.IOException; - -public class ParameterTest extends AbstractAllTypeTest { - - @Test - public void testEqualDouble() throws Exception { - try (RecordSource rs = compileSource("abc where eq(d, :value, 0.0000001)")) { - rs.getParam(":value").set(566.734375); - assertThat("i\td\tf\tb\tl\tstr\tboo\tsym\tsho\tdate\ttimestamp\n" + - "-2041844972\t566.734375000000\t0.7780\t-120\t-6943924477733600060\tXX\tfalse\tBZ\t-24357\t-284210729-04-16T06:37:25.107Z\t2016-05-01T10:22:00.000Z\n", - rs, true); - } - - try (RecordSource rs = compileSource("abc where eq(d, :value, :scale)")) { - rs.getParam(":value").set(566.734375); - rs.getParam(":scale").set(0.000001); - assertThat("i\td\tf\tb\tl\tstr\tboo\tsym\tsho\tdate\ttimestamp\n" + - "-2041844972\t566.734375000000\t0.7780\t-120\t-6943924477733600060\tXX\tfalse\tBZ\t-24357\t-284210729-04-16T06:37:25.107Z\t2016-05-01T10:22:00.000Z\n", - rs, true); - } - - try (RecordSource rs = compileSource("abc where eq(d, 566.734375, :scale)")) { - rs.getParam(":scale").set(0.000001); - assertThat("i\td\tf\tb\tl\tstr\tboo\tsym\tsho\tdate\ttimestamp\n" + - "-2041844972\t566.734375000000\t0.7780\t-120\t-6943924477733600060\tXX\tfalse\tBZ\t-24357\t-284210729-04-16T06:37:25.107Z\t2016-05-01T10:22:00.000Z\n", - rs, true); - } - } - - @Test - public void testEqualInt() throws Exception { - testInt("abc where i = :value"); - testInt("abc where :value = i"); - } - - @Test - public void testEqualLong() throws Exception { - try (RecordSource rs = compileSource("abc where l = :value")) { - rs.getParam(":value").set(-6943924477733600060L); - assertThat("i\td\tf\tb\tl\tstr\tboo\tsym\tsho\tdate\ttimestamp\n" + - "-2041844972\t566.734375000000\t0.7780\t-120\t-6943924477733600060\tXX\tfalse\tBZ\t-24357\t-284210729-04-16T06:37:25.107Z\t2016-05-01T10:22:00.000Z\n", - rs, true); - } - } - - @Test - public void testSymbolEquals() throws Exception { - try (RecordSource rs = compileSource("abc where sym = :sym")) { - rs.getParam(":sym").set("AX"); - assertThat("i\td\tf\tb\tl\tstr\tboo\tsym\tsho\tdate\ttimestamp\n" + - "-235358133\t0.000000005555\t0.3509\t-15\t-3107239868490395663\tBZ\tfalse\tAX\t-15331\t18125533-09-05T04:06:38.086Z\t2016-05-01T10:30:00.000Z\n" + - "-572338288\t632.921875000000\t0.5619\t-114\t7122109662042058469\tKK\tfalse\tAX\t25102\t132059357-01-03T08:27:45.836Z\t2016-05-01T10:32:00.000Z\n" + - "-731466113\t0.000000020896\t0.5433\t-55\t-6626590012581323602\tAX\tfalse\tAX\t-20409\t-253361973-02-05T02:07:37.180Z\t2016-05-01T10:33:00.000Z\n" + - "-1966408995\t0.000000014643\t0.6746\t-77\t-8082754367165748693\tXX\ttrue\tAX\t25974\t-225086326-11-23T21:53:40.936Z\t2016-05-01T10:35:00.000Z\n" + - "1335037859\t512.000000000000\t0.8217\t-83\t6574958665733670985\tAX\ttrue\tAX\t5869\t252677978-05-07T03:29:33.753Z\t2016-05-01T10:36:00.000Z\n" + - "-1383560599\t0.000000157437\t0.6827\t-102\t8889492928577876455\tAX\ttrue\tAX\t-18600\t-196068605-07-20T05:32:43.747Z\t2016-05-01T10:38:00.000Z\n" + - "-1475953213\t0.000032060649\t0.4967\t70\t-6071768268784020226\tBZ\tfalse\tAX\t-24455\t-56977607-10-20T13:10:29.515Z\t2016-05-01T10:40:00.000Z\n", - rs, true); - } - } - - private void testInt(String query) throws ParserException, IOException { - try (RecordSource rs = compileSource(query)) { - rs.getParam(":value").set(1335037859); - - assertThat("i\td\tf\tb\tl\tstr\tboo\tsym\tsho\tdate\ttimestamp\n" + - "1335037859\t512.000000000000\t0.8217\t-83\t6574958665733670985\tAX\ttrue\tAX\t5869\t252677978-05-07T03:29:33.753Z\t2016-05-01T10:36:00.000Z\n", - rs, true); - - rs.getParam(":value").set(-572338288); - assertThat("i\td\tf\tb\tl\tstr\tboo\tsym\tsho\tdate\ttimestamp\n" + - "-572338288\t632.921875000000\t0.5619\t-114\t7122109662042058469\tKK\tfalse\tAX\t25102\t132059357-01-03T08:27:45.836Z\t2016-05-01T10:32:00.000Z\n", - rs, true); - } - } -} diff --git a/core/src/test/java/com/questdb/ql/RecordListTest.java b/core/src/test/java/com/questdb/ql/RecordListTest.java deleted file mode 100644 index a4e6f63a0..000000000 --- a/core/src/test/java/com/questdb/ql/RecordListTest.java +++ /dev/null @@ -1,306 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql; - -import com.questdb.ex.ParserException; -import com.questdb.parser.sql.QueryCompiler; -import com.questdb.std.DirectInputStream; -import com.questdb.std.LongList; -import com.questdb.std.Unsafe; -import com.questdb.std.ex.JournalException; -import com.questdb.store.JournalWriter; -import com.questdb.store.Record; -import com.questdb.store.RecordCursor; -import com.questdb.test.tools.AbstractTest; -import org.junit.Assert; -import org.junit.Test; - -import java.io.IOException; -import java.nio.ByteBuffer; - - -public class RecordListTest extends AbstractTest { - private final QueryCompiler compiler = new QueryCompiler(); - - @Test - public void testAllFieldTypesField() throws JournalException, IOException, ParserException { - writeAndReadRecords(getFactory().writer(AllFieldTypes.class), 1000, 64 * 1024, - new RecordGenerator() { - @Override - public void assertRecord(Record value, int i) throws IOException { - AllFieldTypes expected = generate(i); - int col = 0; - String failedMsg = "Record " + i; - Assert.assertEquals(failedMsg, expected.aBool, value.getBool(col++)); - Assert.assertEquals(failedMsg, expected.aString, value.getFlyweightStr(col++).toString()); - Assert.assertEquals(failedMsg, expected.aByte, value.getByte(col++)); - Assert.assertEquals(failedMsg, expected.aShort, value.getShort(col++)); - Assert.assertEquals(failedMsg, expected.anInt, value.getInt(col++)); - DirectInputStream binCol = value.getBin(col++); - byte[] expectedBin = expected.aBinary.array(); - Assert.assertEquals(failedMsg, expectedBin.length, binCol.size()); - for (int j = 0; j < expectedBin.length; j++) { - Assert.assertEquals(failedMsg + " byte " + j, expectedBin[j], (byte) binCol.read()); - } - Assert.assertEquals(failedMsg, expected.aLong, value.getLong(col++)); - Assert.assertEquals(failedMsg, expected.aDouble, value.getDouble(col++), 0.0001); - Assert.assertEquals(failedMsg, expected.aFloat, value.getFloat(col), 0.0001); - } - - @Override - public AllFieldTypes generate(int i) { - AllFieldTypes af = new AllFieldTypes(); - byte[] bin = new byte[i]; - for (int j = 0; j < i; j++) { - bin[j] = (byte) (j % 255); - } - af.aBinary = ByteBuffer.wrap(bin); - af.aBool = i % 2 == 0; - af.aByte = (byte) (i % 255); - af.aDouble = i * Math.PI; - af.aFloat = (float) (Math.PI / i); - af.aLong = i * 2; - af.anInt = i; - af.aShort = (short) (i / 2); - StringBuilder sb = new StringBuilder(i); - for (int j = 0; j < i; j++) { - sb.append((char) j); - } - af.aString = sb.toString(); - return af; - } - }); - } - - @Test - public void testBlankList() throws Exception { - writeAndReadRecords(getFactory().writer(LongValue.class), 0, 450, - new RecordGenerator() { - @Override - public void assertRecord(Record value, int i) { - } - - @Override - public LongValue generate(int i) { - return new LongValue(i); - } - }); - } - - @Test - public void testCopyBinToAddress() throws JournalException, IOException, ParserException { - final int pageLen = 1024 * 1024; - writeAndReadRecords(getFactory().writer(Binary.class), 1, pageLen, - new RecordGenerator() { - - @Override - public void assertRecord(Record value, int i) { - DirectInputStream binCol = value.getBin(0); - Binary expected = generate(i); - Assert.assertEquals(expected.aBinary.remaining(), binCol.size()); - assertEquals(expected.aBinary, binCol); - } - - @Override - public Binary generate(int i) { - Binary af = new Binary(); - byte[] bin = new byte[1024 * 1024 - 15]; - for (int j = 0; j < bin.length; j++) { - bin[j] = (byte) 'A'; - } - af.aBinary = ByteBuffer.wrap(bin); - return af; - } - }); - } - - @Test - public void testSaveBinOverPageEdge() throws JournalException, IOException, ParserException { - final int pageLen = 100; - writeAndReadRecords(getFactory().writer(Binary.class), 1, pageLen, - new RecordGenerator() { - - @Override - public void assertRecord(Record value, int i) throws IOException { - DirectInputStream binCol = value.getBin(0); - Binary expected = generate(i); - byte[] expectedBin = expected.aBinary.array(); - Assert.assertEquals(expected.aBinary.remaining(), binCol.size()); - for (int j = 0; j < expectedBin.length; j++) { - Assert.assertEquals(expectedBin[j], (byte) binCol.read()); - } - } - - @Override - public Binary generate(int i) { - Binary af = new Binary(); - byte[] bin = new byte[pageLen]; - for (int j = 0; j < bin.length; j++) { - bin[j] = (byte) (j % 255); - } - af.aBinary = ByteBuffer.wrap(bin); - return af; - } - }); - } - - @Test - public void testSaveLongField() throws JournalException, IOException, ParserException { - writeAndReadRecords(getFactory().writer(LongValue.class), 100, 450, - new RecordGenerator() { - - @Override - public void assertRecord(Record value, int i) { - Assert.assertEquals((long) i, value.getLong(0)); - } - - @Override - public LongValue generate(int i) { - return new LongValue(i); - } - }); - } - - @Test - public void testSaveNullBinAndStrings() throws JournalException, IOException, ParserException { - final int pageLen = 100; - writeAndReadRecords(getFactory().writer(StringLongBinary.class), 3, pageLen, - new RecordGenerator() { - - @Override - public void assertRecord(Record value, int i) { - StringLongBinary expected = generate(i); - - CharSequence str = value.getFlyweightStr(0); - if (expected.aString != null || str != null) { - Assert.assertEquals(expected.aString, str.toString()); - } - - Assert.assertEquals(expected.aLong, value.getLong(1)); - - DirectInputStream binCol = value.getBin(2); - if (expected.aBinary != null && binCol != null) { - byte[] expectedBin = expected.aBinary.array(); - Assert.assertEquals(expectedBin.length, binCol.size()); - } - } - - @Override - public StringLongBinary generate(int i) { - StringLongBinary af = new StringLongBinary(); - af.aLong = i; - af.aString = i == 0 ? "A" : null; - af.aBinary = i == 1 ? ByteBuffer.wrap(new byte[2]) : null; - return af; - } - }); - } - - private static void assertEquals(ByteBuffer expected, DirectInputStream actual) { - int sz = (int) actual.size(); - long address = Unsafe.malloc(sz); - try { - long p = address; - actual.copyTo(address, 0, sz); - for (long i = 0; i < sz; i++) { - Assert.assertEquals(expected.get(), Unsafe.getUnsafe().getByte(p++)); - } - } finally { - Unsafe.free(address, sz); - } - } - - private void writeAndReadRecords(JournalWriter journal, int count, int pageSize, RecordGenerator generator) throws IOException, JournalException, ParserException { - try { - for (int i = 0; i < count; i++) { - journal.append(generator.generate(i)); - } - journal.commit(); - - try (RecordList records = new RecordList(journal.getMetadata(), pageSize)) { - LongList offsets = new LongList(); - - try (RecordSource rs = compiler.compile(getFactory(), journal.getLocation().getName())) { - long o = -1; - RecordCursor cursor = rs.prepareCursor(getFactory()); - try { - for (Record rec : cursor) { - offsets.add(o = records.append(rec, o)); - } - } finally { - cursor.releaseCursor(); - } - } - - int i = 0; - records.toTop(); - - while (records.hasNext()) { - generator.assertRecord(records.next(), i++); - } - } - } finally { - journal.close(); - } - } - - private interface RecordGenerator { - void assertRecord(Record value, int i) throws IOException; - - T generate(int i); - } - - private static class LongValue { - long value; - - public LongValue() { - } - - LongValue(long val) { - value = val; - } - } - - private static class AllFieldTypes { - boolean aBool; - String aString; - byte aByte; - short aShort; - int anInt; - ByteBuffer aBinary; - long aLong; - double aDouble; - float aFloat; - } - - private static class Binary { - ByteBuffer aBinary; - } - - private static class StringLongBinary { - String aString; - long aLong; - ByteBuffer aBinary; - } -} \ No newline at end of file diff --git a/core/src/test/java/com/questdb/ql/RenameJournalTest.java b/core/src/test/java/com/questdb/ql/RenameJournalTest.java deleted file mode 100644 index 2648fe92a..000000000 --- a/core/src/test/java/com/questdb/ql/RenameJournalTest.java +++ /dev/null @@ -1,169 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql; - -import com.questdb.ex.ParserException; -import com.questdb.parser.sql.QueryCompiler; -import com.questdb.parser.sql.QueryError; -import com.questdb.std.ex.JournalException; -import com.questdb.std.str.StringSink; -import com.questdb.store.JournalEntryWriter; -import com.questdb.store.JournalKey; -import com.questdb.store.JournalWriter; -import com.questdb.store.factory.Factory; -import com.questdb.test.tools.AbstractTest; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import java.io.IOException; - -public class RenameJournalTest extends AbstractTest { - private static final QueryCompiler compiler = new QueryCompiler(); - - private final StringSink sink = new StringSink(); - private final RecordSourcePrinter printer = new RecordSourcePrinter(sink); - - @Before - public void setUp() { - sink.clear(); - } - - @Test - @SuppressWarnings("unchecked") - public void testJournalAlreadyOpenButIdle() throws Exception { - createX(); - - Factory factory = getFactory(); - assertJournal(factory, "x"); - sink.clear(); - - compiler.execute(factory, "rename table x to y"); - assertJournal(factory, "y"); - - // make sure caching readerFactory doesn't return old journal - try { - factory.reader(new JournalKey("x")); - Assert.fail(); - } catch (JournalException e) { - Assert.assertEquals("Journal does not exist", e.getMessage()); - } - - // make sure compile doesn't pick up old journal - try { - compiler.compile(factory, "x"); - Assert.fail("still exists"); - } catch (ParserException e) { - Assert.assertEquals(0, QueryError.getPosition()); - TestUtils.assertEquals("Journal does not exist", QueryError.getMessage()); - } - - sink.clear(); - createX(); - assertJournal(factory, "x"); - } - - @Test - public void testNonLiteralFrom() throws Exception { - try { - compiler.execute(getFactory(), "rename table 1+2 to 'c d'"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(14, QueryError.getPosition()); - } - } - - @Test - public void testNonLiteralTo() throws Exception { - try { - compiler.execute(getFactory(), "rename table x to 5+5"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(19, QueryError.getPosition()); - } - } - - @Test - public void testReleaseOfJournalInPool() throws Exception { - createX(); - - Factory f = getFactory(); - - assertJournal(f, "x"); - - sink.clear(); - - compiler.execute(f, "rename table x to y"); - assertJournal(f, "y"); - - sink.clear(); - createX(); - assertJournal(f, "x"); - } - - @Test - public void testRenameQuoted() throws Exception { - create("'a b'"); - compiler.execute(getFactory(), "rename table 'a b' to 'c d'"); - } - - @Test - public void testSimpleNonExisting() throws Exception { - try { - compiler.execute(getFactory(), "rename table x to y"); - Assert.fail(); - } catch (ParserException e) { - Assert.assertEquals(13, QueryError.getPosition()); - TestUtils.assertEquals("Journal does not exist", QueryError.getMessage()); - } - } - - @Test - public void testSimpleRename() throws Exception { - createX(); - compiler.execute(getFactory(), "rename table x to y"); - assertJournal(getFactory(), "y"); - } - - private void assertJournal(Factory f, String dest) throws IOException, ParserException { - try (RecordSource rs = compiler.compile(f, dest)) { - printer.print(rs, f); - TestUtils.assertEquals("999\n", sink); - } - } - - private void create(String name) throws JournalException, ParserException { - try (JournalWriter w = compiler.createWriter(getFactory(), "create table " + name + "(a int) record hint 100")) { - JournalEntryWriter ew = w.entryWriter(); - ew.putInt(0, 999); - ew.append(); - w.commit(); - } - } - - private void createX() throws JournalException, ParserException { - create("x"); - } -} diff --git a/core/src/test/java/com/questdb/ql/RoundFunctionsTest.java b/core/src/test/java/com/questdb/ql/RoundFunctionsTest.java deleted file mode 100644 index 789532030..000000000 --- a/core/src/test/java/com/questdb/ql/RoundFunctionsTest.java +++ /dev/null @@ -1,178 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql; - -import org.junit.Test; - -public class RoundFunctionsTest extends AbstractAllTypeTest { - @Test - public void testRoundDown() throws Exception { - assertThat("1.050231933594\t1.050200000000\n" + - "566.734375000000\t566.734300000000\n" + - "0.000013792171\t0.000000000000\n" + - "0.000000567185\t0.000000000000\n" + - "-512.000000000000\t-512.000000000000\n" + - "0.675451681018\t0.675400000000\n" + - "0.332301996648\t0.332300000000\n" + - "0.000001752813\t0.000000000000\n" + - "0.000076281818\t0.000000000000\n" + - "0.000000005555\t0.000000000000\n" + - "0.000002473130\t0.000000000000\n" + - "632.921875000000\t632.921800000000\n" + - "0.000000020896\t0.000000000000\n" + - "0.007371325744\t0.007300000000\n" + - "0.000000014643\t0.000000000000\n" + - "512.000000000000\t512.000000000000\n" + - "864.000000000000\t864.000000000000\n" + - "0.000000157437\t0.000000000000\n" + - "-842.000000000000\t-842.000000000000\n" + - "0.000032060649\t0.000000000000\n", - "select d, roundDown(d, 4) from abc"); - } - - @Test - public void testRoundHalfDown() throws Exception { - assertThat("1.050231933594\t1.050200000000\n" + - "566.734375000000\t566.734400000000\n" + - "0.000013792171\t0.000000000000\n" + - "0.000000567185\t0.000000000000\n" + - "-512.000000000000\t-512.000000000000\n" + - "0.675451681018\t0.675500000000\n" + - "0.332301996648\t0.332300000000\n" + - "0.000001752813\t0.000000000000\n" + - "0.000076281818\t0.000100000000\n" + - "0.000000005555\t0.000000000000\n" + - "0.000002473130\t0.000000000000\n" + - "632.921875000000\t632.921900000000\n" + - "0.000000020896\t0.000000000000\n" + - "0.007371325744\t0.007400000000\n" + - "0.000000014643\t0.000000000000\n" + - "512.000000000000\t512.000000000000\n" + - "864.000000000000\t864.000000000000\n" + - "0.000000157437\t0.000000000000\n" + - "-842.000000000000\t-842.000000000000\n" + - "0.000032060649\t0.000000000000\n", - "select d, roundHalfDown(d,4) from abc"); - } - - @Test - public void testRoundHalfEven() throws Exception { - assertThat("1.050231933594\t1.050200000000\n" + - "566.734375000000\t566.734400000000\n" + - "0.000013792171\t0.000000000000\n" + - "0.000000567185\t0.000000000000\n" + - "-512.000000000000\t-512.000000000000\n" + - "0.675451681018\t0.675500000000\n" + - "0.332301996648\t0.332300000000\n" + - "0.000001752813\t0.000000000000\n" + - "0.000076281818\t0.000100000000\n" + - "0.000000005555\t0.000000000000\n" + - "0.000002473130\t0.000000000000\n" + - "632.921875000000\t632.921900000000\n" + - "0.000000020896\t0.000000000000\n" + - "0.007371325744\t0.007400000000\n" + - "0.000000014643\t0.000000000000\n" + - "512.000000000000\t512.000000000000\n" + - "864.000000000000\t864.000000000000\n" + - "0.000000157437\t0.000000000000\n" + - "-842.000000000000\t-842.000000000000\n" + - "0.000032060649\t0.000000000000\n", - "select d, roundHalfEven(d, 4) from abc"); - } - - @Test - public void testRoundHalfUp() throws Exception { - assertThat("1.050231933594\t1.050230000000\n" + - "566.734375000000\t566.734380000000\n" + - "0.000013792171\t0.000010000000\n" + - "0.000000567185\t0.000000000000\n" + - "-512.000000000000\t-512.000000000000\n" + - "0.675451681018\t0.675450000000\n" + - "0.332301996648\t0.332300000000\n" + - "0.000001752813\t0.000000000000\n" + - "0.000076281818\t0.000080000000\n" + - "0.000000005555\t0.000000000000\n" + - "0.000002473130\t0.000000000000\n" + - "632.921875000000\t632.921880000000\n" + - "0.000000020896\t0.000000000000\n" + - "0.007371325744\t0.007370000000\n" + - "0.000000014643\t0.000000000000\n" + - "512.000000000000\t512.000000000000\n" + - "864.000000000000\t864.000000000000\n" + - "0.000000157437\t0.000000000000\n" + - "-842.000000000000\t-842.000000000000\n" + - "0.000032060649\t0.000030000000\n", - "select d, roundHalfUp(d, 5) from abc"); - } - - @Test - public void testRoundUp() throws Exception { - assertThat("1.050231933594\t1.050232000000\n" + - "566.734375000000\t566.734376000000\n" + - "0.000013792171\t0.000014000000\n" + - "0.000000567185\t0.000001000000\n" + - "-512.000000000000\t-512.000001000000\n" + - "0.675451681018\t0.675452000000\n" + - "0.332301996648\t0.332302000000\n" + - "0.000001752813\t0.000002000000\n" + - "0.000076281818\t0.000077000000\n" + - "0.000000005555\t0.000001000000\n" + - "0.000002473130\t0.000003000000\n" + - "632.921875000000\t632.921876000000\n" + - "0.000000020896\t0.000001000000\n" + - "0.007371325744\t0.007372000000\n" + - "0.000000014643\t0.000001000000\n" + - "512.000000000000\t512.000001000000\n" + - "864.000000000000\t864.000001000000\n" + - "0.000000157437\t0.000001000000\n" + - "-842.000000000000\t-842.000001000000\n" + - "0.000032060649\t0.000033000000\n", - "select d, roundUp(d, 6) from abc"); - } - - @Test - public void testRoundUpInvalidScale() throws Exception { - assertThat("1.050231933594\tNaN\n" + - "566.734375000000\tNaN\n" + - "0.000013792171\tNaN\n" + - "0.000000567185\tNaN\n" + - "-512.000000000000\tNaN\n" + - "0.675451681018\tNaN\n" + - "0.332301996648\tNaN\n" + - "0.000001752813\tNaN\n" + - "0.000076281818\tNaN\n" + - "0.000000005555\tNaN\n" + - "0.000002473130\tNaN\n" + - "632.921875000000\tNaN\n" + - "0.000000020896\tNaN\n" + - "0.007371325744\tNaN\n" + - "0.000000014643\tNaN\n" + - "512.000000000000\tNaN\n" + - "864.000000000000\tNaN\n" + - "0.000000157437\tNaN\n" + - "-842.000000000000\tNaN\n" + - "0.000032060649\tNaN\n", - "select d, roundUp(d, 15) from abc"); - } -} diff --git a/core/src/test/java/com/questdb/ql/SubqueryOptimiserTest.java b/core/src/test/java/com/questdb/ql/SubqueryOptimiserTest.java deleted file mode 100644 index ce9b04f2c..000000000 --- a/core/src/test/java/com/questdb/ql/SubqueryOptimiserTest.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql; - -import com.questdb.ex.ParserException; -import com.questdb.parser.sql.AbstractOptimiserTest; -import com.questdb.parser.sql.QueryError; -import com.questdb.store.JournalWriter; -import com.questdb.store.factory.configuration.JournalStructure; -import com.questdb.test.tools.TestUtils; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class SubqueryOptimiserTest extends AbstractOptimiserTest { - - @BeforeClass - public static void setUpClass() throws Exception { - JournalWriter w = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("tab"). - $sym("id").index().buckets(128). - $double("x"). - $double("y"). - $int("i1"). - $int("i2"). - $ts() - ); - w.close(); - - w = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("tex"). - $sym("id").index().buckets(128). - $double("amount"). - $ts() - ); - - w.close(); - - } - - @Before - public void setUp() { - sink.clear(); - } - - @Test - public void testAmbiguousColumn() { - try { - expectFailure("(((tab order by y) where y = 5) a join tex b on a.id = b.id) a where a.x = 10 and id > 100"); - } catch (ParserException e) { - TestUtils.assertEquals("Ambiguous column name", QueryError.getMessage()); - } - } - - @Test - public void testJoinRecursiveJoinSubQueries() throws Exception { - sink.put(compileSource("(((tab order by y) where y = 5) a join tex b on a.id = b.id) a where a.x = 10 and a.amount > 100")); - TestUtils.assertEquals("{\"op\":\"HashJoinRecordSource\",\"master\":{\"op\":\"RBTreeSortedRecordSource\",\"byRowId\":true,\"src\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"JournalPartitionSource\",\"journal\":\"tab\"},\"rsrc\":{\"op\":\"FilteredRowSource\",\"rsrc\":{\"op\":\"AllRowSource\"}}}},\"slave\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"JournalPartitionSource\",\"journal\":\"tex\"},\"rsrc\":{\"op\":\"FilteredRowSource\",\"rsrc\":{\"op\":\"AllRowSource\"}}},\"joinOn\":[[\"id\"],[\"id\"]]}", - sink); - } - - @Test - public void testJoinSubQueries() throws Exception { - sink.put(compileSource("((tab order by y) a join tex b on a.id = b.id) a where a.x = 10 and a.amount > 100")); - TestUtils.assertEquals("{\"op\":\"HashJoinRecordSource\",\"master\":{\"op\":\"RBTreeSortedRecordSource\",\"byRowId\":true,\"src\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"JournalPartitionSource\",\"journal\":\"tab\"},\"rsrc\":{\"op\":\"FilteredRowSource\",\"rsrc\":{\"op\":\"AllRowSource\"}}}},\"slave\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"JournalPartitionSource\",\"journal\":\"tex\"},\"rsrc\":{\"op\":\"FilteredRowSource\",\"rsrc\":{\"op\":\"AllRowSource\"}}},\"joinOn\":[[\"id\"],[\"id\"]]}", - sink); - } - - @Test - public void testJoinSubQueryFilter() throws Exception { - sink.put(compileSource("(tab a join tex b on a.id = b.id) a where a.x = 10")); - TestUtils.assertEquals("{\"op\":\"HashJoinRecordSource\",\"master\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"JournalPartitionSource\",\"journal\":\"tab\"},\"rsrc\":{\"op\":\"FilteredRowSource\",\"rsrc\":{\"op\":\"AllRowSource\"}}},\"slave\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"JournalPartitionSource\",\"journal\":\"tex\"},\"rsrc\":{\"op\":\"AllRowSource\"}},\"joinOn\":[[\"id\"],[\"id\"]]}", - sink); - } - - @Test - public void testJoinSubQueryFilter2() throws Exception { - sink.put(compileSource("(tab a join tex b on a.id = b.id) a where a.amount = 10")); - TestUtils.assertEquals("{\"op\":\"HashJoinRecordSource\",\"master\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"JournalPartitionSource\",\"journal\":\"tab\"},\"rsrc\":{\"op\":\"AllRowSource\"}},\"slave\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"JournalPartitionSource\",\"journal\":\"tex\"},\"rsrc\":{\"op\":\"FilteredRowSource\",\"rsrc\":{\"op\":\"AllRowSource\"}}},\"joinOn\":[[\"id\"],[\"id\"]]}", - sink); - } - - @Test - public void testOneLevelAliasedSelectedSubQuery() throws Exception { - sink.put(compileSource("(select x from tab order by x) a where a.x = 10")); - TestUtils.assertEquals("{\"op\":\"RBTreeSortedRecordSource\",\"byRowId\":true,\"src\":{\"op\":\"SelectedColumnsRecordSource\",\"src\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"JournalPartitionSource\",\"journal\":\"tab\"},\"rsrc\":{\"op\":\"FilteredRowSource\",\"rsrc\":{\"op\":\"AllRowSource\"}}}}}", - sink); - } - - @Test - public void testOneLevelAliasedSubQuery() throws Exception { - sink.put(compileSource("(tab order by x) a where a.x = 10")); - TestUtils.assertEquals("{\"op\":\"RBTreeSortedRecordSource\",\"byRowId\":true,\"src\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"JournalPartitionSource\",\"journal\":\"tab\"},\"rsrc\":{\"op\":\"FilteredRowSource\",\"rsrc\":{\"op\":\"AllRowSource\"}}}}", - sink); - } - - @Test - public void testOneLevelSimpleSubQuery() throws Exception { - sink.put(compileSource("(tab order by x) where x = 10")); - TestUtils.assertEquals("{\"op\":\"RBTreeSortedRecordSource\",\"byRowId\":true,\"src\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"JournalPartitionSource\",\"journal\":\"tab\"},\"rsrc\":{\"op\":\"FilteredRowSource\",\"rsrc\":{\"op\":\"AllRowSource\"}}}}", - sink); - } - - @Test - public void testRecursiveAliasedMixedSubQuery() throws Exception { - sink.put(compileSource("(select y from (select 1+1 y, x from tab order by x) a where a.x = 10) b where b.y > 100")); - TestUtils.assertEquals("{\"op\":\"SelectedColumnsRecordSource\",\"src\":{\"op\":\"FilteredRecordSource\",\"src\":{\"op\":\"RBTreeSortedRecordSource\",\"byRowId\":true,\"src\":{\"op\":\"SelectedColumnsRecordSource\",\"src\":{\"op\":\"VirtualColumnRecordSource\",\"src\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"JournalPartitionSource\",\"journal\":\"tab\"},\"rsrc\":{\"op\":\"FilteredRowSource\",\"rsrc\":{\"op\":\"AllRowSource\"}}}}}},\"filter\":\"y > 100\"}}", - sink); - } - - @Test - public void testRecursiveAliasedSubQuery() throws Exception { - sink.put(compileSource("((tab order by x) a where a.x = 10) b where b.y > 100")); - TestUtils.assertEquals("{\"op\":\"RBTreeSortedRecordSource\",\"byRowId\":true,\"src\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"JournalPartitionSource\",\"journal\":\"tab\"},\"rsrc\":{\"op\":\"FilteredRowSource\",\"rsrc\":{\"op\":\"AllRowSource\"}}}}", - sink); - } - - @Test - public void testSubQueryFilterOnAggregate() throws Exception { - sink.put(compileSource("(select sum(x) k from tab) a where a.k = 10")); - TestUtils.assertEquals("{\"op\":\"FilteredRecordSource\",\"src\":{\"op\":\"SelectedColumnsRecordSource\",\"src\":{\"op\":\"AggregatedRecordSource\",\"src\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"JournalPartitionSource\",\"journal\":\"tab\"},\"rsrc\":{\"op\":\"AllRowSource\"}}}},\"filter\":\"a.k = 10\"}", - sink); - } - - @Test - public void testSubQueryFilterOnConstant() throws Exception { - sink.put(compileSource("(select 1 k from tab) a where a.k = 10")); - TestUtils.assertEquals("{\"op\":\"FilteredRecordSource\",\"src\":{\"op\":\"SelectedColumnsRecordSource\",\"src\":{\"op\":\"VirtualColumnRecordSource\",\"src\":{\"op\":\"JournalRecordSource\",\"psrc\":{\"op\":\"JournalPartitionSource\",\"journal\":\"tab\"},\"rsrc\":{\"op\":\"AllRowSource\"}}}},\"filter\":\"a.k = 10\"}", - sink); - } -} diff --git a/core/src/test/java/com/questdb/ql/SymbolNullQueryTest.java b/core/src/test/java/com/questdb/ql/SymbolNullQueryTest.java deleted file mode 100644 index 5799f99ff..000000000 --- a/core/src/test/java/com/questdb/ql/SymbolNullQueryTest.java +++ /dev/null @@ -1,610 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql; - -import com.questdb.ex.ParserException; -import com.questdb.parser.sql.AbstractOptimiserTest; -import com.questdb.parser.sql.QueryError; -import com.questdb.std.ObjList; -import com.questdb.std.Rnd; -import com.questdb.std.time.DateFormatUtils; -import com.questdb.store.JournalEntryWriter; -import com.questdb.store.JournalWriter; -import com.questdb.store.factory.configuration.JournalStructure; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -public class SymbolNullQueryTest extends AbstractOptimiserTest { - @BeforeClass - public static void setUp() throws Exception { - - int tradeCount = 100; - int quoteCount = 300; - - JournalWriter trades = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("trades"). - $int("quoteId"). - $sym("tag1"). - $double("amount"). - recordCountHint(tradeCount). - $ts() - ); - - JournalWriter quotes = FACTORY_CONTAINER.getFactory().writer( - new JournalStructure("quotes"). - $int("quoteId"). - $sym("tag"). - $double("rate"). - recordCountHint(quoteCount). - $ts() - ); - - int tsIncrementMax = 10000; - - long timestamp = DateFormatUtils.parseDateTime("2015-03-23T00:00:00.000Z"); - - Rnd rnd = new Rnd(); - ObjList tags = new ObjList<>(); - for (int i = 0; i < 500; i++) { - tags.add(rnd.nextBoolean() ? rnd.nextString(rnd.nextInt() & 15) : null); - } - - for (int i = 0; i < quoteCount; i++) { - JournalEntryWriter w = quotes.entryWriter(); - w.putInt(0, i); - w.putSym(1, tags.getQuick(rnd.nextPositiveInt() % tags.size())); - w.putDouble(2, rnd.nextDouble()); - w.putDate(3, timestamp += rnd.nextPositiveInt() % tsIncrementMax); - w.append(); - } - quotes.commit(); - - - timestamp = DateFormatUtils.parseDateTime("2015-03-23T00:00:00.000Z"); - - for (int i = 0; i < tradeCount; i++) { - JournalEntryWriter w = trades.entryWriter(); - w.putInt(0, rnd.nextPositiveInt() % quoteCount); - w.putSym(1, tags.getQuick(rnd.nextPositiveInt() % tags.size())); - w.putDouble(2, rnd.nextDouble()); - w.putDate(3, timestamp += rnd.nextPositiveInt() % tsIncrementMax); - w.append(); - } - - quotes.close(); - trades.close(); - } - - @Test - public void testAsOfLeftNull() throws Exception { - final String expected = "quoteId\ttag1\tamount\ttimestamp\tquoteId\ttag\trate\ttimestamp\n" + - "167\t\t0.000269699180\t2015-03-23T00:00:00.041Z\tNaN\t\tNaN\t\n" + - "185\t\t320.000000000000\t2015-03-23T00:00:03.905Z\t0\t\t1.803355813026\t2015-03-23T00:00:00.213Z\n" + - "208\t\t0.000283450820\t2015-03-23T00:00:09.777Z\t1\t\t0.000070708433\t2015-03-23T00:00:06.860Z\n" + - "253\t\t0.000006260114\t2015-03-23T00:00:14.319Z\t4\t\t0.000000004546\t2015-03-23T00:00:13.174Z\n" + - "280\t\t0.000001666620\t2015-03-23T00:00:21.324Z\tNaN\t\tNaN\t\n" + - "250\t\t391.318801879883\t2015-03-23T00:00:38.605Z\t9\tVQ\t-453.500000000000\t2015-03-23T00:00:37.483Z\n" + - "189\t\t638.125000000000\t2015-03-23T00:00:54.293Z\t13\t\t367.500000000000\t2015-03-23T00:00:53.663Z\n" + - "79\t\t0.000000003843\t2015-03-23T00:01:00.686Z\tNaN\t\tNaN\t\n" + - "160\t\t-804.000000000000\t2015-03-23T00:01:22.281Z\t17\t\t0.000010729342\t2015-03-23T00:01:16.171Z\n" + - "146\t\t114.411033630371\t2015-03-23T00:01:35.805Z\t20\tVPPLIPRMDB\t-512.000000000000\t2015-03-23T00:01:31.409Z\n" + - "275\t\t0.000000135166\t2015-03-23T00:01:46.298Z\t26\t\t227.781250000000\t2015-03-23T00:01:45.081Z\n" + - "38\t\t0.000006406346\t2015-03-23T00:01:51.405Z\t27\t\t-881.312500000000\t2015-03-23T00:01:50.570Z\n" + - "174\t\t0.003814977244\t2015-03-23T00:01:54.120Z\t28\tMCGFNWGRMDGGI\t0.018065215554\t2015-03-23T00:01:52.498Z\n" + - "32\t\t0.000000000000\t2015-03-23T00:02:33.565Z\t33\tWZNF\t389.500000000000\t2015-03-23T00:02:27.245Z\n" + - "25\t\t0.000000521190\t2015-03-23T00:02:38.743Z\t35\tBKFIJZZYNPP\t1.767193734646\t2015-03-23T00:02:38.532Z\n" + - "247\t\t1.480640053749\t2015-03-23T00:03:05.144Z\t40\tBJFRPX\t3.300331056118\t2015-03-23T00:03:01.677Z\n" + - "11\t\t0.000000837886\t2015-03-23T00:03:12.568Z\t41\tNRXGZSXUX\t-429.100708007813\t2015-03-23T00:03:08.533Z\n" + - "242\t\t-448.687500000000\t2015-03-23T00:03:18.692Z\t43\t\t7.534469366074\t2015-03-23T00:03:18.528Z\n" + - "125\t\t384.000000000000\t2015-03-23T00:03:24.655Z\tNaN\t\tNaN\t\n" + - "38\t\t0.000000042007\t2015-03-23T00:03:56.155Z\t53\t\t-129.359375000000\t2015-03-23T00:03:55.883Z\n" + - "61\t\t0.002688131004\t2015-03-23T00:03:59.991Z\t55\t\t260.000000000000\t2015-03-23T00:03:58.594Z\n" + - "135\t\t11.436011791229\t2015-03-23T00:04:15.031Z\t57\t\t0.023898910731\t2015-03-23T00:04:09.740Z\n" + - "67\t\t0.000000017864\t2015-03-23T00:04:25.683Z\t59\t\t67.070381164551\t2015-03-23T00:04:23.097Z\n" + - "5\t\t0.001699611719\t2015-03-23T00:04:32.638Z\t60\t\t0.000019430104\t2015-03-23T00:04:26.550Z\n" + - "197\t\t-639.687500000000\t2015-03-23T00:04:34.193Z\tNaN\t\tNaN\t\n" + - "295\t\t3.262981295586\t2015-03-23T00:04:39.143Z\t61\tBKFIJZZYNPP\t97.859756469727\t2015-03-23T00:04:34.967Z\n" + - "11\t\t1.727517306805\t2015-03-23T00:04:52.639Z\t63\t\t74.151687622070\t2015-03-23T00:04:47.655Z\n" + - "47\t\t673.375000000000\t2015-03-23T00:04:56.064Z\t64\tQOLYXWCKYLSUWD\t-965.125000000000\t2015-03-23T00:04:55.914Z\n" + - "97\t\t0.000031514332\t2015-03-23T00:05:04.467Z\t66\tKXPMSXQ\t0.000044817871\t2015-03-23T00:05:01.550Z\n" + - "52\t\t-982.250000000000\t2015-03-23T00:05:06.948Z\t67\tGSVCLLERSM\t214.940444946289\t2015-03-23T00:05:05.637Z\n" + - "101\t\t0.085098911077\t2015-03-23T00:05:07.455Z\t68\t\t0.374871194363\t2015-03-23T00:05:07.144Z\n" + - "204\t\t-864.000000000000\t2015-03-23T00:05:14.905Z\t70\tQG\t0.417922869325\t2015-03-23T00:05:12.520Z\n" + - "157\t\t0.000000038206\t2015-03-23T00:05:24.607Z\t73\t\t-941.475097656250\t2015-03-23T00:05:24.096Z\n" + - "27\t\t0.128199812025\t2015-03-23T00:05:30.349Z\tNaN\t\tNaN\t\n" + - "294\t\t32.320184707642\t2015-03-23T00:05:35.452Z\t75\t\t0.112449161708\t2015-03-23T00:05:34.377Z\n" + - "175\t\t0.000000096432\t2015-03-23T00:05:37.064Z\tNaN\t\tNaN\t\n" + - "140\t\t-384.000000000000\t2015-03-23T00:05:40.901Z\tNaN\t\tNaN\t\n" + - "118\t\t-768.000000000000\t2015-03-23T00:05:50.089Z\t78\t\t0.000000443235\t2015-03-23T00:05:48.820Z\n" + - "88\t\t0.000019480709\t2015-03-23T00:05:50.803Z\tNaN\t\tNaN\t\n" + - "221\t\t-308.000000000000\t2015-03-23T00:05:54.120Z\tNaN\t\tNaN\t\n" + - "214\t\t-1024.000000000000\t2015-03-23T00:06:00.720Z\t80\tFFLTRYZUZYJ\t-1024.000000000000\t2015-03-23T00:05:59.140Z\n" + - "278\t\t100.157985687256\t2015-03-23T00:06:06.542Z\t81\t\t-116.000000000000\t2015-03-23T00:06:06.359Z\n" + - "61\t\t-1024.000000000000\t2015-03-23T00:06:08.793Z\tNaN\t\tNaN\t\n" + - "180\t\t0.223312780261\t2015-03-23T00:06:10.929Z\tNaN\t\tNaN\t\n" + - "94\t\t0.000006785318\t2015-03-23T00:06:15.648Z\t84\t\t0.000000001883\t2015-03-23T00:06:13.867Z\n" + - "242\t\t-557.027343750000\t2015-03-23T00:06:24.968Z\t85\t\t0.000000042277\t2015-03-23T00:06:21.010Z\n" + - "68\t\t0.000000001771\t2015-03-23T00:06:26.396Z\tNaN\t\tNaN\t\n" + - "64\t\t-512.546875000000\t2015-03-23T00:06:26.865Z\tNaN\t\tNaN\t\n" + - "41\t\t0.000001296927\t2015-03-23T00:06:34.398Z\t87\t\t0.000199647140\t2015-03-23T00:06:28.009Z\n" + - "40\t\t0.352436579764\t2015-03-23T00:06:44.446Z\t88\tONWE\t0.000125047416\t2015-03-23T00:06:36.408Z\n" + - "127\t\t0.000750448322\t2015-03-23T00:07:07.023Z\t94\tNKG\t0.000032506398\t2015-03-23T00:07:06.427Z\n" + - "284\t\t0.000000056363\t2015-03-23T00:07:24.963Z\t100\tKRGIIHY\t0.000000004512\t2015-03-23T00:07:22.960Z\n" + - "69\t\t-64.000000000000\t2015-03-23T00:07:32.794Z\t102\t\t21.335580825806\t2015-03-23T00:07:28.848Z\n" + - "206\t\t0.000001646644\t2015-03-23T00:07:40.787Z\t103\t\t89.232910156250\t2015-03-23T00:07:38.365Z\n" + - "110\t\t882.590759277344\t2015-03-23T00:07:44.604Z\tNaN\t\tNaN\t\n" + - "208\t\t0.000000045985\t2015-03-23T00:07:48.156Z\t104\t\t-512.000000000000\t2015-03-23T00:07:45.981Z\n" + - "287\t\t-732.302734375000\t2015-03-23T00:07:54.893Z\t105\tDWWLEVMLKCJBEVL\t0.000000012333\t2015-03-23T00:07:48.554Z\n" + - "208\t\t0.000000447563\t2015-03-23T00:08:04.779Z\t107\t\t0.006601167843\t2015-03-23T00:07:58.974Z\n" + - "190\t\t0.000000005669\t2015-03-23T00:08:10.452Z\t108\tVPPLIPRMDB\t0.003471667413\t2015-03-23T00:08:06.561Z\n" + - "266\t\t0.000002058839\t2015-03-23T00:08:14.465Z\tNaN\t\tNaN\t\n" + - "15\t\t0.000000004841\t2015-03-23T00:08:23.335Z\t111\tRZUPVQFULM\t0.000000017550\t2015-03-23T00:08:22.158Z\n"; - assertThat(expected, "trades t asof join quotes q where tag1 = null", true); - assertThat(expected, "trades t asof join quotes q where null = tag1", true); - } - - @Test - public void testAsOfPartitionedJoinLeftNull() throws Exception { - final String expected = "quoteId\ttag1\tamount\ttimestamp\tquoteId\ttag\trate\ttimestamp\n" + - "167\t\t0.000269699180\t2015-03-23T00:00:00.041Z\tNaN\t\tNaN\t\n" + - "185\t\t320.000000000000\t2015-03-23T00:00:03.905Z\tNaN\t\tNaN\t\n" + - "208\t\t0.000283450820\t2015-03-23T00:00:09.777Z\tNaN\t\tNaN\t\n" + - "253\t\t0.000006260114\t2015-03-23T00:00:14.319Z\tNaN\t\tNaN\t\n" + - "280\t\t0.000001666620\t2015-03-23T00:00:21.324Z\tNaN\t\tNaN\t\n" + - "250\t\t391.318801879883\t2015-03-23T00:00:38.605Z\tNaN\t\tNaN\t\n" + - "189\t\t638.125000000000\t2015-03-23T00:00:54.293Z\tNaN\t\tNaN\t\n" + - "79\t\t0.000000003843\t2015-03-23T00:01:00.686Z\tNaN\t\tNaN\t\n" + - "160\t\t-804.000000000000\t2015-03-23T00:01:22.281Z\tNaN\t\tNaN\t\n" + - "146\t\t114.411033630371\t2015-03-23T00:01:35.805Z\tNaN\t\tNaN\t\n" + - "275\t\t0.000000135166\t2015-03-23T00:01:46.298Z\tNaN\t\tNaN\t\n" + - "38\t\t0.000006406346\t2015-03-23T00:01:51.405Z\tNaN\t\tNaN\t\n" + - "174\t\t0.003814977244\t2015-03-23T00:01:54.120Z\tNaN\t\tNaN\t\n" + - "32\t\t0.000000000000\t2015-03-23T00:02:33.565Z\t32\tFORGFIEVM\t0.000000013271\t2015-03-23T00:02:19.770Z\n" + - "25\t\t0.000000521190\t2015-03-23T00:02:38.743Z\t25\t\t-1024.000000000000\t2015-03-23T00:01:41.578Z\n" + - "247\t\t1.480640053749\t2015-03-23T00:03:05.144Z\tNaN\t\tNaN\t\n" + - "11\t\t0.000000837886\t2015-03-23T00:03:12.568Z\t11\t\t109.844512939453\t2015-03-23T00:00:52.378Z\n" + - "242\t\t-448.687500000000\t2015-03-23T00:03:18.692Z\tNaN\t\tNaN\t\n" + - "125\t\t384.000000000000\t2015-03-23T00:03:24.655Z\tNaN\t\tNaN\t\n" + - "38\t\t0.000000042007\t2015-03-23T00:03:56.155Z\t38\t\t88.440750122070\t2015-03-23T00:02:48.897Z\n" + - "61\t\t0.002688131004\t2015-03-23T00:03:59.991Z\tNaN\t\tNaN\t\n" + - "135\t\t11.436011791229\t2015-03-23T00:04:15.031Z\tNaN\t\tNaN\t\n" + - "67\t\t0.000000017864\t2015-03-23T00:04:25.683Z\tNaN\t\tNaN\t\n" + - "5\t\t0.001699611719\t2015-03-23T00:04:32.638Z\t5\tNEJRMDIKDISGQ\t0.000017155876\t2015-03-23T00:00:21.617Z\n" + - "197\t\t-639.687500000000\t2015-03-23T00:04:34.193Z\tNaN\t\tNaN\t\n" + - "295\t\t3.262981295586\t2015-03-23T00:04:39.143Z\tNaN\t\tNaN\t\n" + - "11\t\t1.727517306805\t2015-03-23T00:04:52.639Z\tNaN\t\tNaN\t\n" + - "47\t\t673.375000000000\t2015-03-23T00:04:56.064Z\t47\tRHHMGZJYYFLS\t0.005148356780\t2015-03-23T00:03:29.150Z\n" + - "97\t\t0.000031514332\t2015-03-23T00:05:04.467Z\tNaN\t\tNaN\t\n" + - "52\t\t-982.250000000000\t2015-03-23T00:05:06.948Z\t52\tX\t0.000004397260\t2015-03-23T00:03:52.621Z\n" + - "101\t\t0.085098911077\t2015-03-23T00:05:07.455Z\tNaN\t\tNaN\t\n" + - "204\t\t-864.000000000000\t2015-03-23T00:05:14.905Z\tNaN\t\tNaN\t\n" + - "157\t\t0.000000038206\t2015-03-23T00:05:24.607Z\tNaN\t\tNaN\t\n" + - "27\t\t0.128199812025\t2015-03-23T00:05:30.349Z\tNaN\t\tNaN\t\n" + - "294\t\t32.320184707642\t2015-03-23T00:05:35.452Z\tNaN\t\tNaN\t\n" + - "175\t\t0.000000096432\t2015-03-23T00:05:37.064Z\tNaN\t\tNaN\t\n" + - "140\t\t-384.000000000000\t2015-03-23T00:05:40.901Z\tNaN\t\tNaN\t\n" + - "118\t\t-768.000000000000\t2015-03-23T00:05:50.089Z\tNaN\t\tNaN\t\n" + - "88\t\t0.000019480709\t2015-03-23T00:05:50.803Z\tNaN\t\tNaN\t\n" + - "221\t\t-308.000000000000\t2015-03-23T00:05:54.120Z\tNaN\t\tNaN\t\n" + - "214\t\t-1024.000000000000\t2015-03-23T00:06:00.720Z\tNaN\t\tNaN\t\n" + - "278\t\t100.157985687256\t2015-03-23T00:06:06.542Z\tNaN\t\tNaN\t\n" + - "61\t\t-1024.000000000000\t2015-03-23T00:06:08.793Z\tNaN\t\tNaN\t\n" + - "180\t\t0.223312780261\t2015-03-23T00:06:10.929Z\tNaN\t\tNaN\t\n" + - "94\t\t0.000006785318\t2015-03-23T00:06:15.648Z\tNaN\t\tNaN\t\n" + - "242\t\t-557.027343750000\t2015-03-23T00:06:24.968Z\tNaN\t\tNaN\t\n" + - "68\t\t0.000000001771\t2015-03-23T00:06:26.396Z\tNaN\t\tNaN\t\n" + - "64\t\t-512.546875000000\t2015-03-23T00:06:26.865Z\tNaN\t\tNaN\t\n" + - "41\t\t0.000001296927\t2015-03-23T00:06:34.398Z\t41\tNRXGZSXUX\t-429.100708007813\t2015-03-23T00:03:08.533Z\n" + - "40\t\t0.352436579764\t2015-03-23T00:06:44.446Z\t40\tBJFRPX\t3.300331056118\t2015-03-23T00:03:01.677Z\n" + - "127\t\t0.000750448322\t2015-03-23T00:07:07.023Z\tNaN\t\tNaN\t\n" + - "284\t\t0.000000056363\t2015-03-23T00:07:24.963Z\tNaN\t\tNaN\t\n" + - "69\t\t-64.000000000000\t2015-03-23T00:07:32.794Z\t69\t\t0.000000001976\t2015-03-23T00:05:12.110Z\n" + - "206\t\t0.000001646644\t2015-03-23T00:07:40.787Z\tNaN\t\tNaN\t\n" + - "110\t\t882.590759277344\t2015-03-23T00:07:44.604Z\tNaN\t\tNaN\t\n" + - "208\t\t0.000000045985\t2015-03-23T00:07:48.156Z\tNaN\t\tNaN\t\n" + - "287\t\t-732.302734375000\t2015-03-23T00:07:54.893Z\tNaN\t\tNaN\t\n" + - "208\t\t0.000000447563\t2015-03-23T00:08:04.779Z\tNaN\t\tNaN\t\n" + - "190\t\t0.000000005669\t2015-03-23T00:08:10.452Z\tNaN\t\tNaN\t\n" + - "266\t\t0.000002058839\t2015-03-23T00:08:14.465Z\tNaN\t\tNaN\t\n" + - "15\t\t0.000000004841\t2015-03-23T00:08:23.335Z\t15\tMYICCXZOUIC\t-504.062500000000\t2015-03-23T00:01:09.396Z\n"; - - assertThat(expected, "trades t asof join quotes q on t.quoteId = q.quoteId where tag1 = null", true); - assertThat(expected, "trades t asof join quotes q on t.quoteId = q.quoteId where null = tag1", true); - } - - @Test - public void testAsOfPartitionedJoinRightNull() throws Exception { - final String expected = "quoteId\ttag1\tamount\ttimestamp\tquoteId\ttag\trate\ttimestamp\n" + - "167\t\t0.000269699180\t2015-03-23T00:00:00.041Z\tNaN\t\tNaN\t\n" + - "185\t\t320.000000000000\t2015-03-23T00:00:03.905Z\tNaN\t\tNaN\t\n" + - "208\t\t0.000283450820\t2015-03-23T00:00:09.777Z\tNaN\t\tNaN\t\n" + - "253\t\t0.000006260114\t2015-03-23T00:00:14.319Z\tNaN\t\tNaN\t\n" + - "280\t\t0.000001666620\t2015-03-23T00:00:21.324Z\tNaN\t\tNaN\t\n" + - "62\tUUQIDLVBVKH\t-655.093750000000\t2015-03-23T00:00:26.965Z\tNaN\t\tNaN\t\n" + - "159\tOJIGFINKGQVZ\t52.300781250000\t2015-03-23T00:00:31.747Z\tNaN\t\tNaN\t\n" + - "250\t\t391.318801879883\t2015-03-23T00:00:38.605Z\tNaN\t\tNaN\t\n" + - "236\tQDSRDJWIMGPLRQU\t0.559725582600\t2015-03-23T00:00:46.696Z\tNaN\t\tNaN\t\n" + - "189\t\t638.125000000000\t2015-03-23T00:00:54.293Z\tNaN\t\tNaN\t\n" + - "206\tDDBHEVGXY\t0.000000983339\t2015-03-23T00:00:54.651Z\tNaN\t\tNaN\t\n" + - "79\t\t0.000000003843\t2015-03-23T00:01:00.686Z\tNaN\t\tNaN\t\n" + - "98\tI\t0.095442861319\t2015-03-23T00:01:08.481Z\tNaN\t\tNaN\t\n" + - "160\t\t-804.000000000000\t2015-03-23T00:01:22.281Z\tNaN\t\tNaN\t\n" + - "114\tFCKDHBQJPLXZGC\t295.336006164551\t2015-03-23T00:01:26.844Z\tNaN\t\tNaN\t\n" + - "146\t\t114.411033630371\t2015-03-23T00:01:35.805Z\tNaN\t\tNaN\t\n" + - "32\tUHNBCCPM\t28.844047546387\t2015-03-23T00:01:39.759Z\tNaN\t\tNaN\t\n" + - "275\t\t0.000000135166\t2015-03-23T00:01:46.298Z\tNaN\t\tNaN\t\n" + - "38\t\t0.000006406346\t2015-03-23T00:01:51.405Z\tNaN\t\tNaN\t\n" + - "174\t\t0.003814977244\t2015-03-23T00:01:54.120Z\tNaN\t\tNaN\t\n" + - "279\tREIJ\t0.001741334971\t2015-03-23T00:02:02.280Z\tNaN\t\tNaN\t\n" + - "83\tTYLHXVPGHPSF\t-768.000000000000\t2015-03-23T00:02:10.007Z\tNaN\t\tNaN\t\n" + - "164\tZWWCCNGTNLEGPUH\t0.000006020679\t2015-03-23T00:02:19.093Z\tNaN\t\tNaN\t\n" + - "178\tQDSRDJWIMGPLRQU\t-482.000000000000\t2015-03-23T00:02:21.866Z\tNaN\t\tNaN\t\n" + - "17\tIOVIKJS\t1.924843549728\t2015-03-23T00:02:24.538Z\tNaN\t\tNaN\t\n" + - "25\t\t0.000000521190\t2015-03-23T00:02:38.743Z\t25\t\t-1024.000000000000\t2015-03-23T00:01:41.578Z\n" + - "233\tV\t0.000000017818\t2015-03-23T00:02:43.116Z\tNaN\t\tNaN\t\n" + - "112\tUVV\t979.898437500000\t2015-03-23T00:02:49.249Z\tNaN\t\tNaN\t\n" + - "295\tJYED\t881.624389648438\t2015-03-23T00:02:58.778Z\tNaN\t\tNaN\t\n" + - "247\t\t1.480640053749\t2015-03-23T00:03:05.144Z\tNaN\t\tNaN\t\n" + - "188\tMDJTHMHZNV\t128.000000000000\t2015-03-23T00:03:11.761Z\tNaN\t\tNaN\t\n" + - "11\t\t0.000000837886\t2015-03-23T00:03:12.568Z\tNaN\t\tNaN\t\n" + - "242\t\t-448.687500000000\t2015-03-23T00:03:18.692Z\tNaN\t\tNaN\t\n" + - "125\t\t384.000000000000\t2015-03-23T00:03:24.655Z\tNaN\t\tNaN\t\n" + - "272\tOSBOS\t911.400665283203\t2015-03-23T00:03:34.502Z\tNaN\t\tNaN\t\n" + - "13\tUMEUKVZI\t976.000000000000\t2015-03-23T00:03:48.769Z\t13\t\t367.500000000000\t2015-03-23T00:00:53.663Z\n" + - "38\t\t0.000000042007\t2015-03-23T00:03:56.155Z\t38\t\t88.440750122070\t2015-03-23T00:02:48.897Z\n" + - "61\t\t0.002688131004\t2015-03-23T00:03:59.991Z\tNaN\t\tNaN\t\n" + - "217\tDWWLEVMLKCJBEVL\t-871.023925781250\t2015-03-23T00:04:05.708Z\tNaN\t\tNaN\t\n" + - "135\t\t11.436011791229\t2015-03-23T00:04:15.031Z\tNaN\t\tNaN\t\n" + - "230\tRZUPVQFULM\t10.552783966064\t2015-03-23T00:04:23.609Z\tNaN\t\tNaN\t\n" + - "67\t\t0.000000017864\t2015-03-23T00:04:25.683Z\tNaN\t\tNaN\t\n" + - "200\tCJOU\t0.000000498588\t2015-03-23T00:04:30.988Z\tNaN\t\tNaN\t\n" + - "5\t\t0.001699611719\t2015-03-23T00:04:32.638Z\tNaN\t\tNaN\t\n" + - "197\t\t-639.687500000000\t2015-03-23T00:04:34.193Z\tNaN\t\tNaN\t\n" + - "295\t\t3.262981295586\t2015-03-23T00:04:39.143Z\tNaN\t\tNaN\t\n" + - "11\t\t1.727517306805\t2015-03-23T00:04:52.639Z\t11\t\t109.844512939453\t2015-03-23T00:00:52.378Z\n" + - "97\t\t0.000031514332\t2015-03-23T00:05:04.467Z\tNaN\t\tNaN\t\n" + - "101\t\t0.085098911077\t2015-03-23T00:05:07.455Z\tNaN\t\tNaN\t\n" + - "245\tUVDRHF\t152.633743286133\t2015-03-23T00:05:12.773Z\tNaN\t\tNaN\t\n" + - "204\t\t-864.000000000000\t2015-03-23T00:05:14.905Z\tNaN\t\tNaN\t\n" + - "157\t\t0.000000038206\t2015-03-23T00:05:24.607Z\tNaN\t\tNaN\t\n" + - "27\t\t0.128199812025\t2015-03-23T00:05:30.349Z\tNaN\t\tNaN\t\n" + - "294\t\t32.320184707642\t2015-03-23T00:05:35.452Z\tNaN\t\tNaN\t\n" + - "145\tPHNIMYFFDTNP\t0.000007616574\t2015-03-23T00:05:36.249Z\tNaN\t\tNaN\t\n" + - "175\t\t0.000000096432\t2015-03-23T00:05:37.064Z\tNaN\t\tNaN\t\n" + - "140\t\t-384.000000000000\t2015-03-23T00:05:40.901Z\tNaN\t\tNaN\t\n" + - "118\t\t-768.000000000000\t2015-03-23T00:05:50.089Z\tNaN\t\tNaN\t\n" + - "88\t\t0.000019480709\t2015-03-23T00:05:50.803Z\tNaN\t\tNaN\t\n" + - "209\tRIIYMHO\t0.036849732511\t2015-03-23T00:05:50.822Z\tNaN\t\tNaN\t\n" + - "221\t\t-308.000000000000\t2015-03-23T00:05:54.120Z\tNaN\t\tNaN\t\n" + - "214\t\t-1024.000000000000\t2015-03-23T00:06:00.720Z\tNaN\t\tNaN\t\n" + - "278\t\t100.157985687256\t2015-03-23T00:06:06.542Z\tNaN\t\tNaN\t\n" + - "219\tSBEOUOJSHRU\t0.007685951889\t2015-03-23T00:06:06.860Z\tNaN\t\tNaN\t\n" + - "61\t\t-1024.000000000000\t2015-03-23T00:06:08.793Z\tNaN\t\tNaN\t\n" + - "180\t\t0.223312780261\t2015-03-23T00:06:10.929Z\tNaN\t\tNaN\t\n" + - "94\t\t0.000006785318\t2015-03-23T00:06:15.648Z\tNaN\t\tNaN\t\n" + - "240\tPNHTDCEBYWXB\t0.000000007430\t2015-03-23T00:06:23.214Z\tNaN\t\tNaN\t\n" + - "242\t\t-557.027343750000\t2015-03-23T00:06:24.968Z\tNaN\t\tNaN\t\n" + - "68\t\t0.000000001771\t2015-03-23T00:06:26.396Z\tNaN\t\tNaN\t\n" + - "64\t\t-512.546875000000\t2015-03-23T00:06:26.865Z\tNaN\t\tNaN\t\n" + - "101\t\t0.003191990079\t2015-03-23T00:06:38.252Z\tNaN\t\tNaN\t\n" + - "32\tSIMYDXUUSKCX\t0.091201189905\t2015-03-23T00:06:42.748Z\tNaN\t\tNaN\t\n" + - "40\t\t0.352436579764\t2015-03-23T00:06:44.446Z\tNaN\t\tNaN\t\n" + - "279\tNEJRMDIKDISGQ\t-186.680175781250\t2015-03-23T00:06:50.222Z\tNaN\t\tNaN\t\n" + - "238\tSED\t0.000000019996\t2015-03-23T00:06:58.896Z\tNaN\t\tNaN\t\n" + - "127\t\t0.000750448322\t2015-03-23T00:07:07.023Z\tNaN\t\tNaN\t\n" + - "277\tIGENFELWWRSLBM\t-305.000000000000\t2015-03-23T00:07:16.365Z\tNaN\t\tNaN\t\n" + - "284\t\t0.000000056363\t2015-03-23T00:07:24.963Z\tNaN\t\tNaN\t\n" + - "69\t\t-64.000000000000\t2015-03-23T00:07:32.794Z\t69\t\t0.000000001976\t2015-03-23T00:05:12.110Z\n" + - "206\t\t0.000001646644\t2015-03-23T00:07:40.787Z\tNaN\t\tNaN\t\n" + - "2\tVQ\t0.000000002305\t2015-03-23T00:07:43.087Z\tNaN\t\tNaN\t\n" + - "110\t\t882.590759277344\t2015-03-23T00:07:44.604Z\tNaN\t\tNaN\t\n" + - "208\t\t0.000000045985\t2015-03-23T00:07:48.156Z\tNaN\t\tNaN\t\n" + - "287\t\t-732.302734375000\t2015-03-23T00:07:54.893Z\tNaN\t\tNaN\t\n" + - "81\tGK\t0.000279274151\t2015-03-23T00:07:54.905Z\tNaN\t\tNaN\t\n" + - "208\t\t0.000000447563\t2015-03-23T00:08:04.779Z\tNaN\t\tNaN\t\n" + - "190\t\t0.000000005669\t2015-03-23T00:08:10.452Z\tNaN\t\tNaN\t\n" + - "266\t\t0.000002058839\t2015-03-23T00:08:14.465Z\tNaN\t\tNaN\t\n" + - "270\tUDVIK\t0.000000391720\t2015-03-23T00:08:17.846Z\tNaN\t\tNaN\t\n" + - "24\tSVTN\t123.810607910156\t2015-03-23T00:08:20.910Z\tNaN\t\tNaN\t\n" + - "216\tZUFEV\t0.000000036476\t2015-03-23T00:08:23.335Z\tNaN\t\tNaN\t\n" + - "15\t\t0.000000004841\t2015-03-23T00:08:23.335Z\tNaN\t\tNaN\t\n"; - assertThat(expected, "trades t asof join quotes q on t.quoteId = q.quoteId where tag = null", true); - assertThat(expected, "trades t asof join quotes q on t.quoteId = q.quoteId where null = tag", true); - } - - @Test - public void testAsOfRightNull() throws Exception { - final String expected = "quoteId\ttag1\tamount\ttimestamp\tquoteId\ttag\trate\ttimestamp\n" + - "167\t\t0.000269699180\t2015-03-23T00:00:00.041Z\tNaN\t\tNaN\t\n" + - "185\t\t320.000000000000\t2015-03-23T00:00:03.905Z\t0\t\t1.803355813026\t2015-03-23T00:00:00.213Z\n" + - "208\t\t0.000283450820\t2015-03-23T00:00:09.777Z\t1\t\t0.000070708433\t2015-03-23T00:00:06.860Z\n" + - "253\t\t0.000006260114\t2015-03-23T00:00:14.319Z\t4\t\t0.000000004546\t2015-03-23T00:00:13.174Z\n" + - "280\t\t0.000001666620\t2015-03-23T00:00:21.324Z\tNaN\t\tNaN\t\n" + - "62\tUUQIDLVBVKH\t-655.093750000000\t2015-03-23T00:00:26.965Z\t7\t\t279.477539062500\t2015-03-23T00:00:24.224Z\n" + - "159\tOJIGFINKGQVZ\t52.300781250000\t2015-03-23T00:00:31.747Z\t8\t\t0.069348402321\t2015-03-23T00:00:30.911Z\n" + - "236\tQDSRDJWIMGPLRQU\t0.559725582600\t2015-03-23T00:00:46.696Z\t10\t\t0.039842596278\t2015-03-23T00:00:43.910Z\n" + - "189\t\t638.125000000000\t2015-03-23T00:00:54.293Z\t13\t\t367.500000000000\t2015-03-23T00:00:53.663Z\n" + - "206\tDDBHEVGXY\t0.000000983339\t2015-03-23T00:00:54.651Z\tNaN\t\tNaN\t\n" + - "79\t\t0.000000003843\t2015-03-23T00:01:00.686Z\tNaN\t\tNaN\t\n" + - "98\tI\t0.095442861319\t2015-03-23T00:01:08.481Z\t14\t\t552.000000000000\t2015-03-23T00:01:03.502Z\n" + - "15\t\t0.013024759479\t2015-03-23T00:01:17.114Z\t17\t\t0.000010729342\t2015-03-23T00:01:16.171Z\n" + - "160\t\t-804.000000000000\t2015-03-23T00:01:22.281Z\tNaN\t\tNaN\t\n" + - "275\t\t0.000000135166\t2015-03-23T00:01:46.298Z\t26\t\t227.781250000000\t2015-03-23T00:01:45.081Z\n" + - "38\t\t0.000006406346\t2015-03-23T00:01:51.405Z\t27\t\t-881.312500000000\t2015-03-23T00:01:50.570Z\n" + - "164\tZWWCCNGTNLEGPUH\t0.000006020679\t2015-03-23T00:02:19.093Z\t31\t\t17.086778640747\t2015-03-23T00:02:12.621Z\n" + - "17\tIOVIKJS\t1.924843549728\t2015-03-23T00:02:24.538Z\tNaN\t\tNaN\t\n" + - "233\tV\t0.000000017818\t2015-03-23T00:02:43.116Z\t36\t\t0.000040406951\t2015-03-23T00:02:41.818Z\n" + - "112\tUVV\t979.898437500000\t2015-03-23T00:02:49.249Z\t38\t\t88.440750122070\t2015-03-23T00:02:48.897Z\n" + - "295\tJYED\t881.624389648438\t2015-03-23T00:02:58.778Z\t39\t\t0.001135725528\t2015-03-23T00:02:54.956Z\n" + - "11\t\t0.000000837886\t2015-03-23T00:03:12.568Z\tNaN\t\tNaN\t\n" + - "242\t\t-448.687500000000\t2015-03-23T00:03:18.692Z\t43\t\t7.534469366074\t2015-03-23T00:03:18.528Z\n" + - "125\t\t384.000000000000\t2015-03-23T00:03:24.655Z\tNaN\t\tNaN\t\n" + - "37\t\t0.000000000000\t2015-03-23T00:03:40.522Z\t49\t\t0.003723925911\t2015-03-23T00:03:37.137Z\n" + - "38\t\t0.000000042007\t2015-03-23T00:03:56.155Z\t53\t\t-129.359375000000\t2015-03-23T00:03:55.883Z\n" + - "61\t\t0.002688131004\t2015-03-23T00:03:59.991Z\t55\t\t260.000000000000\t2015-03-23T00:03:58.594Z\n" + - "217\tDWWLEVMLKCJBEVL\t-871.023925781250\t2015-03-23T00:04:05.708Z\tNaN\t\tNaN\t\n" + - "135\t\t11.436011791229\t2015-03-23T00:04:15.031Z\t57\t\t0.023898910731\t2015-03-23T00:04:09.740Z\n" + - "230\tRZUPVQFULM\t10.552783966064\t2015-03-23T00:04:23.609Z\t59\t\t67.070381164551\t2015-03-23T00:04:23.097Z\n" + - "67\t\t0.000000017864\t2015-03-23T00:04:25.683Z\tNaN\t\tNaN\t\n" + - "200\tCJOU\t0.000000498588\t2015-03-23T00:04:30.988Z\t60\t\t0.000019430104\t2015-03-23T00:04:26.550Z\n" + - "5\t\t0.001699611719\t2015-03-23T00:04:32.638Z\tNaN\t\tNaN\t\n" + - "197\t\t-639.687500000000\t2015-03-23T00:04:34.193Z\tNaN\t\tNaN\t\n" + - "50\tDNZNL\t-258.093750000000\t2015-03-23T00:04:46.445Z\t62\t\t0.000000003979\t2015-03-23T00:04:44.544Z\n" + - "11\t\t1.727517306805\t2015-03-23T00:04:52.639Z\t63\t\t74.151687622070\t2015-03-23T00:04:47.655Z\n" + - "101\t\t0.085098911077\t2015-03-23T00:05:07.455Z\t68\t\t0.374871194363\t2015-03-23T00:05:07.144Z\n" + - "204\t\t-864.000000000000\t2015-03-23T00:05:14.905Z\tNaN\t\tNaN\t\n" + - "157\t\t0.000000038206\t2015-03-23T00:05:24.607Z\t73\t\t-941.475097656250\t2015-03-23T00:05:24.096Z\n" + - "27\t\t0.128199812025\t2015-03-23T00:05:30.349Z\tNaN\t\tNaN\t\n" + - "294\t\t32.320184707642\t2015-03-23T00:05:35.452Z\t75\t\t0.112449161708\t2015-03-23T00:05:34.377Z\n" + - "145\tPHNIMYFFDTNP\t0.000007616574\t2015-03-23T00:05:36.249Z\tNaN\t\tNaN\t\n" + - "175\t\t0.000000096432\t2015-03-23T00:05:37.064Z\tNaN\t\tNaN\t\n" + - "140\t\t-384.000000000000\t2015-03-23T00:05:40.901Z\tNaN\t\tNaN\t\n" + - "118\t\t-768.000000000000\t2015-03-23T00:05:50.089Z\t78\t\t0.000000443235\t2015-03-23T00:05:48.820Z\n" + - "88\t\t0.000019480709\t2015-03-23T00:05:50.803Z\tNaN\t\tNaN\t\n" + - "209\tRIIYMHO\t0.036849732511\t2015-03-23T00:05:50.822Z\tNaN\t\tNaN\t\n" + - "221\t\t-308.000000000000\t2015-03-23T00:05:54.120Z\tNaN\t\tNaN\t\n" + - "278\t\t100.157985687256\t2015-03-23T00:06:06.542Z\t81\t\t-116.000000000000\t2015-03-23T00:06:06.359Z\n" + - "219\tSBEOUOJSHRU\t0.007685951889\t2015-03-23T00:06:06.860Z\tNaN\t\tNaN\t\n" + - "61\t\t-1024.000000000000\t2015-03-23T00:06:08.793Z\tNaN\t\tNaN\t\n" + - "180\t\t0.223312780261\t2015-03-23T00:06:10.929Z\tNaN\t\tNaN\t\n" + - "94\t\t0.000006785318\t2015-03-23T00:06:15.648Z\t84\t\t0.000000001883\t2015-03-23T00:06:13.867Z\n" + - "240\tPNHTDCEBYWXB\t0.000000007430\t2015-03-23T00:06:23.214Z\t85\t\t0.000000042277\t2015-03-23T00:06:21.010Z\n" + - "242\t\t-557.027343750000\t2015-03-23T00:06:24.968Z\tNaN\t\tNaN\t\n" + - "68\t\t0.000000001771\t2015-03-23T00:06:26.396Z\tNaN\t\tNaN\t\n" + - "64\t\t-512.546875000000\t2015-03-23T00:06:26.865Z\tNaN\t\tNaN\t\n" + - "41\t\t0.000001296927\t2015-03-23T00:06:34.398Z\t87\t\t0.000199647140\t2015-03-23T00:06:28.009Z\n" + - "32\tSIMYDXUUSKCX\t0.091201189905\t2015-03-23T00:06:42.748Z\tNaN\t\tNaN\t\n" + - "40\t\t0.352436579764\t2015-03-23T00:06:44.446Z\tNaN\t\tNaN\t\n" + - "279\tNEJRMDIKDISGQ\t-186.680175781250\t2015-03-23T00:06:50.222Z\t91\t\t58.010286331177\t2015-03-23T00:06:46.575Z\n" + - "277\tIGENFELWWRSLBM\t-305.000000000000\t2015-03-23T00:07:16.365Z\t96\t\t0.269549429417\t2015-03-23T00:07:14.324Z\n" + - "69\t\t-64.000000000000\t2015-03-23T00:07:32.794Z\t102\t\t21.335580825806\t2015-03-23T00:07:28.848Z\n" + - "206\t\t0.000001646644\t2015-03-23T00:07:40.787Z\t103\t\t89.232910156250\t2015-03-23T00:07:38.365Z\n" + - "2\tVQ\t0.000000002305\t2015-03-23T00:07:43.087Z\tNaN\t\tNaN\t\n" + - "110\t\t882.590759277344\t2015-03-23T00:07:44.604Z\tNaN\t\tNaN\t\n" + - "81\tGK\t0.000279274151\t2015-03-23T00:07:54.905Z\tNaN\t\tNaN\t\n" + - "208\t\t0.000000447563\t2015-03-23T00:08:04.779Z\t107\t\t0.006601167843\t2015-03-23T00:07:58.974Z\n" + - "266\t\t0.000002058839\t2015-03-23T00:08:14.465Z\tNaN\t\tNaN\t\n" + - "270\tUDVIK\t0.000000391720\t2015-03-23T00:08:17.846Z\t109\t\t135.283298492432\t2015-03-23T00:08:15.320Z\n" + - "24\tSVTN\t123.810607910156\t2015-03-23T00:08:20.910Z\tNaN\t\tNaN\t\n" + - "15\t\t0.000000004841\t2015-03-23T00:08:23.335Z\tNaN\t\tNaN\t\n"; - assertThat(expected, "trades t asof join quotes q where tag = null", true); - assertThat(expected, "trades t asof join quotes q where null = tag", true); - } - - @Test - public void testFilterOnAsOfJoinedColumn() throws Exception { - final String expected = "quoteId\ttag1\tamount\ttimestamp\tquoteId\ttag\trate\ttimestamp\n" + - "279\tREIJ\t0.001741334971\t2015-03-23T00:02:02.280Z\t29\tBROMNXKUIZ\t0.000002532035\t2015-03-23T00:01:59.534Z\n"; - assertThat(expected, "trades t asof join quotes q where tag = 'BROMNXKUIZ'", true); - assertThat(expected, "trades t asof join quotes q where 'BROMNXKUIZ' = tag", true); - } - - @Test - public void testFilterOnOuterJoinedColumns() throws Exception { - final String expected = "quoteId\ttag1\tamount\ttimestamp\tquoteId\ttag\trate\ttimestamp\n" + - "41\t\t0.000001296927\t2015-03-23T00:06:34.398Z\t41\tNRXGZSXUX\t-429.100708007813\t2015-03-23T00:03:08.533Z\n" + - "287\t\t-732.302734375000\t2015-03-23T00:07:54.893Z\t287\tNRXGZSXUX\t-1015.128906250000\t2015-03-23T00:22:07.562Z\n"; - - assertThat(expected, "trades t outer join quotes q on t.quoteId = q.quoteId where tag = 'NRXGZSXUX'", true); - assertThat(expected, "trades t outer join quotes q on t.quoteId = q.quoteId where 'NRXGZSXUX' = tag", true); - } - - @Test - public void testFilterOnPartitionedAsOfJoinedColumn() throws Exception { - final String expected = "quoteId\ttag1\tamount\ttimestamp\tquoteId\ttag\trate\ttimestamp\n" + - "41\t\t0.000001296927\t2015-03-23T00:06:34.398Z\t41\tNRXGZSXUX\t-429.100708007813\t2015-03-23T00:03:08.533Z\n"; - assertThat(expected, "trades t asof join quotes q on t.quoteId = q.quoteId where tag = 'NRXGZSXUX'", true); - assertThat(expected, "trades t asof join quotes q on t.quoteId = q.quoteId where 'NRXGZSXUX' = tag", true); - } - - @Test - public void testInvalidLambdaContext() { - try { - expectFailure("trades where quoteId in (`quotes where tag ~ 'UM'`)"); - } catch (ParserException e) { - Assert.assertEquals(25, QueryError.getPosition()); - } - } - - @Test - public void testOuterJoinLeftNull() throws Exception { - final String expected = "quoteId\ttag1\tamount\ttimestamp\tquoteId\ttag\trate\ttimestamp\n" + - "167\t\t0.000269699180\t2015-03-23T00:00:00.041Z\t167\t\t31.994654655457\t2015-03-23T00:12:48.728Z\n" + - "185\t\t320.000000000000\t2015-03-23T00:00:03.905Z\t185\tQG\t170.000000000000\t2015-03-23T00:14:14.584Z\n" + - "208\t\t0.000283450820\t2015-03-23T00:00:09.777Z\t208\tTYLHXVPGHPSF\t262.875000000000\t2015-03-23T00:16:13.032Z\n" + - "253\t\t0.000006260114\t2015-03-23T00:00:14.319Z\t253\t\t4.114017963409\t2015-03-23T00:19:34.153Z\n" + - "280\t\t0.000001666620\t2015-03-23T00:00:21.324Z\t280\tKOJEDNKRCGKSQD\t0.058121575043\t2015-03-23T00:21:47.324Z\n" + - "250\t\t391.318801879883\t2015-03-23T00:00:38.605Z\t250\t\t277.000000000000\t2015-03-23T00:19:23.568Z\n" + - "189\t\t638.125000000000\t2015-03-23T00:00:54.293Z\t189\t\t-738.307403564453\t2015-03-23T00:14:34.726Z\n" + - "79\t\t0.000000003843\t2015-03-23T00:01:00.686Z\t79\t\t0.000004861412\t2015-03-23T00:05:57.121Z\n" + - "160\t\t-804.000000000000\t2015-03-23T00:01:22.281Z\t160\t\t0.000001974584\t2015-03-23T00:12:13.375Z\n" + - "146\t\t114.411033630371\t2015-03-23T00:01:35.805Z\t146\tBTKV\t-896.000000000000\t2015-03-23T00:11:05.282Z\n" + - "275\t\t0.000000135166\t2015-03-23T00:01:46.298Z\t275\t\t-170.362548828125\t2015-03-23T00:21:22.488Z\n" + - "38\t\t0.000006406346\t2015-03-23T00:01:51.405Z\t38\t\t88.440750122070\t2015-03-23T00:02:48.897Z\n" + - "174\t\t0.003814977244\t2015-03-23T00:01:54.120Z\t174\tKWMDNZZBBUKOJS\t0.000000818166\t2015-03-23T00:13:28.095Z\n" + - "32\t\t0.000000000000\t2015-03-23T00:02:33.565Z\t32\tFORGFIEVM\t0.000000013271\t2015-03-23T00:02:19.770Z\n" + - "25\t\t0.000000521190\t2015-03-23T00:02:38.743Z\t25\t\t-1024.000000000000\t2015-03-23T00:01:41.578Z\n" + - "247\t\t1.480640053749\t2015-03-23T00:03:05.144Z\t247\tRIIYMHO\t0.000000020133\t2015-03-23T00:19:12.159Z\n" + - "11\t\t0.000000837886\t2015-03-23T00:03:12.568Z\t11\t\t109.844512939453\t2015-03-23T00:00:52.378Z\n" + - "242\t\t-448.687500000000\t2015-03-23T00:03:18.692Z\t242\t\t102.382783889771\t2015-03-23T00:18:42.107Z\n" + - "125\t\t384.000000000000\t2015-03-23T00:03:24.655Z\t125\t\t-128.000000000000\t2015-03-23T00:09:41.134Z\n" + - "38\t\t0.000000042007\t2015-03-23T00:03:56.155Z\t38\t\t88.440750122070\t2015-03-23T00:02:48.897Z\n" + - "61\t\t0.002688131004\t2015-03-23T00:03:59.991Z\t61\tBKFIJZZYNPP\t97.859756469727\t2015-03-23T00:04:34.967Z\n" + - "135\t\t11.436011791229\t2015-03-23T00:04:15.031Z\t135\t\t0.000000000000\t2015-03-23T00:10:24.620Z\n" + - "67\t\t0.000000017864\t2015-03-23T00:04:25.683Z\t67\tGSVCLLERSM\t214.940444946289\t2015-03-23T00:05:05.637Z\n" + - "5\t\t0.001699611719\t2015-03-23T00:04:32.638Z\t5\tNEJRMDIKDISGQ\t0.000017155876\t2015-03-23T00:00:21.617Z\n" + - "197\t\t-639.687500000000\t2015-03-23T00:04:34.193Z\t197\t\t618.812500000000\t2015-03-23T00:15:11.692Z\n" + - "295\t\t3.262981295586\t2015-03-23T00:04:39.143Z\t295\t\t0.000079564978\t2015-03-23T00:22:43.107Z\n" + - "11\t\t1.727517306805\t2015-03-23T00:04:52.639Z\t11\t\t109.844512939453\t2015-03-23T00:00:52.378Z\n" + - "47\t\t673.375000000000\t2015-03-23T00:04:56.064Z\t47\tRHHMGZJYYFLS\t0.005148356780\t2015-03-23T00:03:29.150Z\n" + - "97\t\t0.000031514332\t2015-03-23T00:05:04.467Z\t97\t\t0.000000008103\t2015-03-23T00:07:18.538Z\n" + - "52\t\t-982.250000000000\t2015-03-23T00:05:06.948Z\t52\tX\t0.000004397260\t2015-03-23T00:03:52.621Z\n" + - "101\t\t0.085098911077\t2015-03-23T00:05:07.455Z\t101\t\t-524.334808349609\t2015-03-23T00:07:26.447Z\n" + - "204\t\t-864.000000000000\t2015-03-23T00:05:14.905Z\t204\tJYED\t0.000000613136\t2015-03-23T00:15:52.030Z\n" + - "157\t\t0.000000038206\t2015-03-23T00:05:24.607Z\t157\t\t208.000000000000\t2015-03-23T00:11:56.847Z\n" + - "27\t\t0.128199812025\t2015-03-23T00:05:30.349Z\t27\t\t-881.312500000000\t2015-03-23T00:01:50.570Z\n" + - "294\t\t32.320184707642\t2015-03-23T00:05:35.452Z\t294\t\t0.291217848659\t2015-03-23T00:22:36.844Z\n" + - "175\t\t0.000000096432\t2015-03-23T00:05:37.064Z\t175\t\t0.000000018550\t2015-03-23T00:13:32.392Z\n" + - "140\t\t-384.000000000000\t2015-03-23T00:05:40.901Z\t140\tRYRFBVTMHGOOZ\t266.057495117188\t2015-03-23T00:10:42.021Z\n" + - "118\t\t-768.000000000000\t2015-03-23T00:05:50.089Z\t118\t\t0.000000728812\t2015-03-23T00:09:06.419Z\n" + - "88\t\t0.000019480709\t2015-03-23T00:05:50.803Z\t88\tONWE\t0.000125047416\t2015-03-23T00:06:36.408Z\n" + - "221\t\t-308.000000000000\t2015-03-23T00:05:54.120Z\t221\tLKKHTWNWIF\t-336.000000000000\t2015-03-23T00:17:03.370Z\n" + - "214\t\t-1024.000000000000\t2015-03-23T00:06:00.720Z\t214\t\t0.003775255405\t2015-03-23T00:16:42.900Z\n" + - "278\t\t100.157985687256\t2015-03-23T00:06:06.542Z\t278\tRZUPVQFULM\t0.000013578421\t2015-03-23T00:21:40.650Z\n" + - "61\t\t-1024.000000000000\t2015-03-23T00:06:08.793Z\t61\tBKFIJZZYNPP\t97.859756469727\t2015-03-23T00:04:34.967Z\n" + - "180\t\t0.223312780261\t2015-03-23T00:06:10.929Z\t180\t\t0.000098954313\t2015-03-23T00:13:53.085Z\n" + - "94\t\t0.000006785318\t2015-03-23T00:06:15.648Z\t94\tNKG\t0.000032506398\t2015-03-23T00:07:06.427Z\n" + - "242\t\t-557.027343750000\t2015-03-23T00:06:24.968Z\t242\t\t102.382783889771\t2015-03-23T00:18:42.107Z\n" + - "68\t\t0.000000001771\t2015-03-23T00:06:26.396Z\t68\t\t0.374871194363\t2015-03-23T00:05:07.144Z\n" + - "64\t\t-512.546875000000\t2015-03-23T00:06:26.865Z\t64\tQOLYXWCKYLSUWD\t-965.125000000000\t2015-03-23T00:04:55.914Z\n" + - "41\t\t0.000001296927\t2015-03-23T00:06:34.398Z\t41\tNRXGZSXUX\t-429.100708007813\t2015-03-23T00:03:08.533Z\n" + - "40\t\t0.352436579764\t2015-03-23T00:06:44.446Z\t40\tBJFRPX\t3.300331056118\t2015-03-23T00:03:01.677Z\n" + - "127\t\t0.000750448322\t2015-03-23T00:07:07.023Z\t127\tM\t-3.500000000000\t2015-03-23T00:09:51.474Z\n" + - "284\t\t0.000000056363\t2015-03-23T00:07:24.963Z\t284\t\t646.667968750000\t2015-03-23T00:21:59.500Z\n" + - "69\t\t-64.000000000000\t2015-03-23T00:07:32.794Z\t69\t\t0.000000001976\t2015-03-23T00:05:12.110Z\n" + - "206\t\t0.000001646644\t2015-03-23T00:07:40.787Z\t206\t\t0.001282604615\t2015-03-23T00:15:59.559Z\n" + - "110\t\t882.590759277344\t2015-03-23T00:07:44.604Z\t110\t\t-563.960998535156\t2015-03-23T00:08:21.310Z\n" + - "208\t\t0.000000045985\t2015-03-23T00:07:48.156Z\t208\tTYLHXVPGHPSF\t262.875000000000\t2015-03-23T00:16:13.032Z\n" + - "287\t\t-732.302734375000\t2015-03-23T00:07:54.893Z\t287\tNRXGZSXUX\t-1015.128906250000\t2015-03-23T00:22:07.562Z\n" + - "208\t\t0.000000447563\t2015-03-23T00:08:04.779Z\t208\tTYLHXVPGHPSF\t262.875000000000\t2015-03-23T00:16:13.032Z\n" + - "190\t\t0.000000005669\t2015-03-23T00:08:10.452Z\t190\t\t200.281250000000\t2015-03-23T00:14:39.938Z\n" + - "266\t\t0.000002058839\t2015-03-23T00:08:14.465Z\t266\tGIUQZHEISQ\t0.006878267042\t2015-03-23T00:20:31.754Z\n" + - "15\t\t0.000000004841\t2015-03-23T00:08:23.335Z\t15\tMYICCXZOUIC\t-504.062500000000\t2015-03-23T00:01:09.396Z\n"; - assertThat(expected, "trades t outer join quotes q on t.quoteId = q.quoteId where tag1 = null", true); - assertThat(expected, "trades t outer join quotes q on t.quoteId = q.quoteId where null = tag1", true); - assertPlan("+ 0[ cross ] t (filter: 'A' = tag1)\n" + - "+ 1[ outer ] q ON q.quoteId = t.quoteId\n" + - "\n", - "trades t outer join quotes q on t.quoteId = q.quoteId where 'A' = tag1" - ); - } - - @Test - public void testOuterJoinRightNull() throws Exception { - final String expected = "quoteId\ttag1\tamount\ttimestamp\tquoteId\ttag\trate\ttimestamp\n" + - "167\t\t0.000269699180\t2015-03-23T00:00:00.041Z\t167\t\t31.994654655457\t2015-03-23T00:12:48.728Z\n" + - "253\t\t0.000006260114\t2015-03-23T00:00:14.319Z\t253\t\t4.114017963409\t2015-03-23T00:19:34.153Z\n" + - "62\tUUQIDLVBVKH\t-655.093750000000\t2015-03-23T00:00:26.965Z\t62\t\t0.000000003979\t2015-03-23T00:04:44.544Z\n" + - "159\tOJIGFINKGQVZ\t52.300781250000\t2015-03-23T00:00:31.747Z\t159\t\t-168.824218750000\t2015-03-23T00:12:04.161Z\n" + - "250\t\t391.318801879883\t2015-03-23T00:00:38.605Z\t250\t\t277.000000000000\t2015-03-23T00:19:23.568Z\n" + - "189\t\t638.125000000000\t2015-03-23T00:00:54.293Z\t189\t\t-738.307403564453\t2015-03-23T00:14:34.726Z\n" + - "206\tDDBHEVGXY\t0.000000983339\t2015-03-23T00:00:54.651Z\t206\t\t0.001282604615\t2015-03-23T00:15:59.559Z\n" + - "79\t\t0.000000003843\t2015-03-23T00:01:00.686Z\t79\t\t0.000004861412\t2015-03-23T00:05:57.121Z\n" + - "98\tI\t0.095442861319\t2015-03-23T00:01:08.481Z\t98\t\t-615.625000000000\t2015-03-23T00:07:18.987Z\n" + - "160\t\t-804.000000000000\t2015-03-23T00:01:22.281Z\t160\t\t0.000001974584\t2015-03-23T00:12:13.375Z\n" + - "275\t\t0.000000135166\t2015-03-23T00:01:46.298Z\t275\t\t-170.362548828125\t2015-03-23T00:21:22.488Z\n" + - "38\t\t0.000006406346\t2015-03-23T00:01:51.405Z\t38\t\t88.440750122070\t2015-03-23T00:02:48.897Z\n" + - "279\tREIJ\t0.001741334971\t2015-03-23T00:02:02.280Z\t279\t\t0.000059029620\t2015-03-23T00:21:44.691Z\n" + - "83\tTYLHXVPGHPSF\t-768.000000000000\t2015-03-23T00:02:10.007Z\t83\t\t173.568359375000\t2015-03-23T00:06:12.793Z\n" + - "17\tIOVIKJS\t1.924843549728\t2015-03-23T00:02:24.538Z\t17\t\t0.000010729342\t2015-03-23T00:01:16.171Z\n" + - "25\t\t0.000000521190\t2015-03-23T00:02:38.743Z\t25\t\t-1024.000000000000\t2015-03-23T00:01:41.578Z\n" + - "233\tV\t0.000000017818\t2015-03-23T00:02:43.116Z\t233\t\t274.816894531250\t2015-03-23T00:18:08.052Z\n" + - "112\tUVV\t979.898437500000\t2015-03-23T00:02:49.249Z\t112\t\t274.169425964355\t2015-03-23T00:08:30.476Z\n" + - "295\tJYED\t881.624389648438\t2015-03-23T00:02:58.778Z\t295\t\t0.000079564978\t2015-03-23T00:22:43.107Z\n" + - "188\tMDJTHMHZNV\t128.000000000000\t2015-03-23T00:03:11.761Z\t188\t\t0.001495893754\t2015-03-23T00:14:30.135Z\n" + - "11\t\t0.000000837886\t2015-03-23T00:03:12.568Z\t11\t\t109.844512939453\t2015-03-23T00:00:52.378Z\n" + - "242\t\t-448.687500000000\t2015-03-23T00:03:18.692Z\t242\t\t102.382783889771\t2015-03-23T00:18:42.107Z\n" + - "125\t\t384.000000000000\t2015-03-23T00:03:24.655Z\t125\t\t-128.000000000000\t2015-03-23T00:09:41.134Z\n" + - "272\tOSBOS\t911.400665283203\t2015-03-23T00:03:34.502Z\t272\t\t152.160076141357\t2015-03-23T00:21:08.131Z\n" + - "13\tUMEUKVZI\t976.000000000000\t2015-03-23T00:03:48.769Z\t13\t\t367.500000000000\t2015-03-23T00:00:53.663Z\n" + - "38\t\t0.000000042007\t2015-03-23T00:03:56.155Z\t38\t\t88.440750122070\t2015-03-23T00:02:48.897Z\n" + - "217\tDWWLEVMLKCJBEVL\t-871.023925781250\t2015-03-23T00:04:05.708Z\t217\t\t192.425888061523\t2015-03-23T00:16:57.051Z\n" + - "135\t\t11.436011791229\t2015-03-23T00:04:15.031Z\t135\t\t0.000000000000\t2015-03-23T00:10:24.620Z\n" + - "200\tCJOU\t0.000000498588\t2015-03-23T00:04:30.988Z\t200\t\t2.903524160385\t2015-03-23T00:15:28.505Z\n" + - "197\t\t-639.687500000000\t2015-03-23T00:04:34.193Z\t197\t\t618.812500000000\t2015-03-23T00:15:11.692Z\n" + - "295\t\t3.262981295586\t2015-03-23T00:04:39.143Z\t295\t\t0.000079564978\t2015-03-23T00:22:43.107Z\n" + - "11\t\t1.727517306805\t2015-03-23T00:04:52.639Z\t11\t\t109.844512939453\t2015-03-23T00:00:52.378Z\n" + - "97\t\t0.000031514332\t2015-03-23T00:05:04.467Z\t97\t\t0.000000008103\t2015-03-23T00:07:18.538Z\n" + - "101\t\t0.085098911077\t2015-03-23T00:05:07.455Z\t101\t\t-524.334808349609\t2015-03-23T00:07:26.447Z\n" + - "245\tUVDRHF\t152.633743286133\t2015-03-23T00:05:12.773Z\t245\t\t0.000001090484\t2015-03-23T00:19:07.628Z\n" + - "157\t\t0.000000038206\t2015-03-23T00:05:24.607Z\t157\t\t208.000000000000\t2015-03-23T00:11:56.847Z\n" + - "27\t\t0.128199812025\t2015-03-23T00:05:30.349Z\t27\t\t-881.312500000000\t2015-03-23T00:01:50.570Z\n" + - "294\t\t32.320184707642\t2015-03-23T00:05:35.452Z\t294\t\t0.291217848659\t2015-03-23T00:22:36.844Z\n" + - "118\t\t-768.000000000000\t2015-03-23T00:05:50.089Z\t118\t\t0.000000728812\t2015-03-23T00:09:06.419Z\n" + - "209\tRIIYMHO\t0.036849732511\t2015-03-23T00:05:50.822Z\t209\t\t0.286881171167\t2015-03-23T00:16:14.200Z\n" + - "214\t\t-1024.000000000000\t2015-03-23T00:06:00.720Z\t214\t\t0.003775255405\t2015-03-23T00:16:42.900Z\n" + - "219\tSBEOUOJSHRU\t0.007685951889\t2015-03-23T00:06:06.860Z\t219\t\t261.593750000000\t2015-03-23T00:17:01.024Z\n" + - "180\t\t0.223312780261\t2015-03-23T00:06:10.929Z\t180\t\t0.000098954313\t2015-03-23T00:13:53.085Z\n" + - "242\t\t-557.027343750000\t2015-03-23T00:06:24.968Z\t242\t\t102.382783889771\t2015-03-23T00:18:42.107Z\n" + - "68\t\t0.000000001771\t2015-03-23T00:06:26.396Z\t68\t\t0.374871194363\t2015-03-23T00:05:07.144Z\n" + - "101\t\t0.003191990079\t2015-03-23T00:06:38.252Z\t101\t\t-524.334808349609\t2015-03-23T00:07:26.447Z\n" + - "279\tNEJRMDIKDISGQ\t-186.680175781250\t2015-03-23T00:06:50.222Z\t279\t\t0.000059029620\t2015-03-23T00:21:44.691Z\n" + - "238\tSED\t0.000000019996\t2015-03-23T00:06:58.896Z\t238\t\t0.001861780300\t2015-03-23T00:18:23.957Z\n" + - "284\t\t0.000000056363\t2015-03-23T00:07:24.963Z\t284\t\t646.667968750000\t2015-03-23T00:21:59.500Z\n" + - "69\t\t-64.000000000000\t2015-03-23T00:07:32.794Z\t69\t\t0.000000001976\t2015-03-23T00:05:12.110Z\n" + - "206\t\t0.000001646644\t2015-03-23T00:07:40.787Z\t206\t\t0.001282604615\t2015-03-23T00:15:59.559Z\n" + - "2\tVQ\t0.000000002305\t2015-03-23T00:07:43.087Z\t2\t\t0.000000004051\t2015-03-23T00:00:11.420Z\n" + - "110\t\t882.590759277344\t2015-03-23T00:07:44.604Z\t110\t\t-563.960998535156\t2015-03-23T00:08:21.310Z\n" + - "81\tGK\t0.000279274151\t2015-03-23T00:07:54.905Z\t81\t\t-116.000000000000\t2015-03-23T00:06:06.359Z\n" + - "190\t\t0.000000005669\t2015-03-23T00:08:10.452Z\t190\t\t200.281250000000\t2015-03-23T00:14:39.938Z\n" + - "24\tSVTN\t123.810607910156\t2015-03-23T00:08:20.910Z\t24\t\t-421.400390625000\t2015-03-23T00:01:41.440Z\n" + - "216\tZUFEV\t0.000000036476\t2015-03-23T00:08:23.335Z\t216\t\t512.000000000000\t2015-03-23T00:16:53.939Z\n"; - - assertThat(expected, "trades t outer join quotes q on t.quoteId = q.quoteId where tag = null", true); - assertThat(expected, "trades t outer join quotes q on t.quoteId = q.quoteId where null = tag", true); - } - - @Test - public void testRegexFilterOnAsOfJoinedColumn() throws Exception { - final String expected = "quoteId\ttag1\tamount\ttimestamp\tquoteId\ttag\trate\ttimestamp\n" + - "279\tREIJ\t0.001741334971\t2015-03-23T00:02:02.280Z\t29\tBROMNXKUIZ\t0.000002532035\t2015-03-23T00:01:59.534Z\n"; - assertThat(expected, "trades t asof join quotes q where tag ~ 'BROMNXKUIZ'", true); - } - - @Test - public void testWhereColumnAlias() throws Exception { - assertThat("quoteId\ttag1\tamount\ttimestamp\tquoteId\ttag\trate\ttimestamp\n" + - "50\tDNZNL\t-258.093750000000\t2015-03-23T00:04:46.445Z\t50\tVUYGMBMKSCPWLZK\t0.000000011817\t2015-03-23T00:03:43.678Z\n", - "trades t asof join quotes q on q.quoteId = t.quoteId where q.tag ~ 'B' and t.quoteId = 50", true); - } - - @Test - public void testWhereColumnAlias2() throws Exception { - assertThat("quoteId\ttag1\tamount\ttimestamp\tquoteId\ttag\trate\ttimestamp\n" + - "50\tDNZNL\t-258.093750000000\t2015-03-23T00:04:46.445Z\t50\tVUYGMBMKSCPWLZK\t0.000000011817\t2015-03-23T00:03:43.678Z\n", - "trades t asof join quotes q on q.quoteId = t.quoteId where q.tag ~ 'B' and q.quoteId = 50", true); - } - -} diff --git a/core/src/test/java/com/questdb/ql/TopRecordSourceTest.java b/core/src/test/java/com/questdb/ql/TopRecordSourceTest.java deleted file mode 100644 index 7efc98317..000000000 --- a/core/src/test/java/com/questdb/ql/TopRecordSourceTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql; - -import com.questdb.model.Quote; -import com.questdb.ql.ops.constant.LongConstant; -import com.questdb.store.JournalWriter; -import com.questdb.test.tools.AbstractTest; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class TopRecordSourceTest extends AbstractTest { - - @Before - public void setUp() throws Exception { - try (JournalWriter w = getFactory().writer(Quote.class, "quote")) { - TestUtils.generateQuoteData(w, 100000); - } - } - - @Test - public void testBottomSource() throws Exception { - RecordSourcePrinter p = new RecordSourcePrinter(sink); - try (RecordSource rs = new TopRecordSource(compile("quote"), new LongConstant(99997, 0), new LongConstant(100000, 0))) { - p.print(rs, getFactory()); - final String expected = "2013-11-04T10:00:00.000Z\tBT-A.L\t168.000000000000\t0.001307277009\t319936098\t1456039311\tFast trading\tLXE\n" + - "2013-11-04T10:00:00.000Z\tAGK.L\t0.000031983279\t878.000000000000\t819380635\t1732419403\tFast trading\tLXE\n" + - "2013-11-04T10:00:00.000Z\tHSBA.L\t243.601509094238\t44.582113265991\t532679143\t345298132\tFast trading\tLXE\n"; - Assert.assertEquals(expected, sink.toString()); - } - } - - @Test - public void testMiddleSource() throws Exception { - RecordSourcePrinter p = new RecordSourcePrinter(sink); - try (RecordSource rs = new TopRecordSource(compile("quote"), new LongConstant(102, 0), new LongConstant(112, 0))) { - p.print(rs, getFactory()); - - final String expected = "2013-09-04T10:00:00.000Z\tTLW.L\t0.003675992833\t0.000000006044\t233699709\t984001343\tFast trading\tLXE\n" + - "2013-09-04T10:00:00.000Z\tGKN.L\t0.000001392326\t0.000000010696\t1921077830\t83098719\tFast trading\tLXE\n" + - "2013-09-04T10:00:00.000Z\tHSBA.L\t125.000000000000\t113.359375000000\t347349195\t1619900957\tFast trading\tLXE\n" + - "2013-09-04T10:00:00.000Z\tTLW.L\t0.000000539488\t1.938893854618\t1012023467\t596418088\tFast trading\tLXE\n" + - "2013-09-04T10:00:00.000Z\tBP.L\t0.009742939146\t0.000000729716\t952785207\t94086655\tFast trading\tLXE\n" + - "2013-09-04T10:00:00.000Z\tBT-A.L\t10.085297346115\t0.293467730284\t1376102367\t166757857\tFast trading\tLXE\n" + - "2013-09-04T10:00:00.000Z\tABF.L\t488.272369384766\t342.142333984375\t1016986855\t1939793032\tFast trading\tLXE\n" + - "2013-09-04T10:00:00.000Z\tLLOY.L\t601.087127685547\t0.519029200077\t337891645\t1650060090\tFast trading\tLXE\n" + - "2013-09-04T10:00:00.000Z\tABF.L\t0.025374564342\t0.009976797737\t1448235215\t107181743\tFast trading\tLXE\n" + - "2013-09-04T10:00:00.000Z\tAGK.L\t335.908935546875\t492.000000000000\t1466344037\t79845289\tFast trading\tLXE\n"; - Assert.assertEquals(expected, sink.toString()); - } - } - - @Test - public void testNoRows() throws Exception { - RecordSourcePrinter p = new RecordSourcePrinter(sink); - try (RecordSource rs = new TopRecordSource(compile("quote"), new LongConstant(99997, 0), new LongConstant(10, 0))) { - p.print(rs, getFactory()); - Assert.assertEquals("", sink.toString()); - } - } - - @Test - public void testTopSource() throws Exception { - RecordSourcePrinter p = new RecordSourcePrinter(sink); - try (RecordSource rs = new TopRecordSource(compile("quote"), new LongConstant(0, 0), new LongConstant(10, 0))) { - p.print(rs, getFactory()); - final String expected = "2013-09-04T10:00:00.000Z\tBT-A.L\t0.000001189157\t1.050231933594\t1326447242\t948263339\tFast trading\tLXE\n" + - "2013-09-04T10:00:00.000Z\tADM.L\t104.021850585938\t0.006688738358\t1575378703\t1436881714\tFast trading\tLXE\n" + - "2013-09-04T10:00:00.000Z\tAGK.L\t879.117187500000\t496.806518554688\t1530831067\t339631474\tFast trading\tLXE\n" + - "2013-09-04T10:00:00.000Z\tABF.L\t768.000000000000\t0.000020634160\t426455968\t1432278050\tFast trading\tLXE\n" + - "2013-09-04T10:00:00.000Z\tABF.L\t256.000000000000\t0.000000035797\t1404198\t1153445279\tFast trading\tLXE\n" + - "2013-09-04T10:00:00.000Z\tWTB.L\t920.625000000000\t0.040750414133\t761275053\t1232884790\tFast trading\tLXE\n" + - "2013-09-04T10:00:00.000Z\tAGK.L\t512.000000000000\t896.000000000000\t422941535\t113506296\tFast trading\tLXE\n" + - "2013-09-04T10:00:00.000Z\tRRS.L\t12.923866510391\t0.032379742712\t2006313928\t2132716300\tFast trading\tLXE\n" + - "2013-09-04T10:00:00.000Z\tBT-A.L\t0.006530375686\t0.000000000000\t1890602616\t2137969456\tFast trading\tLXE\n" + - "2013-09-04T10:00:00.000Z\tABF.L\t0.000000017324\t720.000000000000\t410717394\t458818940\tFast trading\tLXE\n"; - Assert.assertEquals(expected, sink.toString()); - } - } -} diff --git a/core/src/test/java/com/questdb/ql/VirtualColumnTest.java b/core/src/test/java/com/questdb/ql/VirtualColumnTest.java deleted file mode 100644 index 37959c26c..000000000 --- a/core/src/test/java/com/questdb/ql/VirtualColumnTest.java +++ /dev/null @@ -1,334 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql; - -import com.questdb.BootstrapEnv; -import com.questdb.ServerConfiguration; -import com.questdb.ql.ops.VirtualColumn; -import com.questdb.ql.ops.col.DoubleRecordSourceColumn; -import com.questdb.ql.ops.constant.DoubleConstant; -import com.questdb.ql.ops.plus.AddDoubleOperator; -import com.questdb.ql.select.SelectedColumnsRecordSource; -import com.questdb.ql.virtual.VirtualColumnRecordSource; -import com.questdb.std.ObjList; -import com.questdb.std.Rnd; -import com.questdb.std.str.StringSink; -import com.questdb.store.JournalEntryWriter; -import com.questdb.store.JournalWriter; -import com.questdb.store.factory.configuration.JournalStructure; -import com.questdb.test.tools.AbstractTest; -import org.junit.Assert; -import org.junit.Test; - -public class VirtualColumnTest extends AbstractTest { - - @Test - public void testPlusDouble() throws Exception { - - try (final JournalWriter w = getFactory().writer(new JournalStructure("xyz") {{ - $str("ccy"); - $double("bid"); - }})) { - - Rnd rnd = new Rnd(); - - for (int i = 0; i < 100; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putStr(0, rnd.nextString(10)); - ew.putDouble(1, rnd.nextDouble()); - ew.append(); - } - w.commit(); - - StringSink sink = new StringSink(); - RecordSourcePrinter p = new RecordSourcePrinter(sink); - BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(); - - final AddDoubleOperator plus = (AddDoubleOperator) AddDoubleOperator.FACTORY.newInstance(0, env); - plus.setName("plus"); - plus.setLhs(new DoubleRecordSourceColumn(w.getMetadata().getColumnIndex("bid"), 0)); - plus.setRhs(new DoubleConstant(12.5, 0)); - - // select ccy, bid, bid+12.5 plus from xyz - try (VirtualColumnRecordSource src = new VirtualColumnRecordSource(compile("xyz"), new ObjList() {{ - add(plus); - }})) { - - p.print(src, getFactory()); - - final String expected = "VTJWCPSWHY\t-104.021850585938\t-91.521850585938\n" + - "PEHNRXGZSX\t0.000020634160\t12.500020634160\n" + - "IBBTGPGWFF\t0.000000567185\t12.500000567185\n" + - "DEYYQEHBHF\t0.000000401164\t12.500000401164\n" + - "LPDXYSBEOU\t384.072387695313\t396.572387695313\n" + - "SHRUEDRQQU\t109.355468750000\t121.855468750000\n" + - "FJGETJRSZS\t198.750000000000\t211.250000000000\n" + - "RFBVTMHGOO\t172.796875000000\t185.296875000000\n" + - "VDZJMYICCX\t-1024.000000000000\t-1011.500000000000\n" + - "UICWEKGHVU\t0.000425009843\t12.500425009843\n" + - "DOTSEDYYCT\t557.000000000000\t569.500000000000\n" + - "OLYXWCKYLS\t0.000553289865\t12.500553289865\n" + - "DSWUGSHOLN\t-1013.467773437500\t-1000.967773437500\n" + - "IQBZXIOVIK\t512.000000000000\t524.500000000000\n" + - "MSSUQSRLTK\t0.000000776007\t12.500000776007\n" + - "SJOJIPHZEP\t174.774871826172\t187.274871826172\n" + - "VLTOVLJUML\t-77.428833007813\t-64.928833007813\n" + - "HMLLEOYPHR\t0.000327562877\t12.500327562877\n" + - "ZIMNZZRMFM\t238.632812500000\t251.132812500000\n" + - "ZGHWVDKFLO\t0.000102697388\t12.500102697388\n" + - "OXPKRGIIHY\t128.000000000000\t140.500000000000\n" + - "OQMYSSMPGL\t-144.421875000000\t-131.921875000000\n" + - "HNZHZSQLDG\t832.000000000000\t844.500000000000\n" + - "GIFOUSZMZV\t-200.000000000000\t-187.500000000000\n" + - "BNDCQCEHNO\t2.602588653564\t15.102588653564\n" + - "ELLKKHTWNW\t0.000969694171\t12.500969694171\n" + - "FLRBROMNXK\t0.000000548919\t12.500000548919\n" + - "ZULIGYVFZF\t-327.250000000000\t-314.750000000000\n" + - "ZLUOGXHFVW\t0.000002116648\t12.500002116648\n" + - "SRGOONFCLT\t310.101058959961\t322.601058959961\n" + - "KFMQNTOGMX\t0.000012478828\t12.500012478828\n" + - "LGMXSLUQDY\t0.000013214448\t12.500013214448\n" + - "HNIMYFFDTN\t0.000000001910\t12.500000001910\n" + - "FLPBNHGZWW\t695.173828125000\t707.673828125000\n" + - "NGTNLEGPUH\t0.205350898206\t12.705350898206\n" + - "UGGLNYRZLC\t638.000000000000\t650.500000000000\n" + - "MIGQZVKHTL\t0.000000040298\t12.500000040298\n" + - "SLQVFGPPRG\t-1024.000000000000\t-1011.500000000000\n" + - "BHYSBQYMIZ\t5.336447119713\t17.836447119713\n" + - "VTNPIWZNFK\t0.000000012570\t12.500000012570\n" + - "VMCGFNWGRM\t-128.000000000000\t-115.500000000000\n" + - "GIJYDVRVNG\t0.000000052204\t12.500000052204\n" + - "EQODRZEIWF\t-31.000000000000\t-18.500000000000\n" + - "KYHQQUWQOE\t880.000000000000\t892.500000000000\n" + - "NEBQQEMXDK\t25.839271545410\t38.339271545410\n" + - "JCTIZKYFLU\t768.000000000000\t780.500000000000\n" + - "QSNPXMKJSM\t0.004184104619\t12.504184104619\n" + - "XEYVTUPDHH\t845.823730468750\t858.323730468750\n" + - "IWHPZRHHMG\t37.350353240967\t49.850353240967\n" + - "YYFLSVIHDW\t-400.000000000000\t-387.500000000000\n" + - "EVMLKCJBEV\t0.000000914462\t12.500000914462\n" + - "HLIHYBTVZN\t0.000001439041\t12.500001439041\n" + - "NXFSUWPNXH\t-199.648437500000\t-187.148437500000\n" + - "TZODWKOCPF\t0.002563251997\t12.502563251997\n" + - "PVKNCBWLNL\t0.397523656487\t12.897523656487\n" + - "WQXYPOVFDB\t8.950848102570\t21.450848102570\n" + - "NIJEEHRUGP\t448.000000000000\t460.500000000000\n" + - "BTKVSBEGMI\t391.000000000000\t403.500000000000\n" + - "NLKFNUHNRJ\t0.000000048669\t12.500000048669\n" + - "BWVLOMPBET\t0.000038398017\t12.500038398017\n" + - "KRIVOCUGPU\t2.929819107056\t15.429819107056\n" + - "FIVQFNIZOS\t815.000000000000\t827.500000000000\n" + - "SEPGIUQZHE\t0.017051883508\t12.517051883508\n" + - "QHNOJIGFIN\t601.087127685547\t613.587127685547\n" + - "QVZWEVQTQO\t-492.000000000000\t-479.500000000000\n" + - "XTPNHTDCEB\t-966.000000000000\t-953.500000000000\n" + - "XBBZVRLPTY\t70.810325622559\t83.310325622559\n" + - "GYFUXCDKDW\t0.000837845349\t12.500837845349\n" + - "DXCBJFRPXZ\t0.000008696692\t12.500008696692\n" + - "XUNYQXTGNJ\t6.359375000000\t18.859375000000\n" + - "LLEYMIWTCW\t792.242187500000\t804.742187500000\n" + - "ORGFIEVMKP\t-726.000000000000\t-713.500000000000\n" + - "GPYKKBMQMU\t0.000000000000\t12.500000000000\n" + - "CIHCNPUGJO\t-762.240234375000\t-749.740234375000\n" + - "EUKWMDNZZB\t0.000000031117\t12.500000031117\n" + - "KOJSOLDYRO\t552.000000000000\t564.500000000000\n" + - "PUNRPSMIFD\t73.947616577148\t86.447616577148\n" + - "DKOEZBRQSQ\t-736.000000000000\t-723.500000000000\n" + - "DIHHNSSTCR\t0.000002963134\t12.500002963134\n" + - "PVQFULMERT\t0.000005817310\t12.500005817310\n" + - "QBUYZVQQHS\t0.000000011688\t12.500000011688\n" + - "PZPBHLNEJR\t-1003.625000000000\t-991.125000000000\n" + - "IKDISGQFYQ\t351.509208679199\t364.009208679199\n" + - "GPZNYVLTPK\t0.000702012621\t12.500702012621\n" + - "QFNPOYNNCT\t0.000445737198\t12.500445737198\n" + - "NSXHHDILEL\t0.001584486396\t12.501584486396\n" + - "MMZSCJOUOU\t642.865234375000\t655.365234375000\n" + - "ENFELWWRSL\t-934.268554687500\t-921.768554687500\n" + - "QHGJBFQBBK\t103.908081054688\t116.408081054688\n" + - "JZZYNPPBXB\t-944.000000000000\t-931.500000000000\n" + - "RIIYMHOWKC\t0.000000542615\t12.500000542615\n" + - "ZNLCNGZTOY\t0.000080315222\t12.500080315222\n" + - "XRSFPVRQLG\t0.000000093226\t12.500000093226\n" + - "ONNLITWGLF\t0.000000000000\t12.500000000000\n" + - "QWPKLHTIIG\t-783.750000000000\t-771.250000000000\n" + - "YYPDVRGRQG\t0.000376001219\t12.500376001219\n" + - "PHKOWBVDEG\t0.000002666791\t12.500002666791\n" + - "XGZMDJTHMH\t-670.500000000000\t-658.000000000000\n" + - "VZHCNXZEQG\t-524.507812500000\t-512.007812500000\n" + - "LUCFTLNKYT\t0.000000001835\t12.500000001835\n"; - - Assert.assertEquals(expected, sink.toString()); - } - } - } - - @Test - public void testSelectedColumns() throws Exception { - - try (final JournalWriter w = getFactory().writer(new JournalStructure("xyz") {{ - $str("ccy"); - $double("bid"); - }})) { - - Rnd rnd = new Rnd(); - - for (int i = 0; i < 100; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putStr(0, rnd.nextString(10)); - ew.putDouble(1, rnd.nextDouble()); - ew.append(); - } - w.commit(); - - StringSink sink = new StringSink(); - RecordSourcePrinter p = new RecordSourcePrinter(sink); - BootstrapEnv env = new BootstrapEnv(); - env.configuration = new ServerConfiguration(); - final AddDoubleOperator plus = (AddDoubleOperator) AddDoubleOperator.FACTORY.newInstance(0, env); - plus.setName("plus"); - plus.setLhs(new DoubleRecordSourceColumn(w.getMetadata().getColumnIndex("bid"), 0)); - plus.setRhs(new DoubleConstant(12.5, 0)); - - // select ccy, bid+12.5 plus from xyz - try (RecordSource src = new SelectedColumnsRecordSource( - new VirtualColumnRecordSource( - compile("xyz"), - new ObjList() {{ - add(plus); - }} - ), - new ObjList() {{ - add("ccy"); - add("plus"); - }})) { - - p.print(src, getFactory()); - - final String expected = "VTJWCPSWHY\t-91.521850585938\n" + - "PEHNRXGZSX\t12.500020634160\n" + - "IBBTGPGWFF\t12.500000567185\n" + - "DEYYQEHBHF\t12.500000401164\n" + - "LPDXYSBEOU\t396.572387695313\n" + - "SHRUEDRQQU\t121.855468750000\n" + - "FJGETJRSZS\t211.250000000000\n" + - "RFBVTMHGOO\t185.296875000000\n" + - "VDZJMYICCX\t-1011.500000000000\n" + - "UICWEKGHVU\t12.500425009843\n" + - "DOTSEDYYCT\t569.500000000000\n" + - "OLYXWCKYLS\t12.500553289865\n" + - "DSWUGSHOLN\t-1000.967773437500\n" + - "IQBZXIOVIK\t524.500000000000\n" + - "MSSUQSRLTK\t12.500000776007\n" + - "SJOJIPHZEP\t187.274871826172\n" + - "VLTOVLJUML\t-64.928833007813\n" + - "HMLLEOYPHR\t12.500327562877\n" + - "ZIMNZZRMFM\t251.132812500000\n" + - "ZGHWVDKFLO\t12.500102697388\n" + - "OXPKRGIIHY\t140.500000000000\n" + - "OQMYSSMPGL\t-131.921875000000\n" + - "HNZHZSQLDG\t844.500000000000\n" + - "GIFOUSZMZV\t-187.500000000000\n" + - "BNDCQCEHNO\t15.102588653564\n" + - "ELLKKHTWNW\t12.500969694171\n" + - "FLRBROMNXK\t12.500000548919\n" + - "ZULIGYVFZF\t-314.750000000000\n" + - "ZLUOGXHFVW\t12.500002116648\n" + - "SRGOONFCLT\t322.601058959961\n" + - "KFMQNTOGMX\t12.500012478828\n" + - "LGMXSLUQDY\t12.500013214448\n" + - "HNIMYFFDTN\t12.500000001910\n" + - "FLPBNHGZWW\t707.673828125000\n" + - "NGTNLEGPUH\t12.705350898206\n" + - "UGGLNYRZLC\t650.500000000000\n" + - "MIGQZVKHTL\t12.500000040298\n" + - "SLQVFGPPRG\t-1011.500000000000\n" + - "BHYSBQYMIZ\t17.836447119713\n" + - "VTNPIWZNFK\t12.500000012570\n" + - "VMCGFNWGRM\t-115.500000000000\n" + - "GIJYDVRVNG\t12.500000052204\n" + - "EQODRZEIWF\t-18.500000000000\n" + - "KYHQQUWQOE\t892.500000000000\n" + - "NEBQQEMXDK\t38.339271545410\n" + - "JCTIZKYFLU\t780.500000000000\n" + - "QSNPXMKJSM\t12.504184104619\n" + - "XEYVTUPDHH\t858.323730468750\n" + - "IWHPZRHHMG\t49.850353240967\n" + - "YYFLSVIHDW\t-387.500000000000\n" + - "EVMLKCJBEV\t12.500000914462\n" + - "HLIHYBTVZN\t12.500001439041\n" + - "NXFSUWPNXH\t-187.148437500000\n" + - "TZODWKOCPF\t12.502563251997\n" + - "PVKNCBWLNL\t12.897523656487\n" + - "WQXYPOVFDB\t21.450848102570\n" + - "NIJEEHRUGP\t460.500000000000\n" + - "BTKVSBEGMI\t403.500000000000\n" + - "NLKFNUHNRJ\t12.500000048669\n" + - "BWVLOMPBET\t12.500038398017\n" + - "KRIVOCUGPU\t15.429819107056\n" + - "FIVQFNIZOS\t827.500000000000\n" + - "SEPGIUQZHE\t12.517051883508\n" + - "QHNOJIGFIN\t613.587127685547\n" + - "QVZWEVQTQO\t-479.500000000000\n" + - "XTPNHTDCEB\t-953.500000000000\n" + - "XBBZVRLPTY\t83.310325622559\n" + - "GYFUXCDKDW\t12.500837845349\n" + - "DXCBJFRPXZ\t12.500008696692\n" + - "XUNYQXTGNJ\t18.859375000000\n" + - "LLEYMIWTCW\t804.742187500000\n" + - "ORGFIEVMKP\t-713.500000000000\n" + - "GPYKKBMQMU\t12.500000000000\n" + - "CIHCNPUGJO\t-749.740234375000\n" + - "EUKWMDNZZB\t12.500000031117\n" + - "KOJSOLDYRO\t564.500000000000\n" + - "PUNRPSMIFD\t86.447616577148\n" + - "DKOEZBRQSQ\t-723.500000000000\n" + - "DIHHNSSTCR\t12.500002963134\n" + - "PVQFULMERT\t12.500005817310\n" + - "QBUYZVQQHS\t12.500000011688\n" + - "PZPBHLNEJR\t-991.125000000000\n" + - "IKDISGQFYQ\t364.009208679199\n" + - "GPZNYVLTPK\t12.500702012621\n" + - "QFNPOYNNCT\t12.500445737198\n" + - "NSXHHDILEL\t12.501584486396\n" + - "MMZSCJOUOU\t655.365234375000\n" + - "ENFELWWRSL\t-921.768554687500\n" + - "QHGJBFQBBK\t116.408081054688\n" + - "JZZYNPPBXB\t-931.500000000000\n" + - "RIIYMHOWKC\t12.500000542615\n" + - "ZNLCNGZTOY\t12.500080315222\n" + - "XRSFPVRQLG\t12.500000093226\n" + - "ONNLITWGLF\t12.500000000000\n" + - "QWPKLHTIIG\t-771.250000000000\n" + - "YYPDVRGRQG\t12.500376001219\n" + - "PHKOWBVDEG\t12.500002666791\n" + - "XGZMDJTHMH\t-658.000000000000\n" + - "VZHCNXZEQG\t-512.007812500000\n" + - "LUCFTLNKYT\t12.500000001835\n"; - - Assert.assertEquals(expected, sink.toString()); - } - } - } -} diff --git a/core/src/test/java/com/questdb/ql/aggregation/SamplerTest.java b/core/src/test/java/com/questdb/ql/aggregation/SamplerTest.java deleted file mode 100644 index 8f64cd84a..000000000 --- a/core/src/test/java/com/questdb/ql/aggregation/SamplerTest.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql.aggregation; - -import com.questdb.std.str.StringSink; -import com.questdb.std.time.DateFormatUtils; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class SamplerTest { - - private final StringSink sink = new StringSink(); - - @Before - public void setUp() { - sink.clear(); - } - - @Test - public void testDays() throws Exception { - TimestampSampler sampler = SamplerFactory.from("2d"); - Assert.assertNotNull(sampler); - DateFormatUtils.appendDateTime(sink, sampler.resample(DateFormatUtils.parseDateTime("2015-04-03T09:04:45.000Z"))); - TestUtils.assertEquals("2015-04-03T00:00:00.000Z", sink); - } - - @Test - public void testHours() throws Exception { - TimestampSampler sampler = SamplerFactory.from("3h"); - Assert.assertNotNull(sampler); - DateFormatUtils.appendDateTime(sink, sampler.resample(DateFormatUtils.parseDateTime("2015-04-10T10:04:45.000Z"))); - TestUtils.assertEquals("2015-04-10T09:00:00.000Z", sink); - } - - @Test - public void testInvalidQualifier() { - Assert.assertNull(SamplerFactory.from("2z")); - } - - @Test - public void testMinutes() throws Exception { - TimestampSampler sampler = SamplerFactory.from("3m"); - Assert.assertNotNull(sampler); - DateFormatUtils.appendDateTime(sink, sampler.resample(DateFormatUtils.parseDateTime("2015-04-10T10:04:45.000Z"))); - TestUtils.assertEquals("2015-04-10T10:03:00.000Z", sink); - - sink.clear(); - - DateFormatUtils.appendDateTime(sink, sampler.resample(DateFormatUtils.parseDateTime("2015-04-10T10:07:15.000Z"))); - TestUtils.assertEquals("2015-04-10T10:06:00.000Z", sink); - } - - @Test - public void testMonths() throws Exception { - TimestampSampler sampler = SamplerFactory.from("3M"); - Assert.assertNotNull(sampler); - DateFormatUtils.appendDateTime(sink, sampler.resample(DateFormatUtils.parseDateTime("2015-07-03T09:04:45.000Z"))); - TestUtils.assertEquals("2015-07-01T00:00:00.000Z", sink); - } - - @Test - public void testNoQualifier() { - Assert.assertNull(SamplerFactory.from("2")); - } - - @Test - public void testSeconds() throws Exception { - TimestampSampler sampler = SamplerFactory.from("15s"); - Assert.assertNotNull(sampler); - DateFormatUtils.appendDateTime(sink, sampler.resample(DateFormatUtils.parseDateTime("2015-04-10T10:04:48.100Z"))); - TestUtils.assertEquals("2015-04-10T10:04:45.000Z", sink); - sink.clear(); - } - - @Test - public void testYear() throws Exception { - TimestampSampler sampler = SamplerFactory.from("Y"); - Assert.assertNotNull(sampler); - DateFormatUtils.appendDateTime(sink, sampler.resample(DateFormatUtils.parseDateTime("2015-07-03T09:04:45.000Z"))); - TestUtils.assertEquals("2015-01-01T00:00:00.000Z", sink); - } - - @Test - public void testYears() { - Assert.assertNull(SamplerFactory.from("2Y")); - } -} diff --git a/core/src/test/java/com/questdb/ql/analytic/DenseRankAnalyticFunctionTest.java b/core/src/test/java/com/questdb/ql/analytic/DenseRankAnalyticFunctionTest.java deleted file mode 100644 index 09c7d9a9b..000000000 --- a/core/src/test/java/com/questdb/ql/analytic/DenseRankAnalyticFunctionTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql.analytic; - -import com.questdb.ex.ParserException; -import com.questdb.parser.sql.QueryError; -import com.questdb.ql.AbstractAllTypeTest; -import com.questdb.test.tools.TestUtils; -import org.junit.Test; - -public class DenseRankAnalyticFunctionTest extends AbstractAllTypeTest { - @Test - public void testRank() throws Exception { - assertThat("5\ttrue\tAX\t2016-05-01T10:26:00.000Z\n" + - "6\tfalse\tBZ\t2016-05-01T10:27:00.000Z\n" + - "7\ttrue\tBZ\t2016-05-01T10:28:00.000Z\n" + - "8\tfalse\tAX\t2016-05-01T10:29:00.000Z\n" + - "9\tfalse\tBZ\t2016-05-01T10:30:00.000Z\n", - "select dense_rank() x over(), boo, str, timestamp from 'abc' limit 5,10"); - } - - @Test - public void testRankOrdered() throws Exception { - assertThat("15\tBZ\t1.050231933594\n" + - "17\tXX\t566.734375000000\n" + - "9\tKK\t0.000013792171\n" + - "6\tAX\t0.000000567185\n" + - "1\tAX\t-512.000000000000\n" + - "14\tAX\t0.675451681018\n" + - "13\tBZ\t0.332301996648\n" + - "7\tBZ\t0.000001752813\n" + - "11\tAX\t0.000076281818\n" + - "2\tBZ\t0.000000005555\n" + - "8\tXX\t0.000002473130\n" + - "18\tKK\t632.921875000000\n" + - "4\tAX\t0.000000020896\n" + - "12\tBZ\t0.007371325744\n" + - "3\tXX\t0.000000014643\n" + - "16\tAX\t512.000000000000\n" + - "19\tXX\t864.000000000000\n" + - "5\tAX\t0.000000157437\n" + - "0\tBZ\t-842.000000000000\n" + - "10\tBZ\t0.000032060649\n", - "select dense_rank() x over(order by d), str, d from abc"); - } - - @Test - public void testRankOrderedPartitioned() throws Exception { - assertThat("BZ\t0\n" + - "XX\t0\n" + - "KK\t0\n" + - "AX\t0\n" + - "AX\t1\n" + - "AX\t2\n" + - "BZ\t1\n" + - "BZ\t2\n" + - "AX\t3\n" + - "BZ\t3\n" + - "XX\t1\n" + - "KK\t1\n" + - "AX\t4\n" + - "BZ\t4\n" + - "XX\t2\n" + - "AX\t5\n" + - "XX\t3\n" + - "AX\t6\n" + - "BZ\t5\n" + - "BZ\t6\n", - "select str, dense_rank() rank over(partition by str order by timestamp) from 'abc'"); - } - - @Test - public void testRankPartitioned() throws Exception { - assertThat("BZ\t0\n" + - "XX\t0\n" + - "KK\t0\n" + - "AX\t0\n" + - "AX\t1\n" + - "AX\t2\n" + - "BZ\t1\n" + - "BZ\t2\n" + - "AX\t3\n" + - "BZ\t3\n" + - "XX\t1\n" + - "KK\t1\n" + - "AX\t4\n" + - "BZ\t4\n" + - "XX\t2\n" + - "AX\t5\n" + - "XX\t3\n" + - "AX\t6\n" + - "BZ\t5\n" + - "BZ\t6\n", - "select str, dense_rank() rank over(partition by str) from 'abc'"); - } - - @Test - public void testRankWithArg() { - try { - expectFailure("select str, dense_rank(sym) rank over(partition by str) from 'abc'"); - } catch (ParserException e) { - TestUtils.assertEquals("Unknown function", QueryError.getMessage()); - } - } -} diff --git a/core/src/test/java/com/questdb/ql/analytic/MiscAnalyticFunctionTest.java b/core/src/test/java/com/questdb/ql/analytic/MiscAnalyticFunctionTest.java deleted file mode 100644 index 3937a8b95..000000000 --- a/core/src/test/java/com/questdb/ql/analytic/MiscAnalyticFunctionTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql.analytic; - -import com.questdb.ql.AbstractAllTypeTest; -import org.junit.Test; - -public class MiscAnalyticFunctionTest extends AbstractAllTypeTest { - @Test - public void testAnalyticAndAggregates() throws Exception { - assertThat("0\tBZ\t2016-05-01T10:40:00.000Z\n" + - "1\tXX\t2016-05-01T10:37:00.000Z\n" + - "2\tKK\t2016-05-01T10:32:00.000Z\n" + - "3\tAX\t2016-05-01T10:38:00.000Z\n", - "select dense_rank() x over(), str, max(timestamp) from 'abc'"); - } -} diff --git a/core/src/test/java/com/questdb/ql/analytic/NextAnalyticFunctionTest.java b/core/src/test/java/com/questdb/ql/analytic/NextAnalyticFunctionTest.java deleted file mode 100644 index 871e0472b..000000000 --- a/core/src/test/java/com/questdb/ql/analytic/NextAnalyticFunctionTest.java +++ /dev/null @@ -1,741 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql.analytic; - -import com.questdb.ex.ParserException; -import com.questdb.parser.sql.QueryError; -import com.questdb.ql.AbstractAllTypeTest; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Test; - -public class NextAnalyticFunctionTest extends AbstractAllTypeTest { - - private final static String expected = "-1148479920\tBZ\t2016-05-01T10:21:00.000Z\t-409854405\n" + - "1548800833\tKK\t2016-05-01T10:22:00.000Z\t73575701\n" + - "73575701\tKK\t2016-05-01T10:23:00.000Z\t1326447242\n" + - "1326447242\tKK\t2016-05-01T10:24:00.000Z\t-1436881714\n" + - "1868723706\tAX\t2016-05-01T10:25:00.000Z\t-1191262516\n" + - "-1191262516\tAX\t2016-05-01T10:26:00.000Z\t806715481\n" + - "-1436881714\tKK\t2016-05-01T10:27:00.000Z\t1530831067\n" + - "806715481\tAX\t2016-05-01T10:28:00.000Z\t1125579207\n" + - "1569490116\tXX\t2016-05-01T10:29:00.000Z\t-1532328444\n" + - "-409854405\tBZ\t2016-05-01T10:30:00.000Z\t1699553881\n" + - "1530831067\tKK\t2016-05-01T10:31:00.000Z\t-1844391305\n" + - "-1532328444\tXX\t2016-05-01T10:32:00.000Z\t1404198\n" + - "1125579207\tAX\t2016-05-01T10:33:00.000Z\t-1432278050\n" + - "-1432278050\tAX\t2016-05-01T10:34:00.000Z\t-85170055\n" + - "-85170055\tAX\t2016-05-01T10:35:00.000Z\t-1125169127\n" + - "-1844391305\tKK\t2016-05-01T10:36:00.000Z\t-1101822104\n" + - "-1101822104\tKK\t2016-05-01T10:37:00.000Z\t-547127752\n" + - "1404198\tXX\t2016-05-01T10:38:00.000Z\t1232884790\n" + - "-1125169127\tAX\t2016-05-01T10:39:00.000Z\t-1975183723\n" + - "-1975183723\tAX\t2016-05-01T10:40:00.000Z\t-2119387831\n" + - "1232884790\tXX\t2016-05-01T10:41:00.000Z\t-1575135393\n" + - "-2119387831\tAX\t2016-05-01T10:42:00.000Z\t1253890363\n" + - "1699553881\tBZ\t2016-05-01T10:43:00.000Z\t-422941535\n" + - "1253890363\tAX\t2016-05-01T10:44:00.000Z\t-2132716300\n" + - "-422941535\tBZ\t2016-05-01T10:45:00.000Z\t-303295973\n" + - "-547127752\tKK\t2016-05-01T10:46:00.000Z\t-461611463\n" + - "-303295973\tBZ\t2016-05-01T10:47:00.000Z\t1890602616\n" + - "-2132716300\tAX\t2016-05-01T10:48:00.000Z\t264240638\n" + - "-461611463\tKK\t2016-05-01T10:49:00.000Z\t-2144581835\n" + - "264240638\tAX\t2016-05-01T10:50:00.000Z\t-483853667\n" + - "-483853667\tAX\t2016-05-01T10:51:00.000Z\t-2002373666\n" + - "1890602616\tBZ\t2016-05-01T10:52:00.000Z\t68265578\n" + - "68265578\tBZ\t2016-05-01T10:53:00.000Z\t458818940\n" + - "-2002373666\tAX\t2016-05-01T10:54:00.000Z\t-1418341054\n" + - "458818940\tBZ\t2016-05-01T10:55:00.000Z\t-2034804966\n" + - "-2144581835\tKK\t2016-05-01T10:56:00.000Z\t2031014705\n" + - "-1418341054\tAX\t2016-05-01T10:57:00.000Z\t-1787109293\n" + - "2031014705\tKK\t2016-05-01T10:58:00.000Z\t936627841\n" + - "-1575135393\tXX\t2016-05-01T10:59:00.000Z\t-372268574\n" + - "936627841\tKK\t2016-05-01T11:00:00.000Z\t-667031149\n" + - "-667031149\tKK\t2016-05-01T11:01:00.000Z\t1637847416\n" + - "-2034804966\tBZ\t2016-05-01T11:02:00.000Z\t161592763\n" + - "1637847416\tKK\t2016-05-01T11:03:00.000Z\t-1819240775\n" + - "-1819240775\tKK\t2016-05-01T11:04:00.000Z\t-1201923128\n" + - "-1787109293\tAX\t2016-05-01T11:05:00.000Z\t-1515787781\n" + - "-1515787781\tAX\t2016-05-01T11:06:00.000Z\t636045524\n" + - "161592763\tBZ\t2016-05-01T11:07:00.000Z\t-1299391311\n" + - "636045524\tAX\t2016-05-01T11:08:00.000Z\t-1538602195\n" + - "-1538602195\tAX\t2016-05-01T11:09:00.000Z\t-443320374\n" + - "-372268574\tXX\t2016-05-01T11:10:00.000Z\t-10505757\n" + - "-1299391311\tBZ\t2016-05-01T11:11:00.000Z\t1857212401\n" + - "-10505757\tXX\t2016-05-01T11:12:00.000Z\t-1566901076\n" + - "1857212401\tBZ\t2016-05-01T11:13:00.000Z\t1196016669\n" + - "-443320374\tAX\t2016-05-01T11:14:00.000Z\t1234796102\n" + - "1196016669\tBZ\t2016-05-01T11:15:00.000Z\t532665695\n" + - "-1566901076\tXX\t2016-05-01T11:16:00.000Z\t1876812930\n" + - "-1201923128\tKK\t2016-05-01T11:17:00.000Z\t-1582495445\n" + - "1876812930\tXX\t2016-05-01T11:18:00.000Z\t-1172180184\n" + - "-1582495445\tKK\t2016-05-01T11:19:00.000Z\t-45567293\n" + - "532665695\tBZ\t2016-05-01T11:20:00.000Z\t-373499303\n" + - "1234796102\tAX\t2016-05-01T11:21:00.000Z\t114747951\n" + - "-45567293\tKK\t2016-05-01T11:22:00.000Z\t-916132123\n" + - "-373499303\tBZ\t2016-05-01T11:23:00.000Z\t-1723887671\n" + - "-916132123\tKK\t2016-05-01T11:24:00.000Z\t-731466113\n" + - "114747951\tAX\t2016-05-01T11:25:00.000Z\t-1794809330\n" + - "-1794809330\tAX\t2016-05-01T11:26:00.000Z\t-882371473\n" + - "-731466113\tKK\t2016-05-01T11:27:00.000Z\t-2075675260\n" + - "-882371473\tAX\t2016-05-01T11:28:00.000Z\t1235206821\n" + - "-1723887671\tBZ\t2016-05-01T11:29:00.000Z\t-712702244\n" + - "-1172180184\tXX\t2016-05-01T11:30:00.000Z\t865832060\n" + - "-2075675260\tKK\t2016-05-01T11:31:00.000Z\t-1768335227\n" + - "-712702244\tBZ\t2016-05-01T11:32:00.000Z\t1795359355\n" + - "-1768335227\tKK\t2016-05-01T11:33:00.000Z\t-1966408995\n" + - "1235206821\tAX\t2016-05-01T11:34:00.000Z\t838743782\n" + - "1795359355\tBZ\t2016-05-01T11:35:00.000Z\t-876466531\n" + - "-876466531\tBZ\t2016-05-01T11:36:00.000Z\t-2043803188\n" + - "865832060\tXX\t2016-05-01T11:37:00.000Z\t614536941\n" + - "-1966408995\tKK\t2016-05-01T11:38:00.000Z\t1107889075\n" + - "838743782\tAX\t2016-05-01T11:39:00.000Z\t-618037497\n" + - "1107889075\tKK\t2016-05-01T11:40:00.000Z\t-68027832\n" + - "-618037497\tAX\t2016-05-01T11:41:00.000Z\t519895483\n" + - "-2043803188\tBZ\t2016-05-01T11:42:00.000Z\t1658228795\n" + - "-68027832\tKK\t2016-05-01T11:43:00.000Z\t-2088317486\n" + - "519895483\tAX\t2016-05-01T11:44:00.000Z\t602835017\n" + - "-2088317486\tKK\t2016-05-01T11:45:00.000Z\t-283321892\n" + - "602835017\tAX\t2016-05-01T11:46:00.000Z\t-2111250190\n" + - "-2111250190\tAX\t2016-05-01T11:47:00.000Z\t1598679468\n" + - "614536941\tXX\t2016-05-01T11:48:00.000Z\t1015055928\n" + - "1598679468\tAX\t2016-05-01T11:49:00.000Z\t1362833895\n" + - "1658228795\tBZ\t2016-05-01T11:50:00.000Z\t1238491107\n" + - "-283321892\tKK\t2016-05-01T11:51:00.000Z\t116799613\n" + - "116799613\tKK\t2016-05-01T11:52:00.000Z\t-636975106\n" + - "1238491107\tBZ\t2016-05-01T11:53:00.000Z\t1100812407\n" + - "-636975106\tKK\t2016-05-01T11:54:00.000Z\t-640305320\n" + - "1015055928\tXX\t2016-05-01T11:55:00.000Z\tNaN\n" + - "1100812407\tBZ\t2016-05-01T11:56:00.000Z\t1751526583\n" + - "1362833895\tAX\t2016-05-01T11:57:00.000Z\t-805434743\n" + - "-805434743\tAX\t2016-05-01T11:58:00.000Z\tNaN\n" + - "-640305320\tKK\t2016-05-01T11:59:00.000Z\tNaN\n" + - "1751526583\tBZ\t2016-05-01T12:00:00.000Z\tNaN\n"; - - @Test - public void testAnalyticSymbolBehaviour() throws Exception { - assertSymbol("select l, str, sym, timestamp , next(sym) over (partition by str) from abc", 4); - assertSymbol("select l, str, sym, timestamp , next(sym) over (partition by str) from '*!*abc'", 4); - } - - @Test - public void testBoolean() throws Exception { - final String expected = "true\tBZ\tBZ\t2016-05-01T10:21:00.000Z\tfalse\n" + - "false\tXX\tBZ\t2016-05-01T10:22:00.000Z\tfalse\n" + - "false\tKK\tXX\t2016-05-01T10:23:00.000Z\tfalse\n" + - "false\tAX\tXX\t2016-05-01T10:24:00.000Z\ttrue\n" + - "true\tAX\tXX\t2016-05-01T10:25:00.000Z\ttrue\n" + - "true\tAX\tBZ\t2016-05-01T10:26:00.000Z\tfalse\n" + - "false\tBZ\tXX\t2016-05-01T10:27:00.000Z\ttrue\n" + - "true\tBZ\tKK\t2016-05-01T10:28:00.000Z\tfalse\n" + - "false\tAX\tKK\t2016-05-01T10:29:00.000Z\tfalse\n" + - "false\tBZ\tAX\t2016-05-01T10:30:00.000Z\tfalse\n" + - "false\tXX\tKK\t2016-05-01T10:31:00.000Z\ttrue\n" + - "false\tKK\tAX\t2016-05-01T10:32:00.000Z\tfalse\n" + - "false\tAX\tAX\t2016-05-01T10:33:00.000Z\ttrue\n" + - "false\tBZ\tBZ\t2016-05-01T10:34:00.000Z\tfalse\n" + - "true\tXX\tAX\t2016-05-01T10:35:00.000Z\ttrue\n" + - "true\tAX\tAX\t2016-05-01T10:36:00.000Z\ttrue\n" + - "true\tXX\tKK\t2016-05-01T10:37:00.000Z\tfalse\n" + - "true\tAX\tAX\t2016-05-01T10:38:00.000Z\tfalse\n" + - "false\tBZ\tBZ\t2016-05-01T10:39:00.000Z\tfalse\n" + - "false\tBZ\tAX\t2016-05-01T10:40:00.000Z\tfalse\n"; - assertThat(expected, "select boo, str, sym, timestamp , next(boo) over (partition by str) from abc"); - assertThat(expected, "select boo, str, sym, timestamp , next(boo) over (partition by str) from '*!*abc'"); - } - - @Test - public void testByte() throws Exception { - final String expected = "21\tBZ\tBZ\t2016-05-01T10:21:00.000Z\t53\n" + - "-120\tXX\tBZ\t2016-05-01T10:22:00.000Z\t-126\n" + - "-34\tKK\tXX\t2016-05-01T10:23:00.000Z\t-114\n" + - "-60\tAX\tXX\t2016-05-01T10:24:00.000Z\t-95\n" + - "-95\tAX\tXX\t2016-05-01T10:25:00.000Z\t-40\n" + - "-40\tAX\tBZ\t2016-05-01T10:26:00.000Z\t-69\n" + - "53\tBZ\tXX\t2016-05-01T10:27:00.000Z\t77\n" + - "77\tBZ\tKK\t2016-05-01T10:28:00.000Z\t-15\n" + - "-69\tAX\tKK\t2016-05-01T10:29:00.000Z\t-55\n" + - "-15\tBZ\tAX\t2016-05-01T10:30:00.000Z\t-72\n" + - "-126\tXX\tKK\t2016-05-01T10:31:00.000Z\t-77\n" + - "-114\tKK\tAX\t2016-05-01T10:32:00.000Z\t0\n" + - "-55\tAX\tAX\t2016-05-01T10:33:00.000Z\t-83\n" + - "-72\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t-114\n" + - "-77\tXX\tAX\t2016-05-01T10:35:00.000Z\t-36\n" + - "-83\tAX\tAX\t2016-05-01T10:36:00.000Z\t-102\n" + - "-36\tXX\tKK\t2016-05-01T10:37:00.000Z\t0\n" + - "-102\tAX\tAX\t2016-05-01T10:38:00.000Z\t0\n" + - "-114\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t70\n" + - "70\tBZ\tAX\t2016-05-01T10:40:00.000Z\t0\n"; - assertThat(expected, "select b, str, sym, timestamp , next(b) over (partition by str) from abc"); - assertThat(expected, "select b, str, sym, timestamp , next(b) over (partition by str) from '*!*abc'"); - } - - @Test - public void testCompilation() throws Exception { - assertThat(expected, "select i, str, timestamp, next(i) over (partition by str) from xyz"); - } - - @Test - public void testCompileNonPart() throws Exception { - final String expected = "-1148479920\tBZ\t2016-05-01T10:21:00.000Z\t1548800833\n" + - "1548800833\tKK\t2016-05-01T10:22:00.000Z\t73575701\n" + - "73575701\tKK\t2016-05-01T10:23:00.000Z\t1326447242\n" + - "1326447242\tKK\t2016-05-01T10:24:00.000Z\t1868723706\n" + - "1868723706\tAX\t2016-05-01T10:25:00.000Z\t-1191262516\n" + - "-1191262516\tAX\t2016-05-01T10:26:00.000Z\t-1436881714\n" + - "-1436881714\tKK\t2016-05-01T10:27:00.000Z\t806715481\n" + - "806715481\tAX\t2016-05-01T10:28:00.000Z\t1569490116\n" + - "1569490116\tXX\t2016-05-01T10:29:00.000Z\t-409854405\n" + - "-409854405\tBZ\t2016-05-01T10:30:00.000Z\t1530831067\n" + - "1530831067\tKK\t2016-05-01T10:31:00.000Z\t-1532328444\n" + - "-1532328444\tXX\t2016-05-01T10:32:00.000Z\t1125579207\n" + - "1125579207\tAX\t2016-05-01T10:33:00.000Z\t-1432278050\n" + - "-1432278050\tAX\t2016-05-01T10:34:00.000Z\t-85170055\n" + - "-85170055\tAX\t2016-05-01T10:35:00.000Z\t-1844391305\n" + - "-1844391305\tKK\t2016-05-01T10:36:00.000Z\t-1101822104\n" + - "-1101822104\tKK\t2016-05-01T10:37:00.000Z\t1404198\n" + - "1404198\tXX\t2016-05-01T10:38:00.000Z\t-1125169127\n" + - "-1125169127\tAX\t2016-05-01T10:39:00.000Z\t-1975183723\n" + - "-1975183723\tAX\t2016-05-01T10:40:00.000Z\t1232884790\n" + - "1232884790\tXX\t2016-05-01T10:41:00.000Z\t-2119387831\n" + - "-2119387831\tAX\t2016-05-01T10:42:00.000Z\t1699553881\n" + - "1699553881\tBZ\t2016-05-01T10:43:00.000Z\t1253890363\n" + - "1253890363\tAX\t2016-05-01T10:44:00.000Z\t-422941535\n" + - "-422941535\tBZ\t2016-05-01T10:45:00.000Z\t-547127752\n" + - "-547127752\tKK\t2016-05-01T10:46:00.000Z\t-303295973\n" + - "-303295973\tBZ\t2016-05-01T10:47:00.000Z\t-2132716300\n" + - "-2132716300\tAX\t2016-05-01T10:48:00.000Z\t-461611463\n" + - "-461611463\tKK\t2016-05-01T10:49:00.000Z\t264240638\n" + - "264240638\tAX\t2016-05-01T10:50:00.000Z\t-483853667\n" + - "-483853667\tAX\t2016-05-01T10:51:00.000Z\t1890602616\n" + - "1890602616\tBZ\t2016-05-01T10:52:00.000Z\t68265578\n" + - "68265578\tBZ\t2016-05-01T10:53:00.000Z\t-2002373666\n" + - "-2002373666\tAX\t2016-05-01T10:54:00.000Z\t458818940\n" + - "458818940\tBZ\t2016-05-01T10:55:00.000Z\t-2144581835\n" + - "-2144581835\tKK\t2016-05-01T10:56:00.000Z\t-1418341054\n" + - "-1418341054\tAX\t2016-05-01T10:57:00.000Z\t2031014705\n" + - "2031014705\tKK\t2016-05-01T10:58:00.000Z\t-1575135393\n" + - "-1575135393\tXX\t2016-05-01T10:59:00.000Z\t936627841\n" + - "936627841\tKK\t2016-05-01T11:00:00.000Z\t-667031149\n" + - "-667031149\tKK\t2016-05-01T11:01:00.000Z\t-2034804966\n" + - "-2034804966\tBZ\t2016-05-01T11:02:00.000Z\t1637847416\n" + - "1637847416\tKK\t2016-05-01T11:03:00.000Z\t-1819240775\n" + - "-1819240775\tKK\t2016-05-01T11:04:00.000Z\t-1787109293\n" + - "-1787109293\tAX\t2016-05-01T11:05:00.000Z\t-1515787781\n" + - "-1515787781\tAX\t2016-05-01T11:06:00.000Z\t161592763\n" + - "161592763\tBZ\t2016-05-01T11:07:00.000Z\t636045524\n" + - "636045524\tAX\t2016-05-01T11:08:00.000Z\t-1538602195\n" + - "-1538602195\tAX\t2016-05-01T11:09:00.000Z\t-372268574\n" + - "-372268574\tXX\t2016-05-01T11:10:00.000Z\t-1299391311\n" + - "-1299391311\tBZ\t2016-05-01T11:11:00.000Z\t-10505757\n" + - "-10505757\tXX\t2016-05-01T11:12:00.000Z\t1857212401\n" + - "1857212401\tBZ\t2016-05-01T11:13:00.000Z\t-443320374\n" + - "-443320374\tAX\t2016-05-01T11:14:00.000Z\t1196016669\n" + - "1196016669\tBZ\t2016-05-01T11:15:00.000Z\t-1566901076\n" + - "-1566901076\tXX\t2016-05-01T11:16:00.000Z\t-1201923128\n" + - "-1201923128\tKK\t2016-05-01T11:17:00.000Z\t1876812930\n" + - "1876812930\tXX\t2016-05-01T11:18:00.000Z\t-1582495445\n" + - "-1582495445\tKK\t2016-05-01T11:19:00.000Z\t532665695\n" + - "532665695\tBZ\t2016-05-01T11:20:00.000Z\t1234796102\n" + - "1234796102\tAX\t2016-05-01T11:21:00.000Z\t-45567293\n" + - "-45567293\tKK\t2016-05-01T11:22:00.000Z\t-373499303\n" + - "-373499303\tBZ\t2016-05-01T11:23:00.000Z\t-916132123\n" + - "-916132123\tKK\t2016-05-01T11:24:00.000Z\t114747951\n" + - "114747951\tAX\t2016-05-01T11:25:00.000Z\t-1794809330\n" + - "-1794809330\tAX\t2016-05-01T11:26:00.000Z\t-731466113\n" + - "-731466113\tKK\t2016-05-01T11:27:00.000Z\t-882371473\n" + - "-882371473\tAX\t2016-05-01T11:28:00.000Z\t-1723887671\n" + - "-1723887671\tBZ\t2016-05-01T11:29:00.000Z\t-1172180184\n" + - "-1172180184\tXX\t2016-05-01T11:30:00.000Z\t-2075675260\n" + - "-2075675260\tKK\t2016-05-01T11:31:00.000Z\t-712702244\n" + - "-712702244\tBZ\t2016-05-01T11:32:00.000Z\t-1768335227\n" + - "-1768335227\tKK\t2016-05-01T11:33:00.000Z\t1235206821\n" + - "1235206821\tAX\t2016-05-01T11:34:00.000Z\t1795359355\n" + - "1795359355\tBZ\t2016-05-01T11:35:00.000Z\t-876466531\n" + - "-876466531\tBZ\t2016-05-01T11:36:00.000Z\t865832060\n" + - "865832060\tXX\t2016-05-01T11:37:00.000Z\t-1966408995\n" + - "-1966408995\tKK\t2016-05-01T11:38:00.000Z\t838743782\n" + - "838743782\tAX\t2016-05-01T11:39:00.000Z\t1107889075\n" + - "1107889075\tKK\t2016-05-01T11:40:00.000Z\t-618037497\n" + - "-618037497\tAX\t2016-05-01T11:41:00.000Z\t-2043803188\n" + - "-2043803188\tBZ\t2016-05-01T11:42:00.000Z\t-68027832\n" + - "-68027832\tKK\t2016-05-01T11:43:00.000Z\t519895483\n" + - "519895483\tAX\t2016-05-01T11:44:00.000Z\t-2088317486\n" + - "-2088317486\tKK\t2016-05-01T11:45:00.000Z\t602835017\n" + - "602835017\tAX\t2016-05-01T11:46:00.000Z\t-2111250190\n" + - "-2111250190\tAX\t2016-05-01T11:47:00.000Z\t614536941\n" + - "614536941\tXX\t2016-05-01T11:48:00.000Z\t1598679468\n" + - "1598679468\tAX\t2016-05-01T11:49:00.000Z\t1658228795\n" + - "1658228795\tBZ\t2016-05-01T11:50:00.000Z\t-283321892\n" + - "-283321892\tKK\t2016-05-01T11:51:00.000Z\t116799613\n" + - "116799613\tKK\t2016-05-01T11:52:00.000Z\t1238491107\n" + - "1238491107\tBZ\t2016-05-01T11:53:00.000Z\t-636975106\n" + - "-636975106\tKK\t2016-05-01T11:54:00.000Z\t1015055928\n" + - "1015055928\tXX\t2016-05-01T11:55:00.000Z\t1100812407\n" + - "1100812407\tBZ\t2016-05-01T11:56:00.000Z\t1362833895\n" + - "1362833895\tAX\t2016-05-01T11:57:00.000Z\t-805434743\n" + - "-805434743\tAX\t2016-05-01T11:58:00.000Z\t-640305320\n" + - "-640305320\tKK\t2016-05-01T11:59:00.000Z\t1751526583\n" + - "1751526583\tBZ\t2016-05-01T12:00:00.000Z\tNaN\n"; - assertThat(expected, "select i, str, timestamp, next(i) over () from xyz"); - assertThat(expected, "select i, str, timestamp, next(i) over () from '*!*xyz'"); - } - - @Test - public void testDate() throws Exception { - final String expected = "277433687-10-12T08:51:21.932Z\tBZ\tBZ\t2016-05-01T10:21:00.000Z\t231478896-06-17T12:18:04.767Z\n" + - "-284210729-04-16T06:37:25.107Z\tXX\tBZ\t2016-05-01T10:22:00.000Z\t-201714876-08-10T10:14:48.134Z\n" + - "-142145720-12-30T10:07:22.984Z\tKK\tXX\t2016-05-01T10:23:00.000Z\t132059357-01-03T08:27:45.836Z\n" + - "-268695905-10-25T00:06:37.492Z\tAX\tXX\t2016-05-01T10:24:00.000Z\t217217443-02-16T18:39:59.220Z\n" + - "217217443-02-16T18:39:59.220Z\tAX\tXX\t2016-05-01T10:25:00.000Z\t263840408-06-11T18:15:05.778Z\n" + - "263840408-06-11T18:15:05.778Z\tAX\tBZ\t2016-05-01T10:26:00.000Z\t-230266796-08-17T22:57:03.970Z\n" + - "231478896-06-17T12:18:04.767Z\tBZ\tXX\t2016-05-01T10:27:00.000Z\t220352915-01-17T00:08:45.841Z\n" + - "220352915-01-17T00:08:45.841Z\tBZ\tKK\t2016-05-01T10:28:00.000Z\t18125533-09-05T04:06:38.086Z\n" + - "-230266796-08-17T22:57:03.970Z\tAX\tKK\t2016-05-01T10:29:00.000Z\t-253361973-02-05T02:07:37.180Z\n" + - "18125533-09-05T04:06:38.086Z\tBZ\tAX\t2016-05-01T10:30:00.000Z\t-180947413-05-05T10:19:58.733Z\n" + - "-201714876-08-10T10:14:48.134Z\tXX\tKK\t2016-05-01T10:31:00.000Z\t-225086326-11-23T21:53:40.936Z\n" + - "132059357-01-03T08:27:45.836Z\tKK\tAX\t2016-05-01T10:32:00.000Z\t\n" + - "-253361973-02-05T02:07:37.180Z\tAX\tAX\t2016-05-01T10:33:00.000Z\t252677978-05-07T03:29:33.753Z\n" + - "-180947413-05-05T10:19:58.733Z\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t167791211-12-09T07:52:02.538Z\n" + - "-225086326-11-23T21:53:40.936Z\tXX\tAX\t2016-05-01T10:35:00.000Z\t-244304870-03-25T17:50:45.758Z\n" + - "252677978-05-07T03:29:33.753Z\tAX\tAX\t2016-05-01T10:36:00.000Z\t-196068605-07-20T05:32:43.747Z\n" + - "-244304870-03-25T17:50:45.758Z\tXX\tKK\t2016-05-01T10:37:00.000Z\t\n" + - "-196068605-07-20T05:32:43.747Z\tAX\tAX\t2016-05-01T10:38:00.000Z\t\n" + - "167791211-12-09T07:52:02.538Z\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t-56977607-10-20T13:10:29.515Z\n" + - "-56977607-10-20T13:10:29.515Z\tBZ\tAX\t2016-05-01T10:40:00.000Z\t\n"; - assertThat(expected, "select date, str, sym, timestamp , next(date) over (partition by str) from abc"); - assertThat(expected, "select date, str, sym, timestamp , next(date) over (partition by str) from '*!*abc'"); - } - - @Test - public void testDifferentOrderByRowId() throws Exception { - final String result = "sho\tstr\tsym\ttimestamp\tblah\tcol0\tcol1\tcol2\n" + - "-19496\tBZ\tBZ\t2016-05-01T10:21:00.000Z\t-24357\tXX\tXX\t-20409\n" + - "-24357\tXX\tBZ\t2016-05-01T10:22:00.000Z\t21781\tKK\tKK\t-391\n" + - "21781\tKK\tXX\t2016-05-01T10:23:00.000Z\t-19127\tAX\tAX\t-24455\n" + - "-19127\tAX\tXX\t2016-05-01T10:24:00.000Z\t-15458\tXX\tXX\t-19496\n" + - "-15458\tAX\tXX\t2016-05-01T10:25:00.000Z\t-22934\tBZ\tBZ\t11755\n" + - "-22934\tAX\tBZ\t2016-05-01T10:26:00.000Z\t-391\tKK\tKK\t0\n" + - "-391\tBZ\tXX\t2016-05-01T10:27:00.000Z\t-26951\tKK\tKK\t25974\n" + - "-26951\tBZ\tKK\t2016-05-01T10:28:00.000Z\t-19136\tAX\tAX\t-15331\n" + - "-19136\tAX\tKK\t2016-05-01T10:29:00.000Z\t-15331\tAX\tAX\t-4874\n" + - "-15331\tBZ\tAX\t2016-05-01T10:30:00.000Z\t-4874\tBZ\tBZ\t5869\n" + - "-4874\tXX\tKK\t2016-05-01T10:31:00.000Z\t25102\tAX\tAX\t21781\n" + - "25102\tKK\tAX\t2016-05-01T10:32:00.000Z\t-20409\t\t\t-26951\n" + - "-20409\tAX\tAX\t2016-05-01T10:33:00.000Z\t-29572\tAX\tAX\t25102\n" + - "-29572\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t25974\tBZ\tBZ\t-18600\n" + - "25974\tXX\tAX\t2016-05-01T10:35:00.000Z\t5869\tKK\tKK\t-19136\n" + - "5869\tAX\tAX\t2016-05-01T10:36:00.000Z\t-22894\tAX\tAX\t-22894\n" + - "-22894\tXX\tKK\t2016-05-01T10:37:00.000Z\t-18600\t\t\t-15458\n" + - "-18600\tAX\tAX\t2016-05-01T10:38:00.000Z\t11755\t\t\t-19127\n" + - "11755\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t-24455\tAX\tAX\t-22934\n" + - "-24455\tBZ\tAX\t2016-05-01T10:40:00.000Z\t0\t\t\t-29572\n"; - - assertThat(result, - "select sho, str, sym, timestamp, " + - "next(sho) blah over (order by timestamp), " + - "next(sym) over (partition by str order by timestamp), " + - "next(sym) over (partition by str), " + - "next(sho) over (order by i) " + - "from '*!*abc'", true); - } - - @Test - public void testDouble() throws Exception { - final String expected = "1.050231933594\tBZ\tBZ\t2016-05-01T10:21:00.000Z\t0.332301996648\n" + - "566.734375000000\tXX\tBZ\t2016-05-01T10:22:00.000Z\t0.000002473130\n" + - "0.000013792171\tKK\tXX\t2016-05-01T10:23:00.000Z\t632.921875000000\n" + - "0.000000567185\tAX\tXX\t2016-05-01T10:24:00.000Z\t-512.000000000000\n" + - "-512.000000000000\tAX\tXX\t2016-05-01T10:25:00.000Z\t0.675451681018\n" + - "0.675451681018\tAX\tBZ\t2016-05-01T10:26:00.000Z\t0.000076281818\n" + - "0.332301996648\tBZ\tXX\t2016-05-01T10:27:00.000Z\t0.000001752813\n" + - "0.000001752813\tBZ\tKK\t2016-05-01T10:28:00.000Z\t0.000000005555\n" + - "0.000076281818\tAX\tKK\t2016-05-01T10:29:00.000Z\t0.000000020896\n" + - "0.000000005555\tBZ\tAX\t2016-05-01T10:30:00.000Z\t0.007371325744\n" + - "0.000002473130\tXX\tKK\t2016-05-01T10:31:00.000Z\t0.000000014643\n" + - "632.921875000000\tKK\tAX\t2016-05-01T10:32:00.000Z\tNaN\n" + - "0.000000020896\tAX\tAX\t2016-05-01T10:33:00.000Z\t512.000000000000\n" + - "0.007371325744\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t-842.000000000000\n" + - "0.000000014643\tXX\tAX\t2016-05-01T10:35:00.000Z\t864.000000000000\n" + - "512.000000000000\tAX\tAX\t2016-05-01T10:36:00.000Z\t0.000000157437\n" + - "864.000000000000\tXX\tKK\t2016-05-01T10:37:00.000Z\tNaN\n" + - "0.000000157437\tAX\tAX\t2016-05-01T10:38:00.000Z\tNaN\n" + - "-842.000000000000\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t0.000032060649\n" + - "0.000032060649\tBZ\tAX\t2016-05-01T10:40:00.000Z\tNaN\n"; - assertThat(expected, "select d, str, sym, timestamp , next(d) over (partition by str) from abc"); - assertThat(expected, "select d, str, sym, timestamp , next(d) over (partition by str) from '*!*abc'"); - } - - @Test - public void testFloat() throws Exception { - final String expected = "0.6235\tBZ\tBZ\t2016-05-01T10:21:00.000Z\t0.5725\n" + - "0.7780\tXX\tBZ\t2016-05-01T10:22:00.000Z\t0.7274\n" + - "0.5509\tKK\tXX\t2016-05-01T10:23:00.000Z\t0.5619\n" + - "0.0204\tAX\tXX\t2016-05-01T10:24:00.000Z\t0.4848\n" + - "0.4848\tAX\tXX\t2016-05-01T10:25:00.000Z\t0.2969\n" + - "0.2969\tAX\tBZ\t2016-05-01T10:26:00.000Z\t0.1609\n" + - "0.5725\tBZ\tXX\t2016-05-01T10:27:00.000Z\t0.5967\n" + - "0.5967\tBZ\tKK\t2016-05-01T10:28:00.000Z\t0.3509\n" + - "0.1609\tAX\tKK\t2016-05-01T10:29:00.000Z\t0.5433\n" + - "0.3509\tBZ\tAX\t2016-05-01T10:30:00.000Z\t0.5442\n" + - "0.7274\tXX\tKK\t2016-05-01T10:31:00.000Z\t0.6746\n" + - "0.5619\tKK\tAX\t2016-05-01T10:32:00.000Z\tNaN\n" + - "0.5433\tAX\tAX\t2016-05-01T10:33:00.000Z\t0.8217\n" + - "0.5442\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t0.1168\n" + - "0.6746\tXX\tAX\t2016-05-01T10:35:00.000Z\t0.3591\n" + - "0.8217\tAX\tAX\t2016-05-01T10:36:00.000Z\t0.6827\n" + - "0.3591\tXX\tKK\t2016-05-01T10:37:00.000Z\tNaN\n" + - "0.6827\tAX\tAX\t2016-05-01T10:38:00.000Z\tNaN\n" + - "0.1168\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t0.4967\n" + - "0.4967\tBZ\tAX\t2016-05-01T10:40:00.000Z\tNaN\n"; - assertThat(expected, "select f, str, sym, timestamp , next(f) over (partition by str) from abc"); - assertThat(expected, "select f, str, sym, timestamp , next(f) over (partition by str) from '*!*abc'"); - } - - @Test - public void testLong() throws Exception { - final String expected = "8920866532787660373\tBZ\tBZ\t2016-05-01T10:21:00.000Z\t-6253307669002054137\n" + - "-6943924477733600060\tXX\tBZ\t2016-05-01T10:22:00.000Z\t-7387846268299105911\n" + - "-6856503215590263904\tKK\tXX\t2016-05-01T10:23:00.000Z\t7122109662042058469\n" + - "8416773233910814357\tAX\tXX\t2016-05-01T10:24:00.000Z\t7199909180655756830\n" + - "7199909180655756830\tAX\tXX\t2016-05-01T10:25:00.000Z\t6270672455202306717\n" + - "6270672455202306717\tAX\tBZ\t2016-05-01T10:26:00.000Z\t-7316123607359392486\n" + - "-6253307669002054137\tBZ\tXX\t2016-05-01T10:27:00.000Z\t7392877322819819290\n" + - "7392877322819819290\tBZ\tKK\t2016-05-01T10:28:00.000Z\t-3107239868490395663\n" + - "-7316123607359392486\tAX\tKK\t2016-05-01T10:29:00.000Z\t-6626590012581323602\n" + - "-3107239868490395663\tBZ\tAX\t2016-05-01T10:30:00.000Z\t8611582118025429627\n" + - "-7387846268299105911\tXX\tKK\t2016-05-01T10:31:00.000Z\t-8082754367165748693\n" + - "7122109662042058469\tKK\tAX\t2016-05-01T10:32:00.000Z\tNaN\n" + - "-6626590012581323602\tAX\tAX\t2016-05-01T10:33:00.000Z\t6574958665733670985\n" + - "8611582118025429627\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t8152044974329490473\n" + - "-8082754367165748693\tXX\tAX\t2016-05-01T10:35:00.000Z\t3446015290144635451\n" + - "6574958665733670985\tAX\tAX\t2016-05-01T10:36:00.000Z\t8889492928577876455\n" + - "3446015290144635451\tXX\tKK\t2016-05-01T10:37:00.000Z\tNaN\n" + - "8889492928577876455\tAX\tAX\t2016-05-01T10:38:00.000Z\tNaN\n" + - "8152044974329490473\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t-6071768268784020226\n" + - "-6071768268784020226\tBZ\tAX\t2016-05-01T10:40:00.000Z\tNaN\n"; - assertThat(expected, "select l, str, sym, timestamp , next(l) over (partition by str) from abc"); - assertThat(expected, "select l, str, sym, timestamp , next(l) over (partition by str) from '*!*abc'"); - } - - @Test - public void testNoArg() { - try { - expectFailure("select str, next() rank over(partition by str) from 'abc'"); - } catch (ParserException e) { - TestUtils.assertEquals("Unknown function", QueryError.getMessage()); - } - } - - @Test - public void testNonPartAnalyticSymbolBehaviour() throws Exception { - assertSymbol("select l, str, sym, timestamp , next(sym) over () from abc", 4); - } - - @Test - public void testPlan() throws Exception { - assertPlan2("{\n" + - " \"op\": \"SelectedColumnsRecordSource\",\n" + - " \"src\": {\n" + - " \"op\": \"CachedRowAnalyticRecordSource\",\n" + - " \"functions\": 1,\n" + - " \"orderedSources\": 1,\n" + - " \"src\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"abc\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " }\n" + - " }\n" + - "}", - "select str, sym, timestamp , next(sym) over (partition by str) from abc"); - } - - @Test - public void testShort() throws Exception { - final String expected = "-19496\tBZ\tBZ\t2016-05-01T10:21:00.000Z\t-391\n" + - "-24357\tXX\tBZ\t2016-05-01T10:22:00.000Z\t-4874\n" + - "21781\tKK\tXX\t2016-05-01T10:23:00.000Z\t25102\n" + - "-19127\tAX\tXX\t2016-05-01T10:24:00.000Z\t-15458\n" + - "-15458\tAX\tXX\t2016-05-01T10:25:00.000Z\t-22934\n" + - "-22934\tAX\tBZ\t2016-05-01T10:26:00.000Z\t-19136\n" + - "-391\tBZ\tXX\t2016-05-01T10:27:00.000Z\t-26951\n" + - "-26951\tBZ\tKK\t2016-05-01T10:28:00.000Z\t-15331\n" + - "-19136\tAX\tKK\t2016-05-01T10:29:00.000Z\t-20409\n" + - "-15331\tBZ\tAX\t2016-05-01T10:30:00.000Z\t-29572\n" + - "-4874\tXX\tKK\t2016-05-01T10:31:00.000Z\t25974\n" + - "25102\tKK\tAX\t2016-05-01T10:32:00.000Z\t0\n" + - "-20409\tAX\tAX\t2016-05-01T10:33:00.000Z\t5869\n" + - "-29572\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t11755\n" + - "25974\tXX\tAX\t2016-05-01T10:35:00.000Z\t-22894\n" + - "5869\tAX\tAX\t2016-05-01T10:36:00.000Z\t-18600\n" + - "-22894\tXX\tKK\t2016-05-01T10:37:00.000Z\t0\n" + - "-18600\tAX\tAX\t2016-05-01T10:38:00.000Z\t0\n" + - "11755\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t-24455\n" + - "-24455\tBZ\tAX\t2016-05-01T10:40:00.000Z\t0\n"; - assertThat(expected, "select sho, str, sym, timestamp , next(sho) over (partition by str) from abc"); - assertThat(expected, "select sho, str, sym, timestamp , next(sho) over (partition by str) from '*!*abc'"); - } - - @Test - public void testShort2() throws Exception { - final String expected = "-19496\tBZ\tBZ\t2016-05-01T10:21:00.000Z\t-24357\n" + - "-24357\tXX\tBZ\t2016-05-01T10:22:00.000Z\t21781\n" + - "21781\tKK\tXX\t2016-05-01T10:23:00.000Z\t-19127\n" + - "-19127\tAX\tXX\t2016-05-01T10:24:00.000Z\t-15458\n" + - "-15458\tAX\tXX\t2016-05-01T10:25:00.000Z\t-22934\n" + - "-22934\tAX\tBZ\t2016-05-01T10:26:00.000Z\t-391\n" + - "-391\tBZ\tXX\t2016-05-01T10:27:00.000Z\t-26951\n" + - "-26951\tBZ\tKK\t2016-05-01T10:28:00.000Z\t-19136\n" + - "-19136\tAX\tKK\t2016-05-01T10:29:00.000Z\t-15331\n" + - "-15331\tBZ\tAX\t2016-05-01T10:30:00.000Z\t-4874\n" + - "-4874\tXX\tKK\t2016-05-01T10:31:00.000Z\t25102\n" + - "25102\tKK\tAX\t2016-05-01T10:32:00.000Z\t-20409\n" + - "-20409\tAX\tAX\t2016-05-01T10:33:00.000Z\t-29572\n" + - "-29572\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t25974\n" + - "25974\tXX\tAX\t2016-05-01T10:35:00.000Z\t5869\n" + - "5869\tAX\tAX\t2016-05-01T10:36:00.000Z\t-22894\n" + - "-22894\tXX\tKK\t2016-05-01T10:37:00.000Z\t-18600\n" + - "-18600\tAX\tAX\t2016-05-01T10:38:00.000Z\t11755\n" + - "11755\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t-24455\n" + - "-24455\tBZ\tAX\t2016-05-01T10:40:00.000Z\t0\n"; - assertThat(expected, "select sho, str, sym, timestamp , next(sho) over () from abc"); - assertThat(expected, "select sho, str, sym, timestamp , next(sho) over () from '*!*abc'"); - } - - @Test - public void testShortAliased() throws Exception { - final String expected = "sho\tstr\tsym\ttimestamp\tblah\n" + - "-19496\tBZ\tBZ\t2016-05-01T10:21:00.000Z\t-391\n" + - "-24357\tXX\tBZ\t2016-05-01T10:22:00.000Z\t-4874\n" + - "21781\tKK\tXX\t2016-05-01T10:23:00.000Z\t25102\n" + - "-19127\tAX\tXX\t2016-05-01T10:24:00.000Z\t-15458\n" + - "-15458\tAX\tXX\t2016-05-01T10:25:00.000Z\t-22934\n" + - "-22934\tAX\tBZ\t2016-05-01T10:26:00.000Z\t-19136\n" + - "-391\tBZ\tXX\t2016-05-01T10:27:00.000Z\t-26951\n" + - "-26951\tBZ\tKK\t2016-05-01T10:28:00.000Z\t-15331\n" + - "-19136\tAX\tKK\t2016-05-01T10:29:00.000Z\t-20409\n" + - "-15331\tBZ\tAX\t2016-05-01T10:30:00.000Z\t-29572\n" + - "-4874\tXX\tKK\t2016-05-01T10:31:00.000Z\t25974\n" + - "25102\tKK\tAX\t2016-05-01T10:32:00.000Z\t0\n" + - "-20409\tAX\tAX\t2016-05-01T10:33:00.000Z\t5869\n" + - "-29572\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t11755\n" + - "25974\tXX\tAX\t2016-05-01T10:35:00.000Z\t-22894\n" + - "5869\tAX\tAX\t2016-05-01T10:36:00.000Z\t-18600\n" + - "-22894\tXX\tKK\t2016-05-01T10:37:00.000Z\t0\n" + - "-18600\tAX\tAX\t2016-05-01T10:38:00.000Z\t0\n" + - "11755\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t-24455\n" + - "-24455\tBZ\tAX\t2016-05-01T10:40:00.000Z\t0\n"; - assertThat(expected, "select sho, str, sym, timestamp , next(sho) blah over (partition by str) from abc", true); - assertThat(expected, "select sho, str, sym, timestamp , next(sho) blah over (partition by str) from '*!*abc'", true); - } - - @Test - public void testStr() throws Exception { - final String expected = "BZ\tBZ\t2016-05-01T10:21:00.000Z\tXX\n" + - "XX\tBZ\t2016-05-01T10:22:00.000Z\tAX\n" + - "KK\tXX\t2016-05-01T10:23:00.000Z\tAX\n" + - "AX\tXX\t2016-05-01T10:24:00.000Z\tAX\n" + - "AX\tXX\t2016-05-01T10:25:00.000Z\tBZ\n" + - "AX\tBZ\t2016-05-01T10:26:00.000Z\tBZ\n" + - "BZ\tXX\t2016-05-01T10:27:00.000Z\t\n" + - "BZ\tKK\t2016-05-01T10:28:00.000Z\tAX\n" + - "AX\tKK\t2016-05-01T10:29:00.000Z\tXX\n" + - "BZ\tAX\t2016-05-01T10:30:00.000Z\tKK\n" + - "XX\tKK\t2016-05-01T10:31:00.000Z\tXX\n" + - "KK\tAX\t2016-05-01T10:32:00.000Z\tAX\n" + - "AX\tAX\t2016-05-01T10:33:00.000Z\tXX\n" + - "BZ\tBZ\t2016-05-01T10:34:00.000Z\tBZ\n" + - "XX\tAX\t2016-05-01T10:35:00.000Z\tAX\n" + - "AX\tAX\t2016-05-01T10:36:00.000Z\tAX\n" + - "XX\tKK\t2016-05-01T10:37:00.000Z\t\n" + - "AX\tAX\t2016-05-01T10:38:00.000Z\tBZ\n" + - "BZ\tBZ\t2016-05-01T10:39:00.000Z\t\n" + - "BZ\tAX\t2016-05-01T10:40:00.000Z\t\n"; - assertThat(expected, "select str, sym, timestamp , next(str) over (partition by sym) from 'abc'"); - assertThat(expected, "select str, sym, timestamp , next(str) over (partition by sym) from '*!*abc'"); - } - - @Test - public void testStreamingAndTwoPass() throws Exception { - final String expected = "BZ\tBZ\t2016-05-01T10:21:00.000Z\tXX\t\n" + - "XX\tBZ\t2016-05-01T10:22:00.000Z\tKK\t\n" + - "KK\tXX\t2016-05-01T10:23:00.000Z\tAX\t\n" + - "AX\tXX\t2016-05-01T10:24:00.000Z\tXX\t\n" + - "AX\tXX\t2016-05-01T10:25:00.000Z\tBZ\tXX\n" + - "AX\tBZ\t2016-05-01T10:26:00.000Z\tKK\tXX\n" + - "BZ\tXX\t2016-05-01T10:27:00.000Z\tKK\tBZ\n" + - "BZ\tKK\t2016-05-01T10:28:00.000Z\tAX\tXX\n" + - "AX\tKK\t2016-05-01T10:29:00.000Z\tAX\tBZ\n" + - "BZ\tAX\t2016-05-01T10:30:00.000Z\tBZ\tKK\n" + - "XX\tKK\t2016-05-01T10:31:00.000Z\tAX\tBZ\n" + - "KK\tAX\t2016-05-01T10:32:00.000Z\t\tXX\n" + - "AX\tAX\t2016-05-01T10:33:00.000Z\tAX\tKK\n" + - "BZ\tBZ\t2016-05-01T10:34:00.000Z\tBZ\tAX\n" + - "XX\tAX\t2016-05-01T10:35:00.000Z\tKK\tKK\n" + - "AX\tAX\t2016-05-01T10:36:00.000Z\tAX\tAX\n" + - "XX\tKK\t2016-05-01T10:37:00.000Z\t\tAX\n" + - "AX\tAX\t2016-05-01T10:38:00.000Z\t\tAX\n" + - "BZ\tBZ\t2016-05-01T10:39:00.000Z\tAX\tBZ\n" + - "BZ\tAX\t2016-05-01T10:40:00.000Z\t\tBZ\n"; - assertThat(expected, "select str, sym, timestamp , next(sym) over (partition by str), prev(sym) over (partition by str) from abc"); - } - - @Test - public void testSymNonPart() throws Exception { - final String expected = "BZ\tBZ\t2016-05-01T10:21:00.000Z\tBZ\n" + - "XX\tBZ\t2016-05-01T10:22:00.000Z\tXX\n" + - "KK\tXX\t2016-05-01T10:23:00.000Z\tXX\n" + - "AX\tXX\t2016-05-01T10:24:00.000Z\tXX\n" + - "AX\tXX\t2016-05-01T10:25:00.000Z\tBZ\n" + - "AX\tBZ\t2016-05-01T10:26:00.000Z\tXX\n" + - "BZ\tXX\t2016-05-01T10:27:00.000Z\tKK\n" + - "BZ\tKK\t2016-05-01T10:28:00.000Z\tKK\n" + - "AX\tKK\t2016-05-01T10:29:00.000Z\tAX\n" + - "BZ\tAX\t2016-05-01T10:30:00.000Z\tKK\n" + - "XX\tKK\t2016-05-01T10:31:00.000Z\tAX\n" + - "KK\tAX\t2016-05-01T10:32:00.000Z\tAX\n" + - "AX\tAX\t2016-05-01T10:33:00.000Z\tBZ\n" + - "BZ\tBZ\t2016-05-01T10:34:00.000Z\tAX\n" + - "XX\tAX\t2016-05-01T10:35:00.000Z\tAX\n" + - "AX\tAX\t2016-05-01T10:36:00.000Z\tKK\n" + - "XX\tKK\t2016-05-01T10:37:00.000Z\tAX\n" + - "AX\tAX\t2016-05-01T10:38:00.000Z\tBZ\n" + - "BZ\tBZ\t2016-05-01T10:39:00.000Z\tAX\n" + - "BZ\tAX\t2016-05-01T10:40:00.000Z\t\n"; - assertThat(expected, "select str, sym, timestamp , next(sym) over () from abc"); - } - - @Test - public void testSymbol() throws Exception { - final String expected = "BZ\tBZ\t2016-05-01T10:21:00.000Z\tXX\n" + - "XX\tBZ\t2016-05-01T10:22:00.000Z\tKK\n" + - "KK\tXX\t2016-05-01T10:23:00.000Z\tAX\n" + - "AX\tXX\t2016-05-01T10:24:00.000Z\tXX\n" + - "AX\tXX\t2016-05-01T10:25:00.000Z\tBZ\n" + - "AX\tBZ\t2016-05-01T10:26:00.000Z\tKK\n" + - "BZ\tXX\t2016-05-01T10:27:00.000Z\tKK\n" + - "BZ\tKK\t2016-05-01T10:28:00.000Z\tAX\n" + - "AX\tKK\t2016-05-01T10:29:00.000Z\tAX\n" + - "BZ\tAX\t2016-05-01T10:30:00.000Z\tBZ\n" + - "XX\tKK\t2016-05-01T10:31:00.000Z\tAX\n" + - "KK\tAX\t2016-05-01T10:32:00.000Z\t\n" + - "AX\tAX\t2016-05-01T10:33:00.000Z\tAX\n" + - "BZ\tBZ\t2016-05-01T10:34:00.000Z\tBZ\n" + - "XX\tAX\t2016-05-01T10:35:00.000Z\tKK\n" + - "AX\tAX\t2016-05-01T10:36:00.000Z\tAX\n" + - "XX\tKK\t2016-05-01T10:37:00.000Z\t\n" + - "AX\tAX\t2016-05-01T10:38:00.000Z\t\n" + - "BZ\tBZ\t2016-05-01T10:39:00.000Z\tAX\n" + - "BZ\tAX\t2016-05-01T10:40:00.000Z\t\n"; - assertThat(expected, "select str, sym, timestamp , next(sym) over (partition by str) from abc"); - } - - @Test - public void testTwoSameOrder() throws Exception { - final String result = "sho\tstr\tsym\ttimestamp\tblah\tcol0\n" + - "-19496\tBZ\tBZ\t2016-05-01T10:21:00.000Z\t-24357\tBZ\n" + - "-24357\tXX\tBZ\t2016-05-01T10:22:00.000Z\t21781\tXX\n" + - "21781\tKK\tXX\t2016-05-01T10:23:00.000Z\t-19127\tXX\n" + - "-19127\tAX\tXX\t2016-05-01T10:24:00.000Z\t-15458\tXX\n" + - "-15458\tAX\tXX\t2016-05-01T10:25:00.000Z\t-22934\tBZ\n" + - "-22934\tAX\tBZ\t2016-05-01T10:26:00.000Z\t-391\tXX\n" + - "-391\tBZ\tXX\t2016-05-01T10:27:00.000Z\t-26951\tKK\n" + - "-26951\tBZ\tKK\t2016-05-01T10:28:00.000Z\t-19136\tKK\n" + - "-19136\tAX\tKK\t2016-05-01T10:29:00.000Z\t-15331\tAX\n" + - "-15331\tBZ\tAX\t2016-05-01T10:30:00.000Z\t-4874\tKK\n" + - "-4874\tXX\tKK\t2016-05-01T10:31:00.000Z\t25102\tAX\n" + - "25102\tKK\tAX\t2016-05-01T10:32:00.000Z\t-20409\tAX\n" + - "-20409\tAX\tAX\t2016-05-01T10:33:00.000Z\t-29572\tBZ\n" + - "-29572\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t25974\tAX\n" + - "25974\tXX\tAX\t2016-05-01T10:35:00.000Z\t5869\tAX\n" + - "5869\tAX\tAX\t2016-05-01T10:36:00.000Z\t-22894\tKK\n" + - "-22894\tXX\tKK\t2016-05-01T10:37:00.000Z\t-18600\tAX\n" + - "-18600\tAX\tAX\t2016-05-01T10:38:00.000Z\t11755\tBZ\n" + - "11755\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t-24455\tAX\n" + - "-24455\tBZ\tAX\t2016-05-01T10:40:00.000Z\t0\t\n"; - assertThat(result, "select sho, str, sym, timestamp, next(sho) blah over (order by timestamp), next(sym) over () from '*!*abc'", true); - } - - @Test - public void testTwoSameOrderByRowId() throws Exception { - final String result = "-19496\tBZ\tBZ\t2016-05-01T10:21:00.000Z\t-391\tXX\n" + - "-24357\tXX\tBZ\t2016-05-01T10:22:00.000Z\t-4874\tKK\n" + - "21781\tKK\tXX\t2016-05-01T10:23:00.000Z\t25102\tAX\n" + - "-19127\tAX\tXX\t2016-05-01T10:24:00.000Z\t-15458\tXX\n" + - "-15458\tAX\tXX\t2016-05-01T10:25:00.000Z\t-22934\tBZ\n" + - "-22934\tAX\tBZ\t2016-05-01T10:26:00.000Z\t-19136\tKK\n" + - "-391\tBZ\tXX\t2016-05-01T10:27:00.000Z\t-26951\tKK\n" + - "-26951\tBZ\tKK\t2016-05-01T10:28:00.000Z\t-15331\tAX\n" + - "-19136\tAX\tKK\t2016-05-01T10:29:00.000Z\t-20409\tAX\n" + - "-15331\tBZ\tAX\t2016-05-01T10:30:00.000Z\t-29572\tBZ\n" + - "-4874\tXX\tKK\t2016-05-01T10:31:00.000Z\t25974\tAX\n" + - "25102\tKK\tAX\t2016-05-01T10:32:00.000Z\t0\t\n" + - "-20409\tAX\tAX\t2016-05-01T10:33:00.000Z\t5869\tAX\n" + - "-29572\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t11755\tBZ\n" + - "25974\tXX\tAX\t2016-05-01T10:35:00.000Z\t-22894\tKK\n" + - "5869\tAX\tAX\t2016-05-01T10:36:00.000Z\t-18600\tAX\n" + - "-22894\tXX\tKK\t2016-05-01T10:37:00.000Z\t0\t\n" + - "-18600\tAX\tAX\t2016-05-01T10:38:00.000Z\t0\t\n" + - "11755\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t-24455\tAX\n" + - "-24455\tBZ\tAX\t2016-05-01T10:40:00.000Z\t0\t\n"; - assertThat(result, "select sho, str, sym, timestamp, " + - "next(sho) blah over (partition by str order by timestamp), " + - "next(sym) over (partition by str order by timestamp) from abc"); - } - - @Test - public void testTwoSameOrderByRowIdSymbolBehaviour() throws Exception { - assertSymbol("select sho, str, sym, timestamp, next(sho) blah over (partition by str order by timestamp), next(sym) over (partition by str order by timestamp) from abc", 2); - assertSymbol("select sho, str, sym, timestamp, next(sho) blah over (partition by str order by timestamp), next(sym) over (partition by str order by timestamp) from abc", 5); - } - - @Test - public void testTwoSameOrderBySymbolBehaviour() throws Exception { - assertSymbol("select sho, str, sym, timestamp, next(sho) blah over (partition by str order by timestamp), next(sym) over (partition by str order by timestamp) from '*!*abc'", 2); - assertSymbol("select sho, str, sym, timestamp, next(sho) blah over (partition by str order by timestamp), next(sym) over (partition by str order by timestamp) from '*!*abc'", 5); - } - - @Test - public void testWrongColumnInFunc() { - try { - expectFailure("select str, sym, timestamp , next(symx) over (partition by str) from abc"); - } catch (ParserException e) { - Assert.assertEquals(34, QueryError.getPosition()); - } - } - - @Test - public void testWrongColumnInPartition() { - try { - expectFailure("select str, sym, timestamp , next(sym) over (partition by strx) from abc"); - } catch (ParserException e) { - Assert.assertEquals(58, QueryError.getPosition()); - } - } -} \ No newline at end of file diff --git a/core/src/test/java/com/questdb/ql/analytic/PrevAnalyticFunctionTest.java b/core/src/test/java/com/questdb/ql/analytic/PrevAnalyticFunctionTest.java deleted file mode 100644 index b55208888..000000000 --- a/core/src/test/java/com/questdb/ql/analytic/PrevAnalyticFunctionTest.java +++ /dev/null @@ -1,1512 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql.analytic; - -import com.questdb.ex.ParserException; -import com.questdb.parser.sql.QueryError; -import com.questdb.ql.AbstractAllTypeTest; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -public class PrevAnalyticFunctionTest extends AbstractAllTypeTest { - - private final static String expected = "-1148479920\tBZ\t2016-05-01T10:21:00.000Z\tNaN\n" + - "1548800833\tKK\t2016-05-01T10:22:00.000Z\tNaN\n" + - "73575701\tKK\t2016-05-01T10:23:00.000Z\t1548800833\n" + - "1326447242\tKK\t2016-05-01T10:24:00.000Z\t73575701\n" + - "1868723706\tAX\t2016-05-01T10:25:00.000Z\tNaN\n" + - "-1191262516\tAX\t2016-05-01T10:26:00.000Z\t1868723706\n" + - "-1436881714\tKK\t2016-05-01T10:27:00.000Z\t1326447242\n" + - "806715481\tAX\t2016-05-01T10:28:00.000Z\t-1191262516\n" + - "1569490116\tXX\t2016-05-01T10:29:00.000Z\tNaN\n" + - "-409854405\tBZ\t2016-05-01T10:30:00.000Z\t-1148479920\n" + - "1530831067\tKK\t2016-05-01T10:31:00.000Z\t-1436881714\n" + - "-1532328444\tXX\t2016-05-01T10:32:00.000Z\t1569490116\n" + - "1125579207\tAX\t2016-05-01T10:33:00.000Z\t806715481\n" + - "-1432278050\tAX\t2016-05-01T10:34:00.000Z\t1125579207\n" + - "-85170055\tAX\t2016-05-01T10:35:00.000Z\t-1432278050\n" + - "-1844391305\tKK\t2016-05-01T10:36:00.000Z\t1530831067\n" + - "-1101822104\tKK\t2016-05-01T10:37:00.000Z\t-1844391305\n" + - "1404198\tXX\t2016-05-01T10:38:00.000Z\t-1532328444\n" + - "-1125169127\tAX\t2016-05-01T10:39:00.000Z\t-85170055\n" + - "-1975183723\tAX\t2016-05-01T10:40:00.000Z\t-1125169127\n" + - "1232884790\tXX\t2016-05-01T10:41:00.000Z\t1404198\n" + - "-2119387831\tAX\t2016-05-01T10:42:00.000Z\t-1975183723\n" + - "1699553881\tBZ\t2016-05-01T10:43:00.000Z\t-409854405\n" + - "1253890363\tAX\t2016-05-01T10:44:00.000Z\t-2119387831\n" + - "-422941535\tBZ\t2016-05-01T10:45:00.000Z\t1699553881\n" + - "-547127752\tKK\t2016-05-01T10:46:00.000Z\t-1101822104\n" + - "-303295973\tBZ\t2016-05-01T10:47:00.000Z\t-422941535\n" + - "-2132716300\tAX\t2016-05-01T10:48:00.000Z\t1253890363\n" + - "-461611463\tKK\t2016-05-01T10:49:00.000Z\t-547127752\n" + - "264240638\tAX\t2016-05-01T10:50:00.000Z\t-2132716300\n" + - "-483853667\tAX\t2016-05-01T10:51:00.000Z\t264240638\n" + - "1890602616\tBZ\t2016-05-01T10:52:00.000Z\t-303295973\n" + - "68265578\tBZ\t2016-05-01T10:53:00.000Z\t1890602616\n" + - "-2002373666\tAX\t2016-05-01T10:54:00.000Z\t-483853667\n" + - "458818940\tBZ\t2016-05-01T10:55:00.000Z\t68265578\n" + - "-2144581835\tKK\t2016-05-01T10:56:00.000Z\t-461611463\n" + - "-1418341054\tAX\t2016-05-01T10:57:00.000Z\t-2002373666\n" + - "2031014705\tKK\t2016-05-01T10:58:00.000Z\t-2144581835\n" + - "-1575135393\tXX\t2016-05-01T10:59:00.000Z\t1232884790\n" + - "936627841\tKK\t2016-05-01T11:00:00.000Z\t2031014705\n" + - "-667031149\tKK\t2016-05-01T11:01:00.000Z\t936627841\n" + - "-2034804966\tBZ\t2016-05-01T11:02:00.000Z\t458818940\n" + - "1637847416\tKK\t2016-05-01T11:03:00.000Z\t-667031149\n" + - "-1819240775\tKK\t2016-05-01T11:04:00.000Z\t1637847416\n" + - "-1787109293\tAX\t2016-05-01T11:05:00.000Z\t-1418341054\n" + - "-1515787781\tAX\t2016-05-01T11:06:00.000Z\t-1787109293\n" + - "161592763\tBZ\t2016-05-01T11:07:00.000Z\t-2034804966\n" + - "636045524\tAX\t2016-05-01T11:08:00.000Z\t-1515787781\n" + - "-1538602195\tAX\t2016-05-01T11:09:00.000Z\t636045524\n" + - "-372268574\tXX\t2016-05-01T11:10:00.000Z\t-1575135393\n" + - "-1299391311\tBZ\t2016-05-01T11:11:00.000Z\t161592763\n" + - "-10505757\tXX\t2016-05-01T11:12:00.000Z\t-372268574\n" + - "1857212401\tBZ\t2016-05-01T11:13:00.000Z\t-1299391311\n" + - "-443320374\tAX\t2016-05-01T11:14:00.000Z\t-1538602195\n" + - "1196016669\tBZ\t2016-05-01T11:15:00.000Z\t1857212401\n" + - "-1566901076\tXX\t2016-05-01T11:16:00.000Z\t-10505757\n" + - "-1201923128\tKK\t2016-05-01T11:17:00.000Z\t-1819240775\n" + - "1876812930\tXX\t2016-05-01T11:18:00.000Z\t-1566901076\n" + - "-1582495445\tKK\t2016-05-01T11:19:00.000Z\t-1201923128\n" + - "532665695\tBZ\t2016-05-01T11:20:00.000Z\t1196016669\n" + - "1234796102\tAX\t2016-05-01T11:21:00.000Z\t-443320374\n" + - "-45567293\tKK\t2016-05-01T11:22:00.000Z\t-1582495445\n" + - "-373499303\tBZ\t2016-05-01T11:23:00.000Z\t532665695\n" + - "-916132123\tKK\t2016-05-01T11:24:00.000Z\t-45567293\n" + - "114747951\tAX\t2016-05-01T11:25:00.000Z\t1234796102\n" + - "-1794809330\tAX\t2016-05-01T11:26:00.000Z\t114747951\n" + - "-731466113\tKK\t2016-05-01T11:27:00.000Z\t-916132123\n" + - "-882371473\tAX\t2016-05-01T11:28:00.000Z\t-1794809330\n" + - "-1723887671\tBZ\t2016-05-01T11:29:00.000Z\t-373499303\n" + - "-1172180184\tXX\t2016-05-01T11:30:00.000Z\t1876812930\n" + - "-2075675260\tKK\t2016-05-01T11:31:00.000Z\t-731466113\n" + - "-712702244\tBZ\t2016-05-01T11:32:00.000Z\t-1723887671\n" + - "-1768335227\tKK\t2016-05-01T11:33:00.000Z\t-2075675260\n" + - "1235206821\tAX\t2016-05-01T11:34:00.000Z\t-882371473\n" + - "1795359355\tBZ\t2016-05-01T11:35:00.000Z\t-712702244\n" + - "-876466531\tBZ\t2016-05-01T11:36:00.000Z\t1795359355\n" + - "865832060\tXX\t2016-05-01T11:37:00.000Z\t-1172180184\n" + - "-1966408995\tKK\t2016-05-01T11:38:00.000Z\t-1768335227\n" + - "838743782\tAX\t2016-05-01T11:39:00.000Z\t1235206821\n" + - "1107889075\tKK\t2016-05-01T11:40:00.000Z\t-1966408995\n" + - "-618037497\tAX\t2016-05-01T11:41:00.000Z\t838743782\n" + - "-2043803188\tBZ\t2016-05-01T11:42:00.000Z\t-876466531\n" + - "-68027832\tKK\t2016-05-01T11:43:00.000Z\t1107889075\n" + - "519895483\tAX\t2016-05-01T11:44:00.000Z\t-618037497\n" + - "-2088317486\tKK\t2016-05-01T11:45:00.000Z\t-68027832\n" + - "602835017\tAX\t2016-05-01T11:46:00.000Z\t519895483\n" + - "-2111250190\tAX\t2016-05-01T11:47:00.000Z\t602835017\n" + - "614536941\tXX\t2016-05-01T11:48:00.000Z\t865832060\n" + - "1598679468\tAX\t2016-05-01T11:49:00.000Z\t-2111250190\n" + - "1658228795\tBZ\t2016-05-01T11:50:00.000Z\t-2043803188\n" + - "-283321892\tKK\t2016-05-01T11:51:00.000Z\t-2088317486\n" + - "116799613\tKK\t2016-05-01T11:52:00.000Z\t-283321892\n" + - "1238491107\tBZ\t2016-05-01T11:53:00.000Z\t1658228795\n" + - "-636975106\tKK\t2016-05-01T11:54:00.000Z\t116799613\n" + - "1015055928\tXX\t2016-05-01T11:55:00.000Z\t614536941\n" + - "1100812407\tBZ\t2016-05-01T11:56:00.000Z\t1238491107\n" + - "1362833895\tAX\t2016-05-01T11:57:00.000Z\t1598679468\n" + - "-805434743\tAX\t2016-05-01T11:58:00.000Z\t1362833895\n" + - "-640305320\tKK\t2016-05-01T11:59:00.000Z\t-636975106\n" + - "1751526583\tBZ\t2016-05-01T12:00:00.000Z\t1100812407\n"; - - @BeforeClass - public static void setup() { - // this check will initialise thread local object outside of memory leak tests - FACTORY_CONTAINER.getFactory().getConfiguration().exists(""); - } - - @Test - public void testAggregationContext() { - try { - expectFailure("select sym, sum(d) x, prev(x) over() from abc"); - } catch (ParserException e) { - Assert.assertEquals(22, QueryError.getPosition()); - } - } - - @Test - public void testBoolOrdered() throws Exception { - final String expected = "8920866532787660373\ttrue\t2016-05-01T10:21:00.000Z\ttrue\n" + - "-6943924477733600060\tfalse\t2016-05-01T10:22:00.000Z\tfalse\n" + - "-6856503215590263904\tfalse\t2016-05-01T10:23:00.000Z\tfalse\n" + - "8416773233910814357\tfalse\t2016-05-01T10:24:00.000Z\tfalse\n" + - "7199909180655756830\ttrue\t2016-05-01T10:25:00.000Z\tfalse\n" + - "6270672455202306717\ttrue\t2016-05-01T10:26:00.000Z\ttrue\n" + - "-6253307669002054137\tfalse\t2016-05-01T10:27:00.000Z\tfalse\n" + - "7392877322819819290\ttrue\t2016-05-01T10:28:00.000Z\ttrue\n" + - "-7316123607359392486\tfalse\t2016-05-01T10:29:00.000Z\tfalse\n" + - "-3107239868490395663\tfalse\t2016-05-01T10:30:00.000Z\tfalse\n" + - "-7387846268299105911\tfalse\t2016-05-01T10:31:00.000Z\ttrue\n" + - "7122109662042058469\tfalse\t2016-05-01T10:32:00.000Z\ttrue\n" + - "-6626590012581323602\tfalse\t2016-05-01T10:33:00.000Z\tfalse\n" + - "8611582118025429627\tfalse\t2016-05-01T10:34:00.000Z\tfalse\n" + - "-8082754367165748693\ttrue\t2016-05-01T10:35:00.000Z\tfalse\n" + - "6574958665733670985\ttrue\t2016-05-01T10:36:00.000Z\ttrue\n" + - "3446015290144635451\ttrue\t2016-05-01T10:37:00.000Z\tfalse\n" + - "8889492928577876455\ttrue\t2016-05-01T10:38:00.000Z\tfalse\n" + - "8152044974329490473\tfalse\t2016-05-01T10:39:00.000Z\ttrue\n" + - "-6071768268784020226\tfalse\t2016-05-01T10:40:00.000Z\tfalse\n"; - assertThat(expected, "select l, boo, timestamp , prev(boo) over (order by l) from abc"); - assertThat(expected, "select l, boo, timestamp , prev(boo) over (order by l) from '*!*abc'"); - } - - @Test - public void testBoolean() throws Exception { - final String expected = "true\tBZ\t2016-05-01T10:21:00.000Z\tfalse\n" + - "false\tXX\t2016-05-01T10:22:00.000Z\tfalse\n" + - "false\tKK\t2016-05-01T10:23:00.000Z\tfalse\n" + - "false\tAX\t2016-05-01T10:24:00.000Z\tfalse\n" + - "true\tAX\t2016-05-01T10:25:00.000Z\tfalse\n" + - "true\tAX\t2016-05-01T10:26:00.000Z\ttrue\n" + - "false\tBZ\t2016-05-01T10:27:00.000Z\ttrue\n" + - "true\tBZ\t2016-05-01T10:28:00.000Z\tfalse\n" + - "false\tAX\t2016-05-01T10:29:00.000Z\ttrue\n" + - "false\tBZ\t2016-05-01T10:30:00.000Z\ttrue\n" + - "false\tXX\t2016-05-01T10:31:00.000Z\tfalse\n" + - "false\tKK\t2016-05-01T10:32:00.000Z\tfalse\n" + - "false\tAX\t2016-05-01T10:33:00.000Z\tfalse\n" + - "false\tBZ\t2016-05-01T10:34:00.000Z\tfalse\n" + - "true\tXX\t2016-05-01T10:35:00.000Z\tfalse\n" + - "true\tAX\t2016-05-01T10:36:00.000Z\tfalse\n" + - "true\tXX\t2016-05-01T10:37:00.000Z\ttrue\n" + - "true\tAX\t2016-05-01T10:38:00.000Z\ttrue\n" + - "false\tBZ\t2016-05-01T10:39:00.000Z\tfalse\n" + - "false\tBZ\t2016-05-01T10:40:00.000Z\tfalse\n"; - assertThat(expected, "select boo, str, timestamp , prev(boo) over (partition by str) from abc"); - assertThat(expected, "select boo, str, timestamp , prev(boo) over (partition by str) from '*!*abc'"); - } - - @Test - public void testBoolean2() throws Exception { - final String expected = "true\tBZ\t2016-05-01T10:21:00.000Z\tfalse\n" + - "false\tXX\t2016-05-01T10:22:00.000Z\ttrue\n" + - "false\tKK\t2016-05-01T10:23:00.000Z\tfalse\n" + - "false\tAX\t2016-05-01T10:24:00.000Z\tfalse\n" + - "true\tAX\t2016-05-01T10:25:00.000Z\tfalse\n" + - "true\tAX\t2016-05-01T10:26:00.000Z\ttrue\n" + - "false\tBZ\t2016-05-01T10:27:00.000Z\ttrue\n" + - "true\tBZ\t2016-05-01T10:28:00.000Z\tfalse\n" + - "false\tAX\t2016-05-01T10:29:00.000Z\ttrue\n" + - "false\tBZ\t2016-05-01T10:30:00.000Z\tfalse\n" + - "false\tXX\t2016-05-01T10:31:00.000Z\tfalse\n" + - "false\tKK\t2016-05-01T10:32:00.000Z\tfalse\n" + - "false\tAX\t2016-05-01T10:33:00.000Z\tfalse\n" + - "false\tBZ\t2016-05-01T10:34:00.000Z\tfalse\n" + - "true\tXX\t2016-05-01T10:35:00.000Z\tfalse\n" + - "true\tAX\t2016-05-01T10:36:00.000Z\ttrue\n" + - "true\tXX\t2016-05-01T10:37:00.000Z\ttrue\n" + - "true\tAX\t2016-05-01T10:38:00.000Z\ttrue\n" + - "false\tBZ\t2016-05-01T10:39:00.000Z\ttrue\n" + - "false\tBZ\t2016-05-01T10:40:00.000Z\tfalse\n"; - assertThat(expected, "select boo, str, timestamp , prev(boo) over () from abc"); - assertThat(expected, "select boo, str, timestamp , prev(boo) over () from '*!*abc'"); - } - - @Test - public void testByte() throws Exception { - final String expected = "21\tBZ\tBZ\t2016-05-01T10:21:00.000Z\t0\n" + - "-120\tXX\tBZ\t2016-05-01T10:22:00.000Z\t0\n" + - "-34\tKK\tXX\t2016-05-01T10:23:00.000Z\t0\n" + - "-60\tAX\tXX\t2016-05-01T10:24:00.000Z\t0\n" + - "-95\tAX\tXX\t2016-05-01T10:25:00.000Z\t-60\n" + - "-40\tAX\tBZ\t2016-05-01T10:26:00.000Z\t-95\n" + - "53\tBZ\tXX\t2016-05-01T10:27:00.000Z\t21\n" + - "77\tBZ\tKK\t2016-05-01T10:28:00.000Z\t53\n" + - "-69\tAX\tKK\t2016-05-01T10:29:00.000Z\t-40\n" + - "-15\tBZ\tAX\t2016-05-01T10:30:00.000Z\t77\n" + - "-126\tXX\tKK\t2016-05-01T10:31:00.000Z\t-120\n" + - "-114\tKK\tAX\t2016-05-01T10:32:00.000Z\t-34\n" + - "-55\tAX\tAX\t2016-05-01T10:33:00.000Z\t-69\n" + - "-72\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t-15\n" + - "-77\tXX\tAX\t2016-05-01T10:35:00.000Z\t-126\n" + - "-83\tAX\tAX\t2016-05-01T10:36:00.000Z\t-55\n" + - "-36\tXX\tKK\t2016-05-01T10:37:00.000Z\t-77\n" + - "-102\tAX\tAX\t2016-05-01T10:38:00.000Z\t-83\n" + - "-114\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t-72\n" + - "70\tBZ\tAX\t2016-05-01T10:40:00.000Z\t-114\n"; - assertThat(expected, "select b, str, sym, timestamp , prev(b) over (partition by str) from abc"); - assertThat(expected, "select b, str, sym, timestamp , prev(b) over (partition by str) from '*!*abc'"); - } - - @Test - public void testByte2() throws Exception { - final String expected = "21\tBZ\tBZ\t2016-05-01T10:21:00.000Z\t0\n" + - "-120\tXX\tBZ\t2016-05-01T10:22:00.000Z\t21\n" + - "-34\tKK\tXX\t2016-05-01T10:23:00.000Z\t-120\n" + - "-60\tAX\tXX\t2016-05-01T10:24:00.000Z\t-34\n" + - "-95\tAX\tXX\t2016-05-01T10:25:00.000Z\t-60\n" + - "-40\tAX\tBZ\t2016-05-01T10:26:00.000Z\t-95\n" + - "53\tBZ\tXX\t2016-05-01T10:27:00.000Z\t-40\n" + - "77\tBZ\tKK\t2016-05-01T10:28:00.000Z\t53\n" + - "-69\tAX\tKK\t2016-05-01T10:29:00.000Z\t77\n" + - "-15\tBZ\tAX\t2016-05-01T10:30:00.000Z\t-69\n" + - "-126\tXX\tKK\t2016-05-01T10:31:00.000Z\t-15\n" + - "-114\tKK\tAX\t2016-05-01T10:32:00.000Z\t-126\n" + - "-55\tAX\tAX\t2016-05-01T10:33:00.000Z\t-114\n" + - "-72\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t-55\n" + - "-77\tXX\tAX\t2016-05-01T10:35:00.000Z\t-72\n" + - "-83\tAX\tAX\t2016-05-01T10:36:00.000Z\t-77\n" + - "-36\tXX\tKK\t2016-05-01T10:37:00.000Z\t-83\n" + - "-102\tAX\tAX\t2016-05-01T10:38:00.000Z\t-36\n" + - "-114\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t-102\n" + - "70\tBZ\tAX\t2016-05-01T10:40:00.000Z\t-114\n"; - assertThat(expected, "select b, str, sym, timestamp , prev(b) over () from abc"); - assertThat(expected, "select b, str, sym, timestamp , prev(b) over () from '*!*abc'"); - } - - @Test - public void testByteOrdered() throws Exception { - final String expected = "8920866532787660373\t21\t2016-05-01T10:21:00.000Z\t-102\n" + - "-6943924477733600060\t-120\t2016-05-01T10:22:00.000Z\t-69\n" + - "-6856503215590263904\t-34\t2016-05-01T10:23:00.000Z\t-120\n" + - "8416773233910814357\t-60\t2016-05-01T10:24:00.000Z\t-114\n" + - "7199909180655756830\t-95\t2016-05-01T10:25:00.000Z\t-114\n" + - "6270672455202306717\t-40\t2016-05-01T10:26:00.000Z\t-36\n" + - "-6253307669002054137\t53\t2016-05-01T10:27:00.000Z\t-55\n" + - "7392877322819819290\t77\t2016-05-01T10:28:00.000Z\t-95\n" + - "-7316123607359392486\t-69\t2016-05-01T10:29:00.000Z\t-126\n" + - "-3107239868490395663\t-15\t2016-05-01T10:30:00.000Z\t70\n" + - "-7387846268299105911\t-126\t2016-05-01T10:31:00.000Z\t-77\n" + - "7122109662042058469\t-114\t2016-05-01T10:32:00.000Z\t-83\n" + - "-6626590012581323602\t-55\t2016-05-01T10:33:00.000Z\t-34\n" + - "8611582118025429627\t-72\t2016-05-01T10:34:00.000Z\t-60\n" + - "-8082754367165748693\t-77\t2016-05-01T10:35:00.000Z\t0\n" + - "6574958665733670985\t-83\t2016-05-01T10:36:00.000Z\t-40\n" + - "3446015290144635451\t-36\t2016-05-01T10:37:00.000Z\t-15\n" + - "8889492928577876455\t-102\t2016-05-01T10:38:00.000Z\t-72\n" + - "8152044974329490473\t-114\t2016-05-01T10:39:00.000Z\t77\n" + - "-6071768268784020226\t70\t2016-05-01T10:40:00.000Z\t53\n"; - assertThat(expected, "select l, b, timestamp , prev(b) over (order by l) from abc"); - assertThat(expected, "select l, b, timestamp , prev(b) over (order by l) from '*!*abc'"); - } - - @Test - public void testColumnNameGeneration() throws Exception { - assertThat("str\tsym\ttimestamp\tcol0\n" + - "BZ\tBZ\t2016-05-01T10:21:00.000Z\t\n" + - "XX\tBZ\t2016-05-01T10:22:00.000Z\tBZ\n" + - "KK\tXX\t2016-05-01T10:23:00.000Z\tBZ\n" + - "AX\tXX\t2016-05-01T10:24:00.000Z\tXX\n" + - "AX\tXX\t2016-05-01T10:25:00.000Z\tXX\n" + - "AX\tBZ\t2016-05-01T10:26:00.000Z\tXX\n" + - "BZ\tXX\t2016-05-01T10:27:00.000Z\tBZ\n" + - "BZ\tKK\t2016-05-01T10:28:00.000Z\tXX\n" + - "AX\tKK\t2016-05-01T10:29:00.000Z\tKK\n" + - "BZ\tAX\t2016-05-01T10:30:00.000Z\tKK\n" + - "XX\tKK\t2016-05-01T10:31:00.000Z\tAX\n" + - "KK\tAX\t2016-05-01T10:32:00.000Z\tKK\n" + - "AX\tAX\t2016-05-01T10:33:00.000Z\tAX\n" + - "BZ\tBZ\t2016-05-01T10:34:00.000Z\tAX\n" + - "XX\tAX\t2016-05-01T10:35:00.000Z\tBZ\n" + - "AX\tAX\t2016-05-01T10:36:00.000Z\tAX\n" + - "XX\tKK\t2016-05-01T10:37:00.000Z\tAX\n" + - "AX\tAX\t2016-05-01T10:38:00.000Z\tKK\n" + - "BZ\tBZ\t2016-05-01T10:39:00.000Z\tAX\n" + - "BZ\tAX\t2016-05-01T10:40:00.000Z\tBZ\n", - "select str, sym, timestamp , prev(sym) over () from abc", true); - - } - - @Test - public void testCompilation() throws Exception { - assertThat(expected, "select i, str, timestamp, prev(i) over (partition by str) from xyz"); - } - - @Test - public void testCompileNonPart() throws Exception { - final String expected = "-1148479920\tBZ\t2016-05-01T10:21:00.000Z\tNaN\n" + - "1548800833\tKK\t2016-05-01T10:22:00.000Z\t-1148479920\n" + - "73575701\tKK\t2016-05-01T10:23:00.000Z\t1548800833\n" + - "1326447242\tKK\t2016-05-01T10:24:00.000Z\t73575701\n" + - "1868723706\tAX\t2016-05-01T10:25:00.000Z\t1326447242\n" + - "-1191262516\tAX\t2016-05-01T10:26:00.000Z\t1868723706\n" + - "-1436881714\tKK\t2016-05-01T10:27:00.000Z\t-1191262516\n" + - "806715481\tAX\t2016-05-01T10:28:00.000Z\t-1436881714\n" + - "1569490116\tXX\t2016-05-01T10:29:00.000Z\t806715481\n" + - "-409854405\tBZ\t2016-05-01T10:30:00.000Z\t1569490116\n" + - "1530831067\tKK\t2016-05-01T10:31:00.000Z\t-409854405\n" + - "-1532328444\tXX\t2016-05-01T10:32:00.000Z\t1530831067\n" + - "1125579207\tAX\t2016-05-01T10:33:00.000Z\t-1532328444\n" + - "-1432278050\tAX\t2016-05-01T10:34:00.000Z\t1125579207\n" + - "-85170055\tAX\t2016-05-01T10:35:00.000Z\t-1432278050\n" + - "-1844391305\tKK\t2016-05-01T10:36:00.000Z\t-85170055\n" + - "-1101822104\tKK\t2016-05-01T10:37:00.000Z\t-1844391305\n" + - "1404198\tXX\t2016-05-01T10:38:00.000Z\t-1101822104\n" + - "-1125169127\tAX\t2016-05-01T10:39:00.000Z\t1404198\n" + - "-1975183723\tAX\t2016-05-01T10:40:00.000Z\t-1125169127\n" + - "1232884790\tXX\t2016-05-01T10:41:00.000Z\t-1975183723\n" + - "-2119387831\tAX\t2016-05-01T10:42:00.000Z\t1232884790\n" + - "1699553881\tBZ\t2016-05-01T10:43:00.000Z\t-2119387831\n" + - "1253890363\tAX\t2016-05-01T10:44:00.000Z\t1699553881\n" + - "-422941535\tBZ\t2016-05-01T10:45:00.000Z\t1253890363\n" + - "-547127752\tKK\t2016-05-01T10:46:00.000Z\t-422941535\n" + - "-303295973\tBZ\t2016-05-01T10:47:00.000Z\t-547127752\n" + - "-2132716300\tAX\t2016-05-01T10:48:00.000Z\t-303295973\n" + - "-461611463\tKK\t2016-05-01T10:49:00.000Z\t-2132716300\n" + - "264240638\tAX\t2016-05-01T10:50:00.000Z\t-461611463\n" + - "-483853667\tAX\t2016-05-01T10:51:00.000Z\t264240638\n" + - "1890602616\tBZ\t2016-05-01T10:52:00.000Z\t-483853667\n" + - "68265578\tBZ\t2016-05-01T10:53:00.000Z\t1890602616\n" + - "-2002373666\tAX\t2016-05-01T10:54:00.000Z\t68265578\n" + - "458818940\tBZ\t2016-05-01T10:55:00.000Z\t-2002373666\n" + - "-2144581835\tKK\t2016-05-01T10:56:00.000Z\t458818940\n" + - "-1418341054\tAX\t2016-05-01T10:57:00.000Z\t-2144581835\n" + - "2031014705\tKK\t2016-05-01T10:58:00.000Z\t-1418341054\n" + - "-1575135393\tXX\t2016-05-01T10:59:00.000Z\t2031014705\n" + - "936627841\tKK\t2016-05-01T11:00:00.000Z\t-1575135393\n" + - "-667031149\tKK\t2016-05-01T11:01:00.000Z\t936627841\n" + - "-2034804966\tBZ\t2016-05-01T11:02:00.000Z\t-667031149\n" + - "1637847416\tKK\t2016-05-01T11:03:00.000Z\t-2034804966\n" + - "-1819240775\tKK\t2016-05-01T11:04:00.000Z\t1637847416\n" + - "-1787109293\tAX\t2016-05-01T11:05:00.000Z\t-1819240775\n" + - "-1515787781\tAX\t2016-05-01T11:06:00.000Z\t-1787109293\n" + - "161592763\tBZ\t2016-05-01T11:07:00.000Z\t-1515787781\n" + - "636045524\tAX\t2016-05-01T11:08:00.000Z\t161592763\n" + - "-1538602195\tAX\t2016-05-01T11:09:00.000Z\t636045524\n" + - "-372268574\tXX\t2016-05-01T11:10:00.000Z\t-1538602195\n" + - "-1299391311\tBZ\t2016-05-01T11:11:00.000Z\t-372268574\n" + - "-10505757\tXX\t2016-05-01T11:12:00.000Z\t-1299391311\n" + - "1857212401\tBZ\t2016-05-01T11:13:00.000Z\t-10505757\n" + - "-443320374\tAX\t2016-05-01T11:14:00.000Z\t1857212401\n" + - "1196016669\tBZ\t2016-05-01T11:15:00.000Z\t-443320374\n" + - "-1566901076\tXX\t2016-05-01T11:16:00.000Z\t1196016669\n" + - "-1201923128\tKK\t2016-05-01T11:17:00.000Z\t-1566901076\n" + - "1876812930\tXX\t2016-05-01T11:18:00.000Z\t-1201923128\n" + - "-1582495445\tKK\t2016-05-01T11:19:00.000Z\t1876812930\n" + - "532665695\tBZ\t2016-05-01T11:20:00.000Z\t-1582495445\n" + - "1234796102\tAX\t2016-05-01T11:21:00.000Z\t532665695\n" + - "-45567293\tKK\t2016-05-01T11:22:00.000Z\t1234796102\n" + - "-373499303\tBZ\t2016-05-01T11:23:00.000Z\t-45567293\n" + - "-916132123\tKK\t2016-05-01T11:24:00.000Z\t-373499303\n" + - "114747951\tAX\t2016-05-01T11:25:00.000Z\t-916132123\n" + - "-1794809330\tAX\t2016-05-01T11:26:00.000Z\t114747951\n" + - "-731466113\tKK\t2016-05-01T11:27:00.000Z\t-1794809330\n" + - "-882371473\tAX\t2016-05-01T11:28:00.000Z\t-731466113\n" + - "-1723887671\tBZ\t2016-05-01T11:29:00.000Z\t-882371473\n" + - "-1172180184\tXX\t2016-05-01T11:30:00.000Z\t-1723887671\n" + - "-2075675260\tKK\t2016-05-01T11:31:00.000Z\t-1172180184\n" + - "-712702244\tBZ\t2016-05-01T11:32:00.000Z\t-2075675260\n" + - "-1768335227\tKK\t2016-05-01T11:33:00.000Z\t-712702244\n" + - "1235206821\tAX\t2016-05-01T11:34:00.000Z\t-1768335227\n" + - "1795359355\tBZ\t2016-05-01T11:35:00.000Z\t1235206821\n" + - "-876466531\tBZ\t2016-05-01T11:36:00.000Z\t1795359355\n" + - "865832060\tXX\t2016-05-01T11:37:00.000Z\t-876466531\n" + - "-1966408995\tKK\t2016-05-01T11:38:00.000Z\t865832060\n" + - "838743782\tAX\t2016-05-01T11:39:00.000Z\t-1966408995\n" + - "1107889075\tKK\t2016-05-01T11:40:00.000Z\t838743782\n" + - "-618037497\tAX\t2016-05-01T11:41:00.000Z\t1107889075\n" + - "-2043803188\tBZ\t2016-05-01T11:42:00.000Z\t-618037497\n" + - "-68027832\tKK\t2016-05-01T11:43:00.000Z\t-2043803188\n" + - "519895483\tAX\t2016-05-01T11:44:00.000Z\t-68027832\n" + - "-2088317486\tKK\t2016-05-01T11:45:00.000Z\t519895483\n" + - "602835017\tAX\t2016-05-01T11:46:00.000Z\t-2088317486\n" + - "-2111250190\tAX\t2016-05-01T11:47:00.000Z\t602835017\n" + - "614536941\tXX\t2016-05-01T11:48:00.000Z\t-2111250190\n" + - "1598679468\tAX\t2016-05-01T11:49:00.000Z\t614536941\n" + - "1658228795\tBZ\t2016-05-01T11:50:00.000Z\t1598679468\n" + - "-283321892\tKK\t2016-05-01T11:51:00.000Z\t1658228795\n" + - "116799613\tKK\t2016-05-01T11:52:00.000Z\t-283321892\n" + - "1238491107\tBZ\t2016-05-01T11:53:00.000Z\t116799613\n" + - "-636975106\tKK\t2016-05-01T11:54:00.000Z\t1238491107\n" + - "1015055928\tXX\t2016-05-01T11:55:00.000Z\t-636975106\n" + - "1100812407\tBZ\t2016-05-01T11:56:00.000Z\t1015055928\n" + - "1362833895\tAX\t2016-05-01T11:57:00.000Z\t1100812407\n" + - "-805434743\tAX\t2016-05-01T11:58:00.000Z\t1362833895\n" + - "-640305320\tKK\t2016-05-01T11:59:00.000Z\t-805434743\n" + - "1751526583\tBZ\t2016-05-01T12:00:00.000Z\t-640305320\n"; - assertThat(expected, "select i, str, timestamp, prev(i) over () from xyz"); - assertThat(expected, "select i, str, timestamp, prev(i) over () from '*!*xyz'"); - } - - @Test - public void testDate() throws Exception { - final String expected = "277433687-10-12T08:51:21.932Z\tBZ\tBZ\t2016-05-01T10:21:00.000Z\t\n" + - "-284210729-04-16T06:37:25.107Z\tXX\tBZ\t2016-05-01T10:22:00.000Z\t\n" + - "-142145720-12-30T10:07:22.984Z\tKK\tXX\t2016-05-01T10:23:00.000Z\t\n" + - "-268695905-10-25T00:06:37.492Z\tAX\tXX\t2016-05-01T10:24:00.000Z\t\n" + - "217217443-02-16T18:39:59.220Z\tAX\tXX\t2016-05-01T10:25:00.000Z\t-268695905-10-25T00:06:37.492Z\n" + - "263840408-06-11T18:15:05.778Z\tAX\tBZ\t2016-05-01T10:26:00.000Z\t217217443-02-16T18:39:59.220Z\n" + - "231478896-06-17T12:18:04.767Z\tBZ\tXX\t2016-05-01T10:27:00.000Z\t277433687-10-12T08:51:21.932Z\n" + - "220352915-01-17T00:08:45.841Z\tBZ\tKK\t2016-05-01T10:28:00.000Z\t231478896-06-17T12:18:04.767Z\n" + - "-230266796-08-17T22:57:03.970Z\tAX\tKK\t2016-05-01T10:29:00.000Z\t263840408-06-11T18:15:05.778Z\n" + - "18125533-09-05T04:06:38.086Z\tBZ\tAX\t2016-05-01T10:30:00.000Z\t220352915-01-17T00:08:45.841Z\n" + - "-201714876-08-10T10:14:48.134Z\tXX\tKK\t2016-05-01T10:31:00.000Z\t-284210729-04-16T06:37:25.107Z\n" + - "132059357-01-03T08:27:45.836Z\tKK\tAX\t2016-05-01T10:32:00.000Z\t-142145720-12-30T10:07:22.984Z\n" + - "-253361973-02-05T02:07:37.180Z\tAX\tAX\t2016-05-01T10:33:00.000Z\t-230266796-08-17T22:57:03.970Z\n" + - "-180947413-05-05T10:19:58.733Z\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t18125533-09-05T04:06:38.086Z\n" + - "-225086326-11-23T21:53:40.936Z\tXX\tAX\t2016-05-01T10:35:00.000Z\t-201714876-08-10T10:14:48.134Z\n" + - "252677978-05-07T03:29:33.753Z\tAX\tAX\t2016-05-01T10:36:00.000Z\t-253361973-02-05T02:07:37.180Z\n" + - "-244304870-03-25T17:50:45.758Z\tXX\tKK\t2016-05-01T10:37:00.000Z\t-225086326-11-23T21:53:40.936Z\n" + - "-196068605-07-20T05:32:43.747Z\tAX\tAX\t2016-05-01T10:38:00.000Z\t252677978-05-07T03:29:33.753Z\n" + - "167791211-12-09T07:52:02.538Z\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t-180947413-05-05T10:19:58.733Z\n" + - "-56977607-10-20T13:10:29.515Z\tBZ\tAX\t2016-05-01T10:40:00.000Z\t167791211-12-09T07:52:02.538Z\n"; - assertThat(expected, "select date, str, sym, timestamp , prev(date) over (partition by str) from abc"); - assertThat(expected, "select date, str, sym, timestamp , prev(date) over (partition by str) from '*!*abc'"); - } - - @Test - public void testDate2() throws Exception { - final String expected = "277433687-10-12T08:51:21.932Z\tBZ\tBZ\t2016-05-01T10:21:00.000Z\t\n" + - "-284210729-04-16T06:37:25.107Z\tXX\tBZ\t2016-05-01T10:22:00.000Z\t277433687-10-12T08:51:21.932Z\n" + - "-142145720-12-30T10:07:22.984Z\tKK\tXX\t2016-05-01T10:23:00.000Z\t-284210729-04-16T06:37:25.107Z\n" + - "-268695905-10-25T00:06:37.492Z\tAX\tXX\t2016-05-01T10:24:00.000Z\t-142145720-12-30T10:07:22.984Z\n" + - "217217443-02-16T18:39:59.220Z\tAX\tXX\t2016-05-01T10:25:00.000Z\t-268695905-10-25T00:06:37.492Z\n" + - "263840408-06-11T18:15:05.778Z\tAX\tBZ\t2016-05-01T10:26:00.000Z\t217217443-02-16T18:39:59.220Z\n" + - "231478896-06-17T12:18:04.767Z\tBZ\tXX\t2016-05-01T10:27:00.000Z\t263840408-06-11T18:15:05.778Z\n" + - "220352915-01-17T00:08:45.841Z\tBZ\tKK\t2016-05-01T10:28:00.000Z\t231478896-06-17T12:18:04.767Z\n" + - "-230266796-08-17T22:57:03.970Z\tAX\tKK\t2016-05-01T10:29:00.000Z\t220352915-01-17T00:08:45.841Z\n" + - "18125533-09-05T04:06:38.086Z\tBZ\tAX\t2016-05-01T10:30:00.000Z\t-230266796-08-17T22:57:03.970Z\n" + - "-201714876-08-10T10:14:48.134Z\tXX\tKK\t2016-05-01T10:31:00.000Z\t18125533-09-05T04:06:38.086Z\n" + - "132059357-01-03T08:27:45.836Z\tKK\tAX\t2016-05-01T10:32:00.000Z\t-201714876-08-10T10:14:48.134Z\n" + - "-253361973-02-05T02:07:37.180Z\tAX\tAX\t2016-05-01T10:33:00.000Z\t132059357-01-03T08:27:45.836Z\n" + - "-180947413-05-05T10:19:58.733Z\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t-253361973-02-05T02:07:37.180Z\n" + - "-225086326-11-23T21:53:40.936Z\tXX\tAX\t2016-05-01T10:35:00.000Z\t-180947413-05-05T10:19:58.733Z\n" + - "252677978-05-07T03:29:33.753Z\tAX\tAX\t2016-05-01T10:36:00.000Z\t-225086326-11-23T21:53:40.936Z\n" + - "-244304870-03-25T17:50:45.758Z\tXX\tKK\t2016-05-01T10:37:00.000Z\t252677978-05-07T03:29:33.753Z\n" + - "-196068605-07-20T05:32:43.747Z\tAX\tAX\t2016-05-01T10:38:00.000Z\t-244304870-03-25T17:50:45.758Z\n" + - "167791211-12-09T07:52:02.538Z\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t-196068605-07-20T05:32:43.747Z\n" + - "-56977607-10-20T13:10:29.515Z\tBZ\tAX\t2016-05-01T10:40:00.000Z\t167791211-12-09T07:52:02.538Z\n"; - assertThat(expected, "select date, str, sym, timestamp , prev(date) over () from abc"); - assertThat(expected, "select date, str, sym, timestamp , prev(date) over () from '*!*abc'"); - } - - @Test - public void testDateOrdered() throws Exception { - final String expected = "8920866532787660373\t277433687-10-12T08:51:21.932Z\t2016-05-01T10:21:00.000Z\t-196068605-07-20T05:32:43.747Z\n" + - "-6943924477733600060\t-284210729-04-16T06:37:25.107Z\t2016-05-01T10:22:00.000Z\t-230266796-08-17T22:57:03.970Z\n" + - "-6856503215590263904\t-142145720-12-30T10:07:22.984Z\t2016-05-01T10:23:00.000Z\t-284210729-04-16T06:37:25.107Z\n" + - "8416773233910814357\t-268695905-10-25T00:06:37.492Z\t2016-05-01T10:24:00.000Z\t167791211-12-09T07:52:02.538Z\n" + - "7199909180655756830\t217217443-02-16T18:39:59.220Z\t2016-05-01T10:25:00.000Z\t132059357-01-03T08:27:45.836Z\n" + - "6270672455202306717\t263840408-06-11T18:15:05.778Z\t2016-05-01T10:26:00.000Z\t-244304870-03-25T17:50:45.758Z\n" + - "-6253307669002054137\t231478896-06-17T12:18:04.767Z\t2016-05-01T10:27:00.000Z\t-253361973-02-05T02:07:37.180Z\n" + - "7392877322819819290\t220352915-01-17T00:08:45.841Z\t2016-05-01T10:28:00.000Z\t217217443-02-16T18:39:59.220Z\n" + - "-7316123607359392486\t-230266796-08-17T22:57:03.970Z\t2016-05-01T10:29:00.000Z\t-201714876-08-10T10:14:48.134Z\n" + - "-3107239868490395663\t18125533-09-05T04:06:38.086Z\t2016-05-01T10:30:00.000Z\t-56977607-10-20T13:10:29.515Z\n" + - "-7387846268299105911\t-201714876-08-10T10:14:48.134Z\t2016-05-01T10:31:00.000Z\t-225086326-11-23T21:53:40.936Z\n" + - "7122109662042058469\t132059357-01-03T08:27:45.836Z\t2016-05-01T10:32:00.000Z\t252677978-05-07T03:29:33.753Z\n" + - "-6626590012581323602\t-253361973-02-05T02:07:37.180Z\t2016-05-01T10:33:00.000Z\t-142145720-12-30T10:07:22.984Z\n" + - "8611582118025429627\t-180947413-05-05T10:19:58.733Z\t2016-05-01T10:34:00.000Z\t-268695905-10-25T00:06:37.492Z\n" + - "-8082754367165748693\t-225086326-11-23T21:53:40.936Z\t2016-05-01T10:35:00.000Z\t\n" + - "6574958665733670985\t252677978-05-07T03:29:33.753Z\t2016-05-01T10:36:00.000Z\t263840408-06-11T18:15:05.778Z\n" + - "3446015290144635451\t-244304870-03-25T17:50:45.758Z\t2016-05-01T10:37:00.000Z\t18125533-09-05T04:06:38.086Z\n" + - "8889492928577876455\t-196068605-07-20T05:32:43.747Z\t2016-05-01T10:38:00.000Z\t-180947413-05-05T10:19:58.733Z\n" + - "8152044974329490473\t167791211-12-09T07:52:02.538Z\t2016-05-01T10:39:00.000Z\t220352915-01-17T00:08:45.841Z\n" + - "-6071768268784020226\t-56977607-10-20T13:10:29.515Z\t2016-05-01T10:40:00.000Z\t231478896-06-17T12:18:04.767Z\n"; - assertThat(expected, "select l, date, timestamp , prev(date) over (order by l) from abc"); - assertThat(expected, "select l, date, timestamp , prev(date) over (order by l) from '*!*abc'"); - } - - @Test - public void testDouble() throws Exception { - final String expected = "1.050231933594\tBZ\tBZ\t2016-05-01T10:21:00.000Z\tNaN\n" + - "566.734375000000\tXX\tBZ\t2016-05-01T10:22:00.000Z\tNaN\n" + - "0.000013792171\tKK\tXX\t2016-05-01T10:23:00.000Z\tNaN\n" + - "0.000000567185\tAX\tXX\t2016-05-01T10:24:00.000Z\tNaN\n" + - "-512.000000000000\tAX\tXX\t2016-05-01T10:25:00.000Z\t0.000000567185\n" + - "0.675451681018\tAX\tBZ\t2016-05-01T10:26:00.000Z\t-512.000000000000\n" + - "0.332301996648\tBZ\tXX\t2016-05-01T10:27:00.000Z\t1.050231933594\n" + - "0.000001752813\tBZ\tKK\t2016-05-01T10:28:00.000Z\t0.332301996648\n" + - "0.000076281818\tAX\tKK\t2016-05-01T10:29:00.000Z\t0.675451681018\n" + - "0.000000005555\tBZ\tAX\t2016-05-01T10:30:00.000Z\t0.000001752813\n" + - "0.000002473130\tXX\tKK\t2016-05-01T10:31:00.000Z\t566.734375000000\n" + - "632.921875000000\tKK\tAX\t2016-05-01T10:32:00.000Z\t0.000013792171\n" + - "0.000000020896\tAX\tAX\t2016-05-01T10:33:00.000Z\t0.000076281818\n" + - "0.007371325744\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t0.000000005555\n" + - "0.000000014643\tXX\tAX\t2016-05-01T10:35:00.000Z\t0.000002473130\n" + - "512.000000000000\tAX\tAX\t2016-05-01T10:36:00.000Z\t0.000000020896\n" + - "864.000000000000\tXX\tKK\t2016-05-01T10:37:00.000Z\t0.000000014643\n" + - "0.000000157437\tAX\tAX\t2016-05-01T10:38:00.000Z\t512.000000000000\n" + - "-842.000000000000\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t0.007371325744\n" + - "0.000032060649\tBZ\tAX\t2016-05-01T10:40:00.000Z\t-842.000000000000\n"; - assertThat(expected, "select d, str, sym, timestamp , prev(d) over (partition by str) from abc"); - assertThat(expected, "select d, str, sym, timestamp , prev(d) over (partition by str) from '*!*abc'"); - } - - @Test - public void testDouble2() throws Exception { - final String expected = "1.050231933594\tBZ\tBZ\t2016-05-01T10:21:00.000Z\tNaN\n" + - "566.734375000000\tXX\tBZ\t2016-05-01T10:22:00.000Z\t1.050231933594\n" + - "0.000013792171\tKK\tXX\t2016-05-01T10:23:00.000Z\t566.734375000000\n" + - "0.000000567185\tAX\tXX\t2016-05-01T10:24:00.000Z\t0.000013792171\n" + - "-512.000000000000\tAX\tXX\t2016-05-01T10:25:00.000Z\t0.000000567185\n" + - "0.675451681018\tAX\tBZ\t2016-05-01T10:26:00.000Z\t-512.000000000000\n" + - "0.332301996648\tBZ\tXX\t2016-05-01T10:27:00.000Z\t0.675451681018\n" + - "0.000001752813\tBZ\tKK\t2016-05-01T10:28:00.000Z\t0.332301996648\n" + - "0.000076281818\tAX\tKK\t2016-05-01T10:29:00.000Z\t0.000001752813\n" + - "0.000000005555\tBZ\tAX\t2016-05-01T10:30:00.000Z\t0.000076281818\n" + - "0.000002473130\tXX\tKK\t2016-05-01T10:31:00.000Z\t0.000000005555\n" + - "632.921875000000\tKK\tAX\t2016-05-01T10:32:00.000Z\t0.000002473130\n" + - "0.000000020896\tAX\tAX\t2016-05-01T10:33:00.000Z\t632.921875000000\n" + - "0.007371325744\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t0.000000020896\n" + - "0.000000014643\tXX\tAX\t2016-05-01T10:35:00.000Z\t0.007371325744\n" + - "512.000000000000\tAX\tAX\t2016-05-01T10:36:00.000Z\t0.000000014643\n" + - "864.000000000000\tXX\tKK\t2016-05-01T10:37:00.000Z\t512.000000000000\n" + - "0.000000157437\tAX\tAX\t2016-05-01T10:38:00.000Z\t864.000000000000\n" + - "-842.000000000000\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t0.000000157437\n" + - "0.000032060649\tBZ\tAX\t2016-05-01T10:40:00.000Z\t-842.000000000000\n"; - assertThat(expected, "select d, str, sym, timestamp , prev(d) over () from abc"); - assertThat(expected, "select d, str, sym, timestamp , prev(d) over () from '*!*abc'"); - } - - @Test - public void testDoubleOrdered() throws Exception { - final String expected = "8920866532787660373\t1.050231933594\t2016-05-01T10:21:00.000Z\t0.000000157437\n" + - "-6943924477733600060\t566.734375000000\t2016-05-01T10:22:00.000Z\t0.000076281818\n" + - "-6856503215590263904\t0.000013792171\t2016-05-01T10:23:00.000Z\t566.734375000000\n" + - "8416773233910814357\t0.000000567185\t2016-05-01T10:24:00.000Z\t-842.000000000000\n" + - "7199909180655756830\t-512.000000000000\t2016-05-01T10:25:00.000Z\t632.921875000000\n" + - "6270672455202306717\t0.675451681018\t2016-05-01T10:26:00.000Z\t864.000000000000\n" + - "-6253307669002054137\t0.332301996648\t2016-05-01T10:27:00.000Z\t0.000000020896\n" + - "7392877322819819290\t0.000001752813\t2016-05-01T10:28:00.000Z\t-512.000000000000\n" + - "-7316123607359392486\t0.000076281818\t2016-05-01T10:29:00.000Z\t0.000002473130\n" + - "-3107239868490395663\t0.000000005555\t2016-05-01T10:30:00.000Z\t0.000032060649\n" + - "-7387846268299105911\t0.000002473130\t2016-05-01T10:31:00.000Z\t0.000000014643\n" + - "7122109662042058469\t632.921875000000\t2016-05-01T10:32:00.000Z\t512.000000000000\n" + - "-6626590012581323602\t0.000000020896\t2016-05-01T10:33:00.000Z\t0.000013792171\n" + - "8611582118025429627\t0.007371325744\t2016-05-01T10:34:00.000Z\t0.000000567185\n" + - "-8082754367165748693\t0.000000014643\t2016-05-01T10:35:00.000Z\tNaN\n" + - "6574958665733670985\t512.000000000000\t2016-05-01T10:36:00.000Z\t0.675451681018\n" + - "3446015290144635451\t864.000000000000\t2016-05-01T10:37:00.000Z\t0.000000005555\n" + - "8889492928577876455\t0.000000157437\t2016-05-01T10:38:00.000Z\t0.007371325744\n" + - "8152044974329490473\t-842.000000000000\t2016-05-01T10:39:00.000Z\t0.000001752813\n" + - "-6071768268784020226\t0.000032060649\t2016-05-01T10:40:00.000Z\t0.332301996648\n"; - assertThat(expected, "select l, d, timestamp , prev(d) over (order by l) from abc"); - assertThat(expected, "select l, d, timestamp , prev(d) over (order by l) from '*!*abc'"); - } - - @Test - public void testFloat() throws Exception { - final String expected = "0.6235\tBZ\tBZ\t2016-05-01T10:21:00.000Z\tNaN\n" + - "0.7780\tXX\tBZ\t2016-05-01T10:22:00.000Z\tNaN\n" + - "0.5509\tKK\tXX\t2016-05-01T10:23:00.000Z\tNaN\n" + - "0.0204\tAX\tXX\t2016-05-01T10:24:00.000Z\tNaN\n" + - "0.4848\tAX\tXX\t2016-05-01T10:25:00.000Z\t0.0204\n" + - "0.2969\tAX\tBZ\t2016-05-01T10:26:00.000Z\t0.4848\n" + - "0.5725\tBZ\tXX\t2016-05-01T10:27:00.000Z\t0.6235\n" + - "0.5967\tBZ\tKK\t2016-05-01T10:28:00.000Z\t0.5725\n" + - "0.1609\tAX\tKK\t2016-05-01T10:29:00.000Z\t0.2969\n" + - "0.3509\tBZ\tAX\t2016-05-01T10:30:00.000Z\t0.5967\n" + - "0.7274\tXX\tKK\t2016-05-01T10:31:00.000Z\t0.7780\n" + - "0.5619\tKK\tAX\t2016-05-01T10:32:00.000Z\t0.5509\n" + - "0.5433\tAX\tAX\t2016-05-01T10:33:00.000Z\t0.1609\n" + - "0.5442\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t0.3509\n" + - "0.6746\tXX\tAX\t2016-05-01T10:35:00.000Z\t0.7274\n" + - "0.8217\tAX\tAX\t2016-05-01T10:36:00.000Z\t0.5433\n" + - "0.3591\tXX\tKK\t2016-05-01T10:37:00.000Z\t0.6746\n" + - "0.6827\tAX\tAX\t2016-05-01T10:38:00.000Z\t0.8217\n" + - "0.1168\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t0.5442\n" + - "0.4967\tBZ\tAX\t2016-05-01T10:40:00.000Z\t0.1168\n"; - assertThat(expected, "select f, str, sym, timestamp , prev(f) over (partition by str) from abc"); - assertThat(expected, "select f, str, sym, timestamp , prev(f) over (partition by str) from '*!*abc'"); - } - - @Test - public void testFloat2() throws Exception { - final String expected = "0.6235\tBZ\tBZ\t2016-05-01T10:21:00.000Z\tNaN\n" + - "0.7780\tXX\tBZ\t2016-05-01T10:22:00.000Z\t0.6235\n" + - "0.5509\tKK\tXX\t2016-05-01T10:23:00.000Z\t0.7780\n" + - "0.0204\tAX\tXX\t2016-05-01T10:24:00.000Z\t0.5509\n" + - "0.4848\tAX\tXX\t2016-05-01T10:25:00.000Z\t0.0204\n" + - "0.2969\tAX\tBZ\t2016-05-01T10:26:00.000Z\t0.4848\n" + - "0.5725\tBZ\tXX\t2016-05-01T10:27:00.000Z\t0.2969\n" + - "0.5967\tBZ\tKK\t2016-05-01T10:28:00.000Z\t0.5725\n" + - "0.1609\tAX\tKK\t2016-05-01T10:29:00.000Z\t0.5967\n" + - "0.3509\tBZ\tAX\t2016-05-01T10:30:00.000Z\t0.1609\n" + - "0.7274\tXX\tKK\t2016-05-01T10:31:00.000Z\t0.3509\n" + - "0.5619\tKK\tAX\t2016-05-01T10:32:00.000Z\t0.7274\n" + - "0.5433\tAX\tAX\t2016-05-01T10:33:00.000Z\t0.5619\n" + - "0.5442\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t0.5433\n" + - "0.6746\tXX\tAX\t2016-05-01T10:35:00.000Z\t0.5442\n" + - "0.8217\tAX\tAX\t2016-05-01T10:36:00.000Z\t0.6746\n" + - "0.3591\tXX\tKK\t2016-05-01T10:37:00.000Z\t0.8217\n" + - "0.6827\tAX\tAX\t2016-05-01T10:38:00.000Z\t0.3591\n" + - "0.1168\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t0.6827\n" + - "0.4967\tBZ\tAX\t2016-05-01T10:40:00.000Z\t0.1168\n"; - assertThat(expected, "select f, str, sym, timestamp , prev(f) over () from abc"); - assertThat(expected, "select f, str, sym, timestamp , prev(f) over () from '*!*abc'"); - } - - @Test - public void testFloatOrdered() throws Exception { - final String expected = "8920866532787660373\t0.6235\t2016-05-01T10:21:00.000Z\t0.6827\n" + - "-6943924477733600060\t0.7780\t2016-05-01T10:22:00.000Z\t0.1609\n" + - "-6856503215590263904\t0.5509\t2016-05-01T10:23:00.000Z\t0.7780\n" + - "8416773233910814357\t0.0204\t2016-05-01T10:24:00.000Z\t0.1168\n" + - "7199909180655756830\t0.4848\t2016-05-01T10:25:00.000Z\t0.5619\n" + - "6270672455202306717\t0.2969\t2016-05-01T10:26:00.000Z\t0.3591\n" + - "-6253307669002054137\t0.5725\t2016-05-01T10:27:00.000Z\t0.5433\n" + - "7392877322819819290\t0.5967\t2016-05-01T10:28:00.000Z\t0.4848\n" + - "-7316123607359392486\t0.1609\t2016-05-01T10:29:00.000Z\t0.7274\n" + - "-3107239868490395663\t0.3509\t2016-05-01T10:30:00.000Z\t0.4967\n" + - "-7387846268299105911\t0.7274\t2016-05-01T10:31:00.000Z\t0.6746\n" + - "7122109662042058469\t0.5619\t2016-05-01T10:32:00.000Z\t0.8217\n" + - "-6626590012581323602\t0.5433\t2016-05-01T10:33:00.000Z\t0.5509\n" + - "8611582118025429627\t0.5442\t2016-05-01T10:34:00.000Z\t0.0204\n" + - "-8082754367165748693\t0.6746\t2016-05-01T10:35:00.000Z\tNaN\n" + - "6574958665733670985\t0.8217\t2016-05-01T10:36:00.000Z\t0.2969\n" + - "3446015290144635451\t0.3591\t2016-05-01T10:37:00.000Z\t0.3509\n" + - "8889492928577876455\t0.6827\t2016-05-01T10:38:00.000Z\t0.5442\n" + - "8152044974329490473\t0.1168\t2016-05-01T10:39:00.000Z\t0.5967\n" + - "-6071768268784020226\t0.4967\t2016-05-01T10:40:00.000Z\t0.5725\n"; - assertThat(expected, "select l, f, timestamp , prev(f) over (order by l) from abc"); - assertThat(expected, "select l, f, timestamp , prev(f) over (order by l) from '*!*abc'"); - } - - @Test - public void testImplicitOrderFromSubQueryOnRenamedColumn() throws Exception { - final String expected = "BZ\tBZ\t\t2016-05-01T10:21:00.000Z\n" + - "BZ\tXX\tBZ\t2016-05-01T10:22:00.000Z\n" + - "XX\tKK\t\t2016-05-01T10:23:00.000Z\n" + - "XX\tAX\tKK\t2016-05-01T10:24:00.000Z\n" + - "XX\tAX\tAX\t2016-05-01T10:25:00.000Z\n" + - "BZ\tAX\tXX\t2016-05-01T10:26:00.000Z\n" + - "XX\tBZ\tAX\t2016-05-01T10:27:00.000Z\n" + - "KK\tBZ\t\t2016-05-01T10:28:00.000Z\n" + - "KK\tAX\tBZ\t2016-05-01T10:29:00.000Z\n" + - "AX\tBZ\t\t2016-05-01T10:30:00.000Z\n" + - "KK\tXX\tAX\t2016-05-01T10:31:00.000Z\n" + - "AX\tKK\tBZ\t2016-05-01T10:32:00.000Z\n" + - "AX\tAX\tKK\t2016-05-01T10:33:00.000Z\n" + - "BZ\tBZ\tAX\t2016-05-01T10:34:00.000Z\n" + - "AX\tXX\tAX\t2016-05-01T10:35:00.000Z\n" + - "AX\tAX\tXX\t2016-05-01T10:36:00.000Z\n" + - "KK\tXX\tXX\t2016-05-01T10:37:00.000Z\n" + - "AX\tAX\tAX\t2016-05-01T10:38:00.000Z\n" + - "BZ\tBZ\tBZ\t2016-05-01T10:39:00.000Z\n" + - "AX\tBZ\tAX\t2016-05-01T10:40:00.000Z\n"; - - assertThat(expected, "select sym, str, prev(str) over (partition by sym order by x), x from (select timestamp x, sym, str from (abc order by timestamp))"); - - assertPlan2("{\n" + - " \"op\": \"SelectedColumnsRecordSource\",\n" + - " \"src\": {\n" + - " \"op\": \"CachedRowAnalyticRecordSource\",\n" + - " \"functions\": 1,\n" + - " \"orderedSources\": 1,\n" + - " \"src\": {\n" + - " \"op\": \"SelectedColumnsRecordSource\",\n" + - " \"src\": {\n" + - " \"op\": \"RBTreeSortedRecordSource\",\n" + - " \"byRowId\": true,\n" + - " \"src\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"abc\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - "}", "select sym, str, prev(str) over (partition by sym order by x), x from (select timestamp x, sym, str from (abc order by timestamp))"); - } - - @Test - public void testImplicitOrderSimple() throws Exception { - assertPlan2("{\n" + - " \"op\": \"RBTreeSortedRecordSource\",\n" + - " \"byRowId\": false,\n" + - " \"src\": {\n" + - " \"op\": \"SelectedColumnsRecordSource\",\n" + - " \"src\": {\n" + - " \"op\": \"CachedRowAnalyticRecordSource\",\n" + - " \"functions\": 1,\n" + - " \"orderedSources\": 1,\n" + - " \"src\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"abc\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - "}", "select sym, str, prev(str) over (partition by sym order by timestamp), timestamp from abc order by timestamp"); - } - - @Test - public void testIntOrdered() throws Exception { - final String expected = "8920866532787660373\t-1148479920\t2016-05-01T10:21:00.000Z\t-1383560599\n" + - "-6943924477733600060\t-2041844972\t2016-05-01T10:22:00.000Z\t-1787109293\n" + - "-6856503215590263904\t-1532328444\t2016-05-01T10:23:00.000Z\t-2041844972\n" + - "8416773233910814357\t-1153445279\t2016-05-01T10:24:00.000Z\t1751526583\n" + - "7199909180655756830\t1699553881\t2016-05-01T10:25:00.000Z\t-572338288\n" + - "6270672455202306717\t2006313928\t2016-05-01T10:26:00.000Z\t1598679468\n" + - "-6253307669002054137\t-2002373666\t2016-05-01T10:27:00.000Z\t-731466113\n" + - "7392877322819819290\t-296610933\t2016-05-01T10:28:00.000Z\t1699553881\n" + - "-7316123607359392486\t-1787109293\t2016-05-01T10:29:00.000Z\t-1566901076\n" + - "-3107239868490395663\t-235358133\t2016-05-01T10:30:00.000Z\t-1475953213\n" + - "-7387846268299105911\t-1566901076\t2016-05-01T10:31:00.000Z\t-1966408995\n" + - "7122109662042058469\t-572338288\t2016-05-01T10:32:00.000Z\t1335037859\n" + - "-6626590012581323602\t-731466113\t2016-05-01T10:33:00.000Z\t-1532328444\n" + - "8611582118025429627\t-1389094446\t2016-05-01T10:34:00.000Z\t-1153445279\n" + - "-8082754367165748693\t-1966408995\t2016-05-01T10:35:00.000Z\tNaN\n" + - "6574958665733670985\t1335037859\t2016-05-01T10:36:00.000Z\t2006313928\n" + - "3446015290144635451\t1598679468\t2016-05-01T10:37:00.000Z\t-235358133\n" + - "8889492928577876455\t-1383560599\t2016-05-01T10:38:00.000Z\t-1389094446\n" + - "8152044974329490473\t1751526583\t2016-05-01T10:39:00.000Z\t-296610933\n" + - "-6071768268784020226\t-1475953213\t2016-05-01T10:40:00.000Z\t-2002373666\n"; - assertThat(expected, "select l, i, timestamp , prev(i) over (order by l) from abc"); - assertThat(expected, "select l, i, timestamp , prev(i) over (order by l) from '*!*abc'"); - } - - @Test - public void testLong() throws Exception { - final String expected = "8920866532787660373\tBZ\tBZ\t2016-05-01T10:21:00.000Z\tNaN\n" + - "-6943924477733600060\tXX\tBZ\t2016-05-01T10:22:00.000Z\tNaN\n" + - "-6856503215590263904\tKK\tXX\t2016-05-01T10:23:00.000Z\tNaN\n" + - "8416773233910814357\tAX\tXX\t2016-05-01T10:24:00.000Z\tNaN\n" + - "7199909180655756830\tAX\tXX\t2016-05-01T10:25:00.000Z\t8416773233910814357\n" + - "6270672455202306717\tAX\tBZ\t2016-05-01T10:26:00.000Z\t7199909180655756830\n" + - "-6253307669002054137\tBZ\tXX\t2016-05-01T10:27:00.000Z\t8920866532787660373\n" + - "7392877322819819290\tBZ\tKK\t2016-05-01T10:28:00.000Z\t-6253307669002054137\n" + - "-7316123607359392486\tAX\tKK\t2016-05-01T10:29:00.000Z\t6270672455202306717\n" + - "-3107239868490395663\tBZ\tAX\t2016-05-01T10:30:00.000Z\t7392877322819819290\n" + - "-7387846268299105911\tXX\tKK\t2016-05-01T10:31:00.000Z\t-6943924477733600060\n" + - "7122109662042058469\tKK\tAX\t2016-05-01T10:32:00.000Z\t-6856503215590263904\n" + - "-6626590012581323602\tAX\tAX\t2016-05-01T10:33:00.000Z\t-7316123607359392486\n" + - "8611582118025429627\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t-3107239868490395663\n" + - "-8082754367165748693\tXX\tAX\t2016-05-01T10:35:00.000Z\t-7387846268299105911\n" + - "6574958665733670985\tAX\tAX\t2016-05-01T10:36:00.000Z\t-6626590012581323602\n" + - "3446015290144635451\tXX\tKK\t2016-05-01T10:37:00.000Z\t-8082754367165748693\n" + - "8889492928577876455\tAX\tAX\t2016-05-01T10:38:00.000Z\t6574958665733670985\n" + - "8152044974329490473\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t8611582118025429627\n" + - "-6071768268784020226\tBZ\tAX\t2016-05-01T10:40:00.000Z\t8152044974329490473\n"; - assertThat(expected, "select l, str, sym, timestamp , prev(l) over (partition by str) from abc"); - assertThat(expected, "select l, str, sym, timestamp , prev(l) over (partition by str) from '*!*abc'"); - } - - @Test - public void testLong2() throws Exception { - final String expected = "8920866532787660373\tBZ\tBZ\t2016-05-01T10:21:00.000Z\tNaN\n" + - "-6943924477733600060\tXX\tBZ\t2016-05-01T10:22:00.000Z\t8920866532787660373\n" + - "-6856503215590263904\tKK\tXX\t2016-05-01T10:23:00.000Z\t-6943924477733600060\n" + - "8416773233910814357\tAX\tXX\t2016-05-01T10:24:00.000Z\t-6856503215590263904\n" + - "7199909180655756830\tAX\tXX\t2016-05-01T10:25:00.000Z\t8416773233910814357\n" + - "6270672455202306717\tAX\tBZ\t2016-05-01T10:26:00.000Z\t7199909180655756830\n" + - "-6253307669002054137\tBZ\tXX\t2016-05-01T10:27:00.000Z\t6270672455202306717\n" + - "7392877322819819290\tBZ\tKK\t2016-05-01T10:28:00.000Z\t-6253307669002054137\n" + - "-7316123607359392486\tAX\tKK\t2016-05-01T10:29:00.000Z\t7392877322819819290\n" + - "-3107239868490395663\tBZ\tAX\t2016-05-01T10:30:00.000Z\t-7316123607359392486\n" + - "-7387846268299105911\tXX\tKK\t2016-05-01T10:31:00.000Z\t-3107239868490395663\n" + - "7122109662042058469\tKK\tAX\t2016-05-01T10:32:00.000Z\t-7387846268299105911\n" + - "-6626590012581323602\tAX\tAX\t2016-05-01T10:33:00.000Z\t7122109662042058469\n" + - "8611582118025429627\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t-6626590012581323602\n" + - "-8082754367165748693\tXX\tAX\t2016-05-01T10:35:00.000Z\t8611582118025429627\n" + - "6574958665733670985\tAX\tAX\t2016-05-01T10:36:00.000Z\t-8082754367165748693\n" + - "3446015290144635451\tXX\tKK\t2016-05-01T10:37:00.000Z\t6574958665733670985\n" + - "8889492928577876455\tAX\tAX\t2016-05-01T10:38:00.000Z\t3446015290144635451\n" + - "8152044974329490473\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t8889492928577876455\n" + - "-6071768268784020226\tBZ\tAX\t2016-05-01T10:40:00.000Z\t8152044974329490473\n"; - assertThat(expected, "select l, str, sym, timestamp , prev(l) over () from abc"); - assertThat(expected, "select l, str, sym, timestamp , prev(l) over () from '*!*abc'"); - } - - @Test - public void testLongOrdered() throws Exception { - final String expected = "8920866532787660373\t-1148479920\t2016-05-01T10:21:00.000Z\t8416773233910814357\n" + - "-6943924477733600060\t-2041844972\t2016-05-01T10:22:00.000Z\tNaN\n" + - "-6856503215590263904\t-1532328444\t2016-05-01T10:23:00.000Z\t-7387846268299105911\n" + - "8416773233910814357\t-1153445279\t2016-05-01T10:24:00.000Z\t8889492928577876455\n" + - "7199909180655756830\t1699553881\t2016-05-01T10:25:00.000Z\t3446015290144635451\n" + - "6270672455202306717\t2006313928\t2016-05-01T10:26:00.000Z\t8152044974329490473\n" + - "-6253307669002054137\t-2002373666\t2016-05-01T10:27:00.000Z\t-6943924477733600060\n" + - "7392877322819819290\t-296610933\t2016-05-01T10:28:00.000Z\t7122109662042058469\n" + - "-7316123607359392486\t-1787109293\t2016-05-01T10:29:00.000Z\t-8082754367165748693\n" + - "-3107239868490395663\t-235358133\t2016-05-01T10:30:00.000Z\t7392877322819819290\n" + - "-7387846268299105911\t-1566901076\t2016-05-01T10:31:00.000Z\t-7316123607359392486\n" + - "7122109662042058469\t-572338288\t2016-05-01T10:32:00.000Z\t-6626590012581323602\n" + - "-6626590012581323602\t-731466113\t2016-05-01T10:33:00.000Z\t8920866532787660373\n" + - "8611582118025429627\t-1389094446\t2016-05-01T10:34:00.000Z\t-6071768268784020226\n" + - "-8082754367165748693\t-1966408995\t2016-05-01T10:35:00.000Z\t-6253307669002054137\n" + - "6574958665733670985\t1335037859\t2016-05-01T10:36:00.000Z\t-3107239868490395663\n" + - "3446015290144635451\t1598679468\t2016-05-01T10:37:00.000Z\t6574958665733670985\n" + - "8889492928577876455\t-1383560599\t2016-05-01T10:38:00.000Z\t8611582118025429627\n" + - "8152044974329490473\t1751526583\t2016-05-01T10:39:00.000Z\t7199909180655756830\n" + - "-6071768268784020226\t-1475953213\t2016-05-01T10:40:00.000Z\t-6856503215590263904\n"; - assertThat(expected, "select l, i, timestamp , prev(l) over (order by i) from abc"); - assertThat(expected, "select l, i, timestamp , prev(l) over (order by i) from '*!*abc'"); - } - - @Test - public void testMultipleNoPart() throws Exception { - final String expected = "str\tsym\ttimestamp\tcol0\tcol1\n" + - "BZ\tBZ\t2016-05-01T10:21:00.000Z\t\t\n" + - "XX\tBZ\t2016-05-01T10:22:00.000Z\tBZ\tBZ\n" + - "KK\tXX\t2016-05-01T10:23:00.000Z\tBZ\tXX\n" + - "AX\tXX\t2016-05-01T10:24:00.000Z\tXX\tKK\n" + - "AX\tXX\t2016-05-01T10:25:00.000Z\tXX\tAX\n" + - "AX\tBZ\t2016-05-01T10:26:00.000Z\tXX\tAX\n" + - "BZ\tXX\t2016-05-01T10:27:00.000Z\tBZ\tAX\n" + - "BZ\tKK\t2016-05-01T10:28:00.000Z\tXX\tBZ\n" + - "AX\tKK\t2016-05-01T10:29:00.000Z\tKK\tBZ\n" + - "BZ\tAX\t2016-05-01T10:30:00.000Z\tKK\tAX\n" + - "XX\tKK\t2016-05-01T10:31:00.000Z\tAX\tBZ\n" + - "KK\tAX\t2016-05-01T10:32:00.000Z\tKK\tXX\n" + - "AX\tAX\t2016-05-01T10:33:00.000Z\tAX\tKK\n" + - "BZ\tBZ\t2016-05-01T10:34:00.000Z\tAX\tAX\n" + - "XX\tAX\t2016-05-01T10:35:00.000Z\tBZ\tBZ\n" + - "AX\tAX\t2016-05-01T10:36:00.000Z\tAX\tXX\n" + - "XX\tKK\t2016-05-01T10:37:00.000Z\tAX\tAX\n" + - "AX\tAX\t2016-05-01T10:38:00.000Z\tKK\tXX\n" + - "BZ\tBZ\t2016-05-01T10:39:00.000Z\tAX\tAX\n" + - "BZ\tAX\t2016-05-01T10:40:00.000Z\tBZ\tBZ\n"; - assertThat(expected, "select str, sym, timestamp , prev(sym) over(), prev(str) over () from abc", true); - assertThat(expected, "select str, sym, timestamp , prev(sym) over(), prev(str) over () from '*!*abc'", true); - } - - @Test - public void testNoArg() { - try { - expectFailure("select str, prev() rank over(partition by str) from 'abc'"); - } catch (ParserException e) { - TestUtils.assertEquals("Unknown function", QueryError.getMessage()); - } - } - - @Test - public void testNoRowIdPlan() throws Exception { - final String expected = "{\n" + - " \"op\": \"SelectedColumnsRecordSource\",\n" + - " \"src\": {\n" + - " \"op\": \"AnalyticRecordSource\",\n" + - " \"functions\": 1,\n" + - " \"src\": {\n" + - " \"op\": \"NoRowIdRecordSource\",\n" + - " \"src\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"abc\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - "}"; - assertPlan2(expected, "select str, sym, timestamp , prev(sym) over () from '*!*abc'"); - } - - @Test - public void testNonPartSymbolBehaviour() throws Exception { - assertSymbol("select str, sym, timestamp , prev(sym) over () from abc", 3); - } - - @Test - public void testOrderBySymbolBehaviour() throws Exception { - assertSymbol("select str, sym, timestamp , prev(sym) x over (partition by str) from abc order by x", 3); - } - - @Test - public void testOrderedSymbolBehaviour() throws Exception { - assertSymbol("select l, sym, timestamp , prev(sym) over (order by l) from abc", 3); - } - - @Test - public void testPlan() throws Exception { - assertPlan2("{\n" + - " \"op\": \"SelectedColumnsRecordSource\",\n" + - " \"src\": {\n" + - " \"op\": \"AnalyticRecordSource\",\n" + - " \"functions\": 1,\n" + - " \"src\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"abc\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " }\n" + - " }\n" + - "}", "select sym, prev(d) over() from abc"); - } - - @Test - public void testPrevMixed() throws Exception { - final String expected = "8920866532787660373\tBZ\t2016-05-01T10:21:00.000Z\t\tAX\n" + - "-6943924477733600060\tBZ\t2016-05-01T10:22:00.000Z\tBZ\tKK\n" + - "-6856503215590263904\tXX\t2016-05-01T10:23:00.000Z\tBZ\tBZ\n" + - "8416773233910814357\tXX\t2016-05-01T10:24:00.000Z\tXX\tBZ\n" + - "7199909180655756830\tXX\t2016-05-01T10:25:00.000Z\tXX\tAX\n" + - "6270672455202306717\tBZ\t2016-05-01T10:26:00.000Z\tXX\tKK\n" + - "-6253307669002054137\tXX\t2016-05-01T10:27:00.000Z\tBZ\tAX\n" + - "7392877322819819290\tKK\t2016-05-01T10:28:00.000Z\tXX\tXX\n" + - "-7316123607359392486\tKK\t2016-05-01T10:29:00.000Z\tKK\tKK\n" + - "-3107239868490395663\tAX\t2016-05-01T10:30:00.000Z\tKK\tAX\n" + - "-7387846268299105911\tKK\t2016-05-01T10:31:00.000Z\tAX\tAX\n" + - "7122109662042058469\tAX\t2016-05-01T10:32:00.000Z\tKK\tAX\n" + - "-6626590012581323602\tAX\t2016-05-01T10:33:00.000Z\tAX\tXX\n" + - "8611582118025429627\tBZ\t2016-05-01T10:34:00.000Z\tAX\tXX\n" + - "-8082754367165748693\tAX\t2016-05-01T10:35:00.000Z\tBZ\t\n" + - "6574958665733670985\tAX\t2016-05-01T10:36:00.000Z\tAX\tBZ\n" + - "3446015290144635451\tKK\t2016-05-01T10:37:00.000Z\tAX\tAX\n" + - "8889492928577876455\tAX\t2016-05-01T10:38:00.000Z\tKK\tBZ\n" + - "8152044974329490473\tBZ\t2016-05-01T10:39:00.000Z\tAX\tKK\n" + - "-6071768268784020226\tAX\t2016-05-01T10:40:00.000Z\tBZ\tXX\n"; - assertThat(expected, "select l, sym, timestamp , prev(sym) over(), prev(sym) over (order by l) from abc"); - assertThat(expected, "select l, sym, timestamp , prev(sym) over(), prev(sym) over (order by l) from '*!*abc'"); - } - - @Test - public void testPrevMixed2() throws Exception { - final String expected = "BZ\t8920866532787660373\tBZ\t2016-05-01T10:21:00.000Z\t\tAX\n" + - "XX\t-6943924477733600060\tBZ\t2016-05-01T10:22:00.000Z\t\tKK\n" + - "KK\t-6856503215590263904\tXX\t2016-05-01T10:23:00.000Z\t\tBZ\n" + - "AX\t8416773233910814357\tXX\t2016-05-01T10:24:00.000Z\t\tBZ\n" + - "AX\t7199909180655756830\tXX\t2016-05-01T10:25:00.000Z\tXX\tAX\n" + - "AX\t6270672455202306717\tBZ\t2016-05-01T10:26:00.000Z\tXX\tKK\n" + - "BZ\t-6253307669002054137\tXX\t2016-05-01T10:27:00.000Z\tBZ\tAX\n" + - "BZ\t7392877322819819290\tKK\t2016-05-01T10:28:00.000Z\tXX\tXX\n" + - "AX\t-7316123607359392486\tKK\t2016-05-01T10:29:00.000Z\tBZ\tKK\n" + - "BZ\t-3107239868490395663\tAX\t2016-05-01T10:30:00.000Z\tKK\tAX\n" + - "XX\t-7387846268299105911\tKK\t2016-05-01T10:31:00.000Z\tBZ\tAX\n" + - "KK\t7122109662042058469\tAX\t2016-05-01T10:32:00.000Z\tXX\tAX\n" + - "AX\t-6626590012581323602\tAX\t2016-05-01T10:33:00.000Z\tKK\tXX\n" + - "BZ\t8611582118025429627\tBZ\t2016-05-01T10:34:00.000Z\tAX\tXX\n" + - "XX\t-8082754367165748693\tAX\t2016-05-01T10:35:00.000Z\tKK\t\n" + - "AX\t6574958665733670985\tAX\t2016-05-01T10:36:00.000Z\tAX\tBZ\n" + - "XX\t3446015290144635451\tKK\t2016-05-01T10:37:00.000Z\tAX\tAX\n" + - "AX\t8889492928577876455\tAX\t2016-05-01T10:38:00.000Z\tAX\tBZ\n" + - "BZ\t8152044974329490473\tBZ\t2016-05-01T10:39:00.000Z\tBZ\tKK\n" + - "BZ\t-6071768268784020226\tAX\t2016-05-01T10:40:00.000Z\tBZ\tXX\n"; - assertThat(expected, "select str, l, sym, timestamp , prev(sym) over(partition by str), prev(sym) over (order by l) from abc"); - assertThat(expected, "select str, l, sym, timestamp , prev(sym) over(partition by str), prev(sym) over (order by l) from '*!*abc'"); - } - - @Test - public void testPrevNextMixed() throws Exception { - final String expected = "BZ\tBZ\t2016-05-01T10:21:00.000Z\t\tXX\n" + - "XX\tBZ\t2016-05-01T10:22:00.000Z\t\tKK\n" + - "KK\tXX\t2016-05-01T10:23:00.000Z\t\tAX\n" + - "AX\tXX\t2016-05-01T10:24:00.000Z\t\tXX\n" + - "AX\tXX\t2016-05-01T10:25:00.000Z\tXX\tBZ\n" + - "AX\tBZ\t2016-05-01T10:26:00.000Z\tXX\tKK\n" + - "BZ\tXX\t2016-05-01T10:27:00.000Z\tBZ\tKK\n" + - "BZ\tKK\t2016-05-01T10:28:00.000Z\tXX\tAX\n" + - "AX\tKK\t2016-05-01T10:29:00.000Z\tBZ\tAX\n" + - "BZ\tAX\t2016-05-01T10:30:00.000Z\tKK\tBZ\n" + - "XX\tKK\t2016-05-01T10:31:00.000Z\tBZ\tAX\n" + - "KK\tAX\t2016-05-01T10:32:00.000Z\tXX\t\n" + - "AX\tAX\t2016-05-01T10:33:00.000Z\tKK\tAX\n" + - "BZ\tBZ\t2016-05-01T10:34:00.000Z\tAX\tBZ\n" + - "XX\tAX\t2016-05-01T10:35:00.000Z\tKK\tKK\n" + - "AX\tAX\t2016-05-01T10:36:00.000Z\tAX\tAX\n" + - "XX\tKK\t2016-05-01T10:37:00.000Z\tAX\t\n" + - "AX\tAX\t2016-05-01T10:38:00.000Z\tAX\t\n" + - "BZ\tBZ\t2016-05-01T10:39:00.000Z\tBZ\tAX\n" + - "BZ\tAX\t2016-05-01T10:40:00.000Z\tBZ\t\n"; - assertThat(expected, "select str, sym, timestamp , prev(sym) over(partition by str), next(sym) over (partition by str) from abc"); - assertThat(expected, "select str, sym, timestamp , prev(sym) over(partition by str), next(sym) over (partition by str) from '*!*abc'"); - } - - @Test - public void testShort() throws Exception { - final String expected = "-19496\tBZ\tBZ\t2016-05-01T10:21:00.000Z\t0\n" + - "-24357\tXX\tBZ\t2016-05-01T10:22:00.000Z\t0\n" + - "21781\tKK\tXX\t2016-05-01T10:23:00.000Z\t0\n" + - "-19127\tAX\tXX\t2016-05-01T10:24:00.000Z\t0\n" + - "-15458\tAX\tXX\t2016-05-01T10:25:00.000Z\t-19127\n" + - "-22934\tAX\tBZ\t2016-05-01T10:26:00.000Z\t-15458\n" + - "-391\tBZ\tXX\t2016-05-01T10:27:00.000Z\t-19496\n" + - "-26951\tBZ\tKK\t2016-05-01T10:28:00.000Z\t-391\n" + - "-19136\tAX\tKK\t2016-05-01T10:29:00.000Z\t-22934\n" + - "-15331\tBZ\tAX\t2016-05-01T10:30:00.000Z\t-26951\n" + - "-4874\tXX\tKK\t2016-05-01T10:31:00.000Z\t-24357\n" + - "25102\tKK\tAX\t2016-05-01T10:32:00.000Z\t21781\n" + - "-20409\tAX\tAX\t2016-05-01T10:33:00.000Z\t-19136\n" + - "-29572\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t-15331\n" + - "25974\tXX\tAX\t2016-05-01T10:35:00.000Z\t-4874\n" + - "5869\tAX\tAX\t2016-05-01T10:36:00.000Z\t-20409\n" + - "-22894\tXX\tKK\t2016-05-01T10:37:00.000Z\t25974\n" + - "-18600\tAX\tAX\t2016-05-01T10:38:00.000Z\t5869\n" + - "11755\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t-29572\n" + - "-24455\tBZ\tAX\t2016-05-01T10:40:00.000Z\t11755\n"; - assertThat(expected, "select sho, str, sym, timestamp , prev(sho) over (partition by str) from abc"); - assertThat(expected, "select sho, str, sym, timestamp , prev(sho) over (partition by str) from '*!*abc'"); - } - - @Test - public void testShort2() throws Exception { - final String expected = "-19496\tBZ\tBZ\t2016-05-01T10:21:00.000Z\t0\n" + - "-24357\tXX\tBZ\t2016-05-01T10:22:00.000Z\t-19496\n" + - "21781\tKK\tXX\t2016-05-01T10:23:00.000Z\t-24357\n" + - "-19127\tAX\tXX\t2016-05-01T10:24:00.000Z\t21781\n" + - "-15458\tAX\tXX\t2016-05-01T10:25:00.000Z\t-19127\n" + - "-22934\tAX\tBZ\t2016-05-01T10:26:00.000Z\t-15458\n" + - "-391\tBZ\tXX\t2016-05-01T10:27:00.000Z\t-22934\n" + - "-26951\tBZ\tKK\t2016-05-01T10:28:00.000Z\t-391\n" + - "-19136\tAX\tKK\t2016-05-01T10:29:00.000Z\t-26951\n" + - "-15331\tBZ\tAX\t2016-05-01T10:30:00.000Z\t-19136\n" + - "-4874\tXX\tKK\t2016-05-01T10:31:00.000Z\t-15331\n" + - "25102\tKK\tAX\t2016-05-01T10:32:00.000Z\t-4874\n" + - "-20409\tAX\tAX\t2016-05-01T10:33:00.000Z\t25102\n" + - "-29572\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t-20409\n" + - "25974\tXX\tAX\t2016-05-01T10:35:00.000Z\t-29572\n" + - "5869\tAX\tAX\t2016-05-01T10:36:00.000Z\t25974\n" + - "-22894\tXX\tKK\t2016-05-01T10:37:00.000Z\t5869\n" + - "-18600\tAX\tAX\t2016-05-01T10:38:00.000Z\t-22894\n" + - "11755\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t-18600\n" + - "-24455\tBZ\tAX\t2016-05-01T10:40:00.000Z\t11755\n"; - assertThat(expected, "select sho, str, sym, timestamp , prev(sho) over () from abc"); - assertThat(expected, "select sho, str, sym, timestamp , prev(sho) over () from '*!*abc'"); - } - - @Test - public void testShortAliased() throws Exception { - final String expected = "sho\tstr\tsym\ttimestamp\tblah\n" + - "-19496\tBZ\tBZ\t2016-05-01T10:21:00.000Z\t0\n" + - "-24357\tXX\tBZ\t2016-05-01T10:22:00.000Z\t0\n" + - "21781\tKK\tXX\t2016-05-01T10:23:00.000Z\t0\n" + - "-19127\tAX\tXX\t2016-05-01T10:24:00.000Z\t0\n" + - "-15458\tAX\tXX\t2016-05-01T10:25:00.000Z\t-19127\n" + - "-22934\tAX\tBZ\t2016-05-01T10:26:00.000Z\t-15458\n" + - "-391\tBZ\tXX\t2016-05-01T10:27:00.000Z\t-19496\n" + - "-26951\tBZ\tKK\t2016-05-01T10:28:00.000Z\t-391\n" + - "-19136\tAX\tKK\t2016-05-01T10:29:00.000Z\t-22934\n" + - "-15331\tBZ\tAX\t2016-05-01T10:30:00.000Z\t-26951\n" + - "-4874\tXX\tKK\t2016-05-01T10:31:00.000Z\t-24357\n" + - "25102\tKK\tAX\t2016-05-01T10:32:00.000Z\t21781\n" + - "-20409\tAX\tAX\t2016-05-01T10:33:00.000Z\t-19136\n" + - "-29572\tBZ\tBZ\t2016-05-01T10:34:00.000Z\t-15331\n" + - "25974\tXX\tAX\t2016-05-01T10:35:00.000Z\t-4874\n" + - "5869\tAX\tAX\t2016-05-01T10:36:00.000Z\t-20409\n" + - "-22894\tXX\tKK\t2016-05-01T10:37:00.000Z\t25974\n" + - "-18600\tAX\tAX\t2016-05-01T10:38:00.000Z\t5869\n" + - "11755\tBZ\tBZ\t2016-05-01T10:39:00.000Z\t-29572\n" + - "-24455\tBZ\tAX\t2016-05-01T10:40:00.000Z\t11755\n"; - assertThat(expected, "select sho, str, sym, timestamp , prev(sho) blah over (partition by str) from abc", true); - assertThat(expected, "select sho, str, sym, timestamp , prev(sho) blah over (partition by str) from '*!*abc'", true); - } - - @Test - public void testShortOrdered() throws Exception { - final String expected = "8920866532787660373\t-19496\t2016-05-01T10:21:00.000Z\t-18600\n" + - "-6943924477733600060\t-24357\t2016-05-01T10:22:00.000Z\t-19136\n" + - "-6856503215590263904\t21781\t2016-05-01T10:23:00.000Z\t-24357\n" + - "8416773233910814357\t-19127\t2016-05-01T10:24:00.000Z\t11755\n" + - "7199909180655756830\t-15458\t2016-05-01T10:25:00.000Z\t25102\n" + - "6270672455202306717\t-22934\t2016-05-01T10:26:00.000Z\t-22894\n" + - "-6253307669002054137\t-391\t2016-05-01T10:27:00.000Z\t-20409\n" + - "7392877322819819290\t-26951\t2016-05-01T10:28:00.000Z\t-15458\n" + - "-7316123607359392486\t-19136\t2016-05-01T10:29:00.000Z\t-4874\n" + - "-3107239868490395663\t-15331\t2016-05-01T10:30:00.000Z\t-24455\n" + - "-7387846268299105911\t-4874\t2016-05-01T10:31:00.000Z\t25974\n" + - "7122109662042058469\t25102\t2016-05-01T10:32:00.000Z\t5869\n" + - "-6626590012581323602\t-20409\t2016-05-01T10:33:00.000Z\t21781\n" + - "8611582118025429627\t-29572\t2016-05-01T10:34:00.000Z\t-19127\n" + - "-8082754367165748693\t25974\t2016-05-01T10:35:00.000Z\t0\n" + - "6574958665733670985\t5869\t2016-05-01T10:36:00.000Z\t-22934\n" + - "3446015290144635451\t-22894\t2016-05-01T10:37:00.000Z\t-15331\n" + - "8889492928577876455\t-18600\t2016-05-01T10:38:00.000Z\t-29572\n" + - "8152044974329490473\t11755\t2016-05-01T10:39:00.000Z\t-26951\n" + - "-6071768268784020226\t-24455\t2016-05-01T10:40:00.000Z\t-391\n"; - assertThat(expected, "select l, sho, timestamp , prev(sho) over (order by l) from abc"); - assertThat(expected, "select l, sho, timestamp , prev(sho) over (order by l) from '*!*abc'"); - } - - @Test - public void testStr() throws Exception { - final String expected = "BZ\tBZ\t2016-05-01T10:21:00.000Z\t\n" + - "XX\tBZ\t2016-05-01T10:22:00.000Z\tBZ\n" + - "KK\tXX\t2016-05-01T10:23:00.000Z\t\n" + - "AX\tXX\t2016-05-01T10:24:00.000Z\tKK\n" + - "AX\tXX\t2016-05-01T10:25:00.000Z\tAX\n" + - "AX\tBZ\t2016-05-01T10:26:00.000Z\tXX\n" + - "BZ\tXX\t2016-05-01T10:27:00.000Z\tAX\n" + - "BZ\tKK\t2016-05-01T10:28:00.000Z\t\n" + - "AX\tKK\t2016-05-01T10:29:00.000Z\tBZ\n" + - "BZ\tAX\t2016-05-01T10:30:00.000Z\t\n" + - "XX\tKK\t2016-05-01T10:31:00.000Z\tAX\n" + - "KK\tAX\t2016-05-01T10:32:00.000Z\tBZ\n" + - "AX\tAX\t2016-05-01T10:33:00.000Z\tKK\n" + - "BZ\tBZ\t2016-05-01T10:34:00.000Z\tAX\n" + - "XX\tAX\t2016-05-01T10:35:00.000Z\tAX\n" + - "AX\tAX\t2016-05-01T10:36:00.000Z\tXX\n" + - "XX\tKK\t2016-05-01T10:37:00.000Z\tXX\n" + - "AX\tAX\t2016-05-01T10:38:00.000Z\tAX\n" + - "BZ\tBZ\t2016-05-01T10:39:00.000Z\tBZ\n" + - "BZ\tAX\t2016-05-01T10:40:00.000Z\tAX\n"; - assertThat(expected, "select str, sym, timestamp , prev(str) over (partition by sym) from abc"); - assertThat(expected, "select str, sym, timestamp , prev(str) over (partition by sym) from '*!*abc'"); - assertString("select str, sym, timestamp , prev(str) over (partition by sym) from abc", 3); - assertString("select str, sym, timestamp , prev(str) over (partition by sym) from '*!*abc'", 3); - } - - @Test - public void testStr2() throws Exception { - final String expected = "21\tBZ\tBZ\t2016-05-01T10:21:00.000Z\t\n" + - "-120\tXX\tBZ\t2016-05-01T10:22:00.000Z\tBZ\n" + - "-34\tKK\tXX\t2016-05-01T10:23:00.000Z\tXX\n" + - "-60\tAX\tXX\t2016-05-01T10:24:00.000Z\tKK\n" + - "-95\tAX\tXX\t2016-05-01T10:25:00.000Z\tAX\n" + - "-40\tAX\tBZ\t2016-05-01T10:26:00.000Z\tAX\n" + - "53\tBZ\tXX\t2016-05-01T10:27:00.000Z\tAX\n" + - "77\tBZ\tKK\t2016-05-01T10:28:00.000Z\tBZ\n" + - "-69\tAX\tKK\t2016-05-01T10:29:00.000Z\tBZ\n" + - "-15\tBZ\tAX\t2016-05-01T10:30:00.000Z\tAX\n" + - "-126\tXX\tKK\t2016-05-01T10:31:00.000Z\tBZ\n" + - "-114\tKK\tAX\t2016-05-01T10:32:00.000Z\tXX\n" + - "-55\tAX\tAX\t2016-05-01T10:33:00.000Z\tKK\n" + - "-72\tBZ\tBZ\t2016-05-01T10:34:00.000Z\tAX\n" + - "-77\tXX\tAX\t2016-05-01T10:35:00.000Z\tBZ\n" + - "-83\tAX\tAX\t2016-05-01T10:36:00.000Z\tXX\n" + - "-36\tXX\tKK\t2016-05-01T10:37:00.000Z\tAX\n" + - "-102\tAX\tAX\t2016-05-01T10:38:00.000Z\tXX\n" + - "-114\tBZ\tBZ\t2016-05-01T10:39:00.000Z\tAX\n" + - "70\tBZ\tAX\t2016-05-01T10:40:00.000Z\tBZ\n"; - assertThat(expected, "select b, str, sym, timestamp , prev(str) over () from abc"); - assertThat(expected, "select b, str, sym, timestamp , prev(str) over () from '*!*abc'"); - assertString("select b, str, sym, timestamp , prev(str) over () from '*!*abc'", 4); - assertString("select b, str, sym, timestamp , prev(str) over () from abc", 4); - } - - @Test - public void testStrNoRowId() throws Exception { - final String expected = "BZ\tBZ\t2016-05-01T10:21:00.000Z\t\n" + - "XX\tBZ\t2016-05-01T10:22:00.000Z\tBZ\n" + - "KK\tXX\t2016-05-01T10:23:00.000Z\t\n" + - "AX\tXX\t2016-05-01T10:24:00.000Z\tKK\n" + - "AX\tXX\t2016-05-01T10:25:00.000Z\tAX\n" + - "AX\tBZ\t2016-05-01T10:26:00.000Z\tXX\n" + - "BZ\tXX\t2016-05-01T10:27:00.000Z\tAX\n" + - "BZ\tKK\t2016-05-01T10:28:00.000Z\t\n" + - "AX\tKK\t2016-05-01T10:29:00.000Z\tBZ\n" + - "BZ\tAX\t2016-05-01T10:30:00.000Z\t\n" + - "XX\tKK\t2016-05-01T10:31:00.000Z\tAX\n" + - "KK\tAX\t2016-05-01T10:32:00.000Z\tBZ\n" + - "AX\tAX\t2016-05-01T10:33:00.000Z\tKK\n" + - "BZ\tBZ\t2016-05-01T10:34:00.000Z\tAX\n" + - "XX\tAX\t2016-05-01T10:35:00.000Z\tAX\n" + - "AX\tAX\t2016-05-01T10:36:00.000Z\tXX\n" + - "XX\tKK\t2016-05-01T10:37:00.000Z\tXX\n" + - "AX\tAX\t2016-05-01T10:38:00.000Z\tAX\n" + - "BZ\tBZ\t2016-05-01T10:39:00.000Z\tBZ\n" + - "BZ\tAX\t2016-05-01T10:40:00.000Z\tAX\n"; - assertThat(expected, "select str, sym, timestamp , prev(str) over (partition by sym) from '*!*abc'"); - assertThat(expected, "select str, sym, timestamp , prev(str) over (partition by sym) from abc"); - assertString("select str, sym, timestamp , prev(str) over (partition by sym) from '*!*abc'", 3); - assertString("select str, sym, timestamp , prev(str) over (partition by sym) from abc", 3); - } - - @Test - public void testStrNonPart() throws Exception { - final String expected = "BZ\tBZ\t2016-05-01T10:21:00.000Z\t\n" + - "XX\tBZ\t2016-05-01T10:22:00.000Z\tBZ\n" + - "KK\tXX\t2016-05-01T10:23:00.000Z\tXX\n" + - "AX\tXX\t2016-05-01T10:24:00.000Z\tKK\n" + - "AX\tXX\t2016-05-01T10:25:00.000Z\tAX\n" + - "AX\tBZ\t2016-05-01T10:26:00.000Z\tAX\n" + - "BZ\tXX\t2016-05-01T10:27:00.000Z\tAX\n" + - "BZ\tKK\t2016-05-01T10:28:00.000Z\tBZ\n" + - "AX\tKK\t2016-05-01T10:29:00.000Z\tBZ\n" + - "BZ\tAX\t2016-05-01T10:30:00.000Z\tAX\n" + - "XX\tKK\t2016-05-01T10:31:00.000Z\tBZ\n" + - "KK\tAX\t2016-05-01T10:32:00.000Z\tXX\n" + - "AX\tAX\t2016-05-01T10:33:00.000Z\tKK\n" + - "BZ\tBZ\t2016-05-01T10:34:00.000Z\tAX\n" + - "XX\tAX\t2016-05-01T10:35:00.000Z\tBZ\n" + - "AX\tAX\t2016-05-01T10:36:00.000Z\tXX\n" + - "XX\tKK\t2016-05-01T10:37:00.000Z\tAX\n" + - "AX\tAX\t2016-05-01T10:38:00.000Z\tXX\n" + - "BZ\tBZ\t2016-05-01T10:39:00.000Z\tAX\n" + - "BZ\tAX\t2016-05-01T10:40:00.000Z\tBZ\n"; - assertThat(expected, "select str, sym, timestamp , prev(str) over () from abc"); - assertThat(expected, "select str, sym, timestamp , prev(str) over () from '*!*abc'"); - } - - @Test - public void testStrOrdered() throws Exception { - final String expected = "8920866532787660373\tBZ\t2016-05-01T10:21:00.000Z\tAX\n" + - "-6943924477733600060\tXX\t2016-05-01T10:22:00.000Z\tAX\n" + - "-6856503215590263904\tKK\t2016-05-01T10:23:00.000Z\tXX\n" + - "8416773233910814357\tAX\t2016-05-01T10:24:00.000Z\tBZ\n" + - "7199909180655756830\tAX\t2016-05-01T10:25:00.000Z\tKK\n" + - "6270672455202306717\tAX\t2016-05-01T10:26:00.000Z\tXX\n" + - "-6253307669002054137\tBZ\t2016-05-01T10:27:00.000Z\tAX\n" + - "7392877322819819290\tBZ\t2016-05-01T10:28:00.000Z\tAX\n" + - "-7316123607359392486\tAX\t2016-05-01T10:29:00.000Z\tXX\n" + - "-3107239868490395663\tBZ\t2016-05-01T10:30:00.000Z\tBZ\n" + - "-7387846268299105911\tXX\t2016-05-01T10:31:00.000Z\tXX\n" + - "7122109662042058469\tKK\t2016-05-01T10:32:00.000Z\tAX\n" + - "-6626590012581323602\tAX\t2016-05-01T10:33:00.000Z\tKK\n" + - "8611582118025429627\tBZ\t2016-05-01T10:34:00.000Z\tAX\n" + - "-8082754367165748693\tXX\t2016-05-01T10:35:00.000Z\t\n" + - "6574958665733670985\tAX\t2016-05-01T10:36:00.000Z\tAX\n" + - "3446015290144635451\tXX\t2016-05-01T10:37:00.000Z\tBZ\n" + - "8889492928577876455\tAX\t2016-05-01T10:38:00.000Z\tBZ\n" + - "8152044974329490473\tBZ\t2016-05-01T10:39:00.000Z\tBZ\n" + - "-6071768268784020226\tBZ\t2016-05-01T10:40:00.000Z\tBZ\n"; - assertThat(expected, "select l, str, timestamp , prev(str) over (order by l) from abc"); - assertThat(expected, "select l, str, timestamp , prev(str) over (order by l) from '*!*abc'"); - assertString("select l, str, timestamp , prev(str) over (order by l) from abc", 3); - assertPlan2("{\n" + - " \"op\": \"SelectedColumnsRecordSource\",\n" + - " \"src\": {\n" + - " \"op\": \"CachedAnalyticRecordSource\",\n" + - " \"functions\": 1,\n" + - " \"orderedSources\": 1,\n" + - " \"src\": {\n" + - " \"op\": \"NoRowIdRecordSource\",\n" + - " \"src\": {\n" + - " \"op\": \"JournalRecordSource\",\n" + - " \"psrc\": {\n" + - " \"op\": \"JournalPartitionSource\",\n" + - " \"journal\": \"abc\"\n" + - " },\n" + - " \"rsrc\": {\n" + - " \"op\": \"AllRowSource\"\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - "}", "select l, str, timestamp , prev(str) over (order by l) from '*!*abc'"); - } - - @Test - public void testStrPartitionedOrdered() throws Exception { - final String expected = "BZ\tBZ\t2016-05-01T10:21:00.000Z\t\n" + - "XX\tBZ\t2016-05-01T10:22:00.000Z\tBZ\n" + - "KK\tXX\t2016-05-01T10:23:00.000Z\t\n" + - "AX\tXX\t2016-05-01T10:24:00.000Z\tKK\n" + - "AX\tXX\t2016-05-01T10:25:00.000Z\tAX\n" + - "AX\tBZ\t2016-05-01T10:26:00.000Z\tXX\n" + - "BZ\tXX\t2016-05-01T10:27:00.000Z\tAX\n" + - "BZ\tKK\t2016-05-01T10:28:00.000Z\t\n" + - "AX\tKK\t2016-05-01T10:29:00.000Z\tBZ\n" + - "BZ\tAX\t2016-05-01T10:30:00.000Z\t\n" + - "XX\tKK\t2016-05-01T10:31:00.000Z\tAX\n" + - "KK\tAX\t2016-05-01T10:32:00.000Z\tBZ\n" + - "AX\tAX\t2016-05-01T10:33:00.000Z\tKK\n" + - "BZ\tBZ\t2016-05-01T10:34:00.000Z\tAX\n" + - "XX\tAX\t2016-05-01T10:35:00.000Z\tAX\n" + - "AX\tAX\t2016-05-01T10:36:00.000Z\tXX\n" + - "XX\tKK\t2016-05-01T10:37:00.000Z\tXX\n" + - "AX\tAX\t2016-05-01T10:38:00.000Z\tAX\n" + - "BZ\tBZ\t2016-05-01T10:39:00.000Z\tBZ\n" + - "BZ\tAX\t2016-05-01T10:40:00.000Z\tAX\n"; - assertThat(expected, "select str, sym, timestamp , prev(str) over (partition by sym order by timestamp) from abc"); - assertThat(expected, "select str, sym, timestamp , prev(str) over (partition by sym order by timestamp) from '*!*abc'"); - assertString("select str, sym, timestamp , prev(str) over (partition by sym order by timestamp) from abc", 3); - assertString("select str, sym, timestamp , prev(str) over (partition by sym order by timestamp) from '*!*abc'", 3); - } - - @Test - public void testSymNonPart() throws Exception { - final String expected = "BZ\tBZ\t2016-05-01T10:21:00.000Z\t\n" + - "XX\tBZ\t2016-05-01T10:22:00.000Z\tBZ\n" + - "KK\tXX\t2016-05-01T10:23:00.000Z\tBZ\n" + - "AX\tXX\t2016-05-01T10:24:00.000Z\tXX\n" + - "AX\tXX\t2016-05-01T10:25:00.000Z\tXX\n" + - "AX\tBZ\t2016-05-01T10:26:00.000Z\tXX\n" + - "BZ\tXX\t2016-05-01T10:27:00.000Z\tBZ\n" + - "BZ\tKK\t2016-05-01T10:28:00.000Z\tXX\n" + - "AX\tKK\t2016-05-01T10:29:00.000Z\tKK\n" + - "BZ\tAX\t2016-05-01T10:30:00.000Z\tKK\n" + - "XX\tKK\t2016-05-01T10:31:00.000Z\tAX\n" + - "KK\tAX\t2016-05-01T10:32:00.000Z\tKK\n" + - "AX\tAX\t2016-05-01T10:33:00.000Z\tAX\n" + - "BZ\tBZ\t2016-05-01T10:34:00.000Z\tAX\n" + - "XX\tAX\t2016-05-01T10:35:00.000Z\tBZ\n" + - "AX\tAX\t2016-05-01T10:36:00.000Z\tAX\n" + - "XX\tKK\t2016-05-01T10:37:00.000Z\tAX\n" + - "AX\tAX\t2016-05-01T10:38:00.000Z\tKK\n" + - "BZ\tBZ\t2016-05-01T10:39:00.000Z\tAX\n" + - "BZ\tAX\t2016-05-01T10:40:00.000Z\tBZ\n"; - assertThat(expected, "select str, sym, timestamp , prev(sym) over () from abc"); - assertThat(expected, "select str, sym, timestamp , prev(sym) over () from '*!*abc'"); - } - - @Test - public void testSymOrdered() throws Exception { - final String expected = "8920866532787660373\tBZ\t2016-05-01T10:21:00.000Z\tAX\n" + - "-6943924477733600060\tBZ\t2016-05-01T10:22:00.000Z\tKK\n" + - "-6856503215590263904\tXX\t2016-05-01T10:23:00.000Z\tBZ\n" + - "8416773233910814357\tXX\t2016-05-01T10:24:00.000Z\tBZ\n" + - "7199909180655756830\tXX\t2016-05-01T10:25:00.000Z\tAX\n" + - "6270672455202306717\tBZ\t2016-05-01T10:26:00.000Z\tKK\n" + - "-6253307669002054137\tXX\t2016-05-01T10:27:00.000Z\tAX\n" + - "7392877322819819290\tKK\t2016-05-01T10:28:00.000Z\tXX\n" + - "-7316123607359392486\tKK\t2016-05-01T10:29:00.000Z\tKK\n" + - "-3107239868490395663\tAX\t2016-05-01T10:30:00.000Z\tAX\n" + - "-7387846268299105911\tKK\t2016-05-01T10:31:00.000Z\tAX\n" + - "7122109662042058469\tAX\t2016-05-01T10:32:00.000Z\tAX\n" + - "-6626590012581323602\tAX\t2016-05-01T10:33:00.000Z\tXX\n" + - "8611582118025429627\tBZ\t2016-05-01T10:34:00.000Z\tXX\n" + - "-8082754367165748693\tAX\t2016-05-01T10:35:00.000Z\t\n" + - "6574958665733670985\tAX\t2016-05-01T10:36:00.000Z\tBZ\n" + - "3446015290144635451\tKK\t2016-05-01T10:37:00.000Z\tAX\n" + - "8889492928577876455\tAX\t2016-05-01T10:38:00.000Z\tBZ\n" + - "8152044974329490473\tBZ\t2016-05-01T10:39:00.000Z\tKK\n" + - "-6071768268784020226\tAX\t2016-05-01T10:40:00.000Z\tXX\n"; - assertThat(expected, "select l, sym, timestamp , prev(sym) over (order by l) from abc"); - assertThat(expected, "select l, sym, timestamp , prev(sym) over (order by l) from '*!*abc'"); - } - - @Test - public void testSymbol() throws Exception { - final String expected = "BZ\tBZ\t2016-05-01T10:21:00.000Z\t\n" + - "XX\tBZ\t2016-05-01T10:22:00.000Z\t\n" + - "KK\tXX\t2016-05-01T10:23:00.000Z\t\n" + - "AX\tXX\t2016-05-01T10:24:00.000Z\t\n" + - "AX\tXX\t2016-05-01T10:25:00.000Z\tXX\n" + - "AX\tBZ\t2016-05-01T10:26:00.000Z\tXX\n" + - "BZ\tXX\t2016-05-01T10:27:00.000Z\tBZ\n" + - "BZ\tKK\t2016-05-01T10:28:00.000Z\tXX\n" + - "AX\tKK\t2016-05-01T10:29:00.000Z\tBZ\n" + - "BZ\tAX\t2016-05-01T10:30:00.000Z\tKK\n" + - "XX\tKK\t2016-05-01T10:31:00.000Z\tBZ\n" + - "KK\tAX\t2016-05-01T10:32:00.000Z\tXX\n" + - "AX\tAX\t2016-05-01T10:33:00.000Z\tKK\n" + - "BZ\tBZ\t2016-05-01T10:34:00.000Z\tAX\n" + - "XX\tAX\t2016-05-01T10:35:00.000Z\tKK\n" + - "AX\tAX\t2016-05-01T10:36:00.000Z\tAX\n" + - "XX\tKK\t2016-05-01T10:37:00.000Z\tAX\n" + - "AX\tAX\t2016-05-01T10:38:00.000Z\tAX\n" + - "BZ\tBZ\t2016-05-01T10:39:00.000Z\tBZ\n" + - "BZ\tAX\t2016-05-01T10:40:00.000Z\tBZ\n"; - assertThat(expected, "select str, sym, timestamp , prev(sym) over (partition by str) from abc"); - assertThat(expected, "select str, sym, timestamp , prev(sym) over (partition by str) from '*!*abc'"); - } - - @Test - public void testSymbol2() throws Exception { - final String expected = "BZ\tBZ\t2016-05-01T10:21:00.000Z\t\n" + - "XX\tBZ\t2016-05-01T10:22:00.000Z\tBZ\n" + - "KK\tXX\t2016-05-01T10:23:00.000Z\tBZ\n" + - "AX\tXX\t2016-05-01T10:24:00.000Z\tXX\n" + - "AX\tXX\t2016-05-01T10:25:00.000Z\tXX\n" + - "AX\tBZ\t2016-05-01T10:26:00.000Z\tXX\n" + - "BZ\tXX\t2016-05-01T10:27:00.000Z\tBZ\n" + - "BZ\tKK\t2016-05-01T10:28:00.000Z\tXX\n" + - "AX\tKK\t2016-05-01T10:29:00.000Z\tKK\n" + - "BZ\tAX\t2016-05-01T10:30:00.000Z\tKK\n" + - "XX\tKK\t2016-05-01T10:31:00.000Z\tAX\n" + - "KK\tAX\t2016-05-01T10:32:00.000Z\tKK\n" + - "AX\tAX\t2016-05-01T10:33:00.000Z\tAX\n" + - "BZ\tBZ\t2016-05-01T10:34:00.000Z\tAX\n" + - "XX\tAX\t2016-05-01T10:35:00.000Z\tBZ\n" + - "AX\tAX\t2016-05-01T10:36:00.000Z\tAX\n" + - "XX\tKK\t2016-05-01T10:37:00.000Z\tAX\n" + - "AX\tAX\t2016-05-01T10:38:00.000Z\tKK\n" + - "BZ\tBZ\t2016-05-01T10:39:00.000Z\tAX\n" + - "BZ\tAX\t2016-05-01T10:40:00.000Z\tBZ\n"; - assertThat(expected, "select str, sym, timestamp , prev(sym) over () from abc"); - assertThat(expected, "select str, sym, timestamp , prev(sym) over () from '*!*abc'"); - assertSymbol("select str, sym, timestamp , prev(sym) over () from abc", 3); - assertSymbol("select str, sym, timestamp , prev(sym) over () from '*!*abc'", 3); - } - - @Test - public void testSymbolBehaviour() throws Exception { - assertSymbol("select str, sym, timestamp , prev(sym) over (partition by str) from abc", 3); - assertSymbol("select str, sym, timestamp , prev(sym) over (partition by str) from abc", 1); - } - - @Test - public void testSymbolSubQuery() throws Exception { - final String expectd = "str\tsym\tp\n" + - "BZ\tBZ\t\n" + - "XX\tBZ\t\n" + - "KK\tXX\t\n" + - "AX\tXX\t\n" + - "AX\tXX\tXX\n" + - "AX\tBZ\tXX\n" + - "BZ\tXX\tBZ\n" + - "BZ\tKK\tXX\n" + - "AX\tKK\tBZ\n" + - "BZ\tAX\tKK\n" + - "XX\tKK\tBZ\n" + - "KK\tAX\tXX\n" + - "AX\tAX\tKK\n" + - "BZ\tBZ\tAX\n" + - "XX\tAX\tKK\n" + - "AX\tAX\tAX\n" + - "XX\tKK\tAX\n" + - "AX\tAX\tAX\n" + - "BZ\tBZ\tBZ\n" + - "BZ\tAX\tBZ\n"; - - assertThat(expectd, "select str, sym, p from (select str, sym, timestamp , prev(sym) p over (partition by str) from abc)", true); - assertThat(expectd, "select str, sym, p from (select str, sym, timestamp , prev(sym) p over (partition by str) from '*!*abc')", true); - } - - @Test - public void testVirtualColumn() throws Exception { - final String expected = "str\tboo\tcol0\tf\td\tcol1\n" + - "BZ\ttrue\t1.673692762852\t0.6235\t1.050231933594\tfalse\n" + - "XX\tfalse\t567.512389898300\t0.7780\t566.734375000000\tfalse\n" + - "KK\tfalse\t0.550908231392\t0.5509\t0.000013792171\tfalse\n" + - "AX\tfalse\t0.020375759351\t0.0204\t0.000000567185\tfalse\n" + - "AX\ttrue\t-511.515212714672\t0.4848\t-512.000000000000\tfalse\n" + - "AX\ttrue\t0.972335502505\t0.2969\t0.675451681018\ttrue\n" + - "BZ\tfalse\t0.904826603830\t0.5725\t0.332301996648\ttrue\n" + - "BZ\ttrue\t0.596724832495\t0.5967\t0.000001752813\tfalse\n" + - "AX\tfalse\t0.161007094177\t0.1609\t0.000076281818\ttrue\n" + - "BZ\tfalse\t0.350913291764\t0.3509\t0.000000005555\ttrue\n" + - "XX\tfalse\t0.727417677178\t0.7274\t0.000002473130\tfalse\n" + - "KK\tfalse\t633.483788669109\t0.5619\t632.921875000000\tfalse\n" + - "AX\tfalse\t0.543259224330\t0.5433\t0.000000020896\tfalse\n" + - "BZ\tfalse\t0.551534552826\t0.5442\t0.007371325744\tfalse\n" + - "XX\ttrue\t0.674562766890\t0.6746\t0.000000014643\tfalse\n" + - "AX\ttrue\t512.821699082851\t0.8217\t512.000000000000\tfalse\n" + - "XX\ttrue\t864.359103977680\t0.3591\t864.000000000000\ttrue\n" + - "AX\ttrue\t0.682714500508\t0.6827\t0.000000157437\ttrue\n" + - "BZ\tfalse\t-841.883159995079\t0.1168\t-842.000000000000\tfalse\n" + - "BZ\tfalse\t0.496688359286\t0.4967\t0.000032060649\tfalse\n"; - assertThat(expected, "select str, boo, f+d, f, d , prev(boo) over (partition by str) from abc", true); - assertThat(expected, "select str, boo, f+d, f, d , prev(boo) over (partition by str) from '*!*abc'", true); - } - - @Test - public void testWrongColumnInFunc() { - try { - expectFailure("select str, sym, timestamp , prev(symx) over (partition by str) from abc"); - } catch (ParserException e) { - Assert.assertEquals(34, QueryError.getPosition()); - } - } - - @Test - public void testWrongColumnInPartition() { - try { - expectFailure("select str, sym, timestamp , prev(sym) over (partition by strx) from abc"); - } catch (ParserException e) { - Assert.assertEquals(58, QueryError.getPosition()); - } - } -} \ No newline at end of file diff --git a/core/src/test/java/com/questdb/ql/collections/FreeListTest.java b/core/src/test/java/com/questdb/ql/collections/FreeListTest.java deleted file mode 100644 index 07ec8f2e9..000000000 --- a/core/src/test/java/com/questdb/ql/collections/FreeListTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql.collections; - -import com.questdb.ql.join.asof.FreeList; -import org.junit.Assert; -import org.junit.Test; - -public class FreeListTest { - - @Test - public void testFindAndRemove() { - FreeList list = new FreeList(); - - list.add(100000L, 11); - list.add(200000L, 7); - list.add(300000L, 13); - list.add(400000L, 15); - list.add(500000L, 10); - - Assert.assertEquals(-1L, list.findAndRemove(20)); - Assert.assertEquals("FreeList{sizes=[7,10,11,13,15], offsets=[200000,500000,100000,300000,400000], maxSize=15}", list.toString()); - - Assert.assertEquals(500000L, list.findAndRemove(10)); - Assert.assertEquals("FreeList{sizes=[7,11,13,15], offsets=[200000,100000,300000,400000], maxSize=15}", list.toString()); - - Assert.assertEquals(200000L, list.findAndRemove(6)); - Assert.assertEquals("FreeList{sizes=[11,13,15], offsets=[100000,300000,400000], maxSize=15}", list.toString()); - - Assert.assertEquals(100000L, list.findAndRemove(10)); - Assert.assertEquals("FreeList{sizes=[13,15], offsets=[300000,400000], maxSize=15}", list.toString()); - - Assert.assertEquals(400000L, list.findAndRemove(15)); - Assert.assertEquals(-1, list.findAndRemove(14)); - Assert.assertEquals(300000L, list.findAndRemove(13)); - - Assert.assertEquals(-1, list.findAndRemove(15)); - Assert.assertEquals("FreeList{sizes=[], offsets=[], maxSize=13}", list.toString()); - - Assert.assertEquals(-1, list.findAndRemove(10)); - Assert.assertEquals("FreeList{sizes=[], offsets=[], maxSize=-1}", list.toString()); - - list.add(13000L, 20); - - Assert.assertEquals(13000L, list.findAndRemove(15)); - Assert.assertEquals("FreeList{sizes=[], offsets=[], maxSize=20}", list.toString()); - } - - @Test - public void testSimple() { - FreeList list = new FreeList(); - - list.add(100000L, 11); - list.add(200000L, 7); - list.add(300000L, 14); - list.add(400000L, 15); - list.add(500000L, 10); - - Assert.assertEquals("FreeList{sizes=[7,10,11,14,15], offsets=[200000,500000,100000,300000,400000], maxSize=15}", list.toString()); - } -} diff --git a/core/src/test/java/com/questdb/ql/join/JoinComplianceTest.java b/core/src/test/java/com/questdb/ql/join/JoinComplianceTest.java deleted file mode 100644 index 2c9a68bfd..000000000 --- a/core/src/test/java/com/questdb/ql/join/JoinComplianceTest.java +++ /dev/null @@ -1,447 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql.join; - -import com.questdb.ql.AbstractAllTypeTest; -import org.junit.Test; - -public class JoinComplianceTest extends AbstractAllTypeTest { - - @Test - public void testAsOfSymbolBehaviour() throws Exception { - assertSymbol("select a.sym, b.sym from abc a asof join abc b", 0); - assertSymbol("select a.sym, b.sym from abc a asof join abc b", 1); - } - - @Test - public void testCrossReset() throws Exception { - assertThat("BZ\tBZ\n" + - "BZ\tBZ\n" + - "BZ\tXX\n" + - "BZ\tXX\n" + - "BZ\tXX\n" + - "BZ\tBZ\n" + - "BZ\tXX\n" + - "BZ\tKK\n" + - "BZ\tKK\n" + - "BZ\tAX\n" + - "BZ\tKK\n" + - "BZ\tAX\n" + - "BZ\tAX\n" + - "BZ\tBZ\n" + - "BZ\tAX\n" + - "BZ\tAX\n" + - "BZ\tKK\n" + - "BZ\tAX\n" + - "BZ\tBZ\n" + - "BZ\tAX\n" + - "BZ\tBZ\n" + - "BZ\tBZ\n" + - "BZ\tXX\n" + - "BZ\tXX\n" + - "BZ\tXX\n" + - "BZ\tBZ\n" + - "BZ\tXX\n" + - "BZ\tKK\n" + - "BZ\tKK\n" + - "BZ\tAX\n" + - "BZ\tKK\n" + - "BZ\tAX\n" + - "BZ\tAX\n" + - "BZ\tBZ\n" + - "BZ\tAX\n" + - "BZ\tAX\n" + - "BZ\tKK\n" + - "BZ\tAX\n" + - "BZ\tBZ\n" + - "BZ\tAX\n" + - "XX\tBZ\n" + - "XX\tBZ\n" + - "XX\tXX\n" + - "XX\tXX\n" + - "XX\tXX\n" + - "XX\tBZ\n" + - "XX\tXX\n" + - "XX\tKK\n" + - "XX\tKK\n" + - "XX\tAX\n" + - "XX\tKK\n" + - "XX\tAX\n" + - "XX\tAX\n" + - "XX\tBZ\n" + - "XX\tAX\n" + - "XX\tAX\n" + - "XX\tKK\n" + - "XX\tAX\n" + - "XX\tBZ\n" + - "XX\tAX\n" + - "XX\tBZ\n" + - "XX\tBZ\n" + - "XX\tXX\n" + - "XX\tXX\n" + - "XX\tXX\n" + - "XX\tBZ\n" + - "XX\tXX\n" + - "XX\tKK\n" + - "XX\tKK\n" + - "XX\tAX\n" + - "XX\tKK\n" + - "XX\tAX\n" + - "XX\tAX\n" + - "XX\tBZ\n" + - "XX\tAX\n" + - "XX\tAX\n" + - "XX\tKK\n" + - "XX\tAX\n" + - "XX\tBZ\n" + - "XX\tAX\n" + - "XX\tBZ\n" + - "XX\tBZ\n" + - "XX\tXX\n" + - "XX\tXX\n" + - "XX\tXX\n" + - "XX\tBZ\n" + - "XX\tXX\n" + - "XX\tKK\n" + - "XX\tKK\n" + - "XX\tAX\n" + - "XX\tKK\n" + - "XX\tAX\n" + - "XX\tAX\n" + - "XX\tBZ\n" + - "XX\tAX\n" + - "XX\tAX\n" + - "XX\tKK\n" + - "XX\tAX\n" + - "XX\tBZ\n" + - "XX\tAX\n" + - "BZ\tBZ\n" + - "BZ\tBZ\n" + - "BZ\tXX\n" + - "BZ\tXX\n" + - "BZ\tXX\n" + - "BZ\tBZ\n" + - "BZ\tXX\n" + - "BZ\tKK\n" + - "BZ\tKK\n" + - "BZ\tAX\n" + - "BZ\tKK\n" + - "BZ\tAX\n" + - "BZ\tAX\n" + - "BZ\tBZ\n" + - "BZ\tAX\n" + - "BZ\tAX\n" + - "BZ\tKK\n" + - "BZ\tAX\n" + - "BZ\tBZ\n" + - "BZ\tAX\n" + - "XX\tBZ\n" + - "XX\tBZ\n" + - "XX\tXX\n" + - "XX\tXX\n" + - "XX\tXX\n" + - "XX\tBZ\n" + - "XX\tXX\n" + - "XX\tKK\n" + - "XX\tKK\n" + - "XX\tAX\n" + - "XX\tKK\n" + - "XX\tAX\n" + - "XX\tAX\n" + - "XX\tBZ\n" + - "XX\tAX\n" + - "XX\tAX\n" + - "XX\tKK\n" + - "XX\tAX\n" + - "XX\tBZ\n" + - "XX\tAX\n" + - "KK\tBZ\n" + - "KK\tBZ\n" + - "KK\tXX\n" + - "KK\tXX\n" + - "KK\tXX\n" + - "KK\tBZ\n" + - "KK\tXX\n" + - "KK\tKK\n" + - "KK\tKK\n" + - "KK\tAX\n" + - "KK\tKK\n" + - "KK\tAX\n" + - "KK\tAX\n" + - "KK\tBZ\n" + - "KK\tAX\n" + - "KK\tAX\n" + - "KK\tKK\n" + - "KK\tAX\n" + - "KK\tBZ\n" + - "KK\tAX\n" + - "KK\tBZ\n" + - "KK\tBZ\n" + - "KK\tXX\n" + - "KK\tXX\n" + - "KK\tXX\n" + - "KK\tBZ\n" + - "KK\tXX\n" + - "KK\tKK\n" + - "KK\tKK\n" + - "KK\tAX\n" + - "KK\tKK\n" + - "KK\tAX\n" + - "KK\tAX\n" + - "KK\tBZ\n" + - "KK\tAX\n" + - "KK\tAX\n" + - "KK\tKK\n" + - "KK\tAX\n" + - "KK\tBZ\n" + - "KK\tAX\n" + - "AX\tBZ\n" + - "AX\tBZ\n" + - "AX\tXX\n" + - "AX\tXX\n" + - "AX\tXX\n" + - "AX\tBZ\n" + - "AX\tXX\n" + - "AX\tKK\n" + - "AX\tKK\n" + - "AX\tAX\n" + - "AX\tKK\n" + - "AX\tAX\n" + - "AX\tAX\n" + - "AX\tBZ\n" + - "AX\tAX\n" + - "AX\tAX\n" + - "AX\tKK\n" + - "AX\tAX\n" + - "AX\tBZ\n" + - "AX\tAX\n" + - "KK\tBZ\n" + - "KK\tBZ\n" + - "KK\tXX\n" + - "KK\tXX\n" + - "KK\tXX\n" + - "KK\tBZ\n" + - "KK\tXX\n" + - "KK\tKK\n" + - "KK\tKK\n" + - "KK\tAX\n" + - "KK\tKK\n" + - "KK\tAX\n" + - "KK\tAX\n" + - "KK\tBZ\n" + - "KK\tAX\n" + - "KK\tAX\n" + - "KK\tKK\n" + - "KK\tAX\n" + - "KK\tBZ\n" + - "KK\tAX\n" + - "AX\tBZ\n" + - "AX\tBZ\n" + - "AX\tXX\n" + - "AX\tXX\n" + - "AX\tXX\n" + - "AX\tBZ\n" + - "AX\tXX\n" + - "AX\tKK\n" + - "AX\tKK\n" + - "AX\tAX\n" + - "AX\tKK\n" + - "AX\tAX\n" + - "AX\tAX\n" + - "AX\tBZ\n" + - "AX\tAX\n" + - "AX\tAX\n" + - "AX\tKK\n" + - "AX\tAX\n" + - "AX\tBZ\n" + - "AX\tAX\n" + - "AX\tBZ\n" + - "AX\tBZ\n" + - "AX\tXX\n" + - "AX\tXX\n" + - "AX\tXX\n" + - "AX\tBZ\n" + - "AX\tXX\n" + - "AX\tKK\n" + - "AX\tKK\n" + - "AX\tAX\n" + - "AX\tKK\n" + - "AX\tAX\n" + - "AX\tAX\n" + - "AX\tBZ\n" + - "AX\tAX\n" + - "AX\tAX\n" + - "AX\tKK\n" + - "AX\tAX\n" + - "AX\tBZ\n" + - "AX\tAX\n" + - "BZ\tBZ\n" + - "BZ\tBZ\n" + - "BZ\tXX\n" + - "BZ\tXX\n" + - "BZ\tXX\n" + - "BZ\tBZ\n" + - "BZ\tXX\n" + - "BZ\tKK\n" + - "BZ\tKK\n" + - "BZ\tAX\n" + - "BZ\tKK\n" + - "BZ\tAX\n" + - "BZ\tAX\n" + - "BZ\tBZ\n" + - "BZ\tAX\n" + - "BZ\tAX\n" + - "BZ\tKK\n" + - "BZ\tAX\n" + - "BZ\tBZ\n" + - "BZ\tAX\n" + - "AX\tBZ\n" + - "AX\tBZ\n" + - "AX\tXX\n" + - "AX\tXX\n" + - "AX\tXX\n" + - "AX\tBZ\n" + - "AX\tXX\n" + - "AX\tKK\n" + - "AX\tKK\n" + - "AX\tAX\n" + - "AX\tKK\n" + - "AX\tAX\n" + - "AX\tAX\n" + - "AX\tBZ\n" + - "AX\tAX\n" + - "AX\tAX\n" + - "AX\tKK\n" + - "AX\tAX\n" + - "AX\tBZ\n" + - "AX\tAX\n" + - "AX\tBZ\n" + - "AX\tBZ\n" + - "AX\tXX\n" + - "AX\tXX\n" + - "AX\tXX\n" + - "AX\tBZ\n" + - "AX\tXX\n" + - "AX\tKK\n" + - "AX\tKK\n" + - "AX\tAX\n" + - "AX\tKK\n" + - "AX\tAX\n" + - "AX\tAX\n" + - "AX\tBZ\n" + - "AX\tAX\n" + - "AX\tAX\n" + - "AX\tKK\n" + - "AX\tAX\n" + - "AX\tBZ\n" + - "AX\tAX\n" + - "KK\tBZ\n" + - "KK\tBZ\n" + - "KK\tXX\n" + - "KK\tXX\n" + - "KK\tXX\n" + - "KK\tBZ\n" + - "KK\tXX\n" + - "KK\tKK\n" + - "KK\tKK\n" + - "KK\tAX\n" + - "KK\tKK\n" + - "KK\tAX\n" + - "KK\tAX\n" + - "KK\tBZ\n" + - "KK\tAX\n" + - "KK\tAX\n" + - "KK\tKK\n" + - "KK\tAX\n" + - "KK\tBZ\n" + - "KK\tAX\n" + - "AX\tBZ\n" + - "AX\tBZ\n" + - "AX\tXX\n" + - "AX\tXX\n" + - "AX\tXX\n" + - "AX\tBZ\n" + - "AX\tXX\n" + - "AX\tKK\n" + - "AX\tKK\n" + - "AX\tAX\n" + - "AX\tKK\n" + - "AX\tAX\n" + - "AX\tAX\n" + - "AX\tBZ\n" + - "AX\tAX\n" + - "AX\tAX\n" + - "AX\tKK\n" + - "AX\tAX\n" + - "AX\tBZ\n" + - "AX\tAX\n" + - "BZ\tBZ\n" + - "BZ\tBZ\n" + - "BZ\tXX\n" + - "BZ\tXX\n" + - "BZ\tXX\n" + - "BZ\tBZ\n" + - "BZ\tXX\n" + - "BZ\tKK\n" + - "BZ\tKK\n" + - "BZ\tAX\n" + - "BZ\tKK\n" + - "BZ\tAX\n" + - "BZ\tAX\n" + - "BZ\tBZ\n" + - "BZ\tAX\n" + - "BZ\tAX\n" + - "BZ\tKK\n" + - "BZ\tAX\n" + - "BZ\tBZ\n" + - "BZ\tAX\n" + - "AX\tBZ\n" + - "AX\tBZ\n" + - "AX\tXX\n" + - "AX\tXX\n" + - "AX\tXX\n" + - "AX\tBZ\n" + - "AX\tXX\n" + - "AX\tKK\n" + - "AX\tKK\n" + - "AX\tAX\n" + - "AX\tKK\n" + - "AX\tAX\n" + - "AX\tAX\n" + - "AX\tBZ\n" + - "AX\tAX\n" + - "AX\tAX\n" + - "AX\tKK\n" + - "AX\tAX\n" + - "AX\tBZ\n" + - "AX\tAX\n", "select a.sym, b.sym from abc a cross join abc b"); - - } - - @Test - public void testCrossSymbolBehaviour() throws Exception { - assertSymbol("select a.sym, b.sym from abc a cross join abc b", 0); - assertSymbol("select a.sym, b.sym from abc a cross join abc b", 1); - } -} \ No newline at end of file diff --git a/core/src/test/java/com/questdb/ql/join/MultiColumnJoinTest.java b/core/src/test/java/com/questdb/ql/join/MultiColumnJoinTest.java deleted file mode 100644 index 48d71c555..000000000 --- a/core/src/test/java/com/questdb/ql/join/MultiColumnJoinTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql.join; - -import com.questdb.ex.ParserException; -import com.questdb.parser.sql.QueryError; -import com.questdb.std.Rnd; -import com.questdb.store.JournalEntryWriter; -import com.questdb.store.JournalWriter; -import com.questdb.store.factory.configuration.JournalStructure; -import com.questdb.test.tools.AbstractTest; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class MultiColumnJoinTest extends AbstractTest { - - @Before - public void setUp() throws Exception { - - getFactory().getConfiguration().exists(""); - try (JournalWriter a = getFactory().writer(new JournalStructure("a").$int("x").$str("y").$double("amount").$())) { - try (JournalWriter b = getFactory().writer(new JournalStructure("b").$int("x").$str("y").$str("name").$())) { - - Rnd rnd = new Rnd(); - - for (int i = 0; i < 10; i++) { - int x = rnd.nextInt(); - String y = rnd.nextString(rnd.nextPositiveInt() % 15); - - JournalEntryWriter ewa = a.entryWriter(); - JournalEntryWriter ewb = b.entryWriter(); - - ewa.putInt(0, x); - ewa.putStr(1, y); - ewa.putDouble(2, rnd.nextDouble()); - ewa.append(); - - ewb.putInt(0, x); - ewb.putStr(1, y); - ewb.putStr(2, rnd.nextChars(rnd.nextPositiveInt() % 20)); - ewb.append(); - } - } -// a.commit(); -// b.commit(); - } - } - - @Test - public void testJoinOnThreeFields() throws Exception { - final String expected = "-1148479920\tJWC\t-1024.000000000000\t-1148479920\tJWC\tHYRXPEHNRXG\n" + - "339631474\tXUXIBBT\t981.018066406250\t339631474\tXUXIBBT\tWFFYU\n" + - "-1125169127\tYYQ\t0.000006369316\t-1125169127\tYYQ\t\n" + - "1699553881\tOWLPDXYSBEOUOJ\t0.169966913760\t1699553881\tOWLPDXYSBEOUOJ\tUEDRQQULOFJGETJR\n" + - "326010667\tSRYR\t695.796875000000\t326010667\tSRYR\tTMHGOOZZVDZJMYI\n" + - "1985398001\tX\t-1024.000000000000\t1985398001\tX\tICWEKGHVU\n" + - "532665695\tDO\t632.921875000000\t532665695\tDO\tDYY\n" + - "114747951\tGQOLYXWC\t0.000229079233\t114747951\tGQOLYXWC\t\n" + - "1254404167\tWDSWUGSHOLNVTI\t770.359375000000\t1254404167\tWDSWUGSHOLNVTI\tXIOVIKJSMSSUQSRLTKV\n" + - "-2080340570\tJO\t0.555824235082\t-2080340570\tJO\tHZEPIHVLTOVLJU\n"; - - assertThat(expected, "a join b on (x,y)"); - } - - @Test - public void testNonLiteral() { - try { - expectFailure("a join b on (1+2)"); - } catch (ParserException e) { - Assert.assertEquals(14, QueryError.getPosition()); - } - } -} diff --git a/core/src/test/java/com/questdb/ql/map/DirectMapTest.java b/core/src/test/java/com/questdb/ql/map/DirectMapTest.java deleted file mode 100644 index 5b461690a..000000000 --- a/core/src/test/java/com/questdb/ql/map/DirectMapTest.java +++ /dev/null @@ -1,310 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql.map; - -import com.questdb.std.*; -import com.questdb.std.str.StringSink; -import com.questdb.store.ColumnType; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.util.HashMap; -import java.util.Map; - -public class DirectMapTest { - - private static final IntList COLUMN_TYPES = new IntList(); - private static final IntList KEY_TYPES = new IntList(); - private static final ColumnTypeResolver KEY_RESOLVER = new TypeListResolver().of(KEY_TYPES); - private static final ColumnTypeResolver VALUE_RESOLVER = new TypeListResolver().of(COLUMN_TYPES); - - @BeforeClass - public static void setUp() { - COLUMN_TYPES.add(ColumnType.INT); - COLUMN_TYPES.add(ColumnType.LONG); - COLUMN_TYPES.add(ColumnType.SHORT); - COLUMN_TYPES.add(ColumnType.BYTE); - COLUMN_TYPES.add(ColumnType.DOUBLE); - COLUMN_TYPES.add(ColumnType.FLOAT); - - KEY_TYPES.add(ColumnType.STRING); - KEY_TYPES.add(ColumnType.LONG); - KEY_TYPES.add(ColumnType.BOOLEAN); - KEY_TYPES.add(ColumnType.INT); - KEY_TYPES.add(ColumnType.SHORT); - KEY_TYPES.add(ColumnType.BYTE); - KEY_TYPES.add(ColumnType.DOUBLE); - KEY_TYPES.add(ColumnType.FLOAT); - KEY_TYPES.add(ColumnType.LONG); - KEY_TYPES.add(ColumnType.STRING); - KEY_TYPES.add(ColumnType.BYTE); - } - - @Test - public void testAllKeysAndCursor() { - - // Objective of this test is to create DirectMap with all - // possible types in both key and value. Simultaneously create - // regular hash map, where key is hex encoded bytes of direct map - // and value is object, which holds same primitive values we - // put into direct map. - - - Rnd rnd = new Rnd(); - final int addressSize = 2 * 1024 * 1024; - long address = Unsafe.malloc(addressSize); - final int tmpSize = 140; - long tmp = Unsafe.malloc(tmpSize); - - DirectMap map = new DirectMap(1024, KEY_RESOLVER, VALUE_RESOLVER); - StringSink sink = new StringSink(); - - HashMap hashMap = new HashMap<>(); - - for (int i = 0; i < 1000; i++) { - sink.clear(); - DirectMap.KeyWriter w = map.keyWriter(); - - long p = address; - - CharSequence cs = rnd.nextChars(rnd.nextInt() % 64); - long l = rnd.nextLong(); - boolean b = rnd.nextBoolean(); - int ii = rnd.nextInt(); - short s = (short) rnd.nextInt(); - byte by = (byte) rnd.nextInt(); - double d = rnd.nextDouble(); - float f = rnd.nextFloat(); - CharSequence s2 = rnd.nextBoolean() ? null : cs; - - w.put(tmp, Chars.strcpyw(cs, tmp)); - w.putLong(l); - w.putBool(b); - w.putInt(ii); - w.putShort(s); - w.putByte(by); - w.putDouble(d); - w.putFloat(f); - w.putLong(l); - w.putStr(s2); - w.putByte(by); - - // write same string to base64 buffer - p = put(p, cs); - p = put(p, l); - p = put(p, b); - p = put(p, ii); - p = put(p, s); - p = put(p, by); - p = put(p, d); - p = put(p, f); - p = put(p, l); - p = put(p, s2); - p = put(p, by); - - MapValue v = new MapValue(); - DirectMapValues values = map.getOrCreateValues(); - values.putInt(0, v.i = rnd.nextPositiveInt()); - values.putLong(1, v.l = rnd.nextPositiveLong()); - values.putShort(2, v.s = (short) rnd.nextInt()); - values.putByte(3, v.bt = (byte) rnd.nextInt()); - values.putDouble(4, v.d = rnd.nextDouble()); - values.putFloat(5, v.f = rnd.nextFloat()); - - hashMap.put(toStr(sink, address, p), v); - } - - Assert.assertEquals(hashMap.size(), map.size()); - - HashMap rowidMap = new HashMap<>(); - - for (DirectMapEntry e : map) { - long p = address; - - // check that A and B return same sequence - CharSequence csA = e.getFlyweightStr(6); - CharSequence csB = e.getFlyweightStrB(6); - TestUtils.assertEquals(csA, csB); - - p = put(p, csA); - p = put(p, e.getLong(7)); - p = put(p, e.getBool(8)); - p = put(p, e.getInt(9)); - p = put(p, e.getShort(10)); - p = put(p, e.get(11)); - p = put(p, e.getDouble(12)); - p = put(p, e.getFloat(13)); - p = put(p, e.getDate(14)); - - String s = e.getStr(15); - p = put(p, s); - - sink.clear(); - e.getStr(15, sink); - - if (s == null) { - Assert.assertEquals(0, sink.length()); - Assert.assertEquals(-1, e.getStrLen(15)); - } else { - TestUtils.assertEquals(s, sink); - Assert.assertEquals(s.length(), e.getStrLen(15)); - } - - p = put(p, e.get(16)); - - sink.clear(); - - MapValue v = hashMap.get(toStr(sink, address, p)); - - Assert.assertEquals(v.i, e.getInt(0)); - Assert.assertEquals(v.l, e.getLong(1)); - Assert.assertEquals(v.s, e.getShort(2)); - Assert.assertEquals(v.bt, e.get(3)); - Assert.assertEquals(v.d, e.getDouble(4), 0.000000001); - Assert.assertEquals(v.f, e.getFloat(5), 0.0000000001f); - rowidMap.put(e.getRowId(), v); - } - - // retrieve map by rowid - - for (Map.Entry me : rowidMap.entrySet()) { - DirectMapEntry e = map.entryAt(me.getKey()); - MapValue v = me.getValue(); - Assert.assertEquals(v.i, e.getInt(0)); - Assert.assertEquals(v.l, e.getLong(1)); - Assert.assertEquals(v.s, e.getShort(2)); - Assert.assertEquals(v.bt, e.get(3)); - Assert.assertEquals(v.d, e.getDouble(4), 0.000000001); - Assert.assertEquals(v.f, e.getFloat(5), 0.0000000001f); - } - - map.clear(); - Assert.assertEquals(0, map.size()); - int count = 0; - for (DirectMapEntry ignored : map) { - count++; - } - Assert.assertEquals(0, count); - - map.close(); - - Unsafe.free(address, addressSize); - Unsafe.free(tmp, tmpSize); - } - - @Test - public void testValuesReadWrite() { - DirectMap map = new DirectMap(1024, KEY_RESOLVER, VALUE_RESOLVER); - HashMap hashMap = new HashMap<>(); - Rnd rnd = new Rnd(); - int n = 1000; - - for (int i = 0; i < n; i++) { - DirectMap.KeyWriter w = map.keyWriter(); - String s = rnd.nextString(rnd.nextPositiveInt() % 32); - w.putStr(s); - MapValue v = new MapValue(); - DirectMapValues values = map.getOrCreateValues(); - values.putInt(0, v.i = rnd.nextPositiveInt()); - values.putLong(1, v.l = rnd.nextPositiveLong()); - values.putShort(2, v.s = (short) rnd.nextInt()); - values.putByte(3, v.bt = (byte) rnd.nextInt()); - values.putDouble(4, v.d = rnd.nextDouble()); - values.putFloat(5, v.f = rnd.nextFloat()); - hashMap.put(s, v); - } - - for (Map.Entry me : hashMap.entrySet()) { - DirectMap.KeyWriter kw = map.keyWriter(); - kw.putStr(me.getKey()); - DirectMapValues values = map.getValues(); - Assert.assertNotNull(values); - - MapValue v = me.getValue(); - Assert.assertEquals(v.i, values.getInt(0)); - Assert.assertEquals(v.l, values.getLong(1)); - Assert.assertEquals(v.s, values.getShort(2)); - Assert.assertEquals(v.bt, values.getByte(3)); - Assert.assertEquals(v.d, values.getDouble(4), 0.000000001); - Assert.assertEquals(v.f, values.getFloat(5), 0.0000000001f); - - } - map.close(); - } - - private static long put(long address, CharSequence cs) { - if (cs == null) { - return address; - } - return address + Chars.strcpyw(cs, address); - } - - private static long put(long address, long value) { - Unsafe.getUnsafe().putLong(address, value); - return address + 8; - } - - private static String toStr(StringSink s, long lo, long hi) { - for (long p = lo; p < hi; p++) { - Numbers.appendHex(s, (int) Unsafe.getUnsafe().getByte(p)); - } - return s.toString(); - } - - private static long put(long address, boolean value) { - Unsafe.getUnsafe().putByte(address, (byte) (value ? 1 : 0)); - return address + 1; - } - - private static long put(long address, int value) { - Unsafe.getUnsafe().putInt(address, value); - return address + 4; - } - - private static long put(long address, byte value) { - Unsafe.getUnsafe().putByte(address, value); - return address + 1; - } - - private static long put(long address, double value) { - Unsafe.getUnsafe().putDouble(address, value); - return address + 1; - } - - private static long put(long address, float value) { - Unsafe.getUnsafe().putFloat(address, value); - return address + 1; - } - - private static class MapValue { - byte bt; - double d; - float f; - int i; - long l; - short s; - } -} \ No newline at end of file diff --git a/core/src/test/java/com/questdb/ql/map/RecordKeyCopierCompilerTest.java b/core/src/test/java/com/questdb/ql/map/RecordKeyCopierCompilerTest.java deleted file mode 100644 index 62d1c7a4d..000000000 --- a/core/src/test/java/com/questdb/ql/map/RecordKeyCopierCompilerTest.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql.map; - -import com.questdb.parser.sql.AbstractOptimiserTest; -import com.questdb.ql.RecordSource; -import com.questdb.std.BytecodeAssembler; -import com.questdb.std.IntList; -import com.questdb.store.*; -import org.junit.Assert; -import org.junit.Test; - -public class RecordKeyCopierCompilerTest extends AbstractOptimiserTest { - @Test - public void testCompiler() throws Exception { - try (JournalWriter w = compiler.createWriter(FACTORY_CONTAINER.getFactory(), "create table x (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING, y BOOLEAN) timestamp(t) partition by MONTH record hint 100")) { - JournalEntryWriter ew = w.entryWriter(); - IntList keyColumns = new IntList(); - ew.putInt(0, 12345); - keyColumns.add(0); - - ew.put(1, (byte) 128); - keyColumns.add(1); - - ew.putShort(2, (short) 6500); - keyColumns.add(2); - - ew.putLong(3, 123456789); - keyColumns.add(3); - - ew.putFloat(4, 0.345f); - keyColumns.add(4); - - ew.putDouble(5, 0.123456789); - keyColumns.add(5); - - ew.putDate(6, 10000000000L); - keyColumns.add(6); - - ew.putSym(9, "xyz"); - keyColumns.add(9); - - ew.putStr(10, "abc"); - keyColumns.add(10); - - ew.putBool(11, true); - keyColumns.add(11); - - ew.append(); - w.commit(); - - - try (RecordSource src = compileSource("x")) { - RecordKeyCopierCompiler cc = new RecordKeyCopierCompiler(new BytecodeAssembler()); - RecordKeyCopier copier = cc.compile(src.getMetadata(), keyColumns); - - IntList valueTypes = new IntList(); - valueTypes.add(ColumnType.DOUBLE); - - MetadataTypeResolver metadataTypeResolver = new MetadataTypeResolver(); - TypeListResolver typeListResolver = new TypeListResolver(); - - try (DirectMap map = new DirectMap(1024, metadataTypeResolver.of(src.getMetadata(), keyColumns), typeListResolver.of(valueTypes))) { - - RecordCursor cursor = src.prepareCursor(FACTORY_CONTAINER.getFactory()); - try { - while (cursor.hasNext()) { - Record r = cursor.next(); - DirectMap.KeyWriter kw = map.keyWriter(); - copier.copy(r, kw); - DirectMapValues val = map.getOrCreateValues(); - val.putDouble(0, 5000.01); - } - - cursor.toTop(); - while (cursor.hasNext()) { - Record r = cursor.next(); - DirectMap.KeyWriter kw = map.keyWriter(); - copier.copy(r, kw); - Assert.assertEquals(map.getValues().getDouble(0), 5000.01, 0.00000001); - } - } finally { - cursor.releaseCursor(); - } - } - } - } - } -} \ No newline at end of file diff --git a/core/src/test/java/com/questdb/ql/map/RedBlackTreeTest.java b/core/src/test/java/com/questdb/ql/map/RedBlackTreeTest.java deleted file mode 100644 index c45f5a77e..000000000 --- a/core/src/test/java/com/questdb/ql/map/RedBlackTreeTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql.map; - -import com.questdb.std.RedBlackTree; -import com.questdb.std.Rnd; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Test; - -import java.util.Iterator; -import java.util.TreeSet; - -public class RedBlackTreeTest { - - @Test - public void testAddAndGet() { - Rnd rnd = new Rnd(); - TreeSet control = new TreeSet<>(); - try (RedBlackTree tree = new RedBlackTree(new RedBlackTree.LongComparator() { - private long left; - - @Override - public int compare(long y) { - return Long.compare(left, y); - } - - @Override - public void setLeft(long left) { - this.left = left; - } - }, 1024)) { - - long l; - for (int i = 0; i < 10000; i++) { - tree.add(l = rnd.nextLong()); - control.add(l); - } - - Iterator controlIterator = control.iterator(); - RedBlackTree.LongIterator iterator = tree.iterator(); - while (iterator.hasNext()) { - Assert.assertTrue(controlIterator.hasNext()); - Assert.assertEquals(controlIterator.next().longValue(), iterator.next()); - } - - tree.clear(); - - Assert.assertFalse(tree.iterator().hasNext()); - } - } - - @Test - public void testNonUnique() { - try (RedBlackTree set = new RedBlackTree(new RedBlackTree.LongComparator() { - private long left; - - @Override - public int compare(long y) { - return Long.compare(left, y); - } - - @Override - public void setLeft(long left) { - this.left = left; - } - }, 1024)) { - - set.add(200); - set.add(200); - set.add(100); - set.add(100); - - RedBlackTree.LongIterator iterator = set.iterator(); - StringBuilder b = new StringBuilder(); - while (iterator.hasNext()) { - b.append(iterator.next()).append(','); - } - TestUtils.assertEquals("100,100,200,200,", b); - } - } -} \ No newline at end of file diff --git a/core/src/test/java/com/questdb/ql/ops/regex/BMPTestCases.txt b/core/src/test/java/com/questdb/ql/ops/regex/BMPTestCases.txt deleted file mode 100644 index a5a4621fb..000000000 --- a/core/src/test/java/com/questdb/ql/ops/regex/BMPTestCases.txt +++ /dev/null @@ -1,951 +0,0 @@ -// -// Copyright (c) 1999, 2009, Oracle and/or its affiliates. All rights reserved. -// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -// -// This code is free software; you can redistribute it and/or modify it -// under the terms of the GNU General Public License version 2 only, as -// published by the Free Software Foundation. -// -// This code is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// version 2 for more details (a copy is included in the LICENSE file that -// accompanied this code). -// -// You should have received a copy of the GNU General Public License version -// 2 along with this work; if not, write to the Free Software Foundation, -// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. -// -// Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA -// or visit www.oracle.com if you need additional information or have any -// questions. -// -// -// This file contains test cases with BMP characters for regular expressions. -// A test case consists of three lines: -// The first line is a pattern used in the test -// The second line is the input to search for the pattern in -// The third line is a concatentation of the match, the number of groups, -// and the contents of the first four subexpressions. -// Empty lines and lines beginning with comment slashes are ignored. - -// Test unsetting of backed off groups -^(\u3042)?\u3042 -\u3042 -true \u3042 1 - -^(\u3042\u3042(\u3043\u3043)?)+$ -\u3042\u3042\u3043\u3043\u3042\u3042 -true \u3042\u3042\u3043\u3043\u3042\u3042 2 \u3042\u3042 \u3043\u3043 - -((\u3042|\u3043)?\u3043)+ -\u3043 -true \u3043 2 \u3043 - -(\u3042\u3042\u3042)?\u3042\u3042\u3042 -\u3042\u3042\u3042 -true \u3042\u3042\u3042 1 - -^(\u3042(\u3043)?)+$ -\u3042\u3043\u3042 -true \u3042\u3043\u3042 2 \u3042 \u3043 - -^(\u3042(\u3043(\u3044)?)?)?\u3042\u3043\u3044 -\u3042\u3043\u3044 -true \u3042\u3043\u3044 3 - -^(\u3042(\u3043(\u3044))).* -\u3042\u3043\u3044 -true \u3042\u3043\u3044 3 \u3042\u3043\u3044 \u3043\u3044 \u3044 - -// use of x modifier -\u3042\u3043\u3044(?x)\u3043la\u3049 -\u3042\u3043\u3044\u3043la\u3049 -true \u3042\u3043\u3044\u3043la\u3049 0 - -\u3042\u3043\u3044(?x) bla\u3049 -\u3042\u3043\u3044bla\u3049 -true \u3042\u3043\u3044bla\u3049 0 - -\u3042\u3043\u3044(?x) bla\u3049 ble\u3044\u3049 -\u3042\u3043\u3044bla\u3049ble\u3044\u3049 -true \u3042\u3043\u3044bla\u3049ble\u3044\u3049 0 - -\u3042\u3043\u3044(?x) bla\u3049 # ignore comment -\u3042\u3043\u3044bla\u3049 -true \u3042\u3043\u3044bla\u3049 0 - -// Simple alternation -\u3042|\u3043 -\u3042 -true \u3042 0 - -\u3042|\u3043 -\u305B -false 0 - -\u3042|\u3043 -\u3043 -true \u3043 0 - -\u3042|\u3043|\u3044\u3045 -\u3044\u3045 -true \u3044\u3045 0 - -\u3042|\u3042\u3045 -\u3042\u3045 -true \u3042 0 - -\u305B(\u3042|\u3042\u3044)\u3043 -\u305B\u3042\u3044\u3043 -true \u305B\u3042\u3044\u3043 1 \u3042\u3044 - -// Simple char class -[\u3042\u3043\u3044]+ -\u3042\u3043\u3042\u3043\u3042\u3043 -true \u3042\u3043\u3042\u3043\u3042\u3043 0 - -[\u3042\u3043\u3044]+ -\u3045\u3046\u3047\u3048 -false 0 - -[\u3042\u3043\u3044]+[\u3045\u3046\u3047]+[\u3048\u3049\u304A]+ -\u305B\u305B\u305B\u3042\u3042\u3045\u3045\u3048\u3048\u305B\u305B\u305B -true \u3042\u3042\u3045\u3045\u3048\u3048 0 - -// Range char class -[\u3042-\u3048]+ -\u305B\u305B\u305B\u3048\u3048\u3048 -true \u3048\u3048\u3048 0 - -[\u3042-\u3048]+ -mmm -false 0 - -[\u3042-]+ -\u305B\u3042-9\u305B -true \u3042- 0 - -[\u3042-\\u4444]+ -\u305B\u3042-9\u305B -true \u305B\u3042 0 - -// Negated char class -[^\u3042\u3043\u3044]+ -\u3042\u3043\u3042\u3043\u3042\u3043 -false 0 - -[^\u3042\u3043\u3044]+ -\u3042\u3042\u3042\u3043\u3043\u3043\u3044\u3044\u3044\u3045\u3046\u3047\u3048 -true \u3045\u3046\u3047\u3048 0 - -// Making sure a ^ not in first position matches literal ^ -[\u3042\u3043\u3044^\u3043] -\u3043 -true \u3043 0 - -[\u3042\u3043\u3044^\u3043] -^ -true ^ 0 - -// Class union and intersection -[\u3042\u3043\u3044[\u3045\u3046\u3047]] -\u3043 -true \u3043 0 - -[\u3042\u3043\u3044[\u3045\u3046\u3047]] -\u3046 -true \u3046 0 - -[\u3042-\u3045[0-9][\u304e-\u3051]] -\u3042 -true \u3042 0 - -[\u3042-\u3045[0-9][\u304e-\u3051]] -\u3050 -true \u3050 0 - -[\u3042-\u3045[0-9][\u304e-\u3051]] -4 -true 4 0 - -[\u3042-\u3045[0-9][\u304e-\u3051]] -\u3046 -false 0 - -[\u3042-\u3045[0-9][\u304e-\u3051]] -\u3056 -false 0 - -[[\u3042-\u3045][0-9][\u304e-\u3051]] -\u3043 -true \u3043 0 - -[[\u3042-\u3045][0-9][\u304e-\u3051]] -\u305B -false 0 - -[\u3042-\u3044[\u3045-\u3047[\u3048-\u304A]]] -\u3042 -true \u3042 0 - -[\u3042-\u3044[\u3045-\u3047[\u3048-\u304A]]] -\u3046 -true \u3046 0 - -[\u3042-\u3044[\u3045-\u3047[\u3048-\u304A]]] -\u3049 -true \u3049 0 - -[\u3042-\u3044[\u3045-\u3047[\u3048-\u304A]]] -m -false 0 - -[\u3042-\u3044[\u3045-\u3047[\u3048-\u304A]]m] -m -true m 0 - -[\u3042\u3043\u3044[\u3045\u3046\u3047]\u3048\u3049\u304A] -\u3042 -true \u3042 0 - -[\u3042\u3043\u3044[\u3045\u3046\u3047]\u3048\u3049\u304A] -\u3045 -true \u3045 0 - -[\u3042\u3043\u3044[\u3045\u3046\u3047]\u3048\u3049\u304A] -\u3049 -true \u3049 0 - -[\u3042\u3043\u3044[\u3045\u3046\u3047]\u3048\u3049\u304A] -w -false 0 - -[\u3042-\u3044&&[\u3045-\u3047]] -\u3042 -false 0 - -[\u3042-\u3044&&[\u3045-\u3047]] -\u3046 -false 0 - -[\u3042-\u3044&&[\u3045-\u3047]] -\u305B -false 0 - -[[\u3042-\u3044]&&[\u3045-\u3047]] -\u3042 -false 0 - -[[\u3042-\u3044]&&[\u3045-\u3047]] -\u3046 -false 0 - -[[\u3042-\u3044]&&[\u3045-\u3047]] -\u305B -false 0 - -[\u3042-\u3044&&\u3045-\u3047] -\u3042 -false 0 - -[\u3042-\u304e&&\u304e-\u305B] -\u304e -true \u304e 0 - -[\u3042-\u304e&&\u304e-\u305B&&\u3042-\u3044] -\u304e -false 0 - -[\u3042-\u304e&&\u304e-\u305B&&\u3042-\u305B] -\u304e -true \u304e 0 - -[[\u3042-\u304e]&&[\u304e-\u305B]] -\u3042 -false 0 - -[[\u3042-\u304e]&&[\u304e-\u305B]] -\u304e -true \u304e 0 - -[[\u3042-\u304e]&&[\u304e-\u305B]] -\u305B -false 0 - -[[\u3042-\u304e]&&[^\u3042-\u3044]] -\u3042 -false 0 - -[[\u3042-\u304e]&&[^\u3042-\u3044]] -\u3045 -true \u3045 0 - -[\u3042-\u304e&&[^\u3042-\u3044]] -\u3042 -false 0 - -[\u3042-\u304e&&[^\u3042-\u3044]] -\u3045 -true \u3045 0 - -[\u3042-\u3044\u3045-\u3047&&[\u3045-\u3047]] -\u3042 -false 0 - -[\u3042-\u3044\u3045-\u3047&&[\u3045-\u3047]] -\u3046 -true \u3046 0 - -[[\u3042-\u3044]&&\u3045-\u3047\u3042-\u3044] -\u3042 -true \u3042 0 - -[[\u3042-\u3044]&&[\u3045-\u3047][\u3042-\u3044]] -\u3042 -true \u3042 0 - -[[\u3042-\u3044][\u3045-\u3047]&&\u3042\u3043\u3044] -\u3042 -true \u3042 0 - -[[\u3042-\u3044][\u3045-\u3047]&&\u3042\u3043\u3044[\u3045\u3046\u3047]] -\u3046 -true \u3046 0 - -[[\u3042-\u3044]&&[\u3043-\u3045]&&[\u3044-\u3046]] -\u3042 -false 0 - -[[\u3042-\u3044]&&[\u3043-\u3045]&&[\u3044-\u3046]] -\u3044 -true \u3044 0 - -[[\u3042-\u3044]&&[\u3043-\u3045][\u3044-\u3046]&&[\u3056-\u305B]] -\u3044 -false 0 - -[\u3042\u3043\u3044[^\u3043\u3044\u3045]] -\u3042 -true \u3042 0 - -[\u3042\u3043\u3044[^\u3043\u3044\u3045]] -\u3045 -false 0 - -[\u3042-\u3044&&\u3042-\u3045&&\u3042-\u3046\u3048\u3049\u304A] -\u3043 -true \u3043 0 - -[\u3042-\u3044&&\u3042-\u3045&&\u3042-\u3046\u3048\u3049\u304A] -\u3048 -false 0 - -[[\u3042[\u3043]]&&[\u3043[\u3042]]] -\u3042 -true \u3042 0 - -[[\u3042]&&[\u3043][\u3044][\u3042]&&[^\u3045]] -\u3042 -true \u3042 0 - -[[\u3042]&&[b][c][\u3042]&&[^d]] -\u3042 -true \u3042 0 - -[[\u3042]&&[\u3043][\u3044][\u3042]&&[^\u3045]] -\u3045 -false 0 - -[[[\u3042-\u3045]&&[\u3044-\u3047]]] -\u3042 -false 0 - -[[[\u3042-\u3045]&&[\u3044-\u3047]]] -\u3044 -true \u3044 0 - -[[[\u3042-\u3045]&&[\u3044-\u3047]]&&[\u3044]] -\u3044 -true \u3044 0 - -[[[\u3042-\u3045]&&[\u3044-\u3047]]&&[\u3044]&&\u3044] -\u3044 -true \u3044 0 - -[[[\u3042-\u3045]&&[\u3044-\u3047]]&&[\u3044]&&\u3044&&\u3044] -\u3044 -true \u3044 0 - -[[[\u3042-\u3045]&&[\u3044-\u3047]]&&[\u3044]&&\u3044&&[\u3044\u3045\u3046]] -\u3044 -true \u3044 0 - -[\u305B[\u3042\u3043\u3044&&\u3043\u3044\u3045]] -\u3044 -true \u3044 0 - -[\u305B[\u3042\u3043\u3044&&\u3043\u3044\u3045]&&[\u3056-\u305B]] -\u305B -true \u305B 0 - -[\u3059[\u3042\u3043\u3044&&\u3043\u3044\u3045[\u305B]]&&[\u3056-\u305B]] -\u305B -false 0 - -[\u3059[[w\u305B]\u3042\u3043\u3044&&\u3043\u3044\u3045[\u305B]]&&[\u3056-\u305B]] -\u305B -true \u305B 0 - -[[\u3042\u3043\u3044]&&[\u3045\u3046\u3047]\u3042\u3043\u3044] -\u3042 -true \u3042 0 - -[[\u3042\u3043\u3044]&&[\u3045\u3046\u3047]\u3059\u305A\u305B[\u3042\u3043\u3044]] -\u3042 -true \u3042 0 - -\pL -\u3042 -true \u3042 0 - -\pL -7 -false 0 - -\p{L} -\u3042 -true \u3042 0 - -\p{IsL} -\u3042 -true \u3042 0 - -\p{InHiragana} -\u3042 -true \u3042 0 - -\p{InHiragana} -\u0370 -false 0 - -\pL\u3043\u3044 -\u3042\u3043\u3044 -true \u3042\u3043\u3044 0 - -\u3042[r\p{InGreek}]\u3044 -\u3042\u0370\u3044 -true \u3042\u0370\u3044 0 - -\u3042\p{InGreek} -\u3042\u0370 -true \u3042\u0370 0 - -\u3042\P{InGreek} -\u3042\u0370 -false 0 - -\u3042\P{InGreek} -\u3042\u3043 -true \u3042\u3043 0 - -\u3042{^InGreek} -- -error - -\u3042\p{^InGreek} -- -error - -\u3042\P{^InGreek} -- -error - -\u3042\p{InGreek} -\u3042\u0370 -true \u3042\u0370 0 - -\u3042[\p{InGreek}]\u3044 -\u3042\u0370\u3044 -true \u3042\u0370\u3044 0 - -\u3042[\P{InGreek}]\u3044 -\u3042\u0370\u3044 -false 0 - -\u3042[\P{InGreek}]\u3044 -\u3042\u3043\u3044 -true \u3042\u3043\u3044 0 - -\u3042[{^InGreek}]\u3044 -\u3042n\u3044 -true \u3042n\u3044 0 - -\u3042[{^InGreek}]\u3044 -\u3042\u305B\u3044 -false 0 - -\u3042[\p{^InGreek}]\u3044 -- -error - -\u3042[\P{^InGreek}]\u3044 -- -error - -\u3042[\p{InGreek}] -\u3042\u0370 -true \u3042\u0370 0 - -\u3042[r\p{InGreek}]\u3044 -\u3042r\u3044 -true \u3042r\u3044 0 - -\u3042[\p{InGreek}r]\u3044 -\u3042r\u3044 -true \u3042r\u3044 0 - -\u3042[r\p{InGreek}]\u3044 -\u3042r\u3044 -true \u3042r\u3044 0 - -\u3042[^\p{InGreek}]\u3044 -\u3042\u0370\u3044 -false 0 - -\u3042[^\P{InGreek}]\u3044 -\u3042\u0370\u3044 -true \u3042\u0370\u3044 0 - -\u3042[\p{InGreek}&&[^\u0370]]\u3044 -\u3042\u0370\u3044 -false 0 - -// Test the dot metacharacter -\u3042.\u3044.+ -\u3042#\u3044%& -true \u3042#\u3044%& 0 - -\u3042\u3043. -\u3042\u3043\n -false 0 - -(?s)\u3042\u3043. -\u3042\u3043\n -true \u3042\u3043\n 0 - -\u3042[\p{L}&&[\P{InGreek}]]\u3044 -\u3042\u6000\u3044 -true \u3042\u6000\u3044 0 - -\u3042[\p{L}&&[\P{InGreek}]]\u3044 -\u3042r\u3044 -true \u3042r\u3044 0 - -\u3042[\p{L}&&[\P{InGreek}]]\u3044 -\u3042\u0370\u3044 -false 0 - -\u3042\p{InGreek}\u3044 -\u3042\u0370\u3044 -true \u3042\u0370\u3044 0 - -\u3042\p{Sc} -\u3042$ -true \u3042$ 0 - -\W\w\W -rrrr#\u3048\u3048\u3048 -false 0 - -\u3042\u3043\u3044[\s\u3045\u3046\u3047]* -\u3042\u3043\u3044 \u3045\u3046\u3047 -true \u3042\u3043\u3044 \u3045\u3046\u3047 0 - -\u3042\u3043\u3044[\s\u305A-\u305B]* -\u3042\u3043\u3044 \u305A \u305B -true \u3042\u3043\u3044 \u305A \u305B 0 - -\u3042\u3043\u3044[\u3042-\u3045\s\u304e-\u3051]* -\u3042\u3043\u3044\u3042\u3042 \u304e\u304f \u3051 -true \u3042\u3043\u3044\u3042\u3042 \u304e\u304f \u3051 0 - -// Test the whitespace escape sequence -\u3042\u3043\s\u3044 -\u3042\u3043 \u3044 -true \u3042\u3043 \u3044 0 - -\s\s\s -\u3043l\u3042\u3049 \u3046rr -false 0 - -\S\S\s -\u3043l\u3042\u3049 \u3046rr -true \u3042\u3049 0 - -// Test the digit escape sequence -\u3042\u3043\d\u3044 -\u3042\u30439\u3044 -true \u3042\u30439\u3044 0 - -\d\d\d -\u3043l\u3042\u304945 -false 0 - -// Test the caret metacharacter -^\u3042\u3043\u3044 -\u3042\u3043\u3044\u3045\u3046\u3047 -true \u3042\u3043\u3044 0 - -^\u3042\u3043\u3044 -\u3043\u3044\u3045\u3042\u3043\u3044 -false 0 - -// Greedy ? metacharacter -\u3042?\u3043 -\u3042\u3042\u3042\u3042\u3043 -true \u3042\u3043 0 - -\u3042?\u3043 -\u3043 -true \u3043 0 - -\u3042?\u3043 -\u3042\u3042\u3042\u3044\u3044\u3044 -false 0 - -.?\u3043 -\u3042\u3042\u3042\u3042\u3043 -true \u3042\u3043 0 - -// Reluctant ? metacharacter -\u3042??\u3043 -\u3042\u3042\u3042\u3042\u3043 -true \u3042\u3043 0 - -\u3042??\u3043 -\u3043 -true \u3043 0 - -\u3042??\u3043 -\u3042\u3042\u3042\u3044\u3044\u3044 -false 0 - -.??\u3043 -\u3042\u3042\u3042\u3042\u3043 -true \u3042\u3043 0 - -// Possessive ? metacharacter -\u3042?+\u3043 -\u3042\u3042\u3042\u3042\u3043 -true \u3042\u3043 0 - -\u3042?+\u3043 -\u3043 -true \u3043 0 - -\u3042?+\u3043 -\u3042\u3042\u3042\u3044\u3044\u3044 -false 0 - -.?+\u3043 -\u3042\u3042\u3042\u3042\u3043 -true \u3042\u3043 0 - -// Greedy + metacharacter -\u3042+\u3043 -\u3042\u3042\u3042\u3042\u3043 -true \u3042\u3042\u3042\u3042\u3043 0 - -\u3042+\u3043 -\u3043 -false 0 - -\u3042+\u3043 -\u3042\u3042\u3042\u3044\u3044\u3044 -false 0 - -.+\u3043 -\u3042\u3042\u3042\u3042\u3043 -true \u3042\u3042\u3042\u3042\u3043 0 - -// Reluctant + metacharacter -\u3042+?\u3043 -\u3042\u3042\u3042\u3042\u3043 -true \u3042\u3042\u3042\u3042\u3043 0 - -\u3042+?\u3043 -\u3043 -false 0 - -\u3042+?\u3043 -\u3042\u3042\u3042\u3044\u3044\u3044 -false 0 - -.+?\u3043 -\u3042\u3042\u3042\u3042\u3043 -true \u3042\u3042\u3042\u3042\u3043 0 - -// Possessive + metacharacter -\u3042++\u3043 -\u3042\u3042\u3042\u3042\u3043 -true \u3042\u3042\u3042\u3042\u3043 0 - -\u3042++\u3043 -\u3043 -false 0 - -\u3042++\u3043 -\u3042\u3042\u3042\u3044\u3044\u3044 -false 0 - -.++\u3043 -\u3042\u3042\u3042\u3042\u3043 -false 0 - -// Greedy Repetition -\u3042{2,3} -\u3042 -false 0 - -\u3042{2,3} -\u3042\u3042 -true \u3042\u3042 0 - -\u3042{2,3} -\u3042\u3042\u3042 -true \u3042\u3042\u3042 0 - -\u3042{2,3} -\u3042\u3042\u3042\u3042 -true \u3042\u3042\u3042 0 - -\u3042{3,} -\u305B\u305B\u305B\u3042\u3042\u3042\u3042\u305B\u305B\u305B -true \u3042\u3042\u3042\u3042 0 - -\u3042{3,} -\u305B\u305B\u305B\u3042\u3042\u305B\u305B\u305B -false 0 - -// Reluctant Repetition -\u3042{2,3}? -\u3042 -false 0 - -\u3042{2,3}? -\u3042\u3042 -true \u3042\u3042 0 - -\u3042{2,3}? -\u3042\u3042\u3042 -true \u3042\u3042 0 - -\u3042{2,3}? -\u3042\u3042\u3042\u3042 -true \u3042\u3042 0 - -// Zero width Positive lookahead -\u3042\u3043\u3044(?=\u3045) -\u305B\u305B\u305B\u3042\u3043\u3044\u3045 -true \u3042\u3043\u3044 0 - -\u3042\u3043\u3044(?=\u3045) -\u305B\u305B\u305B\u3042\u3043\u3044\u3046\u3045 -false 0 - -// Zero width Negative lookahead -\u3042\u3043\u3044(?!\u3045) -\u305B\u305B\u3042\u3043\u3044\u3045 -false 0 - -\u3042\u3043\u3044(?!\u3045) -\u305B\u305B\u3042\u3043\u3044\u3046\u3045 -true \u3042\u3043\u3044 0 - -// Zero width Positive lookbehind -\u3042(?<=\u3042) -###\u3042\u3043\u3044 -true \u3042 0 - -\u3042(?<=\u3042) -###\u3043\u3044### -false 0 - -// Zero width Negative lookbehind -(?3 -// So that the BM optimization is part of test -\Q***\E\u3042\u3043\u3044 -***\u3042\u3043\u3044 -true ***\u3042\u3043\u3044 0 - -\u3043l\Q***\E\u3042\u3043\u3044 -\u3043l***\u3042\u3043\u3044 -true \u3043l***\u3042\u3043\u3044 0 - -\Q***\u3042\u3043\u3044 -***\u3042\u3043\u3044 -true ***\u3042\u3043\u3044 0 - -\u3043l\u3042\u3049\Q***\E\u3042\u3043\u3044 -\u3043l\u3042\u3049***\u3042\u3043\u3044 -true \u3043l\u3042\u3049***\u3042\u3043\u3044 0 - -\Q***\u3042\u3043\u3044 -***\u3042\u3043\u3044 -true ***\u3042\u3043\u3044 0 - -\Q*\u3042\u3043 -*\u3042\u3043 -true *\u3042\u3043 0 - -\u3043l\u3042\u3049\Q***\u3042\u3043\u3044 -\u3043l\u3042\u3049***\u3042\u3043\u3044 -true \u3043l\u3042\u3049***\u3042\u3043\u3044 0 - -\u3043l\u3042\Q***\u3042\u3043\u3044 -\u3043l\u3042***\u3042\u3043\u3044 -true \u3043l\u3042***\u3042\u3043\u3044 0 - -[\043]+ -\u3043l\u3042\u3049\u3043l\u3042\u3049#\u3043le\u3044\u3049 -true # 0 - -[\042-\044]+ -\u3043l\u3042\u3049\u3043l\u3042\u3049#\u3043le\u3044\u3049 -true # 0 - -[\u1234-\u1236] -\u3043l\u3042\u3049\u3043l\u3042\u3049\u1235\u3043le\u3044\u3049 -true \u1235 0 - -[^\043]* -\u3043l\u3042\u3049\u3043l\u3042\u3049#\u3043le\u3044\u3049 -true \u3043l\u3042\u3049\u3043l\u3042\u3049 0 diff --git a/core/src/test/java/com/questdb/ql/ops/regex/POSIX_ASCII.java b/core/src/test/java/com/questdb/ql/ops/regex/POSIX_ASCII.java deleted file mode 100644 index 4d121fdec..000000000 --- a/core/src/test/java/com/questdb/ql/ops/regex/POSIX_ASCII.java +++ /dev/null @@ -1,248 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql.ops.regex; - -final class POSIX_ASCII { - - static final int UPPER = 0x00000100; - - static final int LOWER = 0x00000200; - - static final int DIGIT = 0x00000400; - - static final int SPACE = 0x00000800; - - static final int PUNCT = 0x00001000; - - static final int CNTRL = 0x00002000; - - static final int BLANK = 0x00004000; - - static final int HEX = 0x00008000; - - static final int UNDER = 0x00010000; - - static final int ASCII = 0x0000FF00; - - static final int ALPHA = (UPPER | LOWER); - - static final int ALNUM = (UPPER | LOWER | DIGIT); - - static final int GRAPH = (PUNCT | UPPER | LOWER | DIGIT); - - static final int WORD = (UPPER | LOWER | UNDER | DIGIT); - - static final int XDIGIT = (HEX); - - private static final int[] ctype = new int[]{ - CNTRL, /* 00 (NUL) */ - CNTRL, /* 01 (SOH) */ - CNTRL, /* 02 (STX) */ - CNTRL, /* 03 (ETX) */ - CNTRL, /* 04 (EOT) */ - CNTRL, /* 05 (ENQ) */ - CNTRL, /* 06 (ACK) */ - CNTRL, /* 07 (BEL) */ - CNTRL, /* 08 (BS) */ - SPACE + CNTRL + BLANK, /* 09 (HT) */ - SPACE + CNTRL, /* 0A (LF) */ - SPACE + CNTRL, /* 0B (VT) */ - SPACE + CNTRL, /* 0C (FF) */ - SPACE + CNTRL, /* 0D (CR) */ - CNTRL, /* 0E (SI) */ - CNTRL, /* 0F (SO) */ - CNTRL, /* 10 (DLE) */ - CNTRL, /* 11 (DC1) */ - CNTRL, /* 12 (DC2) */ - CNTRL, /* 13 (DC3) */ - CNTRL, /* 14 (DC4) */ - CNTRL, /* 15 (NAK) */ - CNTRL, /* 16 (SYN) */ - CNTRL, /* 17 (ETB) */ - CNTRL, /* 18 (CAN) */ - CNTRL, /* 19 (EM) */ - CNTRL, /* 1A (SUB) */ - CNTRL, /* 1B (ESC) */ - CNTRL, /* 1C (FS) */ - CNTRL, /* 1D (GS) */ - CNTRL, /* 1E (RS) */ - CNTRL, /* 1F (US) */ - SPACE + BLANK, /* 20 SPACE */ - PUNCT, /* 21 ! */ - PUNCT, /* 22 " */ - PUNCT, /* 23 # */ - PUNCT, /* 24 $ */ - PUNCT, /* 25 % */ - PUNCT, /* 26 & */ - PUNCT, /* 27 ' */ - PUNCT, /* 28 ( */ - PUNCT, /* 29 ) */ - PUNCT, /* 2A * */ - PUNCT, /* 2B + */ - PUNCT, /* 2C , */ - PUNCT, /* 2D - */ - PUNCT, /* 2E . */ - PUNCT, /* 2F / */ - DIGIT + HEX + 0, /* 30 0 */ - DIGIT + HEX + 1, /* 31 1 */ - DIGIT + HEX + 2, /* 32 2 */ - DIGIT + HEX + 3, /* 33 3 */ - DIGIT + HEX + 4, /* 34 4 */ - DIGIT + HEX + 5, /* 35 5 */ - DIGIT + HEX + 6, /* 36 6 */ - DIGIT + HEX + 7, /* 37 7 */ - DIGIT + HEX + 8, /* 38 8 */ - DIGIT + HEX + 9, /* 39 9 */ - PUNCT, /* 3A : */ - PUNCT, /* 3B ; */ - PUNCT, /* 3C < */ - PUNCT, /* 3D = */ - PUNCT, /* 3E > */ - PUNCT, /* 3F ? */ - PUNCT, /* 40 @ */ - UPPER + HEX + 10, /* 41 A */ - UPPER + HEX + 11, /* 42 B */ - UPPER + HEX + 12, /* 43 C */ - UPPER + HEX + 13, /* 44 D */ - UPPER + HEX + 14, /* 45 E */ - UPPER + HEX + 15, /* 46 F */ - UPPER + 16, /* 47 G */ - UPPER + 17, /* 48 H */ - UPPER + 18, /* 49 I */ - UPPER + 19, /* 4A J */ - UPPER + 20, /* 4B K */ - UPPER + 21, /* 4C L */ - UPPER + 22, /* 4D M */ - UPPER + 23, /* 4E N */ - UPPER + 24, /* 4F O */ - UPPER + 25, /* 50 P */ - UPPER + 26, /* 51 Q */ - UPPER + 27, /* 52 R */ - UPPER + 28, /* 53 S */ - UPPER + 29, /* 54 T */ - UPPER + 30, /* 55 U */ - UPPER + 31, /* 56 V */ - UPPER + 32, /* 57 W */ - UPPER + 33, /* 58 X */ - UPPER + 34, /* 59 Y */ - UPPER + 35, /* 5A Z */ - PUNCT, /* 5B [ */ - PUNCT, /* 5C \ */ - PUNCT, /* 5D ] */ - PUNCT, /* 5E ^ */ - PUNCT | UNDER, /* 5F _ */ - PUNCT, /* 60 ` */ - LOWER + HEX + 10, /* 61 a */ - LOWER + HEX + 11, /* 62 b */ - LOWER + HEX + 12, /* 63 c */ - LOWER + HEX + 13, /* 64 d */ - LOWER + HEX + 14, /* 65 e */ - LOWER + HEX + 15, /* 66 f */ - LOWER + 16, /* 67 g */ - LOWER + 17, /* 68 h */ - LOWER + 18, /* 69 i */ - LOWER + 19, /* 6A j */ - LOWER + 20, /* 6B k */ - LOWER + 21, /* 6C l */ - LOWER + 22, /* 6D m */ - LOWER + 23, /* 6E n */ - LOWER + 24, /* 6F o */ - LOWER + 25, /* 70 p */ - LOWER + 26, /* 71 q */ - LOWER + 27, /* 72 r */ - LOWER + 28, /* 73 s */ - LOWER + 29, /* 74 t */ - LOWER + 30, /* 75 u */ - LOWER + 31, /* 76 v */ - LOWER + 32, /* 77 w */ - LOWER + 33, /* 78 x */ - LOWER + 34, /* 79 y */ - LOWER + 35, /* 7A z */ - PUNCT, /* 7B { */ - PUNCT, /* 7C | */ - PUNCT, /* 7D } */ - PUNCT, /* 7E ~ */ - CNTRL, /* 7F (DEL) */ - }; - - static int getType(int ch) { - return ((ch & 0xFFFFFF80) == 0 ? ctype[ch] : 0); - } - - static boolean isType(int ch, int type) { - return (getType(ch) & type) != 0; - } - - static boolean isAscii(int ch) { - return ((ch & 0xFFFFFF80) == 0); - } - - static boolean isAlpha(int ch) { - return isType(ch, ALPHA); - } - - static boolean isDigit(int ch) { - return ((ch - '0') | ('9' - ch)) >= 0; - } - - static boolean isAlnum(int ch) { - return isType(ch, ALNUM); - } - - static boolean isGraph(int ch) { - return isType(ch, GRAPH); - } - - static boolean isPrint(int ch) { - return ((ch - 0x20) | (0x7E - ch)) >= 0; - } - - static boolean isPunct(int ch) { - return isType(ch, PUNCT); - } - - static boolean isSpace(int ch) { - return isType(ch, SPACE); - } - - static boolean isHexDigit(int ch) { - return isType(ch, HEX); - } - - static boolean isCntrl(int ch) { - return isType(ch, CNTRL); - } - - static boolean isLower(int ch) { - return ((ch - 'a') | ('z' - ch)) >= 0; - } - - static boolean isUpper(int ch) { - return ((ch - 'A') | ('Z' - ch)) >= 0; - } - - static boolean isWord(int ch) { - return isType(ch, WORD); - } -} diff --git a/core/src/test/java/com/questdb/ql/ops/regex/POSIX_Unicode.java b/core/src/test/java/com/questdb/ql/ops/regex/POSIX_Unicode.java deleted file mode 100644 index e4f964b5e..000000000 --- a/core/src/test/java/com/questdb/ql/ops/regex/POSIX_Unicode.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql.ops.regex; - -final public class POSIX_Unicode { - - // \p{alpha} - // \p{digit} - public static boolean isAlnum(int ch) { - return Character.isAlphabetic(ch) || Character.isDigit(ch); - } - - public static boolean isAlpha(int ch) { - return Character.isAlphabetic(ch); - } - - // \p{Whitespace} -- - // [\N{LF} \N{VT} \N{FF} \N{CR} \N{NEL} -> 0xa, 0xb, 0xc, 0xd, 0x85 - // \p{gc=Line_Separator} - // \p{gc=Paragraph_Separator}] - public static boolean isBlank(int ch) { - int type = Character.getType(ch); - return isSpace(ch) && - ch != 0xa & ch != 0xb && ch != 0xc && ch != 0xd && ch != 0x85 && - type != Character.LINE_SEPARATOR && - type != Character.PARAGRAPH_SEPARATOR; - } - - // \p{gc=Control} - public static boolean isCntrl(int ch) { - return Character.getType(ch) == Character.CONTROL; - } - - // \p{gc=Decimal_Number} - public static boolean isDigit(int ch) { - return Character.isDigit(ch); - } - - // [^ - // \p{space} - // \p{gc=Control} - // \p{gc=Surrogate} - // \p{gc=Unassigned}] - public static boolean isGraph(int ch) { - int type = Character.getType(ch); - return !(isSpace(ch) || - Character.CONTROL == type || - Character.SURROGATE == type || - Character.UNASSIGNED == type); - } - - // \p{gc=Decimal_Number} - // \p{Hex_Digit} -> PropList.txt: Hex_Digit - public static boolean isHexDigit(int ch) { - return Character.isDigit(ch) || - (ch >= 0x0030 && ch <= 0x0039) || - (ch >= 0x0041 && ch <= 0x0046) || - (ch >= 0x0061 && ch <= 0x0066) || - (ch >= 0xFF10 && ch <= 0xFF19) || - (ch >= 0xFF21 && ch <= 0xFF26) || - (ch >= 0xFF41 && ch <= 0xFF46); - } - - public static boolean isJoinControl(int ch) { - return (ch == 0x200C || ch == 0x200D); - } - - public static boolean isLower(int ch) { - return Character.isLowerCase(ch); - } - - // PropList.txt:Noncharacter_Code_Point - public static boolean isNoncharacterCodePoint(int ch) { - return (ch & 0xfffe) == 0xfffe || (ch >= 0xfdd0 && ch <= 0xfdef); - } - - // \p{graph} - // \p{blank} - // -- \p{cntrl} - public static boolean isPrint(int ch) { - return (isGraph(ch) || isBlank(ch)) && !isCntrl(ch); - } - - // \p{gc=Punctuation} - public static boolean isPunct(int ch) { - return ((((1 << Character.CONNECTOR_PUNCTUATION) | - (1 << Character.DASH_PUNCTUATION) | - (1 << Character.START_PUNCTUATION) | - (1 << Character.END_PUNCTUATION) | - (1 << Character.OTHER_PUNCTUATION) | - (1 << Character.INITIAL_QUOTE_PUNCTUATION) | - (1 << Character.FINAL_QUOTE_PUNCTUATION)) >> Character.getType(ch)) & 1) - != 0; - } - - // \p{Whitespace} - public static boolean isSpace(int ch) { - return ((((1 << Character.SPACE_SEPARATOR) | - (1 << Character.LINE_SEPARATOR) | - (1 << Character.PARAGRAPH_SEPARATOR)) >> Character.getType(ch)) & 1) - != 0 || - (ch >= 0x9 && ch <= 0xd) || - (ch == 0x85); - } - - public static boolean isUpper(int ch) { - return Character.isUpperCase(ch); - } - - // \p{alpha} - // \p{gc=Mark} - // \p{digit} - // \p{gc=Connector_Punctuation} - public static boolean isWord(int ch) { - return isAlpha(ch) || - ((((1 << Character.NON_SPACING_MARK) | - (1 << Character.ENCLOSING_MARK) | - (1 << Character.COMBINING_SPACING_MARK) | - (1 << Character.CONNECTOR_PUNCTUATION)) >> Character.getType(ch)) & 1) - != 0 || - isDigit(ch) || - isJoinControl(ch); - } -} diff --git a/core/src/test/java/com/questdb/ql/ops/regex/RegExTest.java b/core/src/test/java/com/questdb/ql/ops/regex/RegExTest.java deleted file mode 100644 index 76108dfb3..000000000 --- a/core/src/test/java/com/questdb/ql/ops/regex/RegExTest.java +++ /dev/null @@ -1,3933 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql.ops.regex; - -/** - * @test - * @summary tests RegExp framework - * @author Mike McCloskey - * @bug 4481568 4482696 4495089 4504687 4527731 4599621 4631553 4619345 - * 4630911 4672616 4711773 4727935 4750573 4792284 4803197 4757029 4808962 - * 4872664 4803179 4892980 4900747 4945394 4938995 4979006 4994840 4997476 - * 5013885 5003322 4988891 5098443 5110268 6173522 4829857 5027748 6376940 - * 6358731 6178785 6284152 6231989 6497148 6486934 6233084 6504326 6635133 - * 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066 - * 7067045 7014640 7189363 8007395 8013252 8013254 8012646 8023647 6559590 - * 8027645 6854417 - */ - -import java.io.*; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Random; - -/** - * This is a test class created to check the operation of - * the Pattern and Matcher classes. - */ -public class RegExTest { - - private static final Random generator = new Random(); - private static boolean failure = false; - private static int failCount = 0; - private static String firstFailure = null; - - /** - * Main to interpret arguments and run several tests. - */ - public static void main(String[] args) throws Exception { - // Most of the tests are in a file - processFile("TestCases.txt"); - //processFile("PerlCases.txt"); - processFile("BMPTestCases.txt"); - processFile("SupplementaryTestCases.txt"); - - // These test many randomly generated char patterns - bm(); - slice(); - - // These are hard to put into the file - escapes(); - blankInput(); - - // Substitition tests on randomly generated sequences - globalSubstitute(); - stringbufferSubstitute(); - substitutionBasher(); - - // Canonical Equivalence - ceTest(); - - // Anchors - anchorTest(); - - // boolean match calls - matchesTest(); - lookingAtTest(); - - // Pattern API - patternMatchesTest(); - - // Misc - lookbehindTest(); - nullArgumentTest(); - backRefTest(); - groupCaptureTest(); - caretTest(); - charClassTest(); - emptyPatternTest(); - findIntTest(); - group0Test(); - longPatternTest(); - octalTest(); - ampersandTest(); - negationTest(); - appendTest(); - caseFoldingTest(); - commentsTest(); - unixLinesTest(); - replaceFirstTest(); - gTest(); - zTest(); - serializeTest(); - reluctantRepetitionTest(); - multilineDollarTest(); - dollarAtEndTest(); - caretBetweenTerminatorsTest(); - // This RFE rejected in Tiger numOccurrencesTest(); - javaCharClassTest(); - nonCaptureRepetitionTest(); - notCapturedGroupCurlyMatchTest(); - escapedSegmentTest(); - literalPatternTest(); - literalReplacementTest(); - regionTest(); - toStringTest(); - negatedCharClassTest(); - findFromTest(); - boundsTest(); - unicodeWordBoundsTest(); - caretAtEndTest(); - wordSearchTest(); - hitEndTest(); - toMatchResultTest(); - surrogatesInClassTest(); - removeQEQuotingTest(); - namedGroupCaptureTest(); - nonBmpClassComplementTest(); - unicodePropertiesTest(); - unicodeHexNotationTest(); - unicodeClassesTest(); - horizontalAndVerticalWSTest(); - linebreakTest(); - branchTest(); - groupCurlyNotFoundSuppTest(); - groupCurlyBackoffTest(); - - if (failure) { - throw new - RuntimeException("RegExTest failed, 1st failure: " + - firstFailure); - } else { - System.err.println("OKAY: All tests passed."); - } - } - - // Utility functions - - private static String getRandomAlphaString(int length) { - StringBuilder buf = new StringBuilder(length); - for (int i = 0; i < length; i++) { - char randChar = (char) (97 + generator.nextInt(26)); - buf.append(randChar); - } - return buf.toString(); - } - - private static void check(Matcher m, String expected) { - m.find(); - if (!m.group().equals(expected)) - failCount++; - } - - private static void check(Matcher m, String result, boolean expected) { - m.find(); - if (m.group().equals(result) != expected) - failCount++; - } - - private static void check(Pattern p, String s, boolean expected) { - if (p.matcher(s).find() != expected) - failCount++; - } - - private static void check(String p, String s, boolean expected) { - Matcher matcher = Pattern.compile(p).matcher(s); - if (matcher.find() != expected) - failCount++; - } - - private static void check(String p, char c, boolean expected) { - String propertyPattern = expected ? "\\p" + p : "\\P" + p; - Pattern pattern = Pattern.compile(propertyPattern); - char[] ca = new char[1]; - ca[0] = c; - Matcher matcher = pattern.matcher(new String(ca)); - if (!matcher.find()) - failCount++; - } - - private static void check(String p, int codePoint, boolean expected) { - String propertyPattern = expected ? "\\p" + p : "\\P" + p; - Pattern pattern = Pattern.compile(propertyPattern); - char[] ca = Character.toChars(codePoint); - Matcher matcher = pattern.matcher(new String(ca)); - if (!matcher.find()) - failCount++; - } - - private static void check(String p, int flag, String input, String s, - boolean expected) { - Pattern pattern = Pattern.compile(p, flag); - Matcher matcher = pattern.matcher(input); - if (expected) - check(matcher, s, true); - else - check(pattern, input, false); - } - - private static void report(String testName) { - int spacesToAdd = 30 - testName.length(); - StringBuilder paddedNameBuffer = new StringBuilder(testName); - for (int i = 0; i < spacesToAdd; i++) - paddedNameBuffer.append(" "); - String paddedName = paddedNameBuffer.toString(); - System.err.println(paddedName + ": " + - (failCount == 0 ? "Passed" : "Failed(" + failCount + ")")); - if (failCount > 0) { - failure = true; - - if (firstFailure == null) { - firstFailure = testName; - } - } - - failCount = 0; - } - - /** - * Converts ASCII alphabet characters [A-Za-z] in the given 's' to - * supplementary characters. This method does NOT fully take care - * of the regex syntax. - */ - private static String toSupplementaries(String s) { - int length = s.length(); - StringBuilder sb = new StringBuilder(length * 2); - - for (int i = 0; i < length; ) { - char c = s.charAt(i++); - if (c == '\\') { - sb.append(c); - if (i < length) { - c = s.charAt(i++); - sb.append(c); - if (c == 'u') { - // assume no syntax error - sb.append(s.charAt(i++)); - sb.append(s.charAt(i++)); - sb.append(s.charAt(i++)); - sb.append(s.charAt(i++)); - } - } - } else if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) { - sb.append('\ud800').append((char) ('\udc00' + c)); - } else { - sb.append(c); - } - } - return sb.toString(); - } - - // Regular expression tests - - // This is for bug 6178785 - // Test if an expected NPE gets thrown when passing in a null argument - private static boolean check(Runnable test) { - try { - test.run(); - failCount++; - return false; - } catch (NullPointerException npe) { - return true; - } - } - - private static void nullArgumentTest() { - check(() -> Pattern.compile(null)); - check(() -> Pattern.matches(null, null)); - check(() -> Pattern.matches("xyz", null)); - check(() -> Pattern.quote(null)); - check(() -> Pattern.compile("xyz").split(null)); - check(() -> Pattern.compile("xyz").matcher(null)); - - final Matcher m = Pattern.compile("xyz").matcher("xyz"); - m.matches(); - check(() -> m.appendTail(null)); - check(() -> m.replaceAll(null)); - check(() -> m.replaceFirst(null)); - check(() -> m.appendReplacement(null, null)); - check(() -> m.reset(null)); - check(() -> Matcher.quoteReplacement(null)); - //check(new Runnable() { public void run() { m.usePattern(null);}}); - - report("Null Argument"); - } - - // This is for bug6635133 - // Test if surrogate pair in Unicode escapes can be handled correctly. - private static void surrogatesInClassTest() { - Pattern pattern = Pattern.compile("[\\ud834\\udd21-\\ud834\\udd24]"); - Matcher matcher = pattern.matcher("\ud834\udd22"); - if (!matcher.find()) - failCount++; - - report("Surrogate pair in Unicode escape"); - } - - // This is for bug6990617 - // Test if Pattern.RemoveQEQuoting works correctly if the octal unicode - // char encoding is only 2 or 3 digits instead of 4 and the first quoted - // char is an octal digit. - private static void removeQEQuotingTest() { - Pattern pattern = - Pattern.compile("\\011\\Q1sometext\\E\\011\\Q2sometext\\E"); - Matcher matcher = pattern.matcher("\t1sometext\t2sometext"); - if (!matcher.find()) - failCount++; - - report("Remove Q/E Quoting"); - } - - // This is for bug 4988891 - // Test toMatchResult to see that it is a copy of the Matcher - // that is not affected by subsequent operations on the original - private static void toMatchResultTest() { - Pattern pattern = Pattern.compile("squid"); - Matcher matcher = pattern.matcher( - "agiantsquidofdestinyasmallsquidoffate"); - matcher.find(); - int matcherStart1 = matcher.start(); - MatchResult mr = matcher.toMatchResult(); - if (mr == matcher) - failCount++; - int resultStart1 = mr.start(); - if (matcherStart1 != resultStart1) - failCount++; - matcher.find(); - int matcherStart2 = matcher.start(); - int resultStart2 = mr.start(); - if (matcherStart2 == resultStart2) - failCount++; - if (resultStart1 != resultStart2) - failCount++; - MatchResult mr2 = matcher.toMatchResult(); - if (mr == mr2) - failCount++; - if (mr2.start() != matcherStart2) - failCount++; - report("toMatchResult is a copy"); - } - - // This is for bug 5013885 - // Must test a slice to see if it reports hitEnd correctly - private static void hitEndTest() { - // Basic test of Slice node - Pattern p = Pattern.compile("^squidattack"); - Matcher m = p.matcher("squack"); - m.find(); - if (m.hitEnd()) - failCount++; - m.reset("squid"); - m.find(); - if (!m.hitEnd()) - failCount++; - - // Test Slice, SliceA and SliceU nodes - for (int i = 0; i < 3; i++) { - int flags = 0; - if (i == 1) flags = Pattern.CASE_INSENSITIVE; - if (i == 2) flags = Pattern.UNICODE_CASE; - p = Pattern.compile("^abc", flags); - m = p.matcher("ad"); - m.find(); - if (m.hitEnd()) - failCount++; - m.reset("ab"); - m.find(); - if (!m.hitEnd()) - failCount++; - } - - // Test Boyer-Moore node - p = Pattern.compile("catattack"); - m = p.matcher("attack"); - m.find(); - if (!m.hitEnd()) - failCount++; - - p = Pattern.compile("catattack"); - m = p.matcher("attackattackattackcatatta"); - m.find(); - if (!m.hitEnd()) - failCount++; - report("hitEnd from a Slice"); - } - - // This is for bug 4997476 - // It is weird code submitted by customer demonstrating a regression - private static void wordSearchTest() { - String testString = "word1 word2 word3"; - Pattern p = Pattern.compile("\\b"); - Matcher m = p.matcher(testString); - int position = 0; - int start = 0; - while (m.find(position)) { - start = m.start(); - if (start == testString.length()) - break; - if (m.find(start + 1)) { - position = m.start(); - } else { - position = testString.length(); - } - if (testString.substring(start, position).equals(" ")) - continue; - if (!testString.substring(start, position - 1).startsWith("word")) - failCount++; - } - report("Customer word search"); - } - - // This is for bug 4994840 - private static void caretAtEndTest() { - // Problem only occurs with multiline patterns - // containing a beginning-of-line caret "^" followed - // by an expression that also matches the empty string. - Pattern pattern = Pattern.compile("^x?", Pattern.MULTILINE); - Matcher matcher = pattern.matcher("\r"); - matcher.find(); - matcher.find(); - report("Caret at end"); - } - - // This test is for 4979006 - // Check to see if word boundary construct properly handles unicode - // non spacing marks - private static void unicodeWordBoundsTest() { - String spaces = " "; - String wordChar = "a"; - String nsm = "\u030a"; - - assert (Character.getType('\u030a') == Character.NON_SPACING_MARK); - - Pattern pattern = Pattern.compile("\\b"); - Matcher matcher = pattern.matcher(""); - // S=other B=word character N=non spacing mark .=word boundary - // SS.BB.SS - String input = spaces + wordChar + wordChar + spaces; - twoFindIndexes(input, matcher, 2, 4); - // SS.BBN.SS - input = spaces + wordChar + wordChar + nsm + spaces; - twoFindIndexes(input, matcher, 2, 5); - // SS.BN.SS - input = spaces + wordChar + nsm + spaces; - twoFindIndexes(input, matcher, 2, 4); - // SS.BNN.SS - input = spaces + wordChar + nsm + nsm + spaces; - twoFindIndexes(input, matcher, 2, 5); - // SSN.BB.SS - input = spaces + nsm + wordChar + wordChar + spaces; - twoFindIndexes(input, matcher, 3, 5); - // SS.BNB.SS - input = spaces + wordChar + nsm + wordChar + spaces; - twoFindIndexes(input, matcher, 2, 5); - // SSNNSS - input = spaces + nsm + nsm + spaces; - matcher.reset(input); - if (matcher.find()) - failCount++; - // SSN.BBN.SS - input = spaces + nsm + wordChar + wordChar + nsm + spaces; - twoFindIndexes(input, matcher, 3, 6); - - report("Unicode word boundary"); - } - - private static void twoFindIndexes(String input, Matcher matcher, int a, - int b) { - matcher.reset(input); - matcher.find(); - if (matcher.start() != a) - failCount++; - matcher.find(); - if (matcher.start() != b) - failCount++; - } - - // This test is for 6284152 - static void check(String regex, String input, String[] expected) { - List result = new ArrayList<>(); - Pattern p = Pattern.compile(regex); - Matcher m = p.matcher(input); - while (m.find()) { - result.add(m.group()); - } - if (!Arrays.asList(expected).equals(result)) - failCount++; - } - - private static void lookbehindTest() { - //Positive - check("(?<=%.{0,5})foo\\d", - "%foo1\n%bar foo2\n%bar foo3\n%blahblah foo4\nfoo5", - new String[]{"foo1", "foo2", "foo3"}); - - //boundary at end of the lookbehind sub-regex should work consistently - //with the boundary just after the lookbehind sub-regex - check("(?<=.*\\b)foo", "abcd foo", new String[]{"foo"}); - check("(?<=.*)\\bfoo", "abcd foo", new String[]{"foo"}); - check("(?]"); - Matcher matcher = pattern.matcher("\u203A"); - if (!matcher.matches()) - failCount++; - pattern = Pattern.compile("[^fr]"); - matcher = pattern.matcher("a"); - if (!matcher.find()) - failCount++; - matcher.reset("\u203A"); - if (!matcher.find()) - failCount++; - String s = "for"; - String[] result = s.split("[^fr]"); - if (!result[0].equals("f")) - failCount++; - if (!result[1].equals("r")) - failCount++; - s = "f\u203Ar"; - result = s.split("[^fr]"); - if (!result[0].equals("f")) - failCount++; - if (!result[1].equals("r")) - failCount++; - - // Test adding to bits, subtracting a node, then adding to bits again - pattern = Pattern.compile("[^f\u203Ar]"); - matcher = pattern.matcher("a"); - if (!matcher.find()) - failCount++; - matcher.reset("f"); - if (matcher.find()) - failCount++; - matcher.reset("\u203A"); - if (matcher.find()) - failCount++; - matcher.reset("r"); - if (matcher.find()) - failCount++; - matcher.reset("\u203B"); - if (!matcher.find()) - failCount++; - - // Test subtracting a node, adding to bits, subtracting again - pattern = Pattern.compile("[^\u203Ar\u203B]"); - matcher = pattern.matcher("a"); - if (!matcher.find()) - failCount++; - matcher.reset("\u203A"); - if (matcher.find()) - failCount++; - matcher.reset("r"); - if (matcher.find()) - failCount++; - matcher.reset("\u203B"); - if (matcher.find()) - failCount++; - matcher.reset("\u203C"); - if (!matcher.find()) - failCount++; - - report("Negated Character Class"); - } - - // This test is for 4628291 - private static void toStringTest() { - Pattern pattern = Pattern.compile("b+"); - if (pattern.toString() != "b+") - failCount++; - Matcher matcher = pattern.matcher("aaabbbccc"); - String matcherString = matcher.toString(); // unspecified - matcher.find(); - matcherString = matcher.toString(); // unspecified - matcher.region(0, 3); - matcherString = matcher.toString(); // unspecified - matcher.reset(); - matcherString = matcher.toString(); // unspecified - report("toString"); - } - - // This test is for 4808962 - private static void literalPatternTest() { - int flags = Pattern.LITERAL; - - Pattern pattern = Pattern.compile("abc\\t$^", flags); - check(pattern, "abc\\t$^", true); - - pattern = Pattern.compile(Pattern.quote("abc\\t$^")); - check(pattern, "abc\\t$^", true); - - pattern = Pattern.compile("\\Qa^$bcabc\\E", flags); - check(pattern, "\\Qa^$bcabc\\E", true); - check(pattern, "a^$bcabc", false); - - pattern = Pattern.compile("\\\\Q\\\\E"); - check(pattern, "\\Q\\E", true); - - pattern = Pattern.compile("\\Qabc\\Eefg\\\\Q\\\\Ehij"); - check(pattern, "abcefg\\Q\\Ehij", true); - - pattern = Pattern.compile("\\\\\\Q\\\\E"); - check(pattern, "\\\\\\\\", true); - - pattern = Pattern.compile(Pattern.quote("\\Qa^$bcabc\\E")); - check(pattern, "\\Qa^$bcabc\\E", true); - check(pattern, "a^$bcabc", false); - - pattern = Pattern.compile(Pattern.quote("\\Qabc\\Edef")); - check(pattern, "\\Qabc\\Edef", true); - check(pattern, "abcdef", false); - - pattern = Pattern.compile(Pattern.quote("abc\\Edef")); - check(pattern, "abc\\Edef", true); - check(pattern, "abcdef", false); - - pattern = Pattern.compile(Pattern.quote("\\E")); - check(pattern, "\\E", true); - - pattern = Pattern.compile("((((abc.+?:)", flags); - check(pattern, "((((abc.+?:)", true); - - flags |= Pattern.MULTILINE; - - pattern = Pattern.compile("^cat$", flags); - check(pattern, "abc^cat$def", true); - check(pattern, "cat", false); - - flags |= Pattern.CASE_INSENSITIVE; - - pattern = Pattern.compile("abcdef", flags); - check(pattern, "ABCDEF", true); - check(pattern, "AbCdEf", true); - - flags |= Pattern.DOTALL; - - pattern = Pattern.compile("a...b", flags); - check(pattern, "A...b", true); - check(pattern, "Axxxb", false); - - flags |= Pattern.CANON_EQ; - - Pattern p = Pattern.compile("testa\u030a", flags); - check(pattern, "testa\u030a", false); - check(pattern, "test\u00e5", false); - - // Supplementary character test - flags = Pattern.LITERAL; - - pattern = Pattern.compile(toSupplementaries("abc\\t$^"), flags); - check(pattern, toSupplementaries("abc\\t$^"), true); - - pattern = Pattern.compile(Pattern.quote(toSupplementaries("abc\\t$^"))); - check(pattern, toSupplementaries("abc\\t$^"), true); - - pattern = Pattern.compile(toSupplementaries("\\Qa^$bcabc\\E"), flags); - check(pattern, toSupplementaries("\\Qa^$bcabc\\E"), true); - check(pattern, toSupplementaries("a^$bcabc"), false); - - pattern = Pattern.compile(Pattern.quote(toSupplementaries("\\Qa^$bcabc\\E"))); - check(pattern, toSupplementaries("\\Qa^$bcabc\\E"), true); - check(pattern, toSupplementaries("a^$bcabc"), false); - - pattern = Pattern.compile(Pattern.quote(toSupplementaries("\\Qabc\\Edef"))); - check(pattern, toSupplementaries("\\Qabc\\Edef"), true); - check(pattern, toSupplementaries("abcdef"), false); - - pattern = Pattern.compile(Pattern.quote(toSupplementaries("abc\\Edef"))); - check(pattern, toSupplementaries("abc\\Edef"), true); - check(pattern, toSupplementaries("abcdef"), false); - - pattern = Pattern.compile(toSupplementaries("((((abc.+?:)"), flags); - check(pattern, toSupplementaries("((((abc.+?:)"), true); - - flags |= Pattern.MULTILINE; - - pattern = Pattern.compile(toSupplementaries("^cat$"), flags); - check(pattern, toSupplementaries("abc^cat$def"), true); - check(pattern, toSupplementaries("cat"), false); - - flags |= Pattern.DOTALL; - - // note: this is case-sensitive. - pattern = Pattern.compile(toSupplementaries("a...b"), flags); - check(pattern, toSupplementaries("a...b"), true); - check(pattern, toSupplementaries("axxxb"), false); - - flags |= Pattern.CANON_EQ; - - String t = toSupplementaries("test"); - p = Pattern.compile(t + "a\u030a", flags); - check(pattern, t + "a\u030a", false); - check(pattern, t + "\u00e5", false); - - report("Literal pattern"); - } - - // This test is for 4803179 - // This test is also for 4808962, replacement parts - private static void literalReplacementTest() { - int flags = Pattern.LITERAL; - - Pattern pattern = Pattern.compile("abc", flags); - Matcher matcher = pattern.matcher("zzzabczzz"); - String replaceTest = "$0"; - String result = matcher.replaceAll(replaceTest); - if (!result.equals("zzzabczzz")) - failCount++; - - matcher.reset(); - String literalReplacement = Matcher.quoteReplacement(replaceTest); - result = matcher.replaceAll(literalReplacement); - if (!result.equals("zzz$0zzz")) - failCount++; - - matcher.reset(); - replaceTest = "\\t$\\$"; - literalReplacement = Matcher.quoteReplacement(replaceTest); - result = matcher.replaceAll(literalReplacement); - if (!result.equals("zzz\\t$\\$zzz")) - failCount++; - - // Supplementary character test - pattern = Pattern.compile(toSupplementaries("abc"), flags); - matcher = pattern.matcher(toSupplementaries("zzzabczzz")); - replaceTest = "$0"; - result = matcher.replaceAll(replaceTest); - if (!result.equals(toSupplementaries("zzzabczzz"))) - failCount++; - - matcher.reset(); - literalReplacement = Matcher.quoteReplacement(replaceTest); - result = matcher.replaceAll(literalReplacement); - if (!result.equals(toSupplementaries("zzz$0zzz"))) - failCount++; - - matcher.reset(); - replaceTest = "\\t$\\$"; - literalReplacement = Matcher.quoteReplacement(replaceTest); - result = matcher.replaceAll(literalReplacement); - if (!result.equals(toSupplementaries("zzz\\t$\\$zzz"))) - failCount++; - - // IAE should be thrown if backslash or '$' is the last character - // in replacement string - try { - "\uac00".replaceAll("\uac00", "$"); - failCount++; - } catch (IllegalArgumentException iie) { - } catch (Exception e) { - failCount++; - } - try { - "\uac00".replaceAll("\uac00", "\\"); - failCount++; - } catch (IllegalArgumentException iie) { - } catch (Exception e) { - failCount++; - } - report("Literal replacement"); - } - - // This test is for 4757029 - private static void regionTest() { - Pattern pattern = Pattern.compile("abc"); - Matcher matcher = pattern.matcher("abcdefabc"); - - matcher.region(0, 9); - if (!matcher.find()) - failCount++; - if (!matcher.find()) - failCount++; - matcher.region(0, 3); - if (!matcher.find()) - failCount++; - matcher.region(3, 6); - if (matcher.find()) - failCount++; - matcher.region(0, 2); - if (matcher.find()) - failCount++; - - expectRegionFail(matcher, 1, -1); - expectRegionFail(matcher, -1, -1); - expectRegionFail(matcher, -1, 1); - expectRegionFail(matcher, 5, 3); - expectRegionFail(matcher, 5, 12); - expectRegionFail(matcher, 12, 12); - - pattern = Pattern.compile("^abc$"); - matcher = pattern.matcher("zzzabczzz"); - matcher.region(0, 9); - if (matcher.find()) - failCount++; - matcher.region(3, 6); - if (!matcher.find()) - failCount++; - matcher.region(3, 6); - matcher.useAnchoringBounds(false); - if (matcher.find()) - failCount++; - - // Supplementary character test - pattern = Pattern.compile(toSupplementaries("abc")); - matcher = pattern.matcher(toSupplementaries("abcdefabc")); - matcher.region(0, 9 * 2); - if (!matcher.find()) - failCount++; - if (!matcher.find()) - failCount++; - matcher.region(0, 3 * 2); - if (!matcher.find()) - failCount++; - matcher.region(1, 3 * 2); - if (matcher.find()) - failCount++; - matcher.region(3 * 2, 6 * 2); - if (matcher.find()) - failCount++; - matcher.region(0, 2 * 2); - if (matcher.find()) - failCount++; - matcher.region(0, 2 * 2 + 1); - if (matcher.find()) - failCount++; - - expectRegionFail(matcher, 1 * 2, -1); - expectRegionFail(matcher, -1, -1); - expectRegionFail(matcher, -1, 1 * 2); - expectRegionFail(matcher, 5 * 2, 3 * 2); - expectRegionFail(matcher, 5 * 2, 12 * 2); - expectRegionFail(matcher, 12 * 2, 12 * 2); - - pattern = Pattern.compile(toSupplementaries("^abc$")); - matcher = pattern.matcher(toSupplementaries("zzzabczzz")); - matcher.region(0, 9 * 2); - if (matcher.find()) - failCount++; - matcher.region(3 * 2, 6 * 2); - if (!matcher.find()) - failCount++; - matcher.region(3 * 2 + 1, 6 * 2); - if (matcher.find()) - failCount++; - matcher.region(3 * 2, 6 * 2 - 1); - if (matcher.find()) - failCount++; - matcher.region(3 * 2, 6 * 2); - matcher.useAnchoringBounds(false); - if (matcher.find()) - failCount++; - report("Regions"); - } - - private static void expectRegionFail(Matcher matcher, int index1, - int index2) { - try { - matcher.region(index1, index2); - failCount++; - } catch (IndexOutOfBoundsException | IllegalStateException ioobe) { - // Correct result - } - } - - // This test is for 4803197 - private static void escapedSegmentTest() { - - Pattern pattern = Pattern.compile("\\Qdir1\\dir2\\E"); - check(pattern, "dir1\\dir2", true); - - pattern = Pattern.compile("\\Qdir1\\dir2\\\\E"); - check(pattern, "dir1\\dir2\\", true); - - pattern = Pattern.compile("(\\Qdir1\\dir2\\\\E)"); - check(pattern, "dir1\\dir2\\", true); - - // Supplementary character test - pattern = Pattern.compile(toSupplementaries("\\Qdir1\\dir2\\E")); - check(pattern, toSupplementaries("dir1\\dir2"), true); - - pattern = Pattern.compile(toSupplementaries("\\Qdir1\\dir2") + "\\\\E"); - check(pattern, toSupplementaries("dir1\\dir2\\"), true); - - pattern = Pattern.compile(toSupplementaries("(\\Qdir1\\dir2") + "\\\\E)"); - check(pattern, toSupplementaries("dir1\\dir2\\"), true); - - report("Escaped segment"); - } - - // This test is for 4792284 - private static void nonCaptureRepetitionTest() { - String input = "abcdefgh;"; - - String[] patterns = new String[]{ - "(?:\\w{4})+;", - "(?:\\w{8})*;", - "(?:\\w{2}){2,4};", - "(?:\\w{4}){2,};", // only matches the - ".*?(?:\\w{5})+;", // specified minimum - ".*?(?:\\w{9})*;", // number of reps - OK - "(?:\\w{4})+?;", // lazy repetition - OK - "(?:\\w{4})++;", // possessive repetition - OK - "(?:\\w{2,}?)+;", // non-deterministic - OK - "(\\w{4})+;", // capturing group - OK - }; - - for (int i = 0; i < patterns.length; i++) { - // Check find() - check(patterns[i], 0, input, input, true); - // Check matches() - Pattern p = Pattern.compile(patterns[i]); - Matcher m = p.matcher(input); - - if (m.matches()) { - if (!m.group(0).equals(input)) - failCount++; - } else { - failCount++; - } - } - - report("Non capturing repetition"); - } - - // This test is for 6358731 - private static void notCapturedGroupCurlyMatchTest() { - Pattern pattern = Pattern.compile("(abc)+|(abcd)+"); - Matcher matcher = pattern.matcher("abcd"); - if (!matcher.matches() || - matcher.group(1) != null || - !matcher.group(2).equals("abcd")) { - failCount++; - } - report("Not captured GroupCurly"); - } - - // This test is for 4706545 - private static void javaCharClassTest() { - for (int i = 0; i < 1000; i++) { - char c = (char) generator.nextInt(); - check("{javaLowerCase}", c, Character.isLowerCase(c)); - check("{javaUpperCase}", c, Character.isUpperCase(c)); - check("{javaUpperCase}+", c, Character.isUpperCase(c)); - check("{javaTitleCase}", c, Character.isTitleCase(c)); - check("{javaDigit}", c, Character.isDigit(c)); - check("{javaDefined}", c, Character.isDefined(c)); - check("{javaLetter}", c, Character.isLetter(c)); - check("{javaLetterOrDigit}", c, Character.isLetterOrDigit(c)); - check("{javaJavaIdentifierStart}", c, - Character.isJavaIdentifierStart(c)); - check("{javaJavaIdentifierPart}", c, - Character.isJavaIdentifierPart(c)); - check("{javaUnicodeIdentifierStart}", c, - Character.isUnicodeIdentifierStart(c)); - check("{javaUnicodeIdentifierPart}", c, - Character.isUnicodeIdentifierPart(c)); - check("{javaIdentifierIgnorable}", c, - Character.isIdentifierIgnorable(c)); - check("{javaSpaceChar}", c, Character.isSpaceChar(c)); - check("{javaWhitespace}", c, Character.isWhitespace(c)); - check("{javaISOControl}", c, Character.isISOControl(c)); - check("{javaMirrored}", c, Character.isMirrored(c)); - - } - - // Supplementary character test - for (int i = 0; i < 1000; i++) { - int c = generator.nextInt(Character.MAX_CODE_POINT - - Character.MIN_SUPPLEMENTARY_CODE_POINT) - + Character.MIN_SUPPLEMENTARY_CODE_POINT; - check("{javaLowerCase}", c, Character.isLowerCase(c)); - check("{javaUpperCase}", c, Character.isUpperCase(c)); - check("{javaUpperCase}+", c, Character.isUpperCase(c)); - check("{javaTitleCase}", c, Character.isTitleCase(c)); - check("{javaDigit}", c, Character.isDigit(c)); - check("{javaDefined}", c, Character.isDefined(c)); - check("{javaLetter}", c, Character.isLetter(c)); - check("{javaLetterOrDigit}", c, Character.isLetterOrDigit(c)); - check("{javaJavaIdentifierStart}", c, - Character.isJavaIdentifierStart(c)); - check("{javaJavaIdentifierPart}", c, - Character.isJavaIdentifierPart(c)); - check("{javaUnicodeIdentifierStart}", c, - Character.isUnicodeIdentifierStart(c)); - check("{javaUnicodeIdentifierPart}", c, - Character.isUnicodeIdentifierPart(c)); - check("{javaIdentifierIgnorable}", c, - Character.isIdentifierIgnorable(c)); - check("{javaSpaceChar}", c, Character.isSpaceChar(c)); - check("{javaWhitespace}", c, Character.isWhitespace(c)); - check("{javaISOControl}", c, Character.isISOControl(c)); - check("{javaMirrored}", c, Character.isMirrored(c)); - } - - report("Java character classes"); - } - - // This test is for 4523620 - /* - private static void numOccurrencesTest() throws Exception { - Pattern pattern = Pattern.compile("aaa"); - - if (pattern.numOccurrences("aaaaaa", false) != 2) - failCount++; - if (pattern.numOccurrences("aaaaaa", true) != 4) - failCount++; - - pattern = Pattern.compile("^"); - if (pattern.numOccurrences("aaaaaa", false) != 1) - failCount++; - if (pattern.numOccurrences("aaaaaa", true) != 1) - failCount++; - - report("Number of Occurrences"); - } - */ - - // This test is for 4776374 - private static void caretBetweenTerminatorsTest() { - int flags1 = Pattern.DOTALL; - int flags2 = Pattern.DOTALL | Pattern.UNIX_LINES; - int flags3 = Pattern.DOTALL | Pattern.UNIX_LINES | Pattern.MULTILINE; - int flags4 = Pattern.DOTALL | Pattern.MULTILINE; - - check("^....", flags1, "test\ntest", "test", true); - check(".....^", flags1, "test\ntest", "test", false); - check(".....^", flags1, "test\n", "test", false); - check("....^", flags1, "test\r\n", "test", false); - - check("^....", flags2, "test\ntest", "test", true); - check("....^", flags2, "test\ntest", "test", false); - check(".....^", flags2, "test\n", "test", false); - check("....^", flags2, "test\r\n", "test", false); - - check("^....", flags3, "test\ntest", "test", true); - check(".....^", flags3, "test\ntest", "test\n", true); - check(".....^", flags3, "test\u0085test", "test\u0085", false); - check(".....^", flags3, "test\n", "test", false); - check(".....^", flags3, "test\r\n", "test", false); - check("......^", flags3, "test\r\ntest", "test\r\n", true); - - check("^....", flags4, "test\ntest", "test", true); - check(".....^", flags3, "test\ntest", "test\n", true); - check(".....^", flags4, "test\u0085test", "test\u0085", true); - check(".....^", flags4, "test\n", "test\n", false); - check(".....^", flags4, "test\r\n", "test\r", false); - - // Supplementary character test - String t = toSupplementaries("test"); - check("^....", flags1, t + "\n" + t, t, true); - check(".....^", flags1, t + "\n" + t, t, false); - check(".....^", flags1, t + "\n", t, false); - check("....^", flags1, t + "\r\n", t, false); - - check("^....", flags2, t + "\n" + t, t, true); - check("....^", flags2, t + "\n" + t, t, false); - check(".....^", flags2, t + "\n", t, false); - check("....^", flags2, t + "\r\n", t, false); - - check("^....", flags3, t + "\n" + t, t, true); - check(".....^", flags3, t + "\n" + t, t + "\n", true); - check(".....^", flags3, t + "\u0085" + t, t + "\u0085", false); - check(".....^", flags3, t + "\n", t, false); - check(".....^", flags3, t + "\r\n", t, false); - check("......^", flags3, t + "\r\n" + t, t + "\r\n", true); - - check("^....", flags4, t + "\n" + t, t, true); - check(".....^", flags3, t + "\n" + t, t + "\n", true); - check(".....^", flags4, t + "\u0085" + t, t + "\u0085", true); - check(".....^", flags4, t + "\n", t + "\n", false); - check(".....^", flags4, t + "\r\n", t + "\r", false); - - report("Caret between terminators"); - } - - // This test is for 4727935 - private static void dollarAtEndTest() { - int flags1 = Pattern.DOTALL; - int flags2 = Pattern.DOTALL | Pattern.UNIX_LINES; - int flags3 = Pattern.DOTALL | Pattern.MULTILINE; - - check("....$", flags1, "test\n", "test", true); - check("....$", flags1, "test\r\n", "test", true); - check(".....$", flags1, "test\n", "test\n", true); - check(".....$", flags1, "test\u0085", "test\u0085", true); - check("....$", flags1, "test\u0085", "test", true); - - check("....$", flags2, "test\n", "test", true); - check(".....$", flags2, "test\n", "test\n", true); - check(".....$", flags2, "test\u0085", "test\u0085", true); - check("....$", flags2, "test\u0085", "est\u0085", true); - - check("....$.blah", flags3, "test\nblah", "test\nblah", true); - check(".....$.blah", flags3, "test\n\nblah", "test\n\nblah", true); - check("....$blah", flags3, "test\nblah", "!!!!", false); - check(".....$blah", flags3, "test\nblah", "!!!!", false); - - // Supplementary character test - String t = toSupplementaries("test"); - String b = toSupplementaries("blah"); - check("....$", flags1, t + "\n", t, true); - check("....$", flags1, t + "\r\n", t, true); - check(".....$", flags1, t + "\n", t + "\n", true); - check(".....$", flags1, t + "\u0085", t + "\u0085", true); - check("....$", flags1, t + "\u0085", t, true); - - check("....$", flags2, t + "\n", t, true); - check(".....$", flags2, t + "\n", t + "\n", true); - check(".....$", flags2, t + "\u0085", t + "\u0085", true); - check("....$", flags2, t + "\u0085", toSupplementaries("est\u0085"), true); - - check("....$." + b, flags3, t + "\n" + b, t + "\n" + b, true); - check(".....$." + b, flags3, t + "\n\n" + b, t + "\n\n" + b, true); - check("....$" + b, flags3, t + "\n" + b, "!!!!", false); - check(".....$" + b, flags3, t + "\n" + b, "!!!!", false); - - report("Dollar at End"); - } - - // This test is for 4711773 - private static void multilineDollarTest() { - Pattern findCR = Pattern.compile("$", Pattern.MULTILINE); - Matcher matcher = findCR.matcher("first bit\nsecond bit"); - matcher.find(); - if (matcher.start(0) != 9) - failCount++; - matcher.find(); - if (matcher.start(0) != 20) - failCount++; - - // Supplementary character test - matcher = findCR.matcher(toSupplementaries("first bit\n second bit")); // double BMP chars - matcher.find(); - if (matcher.start(0) != 9 * 2) - failCount++; - matcher.find(); - if (matcher.start(0) != 20 * 2) - failCount++; - - report("Multiline Dollar"); - } - - private static void reluctantRepetitionTest() { - Pattern p = Pattern.compile("1(\\s\\S+?){1,3}?[\\s,]2"); - check(p, "1 word word word 2", true); - check(p, "1 wor wo w 2", true); - check(p, "1 word word 2", true); - check(p, "1 word 2", true); - check(p, "1 wo w w 2", true); - check(p, "1 wo w 2", true); - check(p, "1 wor w 2", true); - - p = Pattern.compile("([a-z])+?c"); - Matcher m = p.matcher("ababcdefdec"); - check(m, "ababc"); - - // Supplementary character test - p = Pattern.compile(toSupplementaries("([a-z])+?c")); - m = p.matcher(toSupplementaries("ababcdefdec")); - check(m, toSupplementaries("ababc")); - - report("Reluctant Repetition"); - } - - private static void serializeTest() throws Exception { - String patternStr = "(b)"; - String matchStr = "b"; - Pattern pattern = Pattern.compile(patternStr); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); - oos.writeObject(pattern); - oos.close(); - ObjectInputStream ois = new ObjectInputStream( - new ByteArrayInputStream(baos.toByteArray())); - Pattern serializedPattern = (Pattern) ois.readObject(); - ois.close(); - Matcher matcher = serializedPattern.matcher(matchStr); - if (!matcher.matches()) - failCount++; - if (matcher.groupCount() != 1) - failCount++; - - report("Serialization"); - } - - private static void gTest() { - Pattern pattern = Pattern.compile("\\G\\w"); - Matcher matcher = pattern.matcher("abc#x#x"); - matcher.find(); - matcher.find(); - matcher.find(); - if (matcher.find()) - failCount++; - - pattern = Pattern.compile("\\GA*"); - matcher = pattern.matcher("1A2AA3"); - matcher.find(); - if (matcher.find()) - failCount++; - - pattern = Pattern.compile("\\GA*"); - matcher = pattern.matcher("1A2AA3"); - if (!matcher.find(1)) - failCount++; - matcher.find(); - if (matcher.find()) - failCount++; - - report("\\G"); - } - - private static void zTest() { - Pattern pattern = Pattern.compile("foo\\Z"); - // Positives - check(pattern, "foo\u0085", true); - check(pattern, "foo\u2028", true); - check(pattern, "foo\u2029", true); - check(pattern, "foo\n", true); - check(pattern, "foo\r", true); - check(pattern, "foo\r\n", true); - // Negatives - check(pattern, "fooo", false); - check(pattern, "foo\n\r", false); - - pattern = Pattern.compile("foo\\Z", Pattern.UNIX_LINES); - // Positives - check(pattern, "foo", true); - check(pattern, "foo\n", true); - // Negatives - check(pattern, "foo\r", false); - check(pattern, "foo\u0085", false); - check(pattern, "foo\u2028", false); - check(pattern, "foo\u2029", false); - - report("\\Z"); - } - - private static void replaceFirstTest() { - Pattern pattern = Pattern.compile("(ab)(c*)"); - Matcher matcher = pattern.matcher("abccczzzabcczzzabccc"); - if (!matcher.replaceFirst("test").equals("testzzzabcczzzabccc")) - failCount++; - - matcher.reset("zzzabccczzzabcczzzabccczzz"); - if (!matcher.replaceFirst("test").equals("zzztestzzzabcczzzabccczzz")) - failCount++; - - matcher.reset("zzzabccczzzabcczzzabccczzz"); - String result = matcher.replaceFirst("$1"); - if (!result.equals("zzzabzzzabcczzzabccczzz")) - failCount++; - - matcher.reset("zzzabccczzzabcczzzabccczzz"); - result = matcher.replaceFirst("$2"); - if (!result.equals("zzzccczzzabcczzzabccczzz")) - failCount++; - - pattern = Pattern.compile("a*"); - matcher = pattern.matcher("aaaaaaaaaa"); - if (!matcher.replaceFirst("test").equals("test")) - failCount++; - - pattern = Pattern.compile("a+"); - matcher = pattern.matcher("zzzaaaaaaaaaa"); - if (!matcher.replaceFirst("test").equals("zzztest")) - failCount++; - - // Supplementary character test - pattern = Pattern.compile(toSupplementaries("(ab)(c*)")); - matcher = pattern.matcher(toSupplementaries("abccczzzabcczzzabccc")); - if (!matcher.replaceFirst(toSupplementaries("test")) - .equals(toSupplementaries("testzzzabcczzzabccc"))) - failCount++; - - matcher.reset(toSupplementaries("zzzabccczzzabcczzzabccczzz")); - if (!matcher.replaceFirst(toSupplementaries("test")). - equals(toSupplementaries("zzztestzzzabcczzzabccczzz"))) - failCount++; - - matcher.reset(toSupplementaries("zzzabccczzzabcczzzabccczzz")); - result = matcher.replaceFirst("$1"); - if (!result.equals(toSupplementaries("zzzabzzzabcczzzabccczzz"))) - failCount++; - - matcher.reset(toSupplementaries("zzzabccczzzabcczzzabccczzz")); - result = matcher.replaceFirst("$2"); - if (!result.equals(toSupplementaries("zzzccczzzabcczzzabccczzz"))) - failCount++; - - pattern = Pattern.compile(toSupplementaries("a*")); - matcher = pattern.matcher(toSupplementaries("aaaaaaaaaa")); - if (!matcher.replaceFirst(toSupplementaries("test")).equals(toSupplementaries("test"))) - failCount++; - - pattern = Pattern.compile(toSupplementaries("a+")); - matcher = pattern.matcher(toSupplementaries("zzzaaaaaaaaaa")); - if (!matcher.replaceFirst(toSupplementaries("test")).equals(toSupplementaries("zzztest"))) - failCount++; - - report("Replace First"); - } - - private static void unixLinesTest() { - Pattern pattern = Pattern.compile(".*"); - Matcher matcher = pattern.matcher("aa\u2028blah"); - matcher.find(); - if (!matcher.group(0).equals("aa")) - failCount++; - - pattern = Pattern.compile(".*", Pattern.UNIX_LINES); - matcher = pattern.matcher("aa\u2028blah"); - matcher.find(); - if (!matcher.group(0).equals("aa\u2028blah")) - failCount++; - - pattern = Pattern.compile("[az]$", - Pattern.MULTILINE | Pattern.UNIX_LINES); - matcher = pattern.matcher("aa\u2028zz"); - check(matcher, "a\u2028", false); - - // Supplementary character test - pattern = Pattern.compile(".*"); - matcher = pattern.matcher(toSupplementaries("aa\u2028blah")); - matcher.find(); - if (!matcher.group(0).equals(toSupplementaries("aa"))) - failCount++; - - pattern = Pattern.compile(".*", Pattern.UNIX_LINES); - matcher = pattern.matcher(toSupplementaries("aa\u2028blah")); - matcher.find(); - if (!matcher.group(0).equals(toSupplementaries("aa\u2028blah"))) - failCount++; - - pattern = Pattern.compile(toSupplementaries("[az]$"), - Pattern.MULTILINE | Pattern.UNIX_LINES); - matcher = pattern.matcher(toSupplementaries("aa\u2028zz")); - check(matcher, toSupplementaries("a\u2028"), false); - - report("Unix Lines"); - } - - private static void commentsTest() { - int flags = Pattern.COMMENTS; - - Pattern pattern = Pattern.compile("aa \\# aa", flags); - Matcher matcher = pattern.matcher("aa#aa"); - if (!matcher.matches()) - failCount++; - - pattern = Pattern.compile("aa # blah", flags); - matcher = pattern.matcher("aa"); - if (!matcher.matches()) - failCount++; - - pattern = Pattern.compile("aa blah", flags); - matcher = pattern.matcher("aablah"); - if (!matcher.matches()) - failCount++; - - pattern = Pattern.compile("aa # blah blech ", flags); - matcher = pattern.matcher("aa"); - if (!matcher.matches()) - failCount++; - - pattern = Pattern.compile("aa # blah\n ", flags); - matcher = pattern.matcher("aa"); - if (!matcher.matches()) - failCount++; - - pattern = Pattern.compile("aa # blah\nbc # blech", flags); - matcher = pattern.matcher("aabc"); - if (!matcher.matches()) - failCount++; - - pattern = Pattern.compile("aa # blah\nbc# blech", flags); - matcher = pattern.matcher("aabc"); - if (!matcher.matches()) - failCount++; - - pattern = Pattern.compile("aa # blah\nbc\\# blech", flags); - matcher = pattern.matcher("aabc#blech"); - if (!matcher.matches()) - failCount++; - - // Supplementary character test - pattern = Pattern.compile(toSupplementaries("aa \\# aa"), flags); - matcher = pattern.matcher(toSupplementaries("aa#aa")); - if (!matcher.matches()) - failCount++; - - pattern = Pattern.compile(toSupplementaries("aa # blah"), flags); - matcher = pattern.matcher(toSupplementaries("aa")); - if (!matcher.matches()) - failCount++; - - pattern = Pattern.compile(toSupplementaries("aa blah"), flags); - matcher = pattern.matcher(toSupplementaries("aablah")); - if (!matcher.matches()) - failCount++; - - pattern = Pattern.compile(toSupplementaries("aa # blah blech "), flags); - matcher = pattern.matcher(toSupplementaries("aa")); - if (!matcher.matches()) - failCount++; - - pattern = Pattern.compile(toSupplementaries("aa # blah\n "), flags); - matcher = pattern.matcher(toSupplementaries("aa")); - if (!matcher.matches()) - failCount++; - - pattern = Pattern.compile(toSupplementaries("aa # blah\nbc # blech"), flags); - matcher = pattern.matcher(toSupplementaries("aabc")); - if (!matcher.matches()) - failCount++; - - pattern = Pattern.compile(toSupplementaries("aa # blah\nbc# blech"), flags); - matcher = pattern.matcher(toSupplementaries("aabc")); - if (!matcher.matches()) - failCount++; - - pattern = Pattern.compile(toSupplementaries("aa # blah\nbc\\# blech"), flags); - matcher = pattern.matcher(toSupplementaries("aabc#blech")); - if (!matcher.matches()) - failCount++; - - report("Comments"); - } - - private static void caseFoldingTest() { // bug 4504687 - int flags = Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE; - Pattern pattern = Pattern.compile("aa", flags); - Matcher matcher = pattern.matcher("ab"); - if (matcher.matches()) - failCount++; - - pattern = Pattern.compile("aA", flags); - matcher = pattern.matcher("ab"); - if (matcher.matches()) - failCount++; - - pattern = Pattern.compile("aa", flags); - matcher = pattern.matcher("aB"); - if (matcher.matches()) - failCount++; - matcher = pattern.matcher("Ab"); - if (matcher.matches()) - failCount++; - - // ASCII "a" - // Latin-1 Supplement "a" + grave - // Cyrillic "a" - String[] patterns = new String[]{ - //single - "a", "\u00e0", "\u0430", - //slice - "ab", "\u00e0\u00e1", "\u0430\u0431", - //class single - "[a]", "[\u00e0]", "[\u0430]", - //class range - "[a-b]", "[\u00e0-\u00e5]", "[\u0430-\u0431]", - //back reference - "(a)\\1", "(\u00e0)\\1", "(\u0430)\\1" - }; - - String[] texts = new String[]{ - "A", "\u00c0", "\u0410", - "AB", "\u00c0\u00c1", "\u0410\u0411", - "A", "\u00c0", "\u0410", - "B", "\u00c2", "\u0411", - "aA", "\u00e0\u00c0", "\u0430\u0410" - }; - - boolean[] expected = new boolean[]{ - true, false, false, - true, false, false, - true, false, false, - true, false, false, - true, false, false - }; - - flags = Pattern.CASE_INSENSITIVE; - for (int i = 0; i < patterns.length; i++) { - pattern = Pattern.compile(patterns[i], flags); - matcher = pattern.matcher(texts[i]); - if (matcher.matches() != expected[i]) { - System.out.println("<1> Failed at " + i); - failCount++; - } - } - - flags = Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE; - for (int i = 0; i < patterns.length; i++) { - pattern = Pattern.compile(patterns[i], flags); - matcher = pattern.matcher(texts[i]); - if (!matcher.matches()) { - System.out.println("<2> Failed at " + i); - failCount++; - } - } - // flag unicode_case alone should do nothing - flags = Pattern.UNICODE_CASE; - for (int i = 0; i < patterns.length; i++) { - pattern = Pattern.compile(patterns[i], flags); - matcher = pattern.matcher(texts[i]); - if (matcher.matches()) { - System.out.println("<3> Failed at " + i); - failCount++; - } - } - - // Special cases: i, I, u+0131 and u+0130 - flags = Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE; - pattern = Pattern.compile("[h-j]+", flags); - if (!pattern.matcher("\u0131\u0130").matches()) - failCount++; - report("Case Folding"); - } - - private static void appendTest() { - Pattern pattern = Pattern.compile("(ab)(cd)"); - Matcher matcher = pattern.matcher("abcd"); - String result = matcher.replaceAll("$2$1"); - if (!result.equals("cdab")) - failCount++; - - String s1 = "Swap all: first = 123, second = 456"; - String s2 = "Swap one: first = 123, second = 456"; - String r = "$3$2$1"; - pattern = Pattern.compile("([a-z]+)( *= *)([0-9]+)"); - matcher = pattern.matcher(s1); - - result = matcher.replaceAll(r); - if (!result.equals("Swap all: 123 = first, 456 = second")) - failCount++; - - matcher = pattern.matcher(s2); - - if (matcher.find()) { - StringBuffer sb = new StringBuffer(); - matcher.appendReplacement(sb, r); - matcher.appendTail(sb); - result = sb.toString(); - if (!result.equals("Swap one: 123 = first, second = 456")) - failCount++; - } - - // Supplementary character test - pattern = Pattern.compile(toSupplementaries("(ab)(cd)")); - matcher = pattern.matcher(toSupplementaries("abcd")); - result = matcher.replaceAll("$2$1"); - if (!result.equals(toSupplementaries("cdab"))) - failCount++; - - s1 = toSupplementaries("Swap all: first = 123, second = 456"); - s2 = toSupplementaries("Swap one: first = 123, second = 456"); - r = toSupplementaries("$3$2$1"); - pattern = Pattern.compile(toSupplementaries("([a-z]+)( *= *)([0-9]+)")); - matcher = pattern.matcher(s1); - - result = matcher.replaceAll(r); - if (!result.equals(toSupplementaries("Swap all: 123 = first, 456 = second"))) - failCount++; - - matcher = pattern.matcher(s2); - - if (matcher.find()) { - StringBuffer sb = new StringBuffer(); - matcher.appendReplacement(sb, r); - matcher.appendTail(sb); - result = sb.toString(); - if (!result.equals(toSupplementaries("Swap one: 123 = first, second = 456"))) - failCount++; - } - report("Append"); - } - - - private static void negationTest() { - Pattern pattern = Pattern.compile("[\\[@^]+"); - Matcher matcher = pattern.matcher("@@@@[[[[^^^^"); - if (!matcher.find()) - failCount++; - if (!matcher.group(0).equals("@@@@[[[[^^^^")) - failCount++; - pattern = Pattern.compile("[@\\[^]+"); - matcher = pattern.matcher("@@@@[[[[^^^^"); - if (!matcher.find()) - failCount++; - if (!matcher.group(0).equals("@@@@[[[[^^^^")) - failCount++; - pattern = Pattern.compile("[@\\[^@]+"); - matcher = pattern.matcher("@@@@[[[[^^^^"); - if (!matcher.find()) - failCount++; - if (!matcher.group(0).equals("@@@@[[[[^^^^")) - failCount++; - - pattern = Pattern.compile("\\)"); - matcher = pattern.matcher("xxx)xxx"); - if (!matcher.find()) - failCount++; - - report("Negation"); - } - - private static void ampersandTest() { - Pattern pattern = Pattern.compile("[&@]+"); - check(pattern, "@@@@&&&&", true); - - pattern = Pattern.compile("[@&]+"); - check(pattern, "@@@@&&&&", true); - - pattern = Pattern.compile("[@\\&]+"); - check(pattern, "@@@@&&&&", true); - - report("Ampersand"); - } - - private static void octalTest() { - Pattern pattern = Pattern.compile("\\u0007"); - Matcher matcher = pattern.matcher("\u0007"); - if (!matcher.matches()) - failCount++; - pattern = Pattern.compile("\\07"); - matcher = pattern.matcher("\u0007"); - if (!matcher.matches()) - failCount++; - pattern = Pattern.compile("\\007"); - matcher = pattern.matcher("\u0007"); - if (!matcher.matches()) - failCount++; - pattern = Pattern.compile("\\0007"); - matcher = pattern.matcher("\u0007"); - if (!matcher.matches()) - failCount++; - pattern = Pattern.compile("\\040"); - matcher = pattern.matcher("\u0020"); - if (!matcher.matches()) - failCount++; - pattern = Pattern.compile("\\0403"); - matcher = pattern.matcher("\u00203"); - if (!matcher.matches()) - failCount++; - pattern = Pattern.compile("\\0103"); - matcher = pattern.matcher("\u0043"); - if (!matcher.matches()) - failCount++; - - report("Octal"); - } - - private static void longPatternTest() { - try { - Pattern pattern = Pattern.compile( - "a 32-character-long pattern xxxx"); - pattern = Pattern.compile("a 33-character-long pattern xxxxx"); - pattern = Pattern.compile("a thirty four character long regex"); - StringBuilder patternToBe = new StringBuilder(101); - for (int i = 0; i < 100; i++) - patternToBe.append((char) (97 + i % 26)); - pattern = Pattern.compile(patternToBe.toString()); - } catch (PatternSyntaxException e) { - failCount++; - } - - // Supplementary character test - try { - Pattern pattern = Pattern.compile( - toSupplementaries("a 32-character-long pattern xxxx")); - pattern = Pattern.compile(toSupplementaries("a 33-character-long pattern xxxxx")); - pattern = Pattern.compile(toSupplementaries("a thirty four character long regex")); - StringBuilder patternToBe = new StringBuilder(101 * 2); - for (int i = 0; i < 100; i++) - patternToBe.append(Character.toChars(Character.MIN_SUPPLEMENTARY_CODE_POINT - + 97 + i % 26)); - pattern = Pattern.compile(patternToBe.toString()); - } catch (PatternSyntaxException e) { - failCount++; - } - report("LongPattern"); - } - - private static void group0Test() { - Pattern pattern = Pattern.compile("(tes)ting"); - Matcher matcher = pattern.matcher("testing"); - check(matcher, "testing"); - - matcher.reset("testing"); - if (matcher.lookingAt()) { - if (!matcher.group(0).equals("testing")) - failCount++; - } else { - failCount++; - } - - matcher.reset("testing"); - if (matcher.matches()) { - if (!matcher.group(0).equals("testing")) - failCount++; - } else { - failCount++; - } - - pattern = Pattern.compile("(tes)ting"); - matcher = pattern.matcher("testing"); - if (matcher.lookingAt()) { - if (!matcher.group(0).equals("testing")) - failCount++; - } else { - failCount++; - } - - pattern = Pattern.compile("^(tes)ting"); - matcher = pattern.matcher("testing"); - if (matcher.matches()) { - if (!matcher.group(0).equals("testing")) - failCount++; - } else { - failCount++; - } - - // Supplementary character test - pattern = Pattern.compile(toSupplementaries("(tes)ting")); - matcher = pattern.matcher(toSupplementaries("testing")); - check(matcher, toSupplementaries("testing")); - - matcher.reset(toSupplementaries("testing")); - if (matcher.lookingAt()) { - if (!matcher.group(0).equals(toSupplementaries("testing"))) - failCount++; - } else { - failCount++; - } - - matcher.reset(toSupplementaries("testing")); - if (matcher.matches()) { - if (!matcher.group(0).equals(toSupplementaries("testing"))) - failCount++; - } else { - failCount++; - } - - pattern = Pattern.compile(toSupplementaries("(tes)ting")); - matcher = pattern.matcher(toSupplementaries("testing")); - if (matcher.lookingAt()) { - if (!matcher.group(0).equals(toSupplementaries("testing"))) - failCount++; - } else { - failCount++; - } - - pattern = Pattern.compile(toSupplementaries("^(tes)ting")); - matcher = pattern.matcher(toSupplementaries("testing")); - if (matcher.matches()) { - if (!matcher.group(0).equals(toSupplementaries("testing"))) - failCount++; - } else { - failCount++; - } - - report("Group0"); - } - - private static void findIntTest() { - Pattern p = Pattern.compile("blah"); - Matcher m = p.matcher("zzzzblahzzzzzblah"); - boolean result = m.find(2); - if (!result) - failCount++; - - p = Pattern.compile("$"); - m = p.matcher("1234567890"); - result = m.find(10); - if (!result) - failCount++; - try { - result = m.find(11); - failCount++; - } catch (IndexOutOfBoundsException e) { - // correct result - } - - // Supplementary character test - p = Pattern.compile(toSupplementaries("blah")); - m = p.matcher(toSupplementaries("zzzzblahzzzzzblah")); - result = m.find(2); - if (!result) - failCount++; - - report("FindInt"); - } - - private static void emptyPatternTest() { - Pattern p = Pattern.compile(""); - Matcher m = p.matcher("foo"); - - // Should find empty pattern at beginning of input - boolean result = m.find(); - if (!result) - failCount++; - if (m.start() != 0) - failCount++; - - // Should not match entire input if input is not empty - m.reset(); - result = m.matches(); - if (result) - failCount++; - - try { - m.start(0); - failCount++; - } catch (IllegalStateException e) { - // Correct result - } - - // Should match entire input if input is empty - m.reset(""); - result = m.matches(); - if (!result) - failCount++; - - result = Pattern.matches("", ""); - if (!result) - failCount++; - - result = Pattern.matches("", "foo"); - if (result) - failCount++; - report("EmptyPattern"); - } - - private static void charClassTest() { - Pattern pattern = Pattern.compile("blah[ab]]blech"); - check(pattern, "blahb]blech", true); - - pattern = Pattern.compile("[abc[def]]"); - check(pattern, "b", true); - - // Supplementary character tests - pattern = Pattern.compile(toSupplementaries("blah[ab]]blech")); - check(pattern, toSupplementaries("blahb]blech"), true); - - pattern = Pattern.compile(toSupplementaries("[abc[def]]")); - check(pattern, toSupplementaries("b"), true); - - try { - // u00ff when UNICODE_CASE - pattern = Pattern.compile("[ab\u00ffcd]", - Pattern.CASE_INSENSITIVE | - Pattern.UNICODE_CASE); - check(pattern, "ab\u00ffcd", true); - check(pattern, "Ab\u0178Cd", true); - - // u00b5 when UNICODE_CASE - pattern = Pattern.compile("[ab\u00b5cd]", - Pattern.CASE_INSENSITIVE | - Pattern.UNICODE_CASE); - check(pattern, "ab\u00b5cd", true); - check(pattern, "Ab\u039cCd", true); - } catch (Exception e) { - failCount++; - } - - /* Special cases - (1)LatinSmallLetterLongS u+017f - (2)LatinSmallLetterDotlessI u+0131 - (3)LatineCapitalLetterIWithDotAbove u+0130 - (4)KelvinSign u+212a - (5)AngstromSign u+212b - */ - int flags = Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE; - pattern = Pattern.compile("[sik\u00c5]+", flags); - if (!pattern.matcher("\u017f\u0130\u0131\u212a\u212b").matches()) - failCount++; - - report("CharClass"); - } - - private static void caretTest() { - Pattern pattern = Pattern.compile("\\w*"); - Matcher matcher = pattern.matcher("a#bc#def##g"); - check(matcher, "a"); - check(matcher, ""); - check(matcher, "bc"); - check(matcher, ""); - check(matcher, "def"); - check(matcher, ""); - check(matcher, ""); - check(matcher, "g"); - check(matcher, ""); - if (matcher.find()) - failCount++; - - pattern = Pattern.compile("^\\w*"); - matcher = pattern.matcher("a#bc#def##g"); - check(matcher, "a"); - if (matcher.find()) - failCount++; - - pattern = Pattern.compile("\\w"); - matcher = pattern.matcher("abc##x"); - check(matcher, "a"); - check(matcher, "b"); - check(matcher, "c"); - check(matcher, "x"); - if (matcher.find()) - failCount++; - - pattern = Pattern.compile("^\\w"); - matcher = pattern.matcher("abc##x"); - check(matcher, "a"); - if (matcher.find()) - failCount++; - - pattern = Pattern.compile("\\A\\p{Alpha}{3}"); - matcher = pattern.matcher("abcdef-ghi\njklmno"); - check(matcher, "abc"); - if (matcher.find()) - failCount++; - - pattern = Pattern.compile("^\\p{Alpha}{3}", Pattern.MULTILINE); - matcher = pattern.matcher("abcdef-ghi\njklmno"); - check(matcher, "abc"); - check(matcher, "jkl"); - if (matcher.find()) - failCount++; - - pattern = Pattern.compile("^", Pattern.MULTILINE); - matcher = pattern.matcher("this is some text"); - String result = matcher.replaceAll("X"); - if (!result.equals("Xthis is some text")) - failCount++; - - pattern = Pattern.compile("^"); - matcher = pattern.matcher("this is some text"); - result = matcher.replaceAll("X"); - if (!result.equals("Xthis is some text")) - failCount++; - - pattern = Pattern.compile("^", Pattern.MULTILINE | Pattern.UNIX_LINES); - matcher = pattern.matcher("this is some text\n"); - result = matcher.replaceAll("X"); - if (!result.equals("Xthis is some text\n")) - failCount++; - - report("Caret"); - } - - private static void groupCaptureTest() { - // Independent group - Pattern pattern = Pattern.compile("x+(?>y+)z+"); - Matcher matcher = pattern.matcher("xxxyyyzzz"); - matcher.find(); - try { - String blah = matcher.group(1); - failCount++; - } catch (IndexOutOfBoundsException ioobe) { - // Good result - } - // Pure group - pattern = Pattern.compile("x+(?:y+)z+"); - matcher = pattern.matcher("xxxyyyzzz"); - matcher.find(); - try { - String blah = matcher.group(1); - failCount++; - } catch (IndexOutOfBoundsException ioobe) { - // Good result - } - - // Supplementary character tests - // Independent group - pattern = Pattern.compile(toSupplementaries("x+(?>y+)z+")); - matcher = pattern.matcher(toSupplementaries("xxxyyyzzz")); - matcher.find(); - try { - String blah = matcher.group(1); - failCount++; - } catch (IndexOutOfBoundsException ioobe) { - // Good result - } - // Pure group - pattern = Pattern.compile(toSupplementaries("x+(?:y+)z+")); - matcher = pattern.matcher(toSupplementaries("xxxyyyzzz")); - matcher.find(); - try { - String blah = matcher.group(1); - failCount++; - } catch (IndexOutOfBoundsException ioobe) { - // Good result - } - - report("GroupCapture"); - } - - private static void backRefTest() { - Pattern pattern = Pattern.compile("(a*)bc\\1"); - check(pattern, "zzzaabcazzz", true); - - pattern = Pattern.compile("(a*)bc\\1"); - check(pattern, "zzzaabcaazzz", true); - - pattern = Pattern.compile("(abc)(def)\\1"); - check(pattern, "abcdefabc", true); - - pattern = Pattern.compile("(abc)(def)\\3"); - check(pattern, "abcdefabc", false); - - try { - for (int i = 1; i < 10; i++) { - // Make sure backref 1-9 are always accepted - pattern = Pattern.compile("abcdef\\" + i); - // and fail to match if the target group does not exit - check(pattern, "abcdef", false); - } - } catch (PatternSyntaxException e) { - failCount++; - } - - pattern = Pattern.compile("(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)\\11"); - check(pattern, "abcdefghija", false); - check(pattern, "abcdefghija1", true); - - pattern = Pattern.compile("(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)\\11"); - check(pattern, "abcdefghijkk", true); - - pattern = Pattern.compile("(a)bcdefghij\\11"); - check(pattern, "abcdefghija1", true); - - // Supplementary character tests - pattern = Pattern.compile(toSupplementaries("(a*)bc\\1")); - check(pattern, toSupplementaries("zzzaabcazzz"), true); - - pattern = Pattern.compile(toSupplementaries("(a*)bc\\1")); - check(pattern, toSupplementaries("zzzaabcaazzz"), true); - - pattern = Pattern.compile(toSupplementaries("(abc)(def)\\1")); - check(pattern, toSupplementaries("abcdefabc"), true); - - pattern = Pattern.compile(toSupplementaries("(abc)(def)\\3")); - check(pattern, toSupplementaries("abcdefabc"), false); - - pattern = Pattern.compile(toSupplementaries("(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)\\11")); - check(pattern, toSupplementaries("abcdefghija"), false); - check(pattern, toSupplementaries("abcdefghija1"), true); - - pattern = Pattern.compile(toSupplementaries("(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)\\11")); - check(pattern, toSupplementaries("abcdefghijkk"), true); - - report("BackRef"); - } - - /** - * Unicode Technical Report #18, section 2.6 End of Line - * There is no empty line to be matched in the sequence \u000D\u000A - * but there is an empty line in the sequence \u000A\u000D. - */ - private static void anchorTest() { - Pattern p = Pattern.compile("^.*$", Pattern.MULTILINE); - Matcher m = p.matcher("blah1\r\nblah2"); - m.find(); - m.find(); - if (!m.group().equals("blah2")) - failCount++; - - m.reset("blah1\n\rblah2"); - m.find(); - m.find(); - m.find(); - if (!m.group().equals("blah2")) - failCount++; - - // Test behavior of $ with \r\n at end of input - p = Pattern.compile(".+$"); - m = p.matcher("blah1\r\n"); - if (!m.find()) - failCount++; - if (!m.group().equals("blah1")) - failCount++; - if (m.find()) - failCount++; - - // Test behavior of $ with \r\n at end of input in multiline - p = Pattern.compile(".+$", Pattern.MULTILINE); - m = p.matcher("blah1\r\n"); - if (!m.find()) - failCount++; - if (m.find()) - failCount++; - - // Test for $ recognition of \u0085 for bug 4527731 - p = Pattern.compile(".+$", Pattern.MULTILINE); - m = p.matcher("blah1\u0085"); - if (!m.find()) - failCount++; - - // Supplementary character test - p = Pattern.compile("^.*$", Pattern.MULTILINE); - m = p.matcher(toSupplementaries("blah1\r\nblah2")); - m.find(); - m.find(); - if (!m.group().equals(toSupplementaries("blah2"))) - failCount++; - - m.reset(toSupplementaries("blah1\n\rblah2")); - m.find(); - m.find(); - m.find(); - if (!m.group().equals(toSupplementaries("blah2"))) - failCount++; - - // Test behavior of $ with \r\n at end of input - p = Pattern.compile(".+$"); - m = p.matcher(toSupplementaries("blah1\r\n")); - if (!m.find()) - failCount++; - if (!m.group().equals(toSupplementaries("blah1"))) - failCount++; - if (m.find()) - failCount++; - - // Test behavior of $ with \r\n at end of input in multiline - p = Pattern.compile(".+$", Pattern.MULTILINE); - m = p.matcher(toSupplementaries("blah1\r\n")); - if (!m.find()) - failCount++; - if (m.find()) - failCount++; - - // Test for $ recognition of \u0085 for bug 4527731 - p = Pattern.compile(".+$", Pattern.MULTILINE); - m = p.matcher(toSupplementaries("blah1\u0085")); - if (!m.find()) - failCount++; - - report("Anchors"); - } - - /** - * A basic sanity test of Matcher.lookingAt(). - */ - private static void lookingAtTest() { - Pattern p = Pattern.compile("(ab)(c*)"); - Matcher m = p.matcher("abccczzzabcczzzabccc"); - - if (!m.lookingAt()) - failCount++; - - if (!m.group().equals(m.group(0))) - failCount++; - - m = p.matcher("zzzabccczzzabcczzzabccczzz"); - if (m.lookingAt()) - failCount++; - - // Supplementary character test - p = Pattern.compile(toSupplementaries("(ab)(c*)")); - m = p.matcher(toSupplementaries("abccczzzabcczzzabccc")); - - if (!m.lookingAt()) - failCount++; - - if (!m.group().equals(m.group(0))) - failCount++; - - m = p.matcher(toSupplementaries("zzzabccczzzabcczzzabccczzz")); - if (m.lookingAt()) - failCount++; - - report("Looking At"); - } - - /** - * A basic sanity test of Matcher.matches(). - */ - private static void matchesTest() { - // matches() - Pattern p = Pattern.compile("ulb(c*)"); - Matcher m = p.matcher("ulbcccccc"); - if (!m.matches()) - failCount++; - - // find() but not matches() - m.reset("zzzulbcccccc"); - if (m.matches()) - failCount++; - - // lookingAt() but not matches() - m.reset("ulbccccccdef"); - if (m.matches()) - failCount++; - - // matches() - p = Pattern.compile("a|ad"); - m = p.matcher("ad"); - if (!m.matches()) - failCount++; - - // Supplementary character test - // matches() - p = Pattern.compile(toSupplementaries("ulb(c*)")); - m = p.matcher(toSupplementaries("ulbcccccc")); - if (!m.matches()) - failCount++; - - // find() but not matches() - m.reset(toSupplementaries("zzzulbcccccc")); - if (m.matches()) - failCount++; - - // lookingAt() but not matches() - m.reset(toSupplementaries("ulbccccccdef")); - if (m.matches()) - failCount++; - - // matches() - p = Pattern.compile(toSupplementaries("a|ad")); - m = p.matcher(toSupplementaries("ad")); - if (!m.matches()) - failCount++; - - report("Matches"); - } - - /** - * A basic sanity test of Pattern.matches(). - */ - private static void patternMatchesTest() { - // matches() - if (!Pattern.matches(toSupplementaries("ulb(c*)"), - toSupplementaries("ulbcccccc"))) - failCount++; - - // find() but not matches() - if (Pattern.matches(toSupplementaries("ulb(c*)"), - toSupplementaries("zzzulbcccccc"))) - failCount++; - - // lookingAt() but not matches() - if (Pattern.matches(toSupplementaries("ulb(c*)"), - toSupplementaries("ulbccccccdef"))) - failCount++; - - // Supplementary character test - // matches() - if (!Pattern.matches(toSupplementaries("ulb(c*)"), - toSupplementaries("ulbcccccc"))) - failCount++; - - // find() but not matches() - if (Pattern.matches(toSupplementaries("ulb(c*)"), - toSupplementaries("zzzulbcccccc"))) - failCount++; - - // lookingAt() but not matches() - if (Pattern.matches(toSupplementaries("ulb(c*)"), - toSupplementaries("ulbccccccdef"))) - failCount++; - - report("Pattern Matches"); - } - - /** - * Canonical equivalence testing. Tests the ability of the engine - * to match sequences that are not explicitly specified in the - * pattern when they are considered equivalent by the Unicode Standard. - */ - private static void ceTest() { - // Decomposed char outside char classes - Pattern p = Pattern.compile("testa\u030a", Pattern.CANON_EQ); - Matcher m = p.matcher("test\u00e5"); - if (!m.matches()) - failCount++; - - m.reset("testa\u030a"); - if (!m.matches()) - failCount++; - - // Composed char outside char classes - p = Pattern.compile("test\u00e5", Pattern.CANON_EQ); - m = p.matcher("test\u00e5"); - if (!m.matches()) - failCount++; - - m.reset("testa\u030a"); - if (!m.find()) - failCount++; - - // Decomposed char inside a char class - p = Pattern.compile("test[abca\u030a]", Pattern.CANON_EQ); - m = p.matcher("test\u00e5"); - if (!m.find()) - failCount++; - - m.reset("testa\u030a"); - if (!m.find()) - failCount++; - - // Composed char inside a char class - p = Pattern.compile("test[abc\u00e5def\u00e0]", Pattern.CANON_EQ); - m = p.matcher("test\u00e5"); - if (!m.find()) - failCount++; - - m.reset("testa\u0300"); - if (!m.find()) - failCount++; - - m.reset("testa\u030a"); - if (!m.find()) - failCount++; - - // Marks that cannot legally change order and be equivalent - p = Pattern.compile("testa\u0308\u0300", Pattern.CANON_EQ); - check(p, "testa\u0308\u0300", true); - check(p, "testa\u0300\u0308", false); - - // Marks that can legally change order and be equivalent - p = Pattern.compile("testa\u0308\u0323", Pattern.CANON_EQ); - check(p, "testa\u0308\u0323", true); - check(p, "testa\u0323\u0308", true); - - // Test all equivalences of the sequence a\u0308\u0323\u0300 - p = Pattern.compile("testa\u0308\u0323\u0300", Pattern.CANON_EQ); - check(p, "testa\u0308\u0323\u0300", true); - check(p, "testa\u0323\u0308\u0300", true); - check(p, "testa\u0308\u0300\u0323", true); - check(p, "test\u00e4\u0323\u0300", true); - check(p, "test\u00e4\u0300\u0323", true); - - /* - * The following canonical equivalence tests don't work. Bug id: 4916384. - * - // Decomposed hangul (jamos) - p = Pattern.compile("\u1100\u1161", Pattern.CANON_EQ); - m = p.matcher("\u1100\u1161"); - if (!m.matches()) - failCount++; - - m.reset("\uac00"); - if (!m.matches()) - failCount++; - - // Composed hangul - p = Pattern.compile("\uac00", Pattern.CANON_EQ); - m = p.matcher("\u1100\u1161"); - if (!m.matches()) - failCount++; - - m.reset("\uac00"); - if (!m.matches()) - failCount++; - - // Decomposed supplementary outside char classes - p = Pattern.compile("test\ud834\uddbc\ud834\udd6f", Pattern.CANON_EQ); - m = p.matcher("test\ud834\uddc0"); - if (!m.matches()) - failCount++; - - m.reset("test\ud834\uddbc\ud834\udd6f"); - if (!m.matches()) - failCount++; - - // Composed supplementary outside char classes - p = Pattern.compile("test\ud834\uddc0", Pattern.CANON_EQ); - m.reset("test\ud834\uddbc\ud834\udd6f"); - if (!m.matches()) - failCount++; - - m = p.matcher("test\ud834\uddc0"); - if (!m.matches()) - failCount++; - - */ - - report("Canonical Equivalence"); - } - - /** - * A basic sanity test of Matcher.replaceAll(). - */ - private static void globalSubstitute() { - // Global substitution with a literal - Pattern p = Pattern.compile("(ab)(c*)"); - Matcher m = p.matcher("abccczzzabcczzzabccc"); - if (!m.replaceAll("test").equals("testzzztestzzztest")) - failCount++; - - m.reset("zzzabccczzzabcczzzabccczzz"); - if (!m.replaceAll("test").equals("zzztestzzztestzzztestzzz")) - failCount++; - - // Global substitution with groups - m.reset("zzzabccczzzabcczzzabccczzz"); - String result = m.replaceAll("$1"); - if (!result.equals("zzzabzzzabzzzabzzz")) - failCount++; - - // Supplementary character test - // Global substitution with a literal - p = Pattern.compile(toSupplementaries("(ab)(c*)")); - m = p.matcher(toSupplementaries("abccczzzabcczzzabccc")); - if (!m.replaceAll(toSupplementaries("test")). - equals(toSupplementaries("testzzztestzzztest"))) - failCount++; - - m.reset(toSupplementaries("zzzabccczzzabcczzzabccczzz")); - if (!m.replaceAll(toSupplementaries("test")). - equals(toSupplementaries("zzztestzzztestzzztestzzz"))) - failCount++; - - // Global substitution with groups - m.reset(toSupplementaries("zzzabccczzzabcczzzabccczzz")); - result = m.replaceAll("$1"); - if (!result.equals(toSupplementaries("zzzabzzzabzzzabzzz"))) - failCount++; - - report("Global Substitution"); - } - - /** - * Tests the usage of Matcher.appendReplacement() with literal - * and group substitutions. - */ - private static void stringbufferSubstitute() { - // SB substitution with literal - String blah = "zzzblahzzz"; - Pattern p = Pattern.compile("blah"); - Matcher m = p.matcher(blah); - StringBuffer result = new StringBuffer(); - try { - m.appendReplacement(result, "blech"); - failCount++; - } catch (IllegalStateException e) { - } - m.find(); - m.appendReplacement(result, "blech"); - if (!result.toString().equals("zzzblech")) - failCount++; - - m.appendTail(result); - if (!result.toString().equals("zzzblechzzz")) - failCount++; - - // SB substitution with groups - blah = "zzzabcdzzz"; - p = Pattern.compile("(ab)(cd)*"); - m = p.matcher(blah); - result = new StringBuffer(); - try { - m.appendReplacement(result, "$1"); - failCount++; - } catch (IllegalStateException e) { - } - m.find(); - m.appendReplacement(result, "$1"); - if (!result.toString().equals("zzzab")) - failCount++; - - m.appendTail(result); - if (!result.toString().equals("zzzabzzz")) - failCount++; - - // SB substitution with 3 groups - blah = "zzzabcdcdefzzz"; - p = Pattern.compile("(ab)(cd)*(ef)"); - m = p.matcher(blah); - result = new StringBuffer(); - try { - m.appendReplacement(result, "$1w$2w$3"); - failCount++; - } catch (IllegalStateException e) { - } - m.find(); - m.appendReplacement(result, "$1w$2w$3"); - if (!result.toString().equals("zzzabwcdwef")) - failCount++; - - m.appendTail(result); - if (!result.toString().equals("zzzabwcdwefzzz")) - failCount++; - - // SB substitution with groups and three matches - // skipping middle match - blah = "zzzabcdzzzabcddzzzabcdzzz"; - p = Pattern.compile("(ab)(cd*)"); - m = p.matcher(blah); - result = new StringBuffer(); - try { - m.appendReplacement(result, "$1"); - failCount++; - } catch (IllegalStateException e) { - } - m.find(); - m.appendReplacement(result, "$1"); - if (!result.toString().equals("zzzab")) - failCount++; - - m.find(); - m.find(); - m.appendReplacement(result, "$2"); - if (!result.toString().equals("zzzabzzzabcddzzzcd")) - failCount++; - - m.appendTail(result); - if (!result.toString().equals("zzzabzzzabcddzzzcdzzz")) - failCount++; - - // Check to make sure escaped $ is ignored - blah = "zzzabcdcdefzzz"; - p = Pattern.compile("(ab)(cd)*(ef)"); - m = p.matcher(blah); - result = new StringBuffer(); - m.find(); - m.appendReplacement(result, "$1w\\$2w$3"); - if (!result.toString().equals("zzzabw$2wef")) - failCount++; - - m.appendTail(result); - if (!result.toString().equals("zzzabw$2wefzzz")) - failCount++; - - // Check to make sure a reference to nonexistent group causes error - blah = "zzzabcdcdefzzz"; - p = Pattern.compile("(ab)(cd)*(ef)"); - m = p.matcher(blah); - result = new StringBuffer(); - m.find(); - try { - m.appendReplacement(result, "$1w$5w$3"); - failCount++; - } catch (IndexOutOfBoundsException ioobe) { - // Correct result - } - - // Check double digit group references - blah = "zzz123456789101112zzz"; - p = Pattern.compile("(1)(2)(3)(4)(5)(6)(7)(8)(9)(10)(11)"); - m = p.matcher(blah); - result = new StringBuffer(); - m.find(); - m.appendReplacement(result, "$1w$11w$3"); - if (!result.toString().equals("zzz1w11w3")) - failCount++; - - // Check to make sure it backs off $15 to $1 if only three groups - blah = "zzzabcdcdefzzz"; - p = Pattern.compile("(ab)(cd)*(ef)"); - m = p.matcher(blah); - result = new StringBuffer(); - m.find(); - m.appendReplacement(result, "$1w$15w$3"); - if (!result.toString().equals("zzzabwab5wef")) - failCount++; - - - // Supplementary character test - // SB substitution with literal - blah = toSupplementaries("zzzblahzzz"); - p = Pattern.compile(toSupplementaries("blah")); - m = p.matcher(blah); - result = new StringBuffer(); - try { - m.appendReplacement(result, toSupplementaries("blech")); - failCount++; - } catch (IllegalStateException e) { - } - m.find(); - m.appendReplacement(result, toSupplementaries("blech")); - if (!result.toString().equals(toSupplementaries("zzzblech"))) - failCount++; - - m.appendTail(result); - if (!result.toString().equals(toSupplementaries("zzzblechzzz"))) - failCount++; - - // SB substitution with groups - blah = toSupplementaries("zzzabcdzzz"); - p = Pattern.compile(toSupplementaries("(ab)(cd)*")); - m = p.matcher(blah); - result = new StringBuffer(); - try { - m.appendReplacement(result, "$1"); - failCount++; - } catch (IllegalStateException e) { - } - m.find(); - m.appendReplacement(result, "$1"); - if (!result.toString().equals(toSupplementaries("zzzab"))) - failCount++; - - m.appendTail(result); - if (!result.toString().equals(toSupplementaries("zzzabzzz"))) - failCount++; - - // SB substitution with 3 groups - blah = toSupplementaries("zzzabcdcdefzzz"); - p = Pattern.compile(toSupplementaries("(ab)(cd)*(ef)")); - m = p.matcher(blah); - result = new StringBuffer(); - try { - m.appendReplacement(result, toSupplementaries("$1w$2w$3")); - failCount++; - } catch (IllegalStateException e) { - } - m.find(); - m.appendReplacement(result, toSupplementaries("$1w$2w$3")); - if (!result.toString().equals(toSupplementaries("zzzabwcdwef"))) - failCount++; - - m.appendTail(result); - if (!result.toString().equals(toSupplementaries("zzzabwcdwefzzz"))) - failCount++; - - // SB substitution with groups and three matches - // skipping middle match - blah = toSupplementaries("zzzabcdzzzabcddzzzabcdzzz"); - p = Pattern.compile(toSupplementaries("(ab)(cd*)")); - m = p.matcher(blah); - result = new StringBuffer(); - try { - m.appendReplacement(result, "$1"); - failCount++; - } catch (IllegalStateException e) { - } - m.find(); - m.appendReplacement(result, "$1"); - if (!result.toString().equals(toSupplementaries("zzzab"))) - failCount++; - - m.find(); - m.find(); - m.appendReplacement(result, "$2"); - if (!result.toString().equals(toSupplementaries("zzzabzzzabcddzzzcd"))) - failCount++; - - m.appendTail(result); - if (!result.toString().equals(toSupplementaries("zzzabzzzabcddzzzcdzzz"))) - failCount++; - - // Check to make sure escaped $ is ignored - blah = toSupplementaries("zzzabcdcdefzzz"); - p = Pattern.compile(toSupplementaries("(ab)(cd)*(ef)")); - m = p.matcher(blah); - result = new StringBuffer(); - m.find(); - m.appendReplacement(result, toSupplementaries("$1w\\$2w$3")); - if (!result.toString().equals(toSupplementaries("zzzabw$2wef"))) - failCount++; - - m.appendTail(result); - if (!result.toString().equals(toSupplementaries("zzzabw$2wefzzz"))) - failCount++; - - // Check to make sure a reference to nonexistent group causes error - blah = toSupplementaries("zzzabcdcdefzzz"); - p = Pattern.compile(toSupplementaries("(ab)(cd)*(ef)")); - m = p.matcher(blah); - result = new StringBuffer(); - m.find(); - try { - m.appendReplacement(result, toSupplementaries("$1w$5w$3")); - failCount++; - } catch (IndexOutOfBoundsException ioobe) { - // Correct result - } - - // Check double digit group references - blah = toSupplementaries("zzz123456789101112zzz"); - p = Pattern.compile("(1)(2)(3)(4)(5)(6)(7)(8)(9)(10)(11)"); - m = p.matcher(blah); - result = new StringBuffer(); - m.find(); - m.appendReplacement(result, toSupplementaries("$1w$11w$3")); - if (!result.toString().equals(toSupplementaries("zzz1w11w3"))) - failCount++; - - // Check to make sure it backs off $15 to $1 if only three groups - blah = toSupplementaries("zzzabcdcdefzzz"); - p = Pattern.compile(toSupplementaries("(ab)(cd)*(ef)")); - m = p.matcher(blah); - result = new StringBuffer(); - m.find(); - m.appendReplacement(result, toSupplementaries("$1w$15w$3")); - if (!result.toString().equals(toSupplementaries("zzzabwab5wef"))) - failCount++; - - // Check nothing has been appended into the output buffer if - // the replacement string triggers IllegalArgumentException. - p = Pattern.compile("(abc)"); - m = p.matcher("abcd"); - result = new StringBuffer(); - m.find(); - try { - m.appendReplacement(result, ("xyz$g")); - failCount++; - } catch (IllegalArgumentException iae) { - if (result.length() != 0) - failCount++; - } - - report("SB Substitution"); - } - - /* - * 5 groups of characters are created to make a substitution string. - * A base string will be created including random lead chars, the - * substitution string, and random trailing chars. - * A pattern containing the 5 groups is searched for and replaced with: - * random group + random string + random group. - * The results are checked for correctness. - */ - private static void substitutionBasher() { - for (int runs = 0; runs < 1000; runs++) { - // Create a base string to work in - int leadingChars = generator.nextInt(10); - StringBuilder baseBuffer = new StringBuilder(100); - String leadingString = getRandomAlphaString(leadingChars); - baseBuffer.append(leadingString); - - // Create 5 groups of random number of random chars - // Create the string to substitute - // Create the pattern string to search for - StringBuilder bufferToSub = new StringBuilder(25); - StringBuilder bufferToPat = new StringBuilder(50); - String[] groups = new String[5]; - for (int i = 0; i < 5; i++) { - int aGroupSize = generator.nextInt(5) + 1; - groups[i] = getRandomAlphaString(aGroupSize); - bufferToSub.append(groups[i]); - bufferToPat.append('('); - bufferToPat.append(groups[i]); - bufferToPat.append(')'); - } - String stringToSub = bufferToSub.toString(); - String pattern = bufferToPat.toString(); - - // Place sub string into working string at random index - baseBuffer.append(stringToSub); - - // Append random chars to end - int trailingChars = generator.nextInt(10); - String trailingString = getRandomAlphaString(trailingChars); - baseBuffer.append(trailingString); - String baseString = baseBuffer.toString(); - - // Create test pattern and matcher - Pattern p = Pattern.compile(pattern); - Matcher m = p.matcher(baseString); - - // Reject candidate if pattern happens to start early - m.find(); - if (m.start() < leadingChars) - continue; - - // Reject candidate if more than one match - if (m.find()) - continue; - - // Construct a replacement string with : - // random group + random string + random group - StringBuilder bufferToRep = new StringBuilder(); - int groupIndex1 = generator.nextInt(5); - bufferToRep.append("$").append(groupIndex1 + 1); - String randomMidString = getRandomAlphaString(5); - bufferToRep.append(randomMidString); - int groupIndex2 = generator.nextInt(5); - bufferToRep.append("$").append(groupIndex2 + 1); - String replacement = bufferToRep.toString(); - - // Do the replacement - String result = m.replaceAll(replacement); - - // Construct expected result - String expectedResult = leadingString + - groups[groupIndex1] + - randomMidString + - groups[groupIndex2] + - trailingString; - - // Check results - if (!result.equals(expectedResult)) - failCount++; - } - - report("Substitution Basher"); - } - - /** - * Checks the handling of some escape sequences that the Pattern - * class should process instead of the java compiler. These are - * not in the file because the escapes should be be processed - * by the Pattern class when the regex is compiled. - */ - private static void escapes() { - Pattern p = Pattern.compile("\\043"); - Matcher m = p.matcher("#"); - if (!m.find()) - failCount++; - - p = Pattern.compile("\\x23"); - m = p.matcher("#"); - if (!m.find()) - failCount++; - - p = Pattern.compile("\\u0023"); - m = p.matcher("#"); - if (!m.find()) - failCount++; - - report("Escape sequences"); - } - - /** - * Checks the handling of blank input situations. These - * tests are incompatible with my test file format. - */ - private static void blankInput() { - Pattern p = Pattern.compile("abc", Pattern.CASE_INSENSITIVE); - Matcher m = p.matcher(""); - if (m.find()) - failCount++; - - p = Pattern.compile("a*", Pattern.CASE_INSENSITIVE); - m = p.matcher(""); - if (!m.find()) - failCount++; - - p = Pattern.compile("abc"); - m = p.matcher(""); - if (m.find()) - failCount++; - - p = Pattern.compile("a*"); - m = p.matcher(""); - if (!m.find()) - failCount++; - - report("Blank input"); - } - - /** - * Tests the Boyer-Moore pattern matching of a character sequence - * on randomly generated patterns. - */ - private static void bm() { - doBnM('a'); - report("Boyer Moore (ASCII)"); - - doBnM(Character.MIN_SUPPLEMENTARY_CODE_POINT - 10); - report("Boyer Moore (Supplementary)"); - } - - private static void doBnM(int baseCharacter) { - int achar = 0; - - for (int i = 0; i < 100; i++) { - // Create a short pattern to search for - int patternLength = generator.nextInt(7) + 4; - StringBuilder patternBuffer = new StringBuilder(patternLength); - String pattern; - retry: - for (; ; ) { - for (int x = 0; x < patternLength; x++) { - int ch = baseCharacter + generator.nextInt(26); - if (Character.isSupplementaryCodePoint(ch)) { - patternBuffer.append(Character.toChars(ch)); - } else { - patternBuffer.append((char) ch); - } - } - pattern = patternBuffer.toString(); - - // Avoid patterns that start and end with the same substring - // See JDK-6854417 - for (int x = 1; x < patternLength; x++) { - if (pattern.startsWith(pattern.substring(x))) - continue retry; - } - break; - } - Pattern p = Pattern.compile(pattern); - - // Create a buffer with random ASCII chars that does - // not match the sample - String toSearch = null; - StringBuffer s = null; - Matcher m = p.matcher(""); - do { - s = new StringBuffer(100); - for (int x = 0; x < 100; x++) { - int ch = baseCharacter + generator.nextInt(26); - if (Character.isSupplementaryCodePoint(ch)) { - s.append(Character.toChars(ch)); - } else { - s.append((char) ch); - } - } - toSearch = s.toString(); - m.reset(toSearch); - } while (m.find()); - - // Insert the pattern at a random spot - int insertIndex = generator.nextInt(99); - if (Character.isLowSurrogate(s.charAt(insertIndex))) - insertIndex++; - s = s.insert(insertIndex, pattern); - toSearch = s.toString(); - - // Make sure that the pattern is found - m.reset(toSearch); - if (!m.find()) - failCount++; - - // Make sure that the match text is the pattern - if (!m.group().equals(pattern)) - failCount++; - - // Make sure match occured at insertion point - if (m.start() != insertIndex) - failCount++; - } - } - - /** - * Tests the matching of slices on randomly generated patterns. - * The Boyer-Moore optimization is not done on these patterns - * because it uses unicode case folding. - */ - private static void slice() { - doSlice(Character.MAX_VALUE); - report("Slice"); - - doSlice(Character.MAX_CODE_POINT); - report("Slice (Supplementary)"); - } - - private static void doSlice(int maxCharacter) { - Random generator = new Random(); - int achar = 0; - - for (int i = 0; i < 100; i++) { - // Create a short pattern to search for - int patternLength = generator.nextInt(7) + 4; - StringBuilder patternBuffer = new StringBuilder(patternLength); - for (int x = 0; x < patternLength; x++) { - int randomChar = 0; - while (!Character.isLetterOrDigit(randomChar)) - randomChar = generator.nextInt(maxCharacter); - if (Character.isSupplementaryCodePoint(randomChar)) { - patternBuffer.append(Character.toChars(randomChar)); - } else { - patternBuffer.append((char) randomChar); - } - } - String pattern = patternBuffer.toString(); - Pattern p = Pattern.compile(pattern, Pattern.UNICODE_CASE); - - // Create a buffer with random chars that does not match the sample - String toSearch = null; - StringBuffer s = null; - Matcher m = p.matcher(""); - do { - s = new StringBuffer(100); - for (int x = 0; x < 100; x++) { - int randomChar = 0; - while (!Character.isLetterOrDigit(randomChar)) - randomChar = generator.nextInt(maxCharacter); - if (Character.isSupplementaryCodePoint(randomChar)) { - s.append(Character.toChars(randomChar)); - } else { - s.append((char) randomChar); - } - } - toSearch = s.toString(); - m.reset(toSearch); - } while (m.find()); - - // Insert the pattern at a random spot - int insertIndex = generator.nextInt(99); - if (Character.isLowSurrogate(s.charAt(insertIndex))) - insertIndex++; - s = s.insert(insertIndex, pattern); - toSearch = s.toString(); - - // Make sure that the pattern is found - m.reset(toSearch); - if (!m.find()) - failCount++; - - // Make sure that the match text is the pattern - if (!m.group().equals(pattern)) - failCount++; - - // Make sure match occured at insertion point - if (m.start() != insertIndex) - failCount++; - } - } - - private static void explainFailure(String pattern, String data, - String expected, String actual) { - System.err.println("----------------------------------------"); - System.err.println("Pattern = " + pattern); - System.err.println("Data = " + data); - System.err.println("Expected = " + expected); - System.err.println("Actual = " + actual); - } - - private static void explainFailure(String pattern, String data, - Throwable t) { - System.err.println("----------------------------------------"); - System.err.println("Pattern = " + pattern); - System.err.println("Data = " + data); - t.printStackTrace(System.err); - } - - // Testing examples from a file - - /** - * Goes through the file "TestCases.txt" and creates many patterns - * described in the file, matching the patterns against input lines in - * the file, and comparing the results against the correct results - * also found in the file. The file format is described in comments - * at the head of the file. - */ - private static void processFile(String fileName) throws Exception { - File testCases = new File(System.getProperty("test.src", "."), - fileName); - FileInputStream in = new FileInputStream(testCases); - BufferedReader r = new BufferedReader(new InputStreamReader(in)); - - // Process next test case. - String aLine; - while ((aLine = r.readLine()) != null) { - // Read a line for pattern - String patternString = grabLine(r); - Pattern p = null; - try { - p = compileTestPattern(patternString); - } catch (PatternSyntaxException e) { - String dataString = grabLine(r); - String expectedResult = grabLine(r); - if (expectedResult.startsWith("error")) - continue; - explainFailure(patternString, dataString, e); - failCount++; - continue; - } - - // Read a line for input string - String dataString = grabLine(r); - Matcher m = p.matcher(dataString); - StringBuilder result = new StringBuilder(); - - // Check for IllegalStateExceptions before a match - failCount += preMatchInvariants(m); - - boolean found = m.find(); - - if (found) - failCount += postTrueMatchInvariants(m); - else - failCount += postFalseMatchInvariants(m); - - if (found) { - result.append("true "); - result.append(m.group(0)).append(" "); - } else { - result.append("false "); - } - - result.append(m.groupCount()); - - if (found) { - for (int i = 1; i < m.groupCount() + 1; i++) - if (m.group(i) != null) - result.append(" ").append(m.group(i)); - } - - // Read a line for the expected result - String expectedResult = grabLine(r); - - if (!result.toString().equals(expectedResult)) { - explainFailure(patternString, dataString, expectedResult, result.toString()); - failCount++; - } - } - - report(fileName); - } - - private static int preMatchInvariants(Matcher m) { - int failCount = 0; - try { - m.start(); - failCount++; - } catch (IllegalStateException ise) { - } - try { - m.end(); - failCount++; - } catch (IllegalStateException ise) { - } - try { - m.group(); - failCount++; - } catch (IllegalStateException ise) { - } - return failCount; - } - - private static int postFalseMatchInvariants(Matcher m) { - int failCount = 0; - try { - m.group(); - failCount++; - } catch (IllegalStateException ise) { - } - try { - m.start(); - failCount++; - } catch (IllegalStateException ise) { - } - try { - m.end(); - failCount++; - } catch (IllegalStateException ise) { - } - return failCount; - } - - private static int postTrueMatchInvariants(Matcher m) { - int failCount = 0; - //assert(m.start() = m.start(0); - if (m.start() != m.start(0)) - failCount++; - //assert(m.end() = m.end(0); - if (m.start() != m.start(0)) - failCount++; - //assert(m.group() = m.group(0); - if (!m.group().equals(m.group(0))) - failCount++; - try { - m.group(50); - failCount++; - } catch (IndexOutOfBoundsException ise) { - } - - return failCount; - } - - private static Pattern compileTestPattern(String patternString) { - if (!patternString.startsWith("'")) { - return Pattern.compile(patternString); - } - - int break1 = patternString.lastIndexOf("'"); - String flagString = patternString.substring( - break1 + 1); - patternString = patternString.substring(1, break1); - - if (flagString.equals("i")) - return Pattern.compile(patternString, Pattern.CASE_INSENSITIVE); - - if (flagString.equals("m")) - return Pattern.compile(patternString, Pattern.MULTILINE); - - return Pattern.compile(patternString); - } - - /** - * Reads a line from the input file. Keeps reading lines until a non - * empty non comment line is read. If the line contains a \n then - * these two characters are replaced by a newline char. If a \\uxxxx - * sequence is read then the sequence is replaced by the unicode char. - */ - private static String grabLine(BufferedReader r) throws Exception { - int index = 0; - String line = r.readLine(); - while (line.startsWith("//") || line.length() < 1) - line = r.readLine(); - while ((index = line.indexOf("\\n")) != -1) { - StringBuilder temp = new StringBuilder(line); - temp.replace(index, index + 2, "\n"); - line = temp.toString(); - } - while ((index = line.indexOf("\\u")) != -1) { - StringBuilder temp = new StringBuilder(line); - String value = temp.substring(index + 2, index + 6); - char aChar = (char) Integer.parseInt(value, 16); - String unicodeChar = "" + aChar; - temp.replace(index, index + 6, unicodeChar); - line = temp.toString(); - } - - return line; - } - - private static void check(Pattern p, String s, String g, String expected) { - Matcher m = p.matcher(s); - m.find(); - if (!m.group(g).equals(expected) || - s.charAt(m.start(g)) != expected.charAt(0) || - s.charAt(m.end(g) - 1) != expected.charAt(expected.length() - 1)) - failCount++; - } - - private static void checkReplaceFirst(String p, String s, String r, String expected) { - if (!expected.equals(Pattern.compile(p) - .matcher(s) - .replaceFirst(r))) - failCount++; - } - - private static void checkReplaceAll(String p, String s, String r, String expected) { - if (!expected.equals(Pattern.compile(p) - .matcher(s) - .replaceAll(r))) - failCount++; - } - - private static void checkExpectedFail(String p) { - try { - Pattern.compile(p); - } catch (PatternSyntaxException pse) { - //pse.printStackTrace(); - return; - } - failCount++; - } - - private static void checkExpectedIAE(Matcher m, String g) { - m.find(); - try { - m.group(g); - } catch (IllegalArgumentException x) { - //iae.printStackTrace(); - try { - m.start(g); - } catch (IllegalArgumentException xx) { - try { - m.start(g); - } catch (IllegalArgumentException xxx) { - return; - } - } - } - failCount++; - } - - private static void checkExpectedNPE(Matcher m) { - m.find(); - try { - m.group(null); - } catch (NullPointerException x) { - try { - m.start(null); - } catch (NullPointerException xx) { - try { - m.end(null); - } catch (NullPointerException xxx) { - return; - } - } - } - failCount++; - } - - private static void namedGroupCaptureTest() { - check(Pattern.compile("x+(?y+)z+"), - "xxxyyyzzz", - "gname", - "yyy"); - - check(Pattern.compile("x+(?y+)z+"), - "xxxyyyzzz", - "gname8", - "yyy"); - - //backref - Pattern pattern = Pattern.compile("(a*)bc\\1"); - check(pattern, "zzzaabcazzz", true); // found "abca" - - check(Pattern.compile("(?a*)bc\\k"), - "zzzaabcaazzz", true); - - check(Pattern.compile("(?abc)(def)\\k"), - "abcdefabc", true); - - check(Pattern.compile("(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(?k)\\k"), - "abcdefghijkk", true); - - // Supplementary character tests - check(Pattern.compile("(?" + toSupplementaries("a*)bc") + "\\k"), - toSupplementaries("zzzaabcazzz"), true); - - check(Pattern.compile("(?" + toSupplementaries("a*)bc") + "\\k"), - toSupplementaries("zzzaabcaazzz"), true); - - check(Pattern.compile("(?" + toSupplementaries("abc)(def)") + "\\k"), - toSupplementaries("abcdefabc"), true); - - check(Pattern.compile(toSupplementaries("(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)") + - "(?" + - toSupplementaries("k)") + "\\k"), - toSupplementaries("abcdefghijkk"), true); - - check(Pattern.compile("x+(?y+)z+\\k"), - "xxxyyyzzzyyy", - "gname", - "yyy"); - - //replaceFirst/All - checkReplaceFirst("(?ab)(c*)", - "abccczzzabcczzzabccc", - "${gn}", - "abzzzabcczzzabccc"); - - checkReplaceAll("(?ab)(c*)", - "abccczzzabcczzzabccc", - "${gn}", - "abzzzabzzzab"); - - - checkReplaceFirst("(?ab)(c*)", - "zzzabccczzzabcczzzabccczzz", - "${gn}", - "zzzabzzzabcczzzabccczzz"); - - checkReplaceAll("(?ab)(c*)", - "zzzabccczzzabcczzzabccczzz", - "${gn}", - "zzzabzzzabzzzabzzz"); - - checkReplaceFirst("(?ab)(?c*)", - "zzzabccczzzabcczzzabccczzz", - "${gn2}", - "zzzccczzzabcczzzabccczzz"); - - checkReplaceAll("(?ab)(?c*)", - "zzzabccczzzabcczzzabccczzz", - "${gn2}", - "zzzccczzzcczzzccczzz"); - - //toSupplementaries("(ab)(c*)")); - checkReplaceFirst("(?" + toSupplementaries("ab") + - ")(?" + toSupplementaries("c") + "*)", - toSupplementaries("abccczzzabcczzzabccc"), - "${gn1}", - toSupplementaries("abzzzabcczzzabccc")); - - - checkReplaceAll("(?" + toSupplementaries("ab") + - ")(?" + toSupplementaries("c") + "*)", - toSupplementaries("abccczzzabcczzzabccc"), - "${gn1}", - toSupplementaries("abzzzabzzzab")); - - checkReplaceFirst("(?" + toSupplementaries("ab") + - ")(?" + toSupplementaries("c") + "*)", - toSupplementaries("abccczzzabcczzzabccc"), - "${gn2}", - toSupplementaries("ccczzzabcczzzabccc")); - - - checkReplaceAll("(?" + toSupplementaries("ab") + - ")(?" + toSupplementaries("c") + "*)", - toSupplementaries("abccczzzabcczzzabccc"), - "${gn2}", - toSupplementaries("ccczzzcczzzccc")); - - checkReplaceFirst("(?Dog)AndCat", - "zzzDogAndCatzzzDogAndCatzzz", - "${dog}", - "zzzDogzzzDogAndCatzzz"); - - - checkReplaceAll("(?Dog)AndCat", - "zzzDogAndCatzzzDogAndCatzzz", - "${dog}", - "zzzDogzzzDogzzz"); - - // backref in Matcher & String - if (!"abcdefghij".replaceFirst("cd(?ef)gh", "${gn}").equals("abefij") || - !"abbbcbdbefgh".replaceAll("(?[a-e])b", "${gn}").equals("abcdefgh")) - failCount++; - - // negative - checkExpectedFail("(?abc)(def)"); - checkExpectedFail("(?abc)(def)"); - checkExpectedFail("(?<6groupnamestartswithdigit>abc)(def)"); - checkExpectedFail("(?abc)(def)\\k"); - checkExpectedFail("(?abc)(?def)\\k"); - checkExpectedIAE(Pattern.compile("(?abc)(def)").matcher("abcdef"), - "gnameX"); - checkExpectedNPE(Pattern.compile("(?abc)(def)").matcher("abcdef")); - report("NamedGroupCapture"); - } - - // This is for bug 6969132 - private static void nonBmpClassComplementTest() { - Pattern p = Pattern.compile("\\P{Lu}"); - Matcher m = p.matcher(new String(new int[]{0x1d400}, 0, 1)); - if (m.find() && m.start() == 1) - failCount++; - - // from a unicode category - p = Pattern.compile("\\P{Lu}"); - m = p.matcher(new String(new int[]{0x1d400}, 0, 1)); - if (m.find()) - failCount++; - if (!m.hitEnd()) - failCount++; - - // block - p = Pattern.compile("\\P{InMathematicalAlphanumericSymbols}"); - m = p.matcher(new String(new int[]{0x1d400}, 0, 1)); - if (m.find() && m.start() == 1) - failCount++; - - report("NonBmpClassComplement"); - } - - private static void unicodePropertiesTest() { - // different forms - if (!Pattern.compile("\\p{IsLu}").matcher("A").matches() || - !Pattern.compile("\\p{Lu}").matcher("A").matches() || - !Pattern.compile("\\p{gc=Lu}").matcher("A").matches() || - !Pattern.compile("\\p{general_category=Lu}").matcher("A").matches() || - !Pattern.compile("\\p{IsLatin}").matcher("B").matches() || - !Pattern.compile("\\p{sc=Latin}").matcher("B").matches() || - !Pattern.compile("\\p{script=Latin}").matcher("B").matches() || - !Pattern.compile("\\p{InBasicLatin}").matcher("c").matches() || - !Pattern.compile("\\p{blk=BasicLatin}").matcher("c").matches() || - !Pattern.compile("\\p{block=BasicLatin}").matcher("c").matches()) - failCount++; - - Matcher common = Pattern.compile("\\p{script=Common}").matcher(""); - Matcher unknown = Pattern.compile("\\p{IsUnknown}").matcher(""); - Matcher lastSM = common; - Character.UnicodeScript lastScript = Character.UnicodeScript.of(0); - - Matcher latin = Pattern.compile("\\p{block=basic_latin}").matcher(""); - Matcher greek = Pattern.compile("\\p{InGreek}").matcher(""); - Matcher lastBM = latin; - Character.UnicodeBlock lastBlock = Character.UnicodeBlock.of(0); - - for (int cp = 1; cp < Character.MAX_CODE_POINT; cp++) { - if (cp >= 0x30000 && (cp & 0x70) == 0) { - continue; // only pick couple code points, they are the same - } - - // Unicode Script - Character.UnicodeScript script = Character.UnicodeScript.of(cp); - Matcher m; - String str = new String(Character.toChars(cp)); - if (script == lastScript) { - m = lastSM; - m.reset(str); - } else { - m = Pattern.compile("\\p{Is" + script.name() + "}").matcher(str); - } - if (!m.matches()) { - failCount++; - } - Matcher other = (script == Character.UnicodeScript.COMMON) ? unknown : common; - other.reset(str); - if (other.matches()) { - failCount++; - } - lastSM = m; - lastScript = script; - - // Unicode Block - Character.UnicodeBlock block = Character.UnicodeBlock.of(cp); - if (block == null) { - //System.out.printf("Not a Block: cp=%x%n", cp); - continue; - } - if (block == lastBlock) { - m = lastBM; - m.reset(str); - } else { - m = Pattern.compile("\\p{block=" + block.toString() + "}").matcher(str); - } - if (!m.matches()) { - failCount++; - } - other = (block == Character.UnicodeBlock.BASIC_LATIN) ? greek : latin; - other.reset(str); - if (other.matches()) { - failCount++; - } - lastBM = m; - lastBlock = block; - } - report("unicodeProperties"); - } - - private static void unicodeHexNotationTest() { - - // negative - checkExpectedFail("\\x{-23}"); - checkExpectedFail("\\x{110000}"); - checkExpectedFail("\\x{}"); - checkExpectedFail("\\x{AB[ef]"); - - // codepoint - check("^\\x{1033c}$", "\uD800\uDF3C", true); - check("^\\xF0\\x90\\x8C\\xBC$", "\uD800\uDF3C", false); - check("^\\x{D800}\\x{DF3c}+$", "\uD800\uDF3C", false); - check("^\\xF0\\x90\\x8C\\xBC$", "\uD800\uDF3C", false); - - // in class - check("^[\\x{D800}\\x{DF3c}]+$", "\uD800\uDF3C", false); - check("^[\\xF0\\x90\\x8C\\xBC]+$", "\uD800\uDF3C", false); - check("^[\\x{D800}\\x{DF3C}]+$", "\uD800\uDF3C", false); - check("^[\\x{DF3C}\\x{D800}]+$", "\uD800\uDF3C", false); - check("^[\\x{D800}\\x{DF3C}]+$", "\uDF3C\uD800", true); - check("^[\\x{DF3C}\\x{D800}]+$", "\uDF3C\uD800", true); - - for (int cp = 0; cp <= 0x10FFFF; cp++) { - String s = "A" + new String(Character.toChars(cp)) + "B"; - String hexUTF16 = (cp <= 0xFFFF) ? String.format("\\u%04x", cp) - : String.format("\\u%04x\\u%04x", - (int) Character.toChars(cp)[0], - (int) Character.toChars(cp)[1]); - String hexCodePoint = "\\x{" + Integer.toHexString(cp) + "}"; - if (!Pattern.matches("A" + hexUTF16 + "B", s)) - failCount++; - if (!Pattern.matches("A[" + hexUTF16 + "]B", s)) - failCount++; - if (!Pattern.matches("A" + hexCodePoint + "B", s)) - failCount++; - if (!Pattern.matches("A[" + hexCodePoint + "]B", s)) - failCount++; - } - report("unicodeHexNotation"); - } - - private static void unicodeClassesTest() { - - Matcher lower = Pattern.compile("\\p{Lower}").matcher(""); - Matcher upper = Pattern.compile("\\p{Upper}").matcher(""); - Matcher ASCII = Pattern.compile("\\p{ASCII}").matcher(""); - Matcher alpha = Pattern.compile("\\p{Alpha}").matcher(""); - Matcher digit = Pattern.compile("\\p{Digit}").matcher(""); - Matcher alnum = Pattern.compile("\\p{Alnum}").matcher(""); - Matcher punct = Pattern.compile("\\p{Punct}").matcher(""); - Matcher graph = Pattern.compile("\\p{Graph}").matcher(""); - Matcher print = Pattern.compile("\\p{Print}").matcher(""); - Matcher blank = Pattern.compile("\\p{Blank}").matcher(""); - Matcher cntrl = Pattern.compile("\\p{Cntrl}").matcher(""); - Matcher xdigit = Pattern.compile("\\p{XDigit}").matcher(""); - Matcher space = Pattern.compile("\\p{Space}").matcher(""); - Matcher bound = Pattern.compile("\\b").matcher(""); - Matcher word = Pattern.compile("\\w++").matcher(""); - // UNICODE_CHARACTER_CLASS - Matcher lowerU = Pattern.compile("\\p{Lower}", Pattern.UNICODE_CHARACTER_CLASS).matcher(""); - Matcher upperU = Pattern.compile("\\p{Upper}", Pattern.UNICODE_CHARACTER_CLASS).matcher(""); - Matcher ASCIIU = Pattern.compile("\\p{ASCII}", Pattern.UNICODE_CHARACTER_CLASS).matcher(""); - Matcher alphaU = Pattern.compile("\\p{Alpha}", Pattern.UNICODE_CHARACTER_CLASS).matcher(""); - Matcher digitU = Pattern.compile("\\p{Digit}", Pattern.UNICODE_CHARACTER_CLASS).matcher(""); - Matcher alnumU = Pattern.compile("\\p{Alnum}", Pattern.UNICODE_CHARACTER_CLASS).matcher(""); - Matcher punctU = Pattern.compile("\\p{Punct}", Pattern.UNICODE_CHARACTER_CLASS).matcher(""); - Matcher graphU = Pattern.compile("\\p{Graph}", Pattern.UNICODE_CHARACTER_CLASS).matcher(""); - Matcher printU = Pattern.compile("\\p{Print}", Pattern.UNICODE_CHARACTER_CLASS).matcher(""); - Matcher blankU = Pattern.compile("\\p{Blank}", Pattern.UNICODE_CHARACTER_CLASS).matcher(""); - Matcher cntrlU = Pattern.compile("\\p{Cntrl}", Pattern.UNICODE_CHARACTER_CLASS).matcher(""); - Matcher xdigitU = Pattern.compile("\\p{XDigit}", Pattern.UNICODE_CHARACTER_CLASS).matcher(""); - Matcher spaceU = Pattern.compile("\\p{Space}", Pattern.UNICODE_CHARACTER_CLASS).matcher(""); - Matcher boundU = Pattern.compile("\\b", Pattern.UNICODE_CHARACTER_CLASS).matcher(""); - Matcher wordU = Pattern.compile("\\w", Pattern.UNICODE_CHARACTER_CLASS).matcher(""); - // embedded flag (?U) - Matcher lowerEU = Pattern.compile("(?U)\\p{Lower}", Pattern.UNICODE_CHARACTER_CLASS).matcher(""); - Matcher graphEU = Pattern.compile("(?U)\\p{Graph}", Pattern.UNICODE_CHARACTER_CLASS).matcher(""); - Matcher wordEU = Pattern.compile("(?U)\\w", Pattern.UNICODE_CHARACTER_CLASS).matcher(""); - - Matcher bwb = Pattern.compile("\\b\\w\\b").matcher(""); - Matcher bwbU = Pattern.compile("\\b\\w++\\b", Pattern.UNICODE_CHARACTER_CLASS).matcher(""); - Matcher bwbEU = Pattern.compile("(?U)\\b\\w++\\b", Pattern.UNICODE_CHARACTER_CLASS).matcher(""); - // properties - Matcher lowerP = Pattern.compile("\\p{IsLowerCase}").matcher(""); - Matcher upperP = Pattern.compile("\\p{IsUpperCase}").matcher(""); - Matcher titleP = Pattern.compile("\\p{IsTitleCase}").matcher(""); - Matcher letterP = Pattern.compile("\\p{IsLetter}").matcher(""); - Matcher alphaP = Pattern.compile("\\p{IsAlphabetic}").matcher(""); - Matcher ideogP = Pattern.compile("\\p{IsIdeographic}").matcher(""); - Matcher cntrlP = Pattern.compile("\\p{IsControl}").matcher(""); - Matcher spaceP = Pattern.compile("\\p{IsWhiteSpace}").matcher(""); - Matcher definedP = Pattern.compile("\\p{IsAssigned}").matcher(""); - Matcher nonCCPP = Pattern.compile("\\p{IsNoncharacterCodePoint}").matcher(""); - Matcher joinCrtl = Pattern.compile("\\p{IsJoinControl}").matcher(""); - - // javaMethod - Matcher lowerJ = Pattern.compile("\\p{javaLowerCase}").matcher(""); - Matcher upperJ = Pattern.compile("\\p{javaUpperCase}").matcher(""); - Matcher alphaJ = Pattern.compile("\\p{javaAlphabetic}").matcher(""); - Matcher ideogJ = Pattern.compile("\\p{javaIdeographic}").matcher(""); - - for (int cp = 1; cp < 0x30000; cp++) { - String str = new String(Character.toChars(cp)); - int type = Character.getType(cp); - if (// lower - POSIX_ASCII.isLower(cp) != lower.reset(str).matches() || - Character.isLowerCase(cp) != lowerU.reset(str).matches() || - Character.isLowerCase(cp) != lowerP.reset(str).matches() || - Character.isLowerCase(cp) != lowerEU.reset(str).matches() || - Character.isLowerCase(cp) != lowerJ.reset(str).matches() || - // upper - POSIX_ASCII.isUpper(cp) != upper.reset(str).matches() || - POSIX_Unicode.isUpper(cp) != upperU.reset(str).matches() || - Character.isUpperCase(cp) != upperP.reset(str).matches() || - Character.isUpperCase(cp) != upperJ.reset(str).matches() || - // alpha - POSIX_ASCII.isAlpha(cp) != alpha.reset(str).matches() || - POSIX_Unicode.isAlpha(cp) != alphaU.reset(str).matches() || - Character.isAlphabetic(cp) != alphaP.reset(str).matches() || - Character.isAlphabetic(cp) != alphaJ.reset(str).matches() || - // digit - POSIX_ASCII.isDigit(cp) != digit.reset(str).matches() || - Character.isDigit(cp) != digitU.reset(str).matches() || - // alnum - POSIX_ASCII.isAlnum(cp) != alnum.reset(str).matches() || - POSIX_Unicode.isAlnum(cp) != alnumU.reset(str).matches() || - // punct - POSIX_ASCII.isPunct(cp) != punct.reset(str).matches() || - POSIX_Unicode.isPunct(cp) != punctU.reset(str).matches() || - // graph - POSIX_ASCII.isGraph(cp) != graph.reset(str).matches() || - POSIX_Unicode.isGraph(cp) != graphU.reset(str).matches() || - POSIX_Unicode.isGraph(cp) != graphEU.reset(str).matches() || - // blank - POSIX_ASCII.isType(cp, POSIX_ASCII.BLANK) - != blank.reset(str).matches() || - POSIX_Unicode.isBlank(cp) != blankU.reset(str).matches() || - // print - POSIX_ASCII.isPrint(cp) != print.reset(str).matches() || - POSIX_Unicode.isPrint(cp) != printU.reset(str).matches() || - // cntrl - POSIX_ASCII.isCntrl(cp) != cntrl.reset(str).matches() || - POSIX_Unicode.isCntrl(cp) != cntrlU.reset(str).matches() || - (Character.CONTROL == type) != cntrlP.reset(str).matches() || - // hexdigit - POSIX_ASCII.isHexDigit(cp) != xdigit.reset(str).matches() || - POSIX_Unicode.isHexDigit(cp) != xdigitU.reset(str).matches() || - // space - POSIX_ASCII.isSpace(cp) != space.reset(str).matches() || - POSIX_Unicode.isSpace(cp) != spaceU.reset(str).matches() || - POSIX_Unicode.isSpace(cp) != spaceP.reset(str).matches() || - // word - POSIX_ASCII.isWord(cp) != word.reset(str).matches() || - POSIX_Unicode.isWord(cp) != wordU.reset(str).matches() || - POSIX_Unicode.isWord(cp) != wordEU.reset(str).matches() || - // bwordb - POSIX_ASCII.isWord(cp) != bwb.reset(str).matches() || - POSIX_Unicode.isWord(cp) != bwbU.reset(str).matches() || - // properties - Character.isTitleCase(cp) != titleP.reset(str).matches() || - Character.isLetter(cp) != letterP.reset(str).matches() || - Character.isIdeographic(cp) != ideogP.reset(str).matches() || - Character.isIdeographic(cp) != ideogJ.reset(str).matches() || - (Character.UNASSIGNED == type) == definedP.reset(str).matches() || - POSIX_Unicode.isNoncharacterCodePoint(cp) != nonCCPP.reset(str).matches() || - POSIX_Unicode.isJoinControl(cp) != joinCrtl.reset(str).matches()) - failCount++; - } - - // bounds/word align - twoFindIndexes(" \u0180sherman\u0400 ", bound, 1, 10); - if (!bwbU.reset("\u0180sherman\u0400").matches()) - failCount++; - twoFindIndexes(" \u0180sh\u0345erman\u0400 ", bound, 1, 11); - if (!bwbU.reset("\u0180sh\u0345erman\u0400").matches()) - failCount++; - twoFindIndexes(" \u0724\u0739\u0724 ", bound, 1, 4); - if (!bwbU.reset("\u0724\u0739\u0724").matches()) - failCount++; - if (!bwbEU.reset("\u0724\u0739\u0724").matches()) - failCount++; - report("unicodePredefinedClasses"); - } - - private static void horizontalAndVerticalWSTest() { - String hws = new String(new char[]{ - 0x09, 0x20, 0xa0, 0x1680, 0x180e, - 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, - 0x2006, 0x2007, 0x2008, 0x2009, 0x200a, - 0x202f, 0x205f, 0x3000}); - String vws = new String(new char[]{ - 0x0a, 0x0b, 0x0c, 0x0d, 0x85, 0x2028, 0x2029}); - if (!Pattern.compile("\\h+").matcher(hws).matches() || - !Pattern.compile("[\\h]+").matcher(hws).matches()) - failCount++; - if (Pattern.compile("\\H").matcher(hws).find() || - Pattern.compile("[\\H]").matcher(hws).find()) - failCount++; - if (!Pattern.compile("\\v+").matcher(vws).matches() || - !Pattern.compile("[\\v]+").matcher(vws).matches()) - failCount++; - if (Pattern.compile("\\V").matcher(vws).find() || - Pattern.compile("[\\V]").matcher(vws).find()) - failCount++; - String prefix = "abcd"; - String suffix = "efgh"; - String ng = "A"; - for (int i = 0; i < hws.length(); i++) { - String c = String.valueOf(hws.charAt(i)); - Matcher m = Pattern.compile("\\h").matcher(prefix + c + suffix); - if (!m.find() || !c.equals(m.group())) - failCount++; - m = Pattern.compile("[\\h]").matcher(prefix + c + suffix); - if (!m.find() || !c.equals(m.group())) - failCount++; - - m = Pattern.compile("\\H").matcher(hws.substring(0, i) + ng + hws.substring(i)); - if (!m.find() || !ng.equals(m.group())) - failCount++; - m = Pattern.compile("[\\H]").matcher(hws.substring(0, i) + ng + hws.substring(i)); - if (!m.find() || !ng.equals(m.group())) - failCount++; - } - for (int i = 0; i < vws.length(); i++) { - String c = String.valueOf(vws.charAt(i)); - Matcher m = Pattern.compile("\\v").matcher(prefix + c + suffix); - if (!m.find() || !c.equals(m.group())) - failCount++; - m = Pattern.compile("[\\v]").matcher(prefix + c + suffix); - if (!m.find() || !c.equals(m.group())) - failCount++; - - m = Pattern.compile("\\V").matcher(vws.substring(0, i) + ng + vws.substring(i)); - if (!m.find() || !ng.equals(m.group())) - failCount++; - m = Pattern.compile("[\\V]").matcher(vws.substring(0, i) + ng + vws.substring(i)); - if (!m.find() || !ng.equals(m.group())) - failCount++; - } - // \v in range is interpreted as 0x0B. This is the undocumented behavior - if (!Pattern.compile("[\\v-\\v]").matcher(String.valueOf((char) 0x0B)).matches()) - failCount++; - report("horizontalAndVerticalWSTest"); - } - - private static void linebreakTest() { - String linebreaks = new String(new char[]{ - 0x0A, 0x0B, 0x0C, 0x0D, 0x85, 0x2028, 0x2029}); - String crnl = "\r\n"; - if (!Pattern.compile("\\R+").matcher(linebreaks).matches() || - !Pattern.compile("\\R").matcher(crnl).matches() || - Pattern.compile("\\R\\R").matcher(crnl).matches()) - failCount++; - report("linebreakTest"); - } - - // #7189363 - private static void branchTest() { - if (!Pattern.compile("(a)?bc|d").matcher("d").find() || // greedy - !Pattern.compile("(a)+bc|d").matcher("d").find() || - !Pattern.compile("(a)*bc|d").matcher("d").find() || - !Pattern.compile("(a)??bc|d").matcher("d").find() || // reluctant - !Pattern.compile("(a)+?bc|d").matcher("d").find() || - !Pattern.compile("(a)*?bc|d").matcher("d").find() || - !Pattern.compile("(a)?+bc|d").matcher("d").find() || // possessive - !Pattern.compile("(a)++bc|d").matcher("d").find() || - !Pattern.compile("(a)*+bc|d").matcher("d").find() || - !Pattern.compile("(a)?bc|d").matcher("d").matches() || // greedy - !Pattern.compile("(a)+bc|d").matcher("d").matches() || - !Pattern.compile("(a)*bc|d").matcher("d").matches() || - !Pattern.compile("(a)??bc|d").matcher("d").matches() || // reluctant - !Pattern.compile("(a)+?bc|d").matcher("d").matches() || - !Pattern.compile("(a)*?bc|d").matcher("d").matches() || - !Pattern.compile("(a)?+bc|d").matcher("d").matches() || // possessive - !Pattern.compile("(a)++bc|d").matcher("d").matches() || - !Pattern.compile("(a)*+bc|d").matcher("d").matches() || - !Pattern.compile("(a)?bc|de").matcher("de").find() || // others - !Pattern.compile("(a)??bc|de").matcher("de").find() || - !Pattern.compile("(a)?bc|de").matcher("de").matches() || - !Pattern.compile("(a)??bc|de").matcher("de").matches()) - failCount++; - report("branchTest"); - } - - // This test is for 8007395 - private static void groupCurlyNotFoundSuppTest() { - String input = "test this as \ud83d\ude0d"; - for (String pStr : new String[]{"test(.)+(@[a-zA-Z.]+)", - "test(.)*(@[a-zA-Z.]+)", - "test([^B])+(@[a-zA-Z.]+)", - "test([^B])*(@[a-zA-Z.]+)", - "test(\\P{IsControl})+(@[a-zA-Z.]+)", - "test(\\P{IsControl})*(@[a-zA-Z.]+)", - }) { - Matcher m = Pattern.compile(pStr, Pattern.CASE_INSENSITIVE) - .matcher(input); - try { - if (m.find()) { - failCount++; - } - } catch (Exception x) { - failCount++; - } - } - report("GroupCurly NotFoundSupp"); - } - - // This test is for 8023647 - private static void groupCurlyBackoffTest() { - if (!"abc1c".matches("(\\w)+1\\1") || - "abc11".matches("(\\w)+1\\1")) { - failCount++; - } - report("GroupCurly backoff"); - } -} diff --git a/core/src/test/java/com/questdb/ql/ops/regex/SupplementaryTestCases.txt b/core/src/test/java/com/questdb/ql/ops/regex/SupplementaryTestCases.txt deleted file mode 100644 index 644a91b6b..000000000 --- a/core/src/test/java/com/questdb/ql/ops/regex/SupplementaryTestCases.txt +++ /dev/null @@ -1,1434 +0,0 @@ -// -// Copyright (c) 1999, 2009, Oracle and/or its affiliates. All rights reserved. -// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -// -// This code is free software; you can redistribute it and/or modify it -// under the terms of the GNU General Public License version 2 only, as -// published by the Free Software Foundation. -// -// This code is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// version 2 for more details (a copy is included in the LICENSE file that -// accompanied this code). -// -// You should have received a copy of the GNU General Public License version -// 2 along with this work; if not, write to the Free Software Foundation, -// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. -// -// Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA -// or visit www.oracle.com if you need additional information or have any -// questions. -// -// -------------------------------------------------------- -// This file contains test cases with supplementary characters for regular expressions. -// A test case consists of three lines: -// The first line is a pattern used in the test -// The second line is the input to search for the pattern in -// The third line is a concatentation of the match, the number of groups, -// and the contents of the first four subexpressions. -// Empty lines and lines beginning with comment slashes are ignored. - -// Test unsetting of backed off groups -^(\ud800\udc61)?\ud800\udc61 -\ud800\udc61 -true \ud800\udc61 1 - -^(\ud800\udc61\ud800)?\ud800\udc61\ud800 -\ud800\udc61\ud800 -true \ud800\udc61\ud800 1 - -^(\ud800\udc61\ud800\udc61(\ud800\udc62\ud800\udc62)?)+$ -\ud800\udc61\ud800\udc61\ud800\udc62\ud800\udc62\ud800\udc61\ud800\udc61 -true \ud800\udc61\ud800\udc61\ud800\udc62\ud800\udc62\ud800\udc61\ud800\udc61 2 \ud800\udc61\ud800\udc61 \ud800\udc62\ud800\udc62 - -^(\ud800\udc61\ud800\udc61\ud800(\ud800\udc62\ud800\udc62\ud800)?)+$ -\ud800\udc61\ud800\udc61\ud800\ud800\udc62\ud800\udc62\ud800\ud800\udc61\ud800\udc61\ud800 -true \ud800\udc61\ud800\udc61\ud800\ud800\udc62\ud800\udc62\ud800\ud800\udc61\ud800\udc61\ud800 2 \ud800\udc61\ud800\udc61\ud800 \ud800\udc62\ud800\udc62\ud800 - -((\ud800\udc61|\ud800\udc62)?\ud800\udc62)+ -\ud800\udc62 -true \ud800\udc62 2 \ud800\udc62 - -((\ud800|\ud800\udc62)?\ud800\udc62)+ -\ud800\udc62 -true \ud800\udc62 2 \ud800\udc62 - -(\ud800\udc61\ud800\udc61\ud800\udc61)?\ud800\udc61\ud800\udc61\ud800\udc61 -\ud800\udc61\ud800\udc61\ud800\udc61 -true \ud800\udc61\ud800\udc61\ud800\udc61 1 - -(\ud800\udc61\ud800\udc61\ud800\ud800\udc61)?\ud800\udc61\ud800\udc61\ud800\ud800\udc61 -\ud800\udc61\ud800\udc61\ud800\ud800\udc61 -true \ud800\udc61\ud800\udc61\ud800\ud800\udc61 1 - -^(\ud800\udc61\ud800(\ud800\udc62\ud800)?)+$ -\ud800\udc61\ud800\ud800\udc62\ud800\ud800\udc61\ud800 -true \ud800\udc61\ud800\ud800\udc62\ud800\ud800\udc61\ud800 2 \ud800\udc61\ud800 \ud800\udc62\ud800 - -^(\ud800\udc61(\ud800\udc62)?)+$ -\ud800\udc61\ud800\udc62\ud800\udc61 -true \ud800\udc61\ud800\udc62\ud800\udc61 2 \ud800\udc61 \ud800\udc62 - -^(\ud800\udc61\ud800(\ud800\udc62\ud800)?)+$ -\ud800\udc61\ud800\ud800\udc62\ud800\ud800\udc61\ud800 -true \ud800\udc61\ud800\ud800\udc62\ud800\ud800\udc61\ud800 2 \ud800\udc61\ud800 \ud800\udc62\ud800 - -^(\ud800\udc61(\ud800\udc62(\ud800\udc63)?)?)?\ud800\udc61\ud800\udc62\ud800\udc63 -\ud800\udc61\ud800\udc62\ud800\udc63 -true \ud800\udc61\ud800\udc62\ud800\udc63 3 - -^(\ud800\udc61\ud800(\ud800\udc62(\ud800\udc63)?)?)?\ud800\udc61\ud800\ud800\udc62\ud800\udc63 -\ud800\udc61\ud800\ud800\udc62\ud800\udc63 -true \ud800\udc61\ud800\ud800\udc62\ud800\udc63 3 - -^(\ud800\udc61(\ud800\udc02(\ud800\udc63))).* -\ud800\udc61\ud800\udc02\ud800\udc63 -true \ud800\udc61\ud800\udc02\ud800\udc63 3 \ud800\udc61\ud800\udc02\ud800\udc63 \ud800\udc02\ud800\udc63 \ud800\udc63 - -^(\ud800\udc61(\ud800(\ud800\udc63))).* -\ud800\udc61\ud800\ud800\udc63 -true \ud800\udc61\ud800\ud800\udc63 3 \ud800\udc61\ud800\ud800\udc63 \ud800\ud800\udc63 \ud800\udc63 - -// Patterns including no surrogates -(.)([^a])xyz -\ud801\ud800\udc00xyz -true \ud801\ud800\udc00xyz 2 \ud801 \ud800\udc00 - -[^a-z].. -\ud801\ud800\udc00xyz -true \ud801\ud800\udc00x 0 - -.$ -\ud801\ud800\udc00 -true \ud800\udc00 0 - -.$ -\ud801\udc01\ud800\udc00 -true \ud800\udc00 0 - -.$ -\ud801\udc01\ud800\udc00\udcff -true \udcff 0 - -[^x-\uffff][^y-\uffff] -\ud800\udc00pqr -true \ud800\udc00p 0 - -[^x-\uffff]+ -\ud800\udc00pqrx -true \ud800\udc00pqr 0 - -/// The following test cases fail due to use of Start rather than -/// StartS. Disabled for now. -///[a-\uffff] -///\ud800\udc00x -///true x 0 -/// -///[a-\uffff] -///\ud800\udc00 -///false 0 - -// use of x modifier -\ud800\udc61bc(?x)bl\ud800\udc61h -\ud800\udc61bcbl\ud800\udc61h -true \ud800\udc61bcbl\ud800\udc61h 0 - -\ud800\udc61bc(?x) bl\ud800\udc61h -\ud800\udc61bcbl\ud800\udc61h -true \ud800\udc61bcbl\ud800\udc61h 0 - -\ud800\udc61bc(?x) bl\ud800\udc61h blech -\ud800\udc61bcbl\ud800\udc61hblech -true \ud800\udc61bcbl\ud800\udc61hblech 0 - -\ud800\udc61bc(?x) bl\ud800\udc61h # ignore comment -\ud800\udc61bcbl\ud800\udc61h -true \ud800\udc61bcbl\ud800\udc61h 0 - -// Simple alternation -\ud800\udc61|\ud800\udc62 -\ud800\udc61 -true \ud800\udc61 0 - -\ud800\udc61|\ud800\udc62|\ud800 -\ud800\udc61 -true \ud800\udc61 0 - -\ud800\udc61|\ud800 -\ud800\udc62 -false 0 - -\ud800\udc62|\ud800 -\ud800 -true \ud800 0 - -\ud800\udc61|\ud802\udc02 -z -false 0 - -\ud800\udc61|\ud802\udc02 -\ud802\udc02 -true \ud802\udc02 0 - -\ud800\udc61|\ud802\udc02|\ud803\udc03\ud804\udc04 -\ud803\udc03\ud804\udc04 -true \ud803\udc03\ud804\udc04 0 - -\ud800\udc61|\ud800\udc61d -\ud800\udc61d -true \ud800\udc61 0 - -z(\ud800\udc61|\ud800\udc61c)\ud802\udc02 -z\ud800\udc61c\ud802\udc02 -true z\ud800\udc61c\ud802\udc02 1 \ud800\udc61c - -z(\ud800\udc61|\ud800\udc61c|\udc61c)\ud802\udc02 -z\udc61c\ud802\udc02 -true z\udc61c\ud802\udc02 1 \udc61c - -// Simple codepoint class -[\ud800\udc61\ud802\udc02c]+ -\ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02 -true \ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02 0 - -[\ud800\udc61\ud802\udc02c]+ -\ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02 -true \ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02 0 - -[\ud800\udc61\ud802\udc02c\ud800]+ -\ud800\udc61\ud802\udc02\ud800\ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02 -true \ud800\udc61\ud802\udc02\ud800\ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02 0 - -[\ud800\udc61bc]+ -d\ud800\udc62fg -false 0 - -[\ud800\udc61bc]+[\ud804\udc04ef]+[\ud807\udc07hi]+ -zzz\ud800\udc61\ud800\udc61\ud804\udc04\ud804\udc04\ud807\udc07\ud807\udc07zzz -true \ud800\udc61\ud800\udc61\ud804\udc04\ud804\udc04\ud807\udc07\ud807\udc07 0 - -// Range codepoint class -[\ud801\udc01-\ud807\udc07]+ -\ud8ff\udcff\ud8ff\udcff\ud8ff\udcff\ud807\udc07\ud807\udc07\ud807\udc07 -true \ud807\udc07\ud807\udc07\ud807\udc07 0 - -[\ud801\udc01-\ud807\udc07]+ -mmm -false 0 - -[\ud800\udc61-]+ -z\ud800\udc61-9z -true \ud800\udc61- 0 - -// Negated char class -[^\ud800\udc61\ud802\udc02c]+ -\ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02 -false 0 - -[^\ud800\udc61\ud802\udc02\ud803\udc03]+ -\ud800\udc61\ud800\udc61\ud800\udc61\ud802\udc02\ud802\udc02\ud802\udc02\ud803\udc03\ud803\udc03\ud803\udc03\ud804\udc04efg -true \ud804\udc04efg 0 - -[^\ud800\udc61\ud802\udc02\ud803\udc03\ud800]+ -\ud800\udc61\ud800\udc61\ud800\udc61\ud802\udc02\ud802\udc02\ud802\udc02\ud803\udc03\ud803\udc03\ud803\udc03\ud804\udc04efg -true \ud804\udc04efg 0 - -// Making sure a ^ not in first position matches literal ^ -[\ud801\udc01\ud802\udc02\ud803\udc03^\ud802\udc02] -\ud802\udc02 -true \ud802\udc02 0 - -[\ud801\udc01\ud802\udc02\ud803\udc03^\ud802\udc02] -^ -true ^ 0 - -// Class union and intersection -[\ud801\udc01\ud802\udc02\ud803\udc03[\ud804\udc04\ud805\udc05\ud806\udc06]] -\ud802\udc02 -true \ud802\udc02 0 - -[\ud800\udc61\ud802\udc02\ud803\udc03[\ud804\udc04\ud805\udc05\ud806\udc06]] -\ud805\udc05 -true \ud805\udc05 0 - -[\ud801\udc01-\ud804\udc04[0-9][\ud80b\udc0b-\ud80d\udc0d]] -\ud801\udc01 -true \ud801\udc01 0 - -[\ud801\udc01-\ud804\udc04[0-9][\ud80b\udc0b-\ud80d\udc0d]] -\ud80c\udc0c -true \ud80c\udc0c 0 - -[\ud801\udc01-\ud804\udc04[0-9][\ud80b\udc0b-\ud80d\udc0d]] -4 -true 4 0 - -[\ud801\udc01-\ud804\udc04[0-9][\ud80b\udc0b-\ud80d\udc0d]] -\ud805\udc05 -false 0 - -[\ud801\udc01-\ud804\udc04[0-9][\ud80b\udc0b-\ud80d\udc0d]] -\ud816\udc16 -false 0 - -[[\ud801\udc01-\ud804\udc04][0-9][\ud80b\udc0b-\ud80d\udc0d]] -\ud802\udc02 -true \ud802\udc02 0 - -[[\ud801\udc01-\ud804\udc04][0-9][\ud80b\udc0b-\ud80d\udc0d]] -\ud81a\udc1a -false 0 - -[\ud801\udc01-\ud803\udc03[\ud804\udc04-\ud806\udc06[\ud807\udc07-\ud809\udc09]]] -\ud801\udc01 -true \ud801\udc01 0 - -[\ud801\udc01-\ud803\udc03[\ud804\udc04-\ud806\udc06[\ud807\udc07-\ud809\udc09]]] -\ud805\udc05 -true \ud805\udc05 0 - -[\ud801\udc01-\ud803\udc03[\ud804\udc04-\ud806\udc06[\ud807\udc07-\ud809\udc09]]] -\ud808\udc08 -true \ud808\udc08 0 - -[\ud801\udc01-\ud803\udc03[\ud804\udc04-\ud806\udc06[\ud807\udc07-\ud809\udc09]]] -\ud80d\udc0d -false 0 - -[\ud801\udc01-\ud803\udc03[\ud804\udc04-\ud806\udc06[\ud807\udc07-\ud809\udc09]]\ud80d\udc0d] -\ud80d\udc0d -true \ud80d\udc0d 0 - -[\ud801\udc01\ud802\udc02\ud803\udc03[\ud804\udc04\ud805\udc05\ud806\udc06]\ud807\udc07\ud808\udc08\ud809\udc09] -\ud801\udc01 -true \ud801\udc01 0 - -[\ud800\udc61\ud802\udc02\ud803\udc03[\ud804\udc04\ud805\udc05\ud806\udc06]\ud807\udc07\ud808\udc08\ud809\udc09] -\ud804\udc04 -true \ud804\udc04 0 - -[\ud800\udc61\ud802\udc02\ud803\udc03[\ud804\udc04\ud805\udc05\ud806\udc06]\ud807\udc07\ud808\udc08\ud809\udc09] -\ud808\udc08 -true \ud808\udc08 0 - -[\ud800\udc61\ud802\udc02\ud803\udc03[\ud804\udc04\ud805\udc05\ud806\udc06]\ud807\udc07\ud808\udc08\ud809\udc09] -\ud816\udc16 -false 0 - -[\ud801\udc01-\ud803\udc03&&[\ud804\udc04-\ud806\udc06]] -\ud801\udc01 -false 0 - -[\ud801\udc01-\ud803\udc03&&[\ud804\udc04-\ud806\udc06]] -\ud805\udc05 -false 0 - -[\ud801\udc01-\ud803\udc03&&[\ud804\udc04-\ud806\udc06]] -\ud81a\udc1a -false 0 - -[[\ud801\udc01-\ud803\udc03]&&[\ud804\udc04-\ud806\udc06]] -\ud801\udc01 -false 0 - -[[\ud801\udc01-\ud803\udc03]&&[\ud804\udc04-\ud806\udc06]] -\ud805\udc05 -false 0 - -[[\ud801\udc01-\ud803\udc03]&&[\ud804\udc04-\ud806\udc06]] -\ud81a\udc1a -false 0 - -[\ud801\udc01-\ud803\udc03&&\ud804\udc04-\ud806\udc06] -\ud801\udc01 -false 0 - -[\ud801\udc01-\ud80d\udc0d&&\ud80d\udc0d-\ud81a\udc1a] -\ud80d\udc0d -true \ud80d\udc0d 0 - -[\ud801\udc01-\ud80d\udc0d&&\ud80d\udc0d-\ud81a\udc1a&&\ud801\udc01-\ud803\udc03] -\ud80d\udc0d -false 0 - -[\ud801\udc01-\ud80d\udc0d&&\ud80d\udc0d-\ud81a\udc1a&&\ud801\udc01-\ud81a\udc1a] -\ud80d\udc0d -true \ud80d\udc0d 0 - -[[\ud801\udc01-\ud80d\udc0d]&&[\ud80d\udc0d-\ud81a\udc1a]] -\ud801\udc01 -false 0 - -[[\ud801\udc01-\ud80d\udc0d]&&[\ud80d\udc0d-\ud81a\udc1a]] -\ud80d\udc0d -true \ud80d\udc0d 0 - -[[\ud801\udc01-\ud80d\udc0d]&&[\ud80d\udc0d-\ud81a\udc1a]] -\ud81a\udc1a -false 0 - -[[\ud801\udc01-\ud80d\udc0d]&&[^\ud801\udc01-\ud803\udc03]] -\ud801\udc01 -false 0 - -[[\ud801\udc01-\ud80d\udc0d]&&[^\ud801\udc01-\ud803\udc03]] -\ud804\udc04 -true \ud804\udc04 0 - -[\ud801\udc01-\ud80d\udc0d&&[^\ud801\udc01-\ud803\udc03]] -\ud801\udc01 -false 0 - -[\ud801\udc01-\ud80d\udc0d&&[^\ud801\udc01-\ud803\udc03]] -\ud804\udc04 -true \ud804\udc04 0 - -[\ud801\udc01-\ud803\udc03\ud804\udc04-\ud806\udc06&&[\ud804\udc04-\ud806\udc06]] -\ud801\udc01 -false 0 - -[\ud801\udc01-\ud803\udc03\ud804\udc04-\ud806\udc06&&[\ud804\udc04-\ud806\udc06]] -\ud805\udc05 -true \ud805\udc05 0 - -[[\ud801\udc01-\ud803\udc03]&&\ud804\udc04-\ud806\udc06\ud801\udc01-\ud803\udc03] -\ud801\udc01 -true \ud801\udc01 0 - -[[\ud801\udc01-\ud803\udc03]&&[\ud804\udc04-\ud806\udc06][\ud801\udc01-\ud803\udc03]] -\ud801\udc01 -true \ud801\udc01 0 - -[[\ud801\udc01-\ud803\udc03][\ud804\udc04-\ud806\udc06]&&\ud801\udc01\ud802\udc02\ud803\udc03] -\ud801\udc01 -true \ud801\udc01 0 - -[[\ud801\udc01-\ud803\udc03][\ud804\udc04-\ud806\udc06]&&\ud801\udc01\ud802\udc02\ud803\udc03[\ud804\udc04\ud805\udc05\ud806\udc06]] -\ud805\udc05 -true \ud805\udc05 0 - -[[\ud801\udc01-\ud803\udc03]&&[\ud802\udc02-\ud804\udc04]&&[\ud803\udc03-\ud805\udc05]] -\ud801\udc01 -false 0 - -[[\ud801\udc01-\ud803\udc03]&&[\ud802\udc02-\ud804\udc04]&&[\ud803\udc03-\ud805\udc05]] -\ud803\udc03 -true \ud803\udc03 0 - -[[\ud801\udc01-\ud803\udc03]&&[\ud802\udc02-\ud804\udc04][\ud803\udc03-\ud805\udc05]&&[\ud815\udc15-\ud81a\udc1a]] -\ud803\udc03 -false 0 - -[\ud801\udc01\ud802\udc02\ud803\udc03[^\ud802\udc02\ud803\udc03\ud804\udc04]] -\ud801\udc01 -true \ud801\udc01 0 - -[\ud800\udc61\ud802\udc02\ud803\udc03[^\ud802\udc02\ud803\udc03\ud804\udc04]] -\ud804\udc04 -false 0 - -[\ud801\udc01-\ud803\udc03&&\ud801\udc01-\ud804\udc04&&\ud801\udc01-\ud805\udc05\ud807\udc07\ud808\udc08\ud809\udc09] -\ud802\udc02 -true \ud802\udc02 0 - -[\ud801\udc01-\ud803\udc03&&\ud801\udc01-\ud804\udc04&&\ud801\udc01-\ud805\udc05\ud807\udc07\ud808\udc08\ud809\udc09] -\ud807\udc07 -false 0 - -[[\ud801\udc01[\ud802\udc02]]&&[\ud802\udc02[\ud801\udc01]]] -\ud801\udc01 -true \ud801\udc01 0 - -// Unicode isn't supported in clazz() -[[\ud800\udc61]&&[b][c][\ud800\udc61]&&[^d]] -\ud800\udc61 -true \ud800\udc61 0 - -[[\ud800\udc61]&&[\ud802\udc02][\ud800][\ud800\udc61]&&[^\ud804\udc04]] -\ud800\udc61 -true \ud800\udc61 0 - -[[\ud800\udc61]&&[b][\ud800][\ud800\udc61]&&[^\ud804\udc04]] -\ud804\udc04 -false 0 - -[[\ud800\udc61]&&[b][c][\ud800\udc61]&&[^d]] -d -false 0 - -[[[\ud800\udc01-\ud800\udc04]&&[\ud800\udc03-\ud800\udc06]]] -\ud800\udc01 -false 0 - -[[[\ud800\udc01-\ud800\udc04]&&[\ud800\udc03-\ud800\udc06]]] -\ud800\udc03 -true \ud800\udc03 0 - -[[[\ud800\udc01-\ud800\udc04]&&[\ud800\udc03-\ud800\udc06]]&&[\ud800\udc03]] -\ud800\udc03 -true \ud800\udc03 0 - -[[[\ud800\udc01-\ud800\udc04]&&[\ud800\udc03-\ud800\udc06]]&&[\ud800\udc03]&&\ud800\udc03] -\ud800\udc03 -true \ud800\udc03 0 - -[[[\ud800\udc01-\ud800\udc04]&&[\ud800\udc03-\ud800\udc06]]&&[\ud800\udc03]&&\ud800\udc03&&\ud800\udc03] -\ud800\udc03 -true \ud800\udc03 0 - -[[[\ud800\udc01-\ud800\udc04]&&[\ud800\udc03-\ud800\udc06]]&&[\ud800\udc03]&&\ud800\udc03&&[\ud800\udc03\ud800\udc04\ud800\udc05]] -\ud800\udc03 -true \ud800\udc03 0 - -[z[\ud800\udc61b\ud800\udc03&&b\ud800\udc03\ud800\udc04]] -\ud800\udc03 -true \ud800\udc03 0 - -[z[\ud800\udc61b\ud800\udc03&&b\ud800\udc03\ud800\udc04]&&[u-z]] -z -true z 0 - -[x[\ud800\udc61b\ud800\udc03&&b\ud800\udc03\ud800\udc04[z]]&&[u-z]] -z -false 0 - -[x[[wz]\ud800\udc61b\ud800\udc03&&b\ud800\udc03\ud800\udc04[z]]&&[u-z]] -z -true z 0 - -[[\ud800\udc61b\ud800\udc03]&&[\ud800\udc04\ud800\udc05f]\ud800\udc61b\ud800\udc03] -\ud800\udc61 -true \ud800\udc61 0 - -[[\ud800\udc61b\ud800\udc03]&&[\ud800\udc04\ud800\udc05f]xyz[\ud800\udc61b\ud800\udc03]] -\ud800\udc61 -true \ud800\udc61 0 - -\pL -\ud800\udc00 -true \ud800\udc00 0 - -\p{IsASCII} -\ud800\udc00 -false 0 - -\pLbc -\ud800\udc00bc -true \ud800\udc00bc 0 - -\ud800\udc61[r\p{InGreek}]c -\ud800\udc61\u0370c -true \ud800\udc61\u0370c 0 - -\ud800\udc61\p{InGreek} -\ud800\udc61\u0370 -true \ud800\udc61\u0370 0 - -\ud800\udc61\P{InGreek} -\ud800\udc61\u0370 -false 0 - -\ud800\udc61\P{InGreek} -\ud800\udc61b -true \ud800\udc61b 0 - -\ud800\udc61{^InGreek} -- -error - -\ud800\udc61\p{^InGreek} -- -error - -\ud800\udc61\P{^InGreek} -- -error - -\ud800\udc61\p{InGreek} -\ud800\udc61\u0370 -true \ud800\udc61\u0370 0 - -\ud800\udc61[\p{InGreek}]c -\ud800\udc61\u0370c -true \ud800\udc61\u0370c 0 - -\ud800\udc61[\P{InGreek}]c -\ud800\udc61\u0370c -false 0 - -\ud800\udc61[\P{InGreek}]c -\ud800\udc61bc -true \ud800\udc61bc 0 - -\ud800\udc61[{^InGreek}]c -\ud800\udc61nc -true \ud800\udc61nc 0 - -\ud800\udc61[{^InGreek}]c -\ud800\udc61zc -false 0 - -\ud800\udc61[\p{^InGreek}]c -- -error - -\ud800\udc61[\P{^InGreek}]c -- -error - -\ud800\udc61[\p{InGreek}] -\ud800\udc61\u0370 -true \ud800\udc61\u0370 0 - -\ud800\udc61[r\p{InGreek}]c -\ud800\udc61rc -true \ud800\udc61rc 0 - -\ud800\udc61[\p{InGreek}r]c -\ud800\udc61rc -true \ud800\udc61rc 0 - -\ud800\udc61[r\p{InGreek}]c -\ud800\udc61rc -true \ud800\udc61rc 0 - -\ud800\udc61[^\p{InGreek}]c -\ud800\udc61\u0370c -false 0 - -\ud800\udc61[^\P{InGreek}]c -\ud800\udc61\u0370c -true \ud800\udc61\u0370c 0 - -\ud800\udc61[\p{InGreek}&&[^\u0370]]c -\ud800\udc61\u0370c -false 0 - -// Test the dot metacharacter -\ud800\udc61.c.+ -\ud800\udc61#c%& -true \ud800\udc61#c%& 0 - -\ud800\udc61b. -\ud800\udc61b\n -false 0 - -(?s)\ud800\udc61b. -\ud800\udc61b\n -true \ud800\udc61b\n 0 - -\ud800\udc61[\p{L}&&[\P{InGreek}]]c -\ud800\udc61\u6000c -true \ud800\udc61\u6000c 0 - -\ud800\udc61[\p{L}&&[\P{InGreek}]]c -\ud800\udc61rc -true \ud800\udc61rc 0 - -\ud800\udc61[\p{L}&&[\P{InGreek}]]c -\ud800\udc61\u0370c -false 0 - -\ud800\udc61\p{InGreek}c -\ud800\udc61\u0370c -true \ud800\udc61\u0370c 0 - -\ud800\udc61\p{Sc} -\ud800\udc61$ -true \ud800\udc61$ 0 - -// Test \p{L} -\p{L} -\ud800\udf1e -true \ud800\udf1e 0 - -^a\p{L}z$ -a\ud800\udf1ez -true a\ud800\udf1ez 0 - -// Test \P{InDeseret} - -\ud800\udf00\p{L}{2,3}\P{L}*supp->\ud900\udc00<-\P{InDeseret} -\ud800\udf00\ud800\udf1e\ud800\udf1esupp->\ud900\udc00<-\ud901\udf00 -true \ud800\udf00\ud800\udf1e\ud800\udf1esupp->\ud900\udc00<-\ud901\udf00 0 - -\ud800\udf00\p{L}{2,3}\P{L}*supp->\ud900\udc00<-\P{InDeseret} -\ud800\udf00\ud800\udf1e\ud800\udf1e\ud901\udf00supp->\ud900\udc00<-\ud901\udf00 -true \ud800\udf00\ud800\udf1e\ud800\udf1e\ud901\udf00supp->\ud900\udc00<-\ud901\udf00 0 - -// Test \p{InDeseret} -\ud800\udf00\p{L}{2,3}\P{L}*supp->\ud900\udc00<-\p{InDeseret} -\ud800\udf00\ud800\udf1e\ud800\udf1e\ud901\udf00supp->\ud900\udc00<-\ud801\udc00 -true \ud800\udf00\ud800\udf1e\ud800\udf1e\ud901\udf00supp->\ud900\udc00<-\ud801\udc00 0 - -// Test the word char escape sequence -\ud800\udc61b\wc -\ud800\udc61bcc -true \ud800\udc61bcc 0 - -\ud800\udc61bc[\w] -\ud800\udc61bcd -true \ud800\udc61bcd 0 - -\ud800\udc61bc[\sdef]* -\ud800\udc61bc def -true \ud800\udc61bc def 0 - -\ud800\udc61bc[\sy-z]* -\ud800\udc61bc y z -true \ud800\udc61bc y z 0 - -\ud800\udc01bc[\ud800\udc01-\ud800\udc04\sm-p]* -\ud800\udc01bc\ud800\udc01\ud800\udc01 mn p -true \ud800\udc01bc\ud800\udc01\ud800\udc01 mn p 0 - -// Test the whitespace escape sequence -\ud800\udc61b\s\ud800\udc03 -\ud800\udc61b \ud800\udc03 -true \ud800\udc61b \ud800\udc03 0 - -\s\s\s -bl\ud800\udc61h err -false 0 - -\S\S\s -bl\ud800\udc61h err -true \ud800\udc61h 0 - -// Test the digit escape sequence -\ud800\udc61b\d\ud800\udc03 -\ud800\udc61b9\ud800\udc03 -true \ud800\udc61b9\ud800\udc03 0 - -\d\d\d -bl\ud800\udc61h45 -false 0 - -// Test the caret metacharacter -^\ud800\udc61bc -\ud800\udc61bcdef -true \ud800\udc61bc 0 - -^\ud800\udc61bc -bcd\ud800\udc61bc -false 0 - -// Greedy ? metacharacter -\ud800\udc61?\ud800\udc02 -\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 -true \ud800\udc61\ud800\udc02 0 - -\udc61?\ud800\udc02 -\ud800\udc61\udc61\udc61\ud800\udc02 -true \udc61\ud800\udc02 0 - -\ud800\udc61?\ud800\udc02 -\ud800\udc02 -true \ud800\udc02 0 - -\ud800?\ud800\udc02 -\ud800\udc02 -true \ud800\udc02 0 - -\ud800\udc61?\ud800\udc02 -\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc03\ud800\udc03\ud800\udc03 -false 0 - -.?\ud800\udc02 -\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 -true \ud800\udc61\ud800\udc02 0 - -// Reluctant ? metacharacter -\ud800\udc61??\ud800\udc02 -\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 -true \ud800\udc61\ud800\udc02 0 - -\ud800??\ud800\udc02 -\ud800\ud800\ud8001\ud800\ud800\udc02 -true \ud800\ud800\udc02 0 - -\ud800\udc61??\ud800\udc02 -\ud800\udc02 -true \ud800\udc02 0 - -\ud800??\ud800\udc02 -\ud800\udc02 -true \ud800\udc02 0 - -\ud800\udc61??\ud800\udc02 -\ud800\udc61\ud800\udc61\ud800\udc61ccc -false 0 - -.??\ud800\udc02 -\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 -true \ud800\udc61\ud800\udc02 0 - -// Possessive ? metacharacter -\ud800\udc61?+\ud800\udc02 -\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 -true \ud800\udc61\ud800\udc02 0 - -\ud800\udc61?+\ud800\udc02 -\ud800\udc02 -true \ud800\udc02 0 - -\ud800\udc61?+\ud800\udc02 -\ud800\udc61\ud800\udc61\ud800\udc61ccc -false 0 - -.?+\ud800\udc02 -\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 -true \ud800\udc61\ud800\udc02 0 - -// Greedy + metacharacter -\ud800\udc61+\ud800\udc02 -\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 -true \ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 0 - -\udc61+\ud800\udc02 -\ud800\udc61\udc61\udc61\udc61\ud800\udc02 -true \udc61\udc61\udc61\ud800\udc02 0 - -\ud800\udc61+\ud800\udc02 -\ud800\udc02 -false 0 - -\ud800+\ud800\udc02 -\ud800\udc02 -false 0 - -\ud800\udc61+\ud800\udc02 -\ud800\udc61\ud800\udc61\ud800\udc61ccc -false 0 - -.+\ud800\udc02 -\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 -true \ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 0 - -.+\ud800\udc02 -\ud800\udc61\udc61\udc61\udc61\ud800\udc02 -true \ud800\udc61\udc61\udc61\udc61\ud800\udc02 0 - -// Reluctant + metacharacter -\ud800\udc61+?\ud800\udc02 -\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 -true \ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 0 - -\udc61+?\ud800\udc02 -\udc61\udc61\udc61\udc61\ud800\udc02 -true \udc61\udc61\udc61\udc61\ud800\udc02 0 - -\ud800\udc61+?\ud800\udc02 -\ud800\udc02 -false 0 - -\ud800+?\ud800\udc02 -\ud800\udc02 -false 0 - -\ud800\udc61+?\ud800\udc02 -\ud800\udc61\ud800\udc61\ud800\udc61ccc -false 0 - -.+?\ud800\udc02 -\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 -true \ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 0 - -// Possessive + metacharacter -\ud800\udc61++\ud800\udc02 -\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 -true \ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 0 - -\ud800\udc61++\ud800\udc02 -\ud800\udc02 -false 0 - -\ud800\udc61++\ud800\udc02 -\ud800\udc61\ud800\udc61\ud800\udc61ccc -false 0 - -.++\ud800\udc02 -\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 -false 0 - -// Greedy Repetition -\ud800\udc61{2,3} -\ud800\udc61 -false 0 - -\ud800\udc61{2,3} -\ud800\udc61\ud800\udc61 -true \ud800\udc61\ud800\udc61 0 - -\ud800\udc61{2,3} -\ud800\udc61\ud800\udc61\ud800\udc61 -true \ud800\udc61\ud800\udc61\ud800\udc61 0 - -\ud800\udc61{2,3} -\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61 -true \ud800\udc61\ud800\udc61\ud800\udc61 0 - -\ud800\udc61{3,} -zzz\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61zzz -true \ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61 0 - -\ud800\udc61{3,} -zzz\ud800\udc61\ud800\udc61zzz -false 0 - -// Reluctant Repetition -\ud800\udc61{2,3}? -\ud800\udc61 -false 0 - -\ud800\udc61{2,3}? -\ud800\udc61\ud800\udc61 -true \ud800\udc61\ud800\udc61 0 - -\ud800\udc61{2,3}? -\ud800\udc61\ud800\udc61\ud800\udc61 -true \ud800\udc61\ud800\udc61 0 - -\ud800\udc61{2,3}? -\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61 -true \ud800\udc61\ud800\udc61 0 - -// Zero width Positive lookahead -\ud800\udc61\ud802\udc02\ud803\udc03(?=\ud804\udc04) -zzz\ud800\udc61\ud802\udc02\ud803\udc03\ud804\udc04 -true \ud800\udc61\ud802\udc02\ud803\udc03 0 - -\ud800\udc61\ud802\udc02\ud803\udc03(?=\ud804\udc04) -zzz\ud800\udc61\ud802\udc02\ud803\udc03e\ud804\udc04 -false 0 - -\ud800\udc61\ud802\udc02\ud803\udc03(?=\udcff\ud804\udc04) -zzz\ud800\udc61\ud802\udc02\ud803\udc03\udcff\ud804\udc04 -true \ud800\udc61\ud802\udc02\ud803\udc03 0 - -\ud800\udc61\ud802\udc02\ud803\udc03(?=\udcff\ud804\udc04) -zzz\ud800\udc61\ud802\udc02\ud803\udc03\ud8ff\udcff\ud804\udc04 -false 0 - -// Zero width Negative lookahead -\ud800\udc61\ud802\udc02\ud803\udc03(?!\ud804\udc04) -zz\ud800\udc61\ud802\udc02\ud803\udc03\ud804\udc04 -false 0 - -a\ud802\udc02\ud803\udc03(?!\ud804\udc04) -zza\ud802\udc02\ud803\udc03\udc04\ud804\udc04 -true a\ud802\udc02\ud803\udc03 0 - -\ud800\udc61\ud802\udc02\ud803\udc03(?!\ud804\udc04\ud8ff) -zz\ud800\udc61\ud802\udc02\ud803\udc03\ud804\udc04\ud8ffX -false 0 - -a\ud802\udc02\ud803\udc03(?!\ud804\udc04\ud8ff) -zza\ud802\udc02\ud803\udc03e\ud804\udc04\ud8ff\udcff -true a\ud802\udc02\ud803\udc03 0 - -// Zero width Positive lookbehind -(?<=\ud801\udc01\ud802\udc02)\ud803\udc03 -\ud801\udc01\ud802\udc02\ud803\udc03 -true \ud803\udc03 0 - -// Zero width Negative lookbehind -(?3 -// So that the BM optimization is part of test -\Q***\E\ud801\udc01\ud802\udc02\ud800\udc03 -***\ud801\udc01\ud802\udc02\ud800\udc03 -true ***\ud801\udc01\ud802\udc02\ud800\udc03 0 - -\ud802\udc02l\Q***\E\ud801\udc01\ud802\udc02\ud800\udc03 -\ud802\udc02l***\ud801\udc01\ud802\udc02\ud800\udc03 -true \ud802\udc02l***\ud801\udc01\ud802\udc02\ud800\udc03 0 - -\Q***\ud801\udc01\ud802\udc02\ud800\udc03 -***\ud801\udc01\ud802\udc02\ud800\udc03 -true ***\ud801\udc01\ud802\udc02\ud800\udc03 0 - -\ud802\udc02l\ud801\udc01h\Q***\E\ud801\udc01\ud802\udc02\ud800\udc03 -\ud802\udc02l\ud801\udc01h***\ud801\udc01\ud802\udc02\ud800\udc03 -true \ud802\udc02l\ud801\udc01h***\ud801\udc01\ud802\udc02\ud800\udc03 0 - -\Q***\ud801\udc01\ud802\udc02\ud800\udc03 -***\ud801\udc01\ud802\udc02\ud800\udc03 -true ***\ud801\udc01\ud802\udc02\ud800\udc03 0 - -\Q*\ud801\udc01\ud802\udc02 -*\ud801\udc01\ud802\udc02 -true *\ud801\udc01\ud802\udc02 0 - -\ud802\udc02l\ud801\udc01h\Q***\ud801\udc01\ud802\udc02\ud800\udc03 -\ud802\udc02l\ud801\udc01h***\ud801\udc01\ud802\udc02\ud800\udc03 -true \ud802\udc02l\ud801\udc01h***\ud801\udc01\ud802\udc02\ud800\udc03 0 - -\ud802\udc02l\ud801\udc01\Q***\ud801\udc01\ud802\udc02\ud800\udc03 -\ud802\udc02l\ud801\udc01***\ud801\udc01\ud802\udc02\ud800\udc03 -true \ud802\udc02l\ud801\udc01***\ud801\udc01\ud802\udc02\ud800\udc03 0 - -//Test cases below copied from i18n QE's RegexSupplementaryTests.txt -\uD800\uDFFF\uD801\uDFF1\uDB00\uDC00 -\uD800\uDFFF\uD801\uDFF1\uDB00\uDC00 -true \uD800\uDFFF\uD801\uDFF1\uDB00\uDC00 0 - -\uD800\uDFFF\uD801\uDFF1\uDB00\uDC00 -\u1000\uD801\uDFF1\uDB00\uDC00 -false 0 - -\uD800\uDFFF\uD801\uDFF1\uDB00\uDC00 -\uD800\uDFFF\uFFFF\uDB00\uDC00 -false 0 - -\uD800\uDFFF\uD801\uDFF1\uDB00\uDC00 -\uD800\uDFFF\uD801\uDFF1\uFFFF -false 0 - -\u1000.\uFFFF -\u1000\uD800\uDFFF\uFFFF -true \u1000\uD800\uDFFF\uFFFF 0 - -//======= -// Ranges -//======= -[a-\uD800\uDFFF] -\uDFFF -true \uDFFF 0 - -[a-\uD800\uDFFF] -\uD800 -true \uD800 0 - -[a-\uD800\uDFFF] -\uD800\uDFFF -true \uD800\uDFFF 0 - -[\uD800\uDC00-\uDBFF\uDFFF] -\uDBFF -false 0 - -[\uD800\uDC00-\uDBFF\uDFFF] -\uDC00 -false 0 - -[\uD800-\uDFFF] -\uD800\uDFFF -false 0 - -[\uD800-\uDFFF] -\uDFFF\uD800 -true \uDFFF 0 - -foo[^\uD800-\uDFFF] -foo\uD800\uDFFF -true foo\uD800\uDFFF 0 - -foo[^\uD800-\uDFFF] -foo\uDFFF\uD800 -false 0 - -//fo\uD800[\uDC00-\uDFFF] - -//================== -// Character Classes -//================== -// Simple class -[ab\uD800\uDFFFcd]at -\uD800at -false 0 - -[ab\uD800\uDFFFcd]at -\uD800\uDFFFat -true \uD800\uDFFFat 0 - -// Negation -[^\uD800\uDFFFcd]at -\uD800at -true \uD800at 0 - -[^\uD800\uDFFFcd]at -\uDFFFat -true \uDFFFat 0 - -// Inclusive range -[\u0000-\uD800\uDFFF-\uFFFF] -\uD800\uDFFF -true \uD800\uDFFF 0 - -// Unions -[\u0000-\uD800[\uDFFF-\uFFFF]] -\uD800\uDFFF -false 0 - - -// Intersection -[\u0000-\uFFFF&&[\uD800\uDFFF]] -\uD800\uDFFF -false 0 - -[\u0000-\uFFFF&&[\uD800\uDFFF]] -\uD800 -false 0 - -[\u0000-\uFFFF&&[\uDFFF\uD800]] -\uD800 -true \uD800 0 - -[\u0000-\uFFFF&&[\uDFFF\uD800\uDC00]] -\uDC00 -false 0 - -[\u0000-\uDFFF&&[\uD800-\uFFFF]] -\uD800\uDFFF -false 0 - -[\u0000-\uDFFF&&[\uD800-\uFFFF]] -\uDFFF\uD800 -true \uDFFF 0 - -// Subtraction -[\u0000-\uD800\uDFFF&&[^\uD800\uDC00]] -\uD800 -true \uD800 0 - -[\u0000-\uD800\uDFFF&&[^\uD800\uDC00]] -\uDC00 -true \uDC00 0 - -[\u0000-\uD800\uDFFF&&[^\uD800\uDC00]] -\uD800\uDFFF -true \uD800\uDFFF 0 - -[\u0000-\uD800\uDFFF&&[^\uD800\uDBFF\uDC00]] -\uD800 -false 0 - -[\u0000-\uD800\uDFFF&&[^\uDC00\uD800\uDBFF]] -\uD800\uDC00 -true \uD800\uDC00 0 - -// Quantifiers -a\uD800\uDFFF? -a\uD800 -true a 0 - -a\uD800\uDFFF? -a\uDFFF -true a 0 - -a\uD800\uDFFF? -a\uD800\uDFFF -true a\uD800\uDFFF 0 - -a\uDFFF\uD800? -a\uDFFF -true a\uDFFF 0 - -a\uDFFF\uD800? -a\uD800 -false 0 - -\uD800\uDFFF\uDC00? -\uD800 -false 0 - -\uD800\uDFFF\uDC00? -\uD800\uDFFF -true \uD800\uDFFF 0 - -a\uD800\uDFFF?? -a\uDFFF -true a 0 - -a\uD800\uDFFF* -a -true a 0 - -a\uD800\uDFFF* -a\uD800 -true a 0 - -\uD800\uDFFF* -\uD800\uDFFF\uD800\uDFFF\uD800\uDFFF\uD800\uDFFF -true \uD800\uDFFF\uD800\uDFFF\uD800\uDFFF\uD800\uDFFF 0 - -\uD800\uDFFF* -\uD800\uDFFF\uDFFF\uDFFF\uDFFF -true \uD800\uDFFF 0 - -\uD800*\uDFFF -\uD800\uDFFF -false 0 - -a\uD800\uDFFF* -a\uD800 -true a 0 - -\uDFFF\uD800* -\uDFFF -true \uDFFF 0 - -\uDFFF\uD800* -\uDFFF\uD800\uD800\uD800 -true \uDFFF\uD800\uD800\uD800 0 - -\uD800\uDFFF+ -\uD800\uDFFF\uDFFF\uDFFF -true \uD800\uDFFF 0 - -\uD800\uDFFF+ -\uD800 -false 0 - -\uD800\uDFFF+ -\uD800\uDFFF -true \uD800\uDFFF 0 - -\uD800\uDFFF+ -\uD800\uDFFF\uD800\uDFFF\uD800\uDFFF -true \uD800\uDFFF\uD800\uDFFF\uD800\uDFFF 0 - -\uDFFF\uD800+ -\uDFFF\uD800\uDFFF\uD800 -false 0 - -\uD800+\uDFFF -\uD800\uDFFF -false 0 - -\uD800+\uDFFF -\uD800 -false 0 - -\uDFFF+\uD800 -\uD800 -false 0 - -\uDFFF+\uD800 -\uDFFF\uD800 -true \uDFFF\uD800 0 - -\uD800\uDFFF{3} -\uD800\uDFFF\uDFFF\uDFFF -false 0 - -\uD800\uDFFF{3} -\uD800\uDFFF\uD800\uDFFF\uD800\uDFFF -true \uD800\uDFFF\uD800\uDFFF\uD800\uDFFF 0 - -\uDFFF\uD800{3} -\uDFFF\uD800\uDFFF\uD800\uDFFF\uD800 -false 0 - -\uDFFF\uD800{3} -\uDFFF\uD800\uD800\uD800 -true \uDFFF\uD800\uD800\uD800 0 - -\uD800\uDFFF{2,} -\uD800\uDFFF -false 0 - -\uD800\uDFFF{2,} -\uD800\uDFFF\uDFFF -false 0 - -\uD800\uDFFF{2,} -\uD800\uDFFF\uD800\uDFFF -true \uD800\uDFFF\uD800\uDFFF 0 - -\uDFFF\uD800{2,} -\uDFFF\uD800\uDFFF\uD800 -false 0 - -\uDFFF\uD800{2,} -\uDFFF\uD800\uD800\uD800 -true \uDFFF\uD800\uD800\uD800 0 - -\uD800\uDFFF{3,4} -\uD800\uDFFF\uD800\uDFFF\uD800\uDFFF\uD800\uDFFF -true \uD800\uDFFF\uD800\uDFFF\uD800\uDFFF\uD800\uDFFF 0 - -\uD800\uDFFF{3,4} -\uD800\uDFFF\uD800\uDFFF\uD800\uDFFF\uD800 -true \uD800\uDFFF\uD800\uDFFF\uD800\uDFFF 0 - -\uD800\uDFFF{3,4} -\uD800\uDFFF\uD800\uD800\uDFFF\uD800\uDFFF -false 0 - -\uDFFF\uD800{3,5} -\uDFFF\uD800\uD800\uD800\uD800\uD800\uD800\uD800 -true \uDFFF\uD800\uD800\uD800\uD800\uD800 0 - -\uD800\uDFFF{3,5} -\uD800\uDFFF\uDFFF\uDFFF -false 0 - -\uD800\uDFFF{3,5} -\uD800\uDFFF\uD800\uD800\uDFFF\uD800\uDFFF\uD800\uDFFF -true \uD800\uDFFF\uD800\uDFFF\uD800\uDFFF 0 - -// Groupings -(\uD800(\uDFFF)) -\uD800\uDFFF -false 2 - -(\uD800(\uDC00)(\uDFFF)) -\uD800\uDC00\uDFFF -false 3 - -((\uD800)(\uDFFF)) -\uD800\uDFFF -false 3 - -(\uD800(\uDFFF)\uDFFF) -\uD800\uDFFF -false 2 - -(\uDFFF(\uD800)(\uDBFF)) -\uDFFF\uD800\uDBFF -true \uDFFF\uD800\uDBFF 3 \uDFFF\uD800\uDBFF \uD800 \uDBFF - -(\uDFFF(\uD800)(\uDC00)) -\uDFFF\uD800\uDC00 -false 3 - -(\uDFFF\uD800(\uDC00\uDBFF)) -\uDFFF\uD800\uDC00\uDBFF -false 2 - -(\uD800\uDFFF(\uDBFF)(\uDC00)) -\uD800\uDFFF\uDBFF\uDC00 -false 3 - -(\uD800\uDFFF(\uDBFF\uDC00)) -\uD800\uDFFF\uDBFF\uDC00 -true \uD800\uDFFF\uDBFF\uDC00 2 \uD800\uDFFF\uDBFF\uDC00 \uDBFF\uDC00 diff --git a/core/src/test/java/com/questdb/ql/ops/regex/TestCases.txt b/core/src/test/java/com/questdb/ql/ops/regex/TestCases.txt deleted file mode 100644 index 4490eaf95..000000000 --- a/core/src/test/java/com/questdb/ql/ops/regex/TestCases.txt +++ /dev/null @@ -1,1092 +0,0 @@ -// -// Copyright (c) 1999, 2009, Oracle and/or its affiliates. All rights reserved. -// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -// -// This code is free software; you can redistribute it and/or modify it -// under the terms of the GNU General Public License version 2 only, as -// published by the Free Software Foundation. -// -// This code is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// version 2 for more details (a copy is included in the LICENSE file that -// accompanied this code). -// -// You should have received a copy of the GNU General Public License version -// 2 along with this work; if not, write to the Free Software Foundation, -// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. -// -// Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA -// or visit www.oracle.com if you need additional information or have any -// questions. -// -// -// This file contains test cases for regular expressions. -// A test case consists of three lines: -// The first line is a pattern used in the test -// The second line is the input to search for the pattern in -// The third line is a concatentation of the match, the number of groups, -// and the contents of the first four subexpressions. -// Empty lines and lines beginning with comment slashes are ignored. -// -// Test unsetting of backed off groups -^(a)?a -a -true a 1 - -^(aa(bb)?)+$ -aabbaa -true aabbaa 2 aa bb - -((a|b)?b)+ -b -true b 2 b - -(aaa)?aaa -aaa -true aaa 1 - -^(a(b)?)+$ -aba -true aba 2 a b - -^(a(b(c)?)?)?abc -abc -true abc 3 - -^(a(b(c))).* -abc -true abc 3 abc bc c - -// use of x modifier -abc(?x)blah -abcblah -true abcblah 0 - -abc(?x) blah -abcblah -true abcblah 0 - -abc(?x) blah blech -abcblahblech -true abcblahblech 0 - -abc(?x) blah # ignore comment -abcblah -true abcblah 0 - -// Simple alternation -a|b -a -true a 0 - -a|b -z -false 0 - -a|b -b -true b 0 - -a|b|cd -cd -true cd 0 - -a|ad -ad -true a 0 - -z(a|ac)b -zacb -true zacb 1 ac - -// Simple char class -[abc]+ -ababab -true ababab 0 - -[abc]+ -defg -false 0 - -[abc]+[def]+[ghi]+ -zzzaaddggzzz -true aaddgg 0 - -// Range char class -[a-g]+ -zzzggg -true ggg 0 - -[a-g]+ -mmm -false 0 - -[a-]+ -za-9z -true a- 0 - -[a-\\u4444]+ -za-9z -true za 0 - -// Negated char class -[^abc]+ -ababab -false 0 - -[^abc]+ -aaabbbcccdefg -true defg 0 - -// Making sure a ^ not in first position matches literal ^ -[abc^b] -b -true b 0 - -[abc^b] -^ -true ^ 0 - -// Class union and intersection -[abc[def]] -b -true b 0 - -[abc[def]] -e -true e 0 - -[a-d[0-9][m-p]] -a -true a 0 - -[a-d[0-9][m-p]] -o -true o 0 - -[a-d[0-9][m-p]] -4 -true 4 0 - -[a-d[0-9][m-p]] -e -false 0 - -[a-d[0-9][m-p]] -u -false 0 - -[[a-d][0-9][m-p]] -b -true b 0 - -[[a-d][0-9][m-p]] -z -false 0 - -[a-c[d-f[g-i]]] -a -true a 0 - -[a-c[d-f[g-i]]] -e -true e 0 - -[a-c[d-f[g-i]]] -h -true h 0 - -[a-c[d-f[g-i]]] -m -false 0 - -[a-c[d-f[g-i]]m] -m -true m 0 - -[abc[def]ghi] -a -true a 0 - -[abc[def]ghi] -d -true d 0 - -[abc[def]ghi] -h -true h 0 - -[abc[def]ghi] -w -false 0 - -[a-c&&[d-f]] -a -false 0 - -[a-c&&[d-f]] -e -false 0 - -[a-c&&[d-f]] -z -false 0 - -[[a-c]&&[d-f]] -a -false 0 - -[[a-c]&&[d-f]] -e -false 0 - -[[a-c]&&[d-f]] -z -false 0 - -[a-c&&d-f] -a -false 0 - -[a-m&&m-z] -m -true m 0 - -[a-m&&m-z&&a-c] -m -false 0 - -[a-m&&m-z&&a-z] -m -true m 0 - -[[a-m]&&[m-z]] -a -false 0 - -[[a-m]&&[m-z]] -m -true m 0 - -[[a-m]&&[m-z]] -z -false 0 - -[[a-m]&&[^a-c]] -a -false 0 - -[[a-m]&&[^a-c]] -d -true d 0 - -[a-m&&[^a-c]] -a -false 0 - -[a-m&&[^a-c]] -d -true d 0 - -[a-cd-f&&[d-f]] -a -false 0 - -[a-cd-f&&[d-f]] -e -true e 0 - -[[a-c]&&d-fa-c] -a -true a 0 - -[[a-c]&&[d-f][a-c]] -a -true a 0 - -[[a-c][d-f]&&abc] -a -true a 0 - -[[a-c][d-f]&&abc[def]] -e -true e 0 - -[[a-c]&&[b-d]&&[c-e]] -a -false 0 - -[[a-c]&&[b-d]&&[c-e]] -c -true c 0 - -[[a-c]&&[b-d][c-e]&&[u-z]] -c -false 0 - -[abc[^bcd]] -a -true a 0 - -[abc[^bcd]] -d -false 0 - -[a-c&&a-d&&a-eghi] -b -true b 0 - -[a-c&&a-d&&a-eghi] -g -false 0 - -[[a[b]]&&[b[a]]] -a -true a 0 - -[[a]&&[b][c][a]&&[^d]] -a -true a 0 - -[[a]&&[b][c][a]&&[^d]] -d -false 0 - -[[[a-d]&&[c-f]]] -a -false 0 - -[[[a-d]&&[c-f]]] -c -true c 0 - -[[[a-d]&&[c-f]]&&[c]] -c -true c 0 - -[[[a-d]&&[c-f]]&&[c]&&c] -c -true c 0 - -[[[a-d]&&[c-f]]&&[c]&&c&&c] -c -true c 0 - -[[[a-d]&&[c-f]]&&[c]&&c&&[cde]] -c -true c 0 - -[z[abc&&bcd]] -c -true c 0 - -[z[abc&&bcd]&&[u-z]] -z -true z 0 - -[x[abc&&bcd[z]]&&[u-z]] -z -false 0 - -[x[[wz]abc&&bcd[z]]&&[u-z]] -z -true z 0 - -[[abc]&&[def]abc] -a -true a 0 - -[[abc]&&[def]xyz[abc]] -a -true a 0 - -\pL -a -true a 0 - -\pL -7 -false 0 - -\p{L} -a -true a 0 - -\p{LC} -a -true a 0 - -\p{LC} -A -true A 0 - -\p{IsL} -a -true a 0 - -\p{IsLC} -a -true a 0 - -\p{IsLC} -A -true A 0 - -\p{IsLC} -9 -false 0 - -\P{IsLC} -9 -true 9 0 - -// Guillemet left is initial quote punctuation -\p{Pi} -\u00ab -true \u00ab 0 - -\P{Pi} -\u00ac -true \u00ac 0 - -// Guillemet right is final quote punctuation -\p{IsPf} -\u00bb -true \u00bb 0 - -\p{P} -\u00bb -true \u00bb 0 - -\p{P}+ -\u00bb -true \u00bb 0 - -\P{IsPf} -\u00bc -true \u00bc 0 - -\P{IsP} -\u00bc -true \u00bc 0 - -\p{L1} -\u00bc -true \u00bc 0 - -\p{L1}+ -\u00bc -true \u00bc 0 - -\p{L1} -\u02bc -false 0 - -\p{ASCII} -a -true a 0 - -\p{IsASCII} -a -true a 0 - -\p{IsASCII} -\u0370 -false 0 - -\pLbc -abc -true abc 0 - -a[r\p{InGreek}]c -a\u0370c -true a\u0370c 0 - -a\p{InGreek} -a\u0370 -true a\u0370 0 - -a\P{InGreek} -a\u0370 -false 0 - -a\P{InGreek} -ab -true ab 0 - -a{^InGreek} -- -error - -a\p{^InGreek} -- -error - -a\P{^InGreek} -- -error - -a\p{InGreek} -a\u0370 -true a\u0370 0 - -a[\p{InGreek}]c -a\u0370c -true a\u0370c 0 - -a[\P{InGreek}]c -a\u0370c -false 0 - -a[\P{InGreek}]c -abc -true abc 0 - -a[{^InGreek}]c -anc -true anc 0 - -a[{^InGreek}]c -azc -false 0 - -a[\p{^InGreek}]c -- -error - -a[\P{^InGreek}]c -- -error - -a[\p{InGreek}] -a\u0370 -true a\u0370 0 - -a[r\p{InGreek}]c -arc -true arc 0 - -a[\p{InGreek}r]c -arc -true arc 0 - -a[r\p{InGreek}]c -arc -true arc 0 - -a[^\p{InGreek}]c -a\u0370c -false 0 - -a[^\P{InGreek}]c -a\u0370c -true a\u0370c 0 - -a[\p{InGreek}&&[^\u0370]]c -a\u0370c -false 0 - -// Test the dot metacharacter -a.c.+ -a#c%& -true a#c%& 0 - -ab. -ab\n -false 0 - -(?s)ab. -ab\n -true ab\n 0 - -a[\p{L}&&[\P{InGreek}]]c -a\u6000c -true a\u6000c 0 - -a[\p{L}&&[\P{InGreek}]]c -arc -true arc 0 - -a[\p{L}&&[\P{InGreek}]]c -a\u0370c -false 0 - -a\p{InGreek}c -a\u0370c -true a\u0370c 0 - -a\p{Sc} -a$ -true a$ 0 - -// Test the word char escape sequence -ab\wc -abcc -true abcc 0 - -\W\w\W -#r# -true #r# 0 - -\W\w\W -rrrr#ggg -false 0 - -abc[\w] -abcd -true abcd 0 - -abc[\sdef]* -abc def -true abc def 0 - -abc[\sy-z]* -abc y z -true abc y z 0 - -abc[a-d\sm-p]* -abcaa mn p -true abcaa mn p 0 - -// Test the whitespace escape sequence -ab\sc -ab c -true ab c 0 - -\s\s\s -blah err -false 0 - -\S\S\s -blah err -true ah 0 - -// Test the digit escape sequence -ab\dc -ab9c -true ab9c 0 - -\d\d\d -blah45 -false 0 - -// Test the caret metacharacter -^abc -abcdef -true abc 0 - -^abc -bcdabc -false 0 - -// Greedy ? metacharacter -a?b -aaaab -true ab 0 - -a?b -b -true b 0 - -a?b -aaaccc -false 0 - -.?b -aaaab -true ab 0 - -// Reluctant ? metacharacter -a??b -aaaab -true ab 0 - -a??b -b -true b 0 - -a??b -aaaccc -false 0 - -.??b -aaaab -true ab 0 - -// Possessive ? metacharacter -a?+b -aaaab -true ab 0 - -a?+b -b -true b 0 - -a?+b -aaaccc -false 0 - -.?+b -aaaab -true ab 0 - -// Greedy + metacharacter -a+b -aaaab -true aaaab 0 - -a+b -b -false 0 - -a+b -aaaccc -false 0 - -.+b -aaaab -true aaaab 0 - -// Reluctant + metacharacter -a+?b -aaaab -true aaaab 0 - -a+?b -b -false 0 - -a+?b -aaaccc -false 0 - -.+?b -aaaab -true aaaab 0 - -// Possessive + metacharacter -a++b -aaaab -true aaaab 0 - -a++b -b -false 0 - -a++b -aaaccc -false 0 - -.++b -aaaab -false 0 - -// Greedy Repetition -a{2,3} -a -false 0 - -a{2,3} -aa -true aa 0 - -a{2,3} -aaa -true aaa 0 - -a{2,3} -aaaa -true aaa 0 - -a{3,} -zzzaaaazzz -true aaaa 0 - -a{3,} -zzzaazzz -false 0 - -// Reluctant Repetition -a{2,3}? -a -false 0 - -a{2,3}? -aa -true aa 0 - -a{2,3}? -aaa -true aa 0 - -a{2,3}? -aaaa -true aa 0 - -// Zero width Positive lookahead -abc(?=d) -zzzabcd -true abc 0 - -abc(?=d) -zzzabced -false 0 - -// Zero width Negative lookahead -abc(?!d) -zzabcd -false 0 - -abc(?!d) -zzabced -true abc 0 - -// Zero width Positive lookbehind -\w(?<=a) -###abc### -true a 0 - -\w(?<=a) -###ert### -false 0 - -// Zero width Negative lookbehind -(?3 -// So that the BM optimization is part of test -\Q***\Eabc -***abc -true ***abc 0 - -bl\Q***\Eabc -bl***abc -true bl***abc 0 - -\Q***abc -***abc -true ***abc 0 - -blah\Q***\Eabc -blah***abc -true blah***abc 0 - -\Q***abc -***abc -true ***abc 0 - -\Q*ab -*ab -true *ab 0 - -blah\Q***abc -blah***abc -true blah***abc 0 - -bla\Q***abc -bla***abc -true bla***abc 0 - -// Escapes in char classes -[ab\Qdef\E] -d -true d 0 - -[ab\Q[\E] -[ -true [ 0 - -[\Q]\E] -] -true ] 0 - -[\Q\\E] -\ -true \ 0 - -[\Q(\E] -( -true ( 0 - -[\n-#] -! -true ! 0 - -[\n-#] -- -false 0 - -[\w-#] -! -false 0 - -[\w-#] -a -true a 0 - -[\w-#] -- -true - 0 - -[\w-#] -# -true # 0 - -[\043]+ -blahblah#blech -true # 0 - -[\042-\044]+ -blahblah#blech -true # 0 - -[\u1234-\u1236] -blahblah\u1235blech -true \u1235 0 - -[^\043]* -blahblah#blech -true blahblah 0 - -(|f)?+ -foo -true 1 diff --git a/core/src/test/java/com/questdb/ql/sort/ComparatorCompilerTest.java b/core/src/test/java/com/questdb/ql/sort/ComparatorCompilerTest.java deleted file mode 100644 index 0b49ffc89..000000000 --- a/core/src/test/java/com/questdb/ql/sort/ComparatorCompilerTest.java +++ /dev/null @@ -1,216 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql.sort; - -import com.questdb.parser.sql.AbstractOptimiserTest; -import com.questdb.ql.RecordSource; -import com.questdb.ql.ops.AbstractVirtualColumn; -import com.questdb.std.BytecodeAssembler; -import com.questdb.std.IntList; -import com.questdb.std.ObjList; -import com.questdb.store.*; -import com.questdb.store.factory.configuration.JournalStructure; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Test; - -public class ComparatorCompilerTest extends AbstractOptimiserTest { - - private final ComparatorCompiler cc = new ComparatorCompiler(new BytecodeAssembler()); - - @Test - public void testAllGetters() throws Exception { - try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("xyz") - .$bool("bool") - .$byte("byte") - .$double("double") - .$float("float") - .$int("int") - .$long("long") - .$date("date") - .$short("short") - .$str("str") - .$sym("sym") - .$())) { - - JournalEntryWriter ew = w.entryWriter(); - - ew.putBool(0, true); - ew.put(1, (byte) 13); - ew.putDouble(2, 20.12); - ew.putFloat(3, 10.15f); - ew.putInt(4, 4); - ew.putLong(5, 9988908080988890L); - ew.putDate(6, 88979879L); - ew.putShort(7, (short) 902); - ew.putStr(8, "complexity made simple"); - ew.putSym(9, "questdb"); - ew.append(); - - ew = w.entryWriter(); - ew.put(1, (byte) 13); - ew.putDouble(2, 20.12); - ew.putFloat(3, 10.15f); - ew.putInt(4, 4); - ew.putLong(5, 9988908080988890L); - ew.putDate(6, 88979879L); - ew.putShort(7, (short) 902); - ew.putStr(8, "complexity made simple"); - ew.putSym(9, "appsicle"); - ew.append(); - - w.commit(); - - IntList indices = new IntList(); - for (int i = 0, n = w.getMetadata().getColumnCount(); i < n; i++) { - indices.add(i + 1); - } - RecordSource rs = compileSource("xyz"); - RecordComparator rc = cc.compile(rs.getMetadata(), indices); - RBTreeSortedRecordSource map = new RBTreeSortedRecordSource(rs, rc, 1024 * 1024, 4 * 1024 * 1024); - - sink.clear(); - printer.print(map, FACTORY_CONTAINER.getFactory()); - } - TestUtils.assertEquals( - "false\t13\t20.120000000000\t10.1500\t4\t9988908080988890\t1970-01-02T00:42:59.879Z\t902\tcomplexity made simple\tappsicle\n" + - "true\t13\t20.120000000000\t10.1500\t4\t9988908080988890\t1970-01-02T00:42:59.879Z\t902\tcomplexity made simple\tquestdb\n", - sink); - } - - @Test - public void testCompileAll() { - TestRecordMetadata m = new TestRecordMetadata().addDistinct(); - IntList indices = new IntList(m.getColumnCount()); - for (int i = 0, n = m.getColumnCount(); i < n; i++) { - indices.add(i + 1); - } - RecordComparator rc = cc.compile(m, indices); - Assert.assertNotNull(rc); - } - - @Test - public void testCompileLarge() { - TestRecordMetadata m = new TestRecordMetadata(); - for (int i = 0; i < 155; i++) { - m.addDistinct(); - } - IntList indices = new IntList(m.getColumnCount()); - for (int i = 0, n = m.getColumnCount(); i < n; i++) { - indices.add(i + 1); - } - RecordComparator rc = cc.compile(m, indices); - Assert.assertNotNull(rc); - } - - @Test - public void testCompileMultipleOfSame() { - TestRecordMetadata m = new TestRecordMetadata(); - for (int i = 0; i < 155; i++) { - m.asType(ColumnType.STRING); - } - IntList indices = new IntList(m.getColumnCount()); - for (int i = 0, n = m.getColumnCount(); i < n; i++) { - indices.add(i + 1); - } - RecordComparator rc = cc.compile(m, indices); - Assert.assertNotNull(rc); - } - - @Test - public void testTwoClassesSameClassloader() { - TestRecordMetadata m = new TestRecordMetadata(); - for (int i = 0; i < 155; i++) { - m.asType(ColumnType.STRING); - } - IntList indices = new IntList(m.getColumnCount()); - for (int i = 0, n = m.getColumnCount(); i < n; i++) { - indices.add(i + 1); - } - RecordComparator rc1 = cc.compile(m, indices); - RecordComparator rc2 = cc.compile(m, indices); - - Assert.assertNotNull(rc1); - Assert.assertNotNull(rc2); - } - - private static class TestColumnMetadata extends AbstractVirtualColumn { - - TestColumnMetadata(int columnType) { - super(columnType, 0); - } - - @Override - public boolean isConstant() { - return false; - } - - @Override - public void prepare(StorageFacade facade) { - - } - } - - private static class TestRecordMetadata extends AbstractRecordMetadata { - private final ObjList columns = new ObjList<>(); - - @Override - public int getColumnCount() { - return columns.size(); - } - - @Override - public int getColumnIndexQuiet(CharSequence name) { - return 0; - } - - @Override - public RecordColumnMetadata getColumnQuick(int index) { - return columns.getQuick(index); - } - - @Override - public int getTimestampIndex() { - return -1; - } - - TestRecordMetadata addDistinct() { - asType(ColumnType.BOOLEAN); - asType(ColumnType.BYTE); - asType(ColumnType.DOUBLE); - asType(ColumnType.FLOAT); - asType(ColumnType.INT); - asType(ColumnType.LONG); - asType(ColumnType.DATE); - asType(ColumnType.SHORT); - asType(ColumnType.STRING); - asType(ColumnType.SYMBOL); - return this; - } - - void asType(int columnType) { - columns.add(new TestColumnMetadata(columnType)); - } - } -} \ No newline at end of file diff --git a/core/src/test/java/com/questdb/ql/sort/RBTreeSortedRecordSourceTest.java b/core/src/test/java/com/questdb/ql/sort/RBTreeSortedRecordSourceTest.java deleted file mode 100644 index bcd401d00..000000000 --- a/core/src/test/java/com/questdb/ql/sort/RBTreeSortedRecordSourceTest.java +++ /dev/null @@ -1,556 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql.sort; - -import com.questdb.ex.ParserException; -import com.questdb.parser.sql.AbstractOptimiserTest; -import com.questdb.parser.sql.QueryError; -import com.questdb.std.Rnd; -import com.questdb.std.time.Dates; -import com.questdb.store.JournalEntryWriter; -import com.questdb.store.JournalWriter; -import com.questdb.store.factory.configuration.JournalStructure; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -public class RBTreeSortedRecordSourceTest extends AbstractOptimiserTest { - - @BeforeClass - public static void setUp() throws Exception { - try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("xyz") - .$int("i") - .$str("str") - .$())) { - int n = 100; - Rnd rnd = new Rnd(); - - for (int i = 0; i < n; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putInt(0, rnd.nextInt()); - ew.putStr(1, rnd.nextChars(2)); - ew.append(); - } - w.commit(); - } - - try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("dupes") - .$int("x") - .$() - )) { - for (int i = 0; i < 10; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putInt(0, i % 2 == 0 ? 10 : 20); - ew.append(); - } - JournalEntryWriter ew = w.entryWriter(); - ew.putInt(0, 30); - ew.append(); - w.commit(); - } - - try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("timeseries") - .$double("d") - .$ts() - .$() - )) { - Rnd rnd = new Rnd(); - long ts = Dates.toMillis(2016, 3, 12, 0, 0); - for (int i = 0; i < 1000; i++) { - JournalEntryWriter ew = w.entryWriter(); - ew.putDouble(0, rnd.nextDouble()); - ew.putDate(1, ts + (rnd.nextPositiveInt() % Dates.DAY_MILLIS)); - ew.append(); - } - w.commit(); - } - } - - @Test - public void testBaseRowIdNestedOrder() throws Exception { - assertThat("-10.000000000000\t34\t2016-03-12T07:40:06.028Z\n" + - "-9.000000000000\t18\t2016-03-12T20:30:19.422Z\n" + - "-8.000000000000\t11\t2016-03-12T13:03:05.265Z\n" + - "-7.000000000000\t13\t2016-03-12T09:45:28.391Z\n" + - "-6.000000000000\t27\t2016-03-12T01:09:44.659Z\n" + - "-5.000000000000\t23\t2016-03-12T17:40:21.589Z\n" + - "-4.000000000000\t14\t2016-03-12T12:19:13.427Z\n" + - "-3.000000000000\t20\t2016-03-12T19:26:07.812Z\n" + - "-2.000000000000\t10\t2016-03-12T09:23:09.879Z\n" + - "-1.000000000000\t14\t2016-03-12T12:25:09.894Z\n" + - "0.000000000000\t540\t2016-03-12T14:47:52.891Z\n" + - "0.000000000000\t20\t2016-03-12T04:10:20.861Z\n" + - "1.000000000000\t47\t2016-03-12T19:13:21.813Z\n" + - "2.000000000000\t30\t2016-03-12T15:58:53.134Z\n" + - "3.000000000000\t33\t2016-03-12T05:05:26.412Z\n" + - "4.000000000000\t26\t2016-03-12T16:52:51.947Z\n" + - "5.000000000000\t28\t2016-03-12T13:51:07.787Z\n" + - "6.000000000000\t23\t2016-03-12T18:26:11.749Z\n" + - "7.000000000000\t15\t2016-03-12T15:04:24.613Z\n" + - "8.000000000000\t28\t2016-03-12T06:12:55.118Z\n" + - "9.000000000000\t16\t2016-03-12T22:14:00.570Z\n" + - "10.000000000000\t10\t2016-03-12T06:04:33.309Z\n", - "(select roundHalfUp(d/100,0) r, count() count, last(timestamp) ts from timeseries order by ts) order by r"); - - } - - @Test - public void testEqualRows() throws Exception { - assertThat("10\n" + - "10\n" + - "10\n" + - "10\n" + - "10\n" + - "20\n" + - "20\n" + - "20\n" + - "20\n" + - "20\n" + - "30\n", - "dupes order by x"); - - } - - @Test - public void testFirstColumnOrderDescending() throws Exception { - assertThat("-10505757\tCC\n" + - "-27395319\tOJ\n" + - "-120660220\tQE\n" + - "-147343840\tLD\n" + - "-230430837\tZZ\n" + - "-235358133\tMY\n" + - "-246923735\tGL\n" + - "-283321892\tJO\n" + - "-292438036\tPG\n" + - "-370796356\tNZ\n" + - "-409854405\tZS\n" + - "-422941535\tPD\n" + - "-483853667\tHR\n" + - "-530317703\tTJ\n" + - "-623471113\tQM\n" + - "-636975106\tZE\n" + - "-661194722\tZO\n" + - "-720881601\tQC\n" + - "-727724771\tCP\n" + - "-731466113\tLY\n" + - "-847531048\tRX\n" + - "-876466531\tOL\n" + - "-907794648\tSS\n" + - "-916132123\tYC\n" + - "-942999384\tVV\n" + - "-1121895896\tVD\n" + - "-1125169127\tEY\n" + - "-1148479920\tTJ\n" + - "-1153445279\tYU\n" + - "-1165635863\tMV\n" + - "-1172180184\tYL\n" + - "-1204245663\tPJ\n" + - "-1234141625\tND\n" + - "-1252906348\tQE\n" + - "-1269042121\tEK\n" + - "-1270731285\tEO\n" + - "-1271909747\tYS\n" + - "-1272693194\tED\n" + - "-1311366306\tML\n" + - "-1418341054\tJG\n" + - "-1424048819\tVS\n" + - "-1436881714\tEH\n" + - "-1465751763\tUS\n" + - "-1515787781\tGO\n" + - "-1533414895\tTM\n" + - "-1538602195\tDZ\n" + - "-1613687261\tBE\n" + - "-1768335227\tSW\n" + - "-1810676855\tLO\n" + - "-1844391305\tWF\n" + - "-1870444467\tRY\n" + - "-1871994006\tZS\n" + - "-1960168360\tUO\n" + - "-2002373666\tQQ\n" + - "-2043803188\tVI\n" + - "-2088317486\tSS\n" + - "-2108151088\tXP\n" + - "-2119387831\tBH\n" + - "-2132716300\tEO\n", - "xyz where i < 100 order by i desc"); - } - - @Test - public void testNestedOrderBy() throws Exception { - final String expected = "-1613687261\tBE\n" + - "-2119387831\tBH\n" + - "-10505757\tCC\n" + - "-727724771\tCP\n" + - "-1538602195\tDZ\n" + - "-1272693194\tED\n" + - "-1436881714\tEH\n" + - "-1269042121\tEK\n" + - "-2132716300\tEO\n" + - "-1270731285\tEO\n" + - "-1125169127\tEY\n" + - "-246923735\tGL\n" + - "-1515787781\tGO\n" + - "-483853667\tHR\n" + - "-1418341054\tJG\n" + - "-283321892\tJO\n" + - "-147343840\tLD\n" + - "-1810676855\tLO\n" + - "-731466113\tLY\n" + - "-1311366306\tML\n" + - "-1165635863\tMV\n" + - "-235358133\tMY\n" + - "-1234141625\tND\n" + - "-370796356\tNZ\n" + - "-27395319\tOJ\n" + - "-876466531\tOL\n" + - "-422941535\tPD\n" + - "-292438036\tPG\n" + - "-1204245663\tPJ\n" + - "-720881601\tQC\n" + - "-1252906348\tQE\n" + - "-120660220\tQE\n" + - "-623471113\tQM\n" + - "-2002373666\tQQ\n" + - "-847531048\tRX\n" + - "-1870444467\tRY\n" + - "-2088317486\tSS\n" + - "-907794648\tSS\n" + - "-1768335227\tSW\n" + - "-1148479920\tTJ\n" + - "-530317703\tTJ\n" + - "-1533414895\tTM\n" + - "-1960168360\tUO\n" + - "-1465751763\tUS\n" + - "-1121895896\tVD\n" + - "-2043803188\tVI\n" + - "-1424048819\tVS\n" + - "-942999384\tVV\n" + - "-1844391305\tWF\n" + - "-2108151088\tXP\n" + - "-916132123\tYC\n" + - "-1172180184\tYL\n" + - "-1271909747\tYS\n" + - "-1153445279\tYU\n" + - "-636975106\tZE\n" + - "-661194722\tZO\n" + - "-1871994006\tZS\n" + - "-409854405\tZS\n" + - "-230430837\tZZ\n"; - - assertThat(expected, "(xyz where i < 100 order by i) order by str, i"); - } - - @Test - public void testNestedOrderByDescending() throws Exception { - final String expected = "-1613687261\tBE\n" + - "-2119387831\tBH\n" + - "-10505757\tCC\n" + - "-727724771\tCP\n" + - "-1538602195\tDZ\n" + - "-1272693194\tED\n" + - "-1436881714\tEH\n" + - "-1269042121\tEK\n" + - "-1270731285\tEO\n" + - "-2132716300\tEO\n" + - "-1125169127\tEY\n" + - "-246923735\tGL\n" + - "-1515787781\tGO\n" + - "-483853667\tHR\n" + - "-1418341054\tJG\n" + - "-283321892\tJO\n" + - "-147343840\tLD\n" + - "-1810676855\tLO\n" + - "-731466113\tLY\n" + - "-1311366306\tML\n" + - "-1165635863\tMV\n" + - "-235358133\tMY\n" + - "-1234141625\tND\n" + - "-370796356\tNZ\n" + - "-27395319\tOJ\n" + - "-876466531\tOL\n" + - "-422941535\tPD\n" + - "-292438036\tPG\n" + - "-1204245663\tPJ\n" + - "-720881601\tQC\n" + - "-120660220\tQE\n" + - "-1252906348\tQE\n" + - "-623471113\tQM\n" + - "-2002373666\tQQ\n" + - "-847531048\tRX\n" + - "-1870444467\tRY\n" + - "-907794648\tSS\n" + - "-2088317486\tSS\n" + - "-1768335227\tSW\n" + - "-530317703\tTJ\n" + - "-1148479920\tTJ\n" + - "-1533414895\tTM\n" + - "-1960168360\tUO\n" + - "-1465751763\tUS\n" + - "-1121895896\tVD\n" + - "-2043803188\tVI\n" + - "-1424048819\tVS\n" + - "-942999384\tVV\n" + - "-1844391305\tWF\n" + - "-2108151088\tXP\n" + - "-916132123\tYC\n" + - "-1172180184\tYL\n" + - "-1271909747\tYS\n" + - "-1153445279\tYU\n" + - "-636975106\tZE\n" + - "-661194722\tZO\n" + - "-409854405\tZS\n" + - "-1871994006\tZS\n" + - "-230430837\tZZ\n"; - - assertThat(expected, "(xyz where i < 100 order by i) order by str, i desc"); - assertString("(xyz where i < 100 order by i) order by str, i desc", 1); - } - - @Test - public void testNestedOrderByExplicitAsc() throws Exception { - final String expected = "-1613687261\tBE\n" + - "-2119387831\tBH\n" + - "-10505757\tCC\n" + - "-727724771\tCP\n" + - "-1538602195\tDZ\n" + - "-1272693194\tED\n" + - "-1436881714\tEH\n" + - "-1269042121\tEK\n" + - "-2132716300\tEO\n" + - "-1270731285\tEO\n" + - "-1125169127\tEY\n" + - "-246923735\tGL\n" + - "-1515787781\tGO\n" + - "-483853667\tHR\n" + - "-1418341054\tJG\n" + - "-283321892\tJO\n" + - "-147343840\tLD\n" + - "-1810676855\tLO\n" + - "-731466113\tLY\n" + - "-1311366306\tML\n" + - "-1165635863\tMV\n" + - "-235358133\tMY\n" + - "-1234141625\tND\n" + - "-370796356\tNZ\n" + - "-27395319\tOJ\n" + - "-876466531\tOL\n" + - "-422941535\tPD\n" + - "-292438036\tPG\n" + - "-1204245663\tPJ\n" + - "-720881601\tQC\n" + - "-1252906348\tQE\n" + - "-120660220\tQE\n" + - "-623471113\tQM\n" + - "-2002373666\tQQ\n" + - "-847531048\tRX\n" + - "-1870444467\tRY\n" + - "-2088317486\tSS\n" + - "-907794648\tSS\n" + - "-1768335227\tSW\n" + - "-1148479920\tTJ\n" + - "-530317703\tTJ\n" + - "-1533414895\tTM\n" + - "-1960168360\tUO\n" + - "-1465751763\tUS\n" + - "-1121895896\tVD\n" + - "-2043803188\tVI\n" + - "-1424048819\tVS\n" + - "-942999384\tVV\n" + - "-1844391305\tWF\n" + - "-2108151088\tXP\n" + - "-916132123\tYC\n" + - "-1172180184\tYL\n" + - "-1271909747\tYS\n" + - "-1153445279\tYU\n" + - "-636975106\tZE\n" + - "-661194722\tZO\n" + - "-1871994006\tZS\n" + - "-409854405\tZS\n" + - "-230430837\tZZ\n"; - - assertThat(expected, "(xyz where i < 100 order by i) order by str asc, i asc"); - } - - @Test - public void testOrderByExpression() throws Exception { - try { - assertThat("", "(xyz where i < 100 order by i) order by str, i+i"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertEquals(46, QueryError.getPosition()); - } - } - - @Test - public void testOrderByString() throws Exception { - try { - assertThat("", "(xyz where i < 100 order by i) order by str, 'i+i'"); - Assert.fail("Exception expected"); - } catch (ParserException e) { - Assert.assertEquals(45, QueryError.getPosition()); - } - } - - @Test - public void testRowIdPassThru() throws Exception { - assertThat("2016-03-12T00:00:00.000Z\t997.471052482297\n" + - "2016-03-12T03:00:00.000Z\t-3263.256266783491\n" + - "2016-03-12T06:00:00.000Z\t2356.131512016518\n" + - "2016-03-12T09:00:00.000Z\t929.843516548567\n" + - "2016-03-12T12:00:00.000Z\t589.176100472390\n" + - "2016-03-12T15:00:00.000Z\t2177.881065221333\n" + - "2016-03-12T18:00:00.000Z\t1411.259807112342\n" + - "2016-03-12T21:00:00.000Z\t645.325834388574\n", - "select timestamp, sum(d) from (timeseries order by timestamp) sample by 3h"); - - } - - @Test - public void testSampleWithNestedOrder() throws Exception { - assertThat("2016-03-12T01:00:00.000Z\t27\n" + - "2016-03-12T04:00:00.000Z\t20\n" + - "2016-03-12T05:00:00.000Z\t33\n" + - "2016-03-12T06:00:00.000Z\t38\n" + - "2016-03-12T07:00:00.000Z\t34\n" + - "2016-03-12T09:00:00.000Z\t23\n" + - "2016-03-12T12:00:00.000Z\t28\n" + - "2016-03-12T13:00:00.000Z\t39\n" + - "2016-03-12T14:00:00.000Z\t540\n" + - "2016-03-12T15:00:00.000Z\t45\n" + - "2016-03-12T16:00:00.000Z\t26\n" + - "2016-03-12T17:00:00.000Z\t23\n" + - "2016-03-12T18:00:00.000Z\t23\n" + - "2016-03-12T19:00:00.000Z\t67\n" + - "2016-03-12T20:00:00.000Z\t18\n" + - "2016-03-12T22:00:00.000Z\t16\n", - "select ts, sum(count) from (select roundHalfUp(d/100,0) r, count() count, last(timestamp) ts from timeseries order by ts) timestamp(ts) sample by 1h"); - } - - @Test - public void testStrSort() throws Exception { - final String expected = "1125579207\tBB\n" + - "-1613687261\tBE\n" + - "-2119387831\tBH\n" + - "-10505757\tCC\n" + - "-727724771\tCP\n" + - "-1538602195\tDZ\n" + - "-1272693194\tED\n" + - "1775935667\tED\n" + - "-1436881714\tEH\n" + - "-1269042121\tEK\n" + - "-2132716300\tEO\n" + - "-1270731285\tEO\n" + - "-1125169127\tEY\n" + - "1637847416\tFB\n" + - "1295866259\tFL\n" + - "422714199\tGH\n" + - "-246923735\tGL\n" + - "-1515787781\tGO\n" + - "426455968\tGP\n" + - "215354468\tGQ\n" + - "1060917944\tGS\n" + - "1728220848\tHB\n" + - "1826239903\tHN\n" + - "-483853667\tHR\n" + - "1876812930\tHV\n" + - "1196016669\tIC\n" + - "1920398380\tIF\n" + - "359345889\tIH\n" + - "82099057\tIH\n" + - "133913299\tIM\n" + - "502711083\tIP\n" + - "1677463366\tIP\n" + - "-1418341054\tJG\n" + - "-283321892\tJO\n" + - "1335037859\tJS\n" + - "-147343840\tLD\n" + - "410717394\tLO\n" + - "-1810676855\tLO\n" + - "614536941\tLT\n" + - "1362833895\tLT\n" + - "-731466113\tLY\n" + - "2076507991\tMF\n" + - "-1311366306\tML\n" + - "-1165635863\tMV\n" + - "-235358133\tMY\n" + - "719189074\tMZ\n" + - "-1234141625\tND\n" + - "-370796356\tNZ\n" + - "-27395319\tOJ\n" + - "-876466531\tOL\n" + - "1234796102\tOT\n" + - "1110979454\tOW\n" + - "-422941535\tPD\n" + - "-292438036\tPG\n" + - "387510473\tPH\n" + - "-1204245663\tPJ\n" + - "838743782\tQB\n" + - "-720881601\tQC\n" + - "-1252906348\tQE\n" + - "-120660220\tQE\n" + - "-623471113\tQM\n" + - "-2002373666\tQQ\n" + - "1743740444\tQS\n" + - "239305284\tRG\n" + - "-847531048\tRX\n" + - "1545253512\tRX\n" + - "-1870444467\tRY\n" + - "-2088317486\tSS\n" + - "-907794648\tSS\n" + - "-1768335227\tSW\n" + - "936627841\tSZ\n" + - "-1148479920\tTJ\n" + - "-530317703\tTJ\n" + - "-1533414895\tTM\n" + - "1751526583\tUM\n" + - "-1960168360\tUO\n" + - "-1465751763\tUS\n" + - "1254404167\tUW\n" + - "1904508147\tUX\n" + - "-1121895896\tVD\n" + - "-2043803188\tVI\n" + - "1503763988\tVL\n" + - "-1424048819\tVS\n" + - "1864113037\tVT\n" + - "-942999384\tVV\n" + - "852921272\tWC\n" + - "-1844391305\tWF\n" + - "1326447242\tWH\n" + - "844704299\tXI\n" + - "-2108151088\tXP\n" + - "-916132123\tYC\n" + - "-1172180184\tYL\n" + - "-1271909747\tYS\n" + - "-1153445279\tYU\n" + - "-636975106\tZE\n" + - "-661194722\tZO\n" + - "-409854405\tZS\n" + - "-1871994006\tZS\n" + - "1920890138\tZZ\n" + - "-230430837\tZZ\n"; - - assertThat(expected, "xyz order by str"); - } - -} \ No newline at end of file diff --git a/core/src/test/java/com/questdb/ql/sys/$ColsRecordSourceTest.java b/core/src/test/java/com/questdb/ql/sys/$ColsRecordSourceTest.java deleted file mode 100644 index c3422866a..000000000 --- a/core/src/test/java/com/questdb/ql/sys/$ColsRecordSourceTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql.sys; - -import com.questdb.parser.sql.AbstractOptimiserTest; -import org.junit.BeforeClass; -import org.junit.Test; - -public class $ColsRecordSourceTest extends AbstractOptimiserTest { - @BeforeClass - public static void setUp() throws Exception { - compiler.execute(FACTORY_CONTAINER.getFactory(), "create table xy (x int, y string, ts date), index(y buckets 30) timestamp(ts) partition by YEAR"); - compiler.execute(FACTORY_CONTAINER.getFactory(), "create table abc (a symbol, b boolean, d double), index(a buckets 70)"); - $ColsRecordSource.init(); - } - - @Test - public void testCompiled() throws Exception { - assertThat("abc\ta\tSYMBOL\tfalse\t\ttrue\t127\n" + - "abc\tb\tBOOLEAN\tfalse\t\tfalse\t0\n" + - "abc\td\tDOUBLE\tfalse\t\tfalse\t0\n" + - "xy\tts\tDATE\ttrue\tYEAR\tfalse\t0\n" + - "xy\tx\tINT\tfalse\t\tfalse\t0\n" + - "xy\ty\tSTRING\tfalse\t\ttrue\t31\n", - "$cols order by table_name, column_name"); - } -} \ No newline at end of file diff --git a/core/src/test/java/com/questdb/ql/sys/$TabsRecordSourceTest.java b/core/src/test/java/com/questdb/ql/sys/$TabsRecordSourceTest.java deleted file mode 100644 index 2606a5c0b..000000000 --- a/core/src/test/java/com/questdb/ql/sys/$TabsRecordSourceTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.ql.sys; - -import com.questdb.parser.sql.AbstractOptimiserTest; -import com.questdb.std.time.DateFormatUtils; -import com.questdb.store.JournalEntryWriter; -import com.questdb.store.JournalWriter; -import org.junit.BeforeClass; -import org.junit.Test; - -public class $TabsRecordSourceTest extends AbstractOptimiserTest { - @BeforeClass - public static void setUp() throws Exception { - try (JournalWriter w = compiler.createWriter(FACTORY_CONTAINER.getFactory(), "create table xyz(x int, y string, timestamp date) timestamp(timestamp) partition by MONTH")) { - JournalEntryWriter ew; - - ew = w.entryWriter(DateFormatUtils.parseDateTime("2016-01-02T00:00:00.000Z")); - ew.putInt(0, 0); - ew.append(); - - ew = w.entryWriter(DateFormatUtils.parseDateTime("2016-02-02T00:00:00.000Z")); - ew.putInt(0, 1); - ew.append(); - - w.commit(); - } - $TabsRecordSource.init(); - } - - @Test - public void testAsSubQuery() throws Exception { - assertThat("1\n", "select count() from ($tabs order by last_modified desc)"); - } - - @Test - public void testCompiled() throws Exception { - assertThat("xyz\tMONTH\t2\t3\t9703504\n", "select name, partition_by, partition_count, column_count, size from $tabs"); - } - - @Test - public void testInJoin() throws Exception { - assertThat("xyz\txyz\n", "select a.name, b.name from $tabs a cross join $tabs b"); - } -} \ No newline at end of file diff --git a/core/src/test/java/com/questdb/store/IteratorTest.java b/core/src/test/java/com/questdb/store/IteratorTest.java deleted file mode 100644 index 8eec0913e..000000000 --- a/core/src/test/java/com/questdb/store/IteratorTest.java +++ /dev/null @@ -1,376 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.store; - -import com.questdb.model.Quote; -import com.questdb.std.NumericException; -import com.questdb.std.ObjList; -import com.questdb.std.ex.JournalException; -import com.questdb.std.time.DateFormatUtils; -import com.questdb.store.factory.WriterFactory; -import com.questdb.store.query.iter.*; -import com.questdb.test.tools.AbstractTest; -import com.questdb.test.tools.TestUtils; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.CyclicBarrier; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -@Ignore -public class IteratorTest extends AbstractTest { - - private final Comparator comparator = (o1, o2) -> { - long x = o1.getTimestamp(); - long y = o2.getTimestamp(); - return Long.compare(x, y); - }; - - @Test - @SuppressWarnings("unused") - public void testBufferedIncrementIterator() throws Exception { - getFactory().writer(Quote.class).close(); - try (Journal r = getFactory().reader(Quote.class)) { - try (JournalWriter w = getFactory().writer(Quote.class)) { - try (JournalWriter origin = getFactory().writer(Quote.class, "origin")) { - TestUtils.generateQuoteData(origin, 10000); - - int count = 0; - for (Quote q : JournalIterators.incrementBufferedIterator(r)) { - count++; - } - - Assert.assertEquals(0, count); - w.append(origin.query().all().asResultSet().subset(0, 5000)); - w.commit(); - - for (Quote q : JournalIterators.incrementBufferedIterator(r)) { - count++; - } - Assert.assertEquals(5000, count); - w.append(origin.query().all().asResultSet().subset(5000, 10000)); - w.commit(); - - count = 0; - for (Quote q : JournalIterators.incrementBufferedIterator(r)) { - count++; - } - Assert.assertEquals(5000, count); - } - } - } - } - - @Test - public void testEmptyPartitionFollowedByNonEmpty() throws Exception { - try (JournalWriter w = getFactory().writer(Quote.class)) { - w.getAppendPartition(DateFormatUtils.parseDateTime("2012-01-10T10:00:00.000Z")); - w.append(new Quote().setSym("TST").setTimestamp(DateFormatUtils.parseDateTime("2012-02-10T10:00:00.000Z"))); - Assert.assertTrue(w.iterator().hasNext()); - } - } - - @Test - @SuppressWarnings("unused") - public void testIncrementIterator() throws Exception { - // create empty - getFactory().writer(Quote.class).close(); - try (Journal r = getFactory().reader(Quote.class)) { - try (JournalWriter w = getFactory().writer(Quote.class)) { - try (JournalWriter origin = getFactory().writer(Quote.class, "origin")) { - TestUtils.generateQuoteData(origin, 10000); - - int count = 0; - for (Quote q : JournalIterators.incrementIterator(r)) { - count++; - } - - Assert.assertEquals(0, count); - w.append(origin.query().all().asResultSet().subset(0, 5000)); - w.commit(); - - for (Quote q : JournalIterators.incrementIterator(r)) { - count++; - } - Assert.assertEquals(5000, count); - w.append(origin.query().all().asResultSet().subset(5000, 10000)); - w.commit(); - - count = 0; - for (Quote q : JournalIterators.incrementIterator(r)) { - count++; - } - Assert.assertEquals(5000, count); - } - } - } - } - - @Test - public void testJournalIterator() throws JournalException, NumericException { - - try (JournalWriter w = getFactory().writer(Quote.class)) { - TestUtils.generateQuoteData(w, 1000); - - try (Journal r = getFactory().reader(Quote.class)) { - - List posList = new ArrayList<>((int) r.size()); - for (Quote q : r) { - posList.add(q); - } - - int i = 0; - for (Quote q : JournalIterators.bufferedIterator(r)) { - Assert.assertEquals(q, posList.get(i++)); - } - i = 0; - for (Quote q : r.query().all().bufferedIterator()) { - Assert.assertEquals(q, posList.get(i++)); - } - i = 0; - for (Quote q : r.getPartition(0, true).bufferedIterator()) { - Assert.assertEquals(q, posList.get(i++)); - } - } - } - } - - @Test - public void testJournalParallelIterator() throws Exception { - try (JournalWriter w = getFactory().writer(Quote.class)) { - TestUtils.generateQuoteData(w, 100000); - try (Journal r = getFactory().reader(Quote.class)) { - try (Journal r2 = getFactory().reader(Quote.class)) { - try (ConcurrentIterator it = JournalIterators.concurrentIterator(r)) { - TestUtils.assertEquals(JournalIterators.bufferedIterator(r2), it); - } - } - } - } - } - - @Test - public void testMerge() throws Exception { - populateQuotes(); - ObjList> journals = new ObjList>() {{ - add(getFactory().reader(Quote.class, "quote-0")); - add(getFactory().reader(Quote.class, "quote-1")); - add(getFactory().reader(Quote.class, "quote-2")); - add(getFactory().reader(Quote.class, "quote-3")); - add(getFactory().reader(Quote.class, "quote-4")); - }}; - - try { - - List> list = new ArrayList<>(); - for (int i = 0; i < journals.size(); i++) { - list.add(JournalIterators.bufferedIterator(journals.get(i))); - } - - long ts = 0; - for (Quote q : MergingIterator.merge(list, comparator)) { - Assert.assertTrue(ts <= q.getTimestamp()); - ts = q.getTimestamp(); - } - } finally { - for (int i = 0, n = journals.size(); i < n; i++) { - journals.getQuick(i).close(); - } - } - } - - @Test - public void testMergeAppend() throws Exception { - populateQuotes(); - ObjList> journals = new ObjList>() {{ - add(getFactory().reader(Quote.class, "quote-0")); - add(getFactory().reader(Quote.class, "quote-1")); - add(getFactory().reader(Quote.class, "quote-2")); - add(getFactory().reader(Quote.class, "quote-3")); - add(getFactory().reader(Quote.class, "quote-4")); - }}; - - try { - - try (JournalWriter writer = getFactory().writer(Quote.class, "quote-merge")) { - writer.mergeAppend(JournalIterators.bufferedIterator(journals.get(3))); - writer.commit(); - - - List> list = new ArrayList<>(); - for (int i = 0; i < journals.size(); i++) { - list.add(JournalIterators.bufferedIterator(journals.get(i))); - } - writer.mergeAppend(MergingPeekingIterator.mergePeek(list, comparator)); - writer.commit(); - Assert.assertEquals(60000, writer.size()); - TestUtils.assertOrder(JournalIterators.bufferedIterator(writer)); - } - } finally { - for (int i = 0, n = journals.size(); i < n; i++) { - journals.getQuick(i).close(); - } - } - } - - @Test - public void testMergePeeking() throws Exception { - populateQuotes(); - ObjList> journals = new ObjList>() {{ - add(getFactory().reader(Quote.class, "quote-0")); - add(getFactory().reader(Quote.class, "quote-1")); - add(getFactory().reader(Quote.class, "quote-2")); - add(getFactory().reader(Quote.class, "quote-3")); - add(getFactory().reader(Quote.class, "quote-4")); - }}; - - try { - List> list = new ArrayList<>(); - for (int i = 0; i < journals.size(); i++) { - list.add(JournalIterators.bufferedIterator(journals.get(i))); - } - - long ts = 0; - for (Quote q : MergingPeekingIterator.mergePeek(list, comparator)) { - Assert.assertTrue(ts <= q.getTimestamp()); - ts = q.getTimestamp(); - } - } finally { - for (int i = 0, n = journals.size(); i < n; i++) { - journals.getQuick(i).close(); - } - } - - } - - @Test - public void testMergingIterator() { - ArrayList listA = new ArrayList() {{ - add(1); - add(3); - add(4); - add(4); - add(5); - add(7); - add(9); - add(11); - add(13); - add(14); - add(15); - add(17); - }}; - - ArrayList listB = new ArrayList() {{ - add(1); - add(2); - add(2); - add(4); - add(6); - add(6); - add(8); - add(10); - }}; - - MergingIterator iterator = new MergingIterator().$new(listA.iterator(), listB.iterator(), Integer::compareTo); - - int[] expected = {1, 1, 2, 2, 3, 4, 4, 4, 5, 6, 6, 7, 8, 9, 10, 11, 13, 14, 15, 17}; - int i = 0; - for (int a : iterator) { - Assert.assertEquals(expected[i++], a); - } - } - - @Test - public void testResultSetParallelIterator() throws Exception { - try (JournalWriter w = getFactory().writer(Quote.class)) { - TestUtils.generateQuoteData(w, 100000, new Interval("2014-01-01T00:00:00.000Z", "2014-02-10T00:00:00.000Z")); - try ( - Journal r1 = getFactory().reader(Quote.class); - Journal r2 = getFactory().reader(Quote.class); - ConcurrentIterator expected = JournalIterators.concurrentIterator(r1); - ConcurrentIterator actual = r2.query().all().concurrentIterator()) { - - TestUtils.assertEquals(expected, actual); - } - } - } - - private void populateQuotes() throws InterruptedException { - int count = 5; - CyclicBarrier cyclicBarrier = new CyclicBarrier(count); - CountDownLatch countDownLatch = new CountDownLatch(count); - ExecutorService service = Executors.newCachedThreadPool(); - try { - for (int i = 0; i < count; i++) { - service.submit(new Generator(getFactory(), cyclicBarrier, i, countDownLatch)); - } - countDownLatch.await(); - } finally { - service.shutdown(); - } - } - - private static class Generator implements Runnable { - private final WriterFactory factory; - private final CyclicBarrier barrier; - private final CountDownLatch latch; - private final int index; - - private Generator(WriterFactory factory, CyclicBarrier barrier, int index, CountDownLatch latch) { - this.factory = factory; - this.barrier = barrier; - this.index = index; - this.latch = latch; - } - - @Override - public void run() { - try { - try (JournalWriter w = factory.writer(Quote.class, "quote-" + index)) { - barrier.await(); - - Quote p = new Quote(); - - long t = System.currentTimeMillis(); - for (int i = 0; i < 10000; i++) { - p.setTimestamp(t + i); - p.setSym(String.valueOf(i % 20)); - p.setAsk(i * 1.04598 + i); - w.append(p); - } - w.commit(); - latch.countDown(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - } -} diff --git a/core/src/test/java/com/questdb/test/tools/HttpTestUtils.java b/core/src/test/java/com/questdb/test/tools/HttpTestUtils.java deleted file mode 100644 index 56d47e1d6..000000000 --- a/core/src/test/java/com/questdb/test/tools/HttpTestUtils.java +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************* - * ___ _ ____ ____ - * / _ \ _ _ ___ ___| |_| _ \| __ ) - * | | | | | | |/ _ \/ __| __| | | | _ \ - * | |_| | |_| | __/\__ \ |_| |_| | |_) | - * \__\_\\__,_|\___||___/\__|____/|____/ - * - * Copyright (C) 2014-2018 Appsicle - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - ******************************************************************************/ - -package com.questdb.test.tools; - -import org.apache.http.Header; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.config.Registry; -import org.apache.http.config.RegistryBuilder; -import org.apache.http.conn.socket.ConnectionSocketFactory; -import org.apache.http.conn.socket.PlainConnectionSocketFactory; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.mime.MultipartEntityBuilder; -import org.apache.http.entity.mime.content.FileBody; -import org.apache.http.entity.mime.content.StringBody; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; -import org.apache.http.ssl.SSLContextBuilder; - -import javax.net.ssl.SSLContext; -import java.io.*; - -public class HttpTestUtils { - public static HttpClientBuilder clientBuilder(boolean ssl) throws Exception { - return (ssl ? createHttpClient_AcceptsUntrustedCerts() : HttpClientBuilder.create()); - } - - public static void copy(InputStream is, OutputStream os) throws IOException { - byte[] buf = new byte[4096]; - int l; - while ((l = is.read(buf)) > 0) { - os.write(buf, 0, l); - } - } - - public static void download(HttpClientBuilder b, String url, File out) throws IOException { - try ( - CloseableHttpClient client = b.build(); - CloseableHttpResponse r = client.execute(new HttpGet(url)); - FileOutputStream fos = new FileOutputStream(out) - ) { - copy(r.getEntity().getContent(), fos); - } - } - - public static Header findHeader(String name, Header[] headers) { - for (Header h : headers) { - if (name.equals(h.getName())) { - return h; - } - } - - return null; - } - - public static int upload(String resource, String url, String schema, StringBuilder response) throws IOException { - HttpPost post = new HttpPost(url); - try (CloseableHttpClient client = HttpClients.createDefault()) { - MultipartEntityBuilder b = MultipartEntityBuilder.create(); - if (schema != null) { - b.addPart("schema", new StringBody(schema, ContentType.TEXT_PLAIN)); - } - b.addPart("data", new FileBody(resourceFile(resource))); - post.setEntity(b.build()); - HttpResponse r = client.execute(post); - - if (response != null) { - InputStream is = r.getEntity().getContent(); - int n; - while ((n = is.read()) > 0) { - response.append((char) n); - } - is.close(); - } - return r.getStatusLine().getStatusCode(); - } - } - - private static HttpClientBuilder createHttpClient_AcceptsUntrustedCerts() throws Exception { - HttpClientBuilder b = HttpClientBuilder.create(); - - // setup a Trust Strategy that allows all certificates. - // - SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, (arg0, arg1) -> true).build(); - - b.setSSLContext(sslContext); - - // here's the special part: - // -- need to create an SSL Socket Factory, to use our weakened "trust strategy"; - // -- and create a Registry, to register it. - // - SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, (s, sslSession) -> true); - Registry socketFactoryRegistry = RegistryBuilder.create() - .register("http", PlainConnectionSocketFactory.getSocketFactory()) - .register("https", sslSocketFactory) - .build(); - - // now, we create connection-manager using our Registry. - // -- allows multi-threaded use - b.setConnectionManager(new PoolingHttpClientConnectionManager(socketFactoryRegistry)); - - return b; - } - - private static File resourceFile(String resource) { - return new File(HttpTestUtils.class.getResource(resource).getFile()); - } - -} -- GitLab