Skip to content

Commit

Permalink
add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Ami11111 committed Oct 17, 2024
1 parent 64367a0 commit 0273926
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
15 changes: 15 additions & 0 deletions example/http/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,21 @@ curl --request GET \
"filter": "regex(body, '\''('[0-9A-Za-z_]+'('[-+.][0-9A-Za-z_]+')''*'')'@'('[0-9A-Za-z_]+'('[-.][0-9A-Za-z_]+')''*'')''\\'.'('[0-9A-Za-z_]+'('[-.][0-9A-Za-z_]+')''*'')'\'')"
} '

# show rows of 'tbl1' where first 4 chars of body is 'test'
echo -e '\n\n-- show rows of 'tbl1' where first 4 chars of body is 'test''
curl --request GET \
--url http://localhost:23820/databases/default_db/tables/tbl1/docs \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '
{
"output":
[
"body"
],
"filter": "substring(body, 0, 4) = '\'test\''"
} '

# drop tbl1
echo -e '\n\n-- drop tbl1'
curl --request DELETE \
Expand Down
4 changes: 2 additions & 2 deletions src/function/scalar/regex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ void RegisterRegexFunction(const UniquePtr<Catalog> &catalog_ptr){

SharedPtr<ScalarFunctionSet> function_set_ptr = MakeShared<ScalarFunctionSet>(func_name);

ScalarFunction Regex_function(func_name,
ScalarFunction regex_function(func_name,
{DataType(LogicalType::kVarchar), DataType(LogicalType::kVarchar)},
DataType(LogicalType::kBoolean),
&ScalarFunction::BinaryFunction<VarcharT, VarcharT, BooleanT, RegexFunction>);
function_set_ptr->AddFunction(Regex_function);
function_set_ptr->AddFunction(regex_function);

Catalog::AddFunctionSet(catalog_ptr.get(), function_set_ptr);
}
Expand Down
25 changes: 18 additions & 7 deletions test/sql/dql/type/varchar.slt
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ SELECT * FROM test_varchar_filter where md5(c1) = md5('abcdddde');
abcdddde abcddddd 3
abcdddde abcdddde 4

SELECT * FROM test_varchar_filter where substring(c1, 0, 4) = 'abcd';
----
abcddddd abcddddd 1
abcddddc abcddddd 2
abcdddde abcddddd 3
abcdddde abcdddde 4

statement ok
INSERT INTO test_varchar_filter VALUES ('[email protected]', '[email protected]', 6);

Expand All @@ -94,5 +87,23 @@ SELECT * FROM test_varchar_filter where regex(c1, '(\w+([-+.]\w+)*)@(\w+([-.]\w+
----
[email protected] [email protected] 6

query XIII
SELECT * FROM test_varchar_filter where substring(c1, 0, 4) = 'abcd';
----
abcddddd abcddddd 1
abcddddc abcddddd 2
abcdddde abcddddd 3
abcdddde abcdddde 4

query XIIII
SELECT * FROM test_varchar_filter where substring(c1, 0, 0) = '';
----
abcddddd abcddddd 1
abcddddc abcddddd 2
abcdddde abcddddd 3
abcdddde abcdddde 4
abc abcd 5
[email protected] [email protected] 6

statement ok
DROP TABLE test_varchar_filter;

0 comments on commit 0273926

Please sign in to comment.