All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.facebook.presto.sql.tree.CreateFunction Maven / Gradle / Ivy

There is a newer version: 0.290
Show newest version
/*
 * Licensed 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 com.facebook.presto.sql.tree;

import com.google.common.collect.ImmutableList;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;

public class CreateFunction
        extends Statement
{
    private final QualifiedName functionName;
    private final boolean replace;
    private final List parameters;
    private final String returnType;
    private final Optional comment;
    private final RoutineCharacteristics characteristics;
    private final RoutineBody body;

    public CreateFunction(QualifiedName functionName, boolean replace, List parameters, String returnType, Optional comment, RoutineCharacteristics characteristics, RoutineBody body)
    {
        this(Optional.empty(), replace, functionName, parameters, returnType, comment, characteristics, body);
    }

    public CreateFunction(NodeLocation location, boolean replace, QualifiedName functionName, List parameters, String returnType, Optional comment, RoutineCharacteristics characteristics, RoutineBody body)
    {
        this(Optional.of(location), replace, functionName, parameters, returnType, comment, characteristics, body);
    }

    private CreateFunction(Optional location, boolean replace, QualifiedName functionName, List parameters, String returnType, Optional comment, RoutineCharacteristics characteristics, RoutineBody body)
    {
        super(location);
        this.functionName = requireNonNull(functionName, "functionName is null");
        this.replace = replace;
        this.parameters = ImmutableList.copyOf(requireNonNull(parameters, "parameters is null"));
        this.returnType = requireNonNull(returnType, "returnType is null");
        this.comment = requireNonNull(comment, "comment is null");
        this.characteristics = requireNonNull(characteristics, "routineCharacteristics is null");
        this.body = requireNonNull(body, "body is null");
    }

    public QualifiedName getFunctionName()
    {
        return functionName;
    }

    public boolean isReplace()
    {
        return replace;
    }

    public List getParameters()
    {
        return parameters;
    }

    public String getReturnType()
    {
        return returnType;
    }

    public Optional getComment()
    {
        return comment;
    }

    public RoutineCharacteristics getCharacteristics()
    {
        return characteristics;
    }

    public RoutineBody getBody()
    {
        return body;
    }

    @Override
    public  R accept(AstVisitor visitor, C context)
    {
        return visitor.visitCreateFunction(this, context);
    }

    @Override
    public List getChildren()
    {
        return ImmutableList.builder()
                .add(body)
                .build();
    }

    @Override
    public int hashCode()
    {
        return Objects.hash(functionName, parameters, returnType, comment, characteristics, body);
    }

    @Override
    public boolean equals(Object obj)
    {
        if (this == obj) {
            return true;
        }
        if ((obj == null) || (getClass() != obj.getClass())) {
            return false;
        }
        CreateFunction o = (CreateFunction) obj;
        return Objects.equals(functionName, o.functionName) &&
                Objects.equals(parameters, o.parameters) &&
                Objects.equals(returnType, o.returnType) &&
                Objects.equals(comment, o.comment) &&
                Objects.equals(characteristics, o.characteristics) &&
                Objects.equals(body, o.body);
    }

    @Override
    public String toString()
    {
        return toStringHelper(this)
                .add("functionName", functionName)
                .add("parameters", parameters)
                .add("returnType", returnType)
                .add("comment", comment)
                .add("characteristics", characteristics)
                .add("body", body)
                .toString();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy