Skip to content

Commit 6b66d8d

Browse files
authored
Fixed issue where renaming a table to a name that already existed fails when updating the user metadata since in Metacat(based on app configuration) we do not drop the metadata. (Netflix#299)
1 parent f6f70f1 commit 6b66d8d

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

metacat-common/src/main/java/com/netflix/metacat/common/dto/notifications/sns/SNSMessage.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
@ToString
3939
@EqualsAndHashCode(callSuper = false)
4040
public class SNSMessage<P> extends BaseDto {
41-
41+
private final String source = "metacat";
4242
private final String id;
4343
private final long timestamp;
4444
private final String requestId;

metacat-functional-tests/src/functionalTest/groovy/com/netflix/metacat/MetacatSmokeSpec.groovy

+6
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,12 @@ class MetacatSmokeSpec extends Specification {
548548
then:
549549
noExceptionThrown()
550550
when:
551+
createTable(catalogName, databaseName, tableName1, 'TRUE')
552+
api.deleteTable(catalogName, databaseName, tableName)
553+
api.renameTable(catalogName, databaseName, tableName1, tableName)
554+
then:
555+
noExceptionThrown()
556+
when:
551557
api.renameTable(catalogName, databaseName, tableName, tableName1)
552558
then:
553559
noExceptionThrown()

metacat-metadata-mysql/src/main/java/com/netflix/metacat/metadata/mysql/MySqlTagService.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ public void renameTableTags(final QualifiedName name, final String newTableName)
217217
try {
218218
final QualifiedName newName = QualifiedName.ofTable(name.getCatalogName(), name.getDatabaseName(),
219219
newTableName);
220-
jdbcTemplate.update(SQL_UPDATE_TAG_ITEM,
221-
new String[]{MysqlUserMetadataService.DELETE_MARKER + newName.toString(), newName.toString()},
222-
new int[]{Types.VARCHAR, Types.VARCHAR});
220+
if (get(newName) != null) {
221+
delete(newName, true);
222+
}
223223
jdbcTemplate.update(SQL_UPDATE_TAG_ITEM, new String[]{newName.toString(), name.toString()},
224224
new int[]{Types.VARCHAR, Types.VARCHAR});
225225
} catch (Exception e) {

metacat-metadata-mysql/src/main/java/com/netflix/metacat/metadata/mysql/MysqlUserMetadataService.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@
6464
@SuppressFBWarnings
6565
@Transactional("metadataTxManager")
6666
public class MysqlUserMetadataService extends BaseUserMetadataService {
67-
/**
68-
* Marker for the items that are marked deleted.
69-
* TODO: Need to better handle soft delete.
70-
*/
71-
public static final String DELETE_MARKER = "_";
7267
private final MetacatJson metacatJson;
7368
private final Config config;
7469
private JdbcTemplate jdbcTemplate;
@@ -594,7 +589,7 @@ public int renameDataMetadataKey(
594589
public int renameDefinitionMetadataKey(
595590
@Nonnull final QualifiedName oldName,
596591
@Nonnull final QualifiedName newName) {
597-
executeUpdateForKey(SQL.RENAME_DEFINITION_METADATA, DELETE_MARKER + newName.toString(), newName.toString());
592+
_deleteDefinitionMetadata(Lists.newArrayList(newName));
598593
return executeUpdateForKey(SQL.RENAME_DEFINITION_METADATA, newName.toString(), oldName.toString());
599594
}
600595

metacat-testdata-provider/src/main/groovy/com/netflix/metacat/testdata/provider/PigDataDtoProvider.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,6 @@ class PigDataDtoProvider {
242242
}
243243

244244
def static getDefinitionMetadata(String owner){
245-
return metacatJson.parseJsonObject('{"hive": {"cleanup": true},"owner": {"team": "Cloud Platform Engineering","userId":"' + owner + '","name":"' + owner + '"}}')
245+
return metacatJson.parseJsonObject('{"hive": {"cleanup": true},"tags":["unused"],"owner": {"team": "Cloud Platform Engineering","userId":"' + owner + '","name":"' + owner + '"}}')
246246
}
247247
}

0 commit comments

Comments
 (0)