Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.AnalyticsValueStream.AbstractAnalyticsValueStream;
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.
*
* 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.
*
* 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 extends AbstractAnalyticsValueStream {
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