Search in sources :

Example 1 with ProjectedDataAccessor

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

the class SimpleScanZeroCopyTest method test.

@Test
public void test() 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());
        execute(manager, "INSERT INTO tblspace1.tsql (k1,n1 ,s1) values (?,?,?)", Arrays.asList("a", 1, "b"));
        try (DataScanner scan = TestUtils.scan(manager, "SELECT * FROM tblspace1.tsql ", Collections.emptyList())) {
            List<DataAccessor> data = scan.consume();
            assertEquals(1, data.size());
            // read from the full record
            assertTrue(data.get(0) instanceof DataAccessorForFullRecord);
        }
        try (DataScanner scan = TestUtils.scan(manager, "SELECT k1 FROM tblspace1.tsql ", Collections.emptyList())) {
            List<DataAccessor> data = scan.consume();
            assertEquals(1, data.size());
            // read from the full record, keeping only some field
            assertTrue(data.get(0) instanceof ProjectedDataAccessor || data.get(0) instanceof ZeroCopyProjection.RuntimeProjectedDataAccessor);
            assertEquals(RawString.of("a"), data.get(0).get("k1"));
            assertEquals(RawString.of("a"), data.get(0).get(0));
        }
        try (DataScanner scan = TestUtils.scan(manager, "SELECT COUNT(*) FROM tblspace1.tsql ", Collections.emptyList())) {
            List<DataAccessor> data = scan.consume();
            assertEquals(1, data.size());
            assertTrue(data.get(0) instanceof Tuple);
        }
    }
}
Also used : MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) DataAccessor(herddb.utils.DataAccessor) ProjectedDataAccessor(herddb.utils.ProjectedDataAccessor) RawString(herddb.utils.RawString) ProjectedDataAccessor(herddb.utils.ProjectedDataAccessor) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DataScanner(herddb.model.DataScanner) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) DataAccessorForFullRecord(herddb.codec.DataAccessorForFullRecord) Tuple(herddb.model.Tuple) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Aggregations

DataAccessorForFullRecord (herddb.codec.DataAccessorForFullRecord)1 MemoryCommitLogManager (herddb.mem.MemoryCommitLogManager)1 MemoryDataStorageManager (herddb.mem.MemoryDataStorageManager)1 MemoryMetadataStorageManager (herddb.mem.MemoryMetadataStorageManager)1 DataScanner (herddb.model.DataScanner)1 Tuple (herddb.model.Tuple)1 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)1 DataAccessor (herddb.utils.DataAccessor)1 ProjectedDataAccessor (herddb.utils.ProjectedDataAccessor)1 RawString (herddb.utils.RawString)1 Test (org.junit.Test)1