use of io.crate.data.Row in project crate by crate.
the class SortedPagingIteratorBenchmark method measureListSort.
@Benchmark
public void measureListSort(Blackhole blackhole) {
ArrayList<Row> allRows = new ArrayList<>(unsortedFirst);
allRows.addAll(unsortedSecond);
allRows.sort(compareOnFirstColumn);
for (Row row : allRows) {
blackhole.consume(row);
}
// reset to avoid sorting a already sorted list in the next iteration
Collections.shuffle(unsortedFirst, rnd);
Collections.shuffle(unsortedSecond, rnd);
}
use of io.crate.data.Row in project crate by crate.
the class BatchConsumerToResultReceiver method consumeIt.
private void consumeIt(BatchIterator iterator) {
Row row = RowBridging.toRow(iterator.rowData());
try {
while (iterator.moveNext()) {
rowCount++;
resultReceiver.setNextRow(row);
if (maxRows > 0 && rowCount % maxRows == 0) {
activeIt = iterator;
resultReceiver.batchFinished();
// resumed via postgres protocol, close is done later
return;
}
}
} catch (Throwable t) {
iterator.close();
resultReceiver.fail(t);
return;
}
if (iterator.allLoaded()) {
iterator.close();
resultReceiver.allFinished(false);
} else {
iterator.loadNextBatch().whenComplete((r, f) -> {
if (f == null) {
consumeIt(iterator);
} else {
iterator.close();
resultReceiver.fail(f);
}
});
}
}
use of io.crate.data.Row in project crate by crate.
the class RowGenerator method range.
/**
* Generate a range of rows.
* Both increasing (e.g. 0 -> 10) and decreasing ranges (10 -> 0) are supported.
*
* @param from start (inclusive)
* @param to end (exclusive)
*/
public static Iterable<Row> range(final int from, final int to) {
return new Iterable<Row>() {
@Override
public Iterator<Row> iterator() {
return new Iterator<Row>() {
private Object[] columns = new Object[1];
private RowN sharedRow = new RowN(columns);
private int i = from;
private int step = from < to ? 1 : -1;
@Override
public boolean hasNext() {
return step >= 0 ? i < to : i > to;
}
@Override
public Row next() {
if (!hasNext()) {
throw new NoSuchElementException("Iterator exhausted");
}
columns[0] = i;
i += step;
return sharedRow;
}
@Override
public void remove() {
throw new UnsupportedOperationException("Remove not supported");
}
};
}
};
}
use of io.crate.data.Row in project crate by crate.
the class RestActionReceiversTest method testRestResultSetReceiver.
@Test
public void testRestResultSetReceiver() throws Exception {
RestResultSetReceiver receiver = new RestResultSetReceiver(newChannel(), fields, 0L, true);
for (Row row : rows) {
receiver.setNextRow(row);
}
XContentBuilder actualBuilder = receiver.finishBuilder();
ResultToXContentBuilder builder = ResultToXContentBuilder.builder(newChannel());
builder.cols(fields);
builder.colTypes(fields);
builder.startRows();
for (Row row : rows) {
builder.addRow(row, 3);
}
builder.finishRows();
builder.rowCount(rows.size());
assertXContentBuilder(actualBuilder, builder.build());
}
use of io.crate.data.Row in project crate by crate.
the class CreateAlterTableStatementAnalyzerTest method testExplicitSchemaHasPrecedenceOverDefaultSchema.
@Test
public void testExplicitSchemaHasPrecedenceOverDefaultSchema() throws Exception {
CreateTableAnalyzedStatement statement = (CreateTableAnalyzedStatement) e.analyzer.boundAnalyze(SqlParser.createStatement("create table foo.bar (x string)"), new SessionContext(0, Option.NONE, "hoschi"), new ParameterContext(Row.EMPTY, Collections.<Row>emptyList())).analyzedStatement();
// schema from statement must take precedence
assertThat(statement.tableIdent().schema(), is("foo"));
}
Aggregations