use of io.crate.analyze.OrderBy in project crate by crate.
the class WindowAggTest method testOrderByIsPartitionByWithoutExplicitOrderBy.
@Test
public void testOrderByIsPartitionByWithoutExplicitOrderBy() {
OrderBy orderBy = WindowAgg.createOrderByInclPartitionBy(wd("avg(x) OVER (PARTITION BY x)"));
assertThat(orderBy, notNullValue());
assertThat(orderBy.orderBySymbols(), contains(isReference("x")));
}
use of io.crate.analyze.OrderBy in project crate by crate.
the class OrderedLuceneBatchIteratorBenchmark method createLuceneBatchIterator.
@Setup
public void createLuceneBatchIterator() throws Exception {
IndexWriter iw = new IndexWriter(new ByteBuffersDirectory(), new IndexWriterConfig(new StandardAnalyzer()));
dummyShardId = new ShardId("dummy", UUIDs.randomBase64UUID(), 1);
columnName = "x";
for (int i = 0; i < 10_000_000; i++) {
Document doc = new Document();
doc.add(new NumericDocValuesField(columnName, i));
iw.addDocument(doc);
}
iw.commit();
iw.forceMerge(1, true);
indexSearcher = new IndexSearcher(DirectoryReader.open(iw, true, true));
collectorContext = new CollectorContext();
reference = new Reference(new ReferenceIdent(new RelationName(Schemas.DOC_SCHEMA_NAME, "dummyTable"), columnName), RowGranularity.DOC, DataTypes.INTEGER, 1, null);
orderBy = new OrderBy(Collections.singletonList(reference), reverseFlags, nullsFirst);
}
use of io.crate.analyze.OrderBy in project crate by crate.
the class DocInputFactory method extractImplementations.
public InputFactory.Context<? extends LuceneCollectorExpression<?>> extractImplementations(TransactionContext txnCtx, RoutedCollectPhase phase) {
OrderBy orderBy = phase.orderBy();
ReferenceResolver<? extends LuceneCollectorExpression<?>> refResolver;
if (orderBy == null) {
refResolver = referenceResolver;
} else {
refResolver = ref -> {
if (orderBy.orderBySymbols().contains(ref)) {
DataType<?> dataType = ref.valueType();
return new OrderByCollectorExpression(ref, orderBy, dataType::sanitizeValue);
}
return referenceResolver.getImplementation(ref);
};
}
InputFactory.Context<? extends LuceneCollectorExpression<?>> ctx = inputFactory.ctxForRefs(txnCtx, refResolver);
ctx.add(phase.toCollect());
return ctx;
}
use of io.crate.analyze.OrderBy in project crate by crate.
the class WindowFunction method toString.
@Override
public String toString(Style style) {
var builder = new StringBuilder(super.toString(style));
if (ignoreNulls != null) {
if (ignoreNulls) {
builder.append(" IGNORE NULLS");
} else {
builder.append(" RESPECT NULLS");
}
}
builder.append(" OVER (");
var partitions = windowDefinition.partitions();
if (!partitions.isEmpty()) {
builder.append("PARTITION BY ");
builder.append(Lists2.joinOn(", ", partitions, x -> x.toString(style)));
}
var orderBy = windowDefinition.orderBy();
if (orderBy != null) {
if (!partitions.isEmpty()) {
builder.append(" ");
}
builder.append("ORDER BY ");
OrderBy.explainRepresentation(builder, orderBy.orderBySymbols(), orderBy.reverseFlags(), orderBy.nullsFirst(), x -> x.toString(style));
}
WindowFrameDefinition frameDefinition = windowDefinition.windowFrameDefinition();
if (frameDefinition != WindowDefinition.RANGE_UNBOUNDED_PRECEDING_CURRENT_ROW) {
builder.append(" ");
builder.append(frameDefinition.mode().name());
builder.append(" BETWEEN ");
appendFrameBound(builder, style, frameDefinition.start());
builder.append(" AND ");
appendFrameBound(builder, style, frameDefinition.end());
}
builder.append(")");
return builder.toString();
}
Aggregations