Skip to content

Commit

Permalink
Make error conditional based on point at which code is resolving
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Grote <[email protected]>
  • Loading branch information
cmgrote committed Jan 28, 2025
1 parent 88dec07 commit 614ef0d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,19 @@ abstract class AssetXformer(

fun getConnectorType(inputRow: Map<String, String>): 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<String, String>,
typeName: String,
entityQualifiedNameToType: Map<String, String>,
entityQualifiedNameToType: Map<String, String>? = null,
): SQLHierarchyDetails {
val parent: SQLHierarchyDetails?
val current: String
Expand All @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ object Importer {
): List<String> {
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)
Expand Down

0 comments on commit 614ef0d

Please sign in to comment.