Search in sources :

Example 11 with TuplesList

use of herddb.utils.TuplesList in project herddb by diennea.

the class CalcitePlannerTest method showCreateTable_with_recreating_table_from_command_output.

@Test
public void showCreateTable_with_recreating_table_from_command_output() 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.test23 (k1 int auto_increment ," + "s1 string not null, n1 int, primary key(k1))", Collections.emptyList());
        TranslatedQuery translatedQuery = manager.getPlanner().translate("tblspace1", "SHOW CREATE TABLE tblspace1.test23", 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.test23(k1 integer auto_increment,s1 string not null,n1 integer,PRIMARY KEY(k1))".equalsIgnoreCase(values.get("tabledef").toString()));
            // drop the table
            execute(manager, "DROP TABLE tblspace1.test23", Collections.emptyList());
            // ensure table has been dropped
            try (DataScanner scan = scan(manager, "SELECT * FROM tblspace1.systables where table_name='test23'", Collections.emptyList())) {
                assertTrue(scan.consume().isEmpty());
            }
            // recreate table
            String showCreateTableResult = values.get("tabledef").toString();
            execute(manager, showCreateTableResult, Collections.emptyList());
            // Ensure the table is getting created
            try (DataScanner scan = scan(manager, "SELECT * FROM tblspace1.systables where table_name='test23'", Collections.emptyList())) {
                assertFalse(scan.consume().isEmpty());
            }
        }
    }
}
Also used : ScanResult(herddb.model.ScanResult) 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) 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

TuplesList (herddb.utils.TuplesList)11 DataAccessor (herddb.utils.DataAccessor)10 DataScanner (herddb.model.DataScanner)7 RawString (herddb.utils.RawString)7 ScanResult (herddb.model.ScanResult)5 SQLPlannedOperationStatement (herddb.model.commands.SQLPlannedOperationStatement)5 ScanStatement (herddb.model.commands.ScanStatement)5 ArrayList (java.util.ArrayList)5 HerdDBInternalException (herddb.core.HerdDBInternalException)4 DataScannerException (herddb.model.DataScannerException)4 Message (herddb.network.Message)4 ByteBuf (io.netty.buffer.ByteBuf)4 Test (org.junit.Test)4 DBManager (herddb.core.DBManager)3 MemoryCommitLogManager (herddb.mem.MemoryCommitLogManager)3 MemoryDataStorageManager (herddb.mem.MemoryDataStorageManager)3 MemoryMetadataStorageManager (herddb.mem.MemoryMetadataStorageManager)3 StatementExecutionException (herddb.model.StatementExecutionException)3 Tuple (herddb.model.Tuple)3 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)3