Search in sources :

Example 11 with Projection

use of herddb.model.Projection in project herddb by diennea.

the class CalcitePlannerTest method dirtySQLPlansTests.

@Test
public void dirtySQLPlansTests() 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, "\n\nCREATE TABLE tblspace1.tsql (k1 string primary key,n1 int,s1 string)", Collections.emptyList());
        execute(manager, "\n\nINSERT INTO tblspace1.tsql (k1,n1) values(?,?)", Arrays.asList("mykey", 1234), TransactionContext.NO_TRANSACTION);
        try (DataScanner scan = scan(manager, "SELECT n1,k1 FROM tblspace1.tsql where k1='mykey'", Collections.emptyList())) {
            assertEquals(1, scan.consume().size());
        }
        if (manager.getPlanner() instanceof JSQLParserPlanner) {
            assertInstanceOf(plan(manager, "-- comment\nselect * from tblspace1.tsql"), BindableTableScanOp.class);
        } else {
            assertInstanceOf(plan(manager, "-- comment\nselect * from tblspace1.tsql"), TableScanOp.class);
        }
        assertInstanceOf(plan(manager, "/* multiline\ncomment */\nselect * from tblspace1.tsql where n1=1"), BindableTableScanOp.class);
        assertInstanceOf(plan(manager, "\n\nselect n1 from tblspace1.tsql"), BindableTableScanOp.class);
        assertInstanceOf(plan(manager, "-- comment\nupdate tblspace1.tsql set n1=? where k1=?"), SimpleUpdateOp.class);
        assertInstanceOf(plan(manager, "/* multiline\ncomment */\nupdate tblspace1.tsql set n1=? where k1=? and n1=?"), SimpleUpdateOp.class);
        if (manager.isFullSQLSupportEnabled()) {
            assertInstanceOf(plan(manager, "update tblspace1.tsql set n1=?" + " where n1 in (select b.n1*2 from tblspace1.tsql b)"), UpdateOp.class);
        }
        assertInstanceOf(plan(manager, "-- comment\ndelete from tblspace1.tsql where k1=?"), SimpleDeleteOp.class);
        assertInstanceOf(plan(manager, "/* multiline\ncomment */\ndelete from tblspace1.tsql where k1=? and n1=?"), SimpleDeleteOp.class);
        if (manager.isFullSQLSupportEnabled()) {
            assertInstanceOf(plan(manager, "\n\ndelete from tblspace1.tsql where n1 in (select b.n1*2 from tblspace1.tsql b)"), DeleteOp.class);
        }
        assertInstanceOf(plan(manager, "INSERT INTO tblspace1.tsql (k1,n1) values(?,?)"), SimpleInsertOp.class);
        assertInstanceOf(plan(manager, "INSERT INTO tblspace1.tsql (k1,n1) values(?,?),(?,?)"), InsertOp.class);
        assertInstanceOf(plan(manager, "select k1 from tblspace1.tsql order by k1"), SortedBindableTableScanOp.class);
        assertInstanceOf(plan(manager, "select k1 from tblspace1.tsql order by k1 limit 10"), LimitedSortedBindableTableScanOp.class);
        BindableTableScanOp plan = assertInstanceOf(plan(manager, "select * from tblspace1.tsql where k1=?"), BindableTableScanOp.class);
        Projection projection = plan.getStatement().getProjection();
        System.out.println("projection:" + projection);
        assertThat(projection, instanceOf(IdentityProjection.class));
        assertNull(plan.getStatement().getComparator());
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DBManager(herddb.core.DBManager) DataScanner(herddb.model.DataScanner) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) ZeroCopyProjection(herddb.model.planner.ProjectOp.ZeroCopyProjection) IdentityProjection(herddb.model.planner.ProjectOp.IdentityProjection) Projection(herddb.model.Projection) RawString(herddb.utils.RawString) IdentityProjection(herddb.model.planner.ProjectOp.IdentityProjection) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) BindableTableScanOp(herddb.model.planner.BindableTableScanOp) SortedBindableTableScanOp(herddb.model.planner.SortedBindableTableScanOp) LimitedSortedBindableTableScanOp(herddb.model.planner.LimitedSortedBindableTableScanOp) Test(org.junit.Test)

Aggregations

Projection (herddb.model.Projection)11 Column (herddb.model.Column)6 ScanStatement (herddb.model.commands.ScanStatement)6 StatementExecutionException (herddb.model.StatementExecutionException)5 Table (herddb.model.Table)5 BindableTableScanOp (herddb.model.planner.BindableTableScanOp)5 TupleComparator (herddb.model.TupleComparator)4 DataAccessor (herddb.utils.DataAccessor)4 Test (org.junit.Test)4 TableSpaceManager (herddb.core.TableSpaceManager)3 DataScanner (herddb.model.DataScanner)3 Predicate (herddb.model.Predicate)3 StatementEvaluationContext (herddb.model.StatementEvaluationContext)3 CompiledSQLExpression (herddb.sql.expressions.CompiledSQLExpression)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 AbstractTableManager (herddb.core.AbstractTableManager)2 DBManager (herddb.core.DBManager)2 MemoryCommitLogManager (herddb.mem.MemoryCommitLogManager)2 MemoryDataStorageManager (herddb.mem.MemoryDataStorageManager)2