use of io.crate.types.DataType in project crate by crate.
the class WindowProjector method createComputeStartFrameBoundary.
static ComputeFrameBoundary<Object[]> createComputeStartFrameBoundary(int numCellsInSourceRow, TransactionContext txnCtx, NodeContext nodeCtx, WindowDefinition windowDefinition, @Nullable Comparator<Object[]> cmpOrderBy) {
var frameDefinition = windowDefinition.windowFrameDefinition();
var frameBoundStart = frameDefinition.start();
var framingMode = frameDefinition.mode();
DataType offsetType = frameBoundStart.value().valueType();
Object offsetValue = evaluateWithoutParams(txnCtx, nodeCtx, frameBoundStart.value());
Object[] startProbeValues = new Object[numCellsInSourceRow];
BiFunction<Object[], Object[], Object[]> updateStartProbeValue;
if (offsetValue != null && framingMode == WindowFrame.Mode.RANGE) {
updateStartProbeValue = createUpdateProbeValueFunction(windowDefinition, ArithmeticOperatorsFactory::getSubtractFunction, offsetValue, offsetType);
} else {
updateStartProbeValue = (currentRow, x) -> x;
}
return (partitionStart, partitionEnd, currentIndex, sortedRows) -> frameBoundStart.type().getStart(framingMode, partitionStart, partitionEnd, currentIndex, offsetValue, updateStartProbeValue.apply(sortedRows.get(currentIndex), startProbeValues), cmpOrderBy, sortedRows);
}
use of io.crate.types.DataType in project crate by crate.
the class Limit method build.
@Override
public ExecutionPlan build(PlannerContext plannerContext, Set<PlanHint> planHints, ProjectionBuilder projectionBuilder, int limitHint, int offsetHint, @Nullable OrderBy order, @Nullable Integer pageSizeHint, Row params, SubQueryResults subQueryResults) {
int limit = Objects.requireNonNullElse(DataTypes.INTEGER.sanitizeValue(evaluate(plannerContext.transactionContext(), plannerContext.nodeContext(), this.limit, params, subQueryResults)), NO_LIMIT);
int offset = Objects.requireNonNullElse(DataTypes.INTEGER.sanitizeValue(evaluate(plannerContext.transactionContext(), plannerContext.nodeContext(), this.offset, params, subQueryResults)), 0);
ExecutionPlan executionPlan = source.build(plannerContext, planHints, projectionBuilder, limit, offset, order, pageSizeHint, params, subQueryResults);
List<DataType<?>> sourceTypes = Symbols.typeView(source.outputs());
ResultDescription resultDescription = executionPlan.resultDescription();
if (resultDescription.hasRemainingLimitOrOffset() && (resultDescription.limit() != limit || resultDescription.offset() != offset)) {
executionPlan = Merge.ensureOnHandler(executionPlan, plannerContext);
resultDescription = executionPlan.resultDescription();
}
if (ExecutionPhases.executesOnHandler(plannerContext.handlerNode(), resultDescription.nodeIds())) {
executionPlan.addProjection(new TopNProjection(limit, offset, sourceTypes), TopN.NO_LIMIT, 0, resultDescription.orderBy());
} else if (resultDescription.limit() != limit || resultDescription.offset() != 0) {
executionPlan.addProjection(new TopNProjection(limit + offset, 0, sourceTypes), limit, offset, resultDescription.orderBy());
}
return executionPlan;
}
use of io.crate.types.DataType in project crate by crate.
the class Fetch method build.
@Override
public ExecutionPlan build(PlannerContext plannerContext, Set<PlanHint> hints, ProjectionBuilder projectionBuilder, int limit, int offset, @Nullable OrderBy order, @Nullable Integer pageSizeHint, Row params, SubQueryResults subQueryResults) {
plannerContext.newReaderAllocations();
var executionPlan = Merge.ensureOnHandler(source.build(plannerContext, hints, projectionBuilder, limit, offset, order, pageSizeHint, params, subQueryResults), plannerContext);
ReaderAllocations readerAllocations = plannerContext.buildReaderAllocations();
Function<Symbol, Symbol> paramBinder = new SubQueryAndParamBinder(params, subQueryResults);
FetchPhase fetchPhase = new FetchPhase(plannerContext.nextExecutionPhaseId(), readerAllocations.nodeReaders().keySet(), readerAllocations.bases(), readerAllocations.tableIndices(), fetchRefs);
ArrayList<Symbol> boundOutputs = new ArrayList<>(replacedOutputs.size());
for (var entry : replacedOutputs.entrySet()) {
Symbol key = entry.getKey();
Symbol value = entry.getValue();
if (source.outputs().contains(key)) {
boundOutputs.add(paramBinder.apply(key));
} else {
boundOutputs.add(paramBinder.apply(value));
}
}
List<DataType<?>> inputTypes = Symbols.typeView(source.outputs());
List<Symbol> fetchOutputs = InputColumns.create(boundOutputs, new InputColumns.SourceSymbols(source.outputs()));
FetchProjection fetchProjection = new FetchProjection(fetchPhase.phaseId(), plannerContext.fetchSize(), fetchSourceByRelation, fetchOutputs, inputTypes, readerAllocations.nodeReaders(), readerAllocations.indices(), readerAllocations.indicesToIdents());
executionPlan.addProjection(fetchProjection);
return new QueryThenFetch(executionPlan, fetchPhase);
}
use of io.crate.types.DataType in project crate by crate.
the class CompoundLiteralTest method testNestedArrayLiteral.
@Test
public void testNestedArrayLiteral() throws Exception {
Map<String, DataType<?>> expected = Map.of("'string'", DataTypes.STRING, "0", DataTypes.INTEGER, "1.8", DataTypes.DOUBLE, "TRUE", DataTypes.BOOLEAN);
for (Map.Entry<String, DataType<?>> entry : expected.entrySet()) {
Symbol nestedArraySymbol = analyzeExpression("[[" + entry.getKey() + "]]");
assertThat(nestedArraySymbol, Matchers.instanceOf(Literal.class));
Literal<?> nestedArray = (Literal<?>) nestedArraySymbol;
assertThat(nestedArray.valueType(), is(new ArrayType<>(new ArrayType<>(entry.getValue()))));
}
}
use of io.crate.types.DataType in project crate by crate.
the class DataTypeTest method testForValueWithEmptyList.
@Test
public void testForValueWithEmptyList() {
List<Object> objects = Arrays.<Object>asList();
DataType type = DataTypes.guessType(objects);
assertEquals(type, new ArrayType(DataTypes.UNDEFINED));
}
Aggregations