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());
}
}
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());
}
}
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());
}
}
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());
}
}
}
}
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());
}
}
}
}
Aggregations