WITH t0 AS ( SELECT t14.id AS id, CASE WHEN ( t14.prefix IS NULL OR COALESCE( LOWER(t14.prefix) IN ('', '-1.#qnan', '', '1.#qnan', 'not provided', '1.#ind', 'none', 'nan', 'unknown', 'unidentified', '-1.#ind', 'null', 'pending', 'na', 'n/a', '#n/a n/a', 'not reported', '-nan', '#na', 'need', 'anon', 'anonymous', 'not known', '#n/a', 'not specified'), CAST(FALSE AS BOOLEAN) ) OR NOT COALESCE(REGEXP_MATCHES(LOWER(t14.prefix), '.*[a-z0-9].*'), CAST(FALSE AS BOOLEAN)) ) THEN NULL ELSE t14.prefix END AS prefix, CASE WHEN ( t14.first_name IS NULL OR COALESCE( LOWER(t14.first_name) IN ('', '-1.#qnan', '', '1.#qnan', 'not provided', '1.#ind', 'none', 'nan', 'unknown', 'unidentified', '-1.#ind', 'null', 'pending', 'na', 'n/a', '#n/a n/a', 'not reported', '-nan', '#na', 'need', 'anon', 'anonymous', 'not known', '#n/a', 'not specified'), CAST(FALSE AS BOOLEAN) ) OR NOT COALESCE(REGEXP_MATCHES(LOWER(t14.first_name), '.*[a-z0-9].*'), CAST(FALSE AS BOOLEAN)) ) THEN NULL ELSE t14.first_name END AS first_name, CASE WHEN ( t14.middle_name IS NULL OR COALESCE( LOWER(t14.middle_name) IN ('', '-1.#qnan', '', '1.#qnan', 'not provided', '1.#ind', 'none', 'nan', 'unknown', 'unidentified', '-1.#ind', 'null', 'pending', 'na', 'n/a', '#n/a n/a', 'not reported', '-nan', '#na', 'need', 'anon', 'anonymous', 'not known', '#n/a', 'not specified'), CAST(FALSE AS BOOLEAN) ) OR NOT COALESCE(REGEXP_MATCHES(LOWER(t14.middle_name), '.*[a-z0-9].*'), CAST(FALSE AS BOOLEAN)) ) THEN NULL ELSE t14.middle_name END AS middle_name, CASE WHEN ( t14.last_name IS NULL OR COALESCE( LOWER(t14.last_name) IN ('', '-1.#qnan', '', '1.#qnan', 'not provided', '1.#ind', 'none', 'nan', 'unknown', 'unidentified', '-1.#ind', 'null', 'pending', 'na', 'n/a', '#n/a n/a', 'not reported', '-nan', '#na', 'need', 'anon', 'anonymous', 'not known', '#n/a', 'not specified'), CAST(FALSE AS BOOLEAN) ) OR NOT COALESCE(REGEXP_MATCHES(LOWER(t14.last_name), '.*[a-z0-9].*'), CAST(FALSE AS BOOLEAN)) ) THEN NULL ELSE t14.last_name END AS last_name, CASE WHEN ( t14.suffix IS NULL OR COALESCE( LOWER(t14.suffix) IN ('', '-1.#qnan', '', '1.#qnan', 'not provided', '1.#ind', 'none', 'nan', 'unknown', 'unidentified', '-1.#ind', 'null', 'pending', 'na', 'n/a', '#n/a n/a', 'not reported', '-nan', '#na', 'need', 'anon', 'anonymous', 'not known', '#n/a', 'not specified'), CAST(FALSE AS BOOLEAN) ) OR NOT COALESCE(REGEXP_MATCHES(LOWER(t14.suffix), '.*[a-z0-9].*'), CAST(FALSE AS BOOLEAN)) ) THEN NULL ELSE t14.suffix END AS suffix, CASE WHEN ( t14.nickname IS NULL OR COALESCE( LOWER(t14.nickname) IN ('', '-1.#qnan', '', '1.#qnan', 'not provided', '1.#ind', 'none', 'nan', 'unknown', 'unidentified', '-1.#ind', 'null', 'pending', 'na', 'n/a', '#n/a n/a', 'not reported', '-nan', '#na', 'need', 'anon', 'anonymous', 'not known', '#n/a', 'not specified'), CAST(FALSE AS BOOLEAN) ) OR NOT COALESCE(REGEXP_MATCHES(LOWER(t14.nickname), '.*[a-z0-9].*'), CAST(FALSE AS BOOLEAN)) ) THEN NULL ELSE t14.nickname END AS nickname FROM main.ibis_read_parquet_wjltivuqprauza3pvnwj2u7dcy AS t14 ), t1 AS ( SELECT t0.id AS id, t0.prefix AS prefix, CASE WHEN ( NOT t0.first_name IS NULL AND t0.nickname IS NULL AND ARRAY_LENGTH( STR_SPLIT( NULLIF( TRIM( REGEXP_REPLACE( REGEXP_EXTRACT(t0.first_name, '(.*)(''.*''|".*"|\(.*\))', CAST(1 AS INT)), '\\s+', ' ', 'g' ), ' ' ), '' ), ' ' ) ) = CAST(1 AS TINYINT) AND ARRAY_LENGTH( STR_SPLIT( NULLIF( TRIM( REGEXP_REPLACE( REGEXP_REPLACE( REGEXP_EXTRACT(t0.first_name, '(.*)(''.*''|".*"|\(.*\))', CAST(2 AS INT)), '^(''|"|\(|\))+|(''|"|\(|\))+$', '', 'g' ), '\\s+', ' ', 'g' ), ' ' ), '' ), ' ' ) ) = CAST(1 AS TINYINT) ) THEN NULLIF( TRIM( REGEXP_REPLACE( REGEXP_EXTRACT(t0.first_name, '(.*)(''.*''|".*"|\(.*\))', CAST(1 AS INT)), '\\s+', ' ', 'g' ), ' ' ), '' ) ELSE t0.first_name END AS first_name, t0.middle_name AS middle_name, t0.last_name AS last_name, t0.suffix AS suffix, CASE WHEN ( NOT t0.first_name IS NULL AND t0.nickname IS NULL AND ARRAY_LENGTH( STR_SPLIT( NULLIF( TRIM( REGEXP_REPLACE( REGEXP_EXTRACT(t0.first_name, '(.*)(''.*''|".*"|\(.*\))', CAST(1 AS INT)), '\\s+', ' ', 'g' ), ' ' ), '' ), ' ' ) ) = CAST(1 AS TINYINT) AND ARRAY_LENGTH( STR_SPLIT( NULLIF( TRIM( REGEXP_REPLACE( REGEXP_REPLACE( REGEXP_EXTRACT(t0.first_name, '(.*)(''.*''|".*"|\(.*\))', CAST(2 AS INT)), '^(''|"|\(|\))+|(''|"|\(|\))+$', '', 'g' ), '\\s+', ' ', 'g' ), ' ' ), '' ), ' ' ) ) = CAST(1 AS TINYINT) ) THEN NULLIF( TRIM( REGEXP_REPLACE( REGEXP_REPLACE( REGEXP_EXTRACT(t0.first_name, '(.*)(''.*''|".*"|\(.*\))', CAST(2 AS INT)), '^(''|"|\(|\))+|(''|"|\(|\))+$', '', 'g' ), '\\s+', ' ', 'g' ), ' ' ), '' ) ELSE t0.nickname END AS nickname FROM t0 ), t2 AS ( SELECT t1.id AS id, t1.prefix AS prefix, CASE WHEN ( COALESCE(TRIM(t1.first_name, ' '), '') = '' AND COALESCE( ARRAY_LENGTH( STR_SPLIT( NULLIF( TRIM( REGEXP_REPLACE( NULLIF( TRIM( REGEXP_REPLACE(REGEXP_EXTRACT(t1.last_name, '^(.*),(.*)$', CAST(1 AS INT)), '\\s+', ' ', 'g'), ' ' ), '' ), '\\s+', ' ', 'g' ), ' ' ), '' ), ' ' ) ), CAST(0 AS TINYINT) ) = CAST(1 AS TINYINT) AND COALESCE( ARRAY_LENGTH( STR_SPLIT( NULLIF( TRIM( REGEXP_REPLACE( NULLIF( TRIM( REGEXP_REPLACE(REGEXP_EXTRACT(t1.last_name, '^(.*),(.*)$', CAST(2 AS INT)), '\\s+', ' ', 'g'), ' ' ), '' ), '\\s+', ' ', 'g' ), ' ' ), '' ), ' ' ) ), CAST(0 AS TINYINT) ) = CAST(1 AS TINYINT) ) THEN NULLIF( TRIM( REGEXP_REPLACE(REGEXP_EXTRACT(t1.last_name, '^(.*),(.*)$', CAST(2 AS INT)), '\\s+', ' ', 'g'), ' ' ), '' ) ELSE t1.first_name END AS first_name, t1.middle_name AS middle_name, CASE WHEN ( COALESCE(TRIM(t1.first_name, ' '), '') = '' AND COALESCE( ARRAY_LENGTH( STR_SPLIT( NULLIF( TRIM( REGEXP_REPLACE( NULLIF( TRIM( REGEXP_REPLACE(REGEXP_EXTRACT(t1.last_name, '^(.*),(.*)$', CAST(1 AS INT)), '\\s+', ' ', 'g'), ' ' ), '' ), '\\s+', ' ', 'g' ), ' ' ), '' ), ' ' ) ), CAST(0 AS TINYINT) ) = CAST(1 AS TINYINT) AND COALESCE( ARRAY_LENGTH( STR_SPLIT( NULLIF( TRIM( REGEXP_REPLACE( NULLIF( TRIM( REGEXP_REPLACE(REGEXP_EXTRACT(t1.last_name, '^(.*),(.*)$', CAST(2 AS INT)), '\\s+', ' ', 'g'), ' ' ), '' ), '\\s+', ' ', 'g' ), ' ' ), '' ), ' ' ) ), CAST(0 AS TINYINT) ) = CAST(1 AS TINYINT) ) THEN NULLIF( TRIM( REGEXP_REPLACE(REGEXP_EXTRACT(t1.last_name, '^(.*),(.*)$', CAST(1 AS INT)), '\\s+', ' ', 'g'), ' ' ), '' ) ELSE t1.last_name END AS last_name, t1.suffix AS suffix, t1.nickname AS nickname FROM t1 ), t3 AS ( SELECT t2.id AS id, t2.prefix AS prefix, CASE WHEN ( NOT NULLIF(t2.last_name, '') IS NULL AND NULLIF(t2.first_name, '') IS NULL AND ARRAY_LENGTH(STR_SPLIT(NULLIF(t2.last_name, ''), ' ')) = CAST(2 AS TINYINT) ) THEN NULLIF( TRIM( REGEXP_REPLACE( LIST_EXTRACT( STR_SPLIT(NULLIF(t2.last_name, ''), ' '), CASE WHEN CAST(0 AS TINYINT) < 0 THEN ARRAY_LENGTH(STR_SPLIT(NULLIF(t2.last_name, ''), ' ')) + GREATEST(CAST(0 AS TINYINT), -ARRAY_LENGTH(STR_SPLIT(NULLIF(t2.last_name, ''), ' '))) ELSE CAST(0 AS TINYINT) END + 1 ), '\\s+', ' ', 'g' ), ' ' ), '' ) ELSE NULLIF(t2.first_name, '') END AS first_name, t2.middle_name AS middle_name, CASE WHEN ( NOT NULLIF(t2.last_name, '') IS NULL AND NULLIF(t2.first_name, '') IS NULL AND ARRAY_LENGTH(STR_SPLIT(NULLIF(t2.last_name, ''), ' ')) = CAST(2 AS TINYINT) ) THEN NULLIF( TRIM( REGEXP_REPLACE( LIST_EXTRACT( STR_SPLIT(NULLIF(t2.last_name, ''), ' '), CASE WHEN CAST(1 AS TINYINT) < 0 THEN ARRAY_LENGTH(STR_SPLIT(NULLIF(t2.last_name, ''), ' ')) + GREATEST(CAST(1 AS TINYINT), -ARRAY_LENGTH(STR_SPLIT(NULLIF(t2.last_name, ''), ' '))) ELSE CAST(1 AS TINYINT) END + 1 ), '\\s+', ' ', 'g' ), ' ' ), '' ) ELSE NULLIF(t2.last_name, '') END AS last_name, t2.suffix AS suffix, t2.nickname AS nickname FROM t2 ), t4 AS ( SELECT t3.id AS id, t3.prefix AS prefix, CASE WHEN ( NOT t3.first_name IS NULL AND t3.middle_name IS NULL AND ( COALESCE( LENGTH( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(1 AS INT)), '' ) ), CAST(0 AS TINYINT) ) = CAST(1 AS TINYINT) AND COALESCE( LENGTH( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(2 AS INT)), '' ) ), CAST(0 AS TINYINT) ) > CAST(1 AS TINYINT) OR COALESCE( LENGTH( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(1 AS INT)), '' ) ), CAST(0 AS TINYINT) ) > CAST(1 AS TINYINT) AND COALESCE( LENGTH( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(2 AS INT)), '' ) ), CAST(0 AS TINYINT) ) = CAST(1 AS TINYINT) ) AND NOT COALESCE( t3.last_name LIKE CONCAT( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(1 AS INT)), '' ), '%' ), CAST(FALSE AS BOOLEAN) ) ) THEN NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(1 AS INT)), '' ) ELSE CASE WHEN ( NOT t3.first_name IS NULL AND t3.middle_name IS NULL AND ( COALESCE( LENGTH( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(1 AS INT)), '' ) ), CAST(0 AS TINYINT) ) = CAST(1 AS TINYINT) AND COALESCE( LENGTH( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(2 AS INT)), '' ) ), CAST(0 AS TINYINT) ) > CAST(1 AS TINYINT) OR COALESCE( LENGTH( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(1 AS INT)), '' ) ), CAST(0 AS TINYINT) ) > CAST(1 AS TINYINT) AND COALESCE( LENGTH( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(2 AS INT)), '' ) ), CAST(0 AS TINYINT) ) = CAST(1 AS TINYINT) ) AND COALESCE( t3.last_name LIKE CONCAT( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(1 AS INT)), '' ), '%' ), CAST(FALSE AS BOOLEAN) ) ) THEN NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(2 AS INT)), '' ) ELSE CASE WHEN COALESCE( t3.middle_name LIKE CONCAT( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(2 AS INT)), '' ), '%' ) OR NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(2 AS INT)), '' ) LIKE CONCAT(t3.middle_name, '%'), CAST(FALSE AS BOOLEAN) ) THEN NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(1 AS INT)), '' ) ELSE t3.first_name END END END AS first_name, CASE WHEN ( COALESCE( LENGTH( NULLIF( REGEXP_EXTRACT(t3.last_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(1 AS INT)), '' ) ), CAST(0 AS TINYINT) ) = CAST(1 AS TINYINT) AND COALESCE( LENGTH( NULLIF( REGEXP_EXTRACT(t3.last_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(2 AS INT)), '' ) ), CAST(0 AS TINYINT) ) > CAST(1 AS TINYINT) AND t3.middle_name IS NULL ) THEN NULLIF( REGEXP_EXTRACT(t3.last_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(1 AS INT)), '' ) ELSE CASE WHEN ( NOT t3.first_name IS NULL AND t3.middle_name IS NULL AND ( COALESCE( LENGTH( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(1 AS INT)), '' ) ), CAST(0 AS TINYINT) ) = CAST(1 AS TINYINT) AND COALESCE( LENGTH( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(2 AS INT)), '' ) ), CAST(0 AS TINYINT) ) > CAST(1 AS TINYINT) OR COALESCE( LENGTH( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(1 AS INT)), '' ) ), CAST(0 AS TINYINT) ) > CAST(1 AS TINYINT) AND COALESCE( LENGTH( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(2 AS INT)), '' ) ), CAST(0 AS TINYINT) ) = CAST(1 AS TINYINT) ) AND NOT COALESCE( t3.last_name LIKE CONCAT( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(1 AS INT)), '' ), '%' ), CAST(FALSE AS BOOLEAN) ) ) THEN NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(2 AS INT)), '' ) ELSE CASE WHEN ( NOT t3.first_name IS NULL AND t3.middle_name IS NULL AND ( COALESCE( LENGTH( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(1 AS INT)), '' ) ), CAST(0 AS TINYINT) ) = CAST(1 AS TINYINT) AND COALESCE( LENGTH( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(2 AS INT)), '' ) ), CAST(0 AS TINYINT) ) > CAST(1 AS TINYINT) OR COALESCE( LENGTH( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(1 AS INT)), '' ) ), CAST(0 AS TINYINT) ) > CAST(1 AS TINYINT) AND COALESCE( LENGTH( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(2 AS INT)), '' ) ), CAST(0 AS TINYINT) ) = CAST(1 AS TINYINT) ) AND COALESCE( t3.last_name LIKE CONCAT( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(1 AS INT)), '' ), '%' ), CAST(FALSE AS BOOLEAN) ) ) THEN NULL ELSE CASE WHEN COALESCE( t3.middle_name LIKE CONCAT( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(2 AS INT)), '' ), '%' ) OR NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(2 AS INT)), '' ) LIKE CONCAT(t3.middle_name, '%'), CAST(FALSE AS BOOLEAN) ) THEN CASE WHEN ( COALESCE( LENGTH( NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(2 AS INT)), '' ) ), CAST(0 AS TINYINT) ) > COALESCE(LENGTH(t3.middle_name), CAST(0 AS TINYINT)) ) THEN NULLIF( REGEXP_EXTRACT(t3.first_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(2 AS INT)), '' ) ELSE t3.middle_name END ELSE t3.middle_name END END END END AS middle_name, CASE WHEN ( COALESCE( LENGTH( NULLIF( REGEXP_EXTRACT(t3.last_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(1 AS INT)), '' ) ), CAST(0 AS TINYINT) ) = CAST(1 AS TINYINT) AND COALESCE( LENGTH( NULLIF( REGEXP_EXTRACT(t3.last_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(2 AS INT)), '' ) ), CAST(0 AS TINYINT) ) > CAST(1 AS TINYINT) AND t3.middle_name IS NULL ) THEN NULLIF( REGEXP_EXTRACT(t3.last_name, '^\\s*(\\w+)\\.?\\s+(\\w+)\\.?\\s*$', CAST(2 AS INT)), '' ) ELSE t3.last_name END AS last_name, t3.suffix AS suffix, t3.nickname AS nickname FROM t3 ), t5 AS ( SELECT t4.id AS id, t4.prefix AS prefix, CASE WHEN ( TRIM( LOWER( NULLIF( TRIM( REGEXP_REPLACE( REGEXP_REPLACE(REGEXP_REPLACE(t4.first_name, '[^\\x00-\\x7F]+', '', 'g'), '[^A-Za-z0-9]+', ' ', 'g'), '\\s+', ' ', 'g' ), ' ' ), '' ) ), ' ' ) = TRIM( LOWER( NULLIF( TRIM( REGEXP_REPLACE( REGEXP_REPLACE(REGEXP_REPLACE(t4.last_name, '[^\\x00-\\x7F]+', '', 'g'), '[^A-Za-z0-9]+', ' ', 'g'), '\\s+', ' ', 'g' ), ' ' ), '' ) ), ' ' ) AND COALESCE( ARRAY_LENGTH( STR_SPLIT( NULLIF( TRIM( REGEXP_REPLACE( TRIM( LOWER( NULLIF( TRIM( REGEXP_REPLACE( REGEXP_REPLACE(REGEXP_REPLACE(t4.first_name, '[^\\x00-\\x7F]+', '', 'g'), '[^A-Za-z0-9]+', ' ', 'g'), '\\s+', ' ', 'g' ), ' ' ), '' ) ), ' ' ), '\\s+', ' ', 'g' ), ' ' ), '' ), ' ' ) ), CAST(0 AS TINYINT) ) = CAST(1 AS TINYINT) AND COALESCE( ARRAY_LENGTH( STR_SPLIT( NULLIF( TRIM( REGEXP_REPLACE( TRIM( LOWER( NULLIF( TRIM( REGEXP_REPLACE( REGEXP_REPLACE(REGEXP_REPLACE(t4.last_name, '[^\\x00-\\x7F]+', '', 'g'), '[^A-Za-z0-9]+', ' ', 'g'), '\\s+', ' ', 'g' ), ' ' ), '' ) ), ' ' ), '\\s+', ' ', 'g' ), ' ' ), '' ), ' ' ) ), CAST(0 AS TINYINT) ) = CAST(1 AS TINYINT) ) THEN NULL ELSE t4.first_name END AS first_name, t4.middle_name AS middle_name, t4.last_name AS last_name, t4.suffix AS suffix, t4.nickname AS nickname FROM t4 ), t6 AS ( SELECT t5.id AS id, t5.prefix AS prefix, t5.first_name AS first_name, t5.middle_name AS middle_name, t5.last_name AS last_name, t5.suffix AS suffix, t5.nickname AS nickname, STR_SPLIT(t5.prefix, ' ') AS prefix_tokens, STR_SPLIT(t5.first_name, ' ') AS first_name_tokens, STR_SPLIT(t5.middle_name, ' ') AS middle_name_tokens, STR_SPLIT(t5.last_name, ' ') AS last_name_tokens, STR_SPLIT(t5.suffix, ' ') AS suffix_tokens, STR_SPLIT(t5.nickname, ' ') AS nickname_tokens FROM t5 ), t7 AS ( SELECT t6.id AS id, t6.prefix AS prefix, t6.first_name AS first_name, t6.middle_name AS middle_name, t6.last_name AS last_name, t6.suffix AS suffix, t6.nickname AS nickname, t6.prefix_tokens AS prefix_tokens, t6.first_name_tokens AS first_name_tokens, t6.middle_name_tokens AS middle_name_tokens, t6.last_name_tokens AS last_name_tokens, t6.suffix_tokens AS suffix_tokens, t6.nickname_tokens AS nickname_tokens, CASE WHEN ( ARRAY_LENGTH(t6.prefix_tokens) = CAST(1 AS TINYINT) ) THEN UPPER(t6.prefix) ELSE NULL END AS prefix_single, CASE WHEN ( ARRAY_LENGTH(t6.first_name_tokens) = CAST(1 AS TINYINT) ) THEN UPPER(t6.first_name) ELSE NULL END AS first_name_single, CASE WHEN ( ARRAY_LENGTH(t6.middle_name_tokens) = CAST(1 AS TINYINT) ) THEN UPPER(t6.middle_name) ELSE NULL END AS middle_name_single, CASE WHEN ( ARRAY_LENGTH(t6.last_name_tokens) = CAST(1 AS TINYINT) ) THEN UPPER(t6.last_name) ELSE NULL END AS last_name_single, CASE WHEN ( ARRAY_LENGTH(t6.suffix_tokens) = CAST(1 AS TINYINT) ) THEN UPPER(t6.suffix) ELSE NULL END AS suffix_single, CASE WHEN ( ARRAY_LENGTH(t6.nickname_tokens) = CAST(1 AS TINYINT) ) THEN UPPER(t6.nickname) ELSE NULL END AS nickname_single FROM t6 ), t8 AS ( SELECT t7.id AS id, t7.prefix AS prefix, t7.first_name AS first_name, t7.middle_name AS middle_name, t7.last_name AS last_name, t7.suffix AS suffix, t7.nickname AS nickname, t7.prefix_tokens AS prefix_tokens, t7.first_name_tokens AS first_name_tokens, t7.middle_name_tokens AS middle_name_tokens, t7.last_name_tokens AS last_name_tokens, t7.suffix_tokens AS suffix_tokens, t7.nickname_tokens AS nickname_tokens, t7.prefix_single AS prefix_single, t7.first_name_single AS first_name_single, t7.middle_name_single AS middle_name_single, t7.last_name_single AS last_name_single, t7.suffix_single AS suffix_single, t7.nickname_single AS nickname_single, CAST([t7.first_name_single, t7.middle_name_single, t7.last_name_single, t7.suffix_single, t7.nickname_single] AS TEXT[]) AS singles_except_prefix, CAST([t7.prefix_single, t7.middle_name_single, t7.last_name_single, t7.suffix_single, t7.nickname_single] AS TEXT[]) AS singles_except_first_name, CAST([t7.prefix_single, t7.first_name_single, t7.last_name_single, t7.suffix_single, t7.nickname_single] AS TEXT[]) AS singles_except_middle_name, CAST([t7.prefix_single, t7.first_name_single, t7.middle_name_single, t7.suffix_single, t7.nickname_single] AS TEXT[]) AS singles_except_last_name, CAST([t7.prefix_single, t7.first_name_single, t7.middle_name_single, t7.last_name_single, t7.nickname_single] AS TEXT[]) AS singles_except_suffix, CAST([t7.prefix_single, t7.first_name_single, t7.middle_name_single, t7.last_name_single, t7.suffix_single] AS TEXT[]) AS singles_except_nickname FROM t7 ), t9 AS ( SELECT t8.id AS id, t8.prefix AS prefix, t8.first_name AS first_name, t8.middle_name AS middle_name, t8.last_name AS last_name, t8.suffix AS suffix, t8.nickname AS nickname, t8.prefix_tokens AS prefix_tokens, t8.first_name_tokens AS first_name_tokens, t8.middle_name_tokens AS middle_name_tokens, t8.last_name_tokens AS last_name_tokens, t8.suffix_tokens AS suffix_tokens, t8.nickname_tokens AS nickname_tokens, t8.prefix_single AS prefix_single, t8.first_name_single AS first_name_single, t8.middle_name_single AS middle_name_single, t8.last_name_single AS last_name_single, t8.suffix_single AS suffix_single, t8.nickname_single AS nickname_single, t8.singles_except_prefix AS singles_except_prefix, t8.singles_except_first_name AS singles_except_first_name, t8.singles_except_middle_name AS singles_except_middle_name, t8.singles_except_last_name AS singles_except_last_name, t8.singles_except_suffix AS singles_except_suffix, t8.singles_except_nickname AS singles_except_nickname, LIST_FILTER( t8.prefix_tokens, __ibis_param_token__ -> NOT ARRAY_CONTAINS(t8.singles_except_prefix, UPPER(__ibis_param_token__)) ) AS prefix_tokens_filtered, LIST_FILTER( t8.first_name_tokens, __ibis_param_token__ -> NOT ARRAY_CONTAINS(t8.singles_except_first_name, UPPER(__ibis_param_token__)) ) AS first_name_tokens_filtered, LIST_FILTER( t8.middle_name_tokens, __ibis_param_token__ -> NOT ARRAY_CONTAINS(t8.singles_except_middle_name, UPPER(__ibis_param_token__)) ) AS middle_name_tokens_filtered, LIST_FILTER( t8.last_name_tokens, __ibis_param_token__ -> NOT ARRAY_CONTAINS(t8.singles_except_last_name, UPPER(__ibis_param_token__)) ) AS last_name_tokens_filtered, LIST_FILTER( t8.suffix_tokens, __ibis_param_token__ -> NOT ARRAY_CONTAINS(t8.singles_except_suffix, UPPER(__ibis_param_token__)) ) AS suffix_tokens_filtered, LIST_FILTER( t8.nickname_tokens, __ibis_param_token__ -> NOT ARRAY_CONTAINS(t8.singles_except_nickname, UPPER(__ibis_param_token__)) ) AS nickname_tokens_filtered FROM t8 ), t10 AS ( SELECT t9.id AS id, ARRAY_AGGR(t9.prefix_tokens_filtered, 'string_agg', ' ') AS prefix, ARRAY_AGGR(t9.first_name_tokens_filtered, 'string_agg', ' ') AS first_name, ARRAY_AGGR(t9.middle_name_tokens_filtered, 'string_agg', ' ') AS middle_name, ARRAY_AGGR(t9.last_name_tokens_filtered, 'string_agg', ' ') AS last_name, ARRAY_AGGR(t9.suffix_tokens_filtered, 'string_agg', ' ') AS suffix, ARRAY_AGGR(t9.nickname_tokens_filtered, 'string_agg', ' ') AS nickname, t9.prefix_tokens AS prefix_tokens, t9.first_name_tokens AS first_name_tokens, t9.middle_name_tokens AS middle_name_tokens, t9.last_name_tokens AS last_name_tokens, t9.suffix_tokens AS suffix_tokens, t9.nickname_tokens AS nickname_tokens, t9.prefix_single AS prefix_single, t9.first_name_single AS first_name_single, t9.middle_name_single AS middle_name_single, t9.last_name_single AS last_name_single, t9.suffix_single AS suffix_single, t9.nickname_single AS nickname_single, t9.singles_except_prefix AS singles_except_prefix, t9.singles_except_first_name AS singles_except_first_name, t9.singles_except_middle_name AS singles_except_middle_name, t9.singles_except_last_name AS singles_except_last_name, t9.singles_except_suffix AS singles_except_suffix, t9.singles_except_nickname AS singles_except_nickname, t9.prefix_tokens_filtered AS prefix_tokens_filtered, t9.first_name_tokens_filtered AS first_name_tokens_filtered, t9.middle_name_tokens_filtered AS middle_name_tokens_filtered, t9.last_name_tokens_filtered AS last_name_tokens_filtered, t9.suffix_tokens_filtered AS suffix_tokens_filtered, t9.nickname_tokens_filtered AS nickname_tokens_filtered FROM t9 ), t11 AS ( SELECT t10.id AS id, t10.prefix AS prefix, t10.first_name AS first_name, t10.middle_name AS middle_name, t10.last_name AS last_name, t10.suffix AS suffix, t10.nickname AS nickname FROM t10 ), t12 AS ( SELECT t11.id AS id, TRIM( REGEXP_REPLACE( REGEXP_REPLACE( REGEXP_REPLACE( REGEXP_REPLACE( ARRAY_AGGR( LIST_APPLY( STR_SPLIT(REGEXP_REPLACE(t11.prefix, '[^a-zA-Z \\-'']', '', 'g'), ' '), __ibis_param_t__ -> CASE WHEN ( LENGTH(REGEXP_REPLACE(__ibis_param_t__, '[^A-Z]', '', 'g')) >= CAST(2 AS TINYINT) AND LENGTH(REGEXP_REPLACE(__ibis_param_t__, '[^a-z]', '', 'g')) >= CAST(1 AS TINYINT) OR LENGTH(REGEXP_REPLACE(__ibis_param_t__, '[^A-Z]', '', 'g')) >= CAST(1 AS TINYINT) AND REGEXP_MATCHES(__ibis_param_t__, '[a-z]') ) THEN __ibis_param_t__ ELSE CONCAT(UPPER(SUBSTR(__ibis_param_t__, 1, 1)), LOWER(SUBSTR(__ibis_param_t__, 2))) END ), 'string_agg', ' ' ), '\\s+', ' ', 'g' ), '(\\W) (\\W)', '\\1\\2', 'g' ), '(\\w) (\\W)', '\\1\\2', 'g' ), '(\\W) (\\w)', '\\1\\2', 'g' ), ' ' ) AS prefix, TRIM( REGEXP_REPLACE( REGEXP_REPLACE( REGEXP_REPLACE( REGEXP_REPLACE( ARRAY_AGGR( LIST_APPLY( STR_SPLIT(REGEXP_REPLACE(t11.first_name, '[^a-zA-Z \\-'']', '', 'g'), ' '), __ibis_param_t__ -> CASE WHEN ( LENGTH(REGEXP_REPLACE(__ibis_param_t__, '[^A-Z]', '', 'g')) >= CAST(2 AS TINYINT) AND LENGTH(REGEXP_REPLACE(__ibis_param_t__, '[^a-z]', '', 'g')) >= CAST(1 AS TINYINT) OR LENGTH(REGEXP_REPLACE(__ibis_param_t__, '[^A-Z]', '', 'g')) >= CAST(1 AS TINYINT) AND REGEXP_MATCHES(__ibis_param_t__, '[a-z]') ) THEN __ibis_param_t__ ELSE CONCAT(UPPER(SUBSTR(__ibis_param_t__, 1, 1)), LOWER(SUBSTR(__ibis_param_t__, 2))) END ), 'string_agg', ' ' ), '\\s+', ' ', 'g' ), '(\\W) (\\W)', '\\1\\2', 'g' ), '(\\w) (\\W)', '\\1\\2', 'g' ), '(\\W) (\\w)', '\\1\\2', 'g' ), ' ' ) AS first_name, TRIM( REGEXP_REPLACE( REGEXP_REPLACE( REGEXP_REPLACE( REGEXP_REPLACE( ARRAY_AGGR( LIST_APPLY( STR_SPLIT(REGEXP_REPLACE(t11.middle_name, '[^a-zA-Z \\-'']', '', 'g'), ' '), __ibis_param_t__ -> CASE WHEN ( LENGTH(REGEXP_REPLACE(__ibis_param_t__, '[^A-Z]', '', 'g')) >= CAST(2 AS TINYINT) AND LENGTH(REGEXP_REPLACE(__ibis_param_t__, '[^a-z]', '', 'g')) >= CAST(1 AS TINYINT) OR LENGTH(REGEXP_REPLACE(__ibis_param_t__, '[^A-Z]', '', 'g')) >= CAST(1 AS TINYINT) AND REGEXP_MATCHES(__ibis_param_t__, '[a-z]') ) THEN __ibis_param_t__ ELSE CONCAT(UPPER(SUBSTR(__ibis_param_t__, 1, 1)), LOWER(SUBSTR(__ibis_param_t__, 2))) END ), 'string_agg', ' ' ), '\\s+', ' ', 'g' ), '(\\W) (\\W)', '\\1\\2', 'g' ), '(\\w) (\\W)', '\\1\\2', 'g' ), '(\\W) (\\w)', '\\1\\2', 'g' ), ' ' ) AS middle_name, TRIM( REGEXP_REPLACE( REGEXP_REPLACE( REGEXP_REPLACE( REGEXP_REPLACE( ARRAY_AGGR( LIST_APPLY( STR_SPLIT(REGEXP_REPLACE(t11.last_name, '[^a-zA-Z \\-'']', '', 'g'), ' '), __ibis_param_t__ -> CASE WHEN ( LENGTH(REGEXP_REPLACE(__ibis_param_t__, '[^A-Z]', '', 'g')) >= CAST(2 AS TINYINT) AND LENGTH(REGEXP_REPLACE(__ibis_param_t__, '[^a-z]', '', 'g')) >= CAST(1 AS TINYINT) OR LENGTH(REGEXP_REPLACE(__ibis_param_t__, '[^A-Z]', '', 'g')) >= CAST(1 AS TINYINT) AND REGEXP_MATCHES(__ibis_param_t__, '[a-z]') ) THEN __ibis_param_t__ ELSE CONCAT(UPPER(SUBSTR(__ibis_param_t__, 1, 1)), LOWER(SUBSTR(__ibis_param_t__, 2))) END ), 'string_agg', ' ' ), '\\s+', ' ', 'g' ), '(\\W) (\\W)', '\\1\\2', 'g' ), '(\\w) (\\W)', '\\1\\2', 'g' ), '(\\W) (\\w)', '\\1\\2', 'g' ), ' ' ) AS last_name, TRIM( REGEXP_REPLACE( REGEXP_REPLACE( REGEXP_REPLACE( REGEXP_REPLACE( ARRAY_AGGR( LIST_APPLY( STR_SPLIT(REGEXP_REPLACE(t11.suffix, '[^a-zA-Z \\-'']', '', 'g'), ' '), __ibis_param_t__ -> CASE WHEN ( LENGTH(REGEXP_REPLACE(__ibis_param_t__, '[^A-Z]', '', 'g')) >= CAST(2 AS TINYINT) AND LENGTH(REGEXP_REPLACE(__ibis_param_t__, '[^a-z]', '', 'g')) >= CAST(1 AS TINYINT) OR LENGTH(REGEXP_REPLACE(__ibis_param_t__, '[^A-Z]', '', 'g')) >= CAST(1 AS TINYINT) AND REGEXP_MATCHES(__ibis_param_t__, '[a-z]') ) THEN __ibis_param_t__ ELSE CONCAT(UPPER(SUBSTR(__ibis_param_t__, 1, 1)), LOWER(SUBSTR(__ibis_param_t__, 2))) END ), 'string_agg', ' ' ), '\\s+', ' ', 'g' ), '(\\W) (\\W)', '\\1\\2', 'g' ), '(\\w) (\\W)', '\\1\\2', 'g' ), '(\\W) (\\w)', '\\1\\2', 'g' ), ' ' ) AS suffix, TRIM( REGEXP_REPLACE( REGEXP_REPLACE( REGEXP_REPLACE( REGEXP_REPLACE( ARRAY_AGGR( LIST_APPLY( STR_SPLIT(REGEXP_REPLACE(t11.nickname, '[^a-zA-Z \\-'']', '', 'g'), ' '), __ibis_param_t__ -> CASE WHEN ( LENGTH(REGEXP_REPLACE(__ibis_param_t__, '[^A-Z]', '', 'g')) >= CAST(2 AS TINYINT) AND LENGTH(REGEXP_REPLACE(__ibis_param_t__, '[^a-z]', '', 'g')) >= CAST(1 AS TINYINT) OR LENGTH(REGEXP_REPLACE(__ibis_param_t__, '[^A-Z]', '', 'g')) >= CAST(1 AS TINYINT) AND REGEXP_MATCHES(__ibis_param_t__, '[a-z]') ) THEN __ibis_param_t__ ELSE CONCAT(UPPER(SUBSTR(__ibis_param_t__, 1, 1)), LOWER(SUBSTR(__ibis_param_t__, 2))) END ), 'string_agg', ' ' ), '\\s+', ' ', 'g' ), '(\\W) (\\W)', '\\1\\2', 'g' ), '(\\w) (\\W)', '\\1\\2', 'g' ), '(\\W) (\\w)', '\\1\\2', 'g' ), ' ' ) AS nickname FROM t11 ) SELECT t13.id, t13.prefix, t13.first_name, CASE WHEN ( COALESCE(t13.nickname LIKE CONCAT(t13.middle_name, '%'), CAST(FALSE AS BOOLEAN)) AND NOT t13.first_name LIKE CONCAT(t13.middle_name, '%') ) THEN t13.nickname ELSE t13.middle_name END AS middle_name, t13.last_name, t13.suffix, t13.nickname FROM ( SELECT t12.id AS id, CASE WHEN ( UPPER(t12.prefix) = 'JR' ) THEN 'Jr' WHEN ( UPPER(t12.prefix) = 'SR' ) THEN 'Sr' WHEN ( UPPER(t12.prefix) = 'PHD' ) THEN 'PhD' WHEN ( UPPER(t12.prefix) = 'MR' ) THEN 'Mr' WHEN ( UPPER(t12.prefix) = 'MRS' ) THEN 'Mrs' WHEN ( UPPER(t12.prefix) = 'MS' ) THEN 'Ms' WHEN ( UPPER(t12.prefix) = 'DR' ) THEN 'Dr' ELSE UPPER(t12.prefix) END AS prefix, t12.first_name AS first_name, t12.middle_name AS middle_name, t12.last_name AS last_name, CASE WHEN ( UPPER(t12.suffix) = 'JR' ) THEN 'Jr' WHEN ( UPPER(t12.suffix) = 'SR' ) THEN 'Sr' WHEN ( UPPER(t12.suffix) = 'PHD' ) THEN 'PhD' WHEN ( UPPER(t12.suffix) = 'MR' ) THEN 'Mr' WHEN ( UPPER(t12.suffix) = 'MRS' ) THEN 'Mrs' WHEN ( UPPER(t12.suffix) = 'MS' ) THEN 'Ms' WHEN ( UPPER(t12.suffix) = 'DR' ) THEN 'Dr' ELSE UPPER(t12.suffix) END AS suffix, t12.nickname AS nickname FROM t12 ) AS t13