Skip to content

Commit 95877d9

Browse files
committed
Report planner error when inserting into sources or select from sinks
1 parent 07b65db commit 95877d9

7 files changed

Lines changed: 54 additions & 7 deletions

File tree

crates/arroyo-planner/src/builder.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,8 @@ impl PlanToGraphVisitor<'_> {
323323
})
324324
.collect::<Result<Vec<_>>>()?;
325325

326-
let NodeWithIncomingEdges { node, edges } = extension
327-
.plan_node(&self.planner, self.graph.node_count(), input_schemas)
328-
.map_err(|e| e.context(format!("planning operator {extension:?}")))?;
326+
let NodeWithIncomingEdges { node, edges } =
327+
extension.plan_node(&self.planner, self.graph.node_count(), input_schemas)?;
329328

330329
let node_index = self.graph.add_node(node);
331330
self.add_index_to_traversal(node_index);

crates/arroyo-planner/src/extension/sink.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::sync::Arc;
33
use arroyo_datastream::logical::{LogicalEdge, LogicalEdgeType, LogicalNode, OperatorName};
44
use arroyo_rpc::{
55
UPDATING_META_FIELD,
6+
api_types::connections::ConnectionType,
67
df::{ArroyoSchema, ArroyoSchemaRef},
78
};
89
use datafusion::common::{DFSchemaRef, Result, TableReference, plan_err};
@@ -46,6 +47,13 @@ impl SinkExtension {
4647
.has_column_with_unqualified_name(UPDATING_META_FIELD);
4748
match &table {
4849
Table::ConnectorTable(connector_table) => {
50+
if connector_table.connection_type == ConnectionType::Source {
51+
return plan_err!(
52+
"attempted to insert into table '{}', but it is a source",
53+
connector_table.name
54+
);
55+
}
56+
4957
match (input_is_updating, connector_table.is_updating()) {
5058
(_, true) => {
5159
let to_debezium_extension =

crates/arroyo-planner/src/rewriters.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ use crate::{
1515
};
1616

1717
use arrow_schema::DataType;
18-
use arroyo_rpc::TIMESTAMP_FIELD;
19-
use arroyo_rpc::UPDATING_META_FIELD;
18+
use arroyo_rpc::{TIMESTAMP_FIELD, UPDATING_META_FIELD, api_types::connections::ConnectionType};
2019
use datafusion::logical_expr::UserDefinedLogicalNode;
2120

2221
use crate::extension::AsyncUDFExtension;
@@ -192,6 +191,13 @@ impl SourceRewriter<'_> {
192191
table_scan: &TableScan,
193192
table: &ConnectorTable,
194193
) -> DFResult<Transformed<LogicalPlan>> {
194+
if table.connection_type == ConnectionType::Sink {
195+
return plan_err!(
196+
"attempted to read from table '{}', but it is a sink",
197+
table.name
198+
);
199+
}
200+
195201
let input = self.projection(table_scan, table)?;
196202

197203
let schema = input.schema().clone();

crates/arroyo-planner/src/test/queries/filesystem_invalid_partition.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ create table events_sink (
3737
type = 'sink'
3838
);
3939

40-
INSERT INTO events
40+
INSERT INTO events_sink
4141
SELECT * from events;

crates/arroyo-planner/src/test/queries/filesystem_partition.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ create table events_sink (
3636
'rolling_policy.interval' = interval '6000 seconds'
3737
);
3838

39-
INSERT INTO events
39+
INSERT INTO events_sink
4040
SELECT * from events;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--fail=attempted to insert into table 'source', but it is a source
2+
CREATE TABLE source with (
3+
connector = 'impulse',
4+
event_rate = 10
5+
);
6+
7+
INSERT INTO source
8+
select * from source;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--fail=attempted to read from table 'cars_output', but it is a sink
2+
3+
CREATE TABLE cars (
4+
timestamp TIMESTAMP,
5+
driver_id BIGINT,
6+
event_type TEXT,
7+
location TEXT
8+
) WITH (
9+
connector = 'single_file',
10+
path = 'cars.json',
11+
format = 'json',
12+
type = 'source'
13+
);
14+
15+
CREATE TABLE cars_output (
16+
timestamp TIMESTAMP,
17+
driver_id BIGINT,
18+
event_type TEXT,
19+
location TEXT
20+
) WITH (
21+
connector = 'single_file',
22+
path = 'cars_output.json',
23+
format = 'json',
24+
type = 'sink'
25+
);
26+
INSERT INTO cars_output SELECT * from cars_output;

0 commit comments

Comments
 (0)