001package gudusoft.gsqlparser.lineage.v2.model;
002
003import java.util.Arrays;
004import java.util.Collections;
005import java.util.List;
006import java.util.Map;
007
008/**
009 * A unit of input text (Sections 7.8 and 12). A unit whose analysis failed is still recorded, as a
010 * placeholder with analysisCompleteness FAILED (Section 6.5). Generated from the schema definition
011 * SourceUnit by scripts/sqllr/gen_type_model.py; do not edit.
012 *
013 * @since 4.2.17
014 */
015public final class SourceUnit extends SqllrObject {
016
017    /** The members the schema defines, in schema order. */
018    public static final List<String> MEMBERS = Collections.unmodifiableList(Arrays.asList("ref", "identityKind", "unitId", "analysisContextRef", "analysisContextId", "namespace", "logicalName", "contextDomain", "uri", "originKind", "parentUnitRef", "sitePath", "siteSpan", "originMapping", "derivedTextStatus", "digests", "resolutionInputDigests", "contentDigest", "siteStatementRef", "siteOrdinal", "variantOrdinal", "originMap", "decoding", "text", "analysisCompleteness", "featureCompleteness", "diagnosticRefs", "extensions"));
019
020    /** The members the schema requires. */
021    public static final List<String> REQUIRED = Collections.unmodifiableList(Arrays.<String>asList("ref", "identityKind", "analysisContextRef", "originKind", "analysisCompleteness"));
022
023    /** Reads a JSON object as a {@code SourceUnit}. */
024    public static final Reader<SourceUnit> READER = new Reader<SourceUnit>() {
025        @Override
026        public SourceUnit read(Object json) {
027            return fromJson(json);
028        }
029    };
030
031    private SourceUnit(Map<String, Object> members) {
032        super(members);
033    }
034
035    /** A {@code SourceUnit} with the members of a JSON object, all kept. */
036    public static SourceUnit fromJson(Object json) {
037        return new SourceUnit(members(json, "SourceUnit"));
038    }
039
040    public static Builder builder() {
041        return new Builder(null);
042    }
043
044    /** A builder holding every member of this object. */
045    public Builder toBuilder() {
046        return new Builder(toJson());
047    }
048
049    /**
050     * The member {@code ref}. A document-local reference: an integer that is unique across the
051     * whole document (one reference space for every object that carries a ref). Local references
052     * are assigned after merging and have no meaning outside the document (Sections 6.1 and 13).
053     * Null when absent; throws IllegalStateException when the member holds another JSON type.
054     */
055    public Long getRef() {
056        return integer("ref");
057    }
058
059    /**
060     * The member {@code identityKind}. The kind of a source unit identity. Registry group
061     * 'sourceUnitIdentityKinds' (Section 7.8). Null when absent; throws IllegalStateException when
062     * the member holds another JSON type.
063     */
064    public String getIdentityKind() {
065        return string("identityKind");
066    }
067
068    /**
069     * The member {@code unitId}. The portable source unit id; absent for LOCAL units (identity
070     * stage: ID_MISSING when a NAMED or CONTENT_ADDRESSED unit omits it). An id computed by
071     * SourceUnitIdV1: 'su1-' followed by 64 lowercase hexadecimal characters of a SHA-256 digest
072     * (algorithms/identity-v1.md). Null when absent; throws IllegalStateException when the member
073     * holds another JSON type.
074     */
075    public String getUnitId() {
076        return string("unitId");
077    }
078
079    /**
080     * The member {@code analysisContextRef}. The analysis context under which the document asserts
081     * the content of this unit (an object of analysisContexts). A merged document holds one source
082     * unit record per unit and context. A document-local reference: an integer that is unique
083     * across the whole document (one reference space for every object that carries a ref). Local
084     * references are assigned after merging and have no meaning outside the document (Sections 6.1
085     * and 13). Null when absent; throws IllegalStateException when the member holds another JSON
086     * type.
087     */
088    public Long getAnalysisContextRef() {
089        return integer("analysisContextRef");
090    }
091
092    /**
093     * The member {@code analysisContextId}. AnalysisContextV1 of this unit: the manifest of its
094     * analysis context, its decoding, its version digest selected by algorithms/identity-v1.md,
095     * Section 5.5, and its resolution input digests. Present when the unit has a unitId and at
096     * least one digest (identity stage: ID_MISSING / ID_UNEXPECTED). An id computed by
097     * AnalysisContextV1: 'actx1-' followed by 64 lowercase hexadecimal characters of a SHA-256
098     * digest (algorithms/identity-v1.md). The digest of the analysis context of one source unit.
099     * Null when absent; throws IllegalStateException when the member holds another JSON type.
100     */
101    public String getAnalysisContextId() {
102        return string("analysisContextId");
103    }
104
105    /**
106     * The member {@code namespace}. The caller-provided namespace, such as a repository (NAMED
107     * units). Null when absent; throws IllegalStateException when the member holds another JSON
108     * type.
109     */
110    public String getNamespace() {
111        return string("namespace");
112    }
113
114    /**
115     * The member {@code logicalName}. The caller-provided name within the namespace, such as a path
116     * relative to the repository (NAMED units). Never an absolute local path. Null when absent;
117     * throws IllegalStateException when the member holds another JSON type.
118     */
119    public String getLogicalName() {
120        return string("logicalName");
121    }
122
123    /**
124     * The member {@code contextDomain}. The caller-declared context domain of a CONTENT_ADDRESSED
125     * unit: the domain within which, by the caller's declaration, equal content is one logical
126     * source unit (Section 7.8). An unnamed file without that declaration is a LOCAL unit. Null
127     * when absent; throws IllegalStateException when the member holds another JSON type.
128     */
129    public String getContextDomain() {
130        return string("contextDomain");
131    }
132
133    /**
134     * The member {@code uri}. A retrieval location after redaction. Not part of any identity. Null
135     * when absent; throws IllegalStateException when the member holds another JSON type.
136     */
137    public String getUri() {
138        return string("uri");
139    }
140
141    /**
142     * The member {@code originKind}. The origin of a source unit. Registry group
143     * 'sourceUnitOriginKinds' (Section 7.8). Null when absent; throws IllegalStateException when
144     * the member holds another JSON type.
145     */
146    public String getOriginKind() {
147        return string("originKind");
148    }
149
150    /**
151     * The member {@code parentUnitRef}. The unit a derived unit was derived from. A document-local
152     * reference: an integer that is unique across the whole document (one reference space for every
153     * object that carries a ref). Local references are assigned after merging and have no meaning
154     * outside the document (Sections 6.1 and 13). Null when absent; throws IllegalStateException
155     * when the member holds another JSON type.
156     */
157    public Long getParentUnitRef() {
158        return integer("parentUnitRef");
159    }
160
161    /**
162     * The member {@code sitePath}. The semantic path of the execution or expansion site within the
163     * parent unit's statement. A semantic path. Under the path profile sqllr-path-1 it is a
164     * '/'-joined list of steps CODE[index] (registry group pathStepCodes) that follows
165     * algorithms/path-v1.md (semantic stage: SEMANTIC_PATH_PROFILE_VIOLATION); under another
166     * declared profile it is opaque and comparable only within (producer, path profile). Null when
167     * absent; throws IllegalStateException when the member holds another JSON type.
168     */
169    public String getSitePath() {
170        return string("sitePath");
171    }
172
173    /**
174     * The member {@code siteSpan}. The location of the execution or expansion site in the parent
175     * unit (Section 12.2, rule 1). Null when absent; throws IllegalStateException when the member
176     * holds another JSON type.
177     */
178    public Span getSiteSpan() {
179        return typed("siteSpan", Span.READER);
180    }
181
182    /**
183     * The member {@code originMapping}. Whether a derived source unit is mapped to its parent.
184     * Registry group 'originMappingStatus' (Section 7.8). Null when absent; throws
185     * IllegalStateException when the member holds another JSON type.
186     */
187    public String getOriginMapping() {
188        return string("originMapping");
189    }
190
191    /**
192     * The member {@code derivedTextStatus}. Whether the derived text is proven to be the text the
193     * site executes (algorithms/fold-v1.md, Section 7.3). Required for a derived unit. Whether the
194     * text of a derived source unit is proven. Registry group 'derivedTextStatus' (Sections 7.8 and
195     * 11.4). Null when absent; throws IllegalStateException when the member holds another JSON
196     * type.
197     */
198    public String getDerivedTextStatus() {
199        return string("derivedTextStatus");
200    }
201
202    /**
203     * The member {@code digests}. Version digests of the unit, at most one per domain. They
204     * identify the version, not the unit; the first present in registry order (RAW_BYTES_SHA256,
205     * DECODED_TEXT_SHA256, REDACTED_TEXT_SHA256, KEYED_TOKEN) enters the analysis context. Null
206     * when absent; throws IllegalStateException when the member holds another JSON type.
207     */
208    public List<Digest> getDigests() {
209        return typed("digests", listOf(Digest.READER));
210    }
211
212    /**
213     * The member {@code resolutionInputDigests}. The version digest of every other source unit
214     * whose content the analysis read to resolve the names of this unit (its DDL, views, routines,
215     * session statements). A producer that cannot tell lists every input unit of the analysis. An
216     * input of the analysis context (algorithms/identity-v1.md, Section 5.5). Null when absent;
217     * throws IllegalStateException when the member holds another JSON type.
218     */
219    public List<Digest> getResolutionInputDigests() {
220        return typed("resolutionInputDigests", listOf(Digest.READER));
221    }
222
223    /**
224     * The member {@code contentDigest}. The content digest of a CONTENT_ADDRESSED unit, an input of
225     * its identity. Null when absent; throws IllegalStateException when the member holds another
226     * JSON type.
227     */
228    public Digest getContentDigest() {
229        return typed("contentDigest", Digest.READER);
230    }
231
232    /**
233     * The member {@code siteStatementRef}. The statement of the parent unit that contains the
234     * execution or expansion site. A document-local reference: an integer that is unique across the
235     * whole document (one reference space for every object that carries a ref). Local references
236     * are assigned after merging and have no meaning outside the document (Sections 6.1 and 13).
237     * Null when absent; throws IllegalStateException when the member holds another JSON type.
238     */
239    public Long getSiteStatementRef() {
240        return integer("siteStatementRef");
241    }
242
243    /**
244     * The member {@code siteOrdinal}. The 0-based ordinal of the site on its semantic path. A
245     * 0-based ordinal. Null when absent; throws IllegalStateException when the member holds another
246     * JSON type.
247     */
248    public Long getSiteOrdinal() {
249        return integer("siteOrdinal");
250    }
251
252    /**
253     * The member {@code variantOrdinal}. The 0-based ordinal of this text among the texts derived
254     * from one site. A 0-based ordinal. Null when absent; throws IllegalStateException when the
255     * member holds another JSON type.
256     */
257    public Long getVariantOrdinal() {
258        return integer("variantOrdinal");
259    }
260
261    /**
262     * The member {@code originMap}. The origin map of a MAPPED derived unit, ordered by position in
263     * the derived text. Module exact-spans, defined later. Null when absent; throws
264     * IllegalStateException when the member holds another JSON type.
265     */
266    public List<Map<String, Object>> getOriginMap() {
267        return typed("originMap", listOf(OBJECT));
268    }
269
270    /**
271     * The member {@code decoding}. Null when absent; throws IllegalStateException when the member
272     * holds another JSON type.
273     */
274    public Decoding getDecoding() {
275        return typed("decoding", Decoding.READER);
276    }
277
278    /**
279     * The member {@code text}. The embedded text (Section 12.3): the decoded text under FULL, the
280     * redacted text under REDACTED; absent under NONE. Never part of any id. Null when absent;
281     * throws IllegalStateException when the member holds another JSON type.
282     */
283    public String getText() {
284        return string("text");
285    }
286
287    /**
288     * The member {@code analysisCompleteness}. Analysis completeness of a scope. Registry group
289     * 'analysisCompleteness' (Section 4.4). Null when absent; throws IllegalStateException when the
290     * member holds another JSON type.
291     */
292    public String getAnalysisCompleteness() {
293        return string("analysisCompleteness");
294    }
295
296    /**
297     * The member {@code featureCompleteness}. Feature-scope completeness; one entry per feature.
298     * Null when absent; throws IllegalStateException when the member holds another JSON type.
299     */
300    public List<FeatureCompleteness> getFeatureCompleteness() {
301        return typed("featureCompleteness", listOf(FeatureCompleteness.READER));
302    }
303
304    /**
305     * The member {@code diagnosticRefs}. A set of local references. Null when absent; throws
306     * IllegalStateException when the member holds another JSON type.
307     */
308    public List<Long> getDiagnosticRefs() {
309        return typed("diagnosticRefs", listOf(INTEGER));
310    }
311
312    /**
313     * The member {@code extensions}. Extension data keyed by namespace. Every core object may carry
314     * it; it never takes part in a core identity. Null when absent; throws IllegalStateException
315     * when the member holds another JSON type.
316     */
317    public Map<String, Extension> getExtensions() {
318        return typed("extensions", mapOf(Extension.READER));
319    }
320
321    /** Collects the members of a new {@code SourceUnit}. */
322    public static final class Builder extends SqllrObject.Builder<SourceUnit, Builder> {
323        private Builder(Map<String, Object> from) {
324            super(from);
325        }
326
327        /** Sets the member {@code ref}; null removes it. */
328        public Builder ref(Long value) {
329            return set("ref", value);
330        }
331
332        /** Sets the member {@code identityKind}; null removes it. */
333        public Builder identityKind(String value) {
334            return set("identityKind", value);
335        }
336
337        /** Sets the member {@code unitId}; null removes it. */
338        public Builder unitId(String value) {
339            return set("unitId", value);
340        }
341
342        /** Sets the member {@code analysisContextRef}; null removes it. */
343        public Builder analysisContextRef(Long value) {
344            return set("analysisContextRef", value);
345        }
346
347        /** Sets the member {@code analysisContextId}; null removes it. */
348        public Builder analysisContextId(String value) {
349            return set("analysisContextId", value);
350        }
351
352        /** Sets the member {@code namespace}; null removes it. */
353        public Builder namespace(String value) {
354            return set("namespace", value);
355        }
356
357        /** Sets the member {@code logicalName}; null removes it. */
358        public Builder logicalName(String value) {
359            return set("logicalName", value);
360        }
361
362        /** Sets the member {@code contextDomain}; null removes it. */
363        public Builder contextDomain(String value) {
364            return set("contextDomain", value);
365        }
366
367        /** Sets the member {@code uri}; null removes it. */
368        public Builder uri(String value) {
369            return set("uri", value);
370        }
371
372        /** Sets the member {@code originKind}; null removes it. */
373        public Builder originKind(String value) {
374            return set("originKind", value);
375        }
376
377        /** Sets the member {@code parentUnitRef}; null removes it. */
378        public Builder parentUnitRef(Long value) {
379            return set("parentUnitRef", value);
380        }
381
382        /** Sets the member {@code sitePath}; null removes it. */
383        public Builder sitePath(String value) {
384            return set("sitePath", value);
385        }
386
387        /** Sets the member {@code siteSpan}; null removes it. */
388        public Builder siteSpan(Span value) {
389            return set("siteSpan", value);
390        }
391
392        /** Sets the member {@code originMapping}; null removes it. */
393        public Builder originMapping(String value) {
394            return set("originMapping", value);
395        }
396
397        /** Sets the member {@code derivedTextStatus}; null removes it. */
398        public Builder derivedTextStatus(String value) {
399            return set("derivedTextStatus", value);
400        }
401
402        /** Sets the member {@code digests}; null removes it. */
403        public Builder digests(List<Digest> value) {
404            return set("digests", value);
405        }
406
407        /** Sets the member {@code resolutionInputDigests}; null removes it. */
408        public Builder resolutionInputDigests(List<Digest> value) {
409            return set("resolutionInputDigests", value);
410        }
411
412        /** Sets the member {@code contentDigest}; null removes it. */
413        public Builder contentDigest(Digest value) {
414            return set("contentDigest", value);
415        }
416
417        /** Sets the member {@code siteStatementRef}; null removes it. */
418        public Builder siteStatementRef(Long value) {
419            return set("siteStatementRef", value);
420        }
421
422        /** Sets the member {@code siteOrdinal}; null removes it. */
423        public Builder siteOrdinal(Long value) {
424            return set("siteOrdinal", value);
425        }
426
427        /** Sets the member {@code variantOrdinal}; null removes it. */
428        public Builder variantOrdinal(Long value) {
429            return set("variantOrdinal", value);
430        }
431
432        /** Sets the member {@code originMap}; null removes it. */
433        public Builder originMap(List<Map<String, Object>> value) {
434            return set("originMap", value);
435        }
436
437        /** Sets the member {@code decoding}; null removes it. */
438        public Builder decoding(Decoding value) {
439            return set("decoding", value);
440        }
441
442        /** Sets the member {@code text}; null removes it. */
443        public Builder text(String value) {
444            return set("text", value);
445        }
446
447        /** Sets the member {@code analysisCompleteness}; null removes it. */
448        public Builder analysisCompleteness(String value) {
449            return set("analysisCompleteness", value);
450        }
451
452        /** Sets the member {@code featureCompleteness}; null removes it. */
453        public Builder featureCompleteness(List<FeatureCompleteness> value) {
454            return set("featureCompleteness", value);
455        }
456
457        /** Sets the member {@code diagnosticRefs}; null removes it. */
458        public Builder diagnosticRefs(List<Long> value) {
459            return set("diagnosticRefs", value);
460        }
461
462        /** Sets the member {@code extensions}; null removes it. */
463        public Builder extensions(Map<String, Extension> value) {
464            return set("extensions", value);
465        }
466
467        @Override
468        public SourceUnit build() {
469            return new SourceUnit(frozenMembers());
470        }
471    }
472}