-
Notifications
You must be signed in to change notification settings - Fork 141
[SQL] Connector transport/format validation in the SQL compiler #6538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...piler/src/main/java/org/dbsp/sqlCompiler/compiler/frontend/connectors/ConfigReporter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package org.dbsp.sqlCompiler.compiler.frontend.connectors; | ||
|
|
||
| import org.dbsp.sqlCompiler.compiler.IErrorReporter; | ||
| import org.dbsp.sqlCompiler.compiler.errors.SourcePosition; | ||
| import org.dbsp.sqlCompiler.compiler.errors.SourcePositionRange; | ||
| import org.dbsp.util.Utilities; | ||
|
|
||
| /** | ||
| * A reporter that can resolve field names to source positions within a JSON config object. | ||
| */ | ||
| public final class ConfigReporter { | ||
| private final IErrorReporter reporter; | ||
| private final String outerJson; | ||
| private final String configJPath; | ||
| /** Start source position of the JSON document that is being validated. */ | ||
| private final SourcePosition outerStart; | ||
|
|
||
| /** | ||
| * Creates a reporter that resolves field names to source positions within a JSON | ||
| * config object. | ||
| * | ||
| * @param reporter Underlying error reporter used to emit warnings. | ||
| * @param outerJson The raw connectors-array JSON string (the value of the SQL | ||
| * {@code 'connectors'} property). {@code configPointer} is a | ||
| * JSON Pointer path into this array that identifies the config block. | ||
| * @param configPointer JSON Pointer path to the config block within {@code outerJson} | ||
| * (e.g. {@code "/0/transport/config"}). Field-level warnings | ||
| * append a {@code /fieldName} suffix to this pointer to locate | ||
| * the exact key in the source. | ||
| * @param outerStart Absolute source position in the SQL program | ||
| * of {@code outerJson}'s first character, | ||
| * used to convert within-JSON byte offsets to source positions. | ||
| */ | ||
| public ConfigReporter(IErrorReporter reporter, String outerJson, | ||
| String configPointer, SourcePosition outerStart) { | ||
| this.reporter = reporter; | ||
| this.outerJson = outerJson; | ||
| this.configJPath = configPointer; | ||
| this.outerStart = outerStart; | ||
| } | ||
|
|
||
| /** | ||
| * Report a warning at the key token identified by | ||
| * {@code relativePath} within the config object. {@code relativePath} is a | ||
| * slash-separated relative JSON Pointer suffix (e.g. {@code "delimiter"} or | ||
| * {@code "quoting/delimiter"}); it is appended to the config pointer. | ||
| */ | ||
| public void warnPath(String relativePath, String category, String message) { | ||
| String pointer = this.configJPath + "/" + relativePath; | ||
| SourcePosition pos = Utilities.jsonPointerLocation(this.outerJson, pointer, false); | ||
| SourcePositionRange range = pos != null | ||
| ? pos.relativeTo(this.outerStart).asRange() | ||
| : SourcePositionRange.INVALID; | ||
| this.reporter.reportWarning(range, category, message); | ||
| } | ||
|
|
||
| /** Report a warning that does not correspond to a single field (points at the config block). */ | ||
| public void warn(String category, String message) { | ||
| SourcePosition pos = Utilities.jsonPointerLocation(this.outerJson, this.configJPath, true); | ||
| SourcePositionRange range = pos != null | ||
| ? pos.relativeTo(this.outerStart).asRange() | ||
| : SourcePositionRange.INVALID; | ||
| this.reporter.reportWarning(range, category, message); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth documenting the fail-open contract explicitly: (a) unknown transport/format names are silently skipped by the SQL compiler, (b) Jackson deserialization errors surface as warnings not errors, (c)
@JsonAnySetterkeys are not validated at all. Future contributors will otherwise assume "SQL compiler accepted it → it works." Also: this README does an excellent job of explaining mechanics, but nowhere says "the runtime is still the source of truth — don't remove Rust-side validation when you add a Java mirror." Worth a one-liner since the whole point of the doc is to guide future connector additions.