Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix topics with periods for hive #136 #137

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void alterSchema(String database, String tableName, Schema schema) throws

private Table constructAvroTable(String database, String tableName, Schema schema, Partitioner partitioner)
throws HiveMetaStoreException {
Table table = new Table(database, tableName);
Table table = HiveMetaStore.newTable(database, tableName);
table.setTableType(TableType.EXTERNAL_TABLE);
table.getParameters().put("EXTERNAL", "TRUE");
String tablePath = FileUtils.hiveDirectoryName(url, topicsDir, tableName);
Expand Down
52 changes: 33 additions & 19 deletions src/main/java/io/confluent/connect/hdfs/hive/HiveMetaStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,23 @@

package io.confluent.connect.hdfs.hive;

import io.confluent.connect.hdfs.FileUtils;
import javafx.scene.control.Tab;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you cleanup these imports? I don't see them used anywhere.

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.metastore.IMetaStoreClient;
import org.apache.hadoop.hive.metastore.TableType;
import org.apache.hadoop.hive.metastore.api.AlreadyExistsException;
import org.apache.hadoop.hive.metastore.api.Database;
import org.apache.hadoop.hive.metastore.api.FieldSchema;
import org.apache.hadoop.hive.metastore.api.InvalidObjectException;
import org.apache.hadoop.hive.metastore.api.InvalidOperationException;
import org.apache.hadoop.hive.metastore.api.MetaException;
import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
import org.apache.hadoop.hive.metastore.api.Partition;
import org.apache.hadoop.hive.metastore.api.UnknownDBException;
import org.apache.hadoop.hive.ql.metadata.HiveException;
import org.apache.hadoop.hive.ql.metadata.Table;
import org.apache.hive.hcatalog.common.HCatUtil;
import org.apache.thrift.TException;
Expand Down Expand Up @@ -94,7 +99,7 @@ public Void call() throws TException {
// purposely don't check if the partition already exists because
// getPartition(db, table, path) will throw an exception to indicate the
// partition doesn't exist also. this way, it's only one call.
client.appendPartition(database, tableName, path);
client.appendPartition(database, tableNameConverter(tableName), path);
return null;
}
};
Expand All @@ -104,7 +109,7 @@ public Void call() throws TException {
} catch (AlreadyExistsException e) {
// this is okay
} catch (InvalidObjectException e) {
throw new HiveMetaStoreException("Invalid partition for " + database + "." + tableName + ": " + path, e);
throw new HiveMetaStoreException("Invalid partition for " + database + "." + tableNameConverter(tableName) + ": " + path, e);
} catch (MetaException e) {
throw new HiveMetaStoreException("Hive MetaStore exception", e);
} catch (TException e) {
Expand All @@ -116,7 +121,7 @@ public void dropPartition(final String database, final String tableName, final S
ClientAction<Void> dropPartition = new ClientAction<Void>() {
@Override
public Void call() throws TException {
client.dropPartition(database, tableName, path, false);
client.dropPartition(database, tableNameConverter(tableName), path, false);
return null;
}
};
Expand All @@ -126,7 +131,7 @@ public Void call() throws TException {
} catch (NoSuchObjectException e) {
// this is okay
} catch (InvalidObjectException e) {
throw new HiveMetaStoreException("Invalid partition for " + database + "." + tableName + ": " + path, e);
throw new HiveMetaStoreException("Invalid partition for " + database + "." + tableNameConverter(tableName) + ": " + path, e);
} catch (MetaException e) {
throw new HiveMetaStoreException("Hive MetaStore exception", e);
} catch (TException e) {
Expand Down Expand Up @@ -182,6 +187,7 @@ public void createTable(final Table table) throws HiveMetaStoreException {
ClientAction<Void> create = new ClientAction<Void>() {
@Override
public Void call() throws TException {

client.createTable(table.getTTable());
return null;
}
Expand All @@ -192,7 +198,7 @@ public Void call() throws TException {
try {
doAction(create);
} catch (NoSuchObjectException e) {
throw new HiveMetaStoreException("Hive table not found: " + table.getDbName() + "." + table.getTableName());
throw new HiveMetaStoreException("Hive table not found: " + table.getDbName() + "." + tableNameConverter(table.getTableName()));
} catch (AlreadyExistsException e) {
// this is okey
log.warn("Hive table already exists: {}.{}", table.getDbName(), table.getTableName());
Expand All @@ -209,7 +215,7 @@ public void alterTable(final Table table) throws HiveMetaStoreException {
ClientAction<Void> alter = new ClientAction<Void>() {
@Override
public Void call() throws TException {
client.alter_table(table.getDbName(), table.getTableName(), table.getTTable());
client.alter_table(table.getDbName(), tableNameConverter(table.getTableName()), table.getTTable());
return null;
}
};
Expand All @@ -233,7 +239,7 @@ public void dropTable(final String database, final String tableName) {
ClientAction<Void> drop = new ClientAction<Void>() {
@Override
public Void call() throws TException {
client.dropTable(database, tableName, false, true);
client.dropTable(database, tableNameConverter(tableName), false, true);
return null;
}
};
Expand All @@ -253,7 +259,7 @@ public boolean tableExists(final String database, final String tableName) throws
ClientAction<Boolean> exists = new ClientAction<Boolean>() {
@Override
public Boolean call() throws TException {
return client.tableExists(database, tableName);
return client.tableExists(database, tableNameConverter(tableName));
}
};
try {
Expand All @@ -271,23 +277,23 @@ public Table getTable(final String database, final String tableName) throws Hive
ClientAction<Table> getTable = new ClientAction<Table>() {
@Override
public Table call() throws TException {
return new Table(client.getTable(database, tableName));
return new Table(client.getTable(database, tableNameConverter(tableName)));
}
};

Table table;
try {
table = doAction(getTable);
} catch (NoSuchObjectException e) {
throw new HiveMetaStoreException("Hive table not found: " + database + "." + tableName);
throw new HiveMetaStoreException("Hive table not found: " + database + "." + tableNameConverter(tableName));
} catch (MetaException e) {
throw new HiveMetaStoreException("Hive table lookup exception", e);
} catch (TException e) {
throw new HiveMetaStoreException("Exception communicating with the Hive MetaStore", e);
}

if (table == null) {
throw new HiveMetaStoreException("Could not find info for table: " + tableName);
throw new HiveMetaStoreException("Could not find info for table: " + tableNameConverter(tableName));
}
return table;
}
Expand All @@ -296,7 +302,7 @@ public List<String> listPartitions(final String database, final String tableName
ClientAction<List<String>> listPartitions = new ClientAction<List<String>>() {
@Override
public List<String> call() throws TException {
List<Partition> partitions = client.listPartitions(database, tableName, max);
List<Partition> partitions = client.listPartitions(database, tableNameConverter(tableName), max);
List<String> paths = new ArrayList<>();
for (Partition partition : partitions) {
paths.add(partition.getSd().getLocation());
Expand Down Expand Up @@ -337,12 +343,12 @@ public List<String> call() throws TException {

public List<String> getAllDatabases() throws HiveMetaStoreException {
ClientAction<List<String>> create =
new ClientAction<List<String>>() {
@Override
public List<String> call() throws TException {
return client.getAllDatabases();
}
};
new ClientAction<List<String>>() {
@Override
public List<String> call() throws TException {
return client.getAllDatabases();
}
};

try {
return doAction(create);
Expand All @@ -354,4 +360,12 @@ public List<String> call() throws TException {
throw new HiveMetaStoreException("Exception communicating with the Hive MetaStore", e);
}
}
}

public static String tableNameConverter(String table){
return table == null ? table : table.replaceAll("\\.", "_");
}

public static Table newTable(String database, String table){
return new Table(database, tableNameConverter(table));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void alterSchema(String database, String tableName, Schema schema) {
}

private Table constructParquetTable(String database, String tableName, Schema schema, Partitioner partitioner) throws HiveMetaStoreException {
Table table = new Table(database, tableName);
Table table = HiveMetaStore.newTable(database, tableName);
table.setTableType(TableType.EXTERNAL_TABLE);
table.getParameters().put("EXTERNAL", "TRUE");
String tablePath = FileUtils.hiveDirectoryName(url, topicsDir, tableName);
Expand Down