use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class MySqlTagService method rename.
@Override
public Void rename(final QualifiedName name, final String newTableName) {
try {
final Connection conn = getDataSource().getConnection();
try {
final QualifiedName newName = QualifiedName.ofTable(name.getCatalogName(), name.getDatabaseName(), newTableName);
new QueryRunner().update(conn, SQL_UPDATE_TAG_ITEM, newName.toString(), name.toString());
conn.commit();
} catch (Exception e) {
conn.rollback();
throw e;
} finally {
conn.close();
}
} catch (SQLException e) {
final String message = String.format("Failed to rename item name %s", name);
log.error(message, e);
throw new UserMetadataServiceException(message, e);
}
return null;
}
use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class HiveConvertersImpl method metacatToHiveTable.
/**
* {@inheritDoc}
*/
@Override
public Table metacatToHiveTable(final TableDto dto) {
final Table table = new Table();
String tableName = "";
String databaseName = "";
final QualifiedName name = dto.getName();
if (name != null) {
tableName = name.getTableName();
databaseName = name.getDatabaseName();
}
table.setTableName(tableName);
table.setDbName(databaseName);
final StorageDto storageDto = dto.getSerde();
String owner = "";
if (storageDto != null && storageDto.getOwner() != null) {
owner = storageDto.getOwner();
}
table.setOwner(owner);
final AuditDto auditDto = dto.getAudit();
if (auditDto != null && auditDto.getCreatedDate() != null) {
table.setCreateTime(dateToEpochSeconds(auditDto.getCreatedDate()));
}
Map<String, String> params = new HashMap<>();
if (dto.getMetadata() != null) {
params = dto.getMetadata();
}
table.setParameters(params);
// TODO get this
table.setTableType("EXTERNAL_TABLE");
table.setSd(fromStorageDto(storageDto));
final StorageDescriptor sd = table.getSd();
final List<FieldDto> fields = dto.getFields();
if (fields == null) {
table.setPartitionKeys(Collections.emptyList());
sd.setCols(Collections.emptyList());
} else {
final List<FieldSchema> nonPartitionFields = Lists.newArrayListWithCapacity(fields.size());
final List<FieldSchema> partitionFields = Lists.newArrayListWithCapacity(fields.size());
for (FieldDto fieldDto : fields) {
final FieldSchema f = metacatToHiveField(fieldDto);
if (fieldDto.isPartition_key()) {
partitionFields.add(f);
} else {
nonPartitionFields.add(f);
}
}
table.setPartitionKeys(partitionFields);
sd.setCols(nonPartitionFields);
}
return table;
}
use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class HiveConvertersImpl method metacatToHiveDatabase.
/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings("unchecked")
public Database metacatToHiveDatabase(final DatabaseDto dto) {
final Database database = new Database();
String name = "";
String description = "";
final QualifiedName databaseName = dto.getName();
if (databaseName != null) {
name = databaseName.getDatabaseName();
// Since this is required setting it to the same as the DB name for now
description = databaseName.getDatabaseName();
}
database.setName(name);
database.setDescription(description);
String dbUri = dto.getUri();
if (Strings.isNullOrEmpty(dbUri)) {
dbUri = "";
}
database.setLocationUri(dbUri);
Map<String, String> metadata = dto.getMetadata();
if (metadata == null) {
metadata = Collections.EMPTY_MAP;
}
database.setParameters(metadata);
return database;
}
use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class CatalogThriftHiveMetastore method alter_table_with_environment_context.
/**
* {@inheritDoc}
*/
@Override
public void alter_table_with_environment_context(final String dbname, final String tblName, final Table newTbl, @Nullable final EnvironmentContext environmentContext) throws TException {
requestWrapper("alter_table_with_environment_context", new Object[] { dbname, tblName, newTbl, environmentContext }, () -> {
final String databaseName = normalizeIdentifier(dbname);
final String tableName = normalizeIdentifier(tblName);
final QualifiedName oldName = QualifiedName.ofTable(catalogName, databaseName, tableName);
final QualifiedName newName = QualifiedName.ofTable(catalogName, newTbl.getDbName(), newTbl.getTableName());
final TableDto dto = hiveConverters.hiveToMetacatTable(newName, newTbl);
if (!oldName.equals(newName)) {
v1.renameTable(catalogName, oldName.getDatabaseName(), oldName.getTableName(), newName.getTableName());
}
v1.updateTable(catalogName, dbname, newName.getTableName(), dto);
return null;
});
}
use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class CatalogThriftHiveMetastore method create_table_with_environment_context.
/**
* {@inheritDoc}
*/
@Override
public void create_table_with_environment_context(final Table tbl, @Nullable final EnvironmentContext environmentContext) throws TException {
requestWrapper("create_table_with_environment_context", new Object[] { tbl, environmentContext }, () -> {
final String dbname = normalizeIdentifier(tbl.getDbName());
final String tblName = normalizeIdentifier(tbl.getTableName());
final QualifiedName name = QualifiedName.ofTable(catalogName, dbname, tblName);
final TableDto dto = hiveConverters.hiveToMetacatTable(name, tbl);
v1.createTable(catalogName, dbname, tblName, dto);
return null;
});
}
Aggregations