summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/searchdefinition/processing/ReservedFunctionNames.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-09-18 13:38:38 -0700
committerGitHub <noreply@github.com>2018-09-18 13:38:38 -0700
commitb38fc011d4a5cdcdbdb5d71ca77252502957fa92 (patch)
treee5a20afb500270aac9e4476ab96d60329af99574 /config-model/src/main/java/com/yahoo/searchdefinition/processing/ReservedFunctionNames.java
parent04a2bea1982819f1e250dfc40b7fbff3fcfe303b (diff)
parent1c37f6a5646d991de68759f2312164799a89ccaa (diff)
Merge pull request #6992 from vespa-engine/bratseth/rank-type-information
Bratseth/rank type information
Diffstat (limited to 'config-model/src/main/java/com/yahoo/searchdefinition/processing/ReservedFunctionNames.java')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/processing/ReservedFunctionNames.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/ReservedFunctionNames.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/ReservedFunctionNames.java
new file mode 100644
index 00000000000..d7099215f17
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/processing/ReservedFunctionNames.java
@@ -0,0 +1,56 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.searchdefinition.processing;
+
+import com.google.common.collect.ImmutableSet;
+import com.yahoo.config.application.api.DeployLogger;
+import com.yahoo.searchdefinition.RankProfile;
+import com.yahoo.searchdefinition.RankProfileRegistry;
+import com.yahoo.searchdefinition.Search;
+import com.yahoo.searchlib.rankingexpression.parser.RankingExpressionParserConstants;
+import com.yahoo.vespa.model.container.search.QueryProfiles;
+
+import java.util.Set;
+import java.util.logging.Level;
+
+/**
+ * Issues a warning if some function has a reserved name. This is not necessarily
+ * an error, as a rank profile function can shadow a built-in function.
+ *
+ * @author lesters
+ */
+public class ReservedFunctionNames extends Processor {
+
+ private static Set<String> reservedNames = getReservedNames();
+
+ public ReservedFunctionNames(Search search, DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, QueryProfiles queryProfiles) {
+ super(search, deployLogger, rankProfileRegistry, queryProfiles);
+ }
+
+ @Override
+ public void process(boolean validate, boolean documentsOnly) {
+ if ( ! validate) return;
+ if (documentsOnly) return;
+
+ for (RankProfile rp : rankProfileRegistry.all()) {
+ for (String functionName : rp.getFunctions().keySet()) {
+ if (reservedNames.contains(functionName)) {
+ deployLogger.log(Level.WARNING, "Function '" + functionName + "' " +
+ "in rank profile '" + rp.getName() + "' " +
+ "has a reserved name. This might mean that the function shadows " +
+ "the built-in function with the same name."
+ );
+ }
+ }
+ }
+ }
+
+ private static ImmutableSet<String> getReservedNames() {
+ ImmutableSet.Builder<String> names = ImmutableSet.builder();
+ for (String token : RankingExpressionParserConstants.tokenImage) {
+ String tokenWithoutQuotes = token.substring(1, token.length()-1);
+ names.add(tokenWithoutQuotes);
+ }
+ return names.build();
+ }
+
+}