forked from linkedin/Hoptimator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e493c0
commit b2ef1d5
Showing
4 changed files
with
68 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
plugins { | ||
id 'java' | ||
id 'idea' | ||
} | ||
|
||
dependencies { | ||
implementation project(':hoptimator-catalog') | ||
implementation libs.kafkaClients | ||
implementation libs.calciteCore | ||
implementation libs.flinkConnectorKafka | ||
|
||
testImplementation libs.junit | ||
testImplementation libs.assertj | ||
} | ||
|
||
tasks.withType(JavaCompile) { | ||
options.compilerArgs << '-Xlint:deprecation' | ||
options.compilerArgs << '-Xlint:unchecked' | ||
} | ||
|
||
idea { | ||
module { | ||
downloadJavadoc = true | ||
downloadSources = true | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...ka-adapter/src/main/java/com/linkedin/hoptimator/catalog/kafka/RawKafkaSchemaFactory.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.catalog.kafka; | ||
|
||
import org.apache.calcite.schema.Schema; | ||
import org.apache.calcite.schema.SchemaFactory; | ||
import org.apache.calcite.schema.SchemaPlus; | ||
|
||
import org.apache.kafka.clients.admin.AdminClient; | ||
|
||
import com.linkedin.hoptimator.catalog.ConfigProvider; | ||
import com.linkedin.hoptimator.catalog.DataType; | ||
import com.linkedin.hoptimator.catalog.Database; | ||
import com.linkedin.hoptimator.catalog.DatabaseSchema; | ||
import com.linkedin.hoptimator.catalog.TableLister; | ||
import com.linkedin.hoptimator.catalog.TableResolver; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class RawKafkaSchemaFactory implements SchemaFactory { | ||
|
||
@Override | ||
public Schema create(SchemaPlus parentSchema, String name, Map<String, Object> operand) { | ||
DataType.Struct rowType = DataType.struct() | ||
.with("PAYLOAD", DataType.VARCHAR_NULL); | ||
ConfigProvider configProvider = ConfigProvider.from(operand).withPrefix("properties.") | ||
.with("connector", "kafka") | ||
.with("format", "raw") | ||
.with("topic", x -> x); | ||
TableLister tableLister = () -> { | ||
AdminClient client = AdminClient.create(operand); | ||
Collection<String> topics = client.listTopics().names().get(); | ||
client.close(); | ||
return topics; | ||
}; | ||
TableResolver resolver = x -> rowType.rel(); | ||
Database database = new Database(name, tableLister, resolver, configProvider); | ||
return new DatabaseSchema(database); | ||
} | ||
} |
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