Skip to content
Open
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 @@ -27,8 +27,11 @@
import org.openmetadata.it.util.TestNamespaceExtension;
import org.openmetadata.it.util.UpdateType;
import org.openmetadata.schema.EntityInterface;
import org.openmetadata.schema.type.ApiStatus;
import org.openmetadata.schema.type.ChangeDescription;
import org.openmetadata.schema.type.TagLabel;
import org.openmetadata.schema.type.csv.CsvImportResult;
import org.openmetadata.schema.utils.JsonUtils;
import org.openmetadata.sdk.client.OpenMetadataClient;
import org.openmetadata.sdk.exceptions.InvalidRequestException;
import org.openmetadata.sdk.fluent.Users;
Expand Down Expand Up @@ -4194,6 +4197,20 @@ void test_importCsvDryRun(TestNamespace ns) {
// Import with dry run (should not actually modify data)
String result = service.importCsv(containerName, exportedCsv, true);
assertNotNull(result, "Import dry run should return a result");

// Verify CsvImportResult values
CsvImportResult importResult = JsonUtils.readValue(result, CsvImportResult.class);
assertNotNull(importResult, "Should parse CsvImportResult from response");
assertTrue(importResult.getDryRun(), "Should be a dry run");
assertNotNull(importResult.getStatus(), "Status should not be null");
assertTrue(
importResult.getNumberOfRowsProcessed() >= 0, "Rows processed should be non-negative");
assertTrue(importResult.getNumberOfRowsPassed() >= 0, "Rows passed should be non-negative");
assertTrue(importResult.getNumberOfRowsFailed() >= 0, "Rows failed should be non-negative");
assertEquals(
importResult.getNumberOfRowsProcessed(),
importResult.getNumberOfRowsPassed() + importResult.getNumberOfRowsFailed(),
"Rows processed should equal passed + failed");
} catch (org.openmetadata.sdk.exceptions.OpenMetadataException e) {
fail("Import/export failed: " + e.getMessage());
}
Expand Down Expand Up @@ -4227,6 +4244,18 @@ void test_importExportRoundTrip(TestNamespace ns) {
String result = service.importCsv(containerName, exportedCsv, false);
assertNotNull(result, "Import should return a result");

// Verify CsvImportResult values
CsvImportResult importResult = JsonUtils.readValue(result, CsvImportResult.class);
assertNotNull(importResult, "Should parse CsvImportResult from response");
assertFalse(importResult.getDryRun(), "Should not be a dry run");
assertEquals(
ApiStatus.SUCCESS,
importResult.getStatus(),
"Import should succeed: " + importResult.getImportResultsCsv());
assertTrue(
importResult.getNumberOfRowsProcessed() >= 0, "Rows processed should be non-negative");
assertEquals(0, importResult.getNumberOfRowsFailed(), "No rows should fail on round-trip");

// Export again and verify consistency
String reExportedCsv = service.exportCsv(containerName);
assertNotNull(reExportedCsv, "Re-export should return CSV data");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@
import org.openmetadata.it.util.TestNamespace;
import org.openmetadata.schema.api.data.CreateGlossary;
import org.openmetadata.schema.entity.data.Glossary;
import org.openmetadata.schema.type.ApiStatus;
import org.openmetadata.schema.type.EntityHistory;
import org.openmetadata.schema.type.EntityReference;
import org.openmetadata.schema.type.FieldChange;
import org.openmetadata.schema.type.TagLabel;
import org.openmetadata.schema.type.csv.CsvImportResult;
import org.openmetadata.schema.utils.JsonUtils;
import org.openmetadata.sdk.client.OpenMetadataClient;
import org.openmetadata.sdk.models.ListParams;
import org.openmetadata.sdk.models.ListResponse;
Expand Down Expand Up @@ -898,11 +901,22 @@ void test_bulkImportGlossaryTermsIncrementsVersion(TestNamespace ns) {
String csvContent = buildGlossaryTermsCsv(glossary.getFullyQualifiedName(), ns);

// Step 3: Import CSV using SYNC method (now also creates version history!)
CsvImportResult importResult = null;
try {
String result =
client.glossaries().importCsv(glossary.getFullyQualifiedName(), csvContent, false);
assertNotNull(result, "Import should return result");
// Result is a JSON string of CsvImportResult

importResult = JsonUtils.readValue(result, CsvImportResult.class);
assertNotNull(importResult, "Should parse CsvImportResult from response");
assertEquals(ApiStatus.SUCCESS, importResult.getStatus(), "Import should succeed");
// numberOfRowsProcessed = header row (1) + 3 data rows = 4
assertEquals(
4, importResult.getNumberOfRowsProcessed(), "Should process 4 rows (header + 3 data)");
assertEquals(
4, importResult.getNumberOfRowsPassed(), "All 4 rows should pass (header + 3 data)");
assertEquals(0, importResult.getNumberOfRowsFailed(), "No rows should fail");
assertFalse(importResult.getDryRun(), "Should not be a dry run");
} catch (Exception e) {
fail("CSV import failed: " + e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2025 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.openmetadata.csv;

/** Functional interface for receiving progress updates during CSV export operations. */
@FunctionalInterface
public interface CsvExportProgressCallback {
/**
* Called to report progress during CSV export.
*
* @param exported Number of entities exported so far
* @param total Total number of entities to export
* @param message Human-readable progress message
*/
void onProgress(int exported, int total, String message);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2025 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.openmetadata.csv;

@FunctionalInterface
public interface CsvImportProgressCallback {
void onProgress(int rowsProcessed, int totalRows, int batchNumber, String message);
}
Loading
Loading