Skip to content

Commit

Permalink
port test and delete useless lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Lordworms committed Feb 28, 2024
1 parent f427dde commit c3e3a87
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 119 deletions.
36 changes: 4 additions & 32 deletions datafusion/functions/src/regex/regexpmatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,14 @@ use datafusion_common::ScalarValue;
use datafusion_expr::TypeSignature::*;
use datafusion_expr::{ScalarUDFImpl, Signature, Volatility};
use std::any::Any;

use datafusion_common::exec_err;
use datafusion_common::{arrow_datafusion_err, plan_err};
use datafusion_common::{
cast::as_generic_string_array, internal_err, DataFusionError, Result,
};
use datafusion_expr::ColumnarValue;
use std::sync::Arc;

#[cfg(feature = "regex_expressions")]
macro_rules! invoke_on_array_if_regex_expressions_feature_flag {
($FUNC:ident, $T:tt, $NAME:expr) => {{
$FUNC::<$T>
}};
}

#[cfg(not(feature = "regex_expressions"))]
macro_rules! invoke_on_array_if_regex_expressions_feature_flag {
($FUNC:ident, $T:tt, $NAME:expr) => {
|_: &[ArrayRef]| -> Result<ArrayRef> {
internal_err!(
"function {} requires compilation with feature flag: regex_expressions.",
$NAME
)
}
};
}
#[derive(Debug)]
pub(super) struct RegexpMatchFunc {
signature: Signature,
Expand Down Expand Up @@ -126,20 +108,10 @@ impl ScalarUDFImpl for RegexpMatchFunc {
fn regexp_match_func(args: &[ArrayRef]) -> Result<ArrayRef> {
match args[0].data_type() {
DataType::Utf8 => {
let func = invoke_on_array_if_regex_expressions_feature_flag!(
regexp_match,
i32,
"regexp_match"
);
func(args)
regexp_match::<i32>(args)
}
DataType::LargeUtf8 => {
let func = invoke_on_array_if_regex_expressions_feature_flag!(
regexp_match,
i64,
"regexp_match"
);
func(args)
regexp_match::<i64>(args)
}
other => {
internal_err!("Unsupported data type {other:?} for function regexp_match")
Expand All @@ -166,7 +138,7 @@ pub fn regexp_match<T: OffsetSizeTrait>(args: &[ArrayRef]) -> Result<ArrayRef> {
regexp::regexp_match(values, regex, Some(flags))
.map_err(|e| arrow_datafusion_err!(e))
}
other => internal_err!(
other => exec_err!(
"regexp_match was called with {other} arguments. It requires at least 2 and at most 3."
),
}
Expand Down
84 changes: 0 additions & 84 deletions datafusion/physical-expr/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3161,90 +3161,6 @@ mod tests {
Ok(())
}

// #[test]
// #[cfg(feature = "regex_expressions")]
// fn test_regexp_match() -> Result<()> {
// use datafusion_common::cast::{as_list_array, as_string_array};
// let schema = Schema::new(vec![Field::new("a", DataType::Utf8, false)]);
// let execution_props = ExecutionProps::new();

// let col_value: ArrayRef = Arc::new(StringArray::from(vec!["aaa-555"]));
// let pattern = lit(r".*-(\d*)");
// let columns: Vec<ArrayRef> = vec![col_value];
// let expr = create_physical_expr_with_type_coercion(
// &BuiltinScalarFunction::RegexpMatch,
// &[col("a", &schema)?, pattern],
// &schema,
// &execution_props,
// )?;

// // type is correct
// assert_eq!(
// expr.data_type(&schema)?,
// DataType::List(Arc::new(Field::new("item", DataType::Utf8, true)))
// );

// // evaluate works
// let batch = RecordBatch::try_new(Arc::new(schema.clone()), columns)?;
// let result = expr
// .evaluate(&batch)?
// .into_array(batch.num_rows())
// .expect("Failed to convert to array");

// // downcast works
// let result = as_list_array(&result)?;
// let first_row = result.value(0);
// let first_row = as_string_array(&first_row)?;

// // value is correct
// let expected = "555".to_string();
// assert_eq!(first_row.value(0), expected);

// Ok(())
// }

// #[test]
// #[cfg(feature = "regex_expressions")]
// fn test_regexp_match_all_literals() -> Result<()> {
// use datafusion_common::cast::{as_list_array, as_string_array};
// let schema = Schema::new(vec![Field::new("a", DataType::Int32, false)]);
// let execution_props = ExecutionProps::new();

// let col_value = lit("aaa-555");
// let pattern = lit(r".*-(\d*)");
// let columns: Vec<ArrayRef> = vec![Arc::new(Int32Array::from(vec![1]))];
// let expr = create_physical_expr_with_type_coercion(
// &BuiltinScalarFunction::RegexpMatch,
// &[col_value, pattern],
// &schema,
// &execution_props,
// )?;

// // type is correct
// assert_eq!(
// expr.data_type(&schema)?,
// DataType::List(Arc::new(Field::new("item", DataType::Utf8, true)))
// );

// // evaluate works
// let batch = RecordBatch::try_new(Arc::new(schema.clone()), columns)?;
// let result = expr
// .evaluate(&batch)?
// .into_array(batch.num_rows())
// .expect("Failed to convert to array");

// // downcast works
// let result = as_list_array(&result)?;
// let first_row = result.value(0);
// let first_row = as_string_array(&first_row)?;

// // value is correct
// let expected = "555".to_string();
// assert_eq!(first_row.value(0), expected);

// Ok(())
// }

// Helper function just for testing.
// Returns `expressions` coerced to types compatible with
// `signature`, if possible.
Expand Down
1 change: 0 additions & 1 deletion datafusion/proto/src/logical_plan/from_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,6 @@ impl From<&protobuf::ScalarFunction> for BuiltinScalarFunction {
ScalarFunction::Lpad => Self::Lpad,
ScalarFunction::Random => Self::Random,
ScalarFunction::RegexpLike => Self::RegexpLike,
//ScalarFunction::RegexpMatch => Self::RegexpMatch,
ScalarFunction::RegexpReplace => Self::RegexpReplace,
ScalarFunction::Repeat => Self::Repeat,
ScalarFunction::Replace => Self::Replace,
Expand Down
1 change: 0 additions & 1 deletion datafusion/proto/src/logical_plan/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,6 @@ impl TryFrom<&BuiltinScalarFunction> for protobuf::ScalarFunction {
BuiltinScalarFunction::Random => Self::Random,
BuiltinScalarFunction::Uuid => Self::Uuid,
BuiltinScalarFunction::RegexpLike => Self::RegexpLike,
//BuiltinScalarFunction::RegexpMatch => Self::RegexpMatch,
BuiltinScalarFunction::RegexpReplace => Self::RegexpReplace,
BuiltinScalarFunction::Repeat => Self::Repeat,
BuiltinScalarFunction::Replace => Self::Replace,
Expand Down
8 changes: 7 additions & 1 deletion datafusion/sqllogictest/test_files/regexp.slt
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ SELECT regexp_match('(?<=[A-Z]\w )Smith', 'John Smith', 'i');
----
NULL

# ported test
query ?
SELECT regexp_match('aaa-555', '.*-(\d*)');
----
[555]

#
# regexp_replace tests
#
Expand Down Expand Up @@ -300,4 +306,4 @@ SELECT regexp_replace(arrow_cast('foobar', 'Dictionary(Int32, Utf8)'), 'bar', 'x
fooxx

statement ok
drop table t;
drop table t;

0 comments on commit c3e3a87

Please sign in to comment.