Skip to content
Snippets Groups Projects
Unverified Commit 9562f33d authored by Tom Robinson's avatar Tom Robinson Committed by GitHub
Browse files

Check regexextract driver features (#12111)

* Check regexextract driver features. Resolves #12074

* Fix unit test
parent fb1ed0de
Branches
Tags
No related merge requests found
......@@ -144,6 +144,7 @@ export const MBQL_CLAUSES = {
displayName: t`regexextract`,
type: "string",
args: ["string", "string"],
requiredFeatures: ["regex"],
},
concat: {
displayName: t`concat`,
......
......@@ -54,15 +54,15 @@ import {
EXPRESSION_TYPES,
} from "./config";
const FUNCTION_SUGGESTIONS_BY_TYPE = {};
const OPERATOR_SUGGESTIONS_BY_TYPE = {};
const FUNCTIONS_BY_TYPE = {};
const OPERATORS_BY_TYPE = {};
for (const type of EXPRESSION_TYPES) {
FUNCTION_SUGGESTIONS_BY_TYPE[type] = Array.from(FUNCTIONS)
FUNCTIONS_BY_TYPE[type] = Array.from(FUNCTIONS)
.filter(name => isExpressionType(MBQL_CLAUSES[name].type, type))
.map(name => functionSuggestion("functions", name));
OPERATOR_SUGGESTIONS_BY_TYPE[type] = Array.from(OPERATORS)
.map(name => MBQL_CLAUSES[name]);
OPERATORS_BY_TYPE[type] = Array.from(OPERATORS)
.filter(name => isExpressionType(MBQL_CLAUSES[name].type, type))
.map(name => operatorSuggestion(name));
.map(name => MBQL_CLAUSES[name]);
}
export function suggest({
......@@ -98,13 +98,6 @@ export function suggest({
partialSuggestionMode = true;
}
let finalSuggestions = [];
const syntacticSuggestions = parserWithRecovery.computeContentAssist(
startRule,
tokenVector,
);
const context = getContext({
cst,
tokenVector,
......@@ -118,6 +111,13 @@ export function suggest({
}
const { expectedType } = context;
let finalSuggestions = [];
const syntacticSuggestions = parserWithRecovery.computeContentAssist(
startRule,
tokenVector,
);
for (const suggestion of syntacticSuggestions) {
const { nextTokenType, ruleStack } = suggestion;
......@@ -235,6 +235,7 @@ export function suggest({
isTokenType(nextTokenType, FunctionName) ||
nextTokenType === Case
) {
let functions = [];
if (isExpressionType(expectedType, "aggregation")) {
// special case for aggregation
finalSuggestions.push(
......@@ -249,10 +250,20 @@ export function suggest({
),
),
);
finalSuggestions.push(...FUNCTION_SUGGESTIONS_BY_TYPE["number"]);
functions = FUNCTIONS_BY_TYPE["number"];
} else {
finalSuggestions.push(...FUNCTION_SUGGESTIONS_BY_TYPE[expectedType]);
functions = FUNCTIONS_BY_TYPE[expectedType];
}
const database = query.database();
finalSuggestions.push(
...functions
.filter(
clause =>
!clause.requiredFeatures ||
clause.requiredFeatures.every(f => database.hasFeature(f)),
)
.map(clause => functionSuggestion("functions", clause.name)),
);
} else if (nextTokenType === LParen) {
finalSuggestions.push({
type: "other",
......
......@@ -102,7 +102,8 @@
"right-join",
"left-join",
"inner-join",
"nested-queries"
"nested-queries",
"regex"
],
"name": "Sample Dataset",
"caveats": null,
......
......@@ -34,6 +34,9 @@ const STRING_FUNCTIONS = [
{ text: "trim(", type: "functions" },
{ text: "upper(", type: "functions" },
];
const STRING_FUNCTIONS_EXCLUDING_REGEX = STRING_FUNCTIONS.filter(
({ text }) => text !== "regexextract(",
);
// const EXPRESSION_FUNCTIONS = [
// { text: "case(", type: "functions" },
// { text: "coalesce(", type: "functions" },
......@@ -136,7 +139,7 @@ describe("metabase/lib/expression/suggest", () => {
...FIELDS_CUSTOM,
...FIELDS_CUSTOM_NON_NUMERIC,
{ type: "functions", text: "coalesce(" },
...STRING_FUNCTIONS,
...STRING_FUNCTIONS_EXCLUDING_REGEX,
OPEN_PAREN,
]);
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment