Yizhou-Yang commented on code in PR #7580:
URL: https://github.com/apache/inlong/pull/7580#discussion_r1139914092
##########
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:
refresh the code to see the latest commit, both a javadoc and some inline
comments, adding more now
##########
inlong-sort/sort-connectors/jdbc/src/main/java/org/apache/inlong/sort/jdbc/internal/JdbcMultiBatchingOutputFormat.java:
##########
@@ -302,6 +323,41 @@ private JdbcExec getOrCreateStatementExecutor(
return jdbcExec;
}
+ private JdbcExec enhanceExecutor(JdbcExec exec) throws
NoSuchFieldException, IllegalAccessException {
+ if (dirtySinkHelper.getDirtySink() == null) {
+ return null;
+ }
+ // enhance the actual executor to tablemetricstatementexecutor
+ Field subExecutor;
+ if (exec instanceof TableBufferReducedStatementExecutor) {
+ subExecutor =
TableBufferReducedStatementExecutor.class.getDeclaredField("upsertExecutor");
+ } else if (exec instanceof TableBufferedStatementExecutor) {
+ subExecutor =
TableBufferedStatementExecutor.class.getDeclaredField("statementExecutor");
+ } else {
+ throw new RuntimeException("table enhance failed, can't enhance "
+ exec.getClass());
+ }
+ subExecutor.setAccessible(true);
+ TableSimpleStatementExecutor executor = (TableSimpleStatementExecutor)
subExecutor.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);
+ newExecutor.setMultipleSink(true);
+ if (exec instanceof TableBufferedStatementExecutor) {
+ subExecutor =
TableBufferedStatementExecutor.class.getDeclaredField("valueTransform");
+ subExecutor.setAccessible(true);
+ Function<RowData, RowData> valueTransform = (Function<RowData,
RowData>) subExecutor.get(exec);
+ newExecutor.setValueTransform(valueTransform);
+ return (JdbcExec) newExecutor;
+ }
+ subExecutor.set(exec, newExecutor);
Review Comment:
refresh the code to see the latest commit, both a javadoc and some inline
comments, adding more now
--
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]