use of herddb.model.DataScanner in project herddb by diennea.
the class DropTablespaceTest method test.
@Test
public void test() 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());
try (DataScanner scan = TestUtils.scan(manager, "SELECT COUNT(*) FROM tblspace1.tsql ", Collections.emptyList())) {
Number count = (Number) scan.consume().get(0).get(0);
assertEquals(0, count.intValue());
}
try (DataScanner scan = TestUtils.scan(manager, "SELECT COUNT(*) FROM systablespaces WHERE tablespace_name=?", Arrays.asList("tblspace1"))) {
Number count = (Number) scan.consume().get(0).get(0);
assertEquals(1, count.intValue());
}
manager.executeStatement(new DropTableSpaceStatement("tblspace1"), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
try (DataScanner scan = TestUtils.scan(manager, "SELECT COUNT(*) FROM systablespaces WHERE tablespace_name=?", Arrays.asList("tblspace1"))) {
Number count = (Number) scan.consume().get(0).get(0);
assertEquals(0, count.intValue());
}
boolean ok = false;
for (int i = 0; i < 100; i++) {
try (DataScanner scan = TestUtils.scan(manager, "SELECT COUNT(*) FROM tblspace1.tsql ", Collections.emptyList())) {
Thread.sleep(200);
} catch (herddb.model.StatementExecutionException expected) {
ok = true;
}
}
assertTrue(ok);
// create again the table space, all data should be lost
CreateTableSpaceStatement st1_2 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
manager.executeStatement(st1_2, 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());
try (DataScanner scan = TestUtils.scan(manager, "SELECT COUNT(*) FROM tblspace1.tsql ", Collections.emptyList())) {
Number count = (Number) scan.consume().get(0).get(0);
assertEquals(0, count.intValue());
}
}
}
use of herddb.model.DataScanner in project herddb by diennea.
the class ProfileEqualsAllocationsTest method simpleEqualsLongTest.
@Test
public void simpleEqualsLongTest() 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 long primary key,n2 long, s1 string)", Collections.emptyList());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1,s1,n2) values(?,?,?,?)", Arrays.asList("mykey", Integer.valueOf(1), "a", Long.valueOf(3))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1,s1,n2) values(?,?,?,?)", Arrays.asList("mykey2", Integer.valueOf(2), "a", Long.valueOf(2))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1,s1,n2) values(?,?,?,?)", Arrays.asList("mykey3", Integer.valueOf(5), "b", Long.valueOf(1))).getUpdateCount());
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql where n1=?", Arrays.asList(5))) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql where n1=?", Arrays.asList(5L))) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql where n1=?", Arrays.asList(5.0))) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql where n1=5", Arrays.asList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
}
}
}
use of herddb.model.DataScanner in project herddb by diennea.
the class ProfileEqualsAllocationsTest method simpleEqualsTest.
@Test
public void simpleEqualsTest() 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,n2 long, s1 string)", Collections.emptyList());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1,s1,n2) values(?,?,?,?)", Arrays.asList("mykey", Integer.valueOf(1), "a", Long.valueOf(3))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1,s1,n2) values(?,?,?,?)", Arrays.asList("mykey2", Integer.valueOf(2), "a", Long.valueOf(2))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1,s1,n2) values(?,?,?,?)", Arrays.asList("mykey3", Integer.valueOf(5), "b", Long.valueOf(1))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1) values(?)", Arrays.asList("mykey4")).getUpdateCount());
{
long _start = System.currentTimeMillis();
for (int i = 0; i < 1; i++) {
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql where k1=?", Arrays.asList("mykey"))) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
if (i % 1000 == 0) {
long _stop = System.currentTimeMillis();
System.out.println(i + " time:" + (_stop - _start) + " ms");
}
}
}
long _stop = System.currentTimeMillis();
System.out.println("time:" + (_stop - _start) + " ms");
}
{
long _start = System.currentTimeMillis();
for (int i = 0; i < 1; i++) {
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql where n1=?", Arrays.asList(5))) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
if (i % 1000 == 0) {
long _stop = System.currentTimeMillis();
System.out.println(i + " time:" + (_stop - _start) + " ms");
}
}
}
long _stop = System.currentTimeMillis();
System.out.println("time:" + (_stop - _start) + " ms");
}
}
}
use of herddb.model.DataScanner in project herddb by diennea.
the class RawSQLTest method simpleCountTest.
@Test
public void simpleCountTest() 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 COUNT(*) as cc FROM tblspace1.tsql", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
assertEquals(Long.valueOf(4), result.get(0).get(0));
assertEquals(Long.valueOf(4), result.get(0).get("cc"));
}
}
try (DataScanner scan1 = scan(manager, "SELECT COUNT(*) FROM tblspace1.tsql", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
assertEquals(Long.valueOf(4), result.get(0).get(0));
assertEquals(Long.valueOf(4), result.get(0).get("expr$0"));
}
{
try (DataScanner scan1 = scan(manager, "SELECT COUNT(*) as cc FROM tblspace1.tsql WHERE k1='mykey3'", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
assertEquals(Long.valueOf(1), result.get(0).get(0));
assertEquals(Long.valueOf(1), result.get(0).get("cc"));
}
}
{
try (DataScanner scan1 = scan(manager, "SELECT COUNT(*),k1 FROM tblspace1.tsql", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
Assert.fail();
} catch (StatementExecutionException error) {
assertTrue("field k1 MUST appear in GROUP BY clause".equals(error.getMessage()) || error.getMessage().equals("From line 1, column 17 to line 1, column 18: Expression 'K1' is not being grouped"));
}
}
{
try (DataScanner scan1 = scan(manager, "SELECT COUNT(*) as cc,k1 FROM tblspace1.tsql GROUP BY k1", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(4, result.size());
for (DataAccessor t : result) {
assertEquals(Long.valueOf(1), t.get("cc"));
switch(t.get("k1") + "") {
case "mykey":
case "mykey2":
case "mykey3":
case "mykey4":
break;
default:
fail();
}
}
}
}
}
}
use of herddb.model.DataScanner 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());
}
}
}
}
Aggregations