use of herddb.mem.MemoryCommitLogManager in project herddb by diennea.
the class RawSQLTest method createIndexOnTableTest.
@Test
public void createIndexOnTableTest() throws Exception {
String nodeId = "localhost";
try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
manager.start();
CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
manager.waitForTablespace("tblspace1", 10000);
execute(manager, "CREATE TABLE tblspace1.tsql (k1 string primary key,n1 int,s1 string," + "INDEX ix1 (n1,s1))", Collections.emptyList());
execute(manager, "DROP INDEX tblspace1.ix1", Collections.emptyList());
}
}
use of herddb.mem.MemoryCommitLogManager in project herddb by diennea.
the class RawSQLTest method limitsTest.
@Test
public void limitsTest() throws Exception {
String nodeId = "localhost";
try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
manager.start();
CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
manager.waitForTablespace("tblspace1", 10000);
execute(manager, "CREATE TABLE tblspace1.tsql (k1 string primary key,n1 int,s1 string)", Collections.emptyList());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey", Integer.valueOf(1))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey2", Integer.valueOf(2))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey3", Integer.valueOf(3))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1) values(?)", Arrays.asList("mykey4")).getUpdateCount());
// scan performed at "scan time"
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql ORDER BY k1 LIMIT 1", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
assertEquals(RawString.of("mykey"), result.get(0).get("k1"));
}
if (manager.getPlanner() instanceof SQLPlanner) {
try (DataScanner scan1 = scan(manager, "SELECT TOP 1 * FROM tblspace1.tsql ORDER BY k1", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
assertEquals(RawString.of("mykey"), result.get(0).get("k1"));
}
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql ORDER BY k1 LIMIT 1,1", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
assertEquals(RawString.of("mykey2"), result.get(0).get("k1"));
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql ORDER BY k1 LIMIT 1,2", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(2, result.size());
assertEquals(RawString.of("mykey2"), result.get(0).get("k1"));
assertEquals(RawString.of("mykey3"), result.get(1).get("k1"));
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql ORDER BY k1 LIMIT 10", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(4, result.size());
assertEquals(RawString.of("mykey"), result.get(0).get("k1"));
assertEquals(RawString.of("mykey2"), result.get(1).get("k1"));
assertEquals(RawString.of("mykey3"), result.get(2).get("k1"));
assertEquals(RawString.of("mykey4"), result.get(3).get("k1"));
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql ORDER BY k1 LIMIT 10,10", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(0, result.size());
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql ORDER BY k1 LIMIT 4,10", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(0, result.size());
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql ORDER BY k1 LIMIT 3,10", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
assertEquals(RawString.of("mykey4"), result.get(0).get("k1"));
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql LIMIT 3", Collections.emptyList(), 2, TransactionContext.NO_TRANSACTION)) {
List<DataAccessor> result = scan1.consume();
assertEquals(2, result.size());
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql LIMIT ?", Arrays.asList(3), TransactionContext.NO_TRANSACTION)) {
List<DataAccessor> result = scan1.consume();
assertEquals(3, result.size());
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql LIMIT 1,2", Collections.emptyList(), TransactionContext.NO_TRANSACTION)) {
List<DataAccessor> result = scan1.consume();
assertEquals(2, result.size());
}
if (manager.getPlanner() instanceof CalcitePlanner) {
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql LIMIT ?,?", Arrays.asList(1, 2), TransactionContext.NO_TRANSACTION)) {
List<DataAccessor> result = scan1.consume();
assertEquals(2, result.size());
}
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql " + "WHERE k1 <> ? LIMIT ?", Arrays.asList("aaa", 3), TransactionContext.NO_TRANSACTION)) {
List<DataAccessor> result = scan1.consume();
assertEquals(3, result.size());
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql " + "WHERE k1 <> ? LIMIT 2,?", Arrays.asList("aaa", 3), TransactionContext.NO_TRANSACTION)) {
List<DataAccessor> result = scan1.consume();
assertEquals(2, result.size());
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql " + "WHERE k1 <> ? ORDER BY k1 LIMIT ?", Arrays.asList("aaa", 3), TransactionContext.NO_TRANSACTION)) {
List<DataAccessor> result = scan1.consume();
assertEquals(3, result.size());
}
try (DataScanner scan1 = scan(manager, "SELECT k1, count(*) FROM tblspace1.tsql " + "WHERE k1 <> ? GROUP BY k1 ORDER BY k1 LIMIT ?", Arrays.asList("aaa", 3), TransactionContext.NO_TRANSACTION)) {
List<DataAccessor> result = scan1.consume();
assertEquals(3, result.size());
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql LIMIT ?", Arrays.asList(0), TransactionContext.NO_TRANSACTION)) {
List<DataAccessor> result = scan1.consume();
assertEquals(4, result.size());
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql LIMIT ?", Collections.emptyList(), TransactionContext.NO_TRANSACTION)) {
fail();
} catch (MissingJDBCParameterException err) {
assertEquals(1, err.getIndex());
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql " + "ORDER BY k1 LIMIT 3", Collections.emptyList(), 5, TransactionContext.NO_TRANSACTION)) {
List<DataAccessor> result = scan1.consume();
assertEquals(3, result.size());
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql " + "ORDER BY k1 ", Collections.emptyList(), 2, TransactionContext.NO_TRANSACTION)) {
List<DataAccessor> result = scan1.consume();
assertEquals(2, result.size());
}
}
}
use of herddb.mem.MemoryCommitLogManager in project herddb by diennea.
the class RawSQLTest method simpleExitLoopTest.
@Test
public void simpleExitLoopTest() throws Exception {
String nodeId = "localhost";
try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
manager.start();
CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
manager.waitForTablespace("tblspace1", 10000);
execute(manager, "CREATE TABLE tblspace1.tsql (k1 string primary key,n1 int,s1 string)", Collections.emptyList());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey", Integer.valueOf(1))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey2", Integer.valueOf(2))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey3", Integer.valueOf(3))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1) values(?)", Arrays.asList("mykey4")).getUpdateCount());
{
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql LIMIT 1", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql LIMIT 2", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(2, result.size());
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql LIMIT 10", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(4, result.size());
}
}
}
}
use of herddb.mem.MemoryCommitLogManager in project herddb by diennea.
the class RawSQLTest method limitsAggregatesTest.
@Test
public void limitsAggregatesTest() throws Exception {
String nodeId = "localhost";
try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
manager.start();
CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
manager.waitForTablespace("tblspace1", 10000);
execute(manager, "CREATE TABLE tblspace1.tsql (k1 string primary key,n1 int,s1 string)", Collections.emptyList());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey", Integer.valueOf(1))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey2", Integer.valueOf(2))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey3", Integer.valueOf(2))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1) values(?)", Arrays.asList("mykey4")).getUpdateCount());
// scan performed after aggregation
try (DataScanner scan1 = scan(manager, "SELECT COUNT(*) as cc,k1 " + "FROM tblspace1.tsql " + "GROUP BY k1 " + "ORDER BY k1 DESC", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(4, result.size());
assertEquals(RawString.of("mykey4"), result.get(0).get("k1"));
assertEquals(Long.valueOf(1), result.get(0).get("cc"));
assertEquals(RawString.of("mykey3"), result.get(1).get("k1"));
assertEquals(Long.valueOf(1), result.get(1).get("cc"));
assertEquals(RawString.of("mykey2"), result.get(2).get("k1"));
assertEquals(Long.valueOf(1), result.get(2).get("cc"));
assertEquals(RawString.of("mykey"), result.get(3).get("k1"));
assertEquals(Long.valueOf(1), result.get(3).get("cc"));
}
try (DataScanner scan1 = scan(manager, "SELECT COUNT(*) as cc,k1 FROM tblspace1.tsql GROUP BY k1 ORDER BY k1 DESC LIMIT 1,1", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
assertEquals(RawString.of("mykey3"), result.get(0).get("k1"));
assertEquals(Long.valueOf(1), result.get(0).get("cc"));
}
try (DataScanner scan1 = scan(manager, "SELECT COUNT(*) as alias,k1 FROM tblspace1.tsql GROUP BY k1 ORDER BY k1 DESC LIMIT 1,2", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(2, result.size());
assertEquals(RawString.of("mykey3"), result.get(0).get("k1"));
assertEquals(Long.valueOf(1), result.get(0).get("alias"));
assertEquals(RawString.of("mykey2"), result.get(1).get("k1"));
assertEquals(Long.valueOf(1), result.get(1).get("alias"));
}
try (DataScanner scan1 = scan(manager, "SELECT COUNT(*) as cc,k1 FROM tblspace1.tsql GROUP BY k1 ORDER BY k1 DESC LIMIT 10", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(4, result.size());
assertEquals(RawString.of("mykey4"), result.get(0).get("k1"));
assertEquals(Long.valueOf(1), result.get(0).get("cc"));
assertEquals(RawString.of("mykey3"), result.get(1).get("k1"));
assertEquals(Long.valueOf(1), result.get(1).get("cc"));
assertEquals(RawString.of("mykey2"), result.get(2).get("k1"));
assertEquals(Long.valueOf(1), result.get(2).get("cc"));
assertEquals(RawString.of("mykey"), result.get(3).get("k1"));
assertEquals(Long.valueOf(1), result.get(3).get("cc"));
}
try (DataScanner scan1 = scan(manager, "SELECT COUNT(*),k1 FROM tblspace1.tsql GROUP BY k1 ORDER BY k1 DESC LIMIT 10,10", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(0, result.size());
}
try (DataScanner scan1 = scan(manager, "SELECT COUNT(*),k1 FROM tblspace1.tsql GROUP BY k1 ORDER BY k1 DESC LIMIT 4,10", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(0, result.size());
}
try (DataScanner scan1 = scan(manager, "SELECT COUNT(*) as cc,k1 FROM tblspace1.tsql GROUP BY k1 ORDER BY k1 DESC LIMIT 3,10", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
assertEquals(RawString.of("mykey"), result.get(0).get("k1"));
assertEquals(Long.valueOf(1), result.get(0).get("cc"));
}
try (DataScanner scan1 = scan(manager, "SELECT COUNT(*) as cc,n1 FROM tblspace1.tsql GROUP BY n1 ORDER BY cc", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(3, result.size());
assertNull(result.get(0).get("n1"));
assertEquals(Long.valueOf(1), result.get(0).get("cc"));
assertEquals(Integer.valueOf(1), result.get(1).get("n1"));
assertEquals(Long.valueOf(1), result.get(1).get("cc"));
assertEquals(Integer.valueOf(2), result.get(2).get("n1"));
assertEquals(Long.valueOf(2), result.get(2).get("cc"));
}
try (DataScanner scan1 = scan(manager, "SELECT COUNT(*) as cc,n1" + " FROM tblspace1.tsql" + " WHERE n1 is not null" + " GROUP BY n1" + " ORDER BY cc", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
for (DataAccessor ac : result) {
System.out.println("ac:" + ac.toMap());
}
assertEquals(Integer.valueOf(1), result.get(0).get("n1"));
assertEquals(Long.valueOf(1), result.get(0).get("cc"));
assertEquals(Integer.valueOf(2), result.get(1).get("n1"));
assertEquals(Long.valueOf(2), result.get(1).get("cc"));
assertEquals(2, result.size());
}
}
}
use of herddb.mem.MemoryCommitLogManager in project herddb by diennea.
the class RawSQLTest method currentTimestampTest.
@Test
public void currentTimestampTest() throws Exception {
String nodeId = "localhost";
try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
manager.start();
CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
manager.waitForTablespace("tblspace1", 10000);
execute(manager, "CREATE TABLE tblspace1.tsql (k1 string,n1 int,s1 string,t1 timestamp, primary key (t1) )", Collections.emptyList());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1,t1) values(?,?,CURRENT_TIMESTAMP)", Arrays.asList("mykey", Integer.valueOf(1234))).getUpdateCount());
Thread.sleep(500);
assertEquals(1234, scan(manager, "SELECT n1 FROM tblspace1.tsql WHERE t1<CURRENT_TIMESTAMP", Collections.emptyList()).consume().get(0).get("n1"));
java.sql.Timestamp now = new java.sql.Timestamp(System.currentTimeMillis());
if (manager.getPlanner() instanceof SQLPlanner) {
// non standard syntax, needs a decoding
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1,t1) values(?,?,'" + RecordSerializer.getUTCTimestampFormatter().format(now.toInstant()) + "')", Arrays.asList("mykey2", Integer.valueOf(1234))).getUpdateCount());
}
java.sql.Timestamp now2 = new java.sql.Timestamp(now.getTime() + 1000);
// standard syntax, but timezone dependant
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1,t1) values(?,?,{ts '" + now2 + "'})", Arrays.asList("mykey3", Integer.valueOf(1234))).getUpdateCount());
}
}
Aggregations