This is an automated email from the ASF dual-hosted git repository.
jiabaosun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/flink-connector-mongodb.git
The following commit(s) were added to refs/heads/main by this push:
new 98ada66 [FLINK-35975][Connectors/MongoDB][test] Using reflection to
resolve RexNodeToExpressionConverter constructor conflicts (#38)
98ada66 is described below
commit 98ada669bef8bf43d7f33dce73d0a7a99ea6fbbe
Author: Jiabao Sun <[email protected]>
AuthorDate: Mon Aug 5 11:36:45 2024 +0800
[FLINK-35975][Connectors/MongoDB][test] Using reflection to resolve
RexNodeToExpressionConverter constructor conflicts (#38)
---
.../table/MongoFilterPushDownVisitorTest.java | 43 ++++++++++++++++++++--
1 file changed, 40 insertions(+), 3 deletions(-)
diff --git
a/flink-connector-mongodb/src/test/java/org/apache/flink/connector/mongodb/table/MongoFilterPushDownVisitorTest.java
b/flink-connector-mongodb/src/test/java/org/apache/flink/connector/mongodb/table/MongoFilterPushDownVisitorTest.java
index 1dbb8e9..f92ce17 100644
---
a/flink-connector-mongodb/src/test/java/org/apache/flink/connector/mongodb/table/MongoFilterPushDownVisitorTest.java
+++
b/flink-connector-mongodb/src/test/java/org/apache/flink/connector/mongodb/table/MongoFilterPushDownVisitorTest.java
@@ -52,6 +52,7 @@ import org.bson.types.Decimal128;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import java.lang.reflect.Constructor;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.time.ZoneId;
@@ -276,12 +277,11 @@ class MongoFilterPushDownVisitorTest {
FlinkTypeFactory typeFactory = new FlinkTypeFactory(classLoader,
FlinkTypeSystem.INSTANCE);
RexBuilder rexBuilder = new RexBuilder(typeFactory);
RexNodeToExpressionConverter converter =
- new RexNodeToExpressionConverter(
+ getConverter(
rexBuilder,
sourceType.getFieldNames().toArray(new String[0]),
funCat,
- catMan,
-
TimeZone.getTimeZone(tEnv.getConfig().getLocalTimeZone()));
+ catMan);
RexNodeExpression rexExp =
(RexNodeExpression)
tbImpl.getParser().parseSqlExpression(sqlExp, sourceType, null);
@@ -316,4 +316,41 @@ class MongoFilterPushDownVisitorTest {
return resolver.resolve(resolvedExps);
}
+
+ 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.");
+ }
}