This is an automated email from the ASF dual-hosted git repository.

fanrui pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/flink-connector-jdbc.git


The following commit(s) were added to refs/heads/main by this push:
     new 2ec0b817 [FLINK-35909][test] Using reflection to resolve constructor 
conflicts (#134)
2ec0b817 is described below

commit 2ec0b8173efd7df114d4facdb9f0ef4c0506ca38
Author: He Wang <[email protected]>
AuthorDate: Thu Aug 1 10:10:26 2024 +0800

    [FLINK-35909][test] Using reflection to resolve constructor conflicts (#134)
---
 ...FilterPushdownPreparedStatementVisitorTest.java | 43 ++++++++++++++++++++--
 1 file changed, 40 insertions(+), 3 deletions(-)

diff --git 
a/flink-connector-jdbc-core/src/test/java/org/apache/flink/connector/jdbc/core/table/source/JdbcFilterPushdownPreparedStatementVisitorTest.java
 
b/flink-connector-jdbc-core/src/test/java/org/apache/flink/connector/jdbc/core/table/source/JdbcFilterPushdownPreparedStatementVisitorTest.java
index 752c25da..66e7366a 100644
--- 
a/flink-connector-jdbc-core/src/test/java/org/apache/flink/connector/jdbc/core/table/source/JdbcFilterPushdownPreparedStatementVisitorTest.java
+++ 
b/flink-connector-jdbc-core/src/test/java/org/apache/flink/connector/jdbc/core/table/source/JdbcFilterPushdownPreparedStatementVisitorTest.java
@@ -46,6 +46,7 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import java.io.Serializable;
+import java.lang.reflect.Constructor;
 import java.math.BigDecimal;
 import java.sql.Connection;
 import java.sql.DriverManager;
@@ -254,12 +255,11 @@ class JdbcFilterPushdownPreparedStatementVisitorTest {
 
         FlinkTypeFactory typeFactory = new FlinkTypeFactory(classLoader, 
FlinkTypeSystem.INSTANCE);
         RexNodeToExpressionConverter converter =
-                new RexNodeToExpressionConverter(
+                getConverter(
                         new RexBuilder(typeFactory),
                         sourceType.getFieldNames().toArray(new String[0]),
                         funCat,
-                        catMan,
-                        
TimeZone.getTimeZone(tEnv.getConfig().getLocalTimeZone()));
+                        catMan);
 
         RexNodeExpression rexExp =
                 (RexNodeExpression) 
tbImpl.getParser().parseSqlExpression(sqlExp, sourceType, null);
@@ -294,4 +294,41 @@ class JdbcFilterPushdownPreparedStatementVisitorTest {
 
         return resolver.resolve(Arrays.asList(resolvedExp));
     }
+
+    private RexNodeToExpressionConverter getConverter(
+            RexBuilder rexBuilder,
+            String[] inputNames,
+            FunctionCatalog functionCatalog,
+            CatalogManager catalogManager) {
+        try {
+            Class<?> clazz =
+                    Class.forName(
+                            
RexNodeToExpressionConverter.class.getCanonicalName(),
+                            false,
+                            classLoader);
+
+            Constructor<?>[] constructors = clazz.getConstructors();
+
+            for (Constructor<?> constructor : constructors) {
+                if (constructor.getParameterCount() == 4) {
+                    return (RexNodeToExpressionConverter)
+                            constructor.newInstance(
+                                    rexBuilder, inputNames, functionCatalog, 
catalogManager);
+                }
+                if (constructor.getParameterCount() == 5
+                        && 
TimeZone.class.equals(constructor.getParameters()[4].getType())) {
+                    return (RexNodeToExpressionConverter)
+                            constructor.newInstance(
+                                    rexBuilder,
+                                    inputNames,
+                                    functionCatalog,
+                                    catalogManager,
+                                    
TimeZone.getTimeZone(tEnv.getConfig().getLocalTimeZone()));
+                }
+            }
+        } catch (Throwable e) {
+            throw new RuntimeException("Failed to instantiate 
RexNodeToExpressionConverter", e);
+        }
+        throw new RuntimeException("No suitable RexNodeToExpressionConverter 
constructor found.");
+    }
 }

Reply via email to