Jiabao-Sun commented on code in PR #1:
URL: 
https://github.com/apache/flink-connector-mongodb/pull/1#discussion_r1032991900


##########
flink-connector-mongodb/src/main/java/org/apache/flink/connector/mongodb/table/MongoRowDataLookupFunction.java:
##########
@@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.mongodb.table;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.mongodb.common.config.MongoConnectionOptions;
+import 
org.apache.flink.connector.mongodb.table.converter.BsonToRowDataConverters;
+import 
org.apache.flink.connector.mongodb.table.converter.RowDataToBsonConverters;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.functions.FunctionContext;
+import org.apache.flink.table.functions.LookupFunction;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.RowType;
+
+import com.mongodb.MongoException;
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoCursor;
+import org.bson.BsonDocument;
+import org.bson.conversions.Bson;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static com.mongodb.client.model.Filters.and;
+import static com.mongodb.client.model.Filters.eq;
+import static 
org.apache.flink.connector.mongodb.common.utils.MongoUtils.project;
+import static org.apache.flink.util.Preconditions.checkArgument;
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** A lookup function for {@link MongoDynamicTableSource}. */
+@Internal
+public class MongoRowDataLookupFunction extends LookupFunction {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(MongoRowDataLookupFunction.class);
+    private static final long serialVersionUID = 1L;
+
+    private final MongoConnectionOptions connectionOptions;
+    private final int maxRetries;
+    private final long retryIntervalMs;
+
+    private final List<String> fieldNames;
+    private final List<String> keyNames;
+
+    private final BsonToRowDataConverters.BsonToRowDataConverter 
mongoRowConverter;
+    private final RowDataToBsonConverters.RowDataToBsonConverter 
lookupKeyRowConverter;
+
+    private transient MongoClient mongoClient;
+
+    public MongoRowDataLookupFunction(
+            MongoConnectionOptions connectionOptions,
+            int maxRetries,
+            long retryIntervalMs,
+            List<String> fieldNames,
+            List<DataType> fieldTypes,
+            List<String> keyNames,
+            RowType rowType) {
+        checkNotNull(fieldNames, "No fieldNames supplied.");
+        checkNotNull(fieldTypes, "No fieldTypes supplied.");
+        checkNotNull(keyNames, "No keyNames supplied.");
+        this.connectionOptions = checkNotNull(connectionOptions);
+        this.maxRetries = maxRetries;
+        this.retryIntervalMs = retryIntervalMs;
+        this.fieldNames = fieldNames;
+        this.mongoRowConverter = 
BsonToRowDataConverters.createNullableConverter(rowType);
+
+        this.keyNames = keyNames;
+        LogicalType[] keyTypes =
+                this.keyNames.stream()
+                        .map(
+                                s -> {
+                                    checkArgument(
+                                            fieldNames.contains(s),

Review Comment:
   Thanks. Table API guarantees this to be the case. I'll remove that check.
   > org.apache.flink.table.api.ValidationException: SQL validation failed. 
From line 1, column 131 to line 1, column 133: Column 'f18' not found in table 
'D'
   



-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to