Search in sources :

Example 16 with DBManager

use of herddb.core.DBManager 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 17 with DBManager

use of herddb.core.DBManager 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 18 with DBManager

use of herddb.core.DBManager 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 19 with DBManager

use of herddb.core.DBManager 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)

Example 20 with DBManager

use of herddb.core.DBManager in project herddb by diennea.

the class CalcitePlannerTest method showCreateTableTest.

@Test
public void showCreateTableTest() 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.test (k1 string primary key," + "s1 string not null default 'mydefault')", Collections.emptyList());
        Table table = manager.getTableSpaceManager("tblspace1").getTableManager("test").getTable();
        Column c = table.getColumn("s1");
        assertEquals(ColumnTypes.NOTNULL_STRING, c.type);
        assertEquals("mydefault", c.defaultValue.to_string());
        execute(manager, "CREATE TABLE tblspace1.test22 (k1 string not null ," + "s1 string not null, n1 int, primary key(k1,n1))", Collections.emptyList());
        TranslatedQuery translatedQuery = manager.getPlanner().translate("tblspace1", "SHOW CREATE TABLE tblspace1.test", Collections.emptyList(), true, false, true, -1);
        if (translatedQuery.plan.mainStatement instanceof SQLPlannedOperationStatement || translatedQuery.plan.mainStatement instanceof ScanStatement) {
            ScanResult scanResult = (ScanResult) manager.executePlan(translatedQuery.plan, translatedQuery.context, TransactionContext.NO_TRANSACTION);
            DataScanner dataScanner = scanResult.dataScanner;
            String[] columns = dataScanner.getFieldNames();
            List<DataAccessor> records = dataScanner.consume(2);
            TuplesList tuplesList = new TuplesList(columns, records);
            assertTrue(tuplesList.columnNames[0].equalsIgnoreCase("tabledef"));
            Tuple values = (Tuple) records.get(0);
            assertTrue("CREATE TABLE tblspace1.test(k1 string,s1 string not null DEFAULT 'mydefault',PRIMARY KEY(k1))".equalsIgnoreCase(values.get("tabledef").toString()));
        }
        translatedQuery = manager.getPlanner().translate("tblspace1", "SHOW CREATE TABLE tblspace1.test22", Collections.emptyList(), true, false, true, -1);
        if (translatedQuery.plan.mainStatement instanceof SQLPlannedOperationStatement || translatedQuery.plan.mainStatement instanceof ScanStatement) {
            ScanResult scanResult = (ScanResult) manager.executePlan(translatedQuery.plan, translatedQuery.context, TransactionContext.NO_TRANSACTION);
            DataScanner dataScanner = scanResult.dataScanner;
            String[] columns = dataScanner.getFieldNames();
            List<DataAccessor> records = dataScanner.consume(2);
            TuplesList tuplesList = new TuplesList(columns, records);
            assertTrue(tuplesList.columnNames[0].equalsIgnoreCase("tabledef"));
            Tuple values = (Tuple) records.get(0);
            assertTrue("CREATE TABLE tblspace1.test22(k1 string not null,s1 string not null,n1 integer,Primary key(k1,n1))".equalsIgnoreCase(values.get("tabledef").toString()));
        }
    }
}
Also used : ScanResult(herddb.model.ScanResult) Table(herddb.model.Table) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) RuntimeProjectedDataAccessor(herddb.model.planner.ProjectOp.ZeroCopyProjection.RuntimeProjectedDataAccessor) DataAccessor(herddb.utils.DataAccessor) RawString(herddb.utils.RawString) SQLPlannedOperationStatement(herddb.model.commands.SQLPlannedOperationStatement) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DBManager(herddb.core.DBManager) DataScanner(herddb.model.DataScanner) Column(herddb.model.Column) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) Tuple(herddb.model.Tuple) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) ScanStatement(herddb.model.commands.ScanStatement) TuplesList(herddb.utils.TuplesList) Test(org.junit.Test)

Aggregations

DBManager (herddb.core.DBManager)153 Test (org.junit.Test)143 MemoryCommitLogManager (herddb.mem.MemoryCommitLogManager)133 MemoryMetadataStorageManager (herddb.mem.MemoryMetadataStorageManager)133 MemoryDataStorageManager (herddb.mem.MemoryDataStorageManager)132 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)126 DataScanner (herddb.model.DataScanner)92 RawString (herddb.utils.RawString)82 Table (herddb.model.Table)53 DataAccessor (herddb.utils.DataAccessor)53 CreateTableStatement (herddb.model.commands.CreateTableStatement)34 ScanStatement (herddb.model.commands.ScanStatement)34 RuntimeProjectedDataAccessor (herddb.model.planner.ProjectOp.ZeroCopyProjection.RuntimeProjectedDataAccessor)28 List (java.util.List)28 TransactionContext (herddb.model.TransactionContext)27 Index (herddb.model.Index)25 TranslatedQuery (herddb.sql.TranslatedQuery)23 CreateIndexStatement (herddb.model.commands.CreateIndexStatement)21 SecondaryIndexSeek (herddb.index.SecondaryIndexSeek)18 Timestamp (java.sql.Timestamp)15