use of com.starrocks.connector.flink.row.StarRocksSinkOP in project plugins by qlangtech.
the class StarRocksSinkFactory method createSinkFunction.
private SinkFunction<DTO> createSinkFunction(String dbName, final String targetTabName, ISelectedTab tab, String jdbcUrl, DorisSourceFactory dsFactory, BasicDorisStarRocksWriter.Separator separator) {
// import org.apache.flink.table.types.DataType;
TableSchema.Builder schemaBuilder = TableSchema.builder();
String[] fieldKeys = new String[tab.getCols().size()];
if (fieldKeys.length < 1) {
throw new IllegalArgumentException("fieldKeys.length can not small than 1");
}
int index = 0;
List<String> pks = Lists.newArrayList();
// org.apache.flink.table.types.DataType dataType = null;
for (ISelectedTab.ColMeta cm : tab.getCols()) {
// dataType = ;
if (cm.isPk()) {
pks.add(cm.getName());
}
schemaBuilder.field(cm.getName(), mapFlinkColType(cm.isPk(), cm.getType()));
fieldKeys[index++] = cm.getName();
}
if (!pks.isEmpty()) {
schemaBuilder.primaryKey(pks.toArray(new String[pks.size()]));
}
return StarRocksSink.sink(// the table structure
schemaBuilder.build(), // the sink options
createRocksSinkOptions(dbName, targetTabName, jdbcUrl, dsFactory, separator), // set the slots with streamRowData
(slots, streamRowData) -> {
for (int i = 0; i < fieldKeys.length; i++) {
slots[i] = (DTO.EventType.DELETE == streamRowData.getEventType()) ? streamRowData.getBefore().get(fieldKeys[i]) : streamRowData.getAfter().get(fieldKeys[i]);
}
StarRocksSinkOP sinkOp = getSinkOP(streamRowData.getEventType());
slots[fieldKeys.length] = sinkOp.ordinal();
});
}
Aggregations