Search in sources :

Example 36 with DataAccessor

use of herddb.utils.DataAccessor in project herddb by diennea.

the class SysnodesTest method listNodesTest.

@Test
public void listNodesTest() throws Exception {
    String nodeId = "localhost";
    try (DBManager manager = new DBManager(nodeId, new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
        manager.start();
        assertTrue(manager.waitForTablespace(TableSpace.DEFAULT, 10000));
        try (DataScanner scan = scan(manager, "SELECT * FROM SYSNODES", Collections.emptyList())) {
            List<DataAccessor> tuples = scan.consume();
            assertEquals(1, tuples.size());
            for (DataAccessor t : tuples) {
                System.out.println("node: " + t.toMap());
                assertNotNull(t.get("nodeid"));
                assertNotNull(t.get("address"));
            }
        }
    }
}
Also used : DataScanner(herddb.model.DataScanner) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) DataAccessor(herddb.utils.DataAccessor) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 37 with DataAccessor

use of herddb.utils.DataAccessor in project herddb by diennea.

the class UnloadDirtyPageTest method unloadDirtyPageOnCheckpoint.

@Test
public void unloadDirtyPageOnCheckpoint() 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(), NO_TRANSACTION);
        manager.waitForTablespace("tblspace1", 10000);
        execute(manager, "CREATE TABLE tblspace1.tsql (K1 string ,s1 string,n1 int, primary key(k1))", Collections.emptyList());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,s1,n1) values(?,?,?)", Arrays.asList("mykey", "a", Integer.valueOf(1234))).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,s1,n1) values(?,?,?)", Arrays.asList("mykey2", "a", Integer.valueOf(1234))).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,s1,n1) values(?,?,?)", Arrays.asList("mykey3", "a", Integer.valueOf(1234))).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,s1,n1) values(?,?,?)", Arrays.asList("mykey4", "a", Integer.valueOf(1234))).getUpdateCount());
        manager.checkpoint();
        assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.tsql set s1=? where k1=?", Arrays.asList("b", "mykey4")).getUpdateCount());
        manager.checkpoint();
        assertEquals(2, manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getStats().getLoadedpages());
        try (DataScanner scan = scan(manager, "SELECT * FROM tblspace1.tsql where k1 = 'mykey4'", Collections.emptyList())) {
            List<DataAccessor> result = scan.consume();
            assertEquals(1, result.size());
            assertEquals(RawString.of("b"), result.get(0).get("s1"));
        }
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DataScanner(herddb.model.DataScanner) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) DataAccessor(herddb.utils.DataAccessor) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) RawString(herddb.utils.RawString) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 38 with DataAccessor

use of herddb.utils.DataAccessor in project herddb by diennea.

the class UnloadDirtyPageTest method rebuildPageOnCheckpoint.

@Test
public void rebuildPageOnCheckpoint() 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(), NO_TRANSACTION);
        manager.waitForTablespace("tblspace1", 10000);
        execute(manager, "CREATE TABLE tblspace1.tsql (K1 string ,s1 string,n1 int, primary key(k1))", Collections.emptyList());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,s1,n1) values(?,?,?)", Arrays.asList("mykey", "a", Integer.valueOf(1234))).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,s1,n1) values(?,?,?)", Arrays.asList("mykey2", "a", Integer.valueOf(1234))).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,s1,n1) values(?,?,?)", Arrays.asList("mykey3", "a", Integer.valueOf(1234))).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,s1,n1) values(?,?,?)", Arrays.asList("mykey4", "a", Integer.valueOf(1234))).getUpdateCount());
        manager.checkpoint();
        assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.tsql set s1=? where k1=?", Arrays.asList("b", "mykey4")).getUpdateCount());
        manager.checkpoint();
        assertEquals(2, manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getStats().getLoadedpages());
        try (DataScanner scan = scan(manager, "SELECT * FROM tblspace1.tsql where k1 = 'mykey4'", Collections.emptyList())) {
            List<DataAccessor> result = scan.consume();
            assertEquals(1, result.size());
            assertEquals(RawString.of("b"), result.get(0).get("s1"));
        }
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DataScanner(herddb.model.DataScanner) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) DataAccessor(herddb.utils.DataAccessor) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) RawString(herddb.utils.RawString) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 39 with DataAccessor

use of herddb.utils.DataAccessor in project herddb by diennea.

the class RunHerdDB070Test method test.

@Test
public void test() throws Exception {
    String file = "herddb.070.joinerror.zip";
    File dbdatadir = folder.newFolder("dbdata070_" + file);
    try (InputStream in = RunHerdDB070Test.class.getResourceAsStream(file)) {
        ZIPUtils.unZip(in, dbdatadir);
    }
    System.out.println("UNZIPPED TO " + dbdatadir);
    final Path dbdata = dbdatadir.toPath().resolve("herddb.070.joinerror").resolve("dbdata");
    Path metadataPath = dbdata.resolve("metadata");
    Path dataPath = dbdata.resolve("data");
    Path logsPath = dbdata.resolve("txlog");
    Path tmoDir = dbdata.resolve("tmp");
    assertTrue(Files.isDirectory(metadataPath));
    assertTrue(Files.isDirectory(dataPath));
    assertTrue(Files.isDirectory(logsPath));
    Path nodeid = dataPath.resolve("nodeid");
    assertTrue(Files.isRegularFile(nodeid));
    String id = new String(Files.readAllBytes(nodeid), StandardCharsets.UTF_8);
    System.out.println("id:" + id);
    String expectedNodeId = "asino";
    assertTrue(id.endsWith("\n" + expectedNodeId));
    try (DBManager manager = new DBManager(expectedNodeId, new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new FileCommitLogManager(logsPath), tmoDir, null)) {
        manager.start();
        final String tableSpace = "herd";
        final String tableName = "testtable";
        assertEquals(expectedNodeId, manager.getNodeId());
        assertTrue(manager.waitForTablespace(tableSpace, 10000));
        AbstractTableManager tableManagerLicense = manager.getTableSpaceManager("herd").getTableManager("license");
        Table tableLicense = tableManagerLicense.getTable();
        System.out.println("TABLE PK: " + Arrays.toString(tableLicense.primaryKey));
        for (Column c : tableLicense.columns) {
            System.out.println("COL: " + c.name + " serialPos: " + c.serialPosition);
        }
        AbstractTableManager tableManagerCustomer = manager.getTableSpaceManager("herd").getTableManager("customer");
        Table tableCustomer = tableManagerCustomer.getTable();
        System.out.println("TABLE PK: " + Arrays.toString(tableCustomer.primaryKey));
        for (Column c : tableCustomer.columns) {
            System.out.println("COL: " + c.name + " serialPos: " + c.serialPosition);
        }
        {
            TranslatedQuery translated = manager.getPlanner().translate(tableSpace, "SELECT * FROM license", Collections.emptyList(), true, true, false, -1);
            System.out.println("TABLE CONTENTS");
            try (DataScanner scan1 = ((ScanResult) manager.executePlan(translated.plan, translated.context, TransactionContext.NO_TRANSACTION)).dataScanner) {
                List<DataAccessor> consume = scan1.consume();
                System.out.println("NUM " + consume.size());
                assertEquals(15, consume.size());
                for (DataAccessor r : consume) {
                    System.out.println("RECORD " + r.toMap());
                }
            }
        }
        {
            TranslatedQuery translated = manager.getPlanner().translate(tableSpace, "SELECT * FROM customer", Collections.emptyList(), true, true, false, -1);
            System.out.println("TABLE CONTENTS");
            try (DataScanner scan1 = ((ScanResult) manager.executePlan(translated.plan, translated.context, TransactionContext.NO_TRANSACTION)).dataScanner) {
                List<DataAccessor> consume = scan1.consume();
                System.out.println("NUM " + consume.size());
                assertEquals(7, consume.size());
                for (DataAccessor r : consume) {
                    System.out.println("RECORD " + r.toMap());
                }
            }
        }
        {
            TranslatedQuery translated = manager.getPlanner().translate(tableSpace, "SELECT t0.license_id,c.customer_id FROM license t0, customer c WHERE c.customer_id = 3 AND t0.customer_id = 3 AND c.customer_id = t0.customer_id\n" + "            ", Collections.emptyList(), true, true, false, -1);
            System.out.println("TABLE CONTENTS");
            try (DataScanner scan1 = ((ScanResult) manager.executePlan(translated.plan, translated.context, TransactionContext.NO_TRANSACTION)).dataScanner) {
                List<DataAccessor> consume = scan1.consume();
                System.out.println("NUM " + consume.size());
                assertEquals(9, consume.size());
                for (DataAccessor r : consume) {
                    System.out.println("RECORD " + r.toMap());
                }
            }
        }
        {
            TranslatedQuery translated = manager.getPlanner().translate(tableSpace, "SELECT * FROM license t0, customer c WHERE c.customer_id = t0.customer_id", Collections.emptyList(), true, true, false, -1);
            System.out.println("TABLE CONTENTS");
            try (DataScanner scan1 = ((ScanResult) manager.executePlan(translated.plan, translated.context, TransactionContext.NO_TRANSACTION)).dataScanner) {
                List<DataAccessor> consume = scan1.consume();
                System.out.println("NUM " + consume.size());
                assertEquals(15, consume.size());
                for (DataAccessor r : consume) {
                    System.out.println("RECORD " + r.toMap());
                }
            }
        }
    }
}
Also used : Path(java.nio.file.Path) Table(herddb.model.Table) TranslatedQuery(herddb.sql.TranslatedQuery) InputStream(java.io.InputStream) FileMetadataStorageManager(herddb.file.FileMetadataStorageManager) DataAccessor(herddb.utils.DataAccessor) FileCommitLogManager(herddb.file.FileCommitLogManager) DBManager(herddb.core.DBManager) DataScanner(herddb.model.DataScanner) AbstractTableManager(herddb.core.AbstractTableManager) Column(herddb.model.Column) FileDataStorageManager(herddb.file.FileDataStorageManager) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 40 with DataAccessor

use of herddb.utils.DataAccessor in project herddb by diennea.

the class UpgradeFrom050WithBrinIndexesTest method test.

private void test(String file) throws Exception {
    File dbdatadir = folder.newFolder("dbdata050_" + file);
    try (InputStream in = UpgradeFrom050WithBrinIndexesTest.class.getResourceAsStream(file)) {
        ZIPUtils.unZip(in, dbdatadir);
    }
    final Path dbdata = dbdatadir.toPath().resolve("dbdata");
    Path metadataPath = dbdata.resolve("metadata");
    Path dataPath = dbdata.resolve("data");
    Path logsPath = dbdata.resolve("txlog");
    Path tmoDir = dbdata.resolve("tmp");
    assertTrue(Files.isDirectory(metadataPath));
    assertTrue(Files.isDirectory(dataPath));
    assertTrue(Files.isDirectory(logsPath));
    Path nodeid = dataPath.resolve("nodeid");
    assertTrue(Files.isRegularFile(nodeid));
    String id = new String(Files.readAllBytes(nodeid), StandardCharsets.UTF_8);
    System.out.println("id:" + id);
    String expectedNodeId = "capra";
    assertTrue(id.endsWith("\n" + expectedNodeId));
    try (DBManager manager = new DBManager(expectedNodeId, new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new FileCommitLogManager(logsPath), tmoDir, null)) {
        manager.start();
        final String tableSpace = "herd";
        final String tableName = "testtable";
        assertEquals(expectedNodeId, manager.getNodeId());
        assertTrue(manager.waitForTablespace(tableSpace, 10000));
        TableSpaceManager tableSpaceManager = manager.getTableSpaceManager(tableSpace);
        AbstractTableManager tableManager = tableSpaceManager.getTableManager(tableName);
        List<Index> indexes = tableManager.getAvailableIndexes();
        for (Index e : indexes) {
            System.out.println("INDEX: " + e);
            assertEquals(e.type, Index.TYPE_BRIN);
        }
        assertEquals(4, indexes.size());
        for (Column c : tableManager.getTable().getColumns()) {
            System.out.println("COLUMN :" + c);
        }
        {
            TranslatedQuery translated = manager.getPlanner().translate(tableSpace, "SELECT * FROM " + tableName + " ORDER BY pk,n1,n2", Collections.emptyList(), true, true, false, -1);
            ScanStatement scan = translated.plan.mainStatement.unwrap(ScanStatement.class);
            System.out.println("TABLE CONTENTS");
            try (DataScanner scan1 = manager.scan(scan, translated.context, TransactionContext.NO_TRANSACTION)) {
                for (DataAccessor r : scan1.consume()) {
                    System.out.println("RECORD " + r.toMap());
                }
            }
        }
        test(new TestCase("SELECT * FROM " + tableSpace + "." + tableName + " WHERE n1=1", SecondaryIndexSeek.class, 4), manager, tableSpace);
        // this could be SecondaryIndexSeek but we have more indexes and the planner is not so smart
        test(new TestCase("SELECT * FROM " + tableSpace + "." + tableName + " WHERE n2=3", SecondaryIndexPrefixScan.class, 2), manager, tableSpace);
        test(new TestCase("SELECT * FROM " + tableSpace + "." + tableName + " WHERE n2>=3", SecondaryIndexRangeScan.class, 3), manager, tableSpace);
        test(new TestCase("SELECT * FROM " + tableSpace + "." + tableName + " WHERE n1=1 and n2=3", SecondaryIndexPrefixScan.class, 1), manager, tableSpace);
    }
}
Also used : Path(java.nio.file.Path) TranslatedQuery(herddb.sql.TranslatedQuery) SecondaryIndexRangeScan(herddb.index.SecondaryIndexRangeScan) InputStream(java.io.InputStream) FileMetadataStorageManager(herddb.file.FileMetadataStorageManager) DataAccessor(herddb.utils.DataAccessor) Index(herddb.model.Index) FileCommitLogManager(herddb.file.FileCommitLogManager) DBManager(herddb.core.DBManager) DataScanner(herddb.model.DataScanner) SecondaryIndexSeek(herddb.index.SecondaryIndexSeek) AbstractTableManager(herddb.core.AbstractTableManager) Column(herddb.model.Column) FileDataStorageManager(herddb.file.FileDataStorageManager) TableSpaceManager(herddb.core.TableSpaceManager) SecondaryIndexPrefixScan(herddb.index.SecondaryIndexPrefixScan) File(java.io.File) ScanStatement(herddb.model.commands.ScanStatement)

Aggregations

DataAccessor (herddb.utils.DataAccessor)164 DataScanner (herddb.model.DataScanner)118 Test (org.junit.Test)110 MemoryCommitLogManager (herddb.mem.MemoryCommitLogManager)83 MemoryDataStorageManager (herddb.mem.MemoryDataStorageManager)82 MemoryMetadataStorageManager (herddb.mem.MemoryMetadataStorageManager)82 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)76 RawString (herddb.utils.RawString)70 DBManager (herddb.core.DBManager)52 TransactionContext (herddb.model.TransactionContext)44 StatementExecutionException (herddb.model.StatementExecutionException)38 Table (herddb.model.Table)34 List (java.util.List)31 DataScannerException (herddb.model.DataScannerException)28 DMLStatementExecutionResult (herddb.model.DMLStatementExecutionResult)27 RuntimeProjectedDataAccessor (herddb.model.planner.ProjectOp.ZeroCopyProjection.RuntimeProjectedDataAccessor)27 Column (herddb.model.Column)22 ScanResult (herddb.model.ScanResult)22 ScanStatement (herddb.model.commands.ScanStatement)22 Bytes (herddb.utils.Bytes)22