-
Notifications
You must be signed in to change notification settings - Fork 16
Add support for Flink Beam templates #163
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
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7e7d27c
Add new FlinkBeam type and regenerate k8s models
jogrogan 873c95a
Add new template option to avoid matching if a specific field is present
jogrogan 74350cf
Add field map logic for trivial expressions + lazy evaluation of temp…
jogrogan 0051c5b
Add template equality checks
jogrogan 93c108f
Add beam template, some testing, and some fixes
jogrogan bde03a0
Add fieldMap support for nested field references and add more thoroug…
jogrogan 2bbbe6b
Hide magic strings
jogrogan 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
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,26 @@ | ||
| ## This template adds Flink Beam support. | ||
|
|
||
| apiVersion: hoptimator.linkedin.com/v1alpha1 | ||
| kind: JobTemplate | ||
| metadata: | ||
| name: flink-beam-sqljob-template | ||
| spec: | ||
| yaml: | | ||
| apiVersion: hoptimator.linkedin.com/v1alpha1 | ||
| kind: SqlJob | ||
| metadata: | ||
| name: {{name}} | ||
| spec: | ||
| dialect: FlinkBeam | ||
| executionMode: Streaming | ||
| sql: | ||
| - PLACEHOLDER | ||
| configs: | ||
| {{flink.app.type==BEAM}} | ||
| source.group.id: hoptimator-flink-beam-{{pipeline}} | ||
| source.schemas: {{sourceSchemas}} | ||
| source.tables: {{sourceTables}} | ||
| sink.schema: {{schema}} | ||
| sink.table: {{table}} | ||
| fields: {{fieldMap}} | ||
| {{flinkconfigs}} | ||
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
72 changes: 66 additions & 6 deletions
72
hoptimator-api/src/main/java/com/linkedin/hoptimator/Job.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 |
|---|---|---|
| @@ -1,30 +1,90 @@ | ||
| package com.linkedin.hoptimator; | ||
|
|
||
| import java.util.function.Function; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
|
|
||
| /** | ||
| * Represents a data pipeline job with lazy-evaluated template functions. | ||
| * | ||
| * <p>A Job encapsulates the configuration and execution logic for a data pipeline, | ||
| * including the destination sink and a collection of lazy-evaluated functions that | ||
| * generate SQL scripts, field mappings, and other template values on demand. | ||
| */ | ||
| public class Job implements Deployable { | ||
|
|
||
| private final String name; | ||
| private final Set<Source> sources; | ||
| private final Sink sink; | ||
| private final Function<SqlDialect, String> sql; | ||
|
|
||
| public Job(String name, Sink sink, Function<SqlDialect, String> sql) { | ||
| /** | ||
| * Lazy-evaluated template functions that generate various outputs for the job. | ||
| * | ||
| * <p>This map contains functions that are evaluated on-demand when specific | ||
| * template values are needed. Each function takes a {@link SqlDialect} parameter | ||
| * and returns a string representation of the requested output. | ||
| * | ||
| * @see ThrowingFunction | ||
| * @see SqlDialect | ||
| */ | ||
| private final Map<String, ThrowingFunction<SqlDialect, String>> lazyEvals; | ||
|
|
||
| public Job(String name, Set<Source> sources, Sink sink, Map<String, ThrowingFunction<SqlDialect, String>> lazyEvals) { | ||
| this.name = name; | ||
| this.sources = sources; | ||
| this.sink = sink; | ||
| this.sql = sql; | ||
| this.lazyEvals = lazyEvals; | ||
| } | ||
|
|
||
| public String name() { | ||
| return name; | ||
| } | ||
|
|
||
| public Set<Source> sources() { | ||
| return sources; | ||
| } | ||
|
|
||
| public Sink sink() { | ||
| return sink; | ||
| } | ||
|
|
||
| public Function<SqlDialect, String> sql() { | ||
| return sql; | ||
| public ThrowingFunction<SqlDialect, String> sql() { | ||
| return eval("sql"); | ||
| } | ||
|
|
||
| public ThrowingFunction<SqlDialect, String> query() { | ||
| return eval("query"); | ||
| } | ||
|
|
||
| public ThrowingFunction<SqlDialect, String> fieldMap() { | ||
| return eval("fieldMap"); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves a lazy-evaluated template function by key. | ||
| * | ||
| * <p>This method provides access to the template functions stored in {@link #lazyEvals}. | ||
| * The returned function can be called with a {@link SqlDialect} to generate the | ||
| * corresponding output string. | ||
| * | ||
| * <p><strong>Available Keys:</strong> | ||
| * <ul> | ||
| * <li><code>"sql"</code> - Complete SQL script with INSERT INTO statements</li> | ||
| * <li><code>"query"</code> - SELECT query portion only</li> | ||
| * <li><code>"fieldMap"</code> - JSON mapping of source to destination fields</li> | ||
| * </ul> | ||
| * | ||
| * @param key The template function key to retrieve | ||
| * @return The lazy-evaluated function, or {@code null} if the key doesn't exist | ||
| * | ||
| * @see #lazyEvals | ||
| * @see ThrowingFunction#apply(Object) | ||
| */ | ||
| private ThrowingFunction<SqlDialect, String> eval(String key) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is still weird, but at least it's private now. |
||
| if (!lazyEvals.containsKey(key)) { | ||
| throw new IllegalArgumentException("Unknown eval key: " + key + ". Available keys: " + lazyEvals.keySet()); | ||
| } | ||
| return lazyEvals.get(key); | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
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
12 changes: 12 additions & 0 deletions
12
hoptimator-api/src/main/java/com/linkedin/hoptimator/ThrowingFunction.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,12 @@ | ||
| package com.linkedin.hoptimator; | ||
|
|
||
| import java.sql.SQLException; | ||
|
|
||
|
|
||
| /** | ||
| * Functional interface that allows functions to throw SQLException. | ||
| */ | ||
| @FunctionalInterface | ||
| public interface ThrowingFunction<T, R> { | ||
| R apply(T t) throws SQLException; | ||
| } |
12 changes: 12 additions & 0 deletions
12
hoptimator-api/src/main/java/com/linkedin/hoptimator/ThrowingSupplier.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,12 @@ | ||
| package com.linkedin.hoptimator; | ||
|
|
||
| import java.sql.SQLException; | ||
|
|
||
|
|
||
| /** | ||
| * Functional interface that allows suppliers to throw SQLException. | ||
| */ | ||
| @FunctionalInterface | ||
| public interface ThrowingSupplier<T> { | ||
| T get() throws SQLException; | ||
| } |
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
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
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
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
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.
super cool