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);
}
}
}
Aggregations