mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-30 11:56:01 +00:00
Fix Table Column Imports (#18924)
* Fix Table Column Imports * Fix import status and header name
This commit is contained in:
parent
0629750e0a
commit
fb9bd00a44
@ -1285,34 +1285,38 @@ public class TableRepository extends EntityRepository<Table> {
|
|||||||
// column.dataTypeDisplay,column.dataType, column.arrayDataType, column.dataLength,
|
// column.dataTypeDisplay,column.dataType, column.arrayDataType, column.dataLength,
|
||||||
// column.tags, column.glossaryTerms
|
// column.tags, column.glossaryTerms
|
||||||
Table originalEntity = JsonUtils.deepCopy(table, Table.class);
|
Table originalEntity = JsonUtils.deepCopy(table, Table.class);
|
||||||
|
while (recordIndex < csvRecords.size()) {
|
||||||
CSVRecord csvRecord = getNextRecord(printer, csvRecords);
|
CSVRecord csvRecord = getNextRecord(printer, csvRecords);
|
||||||
if (csvRecord != null) {
|
if (csvRecord != null) {
|
||||||
updateColumnsFromCsv(printer, csvRecord);
|
updateColumnsFromCsv(printer, csvRecord);
|
||||||
|
String violations = ValidatorUtil.validate(table);
|
||||||
|
if (violations != null) {
|
||||||
|
// JSON schema based validation failed for the entity
|
||||||
|
importFailure(printer, violations, csvRecord);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (processRecord) {
|
if (processRecord) {
|
||||||
patchColumns(originalEntity, printer, csvRecord, table);
|
patchColumns(originalEntity, printer, csvRecords, table);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void patchColumns(
|
private void patchColumns(
|
||||||
Table originalTable, CSVPrinter resultsPrinter, CSVRecord csvRecord, Table entity)
|
Table originalTable, CSVPrinter resultsPrinter, List<CSVRecord> records, Table entity)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
EntityRepository<Table> repository =
|
EntityRepository<Table> repository =
|
||||||
(EntityRepository<Table>) Entity.getEntityRepository(TABLE);
|
(EntityRepository<Table>) Entity.getEntityRepository(TABLE);
|
||||||
// Validate
|
|
||||||
String violations = ValidatorUtil.validate(entity);
|
|
||||||
if (violations != null) {
|
|
||||||
// JSON schema based validation failed for the entity
|
|
||||||
importFailure(resultsPrinter, violations, csvRecord);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (Boolean.FALSE.equals(importResult.getDryRun())) { // If not dry run, create the entity
|
if (Boolean.FALSE.equals(importResult.getDryRun())) { // If not dry run, create the entity
|
||||||
try {
|
try {
|
||||||
JsonPatch jsonPatch = JsonUtils.getJsonPatch(originalTable, table);
|
JsonPatch jsonPatch = JsonUtils.getJsonPatch(originalTable, table);
|
||||||
repository.patch(null, table.getId(), importedBy, jsonPatch);
|
repository.patch(null, table.getId(), importedBy, jsonPatch);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
importFailure(resultsPrinter, ex.getMessage(), csvRecord);
|
for (int i = 1; i < records.size(); i++) {
|
||||||
|
importFailure(resultsPrinter, ex.getMessage(), records.get(i));
|
||||||
importResult.setStatus(ApiStatus.FAILURE);
|
importResult.setStatus(ApiStatus.FAILURE);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else { // Dry run don't create the entity
|
} else { // Dry run don't create the entity
|
||||||
@ -1324,7 +1328,9 @@ public class TableRepository extends EntityRepository<Table> {
|
|||||||
dryRunCreatedEntities.put(entity.getFullyQualifiedName(), entity);
|
dryRunCreatedEntities.put(entity.getFullyQualifiedName(), entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
importSuccess(resultsPrinter, csvRecord, ENTITY_UPDATED);
|
for (int i = 1; i < records.size(); i++) {
|
||||||
|
importSuccess(resultsPrinter, records.get(i), ENTITY_UPDATED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateColumnsFromCsv(CSVPrinter printer, CSVRecord csvRecord) throws IOException {
|
public void updateColumnsFromCsv(CSVPrinter printer, CSVRecord csvRecord) throws IOException {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"summary": "Table CSV file is used for importing and exporting table metadata from and to an **existing** table.",
|
"summary": "Table CSV file is used for importing and exporting table metadata from and to an **existing** table.",
|
||||||
"headers": [
|
"headers": [
|
||||||
{
|
{
|
||||||
"name": "column.fullyQualifiedName",
|
"name": "column.name",
|
||||||
"required": true,
|
"required": true,
|
||||||
"description": "Fully qualified name of the column.",
|
"description": "Fully qualified name of the column.",
|
||||||
"examples": [
|
"examples": [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user