@@ -37,45 +37,49 @@ function makeKey(
3737 return `${ queryCausingWork } :${ predicate } ${ suffix ? ` ${ suffix } ` : "" } ` ;
3838}
3939
40- const DEPENDENT_PREDICATES_REGEXP = ( ( ) => {
40+ function getDependentPredicates ( operations : string [ ] ) : I . List < string > {
41+ const id = String . raw `[0-9a-zA-Z:#_\./]+` ;
42+ const idWithAngleBrackets = String . raw `[0-9a-zA-Z:#_<>\./]+` ;
43+ const quotedId = String . raw `\`[^\`\r\n]*\`` ;
4144 const regexps = [
4245 // SCAN id
43- String . raw `SCAN\s+([0-9a-zA-Z:#_]+|\`[^\`\r\n]*\` )\s` ,
46+ String . raw `SCAN\s+(${ id } | ${ quotedId } )\s` ,
4447 // JOIN id WITH id
45- String . raw `JOIN\s+([0-9a-zA-Z:#_]+|\`[^\`\r\n]*\`)\s+WITH\s+([0-9a-zA-Z:#_]+|\`[^\`\r\n]*\`)\s` ,
48+ String . raw `JOIN\s+(${ id } |${ quotedId } )\s+WITH\s+(${ id } |${ quotedId } )\s` ,
49+ // JOIN WITH id
50+ String . raw `JOIN\s+WITH\s+(${ id } |${ quotedId } )\s` ,
4651 // AGGREGATE id, id
47- String . raw `AGGREGATE\s+([0-9a-zA-Z:#_]+|\`[^\`\r\n]*\` )\s*,\s+([0-9a-zA-Z:#_]+|\`[^\`\r\n]*\` )` ,
52+ String . raw `AGGREGATE\s+(${ id } | ${ quotedId } )\s*,\s+(${ id } | ${ quotedId } )` ,
4853 // id AND NOT id
49- String . raw `([0-9a-zA-Z:#_]+|\`[^\`\r\n]*\`)\s+AND\s+NOT\s+([0-9a-zA-Z:#_]+|\`[^\`\r\n]*\`)` ,
54+ String . raw `(${ id } |${ quotedId } )\s+AND\s+NOT\s+(${ id } |${ quotedId } )` ,
55+ // AND NOT id
56+ String . raw `AND\s+NOT\s+(${ id } |${ quotedId } )` ,
5057 // INVOKE HIGHER-ORDER RELATION rel ON <id, ..., id>
51- String . raw `INVOKE\s+HIGHER-ORDER\s+RELATION\s[^\s]+\sON\s+<([0-9a-zA-Z:#_<>]+|\`[^\`\r\n]*\` )((?:,[0-9a-zA-Z:#_<>]+|,\`[^\`\r\n]*\` )*)>` ,
58+ String . raw `INVOKE\s+HIGHER-ORDER\s+RELATION\s[^\s]+\sON\s+<(${ idWithAngleBrackets } | ${ quotedId } )((?:,${ idWithAngleBrackets } |, ${ quotedId } )*)>` ,
5259 // SELECT id
53- String . raw `SELECT\s+([0-9a-zA-Z:#_]+|\`[^\`\r\n]*\` )` ,
60+ String . raw `SELECT\s+(${ id } | ${ quotedId } )` ,
5461 // REWRITE id WITH
55- String . raw `REWRITE\s+([0-9a-zA-Z:#_]+|\`[^\`\r\n]*\`)\s+WITH\s` ,
62+ String . raw `REWRITE\s+(${ id } |${ quotedId } )\s+WITH\s` ,
63+ // id UNION id UNION ... UNION id
64+ String . raw `(${ id } |${ quotedId } )((?:\s+UNION\s+${ id } |${ quotedId } )+)` ,
5665 ] ;
57- return new RegExp (
58- `${ String . raw `\{[0-9]+\}\s+[0-9a-zA-Z]+\s=\s(?:` + regexps . join ( "|" ) } )` ,
66+ const r = new RegExp (
67+ `${
68+ String . raw `\{[0-9]+\}\s+(?:[0-9a-zA-Z]+\s=|\|)\s(?:` + regexps . join ( "|" )
69+ } )`,
5970 ) ;
60- } ) ( ) ;
61-
62- function getDependentPredicates ( operations : string [ ] ) : I . List < string > {
6371 return I . List ( operations ) . flatMap ( ( operation ) => {
64- const matches = DEPENDENT_PREDICATES_REGEXP . exec ( operation . trim ( ) ) ;
65- if ( matches !== null ) {
66- return I . List ( matches )
67- . rest ( ) // Skip the first group as it's just the entire string
68- . filter ( ( x ) => ! ! x && ! x . match ( "r[0-9]+|PRIMITIVE" ) ) // Only keep the references to predicates.
69- . flatMap ( ( x ) => x . split ( "," ) ) // Group 2 in the INVOKE HIGHER_ORDER RELATION case is a comma-separated list of identifiers.
70- . filter ( ( x ) => ! ! x ) // Remove empty strings
71- . map ( ( x ) =>
72- x . startsWith ( "`" ) && x . endsWith ( "`" )
73- ? x . substring ( 1 , x . length - 1 )
74- : x ,
75- ) ; // Remove quotes from quoted identifiers
76- } else {
77- return I . List ( ) ;
78- }
72+ const matches = r . exec ( operation . trim ( ) ) || [ ] ;
73+ return I . List ( matches )
74+ . rest ( ) // Skip the first group as it's just the entire string
75+ . filter ( ( x ) => ! ! x )
76+ . flatMap ( ( x ) => x . split ( "," ) ) // Group 2 in the INVOKE HIGHER_ORDER RELATION case is a comma-separated list of identifiers.
77+ . flatMap ( ( x ) => x . split ( " UNION " ) ) // Split n-ary unions into individual arguments.
78+ . filter ( ( x ) => ! x . match ( "r[0-9]+|PRIMITIVE" ) ) // Only keep the references to predicates.
79+ . filter ( ( x ) => ! ! x ) // Remove empty strings
80+ . map ( ( x ) =>
81+ x . startsWith ( "`" ) && x . endsWith ( "`" ) ? x . substring ( 1 , x . length - 1 ) : x ,
82+ ) ; // Remove quotes from quoted identifiers
7983 } ) ;
8084}
8185
0 commit comments