Yizhou-Yang commented on code in PR #7580:
URL: https://github.com/apache/inlong/pull/7580#discussion_r1139798744
##########
inlong-sort/sort-connectors/jdbc/src/main/java/org/apache/inlong/sort/jdbc/internal/JdbcBatchingOutputFormat.java:
##########
@@ -365,6 +381,41 @@ public synchronized void flush() throws IOException {
}
}
+ private JdbcExec enhanceExecutor(JdbcExec exec) throws
NoSuchFieldException, IllegalAccessException {
+ if (dirtySink == null) {
+ return null;
+ }
+ final DirtySinkHelper dirtySinkHelper = new
DirtySinkHelper<>(dirtyOptions, dirtySink);
+ // enhance the actual executor to tablemetricstatementexecutor
+ Field ExecutorType;
+ if (exec instanceof TableBufferReducedStatementExecutor) {
+ ExecutorType =
TableBufferReducedStatementExecutor.class.getDeclaredField("upsertExecutor");
+ } else if (exec instanceof TableBufferedStatementExecutor) {
+ ExecutorType =
TableBufferedStatementExecutor.class.getDeclaredField("statementExecutor");
+ } else {
+ throw new RuntimeException("table enhance failed, can't enhance "
+ exec.getClass());
+ }
+ ExecutorType.setAccessible(true);
+ TableSimpleStatementExecutor executor = (TableSimpleStatementExecutor)
ExecutorType.get(exec);
+ Field statementFactory =
TableSimpleStatementExecutor.class.getDeclaredField("stmtFactory");
+ Field rowConverter =
TableSimpleStatementExecutor.class.getDeclaredField("converter");
+ statementFactory.setAccessible(true);
+ rowConverter.setAccessible(true);
+ final StatementFactory stmtFactory = (StatementFactory)
statementFactory.get(executor);
+ final JdbcRowConverter converter = (JdbcRowConverter)
rowConverter.get(executor);
+ TableMetricStatementExecutor newExecutor =
+ new TableMetricStatementExecutor(stmtFactory, converter,
dirtySinkHelper, sinkMetricData);
+ if (exec instanceof TableBufferedStatementExecutor) {
+ Field transform =
TableBufferedStatementExecutor.class.getDeclaredField("valueTransform");
+ transform.setAccessible(true);
+ Function<RowData, RowData> valueTransform = (Function<RowData,
RowData>) transform.get(exec);
+ newExecutor.setValueTransform(valueTransform);
+ return (JdbcExec) newExecutor;
+ }
+ ExecutorType.set(exec, newExecutor);
Review Comment:
added
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]