org.graylog.plugins.pipelineprocessor.ast.functions.Function Maven / Gradle / Ivy
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* .
*/
package org.graylog.plugins.pipelineprocessor.ast.functions;
import com.google.common.collect.ImmutableList;
import org.graylog.plugins.pipelineprocessor.EvaluationContext;
import org.graylog.plugins.pipelineprocessor.ast.exceptions.PrecomputeFailure;
import org.graylog.plugins.pipelineprocessor.ast.expressions.Expression;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
public interface Function {
Logger log = LoggerFactory.getLogger(Function.class);
Function ERROR_FUNCTION = new AbstractFunction() {
@Override
public Void evaluate(FunctionArgs args, EvaluationContext context) {
return null;
}
@Override
public void preprocessArgs(FunctionArgs args) {
// intentionally left blank
}
@Override
public FunctionDescriptor descriptor() {
return FunctionDescriptor.builder()
.name("__unresolved_function")
.returnType(Void.class)
.params(ImmutableList.of())
.build();
}
};
default void preprocessArgs(FunctionArgs args) {
for (Map.Entry e : args.getConstantArgs().entrySet()) {
final String name = e.getKey();
try {
final Object value = preComputeConstantArgument(args, name, e.getValue());
if (value != null) {
//noinspection unchecked
final ParameterDescriptor