Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/environmentd/tests/testdata/http/ws

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion src/expr/src/scalar/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2599,7 +2599,7 @@ where
}
}

#[sqlfunc(propagates_nulls = true)]
#[sqlfunc]
fn position(substring: &str, string: &str) -> Result<i32, EvalError> {
let char_index = string.find(substring);

Expand All @@ -2617,6 +2617,11 @@ fn position(substring: &str, string: &str) -> Result<i32, EvalError> {
}
}

#[sqlfunc]
fn strpos(string: &str, substring: &str) -> Result<i32, EvalError> {
position(substring, string)
}

#[sqlfunc(
propagates_nulls = true,
// `left` is unfortunately not monotonic (at least for negative second arguments),
Expand Down
1 change: 1 addition & 0 deletions src/expr/src/scalar/func/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ mod derive {
ConvertFrom(ConvertFrom),
Left(Left),
Position(Position),
Strpos(Strpos),
Right(Right),
RepeatString(RepeatString),
Normalize(Normalize),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/expr/src/scalar/func.rs
expression: "#[sqlfunc(propagates_nulls = true)]\nfn position(substring: &str, string: &str) -> Result<i32, EvalError> {\n let char_index = string.find(substring);\n if let Some(char_index) = char_index {\n let string_prefix = &string[0..char_index];\n let num_prefix_chars = string_prefix.chars().count();\n let num_prefix_chars = i32::try_from(num_prefix_chars)\n .map_err(|_| EvalError::Int32OutOfRange(\n num_prefix_chars.to_string().into(),\n ))?;\n Ok(num_prefix_chars + 1)\n } else {\n Ok(0)\n }\n}\n"
expression: "#[sqlfunc()]\nfn position(substring: &str, string: &str) -> Result<i32, EvalError> {\n let char_index = string.find(substring);\n if let Some(char_index) = char_index {\n let string_prefix = &string[0..char_index];\n let num_prefix_chars = string_prefix.chars().count();\n let num_prefix_chars = i32::try_from(num_prefix_chars)\n .map_err(|_| EvalError::Int32OutOfRange(\n num_prefix_chars.to_string().into(),\n ))?;\n Ok(num_prefix_chars + 1)\n } else {\n Ok(0)\n }\n}\n"
---
#[derive(
proptest_derive::Arbitrary,
Expand Down Expand Up @@ -46,9 +46,6 @@ impl<'a> crate::func::binary::EagerBinaryFunc<'a> for Position {
&& (input_type_a.nullable || input_type_b.nullable)),
)
}
fn propagates_nulls(&self) -> bool {
true
}
}
impl std::fmt::Display for Position {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
source: src/expr/src/scalar/func.rs
expression: "#[sqlfunc()]\nfn strpos(string: &str, substring: &str) -> Result<i32, EvalError> {\n position(substring, string)\n}\n"
---
#[derive(
proptest_derive::Arbitrary,
Ord,
PartialOrd,
Clone,
Debug,
Eq,
PartialEq,
serde::Serialize,
serde::Deserialize,
Hash,
mz_lowertest::MzReflect
)]
pub struct Strpos;
impl<'a> crate::func::binary::EagerBinaryFunc<'a> for Strpos {
type Input1 = &'a str;
type Input2 = &'a str;
type Output = Result<i32, EvalError>;
fn call(
&self,
a: Self::Input1,
b: Self::Input2,
temp_storage: &'a mz_repr::RowArena,
) -> Self::Output {
strpos(a, b)
}
fn output_type(
&self,
input_type_a: mz_repr::SqlColumnType,
input_type_b: mz_repr::SqlColumnType,
) -> mz_repr::SqlColumnType {
use mz_repr::AsColumnType;
let output = Self::Output::as_column_type();
let propagates_nulls = crate::func::binary::EagerBinaryFunc::propagates_nulls(
self,
);
let nullable = output.nullable;
output
.nullable(
nullable
|| (propagates_nulls
&& (input_type_a.nullable || input_type_b.nullable)),
)
}
}
impl std::fmt::Display for Strpos {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(stringify!(strpos))
}
}
fn strpos(string: &str, substring: &str) -> Result<i32, EvalError> {
position(substring, string)
}
3 changes: 3 additions & 0 deletions src/sql/src/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2622,6 +2622,9 @@ pub static PG_CATALOG_BUILTINS: LazyLock<BTreeMap<&'static str, Func>> = LazyLoc
"asinh" => Scalar {
params!(Float64) => UnaryFunc::Asinh(func::Asinh) => Float64, 2465;
},
"strpos" => Scalar {
params!(String, String) => BinaryFunc::from(func::Strpos) => Int32, 868;
},
"split_part" => Scalar {
params!(String, String, Int32) => VariadicFunc::SplitPart => String, 2088;
},
Expand Down
Loading