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));
}
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();
}
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));
}
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));
}
Aggregations