001package gudusoft.gsqlparser.dlineage.dataflow.model;
002
003import gudusoft.gsqlparser.nodes.TFunctionCall;
004import gudusoft.gsqlparser.nodes.TTable;
005
006import java.util.ArrayList;
007import java.util.Collections;
008import java.util.List;
009
010/**
011 * Represents a call site where TABLE(pipelined_func(...)) was used but the
012 * function signature was not yet available at analysis time. These are
013 * resolved during the finalize phase.
014 */
015public class PendingPipelinedCallSite {
016    private List<String> functionKeyCandidates;
017    private List<Object> functionKeys;
018    private int argCount;
019    private TTable table;
020    private TFunctionCall callExpr;
021
022    /**
023     * A call site whose function is looked up under keys of the deprecated text API.
024     *
025     * @deprecated signatures are registered under the identities of their names: use
026     *             {@link #forFunctionKeys(List, List, int, TTable, TFunctionCall)}
027     */
028    @Deprecated
029    public PendingPipelinedCallSite(List<String> functionKeyCandidates, int argCount,
030                                    TTable table, TFunctionCall callExpr) {
031        this(functionKeyCandidates, new ArrayList<Object>(functionKeyCandidates), argCount, table, callExpr);
032    }
033
034    private PendingPipelinedCallSite(List<String> functionNames, List<Object> functionKeys, int argCount,
035                                     TTable table, TFunctionCall callExpr) {
036        this.functionKeyCandidates = functionNames;
037        this.functionKeys = functionKeys;
038        this.argCount = argCount;
039        this.table = table;
040        this.callExpr = callExpr;
041    }
042
043    /**
044     * A call site whose function may be registered under {@code functionKeys}, most specific first (the identities
045     * {@link ModelBindingManager#addPipelinedSignature} registers); {@code functionNames} are the same candidates as
046     * written, for display.
047     */
048    public static PendingPipelinedCallSite forFunctionKeys(List<String> functionNames, List<?> functionKeys,
049                                                           int argCount, TTable table, TFunctionCall callExpr) {
050        return new PendingPipelinedCallSite(functionNames, new ArrayList<Object>(functionKeys), argCount, table,
051                callExpr);
052    }
053
054    /** The candidate names as written (the deprecated text API's keys, for a call site built through it). */
055    public List<String> getFunctionKeyCandidates() {
056        return functionKeyCandidates;
057    }
058
059    /** The keys the call's function may be registered under, most specific first. */
060    public List<Object> getFunctionKeys() {
061        return Collections.unmodifiableList(functionKeys);
062    }
063
064    public int getArgCount() {
065        return argCount;
066    }
067
068    public TTable getTable() {
069        return table;
070    }
071
072    public TFunctionCall getCallExpr() {
073        return callExpr;
074    }
075
076    @Override
077    public String toString() {
078        return "PendingPipelinedCallSite{candidates=" + functionKeyCandidates + ", args=" + argCount + "}";
079    }
080}