lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject [15/58] [abbrv] lucene-solr:jira/solr-10879: SOLR-10123: Upgraded the Analytics Component to version 2.0
Date Mon, 03 Jul 2017 11:57:55 GMT
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d5963beb/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FillMissingFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FillMissingFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FillMissingFunction.java
new file mode 100644
index 0000000..188d698
--- /dev/null
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FillMissingFunction.java
@@ -0,0 +1,842 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.function.Consumer;
+import java.util.function.DoubleConsumer;
+import java.util.function.IntConsumer;
+import java.util.function.LongConsumer;
+
+import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;
+import org.apache.solr.analytics.util.function.BooleanConsumer;
+import org.apache.solr.analytics.util.function.FloatConsumer;
+import org.apache.solr.analytics.value.AnalyticsValue;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.BooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream;
+import org.apache.solr.analytics.value.DateValue;
+import org.apache.solr.analytics.value.DateValueStream;
+import org.apache.solr.analytics.value.DoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream;
+import org.apache.solr.analytics.value.FloatValue;
+import org.apache.solr.analytics.value.FloatValueStream;
+import org.apache.solr.analytics.value.IntValue;
+import org.apache.solr.analytics.value.IntValueStream;
+import org.apache.solr.analytics.value.LongValue;
+import org.apache.solr.analytics.value.LongValueStream;
+import org.apache.solr.analytics.value.StringValue;
+import org.apache.solr.analytics.value.StringValueStream;
+import org.apache.solr.analytics.value.AnalyticsValue.AbstractAnalyticsValue;
+import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;
+import org.apache.solr.analytics.value.DateValue.AbstractDateValue;
+import org.apache.solr.analytics.value.DateValueStream.AbstractDateValueStream;
+import org.apache.solr.analytics.value.DoubleValue.AbstractDoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream.AbstractDoubleValueStream;
+import org.apache.solr.analytics.value.FloatValue.AbstractFloatValue;
+import org.apache.solr.analytics.value.FloatValueStream.AbstractFloatValueStream;
+import org.apache.solr.analytics.value.IntValue.AbstractIntValue;
+import org.apache.solr.analytics.value.IntValueStream.AbstractIntValueStream;
+import org.apache.solr.analytics.value.LongValue.AbstractLongValue;
+import org.apache.solr.analytics.value.LongValueStream.AbstractLongValueStream;
+import org.apache.solr.analytics.value.StringValue.AbstractStringValue;
+import org.apache.solr.analytics.value.StringValueStream.AbstractStringValueStream;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.SolrException.ErrorCode;
+
+/**
+ * A mapping function to fill all non-existing values with a given value. 
+ * <p>
+ * Uses:
+ * <ul>
+ * <li>If two Values are passed in, a Value mimicking the first parameter with the second parameter used as filler will be returned.
+ * <li>If two ValueStreams are passed in, a ValueStream mimicking the first parameter with the second parameter used as filler will be returned.
+ * </ul>
+ * <p>
+ * The resulting Value or ValueStream will be typed with the closest super-type of the two parameters.
+ * (e.g. {@value #name}(double,int) will return a double)
+ */
+public class FillMissingFunction {
+  public static final String name = "fillmissing";
+
+  public static final CreatorFunction creatorFunction = (params -> {
+    if (params.length != 2) {
+      throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 2 paramaters, " + params.length + " found.");
+    }
+
+    AnalyticsValueStream baseExpr = params[0];
+    AnalyticsValueStream fillExpr = params[1];
+    if (baseExpr instanceof DateValue && fillExpr instanceof DateValue) {
+      return new DateFillMissingFunction((DateValue)baseExpr,(DateValue)fillExpr);
+    }
+    if (baseExpr instanceof DateValueStream && fillExpr instanceof DateValueStream) {
+      return new DateStreamFillMissingFunction((DateValueStream)baseExpr,(DateValueStream)fillExpr);
+    }
+    if (baseExpr instanceof BooleanValue && fillExpr instanceof BooleanValue) {
+      return new BooleanFillMissingFunction((BooleanValue)baseExpr,(BooleanValue)fillExpr);
+    }
+    if (baseExpr instanceof BooleanValueStream && fillExpr instanceof BooleanValueStream) {
+      return new BooleanStreamFillMissingFunction((BooleanValueStream)baseExpr,(BooleanValueStream)fillExpr);
+    }
+    if (baseExpr instanceof IntValue && fillExpr instanceof IntValue) {
+      return new IntFillMissingFunction((IntValue)baseExpr,(IntValue)fillExpr);
+    }
+    if (baseExpr instanceof IntValueStream && fillExpr instanceof IntValueStream) {
+      return new IntStreamFillMissingFunction((IntValueStream)baseExpr,(IntValueStream)fillExpr);
+    }
+    if (baseExpr instanceof LongValue && fillExpr instanceof LongValue) {
+      return new LongFillMissingFunction((LongValue)baseExpr,(LongValue)fillExpr);
+    }
+    if (baseExpr instanceof LongValueStream && fillExpr instanceof LongValueStream) {
+      return new LongStreamFillMissingFunction((LongValueStream)baseExpr,(LongValueStream)fillExpr);
+    }
+    if (baseExpr instanceof FloatValue && fillExpr instanceof FloatValue) {
+      return new FloatFillMissingFunction((FloatValue)baseExpr,(FloatValue)fillExpr);
+    }
+    if (baseExpr instanceof FloatValueStream && fillExpr instanceof FloatValueStream) {
+      return new FloatStreamFillMissingFunction((FloatValueStream)baseExpr,(FloatValueStream)fillExpr);
+    }
+    if (baseExpr instanceof DoubleValue && fillExpr instanceof DoubleValue) {
+      return new DoubleFillMissingFunction((DoubleValue)baseExpr,(DoubleValue)fillExpr);
+    }
+    if (baseExpr instanceof DoubleValueStream && fillExpr instanceof DoubleValueStream) {
+      return new DoubleStreamFillMissingFunction((DoubleValueStream)baseExpr,(DoubleValueStream)fillExpr);
+    }
+    if (baseExpr instanceof StringValue && fillExpr instanceof StringValue) {
+      return new StringFillMissingFunction((StringValue)baseExpr,(StringValue)fillExpr);
+    }
+    if (baseExpr instanceof StringValueStream && fillExpr instanceof StringValueStream) {
+      return new StringStreamFillMissingFunction((StringValueStream)baseExpr,(StringValueStream)fillExpr);
+    }
+    if (baseExpr instanceof AnalyticsValue && fillExpr instanceof AnalyticsValue) {
+      return new ValueFillMissingFunction((AnalyticsValue)baseExpr,(AnalyticsValue)fillExpr);
+    }
+    return new StreamFillMissingFunction(baseExpr,fillExpr);
+  });
+}
+class StreamFillMissingFunction implements AnalyticsValueStream, Consumer<Object> {
+  private final AnalyticsValueStream baseExpr;
+  private final AnalyticsValueStream fillExpr;
+  public static final String name = FillMissingFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public StreamFillMissingFunction(AnalyticsValueStream baseExpr, AnalyticsValueStream fillExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.fillExpr = fillExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
+  }
+
+  boolean exists = false;
+  Consumer<Object> cons;
+
+  @Override
+  public void streamObjects(Consumer<Object> cons) {
+    exists = false;
+    this.cons = cons;
+    baseExpr.streamObjects(this);
+    if (!exists) {
+      fillExpr.streamObjects(cons);
+    }
+  }
+  @Override
+  public void accept(Object value) {
+    exists = true;
+    cons.accept(value);
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class ValueFillMissingFunction extends AbstractAnalyticsValue {
+  private final AnalyticsValue baseExpr;
+  private final AnalyticsValue fillExpr;
+  public static final String name = FillMissingFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public ValueFillMissingFunction(AnalyticsValue baseExpr, AnalyticsValue fillExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.fillExpr = fillExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
+  }
+  
+  boolean exists = false;
+
+  @Override
+  public Object getObject() {
+    Object value = baseExpr.getObject();
+    exists = true;
+    if (!baseExpr.exists()) {
+      value = fillExpr.getObject();
+      exists = fillExpr.exists();
+    }
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class BooleanStreamFillMissingFunction extends AbstractBooleanValueStream implements BooleanConsumer {
+  private final BooleanValueStream baseExpr;
+  private final BooleanValueStream fillExpr;
+  public static final String name = FillMissingFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public BooleanStreamFillMissingFunction(BooleanValueStream baseExpr, BooleanValueStream fillExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.fillExpr = fillExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
+  }
+
+  boolean exists = false;
+  BooleanConsumer cons;
+
+  @Override
+  public void streamBooleans(BooleanConsumer cons) {
+    exists = false;
+    this.cons = cons;
+    baseExpr.streamBooleans(this);
+    if (!exists) {
+      fillExpr.streamBooleans(cons);
+    }
+  }
+  @Override
+  public void accept(boolean value) {
+    exists = true;
+    cons.accept(value);
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class BooleanFillMissingFunction extends AbstractBooleanValue {
+  private final BooleanValue baseExpr;
+  private final BooleanValue fillExpr;
+  public static final String name = FillMissingFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public BooleanFillMissingFunction(BooleanValue baseExpr, BooleanValue fillExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.fillExpr = fillExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
+  }
+  
+  boolean exists = false;
+
+  @Override
+  public boolean getBoolean() {
+    boolean value = baseExpr.getBoolean();
+    exists = true;
+    if (!baseExpr.exists()) {
+      value = fillExpr.getBoolean();
+      exists = fillExpr.exists();
+    }
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class IntStreamFillMissingFunction extends AbstractIntValueStream implements IntConsumer {
+  private final IntValueStream baseExpr;
+  private final IntValueStream fillExpr;
+  public static final String name = FillMissingFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public IntStreamFillMissingFunction(IntValueStream baseExpr, IntValueStream fillExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.fillExpr = fillExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
+  }
+
+  boolean exists = false;
+  IntConsumer cons;
+
+  @Override
+  public void streamInts(IntConsumer cons) {
+    exists = false;
+    this.cons = cons;
+    baseExpr.streamInts(this);
+    if (!exists) {
+      fillExpr.streamInts(cons);
+    }
+  }
+  @Override
+  public void accept(int value) {
+    exists = true;
+    cons.accept(value);
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class IntFillMissingFunction extends AbstractIntValue {
+  private final IntValue baseExpr;
+  private final IntValue fillExpr;
+  public static final String name = FillMissingFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public IntFillMissingFunction(IntValue baseExpr, IntValue fillExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.fillExpr = fillExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
+  }
+  
+  boolean exists = false;
+
+  @Override
+  public int getInt() {
+    int value = baseExpr.getInt();
+    exists = true;
+    if (!baseExpr.exists()) {
+      value = fillExpr.getInt();
+      exists = fillExpr.exists();
+    }
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class LongStreamFillMissingFunction extends AbstractLongValueStream implements LongConsumer {
+  private final LongValueStream baseExpr;
+  private final LongValueStream fillExpr;
+  public static final String name = FillMissingFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public LongStreamFillMissingFunction(LongValueStream baseExpr, LongValueStream fillExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.fillExpr = fillExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
+  }
+
+  boolean exists = false;
+  LongConsumer cons;
+
+  @Override
+  public void streamLongs(LongConsumer cons) {
+    exists = false;
+    this.cons = cons;
+    baseExpr.streamLongs(this);
+    if (!exists) {
+      fillExpr.streamLongs(cons);
+    }
+  }
+  @Override
+  public void accept(long value) {
+    exists = true;
+    cons.accept(value);
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class LongFillMissingFunction extends AbstractLongValue {
+  private final LongValue baseExpr;
+  private final LongValue fillExpr;
+  public static final String name = FillMissingFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public LongFillMissingFunction(LongValue baseExpr, LongValue fillExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.fillExpr = fillExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
+  }
+  
+  boolean exists = false;
+
+  @Override
+  public long getLong() {
+    long value = baseExpr.getLong();
+    exists = true;
+    if (!baseExpr.exists()) {
+      value = fillExpr.getLong();
+      exists = fillExpr.exists();
+    }
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class FloatStreamFillMissingFunction extends AbstractFloatValueStream implements FloatConsumer {
+  private final FloatValueStream baseExpr;
+  private final FloatValueStream fillExpr;
+  public static final String name = FillMissingFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public FloatStreamFillMissingFunction(FloatValueStream baseExpr, FloatValueStream fillExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.fillExpr = fillExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
+  }
+
+  boolean exists = false;
+  FloatConsumer cons;
+
+  @Override
+  public void streamFloats(FloatConsumer cons) {
+    exists = false;
+    this.cons = cons;
+    baseExpr.streamFloats(this);
+    if (!exists) {
+      fillExpr.streamFloats(cons);
+    }
+  }
+  @Override
+  public void accept(float value) {
+    exists = true;
+    cons.accept(value);
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class FloatFillMissingFunction extends AbstractFloatValue {
+  private final FloatValue baseExpr;
+  private final FloatValue fillExpr;
+  public static final String name = FillMissingFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public FloatFillMissingFunction(FloatValue baseExpr, FloatValue fillExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.fillExpr = fillExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
+  }
+  
+  boolean exists = false;
+
+  @Override
+  public float getFloat() {
+    float value = baseExpr.getFloat();
+    exists = true;
+    if (!baseExpr.exists()) {
+      value = fillExpr.getFloat();
+      exists = fillExpr.exists();
+    }
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class DoubleStreamFillMissingFunction extends AbstractDoubleValueStream implements DoubleConsumer {
+  private final DoubleValueStream baseExpr;
+  private final DoubleValueStream fillExpr;
+  public static final String name = FillMissingFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public DoubleStreamFillMissingFunction(DoubleValueStream baseExpr, DoubleValueStream fillExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.fillExpr = fillExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
+  }
+
+  boolean exists = false;
+  DoubleConsumer cons;
+
+  @Override
+  public void streamDoubles(DoubleConsumer cons) {
+    exists = false;
+    this.cons = cons;
+    baseExpr.streamDoubles(this);
+    if (!exists) {
+      fillExpr.streamDoubles(cons);
+    }
+  }
+  @Override
+  public void accept(double value) {
+    exists = true;
+    cons.accept(value);
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class DoubleFillMissingFunction extends AbstractDoubleValue {
+  private final DoubleValue baseExpr;
+  private final DoubleValue fillExpr;
+  public static final String name = FillMissingFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public DoubleFillMissingFunction(DoubleValue baseExpr, DoubleValue fillExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.fillExpr = fillExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
+  }
+  
+  boolean exists = false;
+
+  @Override
+  public double getDouble() {
+    double value = baseExpr.getDouble();
+    exists = true;
+    if (!baseExpr.exists()) {
+      value = fillExpr.getDouble();
+      exists = fillExpr.exists();
+    }
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class DateStreamFillMissingFunction extends AbstractDateValueStream implements LongConsumer {
+  private final DateValueStream baseExpr;
+  private final DateValueStream fillExpr;
+  public static final String name = FillMissingFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public DateStreamFillMissingFunction(DateValueStream baseExpr, DateValueStream fillExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.fillExpr = fillExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
+  }
+
+  boolean exists = false;
+  LongConsumer cons;
+
+  @Override
+  public void streamLongs(LongConsumer cons) {
+    exists = false;
+    this.cons = cons;
+    baseExpr.streamLongs(this);
+    if (!exists) {
+      fillExpr.streamLongs(cons);
+    }
+  }
+  @Override
+  public void accept(long value) {
+    exists = true;
+    cons.accept(value);
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class DateFillMissingFunction extends AbstractDateValue {
+  private final DateValue baseExpr;
+  private final DateValue fillExpr;
+  public static final String name = FillMissingFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public DateFillMissingFunction(DateValue baseExpr, DateValue fillExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.fillExpr = fillExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
+  }
+  
+  boolean exists = false;
+
+  @Override
+  public long getLong() {
+    long value = baseExpr.getLong();
+    exists = true;
+    if (!baseExpr.exists()) {
+      value = fillExpr.getLong();
+      exists = fillExpr.exists();
+    }
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class StringStreamFillMissingFunction extends AbstractStringValueStream implements Consumer<String> {
+  private final StringValueStream baseExpr;
+  private final StringValueStream fillExpr;
+  public static final String name = FillMissingFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public StringStreamFillMissingFunction(StringValueStream baseExpr, StringValueStream fillExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.fillExpr = fillExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
+  }
+
+  boolean exists = false;
+  Consumer<String> cons;
+
+  @Override
+  public void streamStrings(Consumer<String> cons) {
+    exists = false;
+    this.cons = cons;
+    baseExpr.streamStrings(this);
+    if (!exists) {
+      fillExpr.streamStrings(cons);
+    }
+  }
+  @Override
+  public void accept(String value) {
+    exists = true;
+    cons.accept(value);
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class StringFillMissingFunction extends AbstractStringValue {
+  private final StringValue baseExpr;
+  private final StringValue fillExpr;
+  public static final String name = FillMissingFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public StringFillMissingFunction(StringValue baseExpr, StringValue fillExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.fillExpr = fillExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
+  }
+  
+  boolean exists = false;
+
+  @Override
+  public String getString() {
+    String value = baseExpr.getString();
+    exists = true;
+    if (!baseExpr.exists()) {
+      value = fillExpr.getString();
+      exists = fillExpr.exists();
+    }
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d5963beb/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FilterFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FilterFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FilterFunction.java
new file mode 100644
index 0000000..84a3e30
--- /dev/null
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/FilterFunction.java
@@ -0,0 +1,722 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.function.Consumer;
+import java.util.function.DoubleConsumer;
+import java.util.function.IntConsumer;
+import java.util.function.LongConsumer;
+
+import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;
+import org.apache.solr.analytics.util.function.BooleanConsumer;
+import org.apache.solr.analytics.util.function.FloatConsumer;
+import org.apache.solr.analytics.value.AnalyticsValue;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.BooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream;
+import org.apache.solr.analytics.value.DateValue;
+import org.apache.solr.analytics.value.DateValueStream;
+import org.apache.solr.analytics.value.DoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream;
+import org.apache.solr.analytics.value.FloatValue;
+import org.apache.solr.analytics.value.FloatValueStream;
+import org.apache.solr.analytics.value.IntValue;
+import org.apache.solr.analytics.value.IntValueStream;
+import org.apache.solr.analytics.value.LongValue;
+import org.apache.solr.analytics.value.LongValueStream;
+import org.apache.solr.analytics.value.StringValue;
+import org.apache.solr.analytics.value.StringValueStream;
+import org.apache.solr.analytics.value.AnalyticsValue.AbstractAnalyticsValue;
+import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;
+import org.apache.solr.analytics.value.DateValue.AbstractDateValue;
+import org.apache.solr.analytics.value.DateValueStream.AbstractDateValueStream;
+import org.apache.solr.analytics.value.DoubleValue.AbstractDoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream.AbstractDoubleValueStream;
+import org.apache.solr.analytics.value.FloatValue.AbstractFloatValue;
+import org.apache.solr.analytics.value.FloatValueStream.AbstractFloatValueStream;
+import org.apache.solr.analytics.value.IntValue.AbstractIntValue;
+import org.apache.solr.analytics.value.IntValueStream.AbstractIntValueStream;
+import org.apache.solr.analytics.value.LongValue.AbstractLongValue;
+import org.apache.solr.analytics.value.LongValueStream.AbstractLongValueStream;
+import org.apache.solr.analytics.value.StringValue.AbstractStringValue;
+import org.apache.solr.analytics.value.StringValueStream.AbstractStringValueStream;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.SolrException.ErrorCode;
+
+/**
+ * A mapping function to filter a Value or ValueStream. For each document, the value exists if the second parameter 
+ * is true and it doesn't exist otherwise.
+ * <p>
+ * The first parameter can be any type of analytics expression. (Required)
+ * <br>
+ * The second parameter must be a {@link BooleanValue}. (Required)
+ */
+public class FilterFunction {
+  public static final String name = "filter";
+
+  public static final CreatorFunction creatorFunction = (params -> {
+    if (params.length != 2) {
+      throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 2 paramaters, " + params.length + " found.");
+    }
+    if (!(params[1] instanceof BooleanValue)) {
+      throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires the second paramater to be single-valued and boolean.");
+    }
+
+    AnalyticsValueStream baseExpr = params[0];
+    BooleanValue filterExpr = (BooleanValue)params[1];
+
+    if (baseExpr instanceof DateValue) {
+      return new DateFilterFunction((DateValue)baseExpr,filterExpr);
+    }
+    if (baseExpr instanceof DateValueStream) {
+      return new DateStreamFilterFunction((DateValueStream)baseExpr,filterExpr);
+    }
+    if (baseExpr instanceof BooleanValue) {
+      return new BooleanFilterFunction((BooleanValue)baseExpr,filterExpr);
+    }
+    if (baseExpr instanceof BooleanValueStream) {
+      return new BooleanStreamFilterFunction((BooleanValueStream)baseExpr,filterExpr);
+    }
+    if (baseExpr instanceof IntValue) {
+      return new IntFilterFunction((IntValue)baseExpr,filterExpr);
+    }
+    if (baseExpr instanceof IntValueStream) {
+      return new IntStreamFilterFunction((IntValueStream)baseExpr,filterExpr);
+    }
+    if (baseExpr instanceof LongValue) {
+      return new LongFilterFunction((LongValue)baseExpr,filterExpr);
+    }
+    if (baseExpr instanceof LongValueStream) {
+      return new LongStreamFilterFunction((LongValueStream)baseExpr,filterExpr);
+    }
+    if (baseExpr instanceof FloatValue) {
+      return new FloatFilterFunction((FloatValue)baseExpr,filterExpr);
+    }
+    if (baseExpr instanceof FloatValueStream) {
+      return new FloatStreamFilterFunction((FloatValueStream)baseExpr,filterExpr);
+    }
+    if (baseExpr instanceof DoubleValue) {
+      return new DoubleFilterFunction((DoubleValue)baseExpr,filterExpr);
+    }
+    if (baseExpr instanceof DoubleValueStream) {
+      return new DoubleStreamFilterFunction((DoubleValueStream)baseExpr,filterExpr);
+    }
+    if (baseExpr instanceof StringValue) {
+      return new StringFilterFunction((StringValue)baseExpr,filterExpr);
+    }
+    if (baseExpr instanceof StringValueStream) {
+      return new StringStreamFilterFunction((StringValueStream)baseExpr,filterExpr);
+    }
+    if (baseExpr instanceof AnalyticsValue) {
+      return new ValueFilterFunction((AnalyticsValue)baseExpr,filterExpr);
+    }
+    return new StreamFilterFunction(baseExpr,filterExpr);
+  });
+}
+class StreamFilterFunction implements AnalyticsValueStream {
+  private final AnalyticsValueStream baseExpr;
+  private final BooleanValue filterExpr;
+  public static final String name = FilterFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public StreamFilterFunction(AnalyticsValueStream baseExpr, BooleanValue filterExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.filterExpr = filterExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
+  }
+
+  @Override
+  public void streamObjects(Consumer<Object> cons) {
+    if (filterExpr.getBoolean() && filterExpr.exists()) {
+      baseExpr.streamObjects(cons);
+    }
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class ValueFilterFunction extends AbstractAnalyticsValue {
+  private final AnalyticsValue baseExpr;
+  private final BooleanValue filterExpr;
+  public static final String name = FilterFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public ValueFilterFunction(AnalyticsValue baseExpr, BooleanValue filterExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.filterExpr = filterExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
+  }
+  
+  boolean exists = false;
+
+  @Override
+  public Object getObject() {
+    Object value = baseExpr.getObject();
+    exists = baseExpr.exists() && filterExpr.getBoolean() && filterExpr.exists();
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class BooleanStreamFilterFunction extends AbstractBooleanValueStream {
+  private final BooleanValueStream baseExpr;
+  private final BooleanValue filterExpr;
+  public static final String name = FilterFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public BooleanStreamFilterFunction(BooleanValueStream baseExpr, BooleanValue filterExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.filterExpr = filterExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
+  }
+
+  @Override
+  public void streamBooleans(BooleanConsumer cons) {
+    if (filterExpr.getBoolean() && filterExpr.exists()) {
+      baseExpr.streamBooleans(cons);
+    }
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class BooleanFilterFunction extends AbstractBooleanValue {
+  private final BooleanValue baseExpr;
+  private final BooleanValue filterExpr;
+  public static final String name = FilterFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public BooleanFilterFunction(BooleanValue baseExpr, BooleanValue filterExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.filterExpr = filterExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
+  }
+  
+  boolean exists = false;
+
+  @Override
+  public boolean getBoolean() {
+    boolean value = baseExpr.getBoolean();
+    exists = baseExpr.exists() && filterExpr.getBoolean() && filterExpr.exists();
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class IntStreamFilterFunction extends AbstractIntValueStream {
+  private final IntValueStream baseExpr;
+  private final BooleanValue filterExpr;
+  public static final String name = FilterFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public IntStreamFilterFunction(IntValueStream baseExpr, BooleanValue filterExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.filterExpr = filterExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
+  }
+
+  @Override
+  public void streamInts(IntConsumer cons) {
+    if (filterExpr.getBoolean() && filterExpr.exists()) {
+      baseExpr.streamInts(cons);
+    }
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class IntFilterFunction extends AbstractIntValue {
+  private final IntValue baseExpr;
+  private final BooleanValue filterExpr;
+  public static final String name = FilterFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public IntFilterFunction(IntValue baseExpr, BooleanValue filterExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.filterExpr = filterExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
+  }
+  
+  boolean exists = false;
+
+  @Override
+  public int getInt() {
+    int value = baseExpr.getInt();
+    exists = baseExpr.exists() && filterExpr.getBoolean() && filterExpr.exists();
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class LongStreamFilterFunction extends AbstractLongValueStream {
+  private final LongValueStream baseExpr;
+  private final BooleanValue filterExpr;
+  public static final String name = FilterFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public LongStreamFilterFunction(LongValueStream baseExpr, BooleanValue filterExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.filterExpr = filterExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
+  }
+
+  @Override
+  public void streamLongs(LongConsumer cons) {
+    if (filterExpr.getBoolean() && filterExpr.exists()) {
+      baseExpr.streamLongs(cons);
+    }
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class LongFilterFunction extends AbstractLongValue {
+  private final LongValue baseExpr;
+  private final BooleanValue filterExpr;
+  public static final String name = FilterFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public LongFilterFunction(LongValue baseExpr, BooleanValue filterExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.filterExpr = filterExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
+  }
+  
+  boolean exists = false;
+
+  @Override
+  public long getLong() {
+    long value = baseExpr.getLong();
+    exists = baseExpr.exists() && filterExpr.getBoolean() && filterExpr.exists();
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class FloatStreamFilterFunction extends AbstractFloatValueStream {
+  private final FloatValueStream baseExpr;
+  private final BooleanValue filterExpr;
+  public static final String name = FilterFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public FloatStreamFilterFunction(FloatValueStream baseExpr, BooleanValue filterExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.filterExpr = filterExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
+  }
+
+  @Override
+  public void streamFloats(FloatConsumer cons) {
+    if (filterExpr.getBoolean() && filterExpr.exists()) {
+      baseExpr.streamFloats(cons);
+    }
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class FloatFilterFunction extends AbstractFloatValue {
+  private final FloatValue baseExpr;
+  private final BooleanValue filterExpr;
+  public static final String name = FilterFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public FloatFilterFunction(FloatValue baseExpr, BooleanValue filterExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.filterExpr = filterExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
+  }
+  
+  boolean exists = false;
+
+  @Override
+  public float getFloat() {
+    float value = baseExpr.getFloat();
+    exists = baseExpr.exists() && filterExpr.getBoolean() && filterExpr.exists();
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class DoubleStreamFilterFunction extends AbstractDoubleValueStream {
+  private final DoubleValueStream baseExpr;
+  private final BooleanValue filterExpr;
+  public static final String name = FilterFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public DoubleStreamFilterFunction(DoubleValueStream baseExpr, BooleanValue filterExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.filterExpr = filterExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
+  }
+
+  @Override
+  public void streamDoubles(DoubleConsumer cons) {
+    if (filterExpr.getBoolean() && filterExpr.exists()) {
+      baseExpr.streamDoubles(cons);
+    }
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class DoubleFilterFunction extends AbstractDoubleValue {
+  private final DoubleValue baseExpr;
+  private final BooleanValue filterExpr;
+  public static final String name = FilterFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public DoubleFilterFunction(DoubleValue baseExpr, BooleanValue filterExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.filterExpr = filterExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
+  }
+  
+  boolean exists = false;
+
+  @Override
+  public double getDouble() {
+    double value = baseExpr.getDouble();
+    exists = baseExpr.exists() && filterExpr.getBoolean() && filterExpr.exists();
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class DateStreamFilterFunction extends AbstractDateValueStream {
+  private final DateValueStream baseExpr;
+  private final BooleanValue filterExpr;
+  public static final String name = FilterFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public DateStreamFilterFunction(DateValueStream baseExpr, BooleanValue filterExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.filterExpr = filterExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
+  }
+
+  @Override
+  public void streamLongs(LongConsumer cons) {
+    if (filterExpr.getBoolean() && filterExpr.exists()) {
+      baseExpr.streamLongs(cons);
+    }
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class DateFilterFunction extends AbstractDateValue {
+  private final DateValue baseExpr;
+  private final BooleanValue filterExpr;
+  public static final String name = FilterFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public DateFilterFunction(DateValue baseExpr, BooleanValue filterExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.filterExpr = filterExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
+  }
+  
+  boolean exists = false;
+
+  @Override
+  public long getLong() {
+    long value = baseExpr.getLong();
+    exists = baseExpr.exists() && filterExpr.getBoolean() && filterExpr.exists();
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class StringStreamFilterFunction extends AbstractStringValueStream {
+  private final StringValueStream baseExpr;
+  private final BooleanValue filterExpr;
+  public static final String name = FilterFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public StringStreamFilterFunction(StringValueStream baseExpr, BooleanValue filterExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.filterExpr = filterExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
+  }
+
+  @Override
+  public void streamStrings(Consumer<String> cons) {
+    if (filterExpr.getBoolean() && filterExpr.exists()) {
+      baseExpr.streamStrings(cons);
+    }
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class StringFilterFunction extends AbstractStringValue {
+  private final StringValue baseExpr;
+  private final BooleanValue filterExpr;
+  public static final String name = FilterFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public StringFilterFunction(StringValue baseExpr, BooleanValue filterExpr) throws SolrException {
+    this.baseExpr = baseExpr;
+    this.filterExpr = filterExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
+  }
+  
+  boolean exists = false;
+
+  @Override
+  public String getString() {
+    String value = baseExpr.getString();
+    exists = baseExpr.exists() && filterExpr.getBoolean() && filterExpr.exists();
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d5963beb/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/IfFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/IfFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/IfFunction.java
new file mode 100644
index 0000000..e2fd163
--- /dev/null
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/IfFunction.java
@@ -0,0 +1,892 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.function.Consumer;
+import java.util.function.DoubleConsumer;
+import java.util.function.IntConsumer;
+import java.util.function.LongConsumer;
+
+import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;
+import org.apache.solr.analytics.util.function.BooleanConsumer;
+import org.apache.solr.analytics.util.function.FloatConsumer;
+import org.apache.solr.analytics.value.AnalyticsValue;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.BooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream;
+import org.apache.solr.analytics.value.DateValue;
+import org.apache.solr.analytics.value.DateValueStream;
+import org.apache.solr.analytics.value.DoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream;
+import org.apache.solr.analytics.value.FloatValue;
+import org.apache.solr.analytics.value.FloatValueStream;
+import org.apache.solr.analytics.value.IntValue;
+import org.apache.solr.analytics.value.IntValueStream;
+import org.apache.solr.analytics.value.LongValue;
+import org.apache.solr.analytics.value.LongValueStream;
+import org.apache.solr.analytics.value.StringValue;
+import org.apache.solr.analytics.value.StringValueStream;
+import org.apache.solr.analytics.value.AnalyticsValue.AbstractAnalyticsValue;
+import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;
+import org.apache.solr.analytics.value.DateValue.AbstractDateValue;
+import org.apache.solr.analytics.value.DateValueStream.AbstractDateValueStream;
+import org.apache.solr.analytics.value.DoubleValue.AbstractDoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream.AbstractDoubleValueStream;
+import org.apache.solr.analytics.value.FloatValue.AbstractFloatValue;
+import org.apache.solr.analytics.value.FloatValueStream.AbstractFloatValueStream;
+import org.apache.solr.analytics.value.IntValue.AbstractIntValue;
+import org.apache.solr.analytics.value.IntValueStream.AbstractIntValueStream;
+import org.apache.solr.analytics.value.LongValue.AbstractLongValue;
+import org.apache.solr.analytics.value.LongValueStream.AbstractLongValueStream;
+import org.apache.solr.analytics.value.StringValue.AbstractStringValue;
+import org.apache.solr.analytics.value.StringValueStream.AbstractStringValueStream;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.SolrException.ErrorCode;
+
+/**
+ * An if-else mapping function. 
+ * <p>
+ * Three arguments are required. The first, the conditional parameter, must be a {@link BooleanValue} and
+ * the later two, the if and else parameters, can be any type of {@link AnalyticsValueStream}. 
+ * For each document, if the conditional value is true then the if-value is used otherwise the else-value is used.
+ * <p>
+ * The resulting Value or ValueStream will be typed with the closest super-type of the two non-conditional parameters.
+ * (e.g. {@value #name}(boolean,double,int) will return a double)
+ * If two {@link AnalyticsValue}s are passed as the if-else parameters, an {@link AnalyticsValue} will be returned.
+ * If either parameter isn't single-valued, a {@link AnalyticsValueStream} will be returned.
+ */
+public class IfFunction implements AnalyticsValueStream {
+  private final BooleanValue ifExpr;
+  private final AnalyticsValueStream thenExpr;
+  private final AnalyticsValueStream elseExpr;
+  public static final String name = "if";
+  private final String exprStr;
+  private final ExpressionType funcType;
+  public static final CreatorFunction creatorFunction = (params -> {
+    if (params.length != 3) {
+      throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 3 paramaters, " + params.length + " found.");
+    }
+    if (!(params[0] instanceof BooleanValue)) {
+      throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires single-valued numeric parameters. " + 
+                      "Incorrect parameter: "+params[0].getExpressionStr());
+    }
+    
+    BooleanValue castedIf = (BooleanValue) params[0];
+    AnalyticsValueStream thenExpr = params[1];
+    AnalyticsValueStream elseExpr = params[2];
+
+    if (thenExpr instanceof DateValue && elseExpr instanceof DateValue) {
+      return new DateIfFunction(castedIf,(DateValue)thenExpr,(DateValue)elseExpr);
+    }
+    if (thenExpr instanceof DateValueStream && elseExpr instanceof DateValueStream) {
+      return new DateStreamIfFunction(castedIf,(DateValueStream)thenExpr,(DateValueStream)elseExpr);
+    }
+    if (thenExpr instanceof BooleanValue && elseExpr instanceof BooleanValue) {
+      return new BooleanIfFunction(castedIf,(BooleanValue)thenExpr,(BooleanValue)elseExpr);
+    }
+    if (thenExpr instanceof BooleanValueStream && elseExpr instanceof BooleanValueStream) {
+      return new BooleanStreamIfFunction(castedIf,(BooleanValueStream)thenExpr,(BooleanValueStream)elseExpr);
+    }
+    if (thenExpr instanceof IntValue && elseExpr instanceof IntValue) {
+      return new IntIfFunction(castedIf,(IntValue)thenExpr,(IntValue)elseExpr);
+    }
+    if (thenExpr instanceof IntValueStream && elseExpr instanceof IntValueStream) {
+      return new IntStreamIfFunction(castedIf,(IntValueStream)thenExpr,(IntValueStream)elseExpr);
+    }
+    if (thenExpr instanceof LongValue && elseExpr instanceof LongValue) {
+      return new LongIfFunction(castedIf,(LongValue)thenExpr,(LongValue)elseExpr);
+    }
+    if (thenExpr instanceof LongValueStream && elseExpr instanceof LongValueStream) {
+      return new LongStreamIfFunction(castedIf,(LongValueStream)thenExpr,(LongValueStream)elseExpr);
+    }
+    if (thenExpr instanceof FloatValue && elseExpr instanceof FloatValue) {
+      return new FloatIfFunction(castedIf,(FloatValue)thenExpr,(FloatValue)elseExpr);
+    }
+    if (thenExpr instanceof FloatValueStream && elseExpr instanceof FloatValueStream) {
+      return new FloatStreamIfFunction(castedIf,(FloatValueStream)thenExpr,(FloatValueStream)elseExpr);
+    }
+    if (thenExpr instanceof DoubleValue && elseExpr instanceof DoubleValue) {
+      return new DoubleIfFunction(castedIf,(DoubleValue)thenExpr,(DoubleValue)elseExpr);
+    }
+    if (thenExpr instanceof DoubleValueStream && elseExpr instanceof DoubleValueStream) {
+      return new DoubleStreamIfFunction(castedIf,(DoubleValueStream)thenExpr,(DoubleValueStream)elseExpr);
+    }
+    if (thenExpr instanceof StringValue && elseExpr instanceof StringValue) {
+      return new StringIfFunction(castedIf,(StringValue)thenExpr,(StringValue)elseExpr);
+    }
+    if (thenExpr instanceof StringValueStream && elseExpr instanceof StringValueStream) {
+      return new StringStreamIfFunction(castedIf,(StringValueStream)thenExpr,(StringValueStream)elseExpr);
+    }
+    if (thenExpr instanceof AnalyticsValue && elseExpr instanceof AnalyticsValue) {
+      return new ValueIfFunction(castedIf,(AnalyticsValue)thenExpr,(AnalyticsValue)elseExpr);
+    }
+    return new IfFunction(castedIf,thenExpr,elseExpr);
+  });
+  
+  public IfFunction(BooleanValue ifExpr, AnalyticsValueStream thenExpr, AnalyticsValueStream elseExpr) throws SolrException {
+    this.ifExpr = ifExpr;
+    this.thenExpr = thenExpr;
+    this.elseExpr = elseExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,ifExpr,thenExpr,elseExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,ifExpr,thenExpr,elseExpr);
+  }
+
+  @Override
+  public void streamObjects(Consumer<Object> cons) {
+    boolean ifValue = ifExpr.getBoolean();
+    if (ifExpr.exists()) {
+      if (ifValue) {
+        thenExpr.streamObjects(cons);
+      }
+      else {
+        elseExpr.streamObjects(cons);
+      }
+    }
+  }
+
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class ValueIfFunction extends AbstractAnalyticsValue {
+  private final BooleanValue ifExpr;
+  private final AnalyticsValue thenExpr;
+  private final AnalyticsValue elseExpr;
+  public static final String name = IfFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public ValueIfFunction(BooleanValue ifExpr, AnalyticsValue thenExpr, AnalyticsValue elseExpr) throws SolrException {
+    this.ifExpr = ifExpr;
+    this.thenExpr = thenExpr;
+    this.elseExpr = elseExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,ifExpr,thenExpr,elseExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,ifExpr,thenExpr,elseExpr);
+  }
+
+  private boolean exists = false;
+
+  @Override
+  public Object getObject() {
+    exists = false;
+    Object value = null;
+    boolean ifValue = ifExpr.getBoolean();
+    if (ifExpr.exists()) {
+      if (ifValue) {
+        value = thenExpr.getObject();
+        exists = thenExpr.exists();
+      }
+      else {
+        value = elseExpr.getObject();
+        exists = elseExpr.exists();
+      }
+    }
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class BooleanStreamIfFunction extends AbstractBooleanValueStream {
+  private final BooleanValue ifExpr;
+  private final BooleanValueStream thenExpr;
+  private final BooleanValueStream elseExpr;
+  public static final String name = IfFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public BooleanStreamIfFunction(BooleanValue ifExpr, BooleanValueStream thenExpr, BooleanValueStream elseExpr) throws SolrException {
+    this.ifExpr = ifExpr;
+    this.thenExpr = thenExpr;
+    this.elseExpr = elseExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,ifExpr,thenExpr,elseExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,ifExpr,thenExpr,elseExpr);
+  }
+
+  @Override
+  public void streamBooleans(BooleanConsumer cons) {
+    boolean ifValue = ifExpr.getBoolean();
+    if (ifExpr.exists()) {
+      if (ifValue) {
+        thenExpr.streamBooleans(cons);
+      }
+      else {
+        elseExpr.streamBooleans(cons);
+      }
+    }
+  }
+
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class BooleanIfFunction extends AbstractBooleanValue {
+  private final BooleanValue ifExpr;
+  private final BooleanValue thenExpr;
+  private final BooleanValue elseExpr;
+  public static final String name = IfFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public BooleanIfFunction(BooleanValue ifExpr, BooleanValue thenExpr, BooleanValue elseExpr) throws SolrException {
+    this.ifExpr = ifExpr;
+    this.thenExpr = thenExpr;
+    this.elseExpr = elseExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,ifExpr,thenExpr,elseExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,ifExpr,thenExpr,elseExpr);
+  }
+
+  private boolean exists = false;
+
+  @Override
+  public boolean getBoolean() {
+    exists = false;
+    boolean value = false;
+    boolean ifValue = ifExpr.getBoolean();
+    if (ifExpr.exists()) {
+      if (ifValue) {
+        value = thenExpr.getBoolean();
+        exists = thenExpr.exists();
+      }
+      else {
+        value = elseExpr.getBoolean();
+        exists = elseExpr.exists();
+      }
+    }
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class IntStreamIfFunction extends AbstractIntValueStream {
+  private final BooleanValue ifExpr;
+  private final IntValueStream thenExpr;
+  private final IntValueStream elseExpr;
+  public static final String name = IfFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public IntStreamIfFunction(BooleanValue ifExpr, IntValueStream thenExpr, IntValueStream elseExpr) throws SolrException {
+    this.ifExpr = ifExpr;
+    this.thenExpr = thenExpr;
+    this.elseExpr = elseExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,ifExpr,thenExpr,elseExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,ifExpr,thenExpr,elseExpr);
+  }
+
+  @Override
+  public void streamInts(IntConsumer cons) {
+    boolean ifValue = ifExpr.getBoolean();
+    if (ifExpr.exists()) {
+      if (ifValue) {
+        thenExpr.streamInts(cons);
+      }
+      else {
+        elseExpr.streamInts(cons);
+      }
+    }
+  }
+
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class IntIfFunction extends AbstractIntValue {
+  private final BooleanValue ifExpr;
+  private final IntValue thenExpr;
+  private final IntValue elseExpr;
+  public static final String name = IfFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public IntIfFunction(BooleanValue ifExpr, IntValue thenExpr, IntValue elseExpr) throws SolrException {
+    this.ifExpr = ifExpr;
+    this.thenExpr = thenExpr;
+    this.elseExpr = elseExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,ifExpr,thenExpr,elseExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,ifExpr,thenExpr,elseExpr);
+  }
+
+  private boolean exists = false;
+
+  @Override
+  public int getInt() {
+    exists = false;
+    int value = 0;
+    boolean ifValue = ifExpr.getBoolean();
+    if (ifExpr.exists()) {
+      if (ifValue) {
+        value = thenExpr.getInt();
+        exists = thenExpr.exists();
+      }
+      else {
+        value = elseExpr.getInt();
+        exists = elseExpr.exists();
+      }
+    }
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class LongStreamIfFunction extends AbstractLongValueStream {
+  private final BooleanValue ifExpr;
+  private final LongValueStream thenExpr;
+  private final LongValueStream elseExpr;
+  public static final String name = IfFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public LongStreamIfFunction(BooleanValue ifExpr, LongValueStream thenExpr, LongValueStream elseExpr) throws SolrException {
+    this.ifExpr = ifExpr;
+    this.thenExpr = thenExpr;
+    this.elseExpr = elseExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,ifExpr,thenExpr,elseExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,ifExpr,thenExpr,elseExpr);
+  }
+
+  @Override
+  public void streamLongs(LongConsumer cons) {
+    boolean ifValue = ifExpr.getBoolean();
+    if (ifExpr.exists()) {
+      if (ifValue) {
+        thenExpr.streamLongs(cons);
+      }
+      else {
+        elseExpr.streamLongs(cons);
+      }
+    }
+  }
+
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class LongIfFunction extends AbstractLongValue {
+  private final BooleanValue ifExpr;
+  private final LongValue thenExpr;
+  private final LongValue elseExpr;
+  public static final String name = IfFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public LongIfFunction(BooleanValue ifExpr, LongValue thenExpr, LongValue elseExpr) throws SolrException {
+    this.ifExpr = ifExpr;
+    this.thenExpr = thenExpr;
+    this.elseExpr = elseExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,ifExpr,thenExpr,elseExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,ifExpr,thenExpr,elseExpr);
+  }
+
+  private boolean exists = false;
+
+  @Override
+  public long getLong() {
+    exists = false;
+    long value = 0;
+    boolean ifValue = ifExpr.getBoolean();
+    if (ifExpr.exists()) {
+      if (ifValue) {
+        value = thenExpr.getLong();
+        exists = thenExpr.exists();
+      }
+      else {
+        value = elseExpr.getLong();
+        exists = elseExpr.exists();
+      }
+    }
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class FloatStreamIfFunction extends AbstractFloatValueStream {
+  private final BooleanValue ifExpr;
+  private final FloatValueStream thenExpr;
+  private final FloatValueStream elseExpr;
+  public static final String name = IfFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public FloatStreamIfFunction(BooleanValue ifExpr, FloatValueStream thenExpr, FloatValueStream elseExpr) throws SolrException {
+    this.ifExpr = ifExpr;
+    this.thenExpr = thenExpr;
+    this.elseExpr = elseExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,ifExpr,thenExpr,elseExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,ifExpr,thenExpr,elseExpr);
+  }
+
+  @Override
+  public void streamFloats(FloatConsumer cons) {
+    boolean ifValue = ifExpr.getBoolean();
+    if (ifExpr.exists()) {
+      if (ifValue) {
+        thenExpr.streamFloats(cons);
+      }
+      else {
+        elseExpr.streamFloats(cons);
+      }
+    }
+  }
+
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class FloatIfFunction extends AbstractFloatValue {
+  private final BooleanValue ifExpr;
+  private final FloatValue thenExpr;
+  private final FloatValue elseExpr;
+  public static final String name = IfFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public FloatIfFunction(BooleanValue ifExpr, FloatValue thenExpr, FloatValue elseExpr) throws SolrException {
+    this.ifExpr = ifExpr;
+    this.thenExpr = thenExpr;
+    this.elseExpr = elseExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,ifExpr,thenExpr,elseExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,ifExpr,thenExpr,elseExpr);
+  }
+
+  private boolean exists = false;
+
+  @Override
+  public float getFloat() {
+    exists = false;
+    float value = 0;
+    boolean ifValue = ifExpr.getBoolean();
+    if (ifExpr.exists()) {
+      if (ifValue) {
+        value = thenExpr.getFloat();
+        exists = thenExpr.exists();
+      }
+      else {
+        value = elseExpr.getFloat();
+        exists = elseExpr.exists();
+      }
+    }
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class DoubleStreamIfFunction extends AbstractDoubleValueStream {
+  private final BooleanValue ifExpr;
+  private final DoubleValueStream thenExpr;
+  private final DoubleValueStream elseExpr;
+  public static final String name = IfFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public DoubleStreamIfFunction(BooleanValue ifExpr, DoubleValueStream thenExpr, DoubleValueStream elseExpr) throws SolrException {
+    this.ifExpr = ifExpr;
+    this.thenExpr = thenExpr;
+    this.elseExpr = elseExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,ifExpr,thenExpr,elseExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,ifExpr,thenExpr,elseExpr);
+  }
+
+  @Override
+  public void streamDoubles(DoubleConsumer cons) {
+    boolean ifValue = ifExpr.getBoolean();
+    if (ifExpr.exists()) {
+      if (ifValue) {
+        thenExpr.streamDoubles(cons);
+      }
+      else {
+        elseExpr.streamDoubles(cons);
+      }
+    }
+  }
+
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class DoubleIfFunction extends AbstractDoubleValue {
+  private final BooleanValue ifExpr;
+  private final DoubleValue thenExpr;
+  private final DoubleValue elseExpr;
+  public static final String name = IfFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public DoubleIfFunction(BooleanValue ifExpr, DoubleValue thenExpr, DoubleValue elseExpr) throws SolrException {
+    this.ifExpr = ifExpr;
+    this.thenExpr = thenExpr;
+    this.elseExpr = elseExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,ifExpr,thenExpr,elseExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,ifExpr,thenExpr,elseExpr);
+  }
+
+  private boolean exists = false;
+
+  @Override
+  public double getDouble() {
+    exists = false;
+    double value = 0;
+    boolean ifValue = ifExpr.getBoolean();
+    if (ifExpr.exists()) {
+      if (ifValue) {
+        value = thenExpr.getDouble();
+        exists = thenExpr.exists();
+      }
+      else {
+        value = elseExpr.getDouble();
+        exists = elseExpr.exists();
+      }
+    }
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class DateStreamIfFunction extends AbstractDateValueStream {
+  private final BooleanValue ifExpr;
+  private final DateValueStream thenExpr;
+  private final DateValueStream elseExpr;
+  public static final String name = IfFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public DateStreamIfFunction(BooleanValue ifExpr, DateValueStream thenExpr, DateValueStream elseExpr) throws SolrException {
+    this.ifExpr = ifExpr;
+    this.thenExpr = thenExpr;
+    this.elseExpr = elseExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,ifExpr,thenExpr,elseExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,ifExpr,thenExpr,elseExpr);
+  }
+
+  @Override
+  public void streamLongs(LongConsumer cons) {
+    boolean ifValue = ifExpr.getBoolean();
+    if (ifExpr.exists()) {
+      if (ifValue) {
+        thenExpr.streamLongs(cons);
+      }
+      else {
+        elseExpr.streamLongs(cons);
+      }
+    }
+  }
+
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class DateIfFunction extends AbstractDateValue {
+  private final BooleanValue ifExpr;
+  private final DateValue thenExpr;
+  private final DateValue elseExpr;
+  public static final String name = IfFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public DateIfFunction(BooleanValue ifExpr, DateValue thenExpr, DateValue elseExpr) throws SolrException {
+    this.ifExpr = ifExpr;
+    this.thenExpr = thenExpr;
+    this.elseExpr = elseExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,ifExpr,thenExpr,elseExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,ifExpr,thenExpr,elseExpr);
+  }
+
+  private boolean exists = false;
+
+  @Override
+  public long getLong() {
+    exists = false;
+    long value = 0;
+    boolean ifValue = ifExpr.getBoolean();
+    if (ifExpr.exists()) {
+      if (ifValue) {
+        value = thenExpr.getLong();
+        exists = thenExpr.exists();
+      }
+      else {
+        value = elseExpr.getLong();
+        exists = elseExpr.exists();
+      }
+    }
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class StringStreamIfFunction extends AbstractStringValueStream {
+  private final BooleanValue ifExpr;
+  private final StringValueStream thenExpr;
+  private final StringValueStream elseExpr;
+  public static final String name = IfFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public StringStreamIfFunction(BooleanValue ifExpr, StringValueStream thenExpr, StringValueStream elseExpr) throws SolrException {
+    this.ifExpr = ifExpr;
+    this.thenExpr = thenExpr;
+    this.elseExpr = elseExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,ifExpr,thenExpr,elseExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,ifExpr,thenExpr,elseExpr);
+  }
+
+  @Override
+  public void streamStrings(Consumer<String> cons) {
+    boolean ifValue = ifExpr.getBoolean();
+    if (ifExpr.exists()) {
+      if (ifValue) {
+        thenExpr.streamStrings(cons);
+      }
+      else {
+        elseExpr.streamStrings(cons);
+      }
+    }
+  }
+  
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
+class StringIfFunction extends AbstractStringValue {
+  private final BooleanValue ifExpr;
+  private final StringValue thenExpr;
+  private final StringValue elseExpr;
+  public static final String name = IfFunction.name;
+  private final String exprStr;
+  private final ExpressionType funcType;
+  
+  public StringIfFunction(BooleanValue ifExpr, StringValue thenExpr, StringValue elseExpr) throws SolrException {
+    this.ifExpr = ifExpr;
+    this.thenExpr = thenExpr;
+    this.elseExpr = elseExpr;
+    this.exprStr = AnalyticsValueStream.createExpressionString(name,ifExpr,thenExpr,elseExpr);
+    this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,ifExpr,thenExpr,elseExpr);
+  }
+
+  private boolean exists = false;
+
+  @Override
+  public String getString() {
+    exists = false;
+    String value = null;
+    boolean ifValue = ifExpr.getBoolean();
+    if (ifExpr.exists()) {
+      if (ifValue) {
+        value = thenExpr.getString();
+        exists = thenExpr.exists();
+      }
+      else {
+        value = elseExpr.getString();
+        exists = elseExpr.exists();
+      }
+    }
+    return value;
+  }
+  @Override
+  public boolean exists() {
+    return exists;
+  }
+
+  @Override
+  public String getName() {
+    return name;
+  }
+  @Override
+  public String getExpressionStr() {
+    return exprStr;
+  }
+  @Override
+  public ExpressionType getExpressionType() {
+    return funcType;
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d5963beb/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/JoinFunction.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/JoinFunction.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/JoinFunction.java
new file mode 100644
index 0000000..528aae2
--- /dev/null
+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/mapping/JoinFunction.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.SolrException.ErrorCode;
+import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.StringValue;
+import org.apache.solr.analytics.value.StringValueStream;
+import org.apache.solr.analytics.value.constant.ConstantStringValue;
+
+/**
+ * A string join mapping function.
+ * <p>
+ * Takes a {@link StringValueStream} as the first parameter and a {@link ConstantStringValue} (e.g. ",") as the second parameter
+ * and a {@link StringValue} is returned.
+ * <br>
+ * The second parameter is used as the separator while joining all values the first parameter has for a document.
+ * No order is guaranteed while joining the string values
+ */
+public class JoinFunction {
+  public static final String name = "join";
+  public static final CreatorFunction creatorFunction = (params -> {
+    if (params.length != 2) {
+      throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 2 parameters.");
+    } 
+    AnalyticsValueStream param1 = params[0];
+    AnalyticsValueStream param2 = params[1];
+    if (!(param2 instanceof ConstantStringValue)) {
+      throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires the second parameter to be a constant string");
+    }
+    String sep = ((StringValue)param2).getString();
+    if (!(param1 instanceof StringValueStream)) {
+      throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires the first parameter to be castable to a string");
+    }
+    if (param1 instanceof StringValue) {
+      return param1;
+    }
+    String uniqueName = name + "(" + sep + ")";
+    return LambdaFunction.createStringLambdaFunction(uniqueName, (a,b) -> a + sep + b, (StringValueStream)params[0]);
+  });
+}
\ No newline at end of file


Mime
View raw message