morningman commented on code in PR #31879:
URL: https://github.com/apache/doris/pull/31879#discussion_r1514499925


##########
be/src/vec/exec/format/table/trino_connector_jni_reader.cpp:
##########
@@ -0,0 +1,100 @@
+// 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.
+
+#include "trino_connector_jni_reader.h"
+
+#include <map>
+#include <ostream>
+
+#include "runtime/descriptors.h"
+#include "runtime/types.h"
+#include "vec/core/types.h"
+
+namespace doris {
+class RuntimeProfile;
+class RuntimeState;
+
+namespace vectorized {
+class Block;
+} // namespace vectorized
+} // namespace doris
+
+namespace doris::vectorized {
+
+const std::string TrinoConnectorJniReader::TRINO_CONNECTOR_OPTION_PREFIX =
+        "trino_connector_option_prefix.";
+
+TrinoConnectorJniReader::TrinoConnectorJniReader(
+        const std::vector<SlotDescriptor*>& file_slot_descs, RuntimeState* 
state,
+        RuntimeProfile* profile, const TFileRangeDesc& range)
+        : _file_slot_descs(file_slot_descs), _state(state), _profile(profile) {
+    std::vector<std::string> column_names;
+    for (auto& desc : _file_slot_descs) {
+        std::string field = desc->col_name();
+        column_names.emplace_back(field);
+    }
+    std::map<String, String> params;
+    params["catalog_name"] = 
range.table_format_params.trino_connector_params.catalog_name;
+    params["db_name"] = 
range.table_format_params.trino_connector_params.db_name;
+    params["table_name"] = 
range.table_format_params.trino_connector_params.table_name;
+    params["trino_connector_split"] =
+            
range.table_format_params.trino_connector_params.trino_connector_split;
+    params["trino_connector_table_handle"] =
+            
range.table_format_params.trino_connector_params.trino_connector_table_handle;
+    params["trino_connector_column_handles"] =
+            
range.table_format_params.trino_connector_params.trino_connector_column_handles;
+    params["trino_connector_column_metadata"] =
+            
range.table_format_params.trino_connector_params.trino_connector_column_metadata;
+    params["trino_connector_column_names"] =
+            
range.table_format_params.trino_connector_params.trino_connector_column_names;
+    params["trino_connector_predicate"] =
+            
range.table_format_params.trino_connector_params.trino_connector_predicate;
+    params["trino_connector_trascation_handle"] =
+            
range.table_format_params.trino_connector_params.trino_connector_trascation_handle;
+
+    // Used to create trino connector options
+    for (auto& kv : 
range.table_format_params.trino_connector_params.trino_connector_options) {
+        params[TRINO_CONNECTOR_OPTION_PREFIX + kv.first] = kv.second;
+    }
+    _jni_connector = std::make_unique<JniConnector>(
+            "org/apache/doris/trinoconnector/TrinoConnectorJniScanner", 
params, column_names);
+}
+
+Status TrinoConnectorJniReader::init_reader(
+        std::unordered_map<std::string, ColumnValueRangeType>* 
colname_to_value_range) {

Review Comment:
   ```suggestion
           const std::unordered_map<std::string, ColumnValueRangeType>* 
colname_to_value_range) {
   ```



##########
be/src/util/jni-util.cpp:
##########
@@ -391,6 +393,47 @@ Status JniUtil::init_jni_scanner_loader(JNIEnv* env) {
     return Status::OK();
 }
 
+Status JniUtil::_load_spi_plugins(JNIEnv* env) {
+    // get PluginLoader class
+    jclass plugin_loader_cls;
+    std::string plugin_loader_str = 
"org/apache/doris/trinoconnector/PluginLoader";
+    // RETURN_IF_ERROR(JniUtil::GetGlobalClassRef(env, 
plugin_loader_str.c_str(), &plugin_loader_cls));

Review Comment:
   Remove unused code



##########
be/src/util/jni-util.cpp:
##########
@@ -518,6 +561,7 @@ Status JniUtil::Init() {
         return Status::InternalError("Failed to find JniUtil.getJMXJson 
method.");
     }
     RETURN_IF_ERROR(init_jni_scanner_loader(env));
+    RETURN_IF_ERROR(_load_spi_plugins(env));

Review Comment:
   Should be in `init_jni_scanner_loader()`?



##########
be/src/vec/exec/format/table/trino_connector_jni_reader.h:
##########
@@ -0,0 +1,77 @@
+// 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.
+
+#pragma once
+
+#include <stddef.h>
+
+#include <memory>
+#include <string>
+#include <unordered_map>
+#include <unordered_set>
+#include <vector>
+
+#include "common/status.h"
+#include "exec/olap_common.h"
+#include "vec/exec/format/generic_reader.h"
+#include "vec/exec/jni_connector.h"
+
+namespace doris {
+class RuntimeProfile;
+class RuntimeState;
+class SlotDescriptor;
+namespace vectorized {
+class Block;
+} // namespace vectorized
+struct TypeDescriptor;
+} // namespace doris
+
+namespace doris::vectorized {
+
+/**
+ * The demo usage of JniReader, showing how to read data from java scanner.

Review Comment:
   Modify the comment



##########
fe/fe-core/src/main/java/org/apache/doris/datasource/trinoconnector/TrinoConnectorPluginLoader.java:
##########
@@ -0,0 +1,81 @@
+// 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.doris.datasource.trinoconnector;
+
+import org.apache.doris.common.Config;
+import org.apache.doris.trinoconnector.TrinoConnectorPluginManager;
+
+import com.google.common.util.concurrent.MoreExecutors;
+import io.trino.FeaturesConfig;
+import io.trino.metadata.HandleResolver;
+import io.trino.metadata.TypeRegistry;
+import io.trino.server.ServerPluginsProvider;
+import io.trino.server.ServerPluginsProviderConfig;
+import io.trino.spi.type.TypeOperators;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.File;
+
+public class TrinoConnectorPluginLoader {
+    private static final Logger LOG = 
LogManager.getLogger(TrinoConnectorPluginLoader.class);
+
+    private static class TrinoConnectorPluginLoad {
+        private static FeaturesConfig featuresConfig = new FeaturesConfig();
+        private static TypeOperators typeOperators = new TypeOperators();
+        private static HandleResolver handleResolver = new HandleResolver();
+        private static TypeRegistry typeRegistry;
+        private static TrinoConnectorPluginManager trinoConnectorPluginManager;
+
+        static {
+            try {
+                typeRegistry = new TypeRegistry(typeOperators, featuresConfig);
+                ServerPluginsProviderConfig serverPluginsProviderConfig = new 
ServerPluginsProviderConfig()
+                        .setInstalledPluginsDir(new 
File(Config.trino_connector_plugin_dir));
+                ServerPluginsProvider serverPluginsProvider = new 
ServerPluginsProvider(serverPluginsProviderConfig,
+                        MoreExecutors.directExecutor());
+                trinoConnectorPluginManager = new 
TrinoConnectorPluginManager(serverPluginsProvider,
+                        typeRegistry, handleResolver);
+                trinoConnectorPluginManager.loadPlugins();
+            } catch (Exception e) {
+                LOG.warn("Exception when load trino-connector plugins from  " 
+ Config.trino_connector_plugin_dir);

Review Comment:
   remove one of these 2 logs



-- 
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: commits-unsubscr...@doris.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to