Search in sources :

Example 1 with WriterProjection

use of io.crate.execution.dsl.projection.WriterProjection in project crate by crate.

the class CopyToPlan method planCopyToExecution.

@VisibleForTesting
static ExecutionPlan planCopyToExecution(AnalyzedCopyTo copyTo, PlannerContext context, TableStats tableStats, ProjectionBuilder projectionBuilder, Row params, SubQueryResults subQueryResults) {
    var boundedCopyTo = bind(copyTo, context.transactionContext(), context.nodeContext(), params, subQueryResults);
    WriterProjection.OutputFormat outputFormat = boundedCopyTo.outputFormat();
    if (outputFormat == null) {
        outputFormat = boundedCopyTo.columnsDefined() ? WriterProjection.OutputFormat.JSON_ARRAY : WriterProjection.OutputFormat.JSON_OBJECT;
    }
    WriterProjection projection = ProjectionBuilder.writerProjection(boundedCopyTo.outputs(), boundedCopyTo.uri(), boundedCopyTo.compressionType(), boundedCopyTo.overwrites(), boundedCopyTo.outputNames(), outputFormat, boundedCopyTo.withClauseOptions());
    LogicalPlan collect = Collect.create(new DocTableRelation(boundedCopyTo.table()), boundedCopyTo.outputs(), boundedCopyTo.whereClause(), tableStats, context.params());
    LogicalPlan source = optimizeCollect(context, tableStats, collect);
    ExecutionPlan executionPlan = source.build(context, Set.of(), projectionBuilder, 0, 0, null, null, params, SubQueryResults.EMPTY);
    executionPlan.addProjection(projection);
    return Merge.ensureOnHandler(executionPlan, context, List.of(MergeCountProjection.INSTANCE));
}
Also used : WriterProjection(io.crate.execution.dsl.projection.WriterProjection) ExecutionPlan(io.crate.planner.ExecutionPlan) DocTableRelation(io.crate.analyze.relations.DocTableRelation) LogicalPlan(io.crate.planner.operators.LogicalPlan) VisibleForTesting(io.crate.common.annotations.VisibleForTesting)

Example 2 with WriterProjection

use of io.crate.execution.dsl.projection.WriterProjection in project crate by crate.

the class ProjectingRowConsumerTest method testErrorHandlingIfProjectorApplicationFails.

@Test
public void testErrorHandlingIfProjectorApplicationFails() throws Exception {
    WriterProjection writerProjection = new WriterProjection(Collections.singletonList(new InputColumn(0, DataTypes.STRING)), Literal.of("/x/y/z/hopefully/invalid/on/your/system/"), null, Collections.emptyMap(), Collections.emptyList(), WriterProjection.OutputFormat.JSON_OBJECT, Settings.EMPTY);
    TestingRowConsumer consumer = new TestingRowConsumer();
    RowConsumer rowConsumer = ProjectingRowConsumer.create(consumer, Collections.singletonList(writerProjection), UUID.randomUUID(), txnCtx, RamAccounting.NO_ACCOUNTING, memoryManager, projectorFactory);
    rowConsumer.accept(InMemoryBatchIterator.empty(SENTINEL), null);
    expectedException.expect(UnhandledServerException.class);
    expectedException.expectMessage("Failed to open output");
    consumer.getResult();
}
Also used : WriterProjection(io.crate.execution.dsl.projection.WriterProjection) InputColumn(io.crate.expression.symbol.InputColumn) RowConsumer(io.crate.data.RowConsumer) TestingRowConsumer(io.crate.testing.TestingRowConsumer) TestingRowConsumer(io.crate.testing.TestingRowConsumer) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 3 with WriterProjection

use of io.crate.execution.dsl.projection.WriterProjection in project crate by crate.

the class CopyToPlannerTest method testCopyToPlanWithParameters.

@Test
public void testCopyToPlanWithParameters() {
    Merge merge = plan("copy users to directory '/path/to' with (protocol = 'http')");
    Collect collect = (Collect) merge.subPlan();
    WriterProjection writerProjection = (WriterProjection) collect.collectPhase().projections().get(0);
    assertThat(writerProjection.withClauseOptions().get("protocol"), is("http"));
    // verify defaults:
    merge = plan("copy users to directory '/path/to/'");
    collect = (Collect) merge.subPlan();
    writerProjection = (WriterProjection) collect.collectPhase().projections().get(0);
    assertThat(writerProjection.withClauseOptions(), is(Settings.EMPTY));
}
Also used : WriterProjection(io.crate.execution.dsl.projection.WriterProjection) Merge(io.crate.planner.Merge) Collect(io.crate.planner.node.dql.Collect) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 4 with WriterProjection

use of io.crate.execution.dsl.projection.WriterProjection in project crate by crate.

the class CopyToPlannerTest method testCopyToWithPartitionedGeneratedColumn.

@Test
public void testCopyToWithPartitionedGeneratedColumn() {
    // test that generated partition column is NOT exported
    Merge plan = plan("copy parted_generated to directory '/tmp'");
    Collect innerPlan = (Collect) plan.subPlan();
    RoutedCollectPhase node = ((RoutedCollectPhase) innerPlan.collectPhase());
    WriterProjection projection = (WriterProjection) node.projections().get(0);
    assertThat(projection.overwrites().size(), is(0));
}
Also used : WriterProjection(io.crate.execution.dsl.projection.WriterProjection) Merge(io.crate.planner.Merge) Collect(io.crate.planner.node.dql.Collect) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Aggregations

WriterProjection (io.crate.execution.dsl.projection.WriterProjection)4 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)3 Test (org.junit.Test)3 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)2 Merge (io.crate.planner.Merge)2 Collect (io.crate.planner.node.dql.Collect)2 DocTableRelation (io.crate.analyze.relations.DocTableRelation)1 VisibleForTesting (io.crate.common.annotations.VisibleForTesting)1 RowConsumer (io.crate.data.RowConsumer)1 RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)1 InputColumn (io.crate.expression.symbol.InputColumn)1 ExecutionPlan (io.crate.planner.ExecutionPlan)1 LogicalPlan (io.crate.planner.operators.LogicalPlan)1 TestingRowConsumer (io.crate.testing.TestingRowConsumer)1