use of herddb.mem.MemoryCommitLogManager in project herddb by diennea.
the class SimplerPlannerTest method plannerUpdateTest.
@Test
public void plannerUpdateTest() 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());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey", Integer.valueOf(1234))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.tsql set n1=1111", Collections.emptyList()).getUpdateCount());
try (DataScanner scan = scan(manager, "SELECT * FROM tblspace1.tsql where n1=1111", Collections.emptyList())) {
List<DataAccessor> results = scan.consume();
assertEquals(1, results.size());
}
assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.tsql set n1=1112 where k1='mykey'", Collections.emptyList()).getUpdateCount());
try (DataScanner scan = scan(manager, "SELECT * FROM tblspace1.tsql where n1=1112", Collections.emptyList())) {
List<DataAccessor> results = scan.consume();
assertEquals(1, results.size());
}
assertEquals(0, executeUpdate(manager, "UPDATE tblspace1.tsql set n1=1112 where k1='no'", Collections.emptyList()).getUpdateCount());
assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.tsql set n1=n1+1 where k1='mykey'", Collections.emptyList()).getUpdateCount());
try (DataScanner scan = scan(manager, "SELECT * FROM tblspace1.tsql where n1=1113", Collections.emptyList())) {
List<DataAccessor> results = scan.consume();
assertEquals(1, results.size());
}
assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.tsql set n1=? where k1=?", Arrays.asList(1114, "mykey")).getUpdateCount());
try (DataScanner scan = scan(manager, "SELECT * FROM tblspace1.tsql where n1=1114", Collections.emptyList())) {
List<DataAccessor> results = scan.consume();
assertEquals(1, results.size());
}
}
}
use of herddb.mem.MemoryCommitLogManager in project herddb by diennea.
the class CalcitePlannerTest method zeroCopyProjectionTest.
@Test
public void zeroCopyProjectionTest() throws Exception {
String nodeId = "localhost";
try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
assumeTrue(manager.getPlanner() instanceof CalcitePlanner);
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," + "s1 string)", Collections.emptyList());
execute(manager, "INSERT INTO tblspace1.tsql (k1 ," + "s1) values('testk1','tests1')", Collections.emptyList());
try (DataScanner scan = scan(manager, "SELECT * FROM tblspace1.tsql", Collections.emptyList())) {
List<DataAccessor> consume = scan.consume();
assertEquals(1, consume.size());
DataAccessor record = consume.get(0);
assertThat(record, instanceOf(DataAccessorForFullRecord.class));
assertEquals("k1", record.getFieldNames()[0]);
assertEquals("s1", record.getFieldNames()[1]);
assertEquals(RawString.of("testk1"), record.get(0));
assertEquals(RawString.of("tests1"), record.get(1));
assertEquals(RawString.of("testk1"), record.get("k1"));
assertEquals(RawString.of("tests1"), record.get("s1"));
}
try (DataScanner scan = scan(manager, "SELECT k1,s1 FROM tblspace1.tsql", Collections.emptyList())) {
List<DataAccessor> consume = scan.consume();
assertEquals(1, consume.size());
DataAccessor record = consume.get(0);
assertThat(record, instanceOf(DataAccessorForFullRecord.class));
assertEquals("k1", record.getFieldNames()[0]);
assertEquals("s1", record.getFieldNames()[1]);
assertEquals(RawString.of("testk1"), record.get(0));
assertEquals(RawString.of("tests1"), record.get(1));
assertEquals(RawString.of("testk1"), record.get("k1"));
assertEquals(RawString.of("tests1"), record.get("s1"));
}
try (DataScanner scan = scan(manager, "SELECT s1,k1 FROM tblspace1.tsql", Collections.emptyList())) {
List<DataAccessor> consume = scan.consume();
assertEquals(1, consume.size());
DataAccessor record = consume.get(0);
assertThat(record, instanceOf(ZeroCopyProjection.RuntimeProjectedDataAccessor.class));
assertEquals("k1", record.getFieldNames()[1]);
assertEquals("s1", record.getFieldNames()[0]);
assertEquals(RawString.of("testk1"), record.get(1));
assertEquals(RawString.of("tests1"), record.get(0));
assertEquals(RawString.of("testk1"), record.get("k1"));
assertEquals(RawString.of("tests1"), record.get("s1"));
}
try (DataScanner scan = scan(manager, "SELECT s1 FROM tblspace1.tsql", Collections.emptyList())) {
List<DataAccessor> consume = scan.consume();
assertEquals(1, consume.size());
DataAccessor record = consume.get(0);
assertThat(record, instanceOf(RuntimeProjectedDataAccessor.class));
assertEquals("s1", record.getFieldNames()[0]);
assertEquals(RawString.of("tests1"), record.get(0));
assertEquals(RawString.of("tests1"), record.get("s1"));
}
try (DataScanner scan = scan(manager, "SELECT k1 FROM tblspace1.tsql", Collections.emptyList())) {
List<DataAccessor> consume = scan.consume();
assertEquals(1, consume.size());
DataAccessor record = consume.get(0);
assertThat(record, instanceOf(RuntimeProjectedDataAccessor.class));
assertEquals("k1", record.getFieldNames()[0]);
assertEquals(RawString.of("testk1"), record.get(0));
assertEquals(RawString.of("testk1"), record.get("k1"));
}
}
}
use of herddb.mem.MemoryCommitLogManager in project herddb by diennea.
the class CalcitePlannerTest method simplePlansTests.
@Test
public void simplePlansTests() throws Exception {
String nodeId = "localhost";
try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
assumeThat(manager.getPlanner(), instanceOf(CalcitePlanner.class));
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());
execute(manager, "INSERT INTO tblspace1.tsql (k1,n1) values(?,?)", Arrays.asList("mykey", 1234), TransactionContext.NO_TRANSACTION);
try (DataScanner scan = scan(manager, "SELECT n1,k1 FROM tblspace1.tsql where k1='mykey'", Collections.emptyList())) {
assertEquals(1, scan.consume().size());
}
assertInstanceOf(plan(manager, "select * from tblspace1.tsql"), TableScanOp.class);
assertInstanceOf(plan(manager, "select * from tblspace1.tsql where n1=1"), BindableTableScanOp.class);
assertInstanceOf(plan(manager, "select n1 from tblspace1.tsql"), BindableTableScanOp.class);
assertInstanceOf(plan(manager, "update tblspace1.tsql set n1=? where k1=?"), SimpleUpdateOp.class);
assertInstanceOf(plan(manager, "update tblspace1.tsql set n1=? where k1=? and n1=?"), SimpleUpdateOp.class);
assertInstanceOf(plan(manager, "update tblspace1.tsql set n1=?" + " where n1 in (select b.n1*2 from tblspace1.tsql b)"), UpdateOp.class);
assertInstanceOf(plan(manager, "delete from tblspace1.tsql where k1=?"), SimpleDeleteOp.class);
assertInstanceOf(plan(manager, "delete from tblspace1.tsql where k1=? and n1=?"), SimpleDeleteOp.class);
assertInstanceOf(plan(manager, "delete from tblspace1.tsql where n1 in (select b.n1*2 from tblspace1.tsql b)"), DeleteOp.class);
assertInstanceOf(plan(manager, "INSERT INTO tblspace1.tsql (k1,n1) values(?,?)"), SimpleInsertOp.class);
assertInstanceOf(plan(manager, "INSERT INTO tblspace1.tsql (k1,n1) values(?,?),(?,?)"), InsertOp.class);
assertInstanceOf(plan(manager, "select k1 from tblspace1.tsql order by k1"), SortedBindableTableScanOp.class);
assertInstanceOf(plan(manager, "select k1 from tblspace1.tsql order by k1 limit 10"), LimitedSortedBindableTableScanOp.class);
{
BindableTableScanOp plan = assertInstanceOf(plan(manager, "select * from tblspace1.tsql where k1=?"), BindableTableScanOp.class);
Projection projection = plan.getStatement().getProjection();
System.out.println("projection:" + projection);
assertThat(projection, instanceOf(IdentityProjection.class));
assertNull(plan.getStatement().getComparator());
}
{
SortedBindableTableScanOp plan = assertInstanceOf(plan(manager, "select n1,k1 from tblspace1.tsql order by n1"), SortedBindableTableScanOp.class);
Projection projection = plan.getStatement().getProjection();
System.out.println("projection:" + projection);
assertThat(projection, instanceOf(ZeroCopyProjection.class));
ZeroCopyProjection zero = (ZeroCopyProjection) projection;
assertArrayEquals(new String[] { "n1", "k1" }, zero.getFieldNames());
assertEquals("n1", zero.getColumns()[0].name);
assertEquals("k1", zero.getColumns()[1].name);
TupleComparator comparator = plan.getStatement().getComparator();
System.out.println("comparator:" + comparator);
assertThat(comparator, instanceOf(SortOp.class));
SortOp sortOp = (SortOp) comparator;
assertFalse(sortOp.isOnlyPrimaryKeyAndAscending());
}
{
SortedBindableTableScanOp plan = assertInstanceOf(plan(manager, "select n1,k1 from tblspace1.tsql order by k1"), SortedBindableTableScanOp.class);
Projection projection = plan.getStatement().getProjection();
System.out.println("projection:" + projection);
assertThat(projection, instanceOf(ZeroCopyProjection.class));
ZeroCopyProjection zero = (ZeroCopyProjection) projection;
assertArrayEquals(new String[] { "n1", "k1" }, zero.getFieldNames());
assertEquals("n1", zero.getColumns()[0].name);
assertEquals("k1", zero.getColumns()[1].name);
TupleComparator comparator = plan.getStatement().getComparator();
System.out.println("comparator:" + comparator);
assertThat(comparator, instanceOf(SortOp.class));
SortOp sortOp = (SortOp) comparator;
assertTrue(sortOp.isOnlyPrimaryKeyAndAscending());
}
{
SortedTableScanOp plan = assertInstanceOf(plan(manager, "select * from tblspace1.tsql order by n1"), SortedTableScanOp.class);
Projection projection = plan.getStatement().getProjection();
System.out.println("projection:" + projection);
assertThat(projection, instanceOf(IdentityProjection.class));
IdentityProjection zero = (IdentityProjection) projection;
assertArrayEquals(new String[] { "k1", "n1", "s1" }, zero.getFieldNames());
assertEquals("k1", zero.getColumns()[0].name);
assertEquals("n1", zero.getColumns()[1].name);
assertEquals("s1", zero.getColumns()[2].name);
TupleComparator comparator = plan.getStatement().getComparator();
System.out.println("comparator:" + comparator);
assertThat(comparator, instanceOf(SortOp.class));
SortOp sortOp = (SortOp) comparator;
assertFalse(sortOp.isOnlyPrimaryKeyAndAscending());
}
{
SortedTableScanOp plan = assertInstanceOf(plan(manager, "select * from tblspace1.tsql order by k1"), SortedTableScanOp.class);
Projection projection = plan.getStatement().getProjection();
System.out.println("projection:" + projection);
assertThat(projection, instanceOf(IdentityProjection.class));
IdentityProjection zero = (IdentityProjection) projection;
assertArrayEquals(new String[] { "k1", "n1", "s1" }, zero.getFieldNames());
assertEquals("k1", zero.getColumns()[0].name);
assertEquals("n1", zero.getColumns()[1].name);
assertEquals("s1", zero.getColumns()[2].name);
TupleComparator comparator = plan.getStatement().getComparator();
System.out.println("comparator:" + comparator);
assertThat(comparator, instanceOf(SortOp.class));
SortOp sortOp = (SortOp) comparator;
assertTrue(sortOp.isOnlyPrimaryKeyAndAscending());
}
}
}
use of herddb.mem.MemoryCommitLogManager in project herddb by diennea.
the class AlterTableSQLTest method modifyColumn.
@Test
public void modifyColumn() 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 int primary key auto_increment,n1 int,s1 string)", Collections.emptyList());
assertTrue(manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getTable().auto_increment);
Table table = manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getTable();
assertEquals(0, table.getColumn("k1").serialPosition);
assertEquals(1, table.getColumn("n1").serialPosition);
assertEquals(2, table.getColumn("s1").serialPosition);
execute(manager, "INSERT INTO tblspace1.tsql (n1,s1) values(1,'b')", Collections.emptyList());
{
List<DataAccessor> tuples = scan(manager, "SELECT * FROM tblspace1.tsql where k1=1", Collections.emptyList()).consume();
assertEquals(1, tuples.size());
assertEquals(3, tuples.get(0).getFieldNames().length);
}
execute(manager, "ALTER TABLE tblspace1.tsql modify column k1 int", Collections.emptyList());
execute(manager, "INSERT INTO tblspace1.tsql (k1,n1,s1) values(2, 2,'b')", Collections.emptyList());
{
List<DataAccessor> tuples = scan(manager, "SELECT * FROM tblspace1.tsql", Collections.emptyList()).consume();
assertEquals(2, tuples.size());
assertEquals(3, tuples.get(0).getFieldNames().length);
}
{
List<DataAccessor> tuples = scan(manager, "SELECT * FROM tblspace1.tsql where k1=2", Collections.emptyList()).consume();
assertEquals(1, tuples.size());
assertEquals(3, tuples.get(0).getFieldNames().length);
}
assertFalse(manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getTable().auto_increment);
execute(manager, "ALTER TABLE tblspace1.tsql modify column k1 int auto_increment", Collections.emptyList());
assertTrue(manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getTable().auto_increment);
execute(manager, "INSERT INTO tblspace1.tsql (n1,s1) values(1,'b')", Collections.emptyList());
{
List<DataAccessor> tuples = scan(manager, "SELECT * FROM tblspace1.tsql", Collections.emptyList()).consume();
assertEquals(3, tuples.size());
assertEquals(3, tuples.get(0).getFieldNames().length);
}
try {
execute(manager, "ALTER TABLE tblspace1.tsql modify column k1 string", Collections.emptyList());
fail();
} catch (StatementExecutionException error) {
assertTrue(error.getMessage().contains("cannot change datatype"));
}
try {
execute(manager, "ALTER TABLE tblspace1.tsql modify column badcol string", Collections.emptyList());
fail();
} catch (StatementExecutionException error) {
assertTrue(error.getMessage().contains("bad column badcol in table tsql"));
}
execute(manager, "ALTER TABLE tblspace1.tsql MODIFY COLUMN k1 int RENAME TO l2", Collections.emptyList());
assertFalse(manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getTable().auto_increment);
{
List<DataAccessor> tuples = scan(manager, "SELECT * FROM tblspace1.tsql " + "where l2=1", Collections.emptyList()).consume();
assertEquals(1, tuples.size());
assertEquals(Arrays.toString(tuples.get(0).getFieldNames()), 3, tuples.get(0).getFieldNames().length);
assertEquals("l2", tuples.get(0).getFieldNames()[0]);
assertEquals("n1", tuples.get(0).getFieldNames()[1]);
assertEquals("s1", tuples.get(0).getFieldNames()[2]);
}
}
}
use of herddb.mem.MemoryCommitLogManager in project herddb by diennea.
the class AlterTableSQLTest method renameTable.
@Test
public void renameTable() 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 int primary key auto_increment,n1 int,s1 string)", Collections.emptyList());
execute(manager, "INSERT INTO tblspace1.tsql (n1,s1) values(1,'b')", Collections.emptyList());
{
List<DataAccessor> tuples = scan(manager, "SELECT * FROM tblspace1.tsql where k1=1", Collections.emptyList()).consume();
assertEquals(1, tuples.size());
assertEquals(3, tuples.get(0).getFieldNames().length);
}
execute(manager, "EXECUTE RENAMETABLE 'tblspace1','tsql','tsql2'", Collections.emptyList());
{
List<DataAccessor> tuples = scan(manager, "SELECT * FROM tblspace1.tsql2 where k1=1", Collections.emptyList()).consume();
assertEquals(1, tuples.size());
assertEquals(3, tuples.get(0).getFieldNames().length);
}
}
}
Aggregations