{"record":{"id":"309c3c998f6ecd3f","repo":"cube-js/cube","slug":"not-implemented-309c3c","errorCode":null,"errorMessage":"not implemented","messagePattern":"not implemented","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rust/cubesql/cubesql/src/compile/engine/udf/common.rs","lineNumber":1418,"sourceCode":"        .replace(\"dd\", \"%d\")\n        .replace(\"HH24\", \"%H\")\n        .replace(\"HH12\", \"%I\")\n        .replace(\"MI\", \"%M\")\n        .replace(\"mi\", \"%M\")\n        .replace(\"SS\", \"%S\")\n        .replace(\"ss\", \"%S\")\n        .replace(\".US\", \"%.f\")\n        .replace(\"MM\", \"%m\")\n        .replace(\".MS\", \"%.3f\")\n}\n\npub fn create_str_to_date_udf() -> ScalarUDF {\n    let fun: Arc<dyn Fn(&[ColumnarValue]) -> Result<ColumnarValue> + Send + Sync> =\n        Arc::new(move |args: &[ColumnarValue]| {\n            let timestamp = match &args[0] {\n                ColumnarValue::Scalar(ScalarValue::Utf8(Some(value))) => value,\n                _ => {\n                    todo!()\n                }\n            };\n\n            let format = match &args[1] {\n                ColumnarValue::Scalar(ScalarValue::Utf8(Some(value))) => value,\n                ColumnarValue::Scalar(value) => {\n                    return Err(DataFusionError::Execution(format!(\n                        \"Expected string but got {:?} as a format param\",\n                        value\n                    )))\n                }\n                ColumnarValue::Array(_) => {\n                    return Err(DataFusionError::Execution(\n                        \"Array is not supported for format param in str_to_date\".to_string(),\n                    ))\n                }\n            };\n","sourceCodeStart":1400,"sourceCodeEnd":1436,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/rust/cubesql/cubesql/src/compile/engine/udf/common.rs#L1400-L1436","documentation":"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.","triggerScenarios":"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').","commonSituations":"MySQL data-cleaning queries applied to table columns (the typical real use); ETL-style casts executed via Cube's SQL API; passing NULL dates.","solutions":["Pass a literal constant string as the first argument (the only supported case), or perform the conversion upstream in the database/model","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","Cast the column to timestamp in the data model (e.g. defined dimension with sql/translate) instead of using STR_TO_DATE"],"exampleFix":"// before\nlet timestamp = match &args[0] {\n    ColumnarValue::Scalar(ScalarValue::Utf8(Some(value))) => value,\n    _ => todo!(),\n};\n// after\nlet timestamp = match &args[0] {\n    ColumnarValue::Scalar(ScalarValue::Utf8(Some(value))) => value.clone(),\n    ColumnarValue::Scalar(ScalarValue::Utf8(None)) => return Ok(ColumnarValue::Scalar(ScalarValue::TimestampNanosecond(None, None))),\n    ColumnarValue::Array(arr) => arrow::array::as_string_array(arr).clone(),\n    other => return Err(CubeError::internal(format!(\"str_to_date: unsupported arg {:?}\", other))),\n};","handlingStrategy":"validation","validationCode":"// Only use STR_TO_DATE with a literal string first argument via Cube SQL API\nfunction assertStrToDateSafe(sql) {\n  const m = sql.match(/STR_TO_DATE\\s*\\(\\s*([^,]+),/i);\n  if (m && !/^\\s*'/.test(m[1])) {\n    throw new Error('STR_TO_DATE only supports constant string dates in CubeSQL; cast the column in the data model instead');\n  }\n}","typeGuard":"function isStrToDateScalarSupported(argExpr) {\n  // supported: non-empty single-quoted string literal, non-NULL\n  return /^'[^']*'$/.test(argExpr.trim());\n}","tryCatchPattern":"try {\n  return await connection.query(sql);\n} catch (e) {\n  if (/Not implemented|internal error/i.test(String(e.message)) && /STR_TO_DATE/i.test(sql)) {\n    // fall back to casting in SQL or fetching raw and parsing client-side\n    return await connection.query(replaceStrToDateWithCast(sql));\n  }\n  throw e;\n}","preventionTips":["Never pass a column as STR_TO_DATE's first argument through CubeSQL","Convert string dates to timestamps in the data model (dimension sql/cast) instead","Parse dates client-side when the value comes back as a string","Handle NULLs explicitly before formatting/parsing dates"],"tags":["rust","udf","not-implemented","cubesql","date-functions"],"backgroundTag":"unimplemented-udf","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}