Search in sources :

Example 86 with CreateTableStatement

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

the class DataConsistencyCheckTest method tableSpaceConsistencyCheck.

@Test
public void tableSpaceConsistencyCheck() throws Exception {
    String tableSpaceName = "tblspace1";
    try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
        manager.start();
        assertTrue(manager.waitForBootOfLocalTablespaces(10000));
        execute(manager, "CREATE TABLESPACE 'tblspace1'", Collections.emptyList());
        manager.waitForTablespace("tblspace1", 10000);
        manager.waitForTablespace(tableSpaceName, 10000, false);
        Table table = Table.builder().tablespace(tableSpaceName).name("t1").column("id", ColumnTypes.STRING).column("name", ColumnTypes.STRING).primaryKey("id").build();
        Table table2 = Table.builder().tablespace(tableSpaceName).name("t2").column("id", ColumnTypes.STRING).column("name", ColumnTypes.BOOLEAN).primaryKey("id").build();
        CreateTableStatement st = new CreateTableStatement(table);
        manager.executeStatement(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        CreateTableStatement st2 = new CreateTableStatement(table2);
        manager.executeStatement(st2, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        execute(manager, "INSERT INTO tblspace1.t1 (id,name) values (?,?)", Arrays.asList("1", true));
        execute(manager, "INSERT INTO tblspace1.t1 (id,name) values (?,?)", Arrays.asList("2", false));
        execute(manager, "INSERT INTO tblspace1.t2 (id,name) values (?,?)", Arrays.asList("1", true));
        execute(manager, "INSERT INTO tblspace1.t2 (id,name) values (?,?)", Arrays.asList("2", false));
        TableSpaceConsistencyCheckStatement statement = new TableSpaceConsistencyCheckStatement(tableSpaceName);
        DataConsistencyStatementResult result = manager.createTableSpaceCheckSum(statement);
        assertTrue("Check tableSpace  ", result.getOk());
    }
}
Also used : TableSpaceConsistencyCheckStatement(herddb.model.commands.TableSpaceConsistencyCheckStatement) DBManager(herddb.core.DBManager) Table(herddb.model.Table) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) CreateTableStatement(herddb.model.commands.CreateTableStatement) DataConsistencyStatementResult(herddb.model.DataConsistencyStatementResult) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 87 with CreateTableStatement

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

the class DataConsistencyCheckTest method emptyTableConsistencyCheck.

@Test
public void emptyTableConsistencyCheck() throws Exception {
    String tableSpaceName = "tblspace1";
    String tableName = "t1";
    try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
        manager.start();
        assertTrue(manager.waitForBootOfLocalTablespaces(10000));
        execute(manager, "CREATE TABLESPACE 'tblspace1'", Collections.emptyList());
        manager.waitForTablespace("tblspace1", 10000);
        Table table = Table.builder().tablespace(tableSpaceName).name(tableName).column("k1", ColumnTypes.STRING).column("n1", ColumnTypes.INTEGER).column("s1", ColumnTypes.STRING).primaryKey("k1").build();
        CreateTableStatement st = new CreateTableStatement(table);
        manager.executeStatement(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        // check empty table
        TableConsistencyCheckStatement statement = new TableConsistencyCheckStatement(tableName, tableSpaceName);
        DataConsistencyStatementResult result = manager.createTableCheckSum(statement, null);
        assertTrue("Check empty table ", result.getOk());
    }
}
Also used : DBManager(herddb.core.DBManager) Table(herddb.model.Table) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) CreateTableStatement(herddb.model.commands.CreateTableStatement) DataConsistencyStatementResult(herddb.model.DataConsistencyStatementResult) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) TableConsistencyCheckStatement(herddb.model.commands.TableConsistencyCheckStatement) Test(org.junit.Test)

Example 88 with CreateTableStatement

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

the class DataConsistencyCheckTest method tableWithNullValueConsistencyCheck.

@Test
public void tableWithNullValueConsistencyCheck() throws Exception {
    String tableSpaceName = "t1";
    String tableName = "nulltable";
    try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
        manager.start();
        assertTrue(manager.waitForBootOfLocalTablespaces(10000));
        execute(manager, "CREATE TABLESPACE 't1'", Collections.emptyList());
        manager.waitForTablespace(tableSpaceName, 10000);
        Table table = Table.builder().tablespace(tableSpaceName).name(tableName).column("k1", ColumnTypes.INTEGER).column("n1", ColumnTypes.INTEGER).column("s1", ColumnTypes.STRING).primaryKey("k1", true).build();
        CreateTableStatement st = new CreateTableStatement(table);
        manager.executeStatement(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        execute(manager, "INSERT INTO " + tableSpaceName + "." + tableName + " (n1 ,s1) values (?,?)", Arrays.asList(null, null));
        execute(manager, "INSERT INTO " + tableSpaceName + "." + tableName + " (n1 ,s1) values (?,?)", Arrays.asList(null, null));
        execute(manager, "INSERT INTO " + tableSpaceName + "." + tableName + " (n1 ,s1) values (?,?)", Arrays.asList(null, null));
        execute(manager, "INSERT INTO " + tableSpaceName + "." + tableName + " (n1 ,s1) values (?,?)", Arrays.asList(null, null));
        TableConsistencyCheckStatement statement = new TableConsistencyCheckStatement(tableName, tableSpaceName);
        DataConsistencyStatementResult result = manager.createTableCheckSum(statement, null);
        assertTrue("Check table with null value ", result.getOk());
    }
}
Also used : DBManager(herddb.core.DBManager) Table(herddb.model.Table) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) CreateTableStatement(herddb.model.commands.CreateTableStatement) DataConsistencyStatementResult(herddb.model.DataConsistencyStatementResult) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) TableConsistencyCheckStatement(herddb.model.commands.TableConsistencyCheckStatement) Test(org.junit.Test)

Example 89 with CreateTableStatement

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

the class SecondaryNonUniqueIndexAccessSuite method secondaryIndexPrefixScan.

@Test
public void secondaryIndexPrefixScan() 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);
        Table table = Table.builder().tablespace("tblspace1").name("t1").column("id", ColumnTypes.STRING).column("n1", ColumnTypes.INTEGER).column("name", ColumnTypes.STRING).primaryKey("id").build();
        CreateTableStatement st2 = new CreateTableStatement(table);
        manager.executeStatement(st2, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        Index index = Index.builder().onTable(table).type(Index.TYPE_BRIN).column("n1", ColumnTypes.INTEGER).column("name", ColumnTypes.STRING).build();
        TestUtils.executeUpdate(manager, "INSERT INTO tblspace1.t1(id,n1,name) values('a',1,'n1')", Collections.emptyList());
        TestUtils.executeUpdate(manager, "INSERT INTO tblspace1.t1(id,n1,name) values('b',1,'n1')", Collections.emptyList());
        TestUtils.executeUpdate(manager, "INSERT INTO tblspace1.t1(id,n1,name) values('c',1,'n2')", Collections.emptyList());
        TestUtils.executeUpdate(manager, "INSERT INTO tblspace1.t1(id,n1,name) values('d',2,'n2')", Collections.emptyList());
        TestUtils.executeUpdate(manager, "INSERT INTO tblspace1.t1(id,n1,name) values('e',3,'n2')", Collections.emptyList());
        // create index, it will be built using existing data
        CreateIndexStatement st3 = new CreateIndexStatement(index);
        manager.executeStatement(st3, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        {
            TranslatedQuery translated = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT * FROM tblspace1.t1 WHERE n1=1", Collections.emptyList(), true, true, false, -1);
            ScanStatement scan = translated.plan.mainStatement.unwrap(ScanStatement.class);
            assertTrue(scan.getPredicate().getIndexOperation() instanceof SecondaryIndexPrefixScan);
            try (DataScanner scan1 = manager.scan(scan, translated.context, TransactionContext.NO_TRANSACTION)) {
                assertEquals(3, scan1.consume().size());
            }
        }
        {
            TranslatedQuery translated = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT * FROM tblspace1.t1 WHERE n1=1 and name='n2'", Collections.emptyList(), true, true, false, -1);
            ScanStatement scan = translated.plan.mainStatement.unwrap(ScanStatement.class);
            assertTrue(scan.getPredicate().getIndexOperation() instanceof SecondaryIndexSeek);
            try (DataScanner scan1 = manager.scan(scan, translated.context, TransactionContext.NO_TRANSACTION)) {
                assertEquals(1, scan1.consume().size());
            }
        }
        {
            TranslatedQuery translated = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT * FROM tblspace1.t1 WHERE n1>=1", Collections.emptyList(), true, true, false, -1);
            ScanStatement scan = translated.plan.mainStatement.unwrap(ScanStatement.class);
            assertNull(scan.getPredicate().getIndexOperation());
            try (DataScanner scan1 = manager.scan(scan, translated.context, TransactionContext.NO_TRANSACTION)) {
                assertEquals(5, scan1.consume().size());
            }
        }
    }
}
Also used : Table(herddb.model.Table) TranslatedQuery(herddb.sql.TranslatedQuery) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) CreateTableStatement(herddb.model.commands.CreateTableStatement) CreateIndexStatement(herddb.model.commands.CreateIndexStatement) Index(herddb.model.Index) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DBManager(herddb.core.DBManager) DataScanner(herddb.model.DataScanner) SecondaryIndexSeek(herddb.index.SecondaryIndexSeek) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) SecondaryIndexPrefixScan(herddb.index.SecondaryIndexPrefixScan) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) ScanStatement(herddb.model.commands.ScanStatement) Test(org.junit.Test)

Example 90 with CreateTableStatement

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

the class SecondaryNonUniqueIndexAccessSuite method createIndexInTransaction2.

@Test
public void createIndexInTransaction2() 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);
        Bytes key = Bytes.from_int(1234);
        Bytes value = Bytes.from_long(8888);
        Table transacted_table = Table.builder().tablespace("tblspace1").name("t1").column("id", ColumnTypes.STRING).column("name", ColumnTypes.STRING).primaryKey("id").build();
        long tx = TestUtils.beginTransaction(manager, "tblspace1");
        CreateTableStatement st_create = new CreateTableStatement(transacted_table);
        manager.executeStatement(st_create, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx));
        Index index = Index.builder().onTable(transacted_table).type(indexType).column("name", ColumnTypes.STRING).build();
        CreateIndexStatement createIndex = new CreateIndexStatement(index);
        manager.executeStatement(createIndex, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx));
        TestUtils.executeUpdate(manager, "INSERT INTO tblspace1.t1(id,name) values(?,?)", Arrays.asList("a", "n1"), new TransactionContext(tx));
        TestUtils.executeUpdate(manager, "INSERT INTO tblspace1.t1(id,name) values(?,?)", Arrays.asList("b", "n1"), new TransactionContext(tx));
        TestUtils.executeUpdate(manager, "INSERT INTO tblspace1.t1(id,name) values(?,?)", Arrays.asList("c", "n2"), new TransactionContext(tx));
        {
            TranslatedQuery translated = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT * FROM tblspace1.t1 WHERE name='n1'", Collections.emptyList(), true, true, false, -1);
            ScanStatement scan = translated.plan.mainStatement.unwrap(ScanStatement.class);
            // uncommitted indexes are not used
            assertFalse(scan.getPredicate().getIndexOperation() instanceof SecondaryIndexSeek);
            try (DataScanner scan1 = manager.scan(scan, translated.context, new TransactionContext(tx))) {
                assertEquals(2, scan1.consume().size());
            }
        }
        manager.executeStatement(new CommitTransactionStatement("tblspace1", tx), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        {
            TranslatedQuery translated = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT * FROM tblspace1.t1 WHERE name='n1'", Collections.emptyList(), true, true, false, -1);
            ScanStatement scan = translated.plan.mainStatement.unwrap(ScanStatement.class);
            assertTrue(scan.getPredicate().getIndexOperation() instanceof SecondaryIndexSeek);
            try (DataScanner scan1 = manager.scan(scan, translated.context, TransactionContext.NO_TRANSACTION)) {
                assertEquals(2, scan1.consume().size());
            }
        }
    }
}
Also used : Table(herddb.model.Table) TranslatedQuery(herddb.sql.TranslatedQuery) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) CommitTransactionStatement(herddb.model.commands.CommitTransactionStatement) CreateTableStatement(herddb.model.commands.CreateTableStatement) CreateIndexStatement(herddb.model.commands.CreateIndexStatement) Index(herddb.model.Index) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) Bytes(herddb.utils.Bytes) DBManager(herddb.core.DBManager) SecondaryIndexSeek(herddb.index.SecondaryIndexSeek) DataScanner(herddb.model.DataScanner) TransactionContext(herddb.model.TransactionContext) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) ScanStatement(herddb.model.commands.ScanStatement) Test(org.junit.Test)

Aggregations

CreateTableStatement (herddb.model.commands.CreateTableStatement)183 Table (herddb.model.Table)180 Test (org.junit.Test)164 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)111 InsertStatement (herddb.model.commands.InsertStatement)102 DataScanner (herddb.model.DataScanner)82 CreateIndexStatement (herddb.model.commands.CreateIndexStatement)72 GetStatement (herddb.model.commands.GetStatement)72 Index (herddb.model.Index)71 GetResult (herddb.model.GetResult)68 ScanStatement (herddb.model.commands.ScanStatement)68 TranslatedQuery (herddb.sql.TranslatedQuery)68 Path (java.nio.file.Path)61 MemoryCommitLogManager (herddb.mem.MemoryCommitLogManager)57 MemoryMetadataStorageManager (herddb.mem.MemoryMetadataStorageManager)57 TransactionContext (herddb.model.TransactionContext)56 MemoryDataStorageManager (herddb.mem.MemoryDataStorageManager)54 Bytes (herddb.utils.Bytes)51 SecondaryIndexSeek (herddb.index.SecondaryIndexSeek)50 Record (herddb.model.Record)44