aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/grouping/request
diff options
context:
space:
mode:
authorGeir Storli <geirst@oath.com>2018-09-07 11:53:25 +0000
committerGeir Storli <geirst@oath.com>2018-09-10 12:18:49 +0000
commit2b799d684ffc9129f51025d2b835e2b1f587a7b8 (patch)
tree256321ceb53cf44f4d33ca789c36ba321574c0f1 /container-search/src/main/java/com/yahoo/search/grouping/request
parente3d76a10ea55c9e195bb19fd7c67a760b23a15c4 (diff)
Extend grouping parser to handle map syntax with indirect key via attribute vector.
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/grouping/request')
-rw-r--r--container-search/src/main/java/com/yahoo/search/grouping/request/AttributeMapLookupValue.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/grouping/request/AttributeMapLookupValue.java b/container-search/src/main/java/com/yahoo/search/grouping/request/AttributeMapLookupValue.java
new file mode 100644
index 00000000000..fb9702cc1cc
--- /dev/null
+++ b/container-search/src/main/java/com/yahoo/search/grouping/request/AttributeMapLookupValue.java
@@ -0,0 +1,57 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.search.grouping.request;
+
+/**
+ * This class represents a lookup in a map attribute in a {@link GroupingExpression}.
+ *
+ * It evaluates to the value found using the given key for the lookup in that attribute.
+ * The key is either specified explicitly or found via a key source attribute.
+ *
+ * @author geirst
+ */
+public class AttributeMapLookupValue extends AttributeValue {
+
+ private final String prefix;
+ private final String suffix;
+ private final String key;
+ private final String keySourceAttribute;
+
+ private AttributeMapLookupValue(String attributeValue, String prefix, String suffix, String key, String keySourceAttribute) {
+ super(attributeValue);
+ this.prefix = prefix;
+ this.suffix = suffix;
+ this.key = key;
+ this.keySourceAttribute = keySourceAttribute;
+ }
+
+ public static AttributeMapLookupValue fromKey(String prefix, String key, String suffix) {
+ return new AttributeMapLookupValue(prefix + "{\"" + key + "\"}" + suffix,
+ prefix, suffix, key, "");
+ }
+
+ public static AttributeMapLookupValue fromKeySourceAttribute(String prefix, String keySourceAttribute, String suffix) {
+ return new AttributeMapLookupValue(prefix + "{attribute(" + keySourceAttribute + ")}" + suffix,
+ prefix, suffix, "", keySourceAttribute);
+ }
+
+ @Override
+ public AttributeMapLookupValue copy() {
+ return new AttributeMapLookupValue(getAttributeName(), prefix, suffix, key, keySourceAttribute);
+ }
+
+ public String getKeyAttribute() {
+ return prefix + ".key";
+ }
+
+ public String getValueAttribute() {
+ return prefix + ".value" + suffix;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public String getKeySourceAttribute() {
+ return keySourceAttribute;
+ }
+}