Search in sources :

Example 91 with CreateTableSpaceStatement

use of herddb.model.commands.CreateTableSpaceStatement in project herddb by diennea.

the class SimpleJoinTest method testStartTransactionInJoinBranch.

@Test
public void testStartTransactionInJoinBranch() 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.table1 (k1 string primary key,n1 int,s1 string)", Collections.emptyList());
        execute(manager, "CREATE TABLE tblspace1.table2 (k2 string primary key,n2 int,s2 string)", Collections.emptyList());
        execute(manager, "INSERT INTO tblspace1.table1 (k1,n1,s1) values('a',1,'A')", Collections.emptyList());
        execute(manager, "INSERT INTO tblspace1.table1 (k1,n1,s1) values('b',2,'B')", Collections.emptyList());
        execute(manager, "INSERT INTO tblspace1.table2 (k2,n2,s2) values('c',3,'A')", Collections.emptyList());
        execute(manager, "INSERT INTO tblspace1.table2 (k2,n2,s2) values('d',4,'A')", Collections.emptyList());
        {
            TranslatedQuery translated = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT * FROM" + " tblspace1.table1 t1" + " JOIN tblspace1.table2 t2" + " ON t1.n1 > 0" + "   and t2.n2 >= 1", Collections.emptyList(), true, true, false, -1);
            translated.context.setForceRetainReadLock(true);
            if (manager.getPlanner() instanceof CalcitePlanner) {
                assertThat(translated.plan.originalRoot, instanceOf(NestedLoopJoinOp.class));
                NestedLoopJoinOp join = (NestedLoopJoinOp) translated.plan.originalRoot;
                assertThat(join.getLeft(), instanceOf(SimpleScanOp.class));
                assertThat(join.getRight(), instanceOf(SimpleScanOp.class));
            }
            // we want that the left branch of the join starts the transactoion
            ScanResult scanResult = ((ScanResult) manager.executePlan(translated.plan, translated.context, TransactionContext.AUTOTRANSACTION_TRANSACTION));
            List<DataAccessor> tuples = scanResult.dataScanner.consumeAndClose();
            assertTrue(scanResult.transactionId > 0);
            for (DataAccessor t : tuples) {
                System.out.println("t:" + t);
                assertEquals(6, t.getFieldNames().length);
                assertEquals("k1", t.getFieldNames()[0]);
                assertEquals("n1", t.getFieldNames()[1]);
                assertEquals("s1", t.getFieldNames()[2]);
                assertEquals("k2", t.getFieldNames()[3]);
                assertEquals("n2", t.getFieldNames()[4]);
                assertEquals("s2", t.getFieldNames()[5]);
            }
            assertEquals(4, tuples.size());
            TestUtils.commitTransaction(manager, "tblspace1", scanResult.transactionId);
        }
        {
            TranslatedQuery translated = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT * FROM" + " tblspace1.table1 t1" + " JOIN tblspace1.table2 t2" + " ON t1.n1 > 0" + "   and t2.n2 >= 1" + "   order by t1.n1, t2.n2", Collections.emptyList(), true, true, false, // with order by
            -1);
            translated.context.setForceRetainReadLock(true);
            assertThat(translated.plan.originalRoot, instanceOf(SortOp.class));
            if (manager.getPlanner() instanceof CalcitePlanner) {
                NestedLoopJoinOp join = (NestedLoopJoinOp) ((SortOp) translated.plan.originalRoot).getInput();
                assertThat(join.getLeft(), instanceOf(SimpleScanOp.class));
                assertThat(join.getRight(), instanceOf(SimpleScanOp.class));
            } else {
                JoinOp join = (JoinOp) ((SortOp) translated.plan.originalRoot).getInput();
                assertThat(join.getLeft(), instanceOf(SimpleScanOp.class));
                assertThat(join.getRight(), instanceOf(SimpleScanOp.class));
            }
            // we want that the left branch of the join starts the transactoion
            ScanResult scanResult = ((ScanResult) manager.executePlan(translated.plan, translated.context, TransactionContext.AUTOTRANSACTION_TRANSACTION));
            List<DataAccessor> tuples = scanResult.dataScanner.consumeAndClose();
            assertTrue(scanResult.transactionId > 0);
            for (DataAccessor t : tuples) {
                System.out.println("t:" + t);
                assertEquals(6, t.getFieldNames().length);
                assertEquals("k1", t.getFieldNames()[0]);
                assertEquals("n1", t.getFieldNames()[1]);
                assertEquals("s1", t.getFieldNames()[2]);
                assertEquals("k2", t.getFieldNames()[3]);
                assertEquals("n2", t.getFieldNames()[4]);
                assertEquals("s2", t.getFieldNames()[5]);
            }
            assertEquals(4, tuples.size());
            TestUtils.commitTransaction(manager, "tblspace1", scanResult.transactionId);
        }
        {
            TranslatedQuery translated = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT t1.s1 FROM" + " tblspace1.table1 t1" + " JOIN tblspace1.table2 t2" + " ON t1.n1 > 0" + "   and t2.n2 >= 1" + "   order by t1.n1, t2.n2", Collections.emptyList(), true, true, false, // with order by on non selected fields
            -1);
            translated.context.setForceRetainReadLock(true);
            assertThat(translated.plan.originalRoot, instanceOf(ProjectOp.class));
            SortOp sort = (SortOp) ((ProjectOp) translated.plan.originalRoot).getInput();
            assertThat(((ProjectOp) translated.plan.originalRoot).getProjection(), instanceOf(ProjectOp.ZeroCopyProjection.class));
            if (manager.getPlanner() instanceof CalcitePlanner) {
                NestedLoopJoinOp join = (NestedLoopJoinOp) sort.getInput();
                assertThat(join.getLeft(), instanceOf(SimpleScanOp.class));
                assertThat(join.getRight(), instanceOf(SimpleScanOp.class));
            } else {
                JoinOp join = (JoinOp) sort.getInput();
                assertThat(join.getLeft(), instanceOf(SimpleScanOp.class));
                assertThat(join.getRight(), instanceOf(SimpleScanOp.class));
            }
            // we want that the left branch of the join starts the transactoion
            ScanResult scanResult = ((ScanResult) manager.executePlan(translated.plan, translated.context, TransactionContext.AUTOTRANSACTION_TRANSACTION));
            List<DataAccessor> tuples = scanResult.dataScanner.consumeAndClose();
            assertTrue(scanResult.transactionId > 0);
            for (DataAccessor t : tuples) {
                System.out.println("t:" + t);
                assertEquals(1, t.getFieldNames().length);
                assertEquals("s1", t.getFieldNames()[0]);
            }
            assertEquals(4, tuples.size());
            TestUtils.commitTransaction(manager, "tblspace1", scanResult.transactionId);
        }
    }
}
Also used : ScanResult(herddb.model.ScanResult) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) DataAccessor(herddb.utils.DataAccessor) ProjectOp(herddb.model.planner.ProjectOp) RawString(herddb.utils.RawString) SortOp(herddb.model.planner.SortOp) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DBManager(herddb.core.DBManager) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) List(java.util.List) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) NestedLoopJoinOp(herddb.model.planner.NestedLoopJoinOp) NestedLoopJoinOp(herddb.model.planner.NestedLoopJoinOp) JoinOp(herddb.model.planner.JoinOp) Test(org.junit.Test)

Example 92 with CreateTableSpaceStatement

use of herddb.model.commands.CreateTableSpaceStatement in project herddb by diennea.

the class SimpleJoinTest method testSubQueryInSelect.

@Test
public void testSubQueryInSelect() throws Exception {
    String nodeId = "localhost";
    try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
        assumeThat(manager.getPlanner(), instanceOf(CalcitePlanner.class));
        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.table1 (k1 string primary key,n1 int,s1 string)", Collections.emptyList());
        execute(manager, "CREATE TABLE tblspace1.table2 (k2 string primary key,n2 int,s2 string)", Collections.emptyList());
        execute(manager, "INSERT INTO tblspace1.table1 (k1,n1,s1) values('a',1,'A')", Collections.emptyList());
        execute(manager, "INSERT INTO tblspace1.table1 (k1,n1,s1) values('b',2,'B')", Collections.emptyList());
        execute(manager, "INSERT INTO tblspace1.table2 (k2,n2,s2) values('c',3,'A')", Collections.emptyList());
        execute(manager, "INSERT INTO tblspace1.table2 (k2,n2,s2) values('d',4,'A')", Collections.emptyList());
        {
            List<DataAccessor> tuples = scan(manager, "SELECT t1.k1, max(n1) as maxn1, max(select n2 from tblspace1.table2 t2 WHERE t1.s1=t2.s2) as maxn2 FROM " + " tblspace1.table1 t1 " + " group by k1", Collections.emptyList()).consumeAndClose();
            for (DataAccessor t : tuples) {
                System.out.println("t:" + t);
                assertEquals(3, t.getFieldNames().length);
                assertEquals("k1", t.getFieldNames()[0]);
                assertEquals("maxn1", t.getFieldNames()[1]);
                assertEquals("maxn2", t.getFieldNames()[2]);
            }
            assertEquals(2, tuples.size());
            assertTrue(tuples.stream().anyMatch(t -> t.toMap().equals(MapUtils.map("k1", RawString.of("a"), "maxn1", 1, "maxn2", 4))));
            assertTrue(tuples.stream().anyMatch(t -> t.toMap().equals(MapUtils.map("k1", RawString.of("b"), "maxn1", 2, "maxn2", null))));
        }
        {
            List<DataAccessor> tuples = scan(manager, "SELECT t1.k1, max(n1) as maxn1, max(select n2 from tblspace1.table2 t2 WHERE t1.s1=t2.s2) as maxn2 FROM " + " tblspace1.table1 t1 " + " group by k1" + " order by max(select n2 from tblspace1.table2 t2 WHERE t1.s1=t2.s2) desc", Collections.emptyList()).consumeAndClose();
            for (DataAccessor t : tuples) {
                System.out.println("t:" + t);
                assertEquals(3, t.getFieldNames().length);
                assertEquals("k1", t.getFieldNames()[0]);
                assertEquals("maxn1", t.getFieldNames()[1]);
                assertEquals("maxn2", t.getFieldNames()[2]);
            }
            assertEquals(2, tuples.size());
            assertTrue(tuples.get(0).toMap().equals(MapUtils.map("k1", RawString.of("b"), "maxn1", 2, "maxn2", null)));
            assertTrue(tuples.get(1).toMap().equals(MapUtils.map("k1", RawString.of("a"), "maxn1", 1, "maxn2", 4)));
        }
        execute(manager, "INSERT INTO tblspace1.table2 (k2,n2,s2) values('a',1,'A')", Collections.emptyList());
        {
            List<DataAccessor> tuples = scan(manager, "SELECT * FROM tblspace1.table1 t1, tblspace1.table2 t2 WHERE t1.k1=? and t2.k2=? and t1.k1=t2.k2", Arrays.asList("a", "a")).consumeAndClose();
            for (DataAccessor t : tuples) {
                System.out.println("t:" + t);
                assertEquals(6, t.getFieldNames().length);
            }
            assertEquals(1, tuples.size());
        }
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DBManager(herddb.core.DBManager) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) DataAccessor(herddb.utils.DataAccessor) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) List(java.util.List) RawString(herddb.utils.RawString) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 93 with CreateTableSpaceStatement

use of herddb.model.commands.CreateTableSpaceStatement in project herddb by diennea.

the class CalcitePlannerTest method showCreateTable_Within_TransactionContext.

@Test(expected = TableDoesNotExistException.class)
public void showCreateTable_Within_TransactionContext() 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);
        long tx = beginTransaction(manager, "tblspace1");
        execute(manager, "CREATE TABLE tblspace1.test (k1 string primary key," + "s1 string not null)", Collections.emptyList(), new TransactionContext(tx));
        TranslatedQuery translatedQuery = manager.getPlanner().translate("herd", "SHOW CREATE TABLE tblspace1.test", Collections.emptyList(), true, false, true, -1);
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DBManager(herddb.core.DBManager) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) TransactionContext(herddb.model.TransactionContext) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) RawString(herddb.utils.RawString) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 94 with CreateTableSpaceStatement

use of herddb.model.commands.CreateTableSpaceStatement in project herddb by diennea.

the class CalcitePlannerTest method simplePlansTests.

@Test
public void simplePlansTests() 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) values(?,?)", Arrays.asList("mykey", 1234), TransactionContext.NO_TRANSACTION);
        try (DataScanner scan = scan(manager, "SELECT * FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(1, scan.consume().size());
        }
        try (DataScanner scan = scan(manager, "SELECT n1,k1 FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(1, scan.consume().size());
        }
        try (DataScanner scan = scan(manager, "SELECT k1,n1 FROM tblspace1.tsql", Collections.emptyList())) {
            assertEquals(1, scan.consume().size());
        }
        try (DataScanner scan = scan(manager, "SELECT n1,k1 FROM tblspace1.tsql where k1='mykey'", Collections.emptyList())) {
            assertEquals(1, scan.consume().size());
        }
        {
            // test ReduceExpressionsRule.FILTER_INSTANCE
            // "n1 = 1 and n1 is not null" -> this must be simplified to "n1 = 1"
            BindableTableScanOp plan = assertInstanceOf(plan(manager, "select * from tblspace1.tsql where n1 = 1 and n1 is not null"), BindableTableScanOp.class);
            ScanStatement statement = (ScanStatement) plan.getStatement();
            Projection projection = statement.getProjection();
            assertThat(projection, instanceOf(IdentityProjection.class));
            SQLRecordPredicate predicate = (SQLRecordPredicate) statement.getPredicate();
            assertThat(predicate.getWhere(), instanceOf(CompiledEqualsExpression.class));
            CompiledEqualsExpression equals = (CompiledEqualsExpression) predicate.getWhere();
            assertThat(equals.getLeft(), instanceOf(AccessCurrentRowExpression.class));
            assertThat(equals.getRight(), instanceOf(ConstantExpression.class));
        }
        if (manager.getPlanner() instanceof JSQLParserPlanner) {
            assertInstanceOf(plan(manager, "select * from tblspace1.tsql"), BindableTableScanOp.class);
        } else {
            assertInstanceOf(plan(manager, "select * from tblspace1.tsql"), TableScanOp.class);
        }
        assertInstanceOf(plan(manager, "select * from tblspace1.tsql where n1=1"), BindableTableScanOp.class);
        assertInstanceOf(plan(manager, "select n1 from tblspace1.tsql"), BindableTableScanOp.class);
        assertInstanceOf(plan(manager, "update tblspace1.tsql set n1=? where k1=?"), SimpleUpdateOp.class);
        assertInstanceOf(plan(manager, "update 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, "delete from tblspace1.tsql where k1=?"), SimpleDeleteOp.class);
        assertInstanceOf(plan(manager, "delete from tblspace1.tsql where k1=? and n1=?"), SimpleDeleteOp.class);
        if (manager.isFullSQLSupportEnabled()) {
            assertInstanceOf(plan(manager, "delete 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);
        if (manager.getPlanner() instanceof JSQLParserPlanner) {
            assertInstanceOf(plan(manager, "select * from tblspace1.tsql order by k1"), SortedBindableTableScanOp.class);
        } else {
            assertInstanceOf(plan(manager, "select * from tblspace1.tsql order by k1"), SortedTableScanOp.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());
        }
        {
            SortedBindableTableScanOp plan = assertInstanceOf(plan(manager, "select n1,k1 from tblspace1.tsql order by n1"), SortedBindableTableScanOp.class);
            Projection projection = plan.getStatement().getProjection();
            System.out.println("projection:" + projection);
            assertThat(projection, instanceOf(ZeroCopyProjection.class));
            ZeroCopyProjection zero = (ZeroCopyProjection) projection;
            assertArrayEquals(new String[] { "n1", "k1" }, zero.getFieldNames());
            assertEquals("n1", zero.getColumns()[0].name);
            assertEquals("k1", zero.getColumns()[1].name);
            TupleComparator comparator = plan.getStatement().getComparator();
            System.out.println("comparator:" + comparator);
            assertThat(comparator, instanceOf(SortOp.class));
            SortOp sortOp = (SortOp) comparator;
            assertFalse(sortOp.isOnlyPrimaryKeyAndAscending());
        }
        {
            SortedBindableTableScanOp plan = assertInstanceOf(plan(manager, "select n1,k1 from tblspace1.tsql order by k1"), SortedBindableTableScanOp.class);
            Projection projection = plan.getStatement().getProjection();
            System.out.println("projection:" + projection);
            assertThat(projection, instanceOf(ZeroCopyProjection.class));
            ZeroCopyProjection zero = (ZeroCopyProjection) projection;
            assertArrayEquals(new String[] { "n1", "k1" }, zero.getFieldNames());
            assertEquals("n1", zero.getColumns()[0].name);
            assertEquals("k1", zero.getColumns()[1].name);
            TupleComparator comparator = plan.getStatement().getComparator();
            System.out.println("comparator:" + comparator);
            assertThat(comparator, instanceOf(SortOp.class));
            SortOp sortOp = (SortOp) comparator;
            assertTrue(sortOp.isOnlyPrimaryKeyAndAscending());
        }
        {
            SimpleScanOp plan = (SimpleScanOp) plan(manager, "select * from tblspace1.tsql order by n1");
            if (manager.getPlanner() instanceof JSQLParserPlanner) {
                assertThat(plan, instanceOf(SortedBindableTableScanOp.class));
            } else {
                assertThat(plan, instanceOf(SortedTableScanOp.class));
            }
            Projection projection = plan.getStatement().getProjection();
            System.out.println("projection:" + projection);
            assertThat(projection, instanceOf(IdentityProjection.class));
            IdentityProjection zero = (IdentityProjection) projection;
            assertArrayEquals(new String[] { "k1", "n1", "s1" }, zero.getFieldNames());
            assertEquals("k1", zero.getColumns()[0].name);
            assertEquals("n1", zero.getColumns()[1].name);
            assertEquals("s1", zero.getColumns()[2].name);
            TupleComparator comparator = plan.getStatement().getComparator();
            System.out.println("comparator:" + comparator);
            assertThat(comparator, instanceOf(SortOp.class));
            SortOp sortOp = (SortOp) comparator;
            assertFalse(sortOp.isOnlyPrimaryKeyAndAscending());
        }
        {
            SimpleScanOp plan = (SimpleScanOp) plan(manager, "select * from tblspace1.tsql order by k1");
            if (manager.getPlanner() instanceof JSQLParserPlanner) {
                assertThat(plan, instanceOf(SortedBindableTableScanOp.class));
            } else {
                assertThat(plan, instanceOf(SortedTableScanOp.class));
            }
            Projection projection = plan.getStatement().getProjection();
            System.out.println("projection:" + projection);
            assertThat(projection, instanceOf(IdentityProjection.class));
            IdentityProjection zero = (IdentityProjection) projection;
            assertArrayEquals(new String[] { "k1", "n1", "s1" }, zero.getFieldNames());
            assertEquals("k1", zero.getColumns()[0].name);
            assertEquals("n1", zero.getColumns()[1].name);
            assertEquals("s1", zero.getColumns()[2].name);
            TupleComparator comparator = plan.getStatement().getComparator();
            System.out.println("comparator:" + comparator);
            assertThat(comparator, instanceOf(SortOp.class));
            SortOp sortOp = (SortOp) comparator;
            assertTrue(sortOp.isOnlyPrimaryKeyAndAscending());
        }
    }
}
Also used : SimpleScanOp(herddb.model.planner.SimpleScanOp) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) ZeroCopyProjection(herddb.model.planner.ProjectOp.ZeroCopyProjection) IdentityProjection(herddb.model.planner.ProjectOp.IdentityProjection) Projection(herddb.model.Projection) TupleComparator(herddb.model.TupleComparator) RawString(herddb.utils.RawString) SortOp(herddb.model.planner.SortOp) IdentityProjection(herddb.model.planner.ProjectOp.IdentityProjection) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) CompiledEqualsExpression(herddb.sql.expressions.CompiledEqualsExpression) DBManager(herddb.core.DBManager) DataScanner(herddb.model.DataScanner) ZeroCopyProjection(herddb.model.planner.ProjectOp.ZeroCopyProjection) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) SortedBindableTableScanOp(herddb.model.planner.SortedBindableTableScanOp) LimitedSortedBindableTableScanOp(herddb.model.planner.LimitedSortedBindableTableScanOp) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) BindableTableScanOp(herddb.model.planner.BindableTableScanOp) SortedBindableTableScanOp(herddb.model.planner.SortedBindableTableScanOp) LimitedSortedBindableTableScanOp(herddb.model.planner.LimitedSortedBindableTableScanOp) ScanStatement(herddb.model.commands.ScanStatement) Test(org.junit.Test)

Example 95 with CreateTableSpaceStatement

use of herddb.model.commands.CreateTableSpaceStatement in project herddb by diennea.

the class CalcitePlannerTest method zeroCopyProjectionTest.

@Test
public void zeroCopyProjectionTest() 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," + "s1 string)", Collections.emptyList());
        execute(manager, "INSERT INTO tblspace1.tsql (k1 ," + "s1) values('testk1','tests1')", Collections.emptyList());
        try (DataScanner scan = scan(manager, "SELECT * FROM tblspace1.tsql", Collections.emptyList())) {
            List<DataAccessor> consume = scan.consume();
            assertEquals(1, consume.size());
            DataAccessor record = consume.get(0);
            assertThat(record, instanceOf(DataAccessorForFullRecord.class));
            assertEquals("k1", record.getFieldNames()[0]);
            assertEquals("s1", record.getFieldNames()[1]);
            assertEquals(RawString.of("testk1"), record.get(0));
            assertEquals(RawString.of("tests1"), record.get(1));
            assertEquals(RawString.of("testk1"), record.get("k1"));
            assertEquals(RawString.of("tests1"), record.get("s1"));
        }
        try (DataScanner scan = scan(manager, "SELECT k1,s1 FROM tblspace1.tsql", Collections.emptyList())) {
            List<DataAccessor> consume = scan.consume();
            assertEquals(1, consume.size());
            DataAccessor record = consume.get(0);
            assertThat(record, instanceOf(DataAccessorForFullRecord.class));
            assertEquals("k1", record.getFieldNames()[0]);
            assertEquals("s1", record.getFieldNames()[1]);
            assertEquals(RawString.of("testk1"), record.get(0));
            assertEquals(RawString.of("tests1"), record.get(1));
            assertEquals(RawString.of("testk1"), record.get("k1"));
            assertEquals(RawString.of("tests1"), record.get("s1"));
        }
        try (DataScanner scan = scan(manager, "SELECT s1,k1 FROM tblspace1.tsql", Collections.emptyList())) {
            List<DataAccessor> consume = scan.consume();
            assertEquals(1, consume.size());
            DataAccessor record = consume.get(0);
            assertThat(record, instanceOf(ZeroCopyProjection.RuntimeProjectedDataAccessor.class));
            assertEquals("k1", record.getFieldNames()[1]);
            assertEquals("s1", record.getFieldNames()[0]);
            assertEquals(RawString.of("testk1"), record.get(1));
            assertEquals(RawString.of("tests1"), record.get(0));
            assertEquals(RawString.of("testk1"), record.get("k1"));
            assertEquals(RawString.of("tests1"), record.get("s1"));
        }
        try (DataScanner scan = scan(manager, "SELECT s1 FROM tblspace1.tsql", Collections.emptyList())) {
            List<DataAccessor> consume = scan.consume();
            assertEquals(1, consume.size());
            DataAccessor record = consume.get(0);
            assertThat(record, instanceOf(RuntimeProjectedDataAccessor.class));
            assertEquals("s1", record.getFieldNames()[0]);
            assertEquals(RawString.of("tests1"), record.get(0));
            assertEquals(RawString.of("tests1"), record.get("s1"));
        }
        try (DataScanner scan = scan(manager, "SELECT k1 FROM tblspace1.tsql", Collections.emptyList())) {
            List<DataAccessor> consume = scan.consume();
            assertEquals(1, consume.size());
            DataAccessor record = consume.get(0);
            assertThat(record, instanceOf(RuntimeProjectedDataAccessor.class));
            assertEquals("k1", record.getFieldNames()[0]);
            assertEquals(RawString.of("testk1"), record.get(0));
            assertEquals(RawString.of("testk1"), record.get("k1"));
        }
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) RuntimeProjectedDataAccessor(herddb.model.planner.ProjectOp.ZeroCopyProjection.RuntimeProjectedDataAccessor) 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) RawString(herddb.utils.RawString) DataAccessorForFullRecord(herddb.codec.DataAccessorForFullRecord) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Aggregations

CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)308 Test (org.junit.Test)295 MemoryCommitLogManager (herddb.mem.MemoryCommitLogManager)241 MemoryMetadataStorageManager (herddb.mem.MemoryMetadataStorageManager)240 MemoryDataStorageManager (herddb.mem.MemoryDataStorageManager)236 DataScanner (herddb.model.DataScanner)164 RawString (herddb.utils.RawString)139 Table (herddb.model.Table)132 DBManager (herddb.core.DBManager)126 CreateTableStatement (herddb.model.commands.CreateTableStatement)111 ScanStatement (herddb.model.commands.ScanStatement)78 DataAccessor (herddb.utils.DataAccessor)77 TransactionContext (herddb.model.TransactionContext)69 TranslatedQuery (herddb.sql.TranslatedQuery)69 Path (java.nio.file.Path)67 Bytes (herddb.utils.Bytes)54 List (java.util.List)54 Index (herddb.model.Index)53 GetStatement (herddb.model.commands.GetStatement)53 CreateIndexStatement (herddb.model.commands.CreateIndexStatement)51