nrg4878 commented on a change in pull request #2037:
URL: https://github.com/apache/hive/pull/2037#discussion_r597386228
##########
File path:
ql/src/java/org/apache/hadoop/hive/ql/ddl/database/create/CreateDatabaseAnalyzer.java
##########
@@ -70,19 +73,43 @@ public void analyzeInternal(ASTNode root) throws
SemanticException {
managedLocationUri =
unescapeSQLString(childNode.getChild(0).getText());
outputs.add(toWriteEntity(managedLocationUri));
break;
+ case HiveParser.TOK_DATACONNECTOR:
+ type = "REMOTE";
+ // locationUri = "REMOTE_DATABASE"; // TODO
+ ASTNode nextNode = (ASTNode) root.getChild(i);
+ connectorName = ((ASTNode)nextNode).getChild(0).getText();
+ outputs.add(toWriteEntity(connectorName));
+ // outputs.remove(toWriteEntity(locationUri));
+ if (managedLocationUri != null) {
+ outputs.remove(toWriteEntity(managedLocationUri));
+ managedLocationUri = null;
+ }
+ break;
default:
throw new SemanticException("Unrecognized token in CREATE DATABASE
statement");
}
}
- CreateDatabaseDesc desc = new CreateDatabaseDesc(databaseName, comment,
locationUri, managedLocationUri,
- ifNotExists, props);
- rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(),
desc)));
-
+ CreateDatabaseDesc desc = null;
Database database = new Database(databaseName, comment, locationUri,
props);
- if (managedLocationUri != null) {
- database.setManagedLocationUri(managedLocationUri);
+ if (type.equalsIgnoreCase("NATIVE")) {
+ desc = new CreateDatabaseDesc(databaseName, comment, locationUri,
managedLocationUri, ifNotExists, props);
+ database.setType(DatabaseType.NATIVE);
+ // database = new Database(databaseName, comment, locationUri, props);
+ if (managedLocationUri != null) {
+ database.setManagedLocationUri(managedLocationUri);
+ }
+ } else {
+ String remoteDbName = databaseName;
+ if (props != null && props.get("connector.remoteDbName") != null) //
TODO finalize the property name
+ remoteDbName = props.get("connector.remoteDbName");
+ desc = new CreateDatabaseDesc(databaseName, comment, locationUri, null,
ifNotExists, props, type,
Review comment:
I am not sure I understand the question. But I can explain this logic.
For NATIVE DBs, location and optionally managedlocation make sense.
For REMOTE DBs, neither of them have any significance and the data for the
tables within this DB is in the remote source. So the 4 lines of code above are
specific to when a REMOTE DB is being created. For such DBs, users can
optionally include a "connector.remoteDbName" in the DBPROPERTIES to use map
the hive DB to a remote DB with a different name than the Hive DB.
For example,
create remote database mysql_testdb using .... // maps "mysql_testdb" to
"mysql_testdb" in the remote datasource as well because the create statement
does not include an alternate name in the DBPROPERTIES.
create remote database mysql_testdb using mysql_connector with DBPROPERTIES
("connector.remoteDbName"="mydb")
this maps mysql_testdb to database named "mydb" in the remote datasource.
Hope this helps.
--
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:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]