cube-js/cube · error

Should be rewritten with UtcTimestamp function

Error message

Should be rewritten with UtcTimestamp function

What it means

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.

Source

Thrown at rust/cubesql/cubesql/src/compile/engine/udf/common.rs:1475

                Some(res.and_utc().timestamp_nanos_opt().unwrap()),
                None,
            )))
        });

    let return_type: ReturnTypeFunction =
        Arc::new(move |_| Ok(Arc::new(DataType::Timestamp(TimeUnit::Millisecond, None))));

    ScalarUDF::new(
        "str_to_date",
        &Signature::exact(vec![DataType::Utf8, DataType::Utf8], Volatility::Immutable),
        &return_type,
        &fun,
    )
}

pub fn create_current_timestamp_udf(name: &str) -> ScalarUDF {
    let fun: Arc<dyn Fn(&[ColumnarValue]) -> Result<ColumnarValue> + Send + Sync> =
        Arc::new(move |_| panic!("Should be rewritten with UtcTimestamp function"));

    let return_type: ReturnTypeFunction =
        Arc::new(move |_| Ok(Arc::new(DataType::Timestamp(TimeUnit::Nanosecond, None))));

    ScalarUDF::new(
        name,
        &Signature::exact(vec![], Volatility::Immutable),
        &return_type,
        &fun,
    )
}

macro_rules! parse_timestamp_arr {
    ($ARR:expr, $ARR_TYPE: ident, $FN_NAME: ident) => {{
        let arr = $ARR.as_any().downcast_ref::<$ARR_TYPE>();
        if arr.is_some() {
            let mut result = Vec::new();
            let arr = arr.unwrap();

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Ensure the rewrite pass that substitutes UtcTimestamp runs before execution for all current-timestamp spellings (NOW(), CURRENT_TIMESTAMP, LOCALTIMESTAMP...).
  2. Add the missing rewrite rule in cubesql's rewriter for the expression form that slipped through.
  3. Avoid evaluating plans containing create_current_timestamp_udf directly in tests/tools.

Example fix

// before
// evaluating plan containing now_udf directly -> panic
// after
// apply rewriter first: rewrite(now_udf) -> udf("UtcTimestamp") before execution
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02). Data as JSON: /api/errors/def32912b5cb3469. Report an issue: GitHub.