[ 
https://issues.apache.org/jira/browse/HIVE-24396?focusedWorklogId=576120&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-576120
 ]

ASF GitHub Bot logged work on HIVE-24396:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 02/Apr/21 14:23
            Start Date: 02/Apr/21 14:23
    Worklog Time Spent: 10m 
      Work Description: yongzhi commented on a change in pull request #2037:
URL: https://github.com/apache/hive/pull/2037#discussion_r606259459



##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreListenerNotifier.java
##########
@@ -94,6 +96,19 @@ public void notify(MetaStoreEventListener listener, 
ListenerEvent event) throws
               listener.onDropDatabase((DropDatabaseEvent)event);
             }
           })
+          .put(EventType.CREATE_DATACONNECTOR, new EventNotifier() {
+            @Override
+            public void notify(MetaStoreEventListener listener,
+                ListenerEvent event) throws MetaException {
+              listener.onCreateDataConnector((CreateDataConnectorEvent)event);
+            }
+          })
+          .put(EventType.DROP_DATACONNECTOR, new EventNotifier() {
+            @Override
+            public void notify(MetaStoreEventListener listener, ListenerEvent 
event) throws MetaException {
+              listener.onDropDataConnector((DropDataConnectorEvent)event);
+            }
+          })

Review comment:
       Do we need AlterDataConnector event or not?

##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/ddl/database/create/CreateDatabaseAnalyzer.java
##########
@@ -70,19 +73,41 @@ public void analyzeInternal(ASTNode root) throws 
SemanticException {
         managedLocationUri = 
unescapeSQLString(childNode.getChild(0).getText());
         outputs.add(toWriteEntity(managedLocationUri));
         break;
+      case HiveParser.TOK_DATACONNECTOR:
+        type = DatabaseType.REMOTE.name();
+        ASTNode nextNode = (ASTNode) root.getChild(i);
+        connectorName = ((ASTNode)nextNode).getChild(0).getText();
+        outputs.add(toWriteEntity(connectorName));
+        if (managedLocationUri != null) {

Review comment:
       If we do not support managed location for remote type, should we throw 
an error when the location is not null?  At least a warning? Or user can be 
confused with some no effective pass-in location.

##########
File path: parser/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g
##########
@@ -1106,14 +1126,16 @@ orReplace
 createDatabaseStatement
 @init { pushMsg("create database statement", state); }
 @after { popMsg(state); }
-    : KW_CREATE (KW_DATABASE|KW_SCHEMA)
+    : KW_CREATE (remote=KW_REMOTE)? (KW_DATABASE|KW_SCHEMA)
         ifNotExists?
         name=identifier
         databaseComment?
         dbLocation?
         dbManagedLocation?
+        dbConnectorName?
         (KW_WITH KW_DBPROPERTIES dbprops=dbProperties)?
-    -> ^(TOK_CREATEDATABASE $name ifNotExists? dbLocation? dbManagedLocation? 
databaseComment? $dbprops?)
+    -> {$remote != null}? ^(TOK_CREATEDATABASE $name ifNotExists? 
databaseComment? $dbprops? dbConnectorName?)

Review comment:
       So, using DB connector for DB, will not create managed tables?

##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/dataconnector/DataConnectorProviderFactory.java
##########
@@ -0,0 +1,101 @@
+package org.apache.hadoop.hive.metastore.dataconnector;
+
+import org.apache.hadoop.hive.metastore.IHMSHandler;
+import org.apache.hadoop.hive.metastore.api.DataConnector;
+import org.apache.hadoop.hive.metastore.api.Database;
+import org.apache.hadoop.hive.metastore.api.DatabaseType;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static 
org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.*;
+
+public class DataConnectorProviderFactory {
+  Logger LOG = LoggerFactory.getLogger(DataConnectorProviderFactory.class);
+
+  private static Map<String, IDataConnectorProvider> cache = null;
+  private static DataConnectorProviderFactory singleton = null;
+  private static IHMSHandler hmsHandler = null;
+
+  private DataConnectorProviderFactory(IHMSHandler hmsHandler) {
+    cache = new HashMap<String, IDataConnectorProvider>();
+    this.hmsHandler = hmsHandler;
+  }
+
+  public static synchronized DataConnectorProviderFactory 
getInstance(IHMSHandler hmsHandler) {
+    if (singleton == null) {
+      singleton = new DataConnectorProviderFactory(hmsHandler);
+    }
+    return singleton;
+  }
+
+  public static synchronized IDataConnectorProvider 
getDataConnectorProvider(Database db) throws MetaException {
+    IDataConnectorProvider provider = null;
+    DataConnector connector = null;
+    if (db.getType() == DatabaseType.NATIVE) {
+      throw new MetaException("Database " + db.getName() + " is of type 
NATIVE, no connector available");
+    }
+
+    String scopedDb = (db.getRemote_dbname() != null) ? db.getRemote_dbname() 
: db.getName();
+    if (cache.containsKey(db.getConnector_name().toLowerCase())) {
+      provider = cache.get(db.getConnector_name().toLowerCase());
+      if (provider != null) {
+        provider.setScope(scopedDb);
+      }
+      return provider;
+    }
+
+    try {
+      connector = hmsHandler.get_dataconnector_core(db.getConnector_name());
+    } catch (NoSuchObjectException notexists) {
+      throw new MetaException("Data connector " + db.getConnector_name() + " 
associated with database "
+          + db.getName() + " does not exist");
+    }
+    String type = connector.getType();
+    switch (type) {
+    case DERBY_TYPE:
+    case MSSQL_TYPE:
+    case MYSQL_TYPE:
+    case ORACLE_TYPE:
+    case POSTGRES_TYPE:
+      try {
+        provider = JDBCConnectorProviderFactory.get(scopedDb, connector);
+      } catch (Exception e) {
+        throw new MetaException("Could not instantiate a provider for database 
" + db.getName());
+      }
+      break;
+    default:
+      throw new MetaException("Data connector of type " + connector.getType() 
+ " not implemented yet");
+    }
+    cache.put(connector.getName().toLowerCase(), provider);
+    return provider;
+  }
+
+  IDataConnectorProvider getDataConnectorProvider(String connectorName) {
+    if (connectorName == null || connectorName.isEmpty()) {
+      return null;
+    }
+
+    if (cache.containsKey(connectorName.toLowerCase() != null)) {
+      return cache.get(connectorName.toLowerCase());
+    }
+    return null;
+    // return getDataConnectorProvider();

Review comment:
       Do you only get the DCProvider from cache or get info from hms if the 
cache does not have it? Please implement accordingly or remove the commented 
statement.




-- 
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.

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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 576120)
    Time Spent: 9.5h  (was: 9h 20m)

> [New Feature] Add data connector support for remote datasources
> ---------------------------------------------------------------
>
>                 Key: HIVE-24396
>                 URL: https://issues.apache.org/jira/browse/HIVE-24396
>             Project: Hive
>          Issue Type: Improvement
>          Components: Hive
>            Reporter: Naveen Gangam
>            Assignee: Naveen Gangam
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 9.5h
>  Remaining Estimate: 0h
>
> This feature work is to be able to support in Hive Metastore to be able to 
> configure data connectors for remote datasources and map databases. We 
> currently have support for remote tables via StorageHandlers like 
> JDBCStorageHandler and HBaseStorageHandler.
> Data connectors are a natural extension to this where we can map an entire 
> database or catalogs instead of individual tables. The tables within are 
> automagically mapped at runtime. The metadata for these tables are not 
> persisted in Hive. They are always mapped and built at runtime. 
> With this feature, we introduce a concept of type for Databases in Hive. 
> NATIVE vs REMOTE. All current databases are NATIVE. To create a REMOTE 
> database, the following syntax is to be used
> CREATE REMOTE DATABASE remote_db USING <dataconnector> WITH DCPROPERTIES 
> (....);
> Will attach a design doc to this jira. 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to