use of herddb.mem.MemoryMetadataStorageManager in project herddb by diennea.
the class DeleteTest method deleteThenInsert.
/**
* Check delete then insert (#320, not every row delete really was run).
*
* @author diego.salvi
*/
@Test
public void deleteThenInsert() throws Exception {
int runs = 50;
int inserts = 100;
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(), NO_TRANSACTION);
manager.waitForTablespace("tblspace1", 10000);
for (int run = 0; run < runs; ++run) {
execute(manager, "CREATE TABLE tblspace1.tsql (k1 int, n1 int, primary key(k1))", Collections.emptyList());
for (int i = 0; i < inserts; ++i) {
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList(Integer.valueOf(i), Integer.valueOf(1))).getUpdateCount());
}
long tx = beginTransaction(manager, "tblspace1");
TransactionContext ctx = new TransactionContext(tx);
executeUpdate(manager, "DELETE FROM tblspace1.tsql", Collections.emptyList(), ctx);
for (int i = 0; i < inserts; ++i) {
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList(Integer.valueOf(i), Integer.valueOf(1)), ctx).getUpdateCount());
}
commitTransaction(manager, "tblspace1", tx);
for (int i = 0; i < inserts; ++i) {
assertEquals(1, scan(manager, "SELECT * FROM tblspace1.tsql WHERE k1 = ?", Arrays.asList(Integer.valueOf(i), ctx)).consumeAndClose().size());
}
execute(manager, "DROP TABLE tblspace1.tsql", Collections.emptyList());
}
}
}
use of herddb.mem.MemoryMetadataStorageManager in project herddb by diennea.
the class DropTableSQLTest method dropTableNoTransaction.
@Test
public void dropTableNoTransaction() 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());
try (DataScanner scan = scan(manager, "SELECT * FROM tblspace1.systables where table_name='tsql'", Collections.emptyList())) {
List<DataAccessor> all = scan.consume();
assertEquals(1, all.size());
}
execute(manager, "DROP TABLE tblspace1.tsql", Collections.emptyList());
try (DataScanner scan = scan(manager, "SELECT * FROM tblspace1.systables where table_name='tsql'", Collections.emptyList())) {
assertTrue(scan.consume().isEmpty());
}
execute(manager, "CREATE TABLE tsql2 (k1 string primary key,n1 int,s1 string)", Collections.emptyList());
try (DataScanner scan = scan(manager, "SELECT * FROM systables where table_name='tsql2'", Collections.emptyList())) {
List<DataAccessor> all = scan.consume();
assertEquals(1, all.size());
}
// name is not case sensitive
execute(manager, "DROP TABLE tSQL2", Collections.emptyList());
try (DataScanner scan = scan(manager, "SELECT * FROM systables where table_name='tsql2'", Collections.emptyList())) {
assertTrue(scan.consume().isEmpty());
}
herddb.utils.TestUtils.assertThrows(StatementExecutionException.class, () -> {
execute(manager, "DROP TABLE tSQL2", Collections.emptyList());
});
execute(manager, "DROP TABLE IF EXISTS tSQL2", Collections.emptyList());
}
}
use of herddb.mem.MemoryMetadataStorageManager in project herddb by diennea.
the class DropTableSQLTest method dropTableWithTransaction.
@Test
public void dropTableWithTransaction() 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 = ((TransactionResult) execute(manager, "EXECUTE begintransaction 'tblspace1'", Collections.emptyList())).getTransactionId();
execute(manager, "CREATE TABLE tblspace1.tsql (k1 string primary key,n1 int,s1 string)", Collections.emptyList(), new TransactionContext(tx));
execute(manager, "INSERT INTO tblspace1.tsql (k1) values('a')", Collections.emptyList(), new TransactionContext(tx));
try (DataScanner scan = scan(manager, "SELECT * FROM tblspace1.tsql ", Collections.emptyList())) {
fail();
} catch (TableDoesNotExistException ok) {
}
try (DataScanner scan = scan(manager, "SELECT * FROM tblspace1.systables where table_name='tsql'", Collections.emptyList())) {
List<DataAccessor> all = scan.consume();
assertEquals(0, all.size());
}
execute(manager, "EXECUTE committransaction 'tblspace1'," + tx, Collections.emptyList());
try (DataScanner scan = scan(manager, "SELECT * FROM tblspace1.tsql ", Collections.emptyList())) {
List<DataAccessor> all = scan.consume();
assertEquals(1, all.size());
}
try (DataScanner scan = scan(manager, "SELECT * FROM tblspace1.systables where table_name='tsql'", Collections.emptyList())) {
List<DataAccessor> all = scan.consume();
assertEquals(1, all.size());
}
long tx2 = ((TransactionResult) execute(manager, "EXECUTE begintransaction 'tblspace1'", Collections.emptyList())).getTransactionId();
// name is not case sensitive
execute(manager, "DROP TABLE tblspace1.tSQL", Collections.emptyList(), new TransactionContext(tx2));
try (DataScanner scan = scan(manager, "SELECT * FROM tblspace1.tsql ", Collections.emptyList())) {
List<DataAccessor> all = scan.consume();
assertEquals(1, all.size());
}
try (DataScanner scan = scan(manager, "SELECT * FROM tblspace1.systables where table_name='tsql'", Collections.emptyList())) {
List<DataAccessor> all = scan.consume();
assertEquals(1, all.size());
}
execute(manager, "EXECUTE committransaction 'tblspace1'," + tx2, Collections.emptyList());
try (DataScanner scan = scan(manager, "SELECT * FROM tblspace1.systables where table_name='tsql'", Collections.emptyList())) {
List<DataAccessor> all = scan.consume();
assertEquals(0, all.size());
}
try (DataScanner scan = scan(manager, "SELECT * FROM tblspace1.tsql ", Collections.emptyList())) {
fail();
} catch (TableDoesNotExistException ok) {
assertTrue(manager.getPlanner() instanceof JSQLParserPlanner);
} catch (StatementExecutionException ok) {
assertEquals("From line 1, column 15 to line 1, column 28: Object 'TSQL' not found within 'tblspace1'", ok.getMessage());
assertTrue(manager.getPlanner() instanceof CalcitePlanner);
}
}
}
use of herddb.mem.MemoryMetadataStorageManager in project herddb by diennea.
the class SimpleIndexAccessTest method multipleColumnPrimaryKeyPrefixScanWithAliasTest.
@Test
public void multipleColumnPrimaryKeyPrefixScanWithAliasTest() 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.q1_HISTORY (\n" + " MSG_ID BIGINT NOT NULL,\n" + " SID TINYINT NOT NULL, \n" + " STATUS INT NOT NULL,\n" + " TIMESTAMP TIMESTAMP,\n" + " STATUSLINE VARCHAR(2000) NULL,\n" + " IDBOUNCECATEGORY SMALLINT NULL,\n" + " PRIMARY KEY (MSG_ID, SID)\n" + ") ;", Collections.emptyList());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.q1_HISTORY(MSG_ID,SID,STATUS) values(1,1,1)", Collections.emptyList()).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.q1_HISTORY(MSG_ID,SID,STATUS) values(1,2,1)", Collections.emptyList()).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.q1_HISTORY(MSG_ID,SID,STATUS) values(1,3,1)", Collections.emptyList()).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.q1_HISTORY(MSG_ID,SID,STATUS) values(2,1,1)", Collections.emptyList()).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.q1_HISTORY(MSG_ID,SID,STATUS) values(2,2,1)", Collections.emptyList()).getUpdateCount());
{
TranslatedQuery translate = manager.getPlanner().translate(TableSpace.DEFAULT, "" + "SELECT H.SID, H.STATUS, H.`TIMESTAMP`, H.STATUSLINE, H.IDBOUNCECATEGORY " + "FROM tblspace1.q1_HISTORY AS H " + "WHERE H.MSG_ID=?", Arrays.asList(1), true, true, false, -1);
ScanStatement scan = translate.plan.mainStatement.unwrap(ScanStatement.class);
assertTrue(scan.getPredicate().getIndexOperation() instanceof PrimaryIndexPrefixScan);
try (DataScanner scan1 = manager.scan(scan, translate.context, TransactionContext.NO_TRANSACTION)) {
assertEquals(3, scan1.consume().size());
}
}
}
}
use of herddb.mem.MemoryMetadataStorageManager in project herddb by diennea.
the class SimpleIndexAccessTest method whereOnPkScanTest.
@Test
public void whereOnPkScanTest() 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," + "n1 int primary key," + "s1 string " + ")", Collections.emptyList());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey", Integer.valueOf(1234))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey2", Integer.valueOf(1235))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey3", Integer.valueOf(1236))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey4", Integer.valueOf(1237))).getUpdateCount());
{
TranslatedQuery translate = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT k1 as theKey," + "'one' as theStringConstant,3 LongConstant FROM tblspace1.tsql where n1 >= ?", Arrays.asList(1235), true, true, false, -1);
ScanStatement scan = translate.plan.mainStatement.unwrap(ScanStatement.class);
assertTrue(scan.getPredicate() instanceof SQLRecordPredicate);
SQLRecordPredicate sqlPred = (SQLRecordPredicate) scan.getPredicate();
assertTrue(sqlPred.getPrimaryKeyFilter() != null);
System.out.println("pkFilter:" + sqlPred.getPrimaryKeyFilter());
try (DataScanner scan1 = ((ScanResult) manager.executePlan(translate.plan, translate.context, TransactionContext.NO_TRANSACTION)).dataScanner) {
assertEquals(3, scan1.consume().size());
}
}
{
TranslatedQuery translate = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT k1 as theKey," + "'one' as theStringConstant,3 LongConstant FROM tblspace1.tsql where n1 >= 30", Arrays.asList(1235), true, true, false, -1);
ScanStatement scan = translate.plan.mainStatement.unwrap(ScanStatement.class);
assertTrue(scan.getPredicate() instanceof SQLRecordPredicate);
SQLRecordPredicate sqlPred = (SQLRecordPredicate) scan.getPredicate();
assertTrue(sqlPred.getPrimaryKeyFilter() != null);
System.out.println("pkFilter:" + sqlPred.getPrimaryKeyFilter());
try (DataScanner scan1 = manager.scan(scan, translate.context, TransactionContext.NO_TRANSACTION)) {
assertEquals(4, scan1.consume().size());
}
}
{
TranslatedQuery translate = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT k1 as theKey," + "'one' as theStringConstant,3 LongConstant FROM tblspace1.tsql" + " where n1 >= 30 and n1 >= 1235", Arrays.asList(1235), true, true, false, -1);
ScanStatement scan = translate.plan.mainStatement.unwrap(ScanStatement.class);
assertTrue(scan.getPredicate() instanceof SQLRecordPredicate);
SQLRecordPredicate sqlPred = (SQLRecordPredicate) scan.getPredicate();
assertTrue(sqlPred.getPrimaryKeyFilter() != null);
System.out.println("pkFilter:" + sqlPred.getPrimaryKeyFilter());
try (DataScanner scan1 = manager.scan(scan, translate.context, TransactionContext.NO_TRANSACTION)) {
assertEquals(3, scan1.consume().size());
}
}
{
TranslatedQuery translate = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT k1 as theKey," + "'one' as theStringConstant,3 LongConstant FROM tblspace1.tsql where n1 >= 10000 or n1 >= ?", Arrays.asList(1235), true, true, false, -1);
ScanStatement scan = translate.plan.mainStatement.unwrap(ScanStatement.class);
assertTrue(scan.getPredicate() instanceof SQLRecordPredicate);
SQLRecordPredicate sqlPred = (SQLRecordPredicate) scan.getPredicate();
assertNull(sqlPred.getPrimaryKeyFilter());
System.out.println("pkFilter:" + sqlPred.getPrimaryKeyFilter());
try (DataScanner scan1 = manager.scan(scan, translate.context, TransactionContext.NO_TRANSACTION)) {
assertEquals(3, scan1.consume().size());
}
}
}
}
Aggregations