Flink Connector
Apache Flink connector for writing data directly into Apache Pinot tables, supporting offline, realtime, and upsert table types.
Last updated
Was this helpful?
Was this helpful?
<dependency>
<groupId>org.apache.pinot</groupId>
<artifactId>pinot-flink-connector</artifactId>
<version>${pinot.version}</version>
</dependency>StreamExecutionEnvironment execEnv = StreamExecutionEnvironment.getExecutionEnvironment();
execEnv.setParallelism(2);
DataStream<Row> srcRows = execEnv.fromData(...);
String controllerUrl = "http://localhost:9000";
URI controllerUri = URI.create(controllerUrl);
String controllerAddress = controllerUri.getAuthority();
String controllerPath = controllerUri.getPath();
if (controllerPath != null && !controllerPath.isEmpty() && !"/".equals(controllerPath)) {
controllerAddress += controllerPath.endsWith("/") ? controllerPath.substring(0, controllerPath.length() - 1)
: controllerPath;
}
Properties properties = new Properties();
properties.setProperty(PinotAdminTransport.ADMIN_TRANSPORT_SCHEME, controllerUri.getScheme());
try (PinotAdminClient adminClient = new PinotAdminClient(controllerAddress, properties)) {
Schema schema = adminClient.getSchemaClient().getSchemaObject("myTable");
TableConfig tableConfig =
adminClient.getTableClient().getTableConfigObjectForType("myTable", TableType.OFFLINE);
srcRows.sinkTo(new PinotSink<>(
new FlinkRowGenericRowConverter(typeInfo),
tableConfig,
schema,
controllerUrl));
}
execEnv.execute();// This code no longer works on Flink 2.x
srcRows.addSink(new PinotSinkFunction<>(...));// Use this for Flink 2.2.0 and later
srcRows.sinkTo(new PinotSink<>(...));