Search in sources :

Example 86 with MemoryCommitLogManager

use of herddb.mem.MemoryCommitLogManager 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"));
            }
        }
        if (manager.getPlanner() instanceof SQLPlanner) {
            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("count(*)"));
            }
        }
        {
            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) DataScanner(herddb.model.DataScanner) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) DataAccessor(herddb.utils.DataAccessor) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) List(java.util.List) RawString(herddb.utils.RawString) SQLPlanner(herddb.sql.SQLPlanner) StatementExecutionException(herddb.model.StatementExecutionException) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 87 with MemoryCommitLogManager

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

the class RecordTooBigTest method insert.

@Test(expected = RecordTooBigException.class)
public void insert() throws Exception {
    String nodeId = "localhost";
    try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
        manager.setMaxLogicalPageSize(150);
        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 (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) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 88 with MemoryCommitLogManager

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

the class SimpleIndexAccessTest method multipleColumnPrimaryKeyPrefixScanTest.

@Test
public void multipleColumnPrimaryKeyPrefixScanTest() 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, " + "primary key (k1,n1)" + ")", Collections.emptyList());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey", Integer.valueOf(1234))).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey", Integer.valueOf(1235))).getUpdateCount());
        {
            TranslatedQuery translate = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT k1 as theKey,'one' as theStringConstant,3  LongConstant FROM tblspace1.tsql where k1 = ?", Arrays.asList("mykey"), true, true, false, -1);
            ScanStatement scan = translate.plan.mainStatement.unwrap(ScanStatement.class);
            assertTrue(scan.getPredicate().getIndexOperation() instanceof PrimaryIndexPrefixScan);
            try (DataScanner scan1 = manager.scan(scan, translate.context, TransactionContext.NO_TRANSACTION)) {
                assertEquals(2, scan1.consume().size());
            }
        }
        {
            TranslatedQuery translate = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT k1 as theKey,'one' as theStringConstant,3  LongConstant FROM tblspace1.tsql where k1 = ? and n1 <> 1235", Arrays.asList("mykey"), true, true, false, -1);
            ScanStatement scan = translate.plan.mainStatement.unwrap(ScanStatement.class);
            assertTrue(scan.getPredicate().getIndexOperation() instanceof PrimaryIndexPrefixScan);
            try (DataScanner scan1 = manager.scan(scan, translate.context, TransactionContext.NO_TRANSACTION)) {
                assertEquals(1, scan1.consume().size());
            }
        }
        {
            TranslatedQuery translate = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT k1 as theKey,'one' as theStringConstant,3  LongConstant FROM tblspace1.tsql where k1 = ? and n1 = 1235", Arrays.asList("mykey"), true, true, false, -1);
            ScanStatement scan = translate.plan.mainStatement.unwrap(ScanStatement.class);
            assertTrue(scan.getPredicate().getIndexOperation() instanceof PrimaryIndexSeek);
            try (DataScanner scan1 = manager.scan(scan, translate.context, TransactionContext.NO_TRANSACTION)) {
                assertEquals(1, scan1.consume().size());
            }
        }
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) PrimaryIndexSeek(herddb.index.PrimaryIndexSeek) TranslatedQuery(herddb.sql.TranslatedQuery) DataScanner(herddb.model.DataScanner) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) PrimaryIndexPrefixScan(herddb.index.PrimaryIndexPrefixScan) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) ScanStatement(herddb.model.commands.ScanStatement) Test(org.junit.Test)

Example 89 with MemoryCommitLogManager

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

the class SimpleOperatorsTest method simpleArithmeticOperationsTest.

@Test
public void simpleArithmeticOperationsTest() 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, l1 long, t1 timestamp, nu string, b1 bool, d1 double)", Collections.emptyList());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1,l1,t1,nu,b1,d1) values(?,?,?,?,?,?,?)", Arrays.asList("mykey", Integer.valueOf(1), Long.valueOf(2), new java.sql.Timestamp(System.currentTimeMillis()), null, Boolean.valueOf(true), Double.valueOf(1.5))).getUpdateCount());
        // Simple constants
        try (DataScanner scan1 = scan(manager, "SELECT 0.5 FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(0.5, scan1.consume().get(0).get(0));
        }
        try (DataScanner scan1 = scan(manager, "SELECT 1 FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(1L, ((Number) scan1.consume().get(0).get(0)).longValue());
        }
        try (DataScanner scan1 = scan(manager, "SELECT 'asd' FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals("asd", scan1.consume().get(0).get(0).toString());
        }
        try (DataScanner scan1 = scan(manager, "SELECT true FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(true, scan1.consume().get(0).get(0));
        }
        try (DataScanner scan1 = scan(manager, "SELECT false FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(false, scan1.consume().get(0).get(0));
        }
        try (DataScanner scan1 = scan(manager, "SELECT CURRENT_TIMESTAMP FROM tblspace1.tsql", Collections.emptyList())) {
            long instant = ((java.sql.Timestamp) scan1.consume().get(0).get(0)).getTime();
            assertTrue(Math.abs(System.currentTimeMillis() - instant) < 200);
        }
        // Simple column access
        try (DataScanner scan1 = scan(manager, "SELECT k1 FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals("mykey", scan1.consume().get(0).get(0).toString());
        }
        try (DataScanner scan1 = scan(manager, "SELECT n1 FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(1, scan1.consume().get(0).get(0));
        }
        try (DataScanner scan1 = scan(manager, "SELECT l1 FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(2L, scan1.consume().get(0).get(0));
        }
        try (DataScanner scan1 = scan(manager, "SELECT t1 FROM tblspace1.tsql", Collections.emptyList())) {
            final Timestamp currentTs = (java.sql.Timestamp) scan1.consume().get(0).get(0);
            System.out.println("currentTs:" + currentTs);
            long instant = currentTs.getTime();
            long delta = System.currentTimeMillis() - instant;
            System.out.println("delta:" + delta);
            assertTrue("too slow ? " + delta, delta < 60000);
        }
        try (DataScanner scan1 = scan(manager, "SELECT nu FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(null, scan1.consume().get(0).get(0));
        }
        try (DataScanner scan1 = scan(manager, "SELECT b1 FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(true, scan1.consume().get(0).get(0));
        }
        try (DataScanner scan1 = scan(manager, "SELECT d1 FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(1.5, scan1.consume().get(0).get(0));
        }
        // Simple expressions
        try (DataScanner scan1 = scan(manager, "SELECT 4+3+2 FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(9.0, scan1.consume().get(0).get(0));
        }
        try (DataScanner scan1 = scan(manager, "SELECT 7-3-2 FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(2.0, scan1.consume().get(0).get(0));
        }
        try (DataScanner scan1 = scan(manager, "SELECT 1/2/2 FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(0.25, scan1.consume().get(0).get(0));
        }
        try (DataScanner scan1 = scan(manager, "SELECT 4*3*2 FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(24.0, scan1.consume().get(0).get(0));
        }
        // Functions
        try (DataScanner scan1 = scan(manager, "SELECT lower('CiAo') FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals("ciao", scan1.consume().get(0).get(0).toString());
        }
        try (DataScanner scan1 = scan(manager, "SELECT upper('CiAo') FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals("CIAO", scan1.consume().get(0).get(0).toString());
        }
        try (DataScanner scan1 = scan(manager, "SELECT abs(-123) FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(123L, ((Number) scan1.consume().get(0).get(0)).longValue());
        }
        try (DataScanner scan1 = scan(manager, "SELECT abs(123) FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(123L, ((Number) scan1.consume().get(0).get(0)).longValue());
        }
        try (DataScanner scan1 = scan(manager, "SELECT abs(-123.5) FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(123.5, scan1.consume().get(0).get(0));
        }
        try (DataScanner scan1 = scan(manager, "SELECT abs(123.5) FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(123.5, scan1.consume().get(0).get(0));
        }
        try (DataScanner scan1 = scan(manager, "SELECT round(98765.98765) FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(98766.0, scan1.consume().get(0).get(0));
        }
        try (DataScanner scan1 = scan(manager, "SELECT round(98765.98765, 2) FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(98765.99, scan1.consume().get(0).get(0));
        }
        try (DataScanner scan1 = scan(manager, "SELECT round(98765.98765, -2) FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(98800.0, scan1.consume().get(0).get(0));
        }
        // Warning: jSQLParser doesn't handle this kind of expressions in select clause
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 1<2", Collections.emptyList())) {
            assertEquals(1, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 2<1", Collections.emptyList())) {
            assertEquals(0, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 1<1", Collections.emptyList())) {
            assertEquals(0, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 2>1", Collections.emptyList())) {
            assertEquals(1, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 1>2", Collections.emptyList())) {
            assertEquals(0, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 1>1", Collections.emptyList())) {
            assertEquals(0, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 1<=2", Collections.emptyList())) {
            assertEquals(1, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 2<=1", Collections.emptyList())) {
            assertEquals(0, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 1<=1", Collections.emptyList())) {
            assertEquals(1, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 2>=1", Collections.emptyList())) {
            assertEquals(1, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 1>=2", Collections.emptyList())) {
            assertEquals(0, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 1>=1", Collections.emptyList())) {
            assertEquals(1, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 2=1", Collections.emptyList())) {
            assertEquals(0, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 1=1", Collections.emptyList())) {
            assertEquals(1, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 1<>2", Collections.emptyList())) {
            assertEquals(1, scan1.consume().size());
        }
        // Logic expressions
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE (1>2) or (1>0)", Collections.emptyList())) {
            assertEquals(1, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE (1>2) or not (1>0)", Collections.emptyList())) {
            assertEquals(0, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE (1>2) and (1>0)", Collections.emptyList())) {
            assertEquals(0, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE not (1>2) and (1>0)", Collections.emptyList())) {
            assertEquals(1, scan1.consume().size());
        }
        // Warning: Parser doesn't handle this kind of expressions in select clause
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE null is null", Collections.emptyList())) {
            assertEquals(1, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE null is not null", Collections.emptyList())) {
            assertEquals(0, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 1 is null", Collections.emptyList())) {
            assertEquals(0, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 1 is not null", Collections.emptyList())) {
            assertEquals(1, scan1.consume().size());
        }
        // Case expressions
        try (DataScanner scan1 = scan(manager, "SELECT CASE " + " WHEN k1='mykey' THEN 1 " + " WHEN k1='mykeys' THEN 2 " + " ELSE 3 " + "END as mycase " + "FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(1L, ((Number) scan1.consume().get(0).get(0)).longValue());
        }
        try (DataScanner scan1 = scan(manager, "SELECT CASE " + " WHEN k1='mykeys' THEN 1 " + " WHEN k1='mykey' THEN 2 " + " ELSE 3 " + "END as mycase " + "FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(2L, ((Number) scan1.consume().get(0).get(0)).longValue());
        }
        try (DataScanner scan1 = scan(manager, "SELECT CASE " + " WHEN k1='mykeys' THEN 1 " + " WHEN k1='mykeyb' THEN 2 " + " ELSE 3 " + "END as mycase " + "FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(3L, ((Number) scan1.consume().get(0).get(0)).longValue());
        }
        // Warning: Parser doesn't handle this kind of expressions in select clause
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 'AbBbCc' LIKE '_b____'", Collections.emptyList())) {
            assertEquals(1, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 'AbBbCc' LIKE '_B____'", Collections.emptyList())) {
            assertEquals(0, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 'AbBbCc' LIKE '_b%'", Collections.emptyList())) {
            assertEquals(1, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 'AbBbCc' LIKE '_d%'", Collections.emptyList())) {
            assertEquals(0, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 'AbBbCc' LIKE 'AbBbCc'", Collections.emptyList())) {
            assertEquals(1, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 'AbBbCc' LIKE '%AbBbCc%'", Collections.emptyList())) {
            assertEquals(1, scan1.consume().size());
        }
        // Warning: jsqlParser doesn't handle this kind of expressions in select clause
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE '1' in (1,2,3)", Collections.emptyList())) {
            if (manager.getPlanner() instanceof CalcitePlanner) {
                assertEquals(0, scan1.consume().size());
            } else {
                assertEquals(1, scan1.consume().size());
            }
        }
        if ((manager.getPlanner() instanceof SQLPlanner)) {
            try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE '1' in ('1',2,3)", Collections.emptyList())) {
                assertEquals(1, scan1.consume().size());
            }
            try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 'b' in ('1',2,3)", Collections.emptyList())) {
                assertEquals(0, scan1.consume().size());
            }
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 'b' in (1)", Collections.emptyList())) {
            assertEquals(0, scan1.consume().size());
        }
        // Warning: Parser doesn't handle this kind of expressions in select clause
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 3 BETWEEN 1 AND 5", Collections.emptyList())) {
            assertEquals(1, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 1 BETWEEN 1 AND 5", Collections.emptyList())) {
            assertEquals(1, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 5 BETWEEN 1 AND 5", Collections.emptyList())) {
            assertEquals(1, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 0 BETWEEN 1 AND 5", Collections.emptyList())) {
            assertEquals(0, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql WHERE 6 BETWEEN 1 AND 5", Collections.emptyList())) {
            assertEquals(0, scan1.consume().size());
        }
        try (DataScanner scan1 = scan(manager, "SELECT ((4+(3+2)-1)*2) FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(16.0, scan1.consume().get(0).get(0));
        }
        try (DataScanner scan1 = scan(manager, "SELECT ((3/2)*3+(1/2)) FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(5.0, scan1.consume().get(0).get(0));
        }
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DataScanner(herddb.model.DataScanner) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) CalcitePlanner(herddb.sql.CalcitePlanner) SQLPlanner(herddb.sql.SQLPlanner) Timestamp(java.sql.Timestamp) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 90 with MemoryCommitLogManager

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

the class SimpleScanZeroCopyTest 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());
        execute(manager, "INSERT INTO tblspace1.tsql (k1,n1 ,s1) values (?,?,?)", Arrays.asList("a", 1, "b"));
        try (DataScanner scan = TestUtils.scan(manager, "SELECT * FROM tblspace1.tsql ", Collections.emptyList())) {
            List<DataAccessor> data = scan.consume();
            assertEquals(1, data.size());
            // read from the full record
            assertTrue(data.get(0) instanceof DataAccessorForFullRecord);
        }
        try (DataScanner scan = TestUtils.scan(manager, "SELECT k1 FROM tblspace1.tsql ", Collections.emptyList())) {
            List<DataAccessor> data = scan.consume();
            assertEquals(1, data.size());
            // read from the full record, keeping only some field
            assertTrue(data.get(0) instanceof ProjectedDataAccessor || data.get(0) instanceof ZeroCopyProjection.RuntimeProjectedDataAccessor);
            assertEquals(RawString.of("a"), data.get(0).get("k1"));
            assertEquals(RawString.of("a"), data.get(0).get(0));
        }
        try (DataScanner scan = TestUtils.scan(manager, "SELECT COUNT(*) FROM tblspace1.tsql ", Collections.emptyList())) {
            List<DataAccessor> data = scan.consume();
            assertEquals(1, data.size());
            assertTrue(data.get(0) instanceof Tuple);
        }
    }
}
Also used : MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) DataAccessor(herddb.utils.DataAccessor) ProjectedDataAccessor(herddb.utils.ProjectedDataAccessor) RawString(herddb.utils.RawString) ProjectedDataAccessor(herddb.utils.ProjectedDataAccessor) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DataScanner(herddb.model.DataScanner) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) DataAccessorForFullRecord(herddb.codec.DataAccessorForFullRecord) Tuple(herddb.model.Tuple) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Aggregations

MemoryCommitLogManager (herddb.mem.MemoryCommitLogManager)110 MemoryDataStorageManager (herddb.mem.MemoryDataStorageManager)109 MemoryMetadataStorageManager (herddb.mem.MemoryMetadataStorageManager)108 Test (org.junit.Test)105 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)103 DataScanner (herddb.model.DataScanner)71 RawString (herddb.utils.RawString)57 DataAccessor (herddb.utils.DataAccessor)37 ScanStatement (herddb.model.commands.ScanStatement)30 TranslatedQuery (herddb.sql.TranslatedQuery)27 Table (herddb.model.Table)26 List (java.util.List)26 CreateTableStatement (herddb.model.commands.CreateTableStatement)23 Index (herddb.model.Index)17 CreateIndexStatement (herddb.model.commands.CreateIndexStatement)17 TransactionContext (herddb.model.TransactionContext)16 SecondaryIndexSeek (herddb.index.SecondaryIndexSeek)14 DBManager (herddb.core.DBManager)10 StatementExecutionException (herddb.model.StatementExecutionException)10 SQLPlanner (herddb.sql.SQLPlanner)10