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

Function interval_literal

datafusion/sql/src/expr/value.rs:268–305  ·  view source on GitHub ↗
(interval_value: SQLExpr, negative: bool)

Source from the content-addressed store, hash-verified

266}
267
268fn interval_literal(interval_value: SQLExpr, negative: bool) -> Result<String> {
269 let s = match interval_value {
270 SQLExpr::Value(ValueWithSpan {
271 value: Value::SingleQuotedString(s) | Value::DoubleQuotedString(s),
272 span: _,
273 }) => s,
274 SQLExpr::Value(ValueWithSpan {
275 value: Value::Number(ref v, long),
276 span: _,
277 }) => {
278 if long {
279 return not_impl_err!(
280 "Unsupported interval argument. Long number not supported: {interval_value:?}"
281 );
282 } else {
283 v.to_string()
284 }
285 }
286 SQLExpr::UnaryOp { op, expr } => {
287 let negative = match op {
288 UnaryOperator::Minus => !negative,
289 UnaryOperator::Plus => negative,
290 _ => {
291 return not_impl_err!(
292 "Unsupported SQL unary operator in interval {op:?}"
293 );
294 }
295 };
296 interval_literal(*expr, negative)?
297 }
298 _ => {
299 return not_impl_err!(
300 "Unsupported interval argument. Expected string literal or number, got: {interval_value:?}"
301 );
302 }
303 };
304 if negative { Ok(format!("-{s}")) } else { Ok(s) }
305}
306
307/// Try to decode bytes from hex literal string.
308///

Callers 1

Calls 1

to_stringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…