{"record":{"id":"def32912b5cb3469","repo":"cube-js/cube","slug":"should-be-rewritten-with-utctimestamp-function","errorCode":null,"errorMessage":"Should be rewritten with UtcTimestamp function","messagePattern":"Should be rewritten with UtcTimestamp function","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rust/cubesql/cubesql/src/compile/engine/udf/common.rs","lineNumber":1475,"sourceCode":"                Some(res.and_utc().timestamp_nanos_opt().unwrap()),\n                None,\n            )))\n        });\n\n    let return_type: ReturnTypeFunction =\n        Arc::new(move |_| Ok(Arc::new(DataType::Timestamp(TimeUnit::Millisecond, None))));\n\n    ScalarUDF::new(\n        \"str_to_date\",\n        &Signature::exact(vec![DataType::Utf8, DataType::Utf8], Volatility::Immutable),\n        &return_type,\n        &fun,\n    )\n}\n\npub fn create_current_timestamp_udf(name: &str) -> ScalarUDF {\n    let fun: Arc<dyn Fn(&[ColumnarValue]) -> Result<ColumnarValue> + Send + Sync> =\n        Arc::new(move |_| panic!(\"Should be rewritten with UtcTimestamp function\"));\n\n    let return_type: ReturnTypeFunction =\n        Arc::new(move |_| Ok(Arc::new(DataType::Timestamp(TimeUnit::Nanosecond, None))));\n\n    ScalarUDF::new(\n        name,\n        &Signature::exact(vec![], Volatility::Immutable),\n        &return_type,\n        &fun,\n    )\n}\n\nmacro_rules! parse_timestamp_arr {\n    ($ARR:expr, $ARR_TYPE: ident, $FN_NAME: ident) => {{\n        let arr = $ARR.as_any().downcast_ref::<$ARR_TYPE>();\n        if arr.is_some() {\n            let mut result = Vec::new();\n            let arr = arr.unwrap();","sourceCodeStart":1457,"sourceCodeEnd":1493,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/rust/cubesql/cubesql/src/compile/engine/udf/common.rs#L1457-L1493","documentation":"create_current_timestamp_udf registers a ScalarUDF whose implementation deliberately panics: NOW/CURRENT_TIMESTAMP must be rewritten to the UtcTimestamp function by the compiler before execution. Hitting the panic means an unrewritten current-timestamp expression reached evaluation.","triggerScenarios":"Executing a plan containing the raw current-timestamp UDF when the rewrite pass (replacing it with UtcTimestamp) did not run or did not match the expression.","commonSituations":"Missed rewrite rules for new SQL syntax forms of NOW()/CURRENT_TIMESTAMP, plans built programmatically bypassing the rewriter, version mismatches after adding new timestamp functions.","solutions":["Ensure the rewrite pass that substitutes UtcTimestamp runs before execution for all current-timestamp spellings (NOW(), CURRENT_TIMESTAMP, LOCALTIMESTAMP...).","Add the missing rewrite rule in cubesql's rewriter for the expression form that slipped through.","Avoid evaluating plans containing create_current_timestamp_udf directly in tests/tools."],"exampleFix":"// before\n// evaluating plan containing now_udf directly -> panic\n// after\n// apply rewriter first: rewrite(now_udf) -> udf(\"UtcTimestamp\") before execution","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always run the rewrite pass that replaces current-timestamp UDFs with UtcTimestamp before execution","Add rewrite rules for every NOW()/CURRENT_TIMESTAMP spelling your SQL accepts","Test plans containing timestamps through the full rewrite+execute pipeline"],"tags":["rust","cubesql","panic","rewrite","timestamp"],"backgroundTag":"unrewritten-expression-panic","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}