mneethiraj commented on code in PR #336:
URL: https://github.com/apache/atlas/pull/336#discussion_r2279570736


##########
addons/trino-extractor/src/main/java/org/apache/atlas/trino/model/Catalog.java:
##########
@@ -0,0 +1,93 @@
+/**
+ * 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.atlas.trino.model;
+
+import org.apache.atlas.model.instance.AtlasEntity;
+import org.apache.atlas.trino.connector.AtlasEntityConnector;
+import org.apache.atlas.trino.connector.ConnectorFactory;
+
+public class Catalog {
+    private String                             instanceName;

Review Comment:
   Consider marking fields that aren't updated after construction as `final`



##########
addons/trino-extractor/src/main/java/org/apache/atlas/trino/client/TrinoClientHelper.java:
##########
@@ -0,0 +1,136 @@
+/**
+ * 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.atlas.trino.client;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.lang.StringUtils;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class TrinoClientHelper {
+
+    private static String jdbcUrl;
+    private static String username;
+    private static String password;
+
+    public TrinoClientHelper(Configuration atlasConf) {
+        this.jdbcUrl  = atlasConf.getString("atlas.trino.jdbc.address");
+        this.username = atlasConf.getString("atlas.trino.jdbc.user");
+        this.password = atlasConf.getString("atlas.trino.jdbc.password", "");
+    }
+
+    public static Connection getTrinoConnection() throws SQLException {

Review Comment:
   `getTrinoConnection()` method is not called outside of this class. Consider 
removing `static` and marking the method as `private`.



##########
addons/trino-extractor/src/main/java/org/apache/atlas/trino/client/TrinoClientHelper.java:
##########
@@ -0,0 +1,136 @@
+/**
+ * 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.atlas.trino.client;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.lang.StringUtils;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class TrinoClientHelper {
+
+    private static String jdbcUrl;
+    private static String username;
+    private static String password;
+
+    public TrinoClientHelper(Configuration atlasConf) {
+        this.jdbcUrl  = atlasConf.getString("atlas.trino.jdbc.address");
+        this.username = atlasConf.getString("atlas.trino.jdbc.user");
+        this.password = atlasConf.getString("atlas.trino.jdbc.password", "");
+    }
+
+    public static Connection getTrinoConnection() throws SQLException {
+        return DriverManager.getConnection(jdbcUrl, username, password);
+    }
+
+    public Map<String, String> getAllTrinoCatalogs() {
+        Map<String, String> catalogs = new HashMap<>();
+        try {
+            Connection    connection = getTrinoConnection();
+            Statement     stmt       = connection.createStatement();
+            StringBuilder query      = new StringBuilder();

Review Comment:
   Use of `StringBuilder` is unnecessary here. Please review and remove.



##########
addons/trino-extractor/src/main/java/org/apache/atlas/trino/connector/IcebergEntityConnector.java:
##########
@@ -0,0 +1,125 @@
+/**
+ * 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.atlas.trino.connector;
+
+import org.apache.atlas.AtlasServiceException;
+import org.apache.atlas.model.instance.AtlasEntity;
+import org.apache.atlas.trino.client.AtlasClientHelper;
+import org.apache.atlas.type.AtlasTypeUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+public class IcebergEntityConnector extends AtlasEntityConnector {
+    private static final Logger LOG = 
LoggerFactory.getLogger(IcebergEntityConnector.class);
+
+    public static final String HIVE_DB                                  = 
"hive_db";
+    public static final String ICEBERG_TABLE                            = 
"iceberg_table";
+    public static final String ICEBERG_COLUMN                           = 
"iceberg_column";
+    public static final String TRINO_SCHEMA_HIVE_DB_RELATIONSHIP        = 
"trino_schema_hive_db";
+    public static final String TRINO_TABLE_ICEBERG_TABLE_RELATIONSHIP   = 
"trino_table_iceberg_table";
+    public static final String TRINO_COLUMN_ICEBERG_COLUMN_RELATIONSHIP = 
"trino_column_iceberg_column";
+    public static final String TRINO_SCHEMA_HIVE_DB_ATTRIBUTE           = 
"hive_db";
+    public static final String TRINO_TABLE_ICEBERG_TABLE_ATTRIBUTE      = 
"iceberg_table";
+    public static final String TRINO_COLUMN_ICEBERG_COLUMN_ATTRIBUTE    = 
"iceberg_column";
+
+    @Override
+    public void connectTrinoCatalog(String instanceName, String catalogName, 
AtlasEntity entity, AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo) {
+
+    }
+
+    @Override
+    public void connectTrinoSchema(String instanceName, String catalogName, 
String schemaName, AtlasEntity dbEntity, AtlasEntity.AtlasEntityWithExtInfo 
entityWithExtInfo) {
+        if (instanceName == null) {
+            LOG.warn("Failed attempting to connect entity since hook namespace 
is empty, Please configure in properties");
+            return;
+        }
+
+        AtlasEntity hiveDb = null;
+        try {
+            hiveDb = toDbEntity(instanceName, schemaName);
+        } catch (AtlasServiceException e) {
+            LOG.error("Error encountered: ", e);
+        }
+
+        if (hiveDb != null) {
+            dbEntity.setRelationshipAttribute(TRINO_SCHEMA_HIVE_DB_ATTRIBUTE, 
AtlasTypeUtil.getAtlasRelatedObjectId(hiveDb, 
TRINO_SCHEMA_HIVE_DB_RELATIONSHIP));
+        }
+    }
+
+    @Override
+    public void connectTrinoTable(String instanceName, String catalogName, 
String schemaName, String tableName, AtlasEntity trinoTable, List<AtlasEntity> 
columnEntities, AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo) {
+        if (instanceName == null) {
+            LOG.warn("Failed attempting to connect entity since hook namespace 
is empty, Please configure in properties");
+            return;
+        }
+
+        AtlasEntity icebergTable;
+        try {
+            icebergTable = toTableEntity(instanceName, schemaName, tableName);
+
+            if (icebergTable != null) {
+                
trinoTable.setRelationshipAttribute(TRINO_TABLE_ICEBERG_TABLE_ATTRIBUTE, 
AtlasTypeUtil.getAtlasRelatedObjectId(icebergTable, 
TRINO_TABLE_ICEBERG_TABLE_RELATIONSHIP));
+
+                for (AtlasEntity columnEntity : columnEntities) {
+                    connectTrinoColumn(instanceName, schemaName, tableName, 
columnEntity);
+                }
+            }
+        } catch (AtlasServiceException e) {
+            LOG.error("Error encountered: ", e);
+        }
+    }
+
+    public void connectTrinoColumn(String instanceName, String schemaName, 
String tableName, AtlasEntity trinoColumn) throws AtlasServiceException {

Review Comment:
   `connectTrinoColumn()` is not called outside of this class. Consider marking 
this method as `private`.



##########
addons/trino-extractor/src/main/java/org/apache/atlas/trino/client/TrinoClientHelper.java:
##########
@@ -0,0 +1,136 @@
+/**
+ * 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.atlas.trino.client;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.lang.StringUtils;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class TrinoClientHelper {
+
+    private static String jdbcUrl;

Review Comment:
   Consider making following as instance members, instead of `static`
   - `jdbcUrl`
   - `username`
   - `password`
   
   Also, consider marking them as `final`.



##########
addons/trino-extractor/src/main/java/org/apache/atlas/trino/connector/HiveEntityConnector.java:
##########
@@ -0,0 +1,124 @@
+/**
+ * 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.atlas.trino.connector;
+
+import org.apache.atlas.AtlasServiceException;
+import org.apache.atlas.model.instance.AtlasEntity;
+import org.apache.atlas.trino.client.AtlasClientHelper;
+import org.apache.atlas.type.AtlasTypeUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+public class HiveEntityConnector extends AtlasEntityConnector {
+    private static final Logger LOG = 
LoggerFactory.getLogger(HiveEntityConnector.class);
+
+    public static final String HIVE_DB                               = 
"hive_db";
+    public static final String HIVE_TABLE                            = 
"hive_table";
+    public static final String HIVE_COLUMN                           = 
"hive_column";
+    public static final String TRINO_SCHEMA_HIVE_DB_RELATIONSHIP     = 
"trino_schema_hive_db";
+    public static final String TRINO_TABLE_HIVE_TABLE_RELATIONSHIP   = 
"trino_table_hive_table";
+    public static final String TRINO_COLUMN_HIVE_COLUMN_RELATIONSHIP = 
"trino_column_hive_column";
+    public static final String TRINO_SCHEMA_HIVE_DB_ATTRIBUTE        = 
"hive_db";
+    public static final String TRINO_TABLE_HIVE_TABLE_ATTRIBUTE      = 
"hive_table";
+    public static final String TRINO_COLUMN_HIVE_COLUMN_ATTRIBUTE    = 
"hive_column";
+    @Override
+    public void connectTrinoCatalog(String instanceName, String catalogName, 
AtlasEntity entity, AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo) {
+
+    }
+
+    @Override
+    public void connectTrinoSchema(String instanceName, String catalogName, 
String schemaName, AtlasEntity dbEntity, AtlasEntity.AtlasEntityWithExtInfo 
entityWithExtInfo) {
+        if (instanceName == null) {
+            LOG.warn("Failed attempting to connect entity since hook namespace 
is empty, Please configure in properties");
+            return;
+        }
+
+        AtlasEntity hiveDb = null;
+        try {
+            hiveDb = toDbEntity(instanceName, schemaName);
+        } catch (AtlasServiceException e) {
+            LOG.error("Error encountered: ", e);
+        }
+
+        if (hiveDb != null) {
+            dbEntity.setRelationshipAttribute(TRINO_SCHEMA_HIVE_DB_ATTRIBUTE, 
AtlasTypeUtil.getAtlasRelatedObjectId(hiveDb, 
TRINO_SCHEMA_HIVE_DB_RELATIONSHIP));
+        }
+    }
+
+    @Override
+    public void connectTrinoTable(String instanceName, String catalogName, 
String schemaName, String tableName, AtlasEntity trinoTable, List<AtlasEntity> 
columnEntities, AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo) {
+        if (instanceName == null) {
+            LOG.warn("Failed attempting to connect entity since hook namespace 
is empty, Please configure in properties");
+            return;
+        }
+
+        AtlasEntity hiveTable;
+        try {
+            hiveTable = toTableEntity(instanceName, schemaName, tableName);
+
+            if (hiveTable != null) {
+                
trinoTable.setRelationshipAttribute(TRINO_TABLE_HIVE_TABLE_ATTRIBUTE, 
AtlasTypeUtil.getAtlasRelatedObjectId(hiveTable, 
TRINO_TABLE_HIVE_TABLE_RELATIONSHIP));
+
+                for (AtlasEntity columnEntity : columnEntities) {
+                    connectTrinoColumn(instanceName, schemaName, tableName, 
columnEntity);
+                }
+            }
+        } catch (AtlasServiceException e) {
+            LOG.error("Error encountered: ", e);
+        }
+    }
+
+    public void connectTrinoColumn(String instanceName, String schemaName, 
String tableName, AtlasEntity trinoColumn) throws AtlasServiceException {

Review Comment:
   `connectTrinoColumn()` is not called outside of this class. Consider marking 
this method as `private`.



##########
addons/trino-extractor/src/main/java/org/apache/atlas/trino/client/TrinoClientHelper.java:
##########
@@ -0,0 +1,136 @@
+/**
+ * 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.atlas.trino.client;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.lang.StringUtils;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class TrinoClientHelper {
+
+    private static String jdbcUrl;
+    private static String username;
+    private static String password;
+
+    public TrinoClientHelper(Configuration atlasConf) {
+        this.jdbcUrl  = atlasConf.getString("atlas.trino.jdbc.address");
+        this.username = atlasConf.getString("atlas.trino.jdbc.user");
+        this.password = atlasConf.getString("atlas.trino.jdbc.password", "");
+    }
+
+    public static Connection getTrinoConnection() throws SQLException {
+        return DriverManager.getConnection(jdbcUrl, username, password);
+    }
+
+    public Map<String, String> getAllTrinoCatalogs() {
+        Map<String, String> catalogs = new HashMap<>();
+        try {
+            Connection    connection = getTrinoConnection();
+            Statement     stmt       = connection.createStatement();
+            StringBuilder query      = new StringBuilder();
+            query.append("SELECT catalog_name, connector_name FROM 
system.metadata.catalogs");
+
+            ResultSet rs = stmt.executeQuery(query.toString());
+            while (rs.next()) {
+                catalogs.put(rs.getString("catalog_name"), 
rs.getString("connector_name"));
+            }
+        } catch (SQLException e) {
+            throw new RuntimeException(e);
+        }
+
+        return catalogs;
+    }
+
+    public List<String> getTrinoSchemas(String catalog, String schemaToImport) 
throws SQLException {
+        List<String>  schemas    = new ArrayList<>();
+        Connection    connection = getTrinoConnection();
+        Statement     stmt       = connection.createStatement();
+        StringBuilder query      = new StringBuilder();
+        query.append("SELECT schema_name FROM " + catalog + 
".information_schema.schemata");
+
+        if (StringUtils.isNotEmpty(schemaToImport)) {
+            query.append(" where schema_name = '" + schemaToImport + "'");
+        }
+
+        ResultSet rs = stmt.executeQuery(query.toString());
+        while (rs.next()) {
+            schemas.add(rs.getString("schema_name"));
+        }
+
+        return schemas;
+    }
+
+    public Map<String, Map<String, Object>> getTrinoTables(String catalog, 
String schema, String tableToImport) throws SQLException {
+        Map<String, Map<String, Object>> tables     = new HashMap<>();
+        Connection                       connection = getTrinoConnection();
+        Statement                        stmt       = 
connection.createStatement();
+        StringBuilder                    query      = new StringBuilder();
+        query.append("SELECT table_name, table_type FROM " + catalog + 
".information_schema.tables WHERE table_schema = '" + schema + "'");

Review Comment:
   Replace string concat with append() calls - in line 92 and 94.



##########
addons/trino-extractor/src/main/java/org/apache/atlas/trino/client/TrinoClientHelper.java:
##########
@@ -0,0 +1,136 @@
+/**
+ * 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.atlas.trino.client;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.lang.StringUtils;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class TrinoClientHelper {
+
+    private static String jdbcUrl;
+    private static String username;
+    private static String password;
+
+    public TrinoClientHelper(Configuration atlasConf) {
+        this.jdbcUrl  = atlasConf.getString("atlas.trino.jdbc.address");
+        this.username = atlasConf.getString("atlas.trino.jdbc.user");
+        this.password = atlasConf.getString("atlas.trino.jdbc.password", "");
+    }
+
+    public static Connection getTrinoConnection() throws SQLException {
+        return DriverManager.getConnection(jdbcUrl, username, password);
+    }
+
+    public Map<String, String> getAllTrinoCatalogs() {
+        Map<String, String> catalogs = new HashMap<>();
+        try {
+            Connection    connection = getTrinoConnection();
+            Statement     stmt       = connection.createStatement();
+            StringBuilder query      = new StringBuilder();
+            query.append("SELECT catalog_name, connector_name FROM 
system.metadata.catalogs");
+
+            ResultSet rs = stmt.executeQuery(query.toString());
+            while (rs.next()) {
+                catalogs.put(rs.getString("catalog_name"), 
rs.getString("connector_name"));
+            }
+        } catch (SQLException e) {
+            throw new RuntimeException(e);
+        }
+
+        return catalogs;
+    }
+
+    public List<String> getTrinoSchemas(String catalog, String schemaToImport) 
throws SQLException {
+        List<String>  schemas    = new ArrayList<>();
+        Connection    connection = getTrinoConnection();
+        Statement     stmt       = connection.createStatement();
+        StringBuilder query      = new StringBuilder();
+        query.append("SELECT schema_name FROM " + catalog + 
".information_schema.schemata");
+
+        if (StringUtils.isNotEmpty(schemaToImport)) {
+            query.append(" where schema_name = '" + schemaToImport + "'");
+        }
+
+        ResultSet rs = stmt.executeQuery(query.toString());
+        while (rs.next()) {
+            schemas.add(rs.getString("schema_name"));
+        }
+
+        return schemas;
+    }
+
+    public Map<String, Map<String, Object>> getTrinoTables(String catalog, 
String schema, String tableToImport) throws SQLException {
+        Map<String, Map<String, Object>> tables     = new HashMap<>();
+        Connection                       connection = getTrinoConnection();
+        Statement                        stmt       = 
connection.createStatement();
+        StringBuilder                    query      = new StringBuilder();
+        query.append("SELECT table_name, table_type FROM " + catalog + 
".information_schema.tables WHERE table_schema = '" + schema + "'");
+        if (StringUtils.isNotEmpty(tableToImport)) {
+            query.append(" and table_name = '" + tableToImport + "'");
+        }
+
+        ResultSet rs = stmt.executeQuery(query.toString());
+        while (rs.next()) {
+            Map<String, Object> tableMetadata = new HashMap<>();
+            tableMetadata.put("table_name", rs.getString("table_name"));
+            tableMetadata.put("table_type", rs.getString("table_type"));
+
+            tables.put(rs.getString("table_name"), tableMetadata);
+        }
+
+        return tables;
+    }
+
+    public Map<String, Map<String, Object>> getTrinoColumns(String catalog, 
String schema, String table) throws SQLException {
+        Map<String, Map<String, Object>> columns    = new HashMap<>();
+        Connection                       connection = getTrinoConnection();
+        Statement                        stmt       = 
connection.createStatement();
+        StringBuilder                    query      = new StringBuilder();
+        query.append("SELECT column_name, ordinal_position, column_default, 
is_nullable, data_type FROM " + catalog + ".information_schema.columns WHERE 
table_schema = '" + schema + "' AND table_name = '" + table + "'");

Review Comment:
   Replace string concat with append() calls.



##########
addons/trino-extractor/src/main/java/org/apache/atlas/trino/client/TrinoClientHelper.java:
##########
@@ -0,0 +1,136 @@
+/**
+ * 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.atlas.trino.client;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.lang.StringUtils;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class TrinoClientHelper {
+
+    private static String jdbcUrl;
+    private static String username;
+    private static String password;
+
+    public TrinoClientHelper(Configuration atlasConf) {
+        this.jdbcUrl  = atlasConf.getString("atlas.trino.jdbc.address");
+        this.username = atlasConf.getString("atlas.trino.jdbc.user");
+        this.password = atlasConf.getString("atlas.trino.jdbc.password", "");
+    }
+
+    public static Connection getTrinoConnection() throws SQLException {
+        return DriverManager.getConnection(jdbcUrl, username, password);
+    }
+
+    public Map<String, String> getAllTrinoCatalogs() {
+        Map<String, String> catalogs = new HashMap<>();
+        try {
+            Connection    connection = getTrinoConnection();
+            Statement     stmt       = connection.createStatement();
+            StringBuilder query      = new StringBuilder();
+            query.append("SELECT catalog_name, connector_name FROM 
system.metadata.catalogs");
+
+            ResultSet rs = stmt.executeQuery(query.toString());
+            while (rs.next()) {
+                catalogs.put(rs.getString("catalog_name"), 
rs.getString("connector_name"));
+            }
+        } catch (SQLException e) {
+            throw new RuntimeException(e);
+        }
+
+        return catalogs;
+    }
+
+    public List<String> getTrinoSchemas(String catalog, String schemaToImport) 
throws SQLException {
+        List<String>  schemas    = new ArrayList<>();
+        Connection    connection = getTrinoConnection();
+        Statement     stmt       = connection.createStatement();
+        StringBuilder query      = new StringBuilder();
+        query.append("SELECT schema_name FROM " + catalog + 
".information_schema.schemata");

Review Comment:
   Replace string concat with append() calls - in line 73 and 76.



##########
addons/trino-extractor/src/main/java/org/apache/atlas/trino/client/TrinoClientHelper.java:
##########
@@ -0,0 +1,136 @@
+/**
+ * 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.atlas.trino.client;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.lang.StringUtils;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class TrinoClientHelper {
+
+    private static String jdbcUrl;
+    private static String username;
+    private static String password;
+
+    public TrinoClientHelper(Configuration atlasConf) {
+        this.jdbcUrl  = atlasConf.getString("atlas.trino.jdbc.address");
+        this.username = atlasConf.getString("atlas.trino.jdbc.user");
+        this.password = atlasConf.getString("atlas.trino.jdbc.password", "");
+    }
+
+    public static Connection getTrinoConnection() throws SQLException {
+        return DriverManager.getConnection(jdbcUrl, username, password);
+    }
+
+    public Map<String, String> getAllTrinoCatalogs() {
+        Map<String, String> catalogs = new HashMap<>();
+        try {
+            Connection    connection = getTrinoConnection();

Review Comment:
   To ensure that `connection` is closed, consider using try-with-resource.



##########
addons/trino-extractor/src/main/java/org/apache/atlas/trino/client/TrinoClientHelper.java:
##########
@@ -0,0 +1,136 @@
+/**
+ * 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.atlas.trino.client;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.lang.StringUtils;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class TrinoClientHelper {
+
+    private static String jdbcUrl;
+    private static String username;
+    private static String password;
+
+    public TrinoClientHelper(Configuration atlasConf) {
+        this.jdbcUrl  = atlasConf.getString("atlas.trino.jdbc.address");
+        this.username = atlasConf.getString("atlas.trino.jdbc.user");
+        this.password = atlasConf.getString("atlas.trino.jdbc.password", "");
+    }
+
+    public static Connection getTrinoConnection() throws SQLException {
+        return DriverManager.getConnection(jdbcUrl, username, password);
+    }
+
+    public Map<String, String> getAllTrinoCatalogs() {
+        Map<String, String> catalogs = new HashMap<>();
+        try {
+            Connection    connection = getTrinoConnection();
+            Statement     stmt       = connection.createStatement();
+            StringBuilder query      = new StringBuilder();
+            query.append("SELECT catalog_name, connector_name FROM 
system.metadata.catalogs");
+
+            ResultSet rs = stmt.executeQuery(query.toString());
+            while (rs.next()) {
+                catalogs.put(rs.getString("catalog_name"), 
rs.getString("connector_name"));
+            }
+        } catch (SQLException e) {
+            throw new RuntimeException(e);
+        }
+
+        return catalogs;
+    }
+
+    public List<String> getTrinoSchemas(String catalog, String schemaToImport) 
throws SQLException {
+        List<String>  schemas    = new ArrayList<>();
+        Connection    connection = getTrinoConnection();
+        Statement     stmt       = connection.createStatement();
+        StringBuilder query      = new StringBuilder();
+        query.append("SELECT schema_name FROM " + catalog + 
".information_schema.schemata");
+
+        if (StringUtils.isNotEmpty(schemaToImport)) {
+            query.append(" where schema_name = '" + schemaToImport + "'");
+        }
+
+        ResultSet rs = stmt.executeQuery(query.toString());
+        while (rs.next()) {
+            schemas.add(rs.getString("schema_name"));
+        }
+
+        return schemas;
+    }
+
+    public Map<String, Map<String, Object>> getTrinoTables(String catalog, 
String schema, String tableToImport) throws SQLException {
+        Map<String, Map<String, Object>> tables     = new HashMap<>();
+        Connection                       connection = getTrinoConnection();
+        Statement                        stmt       = 
connection.createStatement();
+        StringBuilder                    query      = new StringBuilder();
+        query.append("SELECT table_name, table_type FROM " + catalog + 
".information_schema.tables WHERE table_schema = '" + schema + "'");
+        if (StringUtils.isNotEmpty(tableToImport)) {
+            query.append(" and table_name = '" + tableToImport + "'");
+        }
+
+        ResultSet rs = stmt.executeQuery(query.toString());
+        while (rs.next()) {
+            Map<String, Object> tableMetadata = new HashMap<>();
+            tableMetadata.put("table_name", rs.getString("table_name"));
+            tableMetadata.put("table_type", rs.getString("table_type"));
+
+            tables.put(rs.getString("table_name"), tableMetadata);
+        }
+
+        return tables;
+    }
+
+    public Map<String, Map<String, Object>> getTrinoColumns(String catalog, 
String schema, String table) throws SQLException {
+        Map<String, Map<String, Object>> columns    = new HashMap<>();
+        Connection                       connection = getTrinoConnection();

Review Comment:
   To ensure that `connection` is closed, consider using try-with-resource.



##########
addons/trino-extractor/src/main/java/org/apache/atlas/trino/client/TrinoClientHelper.java:
##########
@@ -0,0 +1,136 @@
+/**
+ * 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.atlas.trino.client;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.lang.StringUtils;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class TrinoClientHelper {
+
+    private static String jdbcUrl;
+    private static String username;
+    private static String password;
+
+    public TrinoClientHelper(Configuration atlasConf) {
+        this.jdbcUrl  = atlasConf.getString("atlas.trino.jdbc.address");
+        this.username = atlasConf.getString("atlas.trino.jdbc.user");
+        this.password = atlasConf.getString("atlas.trino.jdbc.password", "");
+    }
+
+    public static Connection getTrinoConnection() throws SQLException {
+        return DriverManager.getConnection(jdbcUrl, username, password);
+    }
+
+    public Map<String, String> getAllTrinoCatalogs() {
+        Map<String, String> catalogs = new HashMap<>();
+        try {
+            Connection    connection = getTrinoConnection();
+            Statement     stmt       = connection.createStatement();
+            StringBuilder query      = new StringBuilder();
+            query.append("SELECT catalog_name, connector_name FROM 
system.metadata.catalogs");
+
+            ResultSet rs = stmt.executeQuery(query.toString());
+            while (rs.next()) {
+                catalogs.put(rs.getString("catalog_name"), 
rs.getString("connector_name"));
+            }
+        } catch (SQLException e) {
+            throw new RuntimeException(e);
+        }
+
+        return catalogs;
+    }
+
+    public List<String> getTrinoSchemas(String catalog, String schemaToImport) 
throws SQLException {
+        List<String>  schemas    = new ArrayList<>();
+        Connection    connection = getTrinoConnection();

Review Comment:
   To ensure that `connection` is closed, consider using try-with-resource.



-- 
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: dev-unsubscr...@atlas.apache.org

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


Reply via email to