Skip to content

Commit 1fa7a93

Browse files
authored
Merge pull request #3051 from github/kaspersv/parse-quoted-ra-idents
Extend join order badness RA parser
2 parents 18d7fae + 053708a commit 1fa7a93

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

extensions/ql-vscode/src/log-insights/join-order.ts

+14-7
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,19 @@ function makeKey(
4040
const DEPENDENT_PREDICATES_REGEXP = (() => {
4141
const regexps = [
4242
// SCAN id
43-
String.raw`SCAN\s+([0-9a-zA-Z:#_]+)\s`,
43+
String.raw`SCAN\s+([0-9a-zA-Z:#_]+|\`[^\`\r\n]*\`)\s`,
4444
// JOIN id WITH id
45-
String.raw`JOIN\s+([0-9a-zA-Z:#_]+)\s+WITH\s+([0-9a-zA-Z:#_]+)\s`,
45+
String.raw`JOIN\s+([0-9a-zA-Z:#_]+|\`[^\`\r\n]*\`)\s+WITH\s+([0-9a-zA-Z:#_]+|\`[^\`\r\n]*\`)\s`,
4646
// AGGREGATE id, id
47-
String.raw`AGGREGATE\s+([0-9a-zA-Z:#_]+)\s*,\s+([0-9a-zA-Z:#_]+)`,
47+
String.raw`AGGREGATE\s+([0-9a-zA-Z:#_]+|\`[^\`\r\n]*\`)\s*,\s+([0-9a-zA-Z:#_]+|\`[^\`\r\n]*\`)`,
4848
// id AND NOT id
49-
String.raw`([0-9a-zA-Z:#_]+)\s+AND\s+NOT\s+([0-9a-zA-Z:#_]+)`,
49+
String.raw`([0-9a-zA-Z:#_]+|\`[^\`\r\n]*\`)\s+AND\s+NOT\s+([0-9a-zA-Z:#_]+|\`[^\`\r\n]*\`)`,
5050
// 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:#_<>]+)((?:,[0-9a-zA-Z:#_<>]+)*)>`,
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]*\`)*)>`,
5252
// SELECT id
53-
String.raw`SELECT\s+([0-9a-zA-Z:#_]+)`,
53+
String.raw`SELECT\s+([0-9a-zA-Z:#_]+|\`[^\`\r\n]*\`)`,
54+
// REWRITE id WITH
55+
String.raw`REWRITE\s+([0-9a-zA-Z:#_]+|\`[^\`\r\n]*\`)\s+WITH\s`,
5456
];
5557
return new RegExp(
5658
`${String.raw`\{[0-9]+\}\s+[0-9a-zA-Z]+\s=\s(?:` + regexps.join("|")})`,
@@ -65,7 +67,12 @@ function getDependentPredicates(operations: string[]): I.List<string> {
6567
.rest() // Skip the first group as it's just the entire string
6668
.filter((x) => !!x && !x.match("r[0-9]+|PRIMITIVE")) // Only keep the references to predicates.
6769
.flatMap((x) => x.split(",")) // Group 2 in the INVOKE HIGHER_ORDER RELATION case is a comma-separated list of identifiers.
68-
.filter((x) => !!x); // Remove empty strings
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
6976
} else {
7077
return I.List();
7178
}

0 commit comments

Comments
 (0)