use of herddb.model.commands.InsertStatement in project herddb by diennea.
the class BigTableScanTest method bigTableScan.
@Test
public void bigTableScan() throws Exception {
int testSize = 5000;
String nodeId = "localhost";
try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
manager.setMaxMemoryReference(128 * 1024);
manager.setMaxLogicalPageSize(32 * 1024);
manager.setMaxPKUsedMemory(manager.getMaxLogicalPageSize() * 2);
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("name", ColumnTypes.STRING).primaryKey("id").build();
CreateTableStatement st2 = new CreateTableStatement(table);
manager.executeStatement(st2, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
for (int i = 0; i < testSize; i++) {
InsertStatement insert = new InsertStatement(table.tablespace, table.name, RecordSerializer.makeRecord(table, "id", "k" + i, "name", "testname" + i));
assertEquals(1, manager.executeUpdate(insert, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
TableManagerStats stats = manager.getTableSpaceManager(table.tablespace).getTableManager(table.name).getStats();
assertEquals(testSize, stats.getTablesize());
assertEquals(2, stats.getLoadedpages());
manager.checkpoint();
try (DataScanner scan = manager.scan(new ScanStatement(table.tablespace, table, new FullTableScanPredicate()), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION)) {
AtomicInteger count = new AtomicInteger();
scan.forEach(tuple -> {
count.incrementAndGet();
});
assertEquals(testSize, count.get());
}
assertEquals(testSize, stats.getTablesize());
}
}
use of herddb.model.commands.InsertStatement in project herddb by diennea.
the class ColumnTimestampTest method test2.
@Test
public void test2() throws Exception {
String tableName2 = "t2";
Table table2 = Table.builder().tablespace("tblspace1").name(tableName2).tablespace(tableSpace).column("id", ColumnTypes.STRING).column("name", ColumnTypes.STRING).column("ts1", ColumnTypes.TIMESTAMP).primaryKey("id").build();
CreateTableStatement st2 = new CreateTableStatement(table2);
manager.executeStatement(st2, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
java.sql.Timestamp ts1 = new java.sql.Timestamp(System.currentTimeMillis());
{
Map<String, Object> bean = new HashMap<>();
bean.put("id", "key1");
bean.put("ts1", ts1);
Record record = RecordSerializer.toRecord(bean, table2);
InsertStatement st = new InsertStatement(tableSpace, "t2", record);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
{
GetResult result = manager.get(new GetStatement(tableSpace, tableName2, Bytes.from_string("key1"), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertTrue(result.found());
Map<String, Object> resultbean = result.getRecord().toBean(table2);
assertEquals(Bytes.from_string("key1"), result.getRecord().key);
assertEquals(2, resultbean.entrySet().size());
assertEquals(RawString.of("key1"), resultbean.get("id"));
assertEquals(ts1, resultbean.get("ts1"));
}
{
Map<String, Object> bean = new HashMap<>();
bean.put("id", "key1");
bean.put("ts1", null);
Record record = RecordSerializer.toRecord(bean, table2);
UpdateStatement st = new UpdateStatement(tableSpace, tableName2, record, null);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
{
GetResult result = manager.get(new GetStatement(tableSpace, tableName2, Bytes.from_string("key1"), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertTrue(result.found());
Map<String, Object> resultbean = result.getRecord().toBean(table2);
assertEquals(Bytes.from_string("key1"), result.getRecord().key);
assertEquals(1, resultbean.entrySet().size());
assertEquals(RawString.of("key1"), resultbean.get("id"));
assertEquals(null, resultbean.get("ts1"));
}
}
use of herddb.model.commands.InsertStatement in project herddb by diennea.
the class DropOldPagesTest method test.
@Test
public void test() throws Exception {
FileDataStorageManager fileDataStorageManager = (FileDataStorageManager) dataStorageManager;
{
Record record = new Record(Bytes.from_string("key1"), Bytes.from_string("0"));
InsertStatement st = new InsertStatement(tableSpace, tableName, record);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
String tableUuid = manager.getTableSpaceManager(tableSpace).getTableManager(tableName).getTable().uuid;
assertEquals(0, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
assertEquals(0, fileDataStorageManager.getTablePageFiles(tableSpaceUUID, tableUuid).size());
manager.checkpoint();
assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
assertEquals(1, fileDataStorageManager.getTablePageFiles(tableSpaceUUID, tableUuid).size());
{
Record record = new Record(Bytes.from_string("key2"), Bytes.from_string("0"));
InsertStatement st = new InsertStatement(tableSpace, tableName, record);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
assertEquals(1, manager.executeUpdate(new DeleteStatement(tableSpace, tableName, Bytes.from_string("key1"), null), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
manager.checkpoint();
assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
assertEquals(1, fileDataStorageManager.getTablePageFiles(tableSpaceUUID, tableUuid).size());
}
use of herddb.model.commands.InsertStatement in project herddb by diennea.
the class MultipleColumnPrimaryKeyTest method test.
@Test
public void test() throws Exception {
{
Record record = RecordSerializer.makeRecord(table, "id", "r1", "name", "k1");
InsertStatement st = new InsertStatement(tableSpace, tableName, record);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
{
Map<String, Object> key = new HashMap<>();
key.put("id", "r1");
key.put("name", "k1");
GetResult result = manager.get(new GetStatement(tableSpace, tableName, RecordSerializer.serializePrimaryKey(key, table, table.primaryKey), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertTrue(result.found());
}
{
Map<String, Object> key = new HashMap<>();
key.put("id", "r1");
key.put("name", "k2");
GetResult result = manager.get(new GetStatement(tableSpace, tableName, RecordSerializer.serializePrimaryKey(key, table, table.primaryKey), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertTrue(!result.found());
}
{
Map<String, Object> key = new HashMap<>();
key.put("id", "r1");
key.put("name", "k1");
{
GetResult result = manager.get(new GetStatement(tableSpace, tableName, RecordSerializer.serializePrimaryKey(key, table, table.primaryKey), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertTrue(result.found());
}
{
DeleteStatement st = new DeleteStatement(tableSpace, tableName, RecordSerializer.serializePrimaryKey(key, table, table.primaryKey), null);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
{
GetResult result = manager.get(new GetStatement(tableSpace, tableName, RecordSerializer.serializePrimaryKey(key, table, table.primaryKey), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertFalse(result.found());
}
}
}
use of herddb.model.commands.InsertStatement in project herddb by diennea.
the class SimpleClusterTest method test.
@Test
public void test() throws Exception {
{
Record record = new Record(Bytes.from_string("key1"), Bytes.from_string("0"));
InsertStatement st = new InsertStatement(tableSpace, tableName, record);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
assertEquals(0, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableName));
manager.checkpoint();
String tableUuid = manager.getTableSpaceManager(tableSpace).getTableManager(tableName).getTable().uuid;
assertNotNull(dataStorageManager.readPage(tableSpaceUUID, tableUuid, 1L));
assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
{
GetResult result = manager.get(new GetStatement(tableSpace, tableName, Bytes.from_string("key1"), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertTrue(result.found());
}
manager.checkpoint();
assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
{
Record record = new Record(Bytes.from_string("key1"), Bytes.from_string("5"));
UpdateStatement st = new UpdateStatement(tableSpace, tableName, record, null);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
// a new page must be allocated
manager.checkpoint();
assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
{
Record record = new Record(Bytes.from_string("key1"), Bytes.from_string("6"));
UpdateStatement st = new UpdateStatement(tableSpace, tableName, record, null);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
{
Record record = new Record(Bytes.from_string("key1"), Bytes.from_string("7"));
UpdateStatement st = new UpdateStatement(tableSpace, tableName, record, null);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
// only a new page must be allocated, not two more
manager.checkpoint();
assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
{
DeleteStatement st = new DeleteStatement(tableSpace, tableName, Bytes.from_string("key1"), null);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
GetResult result = manager.get(new GetStatement(tableSpace, tableName, Bytes.from_string("key1"), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertFalse(result.found());
}
// a delete does not trigger new pages in this case
manager.checkpoint();
assertEquals(0, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
{
assertEquals(1, manager.executeUpdate(new InsertStatement(tableSpace, tableName, new Record(Bytes.from_string("key2"), Bytes.from_string("50"))), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
assertEquals(1, manager.executeUpdate(new InsertStatement(tableSpace, tableName, new Record(Bytes.from_string("key3"), Bytes.from_string("60"))), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
manager.checkpoint();
assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
{
DeleteStatement st = new DeleteStatement(tableSpace, tableName, Bytes.from_string("key2"), null);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
// a new page, containg the key3 record is needed
manager.checkpoint();
assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
Holder<TableStatus> _tableStatus = new Holder<>();
dataStorageManager.fullTableScan(tableSpaceUUID, tableUuid, new FullTableScanConsumer() {
@Override
public void acceptTableStatus(TableStatus tableStatus) {
_tableStatus.value = tableStatus;
}
@Override
public void startPage(long pageId) {
}
@Override
public void acceptRecord(Record record) {
}
@Override
public void endPage() {
}
@Override
public void endTable() {
}
});
for (long pageId : _tableStatus.value.activePages.keySet()) {
List<Record> records = dataStorageManager.readPage(tableSpaceUUID, tableUuid, pageId);
System.out.println("PAGE #" + pageId + " records :" + records);
}
assertEquals(1, _tableStatus.value.activePages.size());
}
Aggregations