Search in sources :

Example 56 with MemoryMetadataStorageManager

use of herddb.mem.MemoryMetadataStorageManager 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());
        }
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DataScanner(herddb.model.DataScanner) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) DataAccessor(herddb.utils.DataAccessor) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 57 with MemoryMetadataStorageManager

use of herddb.mem.MemoryMetadataStorageManager 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");
        }
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DataScanner(herddb.model.DataScanner) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) List(java.util.List) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 58 with MemoryMetadataStorageManager

use of herddb.mem.MemoryMetadataStorageManager in project herddb by diennea.

the class RecordTooBigTest method update.

@Test(expected = RecordTooBigException.class)
public void update() throws Exception {
    String nodeId = "localhost";
    try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
        manager.setMaxLogicalPageSize(160);
        manager.start();
        CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
        manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), NO_TRANSACTION);
        manager.waitForTablespace("tblspace1", 10000);
        execute(manager, "CREATE TABLE tblspace1.tsql (k1 string, s1 string, n1 int, primary key(k1))", Collections.emptyList());
        try {
            assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,s1,n1) values(?,?,?)", Arrays.asList("mykey", "a", Integer.valueOf(1234))).getUpdateCount());
        } catch (Exception e) {
            e.printStackTrace();
            fail("Got an unexpected of exception, insertion failed!");
        }
        try {
            assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.tsql SET s1 = ? WHERE k1 = ?", Arrays.asList(RandomString.getInstance().nextString(25), "mykey")).getUpdateCount());
        } catch (IllegalStateException e) {
            e.printStackTrace();
            fail("Got a wrong type of exception, record failed during page insertion!");
        }
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) RandomString(herddb.utils.RandomString) RecordTooBigException(herddb.model.RecordTooBigException) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 59 with MemoryMetadataStorageManager

use of herddb.mem.MemoryMetadataStorageManager in project herddb by diennea.

the class RawSQLTest method updateTest.

@Test
public void updateTest() 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,s1) values(?,?,?)", Arrays.asList("mykey", Integer.valueOf(1234), "value1")).getUpdateCount());
        assertEquals(1, scan(manager, "SELECT * FROM tblspace1.tsql where s1='value1'", Collections.emptyList()).consumeAndClose().size());
        assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.tsql set s1=k1  where k1=?", Arrays.asList("mykey")).getUpdateCount());
        assertEquals(1, scan(manager, "SELECT * FROM tblspace1.tsql where s1='mykey'", Collections.emptyList()).consumeAndClose().size());
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DBManager(herddb.core.DBManager) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) RawString(herddb.utils.RawString) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 60 with MemoryMetadataStorageManager

use of herddb.mem.MemoryMetadataStorageManager 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();
                    }
                }
            }
        }
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DBManager(herddb.core.DBManager) DataScanner(herddb.model.DataScanner) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) RuntimeProjectedDataAccessor(herddb.model.planner.ProjectOp.ZeroCopyProjection.RuntimeProjectedDataAccessor) DataAccessor(herddb.utils.DataAccessor) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) List(java.util.List) RawString(herddb.utils.RawString) StatementExecutionException(herddb.model.StatementExecutionException) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Aggregations

MemoryMetadataStorageManager (herddb.mem.MemoryMetadataStorageManager)257 MemoryCommitLogManager (herddb.mem.MemoryCommitLogManager)256 MemoryDataStorageManager (herddb.mem.MemoryDataStorageManager)252 Test (org.junit.Test)247 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)240 DataScanner (herddb.model.DataScanner)156 RawString (herddb.utils.RawString)138 DBManager (herddb.core.DBManager)133 DataAccessor (herddb.utils.DataAccessor)83 Table (herddb.model.Table)80 ScanStatement (herddb.model.commands.ScanStatement)65 CreateTableStatement (herddb.model.commands.CreateTableStatement)57 TranslatedQuery (herddb.sql.TranslatedQuery)55 List (java.util.List)54 Index (herddb.model.Index)40 TransactionContext (herddb.model.TransactionContext)39 CreateIndexStatement (herddb.model.commands.CreateIndexStatement)37 SecondaryIndexSeek (herddb.index.SecondaryIndexSeek)30 RuntimeProjectedDataAccessor (herddb.model.planner.ProjectOp.ZeroCopyProjection.RuntimeProjectedDataAccessor)28 StatementExecutionException (herddb.model.StatementExecutionException)26