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;
/**
* A mapping function to fill all non-existing values with a given value.
*
* Uses:
*
*
If two Values are passed in, a Value mimicking the first parameter with the second parameter used as filler will be returned.
*
If two ValueStreams are passed in, a ValueStream mimicking the first parameter with the second parameter used as filler will be returned.
*
*
* 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 = "fill_missing";
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 extends AbstractAnalyticsValueStream implements Consumer