Skip to content

Map<String, Any?> to DataRow conversion with nested maps #1755

@Jolanrensen

Description

@Jolanrensen

While map.toDataRow() is very helpful, there's no easy way to fully unfold nested maps to to datarows, like

val map = mapOf(
    "name" to "a",
    "metadata" to
        mapOf(
            "country" to "Philippines",
            "region" to mapOf("name" to "Caraga", "code" to "XIII"),
            "population" to mapOf("value" to "12345", "year" to 2020),
            "wrongMap" to mapOf(1 to 2, 4 to 4),
        ),
)

Similarly to unfold and toDataFrame(), we could add a maxDepth parameter that would allow us to specify the maximum depth of nesting we scan for and convert.
convertKeysToString: Boolean might be another nice addition because there's no way to tell if keys are strings or not until we encounter a ClassCastException.

Iterable<Map<String, Any?>>.toDataFrame() should probably gain the same treatment.

And if we're converting keys to strings anyways, let's make it work for Map<Any, Any?>, why not

Metadata

Metadata

Assignees

No one assigned

    Labels

    APIIf it touches our APIenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions