use of com.facebook.presto.spi.RecordCursor in project presto by prestodb.
the class AbstractTestHiveClient method assertPageSourceType.
protected static void assertPageSourceType(ConnectorPageSource pageSource, HiveStorageFormat hiveStorageFormat) {
if (pageSource instanceof RecordPageSource) {
RecordCursor hiveRecordCursor = ((RecordPageSource) pageSource).getCursor();
hiveRecordCursor = ((HiveRecordCursor) hiveRecordCursor).getRegularColumnRecordCursor();
if (hiveRecordCursor instanceof HiveCoercionRecordCursor) {
hiveRecordCursor = ((HiveCoercionRecordCursor) hiveRecordCursor).getRegularColumnRecordCursor();
}
assertInstanceOf(hiveRecordCursor, recordCursorType(hiveStorageFormat), hiveStorageFormat.name());
} else {
assertInstanceOf(((HivePageSource) pageSource).getPageSource(), pageSourceType(hiveStorageFormat), hiveStorageFormat.name());
}
}
use of com.facebook.presto.spi.RecordCursor in project presto by prestodb.
the class TestFilterAndProjectOperator method test.
@Test
public void test() throws Exception {
List<Page> input = rowPagesBuilder(VARCHAR, BIGINT).addSequencePage(100, 0, 0).build();
FilterFunction filter = new FilterFunction() {
@Override
public boolean filter(int position, Block... blocks) {
long value = BIGINT.getLong(blocks[1], position);
return 10 <= value && value < 20;
}
@Override
public boolean filter(RecordCursor cursor) {
long value = cursor.getLong(0);
return 10 <= value && value < 20;
}
@Override
public Set<Integer> getInputChannels() {
return singleton(1);
}
};
OperatorFactory operatorFactory = new FilterAndProjectOperator.FilterAndProjectOperatorFactory(0, new PlanNodeId("test"), () -> new GenericPageProcessor(filter, ImmutableList.of(singleColumn(VARCHAR, 0), new Add5Projection(1))), ImmutableList.of(VARCHAR, BIGINT));
MaterializedResult expected = MaterializedResult.resultBuilder(driverContext.getSession(), VARCHAR, BIGINT).row("10", 15L).row("11", 16L).row("12", 17L).row("13", 18L).row("14", 19L).row("15", 20L).row("16", 21L).row("17", 22L).row("18", 23L).row("19", 24L).build();
assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
use of com.facebook.presto.spi.RecordCursor in project presto by prestodb.
the class H2QueryRunner method insertRows.
private static void insertRows(ConnectorTableMetadata tableMetadata, Handle handle, RecordSet data) {
List<ColumnMetadata> columns = tableMetadata.getColumns().stream().filter(columnMetadata -> !columnMetadata.isHidden()).collect(toImmutableList());
String vars = Joiner.on(',').join(nCopies(columns.size(), "?"));
String sql = format("INSERT INTO %s VALUES (%s)", tableMetadata.getTable().getTableName(), vars);
RecordCursor cursor = data.cursor();
while (true) {
// insert 1000 rows at a time
PreparedBatch batch = handle.prepareBatch(sql);
for (int row = 0; row < 1000; row++) {
if (!cursor.advanceNextPosition()) {
batch.execute();
return;
}
PreparedBatchPart part = batch.add();
for (int column = 0; column < columns.size(); column++) {
Type type = columns.get(column).getType();
if (BOOLEAN.equals(type)) {
part.bind(column, cursor.getBoolean(column));
} else if (BIGINT.equals(type)) {
part.bind(column, cursor.getLong(column));
} else if (INTEGER.equals(type)) {
part.bind(column, (int) cursor.getLong(column));
} else if (DOUBLE.equals(type)) {
part.bind(column, cursor.getDouble(column));
} else if (type instanceof VarcharType) {
part.bind(column, cursor.getSlice(column).toStringUtf8());
} else if (DATE.equals(type)) {
long millisUtc = TimeUnit.DAYS.toMillis(cursor.getLong(column));
// H2 expects dates in to be millis at midnight in the JVM timezone
long localMillis = DateTimeZone.UTC.getMillisKeepLocal(DateTimeZone.getDefault(), millisUtc);
part.bind(column, new Date(localMillis));
} else {
throw new IllegalArgumentException("Unsupported type " + type);
}
}
}
batch.execute();
}
}
Aggregations