Skip to content

Commit 3f1a571

Browse files
authored
Support connector hints (#117)
* Support connector hints * Thread through partial view name * nit * update README * partialViewName -> pipelineName * output template as 'pipeline' * update README * Revert back to hints approach * update README
1 parent 8f5f195 commit 3f1a571

File tree

6 files changed

+28
-10
lines changed

6 files changed

+28
-10
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ While Deployers are extensible, today the primary deployer is to Kubernetes. The
156156
and [K8sJobDeployer](hoptimator-k8s/src/main/java/com/linkedin/hoptimator/k8s/K8sJobDeployer.java) (for job-templates)
157157
provide a few template defaults that you can choose to include in your templates:
158158

159-
K8sSourceDeployer: `name, database, schema, table`
159+
K8sSourceDeployer: `name, database, schema, table, pipeline`
160160

161-
K8sJobDeployer: `name, database, schema, table, sql, flinksql, flinkconfigs`
161+
K8sJobDeployer: `name, database, schema, table, pipeline, sql, flinksql, flinkconfigs`
162162

163163
However, it is often a case where you want to add additional information to the templates that will be passed through during Source or Job creation.
164164
There are two mechanisms to achieve this:

hoptimator-jdbc/src/main/java/com/linkedin/hoptimator/jdbc/HoptimatorDdlExecutor.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,13 @@ public void execute(SqlCreateMaterializedView create, CalcitePrepare.Context con
187187

188188
// Support "partial views", i.e. CREATE VIEW FOO$BAR, where the view name
189189
// is "foo-bar" and the sink is just FOO.
190-
String sinkName = viewName.split("\\$", 2)[0];
190+
String[] viewParts = viewName.split("\\$", 2);
191+
String sinkName = viewParts[0];
192+
String pipelineName = database + "-" + sinkName;
193+
if (viewParts.length > 1) {
194+
pipelineName = pipelineName + "-" + viewParts[1];
195+
}
196+
connectionProperties.setProperty(DeploymentService.PIPELINE_OPTION, pipelineName);
191197
List<String> sinkPath = new ArrayList<>();
192198
sinkPath.addAll(schemaPath);
193199
sinkPath.add(sinkName);

hoptimator-k8s/src/main/java/com/linkedin/hoptimator/k8s/K8sConnector.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class K8sConnector implements Connector {
3030
@Override
3131
public Map<String, String> configure() throws SQLException {
3232
Template.Environment env =
33-
new Template.SimpleEnvironment().with("name", source.database() + "-" + source.table().toLowerCase(Locale.ROOT))
33+
new Template.SimpleEnvironment()
34+
.with("name", source.database() + "-" + source.table().toLowerCase(Locale.ROOT))
3435
.with("database", source.database())
3536
.with("table", source.table())
3637
.with(source.options());

hoptimator-kafka/src/test/resources/kafka-ddl.id

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ metadata:
4343
strimzi.io/cluster: one
4444
spec:
4545
topicName: existing-topic-2
46-
partitions: 1
46+
partitions: 4
4747
replicas: 1
4848
config:
4949
retention.ms: 7200000

hoptimator-util/src/main/java/com/linkedin/hoptimator/util/DeploymentService.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.ArrayList;
55
import java.util.Collection;
66
import java.util.Collections;
7+
import java.util.LinkedHashMap;
78
import java.util.List;
89
import java.util.Map;
910
import java.util.Properties;
@@ -29,6 +30,8 @@
2930
public final class DeploymentService {
3031

3132
private static final String HINT_OPTION = "hints";
33+
public static final String PIPELINE_OPTION = "pipeline";
34+
3235
private DeploymentService() {
3336
}
3437

@@ -89,10 +92,16 @@ public static PipelineRel.Implementor plan(RelRoot root, List<RelOptMaterializat
8992
return implementor;
9093
}
9194

95+
// User provided hints will be passed through the "hints" field as KEY=VALUE pairs separated by commas.
96+
// We can also configure additional properties to pass through as hints to the deployer.
9297
public static Map<String, String> parseHints(Properties connectionProperties) {
98+
Map<String, String> hints = new LinkedHashMap<>();
9399
if (connectionProperties.containsKey(HINT_OPTION)) {
94-
return Splitter.on(',').withKeyValueSeparator('=').split(connectionProperties.getProperty(HINT_OPTION));
100+
hints.putAll(Splitter.on(',').withKeyValueSeparator('=').split(connectionProperties.getProperty(HINT_OPTION)));
101+
}
102+
if (connectionProperties.containsKey(PIPELINE_OPTION)) {
103+
hints.put(PIPELINE_OPTION, connectionProperties.getProperty(PIPELINE_OPTION));
95104
}
96-
return Collections.emptyMap();
105+
return hints;
97106
}
98107
}

hoptimator-util/src/main/java/com/linkedin/hoptimator/util/planner/PipelineRel.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.sql.SQLException;
44
import java.util.Arrays;
5-
import java.util.Collections;
65
import java.util.LinkedHashMap;
76
import java.util.List;
87
import java.util.Map;
@@ -50,12 +49,13 @@ class Implementor {
5049
private final ImmutablePairList<Integer, String> targetFields;
5150
private final Map<String, String> hints;
5251
private RelNode query;
53-
private Sink sink = new Sink("PIPELINE", Arrays.asList("PIPELINE", "SINK"), Collections.emptyMap());
52+
private Sink sink;
5453
private RelDataType sinkRowType = null;
5554

5655
public Implementor(ImmutablePairList<Integer, String> targetFields, Map<String, String> hints) {
5756
this.targetFields = targetFields;
5857
this.hints = hints;
58+
this.sink = new Sink("PIPELINE", Arrays.asList("PIPELINE", "SINK"), hints);
5959
}
6060

6161
public void visit(RelNode node) throws SQLException {
@@ -75,7 +75,9 @@ public void visit(RelNode node) throws SQLException {
7575
* a connector. The connector is configured via `CREATE TABLE...WITH(...)`.
7676
*/
7777
public void addSource(String database, List<String> path, RelDataType rowType, Map<String, String> options) {
78-
sources.put(new Source(database, path, addKeysAsOption(options, rowType)), rowType);
78+
Map<String, String> newOptions = addKeysAsOption(options, rowType);
79+
newOptions.putAll(this.hints);
80+
sources.put(new Source(database, path, newOptions), rowType);
7981
}
8082

8183
/**

0 commit comments

Comments
 (0)