MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / cast_to_string

Method cast_to_string

graphlite/src/exec/executor.rs:5016–5059  ·  view source on GitHub ↗

Cast value to STRING

(
        &self,
        value: Value,
        max_length: Option<usize>,
    )

Source from the content-addressed store, hash-verified

5014
5015 /// Cast value to STRING
5016 fn cast_to_string(
5017 &self,
5018 value: Value,
5019 max_length: Option<usize>,
5020 ) -> Result<Value, ExecutionError> {
5021 let string_value = match value {
5022 Value::String(s) => s,
5023 Value::Number(n) => {
5024 if n.fract() == 0.0 {
5025 format!("{}", n as i64)
5026 } else {
5027 format!("{}", n)
5028 }
5029 }
5030 Value::Boolean(b) => {
5031 if b {
5032 "true".to_string()
5033 } else {
5034 "false".to_string()
5035 }
5036 }
5037 Value::DateTime(dt) => dt.format("%Y-%m-%d %H:%M:%S UTC").to_string(),
5038 Value::Null => return Ok(Value::Null),
5039 _ => {
5040 return Err(ExecutionError::RuntimeError(format!(
5041 "Cannot cast {:?} to STRING",
5042 value.type_name()
5043 )))
5044 }
5045 };
5046
5047 // Apply max_length constraint if specified
5048 let final_string = if let Some(max_len) = max_length {
5049 if string_value.len() > max_len {
5050 string_value[..max_len].to_string()
5051 } else {
5052 string_value
5053 }
5054 } else {
5055 string_value
5056 };
5057
5058 Ok(Value::String(final_string))
5059 }
5060
5061 /// Cast value to INTEGER
5062 fn cast_to_integer(&self, value: Value) -> Result<Value, ExecutionError> {

Callers 1

cast_valueMethod · 0.80

Calls 2

formatMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected