MCPcopy Create free account
hub / github.com/apache/datafusion / sqlite_from_unixtime_to_sql

Function sqlite_from_unixtime_to_sql

datafusion/sql/src/unparser/utils.rs:546–564  ·  view source on GitHub ↗

SQLite does not support timestamp/date scalars like `to_timestamp`, `from_unixtime`, `date_trunc`, etc. This remaps `from_unixtime` to `datetime(expr, 'unixepoch')`, expecting the input to be in seconds. It supports no other arguments, so if any are supplied it will return an error. # Errors - If the number of arguments is not 1 - the column or expression to convert. - If the scalar function can

(
    unparser: &Unparser,
    from_unixtime_args: &[Expr],
)

Source from the content-addressed store, hash-verified

544/// - If the number of arguments is not 1 - the column or expression to convert.
545/// - If the scalar function cannot be converted to SQL.
546pub(crate) fn sqlite_from_unixtime_to_sql(
547 unparser: &Unparser,
548 from_unixtime_args: &[Expr],
549) -> Result<Option<ast::Expr>> {
550 assert_eq_or_internal_err!(
551 from_unixtime_args.len(),
552 1,
553 "from_unixtime for SQLite expects 1 argument, found {}",
554 from_unixtime_args.len()
555 );
556
557 Ok(Some(unparser.scalar_function_to_sql(
558 "datetime",
559 &[
560 from_unixtime_args[0].clone(),
561 Expr::Literal(ScalarValue::Utf8(Some("unixepoch".to_string())), None),
562 ],
563 )?))
564}
565
566/// SQLite does not support timestamp/date scalars like `to_timestamp`, `from_unixtime`, `date_trunc`, etc.
567/// This uses the `strftime` function to format the timestamp as a string depending on the truncation unit.

Callers 1

Calls 4

LiteralInterface · 0.50
cloneMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…