rdblue commented on a change in pull request #187: Catalog Implementation for
hive and hadoop.
URL: https://github.com/apache/incubator-iceberg/pull/187#discussion_r284916955
##########
File path: hive/src/main/java/org/apache/iceberg/hive/HiveCatalog.java
##########
@@ -0,0 +1,79 @@
+package org.apache.iceberg.hive;
+
+import java.io.IOException;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.iceberg.BaseMetastoreCatalog;
+import org.apache.iceberg.BaseTable;
+import org.apache.iceberg.TableOperations;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.thrift.TException;
+
+import static
org.apache.iceberg.BaseMetastoreTableOperations.METADATA_LOCATION_PROP;
+
+public class HiveCatalog extends BaseMetastoreCatalog {
+
+ private final HiveClientPool clients;
+ private final Configuration conf;
+
+ public HiveCatalog(Configuration conf) {
+ super(conf);
+ this.conf = conf;
+ this.clients = new HiveClientPool(2, conf);
+ }
+
+ @Override
+ public void dropTable(TableIdentifier tableIdentifier) {
+ validateTableIdentifier(tableIdentifier);
+ HiveMetaStoreClient hiveMetaStoreClient = this.clients.newClient();
+ try {
+ hiveMetaStoreClient.dropTable(tableIdentifier.namespace().levels()[0],
tableIdentifier.name());
+ } catch (TException e) {
+ throw new RuntimeException("Failed to drop " +
tableIdentifier.toString(), e);
+ }
+ }
+
+ @Override
+ public void renameTable(TableIdentifier from, TableIdentifier to) {
+ validateTableIdentifier(from);
+ validateTableIdentifier(to);
+
+ HiveMetaStoreClient hiveMetaStoreClient = this.clients.newClient();
+ String location = ((BaseTable)
getTable(from)).operations().current().file().location();
+ String newDBName = to.namespace().levels()[0];
+ String oldDBName = from.namespace().levels()[0];
+ String newTableName = to.name();
+ String oldTableName = from.name();
+
+ String newLocation = location.replaceFirst(oldDBName, newDBName)
+ .replaceFirst(oldTableName, newTableName);
+ try {
+ Table table = hiveMetaStoreClient.getTable(oldDBName, oldTableName);
+
+ // hive metastore renames the table's directory as part of renaming the
table.
Review comment:
It does?
----------------------------------------------------------------
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]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]