001package gudusoft.gsqlparser.dlineage.dataflow.model;
002
003import java.util.*;
004
005/**
006 * Captures the output row structure and per-column upstream lineage of a pipelined table function.
007 * This is the single source of truth for all stitching operations.
008 */
009public class PipelinedFunctionSignature {
010    private String functionKey;
011    private String nakedKey;
012    private String procedureKey;
013    private String rowTypeKey;
014    private String collectionTypeKey;
015    private int argCount;
016    private boolean pipelined;
017    private boolean resolved;
018    private ResolutionStatus status;
019    private List<String> outputColumns;
020    private Map<String, List<PipelinedSourceRef>> lineageByOutputColumn;
021
022    public enum ResolutionStatus {
023        OK, AMBIGUOUS, UNRESOLVED, SKIPPED
024    }
025
026    public PipelinedFunctionSignature() {
027        this.outputColumns = new ArrayList<>();
028        this.lineageByOutputColumn = new LinkedHashMap<>();
029        this.status = ResolutionStatus.UNRESOLVED;
030        this.resolved = false;
031        this.pipelined = true;
032    }
033
034    private Object functionIdentity;
035    private Object nakedIdentity;
036
037    /** The identity of the function's name as written, package included; see {@link #getFunctionKey()}. */
038    public Object getFunctionIdentity() {
039        return functionIdentity;
040    }
041
042    public void setFunctionIdentity(Object functionIdentity) {
043        this.functionIdentity = functionIdentity;
044    }
045
046    /** The identity of the function's bare name as written. */
047    public Object getNakedIdentity() {
048        return nakedIdentity;
049    }
050
051    public void setNakedIdentity(Object nakedIdentity) {
052        this.nakedIdentity = nakedIdentity;
053    }
054
055    /**
056     * The function's name as written, package included: a label. The signature is registered under
057     * {@link #getFunctionIdentity()} when it has one.
058     */
059    public String getFunctionKey() {
060        return functionKey;
061    }
062
063    public void setFunctionKey(String functionKey) {
064        this.functionKey = functionKey;
065    }
066
067    public String getNakedKey() {
068        return nakedKey;
069    }
070
071    public void setNakedKey(String nakedKey) {
072        this.nakedKey = nakedKey;
073    }
074
075    public String getProcedureKey() {
076        return procedureKey;
077    }
078
079    public void setProcedureKey(String procedureKey) {
080        this.procedureKey = procedureKey;
081    }
082
083    public String getRowTypeKey() {
084        return rowTypeKey;
085    }
086
087    public void setRowTypeKey(String rowTypeKey) {
088        this.rowTypeKey = rowTypeKey;
089    }
090
091    public String getCollectionTypeKey() {
092        return collectionTypeKey;
093    }
094
095    public void setCollectionTypeKey(String collectionTypeKey) {
096        this.collectionTypeKey = collectionTypeKey;
097    }
098
099    public int getArgCount() {
100        return argCount;
101    }
102
103    public void setArgCount(int argCount) {
104        this.argCount = argCount;
105    }
106
107    public boolean isPipelined() {
108        return pipelined;
109    }
110
111    public void setPipelined(boolean pipelined) {
112        this.pipelined = pipelined;
113    }
114
115    public boolean isResolved() {
116        return resolved;
117    }
118
119    public void setResolved(boolean resolved) {
120        this.resolved = resolved;
121    }
122
123    public ResolutionStatus getStatus() {
124        return status;
125    }
126
127    public void setStatus(ResolutionStatus status) {
128        this.status = status;
129    }
130
131    public List<String> getOutputColumns() {
132        return outputColumns;
133    }
134
135    public void setOutputColumns(List<String> outputColumns) {
136        this.outputColumns = outputColumns;
137    }
138
139    public Map<String, List<PipelinedSourceRef>> getLineageByOutputColumn() {
140        return lineageByOutputColumn;
141    }
142
143    public void addSourceRef(String outputColumnNormalized, PipelinedSourceRef ref) {
144        lineageByOutputColumn.computeIfAbsent(outputColumnNormalized, k -> new ArrayList<>()).add(ref);
145    }
146
147    @Override
148    public String toString() {
149        return "PipelinedFunctionSignature{" + functionKey + ", cols=" + outputColumns.size()
150                + ", resolved=" + resolved + ", status=" + status + "}";
151    }
152}