From 614ef0d5f9dcef05cdeeec08d471c312e03c80fb Mon Sep 17 00:00:00 2001 From: Christopher Grote Date: Tue, 28 Jan 2025 19:00:45 +0000 Subject: [PATCH] Make error conditional based on point at which code is resolving Signed-off-by: Christopher Grote --- .../kotlin/com/atlan/pkg/rab/AssetXformer.kt | 20 +++++++++++++++---- .../main/kotlin/com/atlan/pkg/rab/Importer.kt | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/samples/packages/relational-assets-builder/src/main/kotlin/com/atlan/pkg/rab/AssetXformer.kt b/samples/packages/relational-assets-builder/src/main/kotlin/com/atlan/pkg/rab/AssetXformer.kt index e7bcecfc40..f78c0ea091 100644 --- a/samples/packages/relational-assets-builder/src/main/kotlin/com/atlan/pkg/rab/AssetXformer.kt +++ b/samples/packages/relational-assets-builder/src/main/kotlin/com/atlan/pkg/rab/AssetXformer.kt @@ -95,11 +95,19 @@ abstract class AssetXformer( fun getConnectorType(inputRow: Map): String = trimWhitespace(inputRow.getOrElse("connectorType") { "" }) - /** {@inheritDoc} */ + /** + * Attempt to resolve the full SQL hierarchy details of a row (asset). + * Note: when the entityQualifiedNameToType is not passed, only very limited details can be resolved and returned, + * so use with caution unless you're able to provide the entityQualifiedNameToType map. + * + * @param row of data, representing a single asset + * @param typeName of that single row's asset + * @param entityQualifiedNameToType a map from unresolved (unique) qualifiedName of an asset to its type + */ fun getSQLHierarchyDetails( row: Map, typeName: String, - entityQualifiedNameToType: Map, + entityQualifiedNameToType: Map? = null, ): SQLHierarchyDetails { val parent: SQLHierarchyDetails? val current: String @@ -122,8 +130,12 @@ abstract class AssetXformer( "CONTAINER", Table.TYPE_NAME, View.TYPE_NAME, MaterializedView.TYPE_NAME -> { current = trimWhitespace(row.getOrElse(ENTITY_NAME) { "" }) parent = getSQLHierarchyDetails(row, Schema.TYPE_NAME, entityQualifiedNameToType) - actualTypeName = entityQualifiedNameToType.getOrElse("${parent.uniqueQN}/$current") { - throw IllegalStateException("Could not find any table/view at: ${parent.uniqueQN}/$current") + // Only do this lookup if we have been passed a map -- otherwise this is detail that cannot + // yet be resolved (and will not yet be used, either) + if (entityQualifiedNameToType != null) { + actualTypeName = entityQualifiedNameToType.getOrElse("${parent.uniqueQN}/$current") { + throw IllegalStateException("Could not find any table/view at: ${parent.uniqueQN}/$current") + } } } Column.TYPE_NAME -> { diff --git a/samples/packages/relational-assets-builder/src/main/kotlin/com/atlan/pkg/rab/Importer.kt b/samples/packages/relational-assets-builder/src/main/kotlin/com/atlan/pkg/rab/Importer.kt index b27e681b8d..91cded1407 100644 --- a/samples/packages/relational-assets-builder/src/main/kotlin/com/atlan/pkg/rab/Importer.kt +++ b/samples/packages/relational-assets-builder/src/main/kotlin/com/atlan/pkg/rab/Importer.kt @@ -239,7 +239,7 @@ object Importer { ): List { val values = row.toMutableList() val typeName = CSVXformer.trimWhitespace(values.getOrElse(typeIdx) { "" }) - val qnDetails = getSQLHierarchyDetails(CSVXformer.getRowByHeader(header, values), typeName, entityQualifiedNameToType) + val qnDetails = getSQLHierarchyDetails(CSVXformer.getRowByHeader(header, values), typeName) if (typeName !in setOf(Table.TYPE_NAME, View.TYPE_NAME, MaterializedView.TYPE_NAME)) { if (!qualifiedNameToChildCount.containsKey(qnDetails.parentUniqueQN)) { qualifiedNameToChildCount[qnDetails.parentUniqueQN] = AtomicInteger(0)