-
Notifications
You must be signed in to change notification settings - Fork 12
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
WIP: Add support for external engines #84
Draft
ryannedolan
wants to merge
3
commits into
main
Choose a base branch
from
engines
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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
13 changes: 13 additions & 0 deletions
13
hoptimator-api/src/main/java/com/linkedin/hoptimator/Engine.java
This file contains 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,13 @@ | ||
package com.linkedin.hoptimator; | ||
|
||
import javax.sql.DataSource; | ||
|
||
/** An execution engine. */ | ||
public interface Engine { | ||
|
||
String engineName(); | ||
|
||
DataSource dataSource(); | ||
|
||
SqlDialect dialect(); | ||
} |
This file contains 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 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
40 changes: 40 additions & 0 deletions
40
hoptimator-k8s/src/main/java/com/linkedin/hoptimator/k8s/K8sEngine.java
This file contains 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,40 @@ | ||
package com.linkedin.hoptimator.k8s; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import com.linkedin.hoptimator.Engine; | ||
import com.linkedin.hoptimator.SqlDialect; | ||
|
||
import org.apache.calcite.adapter.jdbc.JdbcSchema; | ||
|
||
|
||
public class K8sEngine implements Engine { | ||
|
||
private final String name; | ||
private final String url; | ||
private final SqlDialect dialect; | ||
private final String driver; | ||
|
||
public K8sEngine(String name, String url, SqlDialect dialect, String driver) { | ||
this.name = name; | ||
this.url = url; | ||
this.dialect = dialect; | ||
this.driver = driver; | ||
} | ||
|
||
@Override | ||
public String engineName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public DataSource dataSource() { | ||
// TODO support username, password via Secrets | ||
return JdbcSchema.dataSource(url, driver, null, null); | ||
} | ||
|
||
@Override | ||
public SqlDialect dialect() { | ||
return dialect; | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
hoptimator-k8s/src/main/java/com/linkedin/hoptimator/k8s/K8sEngineTable.java
This file contains 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,90 @@ | ||
package com.linkedin.hoptimator.k8s; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import org.apache.calcite.adapter.jdbc.JdbcSchema; | ||
import org.apache.calcite.schema.Schema; | ||
|
||
import io.kubernetes.client.openapi.models.V1ObjectMeta; | ||
|
||
import com.linkedin.hoptimator.Engine; | ||
import com.linkedin.hoptimator.SqlDialect; | ||
import com.linkedin.hoptimator.k8s.models.V1alpha1Engine; | ||
import com.linkedin.hoptimator.k8s.models.V1alpha1EngineList; | ||
import com.linkedin.hoptimator.k8s.models.V1alpha1EngineSpec; | ||
import com.linkedin.hoptimator.util.HoptimatorJdbcSchema; | ||
|
||
|
||
public class K8sEngineTable extends K8sTable<V1alpha1Engine, V1alpha1EngineList, K8sEngineTable.Row> { | ||
|
||
// CHECKSTYLE:OFF | ||
public static class Row { | ||
public String NAME; | ||
public String URL; | ||
public String DIALECT; | ||
public String DRIVER; | ||
public String[] DATABASES; | ||
|
||
public Row(String name, String url, String dialect, String driver, String[] databases) { | ||
this.NAME = name; | ||
this.URL = url; | ||
this.DIALECT = dialect; | ||
this.DRIVER = driver; | ||
this.DATABASES = databases; | ||
} | ||
} | ||
// CHECKSTYLE:ON | ||
|
||
public K8sEngineTable(K8sContext context) { | ||
super(context, K8sApiEndpoints.ENGINES, Row.class); | ||
} | ||
|
||
/** Engines supporting a given database. */ | ||
public List<Engine> forDatabase(String database) { | ||
return rows().stream().filter(x -> x.DATABASES == null | ||
|| x.DATABASES.length == 0 | ||
|| Arrays.asList(x.DATABASES).contains(database)) | ||
.map(x -> new K8sEngine(x.NAME, x.URL, dialect(x), x.DRIVER)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public Row toRow(V1alpha1Engine obj) { | ||
return new Row(obj.getMetadata().getName(), obj.getSpec().getUrl(), | ||
Optional.ofNullable(obj.getSpec().getDialect()).map(x -> x.toString()).orElseGet(() -> null), | ||
obj.getSpec().getDriver(), obj.getSpec().getDatabases() != null ? | ||
obj.getSpec().getDatabases().toArray(new String[0]) : null); | ||
} | ||
|
||
@Override | ||
public V1alpha1Engine fromRow(Row row) { | ||
K8sUtils.checkK8sName(row.NAME); | ||
return new V1alpha1Engine().kind(K8sApiEndpoints.ENGINES.kind()) | ||
.apiVersion(K8sApiEndpoints.ENGINES.apiVersion()) | ||
.metadata(new V1ObjectMeta().name(row.NAME)) | ||
.spec(new V1alpha1EngineSpec().url(row.URL) | ||
.dialect(V1alpha1EngineSpec.DialectEnum.fromValue(row.DIALECT)) | ||
.driver(row.DRIVER).databases(Arrays.asList(row.DATABASES))); | ||
} | ||
|
||
private static SqlDialect dialect(Row row) { | ||
if (row.DIALECT == null) { | ||
return SqlDialect.ANSI; | ||
} | ||
switch (row.DIALECT) { | ||
case "Flink": | ||
return SqlDialect.FLINK; | ||
default: | ||
return SqlDialect.valueOf(row.DIALECT); | ||
} | ||
} | ||
|
||
@Override | ||
public Schema.TableType getJdbcTableType() { | ||
return Schema.TableType.SYSTEM_TABLE; | ||
} | ||
} |
This file contains 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 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 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 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.
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.
nit: should prob be lowercase so we don't need to disable checkstyle
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.
This is a quirk of Calcite. These fields are referenced in the generated code, and things go sideways if they aren't all caps.