2020-06-09 09:47:59 +00:00
-- error cases
SELECT extractAllGroupsHorizontal ( ) ; - - { serverError 42 } not enough arguments
SELECT extractAllGroupsHorizontal ( ' hello ' ) ; - - { serverError 42 } not enough arguments
SELECT extractAllGroupsHorizontal ( ' hello ' , 123 ) ; - - { serverError 43 } invalid argument type
SELECT extractAllGroupsHorizontal ( 123 , ' world ' ) ; - - { serverError 43 } invalid argument type
SELECT extractAllGroupsHorizontal ( ' hello world ' , ' ((( ' ) ; - - { serverError 427 } invalid re
SELECT extractAllGroupsHorizontal ( ' hello world ' , materialize ( ' \\w+ ' ) ) ; - - { serverError 44 } non - cons needle
2021-07-29 12:36:55 +00:00
SELECT extractAllGroupsHorizontal ( ' hello world ' , ' \\w+ ' ) ; -- { serverError 36 } 0 groups
2021-07-30 09:20:02 +00:00
SELECT extractAllGroupsHorizontal ( ' hello world ' , ' (\\w+) ' ) SETTINGS regexp_max_matches_per_row = 0 ; -- { serverError 128 } to many groups matched per row
SELECT extractAllGroupsHorizontal ( ' hello world ' , ' (\\w+) ' ) SETTINGS regexp_max_matches_per_row = 1 ; -- { serverError 128 } to many groups matched per row
2020-06-09 09:47:59 +00:00
2021-07-30 09:20:02 +00:00
SELECT extractAllGroupsHorizontal ( ' hello world ' , ' (\\w+) ' ) SETTINGS regexp_max_matches_per_row = 1000000 FORMAT Null ; -- users now can set limit bigger than previous 1000 matches per row
2020-06-09 09:47:59 +00:00
SELECT ' 1 group, multiple matches, String and FixedString ' ;
SELECT extractAllGroupsHorizontal ( ' hello world ' , ' (\\w+) ' ) ;
SELECT extractAllGroupsHorizontal ( ' hello world ' , CAST ( ' (\\w+) ' as FixedString ( 5 ) ) ) ;
SELECT extractAllGroupsHorizontal ( CAST ( ' hello world ' AS FixedString ( 12 ) ) , ' (\\w+) ' ) ;
SELECT extractAllGroupsHorizontal ( CAST ( ' hello world ' AS FixedString ( 12 ) ) , CAST ( ' (\\w+) ' as FixedString ( 5 ) ) ) ;
SELECT extractAllGroupsHorizontal ( materialize ( CAST ( ' hello world ' AS FixedString ( 12 ) ) ) , ' (\\w+) ' ) ;
SELECT extractAllGroupsHorizontal ( materialize ( CAST ( ' hello world ' AS FixedString ( 12 ) ) ) , CAST ( ' (\\w+) ' as FixedString ( 5 ) ) ) ;
SELECT ' mutiple groups, multiple matches ' ;
SELECT extractAllGroupsHorizontal ( ' abc=111, def=222, ghi=333 "jkl mno"="444 foo bar" ' , ' ("[^"]+"|\\w+)=("[^"]+"|\\w+) ' ) ;
SELECT ' big match ' ;
SELECT
length ( haystack ) , length ( matches ) , length ( matches [ 1 ] ) , arrayMap ( ( x ) - > length ( x ) , matches [ 1 ] )
FROM (
SELECT
repeat ( ' abcdefghijklmnopqrstuvwxyz ' , number * 10 ) AS haystack ,
extractAllGroupsHorizontal ( haystack , ' (abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz) ' ) AS matches
FROM numbers ( 3 )
) ;
SELECT ' lots of matches ' ;
SELECT
length ( haystack ) , length ( matches ) , length ( matches [ 1 ] ) , arrayReduce ( ' sum ' , arrayMap ( ( x ) - > length ( x ) , matches [ 1 ] ) )
FROM (
SELECT
repeat ( ' abcdefghijklmnopqrstuvwxyz ' , number * 10 ) AS haystack ,
extractAllGroupsHorizontal ( haystack , ' (\\w) ' ) AS matches
FROM numbers ( 3 )
) ;
SELECT ' lots of groups ' ;
SELECT
length ( haystack ) , length ( matches ) , length ( matches [ 1 ] ) , arrayMap ( ( x ) - > length ( x ) , matches [ 1 ] )
FROM (
SELECT
repeat ( ' abcdefghijklmnopqrstuvwxyz ' , number * 10 ) AS haystack ,
extractAllGroupsHorizontal ( haystack , repeat ( ' (\\w) ' , 100 ) ) AS matches
FROM numbers ( 3 )
) ;