Repository: ArroyoSystems/arroyo (language: rust)

Issue:
Planner panics on virtual field
This query produces a panic in the planner:

```sql
create table logs (
    value TEXT NOT NULL,
    parsed TEXT GENERATED ALWAYS AS (value)
) with (
    connector = 'sse',
    endpoint = 'http://host.docker.internal:9563/sse',
    format = 'raw_string'
);

 
SELECT * from logs;
```

```
2023-12-01T05:53:23.641080Z ERROR arroyo_server_common: panicked at arroyo-sql/src/expressions.rs:1925:13:
internal error: entered unreachable code: invalid cast from Utf8 to Utf8 panic.file="arroyo-sql/src/expressions.rs" panic.line=1925 panic.column=13
```

This appears to be due to the NOT NULL to nullable conversion happening.


Discussion / hints:

Fix patch:
diff --git a/arroyo-controller/src/states/running.rs b/arroyo-controller/src/states/running.rs
index 4182ae11d..62dd79ec2 100644
--- a/arroyo-controller/src/states/running.rs
+++ b/arroyo-controller/src/states/running.rs
@@ -111,6 +111,11 @@ impl State for Running {
                         },
                         Err(err) => {
                             error!(message = "error while running", error = format!("{:?}", err), job_id = ctx.config.id);
+                            log_event("running_error", json!({
+                                "service": "controller",
+                                "job_id": ctx.config.id,
+                                "error": format!("{:?}", err),
+                            }));
                             if ctx.status.restarts >= RESTARTS_ALLOWED as i32 {
                                 return Err(fatal(
                                     "Job has restarted too many times",
diff --git a/arroyo-sql/src/expressions.rs b/arroyo-sql/src/expressions.rs
index a6cc0feb0..babe847ac 100644
--- a/arroyo-sql/src/expressions.rs
+++ b/arroyo-sql/src/expressions.rs
@@ -1882,6 +1882,9 @@ impl CastExpression {
         matches!(data_type, DataType::Utf8 | DataType::LargeUtf8)
     }
     fn cast_expr(input_type: &DataType, output_type: &DataType, sub_expr: syn::Expr) -> syn::Expr {
+        if input_type == output_type {
+            return sub_expr;
+        }
         if Self::is_numeric(input_type) && Self::is_numeric(output_type) {
             let cast_type: syn::Type =
                 parse_str(&StructField::data_type_name(output_type)).unwrap();


Test patch:
diff --git a/arroyo-sql-testing/src/full_query_tests.rs b/arroyo-sql-testing/src/full_query_tests.rs
index 303ce809f..8935e54c9 100644
--- a/arroyo-sql-testing/src/full_query_tests.rs
+++ b/arroyo-sql-testing/src/full_query_tests.rs
@@ -557,3 +557,18 @@ INSERT INTO avro_writes
 select cast(bid.datetime as TIMESTAMP), bid.auction as u64, bid.auction as i64, bid.extra
 from nexmark;"
 }
+
+full_pipeline_codegen! {
+  "raw_string_cast",
+  "create table logs (
+    value TEXT NOT NULL,
+    parsed TEXT GENERATED ALWAYS AS (value)
+) with (
+    connector = 'sse',
+    endpoint = 'http://host.docker.internal:9563/sse',
+    format = 'raw_string'
+);
+
+SELECT * from logs;
+"
+}