Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compute-types/tests/snapshots/func_registry.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/expr/src/scalar/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ func_name! {
<E> CastListToJsonb<E> => "cast_list_to_jsonb",
CastListToString => "cast_list_to_string",
CastMapToString => "cast_map_to_string",
CastRangeToString => "cast_range_to_string",
<E> CastRecord1ToRecord2<E> => "cast_record1_to_record2",
CastRecordToString => "cast_record_to_string",
<E> CastStringToArray<E> => "cast_string_to_array",
Expand Down
64 changes: 9 additions & 55 deletions src/expr/src/scalar/func/impls/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0.

use std::fmt;

use mz_expr_derive::sqlfunc;
use mz_repr::adt::range::Range;
use mz_repr::{Datum, RowArena, SqlColumnType, SqlScalarType};
use mz_repr::{Datum, ExcludeNull, SqlScalarType};
use serde::{Deserialize, Serialize};

use crate::scalar::func::{LazyUnaryFunc, stringify_datum};
use crate::{Eval, EvalError};
use crate::EvalError;
use crate::scalar::func::stringify_datum;

#[derive(
Ord,
Expand All @@ -32,56 +30,12 @@ pub struct CastRangeToString {
pub ty: SqlScalarType,
}

impl LazyUnaryFunc for CastRangeToString {
fn eval<'a>(
&'a self,
datums: &[Datum<'a>],
temp_storage: &'a RowArena,
a: &'a impl Eval,
) -> Result<Datum<'a>, EvalError> {
let a = a.eval(datums, temp_storage)?;
if a.is_null() {
return Ok(Datum::Null);
}
let mut buf = String::new();
stringify_datum(&mut buf, a, &self.ty)?;
Ok(Datum::String(temp_storage.push_string(buf)))
}

fn output_sql_type(&self, input_type: SqlColumnType) -> SqlColumnType {
SqlScalarType::String.nullable(input_type.nullable)
}

fn propagates_nulls(&self) -> bool {
true
}

fn introduces_nulls(&self) -> bool {
false
}

fn preserves_uniqueness(&self) -> bool {
true
}

fn inverse(&self) -> Option<crate::UnaryFunc> {
// TODO? if typeconv was in expr, we could determine this
None
}

fn is_monotone(&self) -> bool {
false
}

fn is_eliminable_cast(&self) -> bool {
false
}
}

impl fmt::Display for CastRangeToString {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("rangetostr")
}
// TODO? if typeconv was in expr, we could determine the inverse of this cast
#[sqlfunc(CastRangeToString, sqlname = "rangetostr", preserves_uniqueness = true)]
fn cast_range_to_string<'a>(&self, a: ExcludeNull<Datum<'a>>) -> Result<String, EvalError> {
let mut buf = String::new();
stringify_datum(&mut buf, *a, &self.ty)?;
Ok(buf)
}

// The monotone claim survives this function mapping empty and
Expand Down
Loading