cube-js/cube · error

not implemented

Error message

not implemented

What it means

create_str_to_date_udf implements STR_TO_DATE only for the narrow case where the first argument is a scalar UTF-8 string; any other shape of args[0] (array/column value, non-string, or NULL scalar) hits a todo!() and panics. The function exists and parses, but only constant-string inputs are supported.

Source

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

        .replace("dd", "%d")
        .replace("HH24", "%H")
        .replace("HH12", "%I")
        .replace("MI", "%M")
        .replace("mi", "%M")
        .replace("SS", "%S")
        .replace("ss", "%S")
        .replace(".US", "%.f")
        .replace("MM", "%m")
        .replace(".MS", "%.3f")
}

pub fn create_str_to_date_udf() -> ScalarUDF {
    let fun: Arc<dyn Fn(&[ColumnarValue]) -> Result<ColumnarValue> + Send + Sync> =
        Arc::new(move |args: &[ColumnarValue]| {
            let timestamp = match &args[0] {
                ColumnarValue::Scalar(ScalarValue::Utf8(Some(value))) => value,
                _ => {
                    todo!()
                }
            };

            let format = match &args[1] {
                ColumnarValue::Scalar(ScalarValue::Utf8(Some(value))) => value,
                ColumnarValue::Scalar(value) => {
                    return Err(DataFusionError::Execution(format!(
                        "Expected string but got {:?} as a format param",
                        value
                    )))
                }
                ColumnarValue::Array(_) => {
                    return Err(DataFusionError::Execution(
                        "Array is not supported for format param in str_to_date".to_string(),
                    ))
                }
            };

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Pass a literal constant string as the first argument (the only supported case), or perform the conversion upstream in the database/model
  2. Extend the UDF at rust/cubesql/cubesql/src/compile/engine/udf/common.rs:1418 to handle ColumnarValue::Array (parse per-row with chrono) and NULL inputs
  3. Cast the column to timestamp in the data model (e.g. defined dimension with sql/translate) instead of using STR_TO_DATE

Example fix

// before
let timestamp = match &args[0] {
    ColumnarValue::Scalar(ScalarValue::Utf8(Some(value))) => value,
    _ => todo!(),
};
// after
let timestamp = match &args[0] {
    ColumnarValue::Scalar(ScalarValue::Utf8(Some(value))) => value.clone(),
    ColumnarValue::Scalar(ScalarValue::Utf8(None)) => return Ok(ColumnarValue::Scalar(ScalarValue::TimestampNanosecond(None, None))),
    ColumnarValue::Array(arr) => arrow::array::as_string_array(arr).clone(),
    other => return Err(CubeError::internal(format!("str_to_date: unsupported arg {:?}", other))),
};
Defensive patterns

Strategy: validation

Validate before calling

// Only use STR_TO_DATE with a literal string first argument via Cube SQL API
function assertStrToDateSafe(sql) {
  const m = sql.match(/STR_TO_DATE\s*\(\s*([^,]+),/i);
  if (m && !/^\s*'/.test(m[1])) {
    throw new Error('STR_TO_DATE only supports constant string dates in CubeSQL; cast the column in the data model instead');
  }
}

Type guard

function isStrToDateScalarSupported(argExpr) {
  // supported: non-empty single-quoted string literal, non-NULL
  return /^'[^']*'$/.test(argExpr.trim());
}

Try / catch

try {
  return await connection.query(sql);
} catch (e) {
  if (/Not implemented|internal error/i.test(String(e.message)) && /STR_TO_DATE/i.test(sql)) {
    // fall back to casting in SQL or fetching raw and parsing client-side
    return await connection.query(replaceStrToDateWithCast(sql));
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling STR_TO_DATE in CubeSQL where the first argument is a column (ColumnarValue::Array), a NULL, or a non-Utf8 scalar instead of a literal string, e.g. SELECT STR_TO_DATE(date_column, '%Y-%m-%d').

Common situations: MySQL data-cleaning queries applied to table columns (the typical real use); ETL-style casts executed via Cube's SQL API; passing NULL dates.

Related errors


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