-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Pipeline controller and Kafka JDBC driver (#73)
* Add Pipeline controller and Kafka JDBC driver * PR review fixes h/t @jogrogan
- Loading branch information
1 parent
e12144b
commit 159a0e9
Showing
36 changed files
with
893 additions
and
101 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
apiVersion: hoptimator.linkedin.com/v1alpha1 | ||
kind: Database | ||
metadata: | ||
name: kafka-database | ||
spec: | ||
schema: KAFKA | ||
url: jdbc:kafka://bootstrap.servers=localhost:9092 | ||
dialect: Calcite | ||
|
||
--- | ||
|
||
apiVersion: hoptimator.linkedin.com/v1alpha1 | ||
kind: TableTemplate | ||
metadata: | ||
name: kafka-template | ||
spec: | ||
databases: | ||
- kafka-database | ||
yaml: | | ||
apiVersion: kafka.strimzi.io/v1beta2 | ||
kind: KafkaTopic | ||
metadata: | ||
name: {{name}} | ||
namespace: kafka | ||
labels: | ||
strimzi.io/cluster: one | ||
spec: | ||
topicName: {{table}} | ||
partitions: 1 | ||
replicas: 1 | ||
config: | ||
retention.ms: 7200000 | ||
segment.bytes: 1073741824 | ||
connector: | | ||
connector = kafka | ||
topic = {{table}} | ||
properties.bootstrap.servers = localhost:9092 | ||
--- | ||
|
||
apiVersion: kafka.strimzi.io/v1beta2 | ||
kind: KafkaTopic | ||
metadata: | ||
name: existing-topic-1 | ||
namespace: kafka | ||
labels: | ||
strimzi.io/cluster: one | ||
spec: | ||
partitions: 1 | ||
replicas: 1 | ||
config: | ||
retention.ms: 7200000 | ||
segment.bytes: 1073741824 | ||
|
||
--- | ||
|
||
apiVersion: kafka.strimzi.io/v1beta2 | ||
kind: KafkaTopic | ||
metadata: | ||
name: existing-topic-2 | ||
namespace: kafka | ||
labels: | ||
strimzi.io/cluster: one | ||
spec: | ||
partitions: 1 | ||
replicas: 1 | ||
config: | ||
retention.ms: 7200000 | ||
segment.bytes: 1073741824 | ||
|
||
|
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
51 changes: 0 additions & 51 deletions
51
hoptimator-jdbc/src/test/java/com/linkedin/hoptimator/jdbc/QuidemTestBase.java
This file was deleted.
Oops, something went wrong.
99 changes: 99 additions & 0 deletions
99
hoptimator-jdbc/src/testFixtures/java/com/linkedin/hoptimator/jdbc/QuidemTestBase.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,99 @@ | ||
package com.linkedin.hoptimator.jdbc; | ||
|
||
import com.linkedin.hoptimator.jdbc.HoptimatorDriver; | ||
import com.linkedin.hoptimator.util.ConnectionService; | ||
import com.linkedin.hoptimator.util.DeploymentService; | ||
import com.linkedin.hoptimator.util.Sink; | ||
import com.linkedin.hoptimator.util.planner.PipelineRel; | ||
|
||
import net.hydromatic.quidem.AbstractCommand; | ||
import net.hydromatic.quidem.Command; | ||
import net.hydromatic.quidem.CommandHandler; | ||
import net.hydromatic.quidem.Quidem; | ||
|
||
import org.apache.calcite.rel.RelNode; | ||
import org.apache.calcite.jdbc.CalciteConnection; | ||
|
||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeAll; | ||
|
||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.io.Reader; | ||
import java.io.Writer; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.nio.file.Files; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
|
||
public abstract class QuidemTestBase { | ||
|
||
protected void run(String resourceName) throws IOException, URISyntaxException { | ||
run(Thread.currentThread().getContextClassLoader().getResource(resourceName).toURI()); | ||
} | ||
|
||
protected void run(URI resource) throws IOException { | ||
File in = new File(resource); | ||
File out = File.createTempFile(in.getName(), ".out"); | ||
try (Reader r = new FileReader(in); | ||
Writer w = new PrintWriter(out)) { | ||
Quidem.Config config = Quidem.configBuilder() | ||
.withReader(r) | ||
.withWriter(w) | ||
.withConnectionFactory((x, y) -> DriverManager.getConnection("jdbc:hoptimator://" + x)) | ||
.withCommandHandler(new CustomCommandHandler()) | ||
.build(); | ||
new Quidem(config).execute(); | ||
} | ||
List<String> input = Files.readAllLines(in.toPath(), StandardCharsets.UTF_8); | ||
List<String> output = Files.readAllLines(out.toPath(), StandardCharsets.UTF_8); | ||
Assertions.assertTrue(!input.isEmpty(), "input script is empty"); | ||
Assertions.assertTrue(!output.isEmpty(), "script output is empty"); | ||
for (String line : output) { | ||
System.out.println(line); | ||
} | ||
Assertions.assertIterableEquals(input, output); | ||
} | ||
|
||
private static class CustomCommandHandler implements CommandHandler { | ||
@Override | ||
public Command parseCommand(List<String> lines, List<String> content, final String line) { | ||
List<String> copy = new ArrayList<>(); | ||
copy.addAll(lines); | ||
if (line.startsWith("spec")) { | ||
return new AbstractCommand() { | ||
@Override | ||
public void execute(Context context, boolean execute) throws Exception { | ||
if (execute) { | ||
if (!(context.connection() instanceof CalciteConnection)) { | ||
throw new IllegalArgumentException("This connection doesn't support `!specify`."); | ||
} | ||
String sql = context.previousSqlCommand().sql; | ||
CalciteConnection conn = (CalciteConnection) context.connection(); | ||
RelNode rel = HoptimatorDriver.convert(conn.createPrepareContext(), sql).root.rel; | ||
String specs = DeploymentService.plan(rel).pipeline().specify().stream() | ||
.collect(Collectors.joining("\n---\n")); | ||
context.echo(Collections.singletonList(specs)); | ||
} else { | ||
context.echo(content); | ||
} | ||
context.echo(copy); | ||
} | ||
}; | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.