Skip to content

Commit

Permalink
Revert to 1-based levels for cubes rather than 0-based
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Grote <cmgrote@users.noreply.github.com>
  • Loading branch information
cmgrote committed Aug 20, 2024
1 parent 6ed0270 commit 2b03c50
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class FieldImporter(
trackBatches,
fieldSeparator,
) {
private val leafNodeLevel = 1L
private var generationToProcess = 0L

// Maximum depth of any field in the CSV (overall and by hierarchy)
Expand All @@ -69,7 +70,7 @@ class FieldImporter(
val path = getFieldPath(hierarchyPath, row, header)
if (!maxLevelByPath.containsKey(path)) {
// If path not yet seen, treat it as a leaf (for now)
maxLevelByPath[path] = AtomicLong(0L)
maxLevelByPath[path] = AtomicLong(leafNodeLevel)
}
bubbleUpParentLevel(path, hierarchyPath)
// Consider whether we need to update the maximum depth of fields we need to load
Expand All @@ -94,7 +95,7 @@ class FieldImporter(
val levelFromThisChild = maxLevelByPath[path]!!.get() + 1
val parentPath = StringUtils.getParentQualifiedNameFromQualifiedName(path, Importer.QN_DELIMITER)
if (parentPath != null) {
val currentParentLevel = maxLevelByPath[parentPath]?.get() ?: 0L
val currentParentLevel = maxLevelByPath[parentPath]?.get() ?: leafNodeLevel
// Logic for level calculation:
// - If there are no children, level = 0
// - Else level = max(child) + 1
Expand Down Expand Up @@ -187,7 +188,7 @@ class FieldImporter(
*/
private fun getFieldLevel(row: List<String>, header: List<String>): Long {
val path = getFieldPath(getHierarchyPath(row, header), row, header)
return maxLevelByPath[path]?.get() ?: 0L
return maxLevelByPath[path]?.get() ?: leafNodeLevel
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ class CreateThenUpsertCABTest : PackageTest() {
"COL1" -> {
assertEquals(displayCol1, field.displayName)
assertNull(field.cubeParentField)
assertEquals(2, field.cubeFieldLevel)
assertEquals(3, field.cubeFieldLevel)
assertEquals(1, field.cubeFieldGeneration)
assertNotNull(field.cubeNestedFields)
assertEquals(1, field.cubeNestedFields.size)
Expand All @@ -360,7 +360,7 @@ class CreateThenUpsertCABTest : PackageTest() {
assertEquals(displayCol2, field.displayName)
assertNotNull(field.cubeParentField)
assertEquals("COL1", field.cubeParentField.name)
assertEquals(1, field.cubeFieldLevel)
assertEquals(2, field.cubeFieldLevel)
assertEquals(2, field.cubeFieldGeneration)
assertNotNull(field.cubeNestedFields)
assertEquals(1, field.cubeNestedFields.size)
Expand All @@ -370,7 +370,7 @@ class CreateThenUpsertCABTest : PackageTest() {
assertEquals(displayCol3, field.displayName)
assertNotNull(field.cubeParentField)
assertEquals("COL2", field.cubeParentField.name)
assertEquals(0, field.cubeFieldLevel)
assertEquals(1, field.cubeFieldLevel)
assertEquals(3, field.cubeFieldGeneration)
assertTrue(field.cubeNestedFields.isNullOrEmpty())
assertEquals(0, field.cubeSubFieldCount)
Expand Down Expand Up @@ -452,7 +452,7 @@ class CreateThenUpsertCABTest : PackageTest() {
"COL4" -> {
assertEquals("Test field 4", field.displayName)
assertNull(field.cubeParentField)
assertEquals(1, field.cubeFieldLevel)
assertEquals(2, field.cubeFieldLevel)
assertEquals(1, field.cubeFieldGeneration)
assertNotNull(field.cubeNestedFields)
assertEquals(1, field.cubeNestedFields.size)
Expand All @@ -462,7 +462,7 @@ class CreateThenUpsertCABTest : PackageTest() {
assertEquals("Test field 5", field.displayName)
assertNotNull(field.cubeParentField)
assertEquals("COL4", field.cubeParentField.name)
assertEquals(0, field.cubeFieldLevel)
assertEquals(1, field.cubeFieldLevel)
assertEquals(2, field.cubeFieldGeneration)
assertTrue(field.cubeNestedFields.isNullOrEmpty())
assertEquals(0, field.cubeSubFieldCount)
Expand Down

0 comments on commit 2b03c50

Please sign in to comment.