Search in sources :

Example 76 with DataType

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);
}
Also used : Input(io.crate.data.Input) TransactionContext(io.crate.metadata.TransactionContext) InputColumn(io.crate.expression.symbol.InputColumn) WindowFrame(io.crate.sql.tree.WindowFrame) BiFunction(java.util.function.BiFunction) RowAccountingWithEstimators(io.crate.breaker.RowAccountingWithEstimators) CollectExpression(io.crate.execution.engine.collect.CollectExpression) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Projector(io.crate.data.Projector) IntervalType(io.crate.types.IntervalType) Symbols(io.crate.expression.symbol.Symbols) Nullable(javax.annotation.Nullable) IntSupplier(java.util.function.IntSupplier) NodeContext(io.crate.metadata.NodeContext) Executor(java.util.concurrent.Executor) AggregationFunction(io.crate.execution.engine.aggregation.AggregationFunction) SymbolType(io.crate.expression.symbol.SymbolType) Comparators.createComparator(io.crate.execution.engine.sort.Comparators.createComparator) DataType(io.crate.types.DataType) SymbolEvaluator.evaluateWithoutParams(io.crate.analyze.SymbolEvaluator.evaluateWithoutParams) MemoryManager(io.crate.memory.MemoryManager) RamAccounting(io.crate.breaker.RamAccounting) ExpressionsInput(io.crate.expression.ExpressionsInput) List(java.util.List) OrderBy(io.crate.analyze.OrderBy) Version(org.elasticsearch.Version) Row(io.crate.data.Row) Literal(io.crate.expression.symbol.Literal) WindowDefinition(io.crate.analyze.WindowDefinition) WindowAggProjection(io.crate.execution.dsl.projection.WindowAggProjection) Symbol(io.crate.expression.symbol.Symbol) FunctionImplementation(io.crate.metadata.FunctionImplementation) InputFactory(io.crate.expression.InputFactory) Comparator(java.util.Comparator) DataType(io.crate.types.DataType)

Example 77 with DataType

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;
}
Also used : ExecutionPlan(io.crate.planner.ExecutionPlan) ResultDescription(io.crate.planner.ResultDescription) DataType(io.crate.types.DataType) TopNProjection(io.crate.execution.dsl.projection.TopNProjection)

Example 78 with DataType

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);
}
Also used : InputColumns(io.crate.execution.dsl.projection.builder.InputColumns) QueryThenFetch(io.crate.planner.node.dql.QueryThenFetch) Symbol(io.crate.expression.symbol.Symbol) ArrayList(java.util.ArrayList) FetchProjection(io.crate.execution.dsl.projection.FetchProjection) ReaderAllocations(io.crate.planner.ReaderAllocations) FetchPhase(io.crate.execution.dsl.phases.FetchPhase) DataType(io.crate.types.DataType)

Example 79 with DataType

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()))));
    }
}
Also used : ArrayType(io.crate.types.ArrayType) Symbol(io.crate.expression.symbol.Symbol) Literal(io.crate.expression.symbol.Literal) DataType(io.crate.types.DataType) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 80 with DataType

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));
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType) Test(org.junit.Test)

Aggregations

DataType (io.crate.types.DataType)95 ArrayType (io.crate.types.ArrayType)35 Test (org.junit.Test)33 ArrayList (java.util.ArrayList)17 Map (java.util.Map)17 CrateUnitTest (io.crate.test.integration.CrateUnitTest)14 List (java.util.List)12 Symbol (io.crate.expression.symbol.Symbol)11 Literal (io.crate.expression.symbol.Literal)9 ColumnIdent (io.crate.metadata.ColumnIdent)9 HashMap (java.util.HashMap)9 FunctionIdent (io.crate.metadata.FunctionIdent)8 NodeContext (io.crate.metadata.NodeContext)8 Reference (io.crate.metadata.Reference)8 Row (io.crate.data.Row)7 Symbols (io.crate.expression.symbol.Symbols)7 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)7 Locale (java.util.Locale)7 Lists2 (io.crate.common.collections.Lists2)6 FunctionInfo (io.crate.metadata.FunctionInfo)6