Search in sources :

Example 1 with Row

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);
}
Also used : Row(io.crate.data.Row)

Example 2 with Row

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);
            }
        });
    }
}
Also used : Row(io.crate.data.Row)

Example 3 with Row

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");
                }
            };
        }
    };
}
Also used : RowN(io.crate.data.RowN) Iterator(java.util.Iterator) Row(io.crate.data.Row) NoSuchElementException(java.util.NoSuchElementException)

Example 4 with Row

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());
}
Also used : Row(io.crate.data.Row) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 5 with Row

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"));
}
Also used : SessionContext(io.crate.action.sql.SessionContext) Row(io.crate.data.Row) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

Row (io.crate.data.Row)28 Test (org.junit.Test)17 CrateUnitTest (io.crate.test.integration.CrateUnitTest)12 Bucket (io.crate.data.Bucket)7 TestingHelpers.isRow (io.crate.testing.TestingHelpers.isRow)5 Input (io.crate.data.Input)4 RowN (io.crate.data.RowN)4 ArrayList (java.util.ArrayList)4 SessionContext (io.crate.action.sql.SessionContext)3 OrderBy (io.crate.analyze.OrderBy)3 Symbol (io.crate.analyze.symbol.Symbol)3 ArrayBucket (io.crate.data.ArrayBucket)3 BatchIterator (io.crate.data.BatchIterator)3 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)3 CollectExpression (io.crate.operation.collect.CollectExpression)3 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)3 WhereClause (io.crate.analyze.WhereClause)2 Projector (io.crate.data.Projector)2 InputFactory (io.crate.operation.InputFactory)2 InputCollectExpression (io.crate.operation.collect.InputCollectExpression)2