Skip to content
Merged
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 @@ -322,8 +322,10 @@ public class AddDsl<T>(
add(dsl.columns.toColumnGroup(name))
}

@Interpretable("AddDslAddGroup")
public fun group(body: AddDsl<T>.() -> Unit): AddGroup<T> = AddGroup(body)

@Interpretable("AddDslAddGroupInto")
public infix fun AddGroup<T>.into(groupName: String): Unit = group(groupName, body)

@Deprecated(DEPRECATED_ACCESS_API)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ public interface TraversePropertiesDsl {
public fun preserve(vararg properties: KCallable<*>)
}

/**
* Store values of given type [T] in ValueColumns without transformation into ColumnGroups or FrameColumns.
*/
@Interpretable("PreserveT")
public inline fun <reified T> TraversePropertiesDsl.preserve(): Unit = preserve(T::class)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never knew we had this function, thanks for the docs!


public abstract class CreateDataFrameDsl<T> : TraversePropertiesDsl {
Expand All @@ -177,8 +181,10 @@ public abstract class CreateDataFrameDsl<T> : TraversePropertiesDsl {

public abstract fun add(column: AnyBaseCol, path: ColumnPath? = null)

@Interpretable("ToDataFrameDslIntoString")
public infix fun AnyBaseCol.into(name: String): Unit = add(this, pathOf(name))

@Interpretable("ToDataFrameDslIntoPath")
public infix fun AnyBaseCol.into(path: ColumnPath): Unit = add(this, path)

@Interpretable("Properties0")
Expand All @@ -191,6 +197,7 @@ public abstract class CreateDataFrameDsl<T> : TraversePropertiesDsl {
public inline fun <reified R> expr(infer: Infer = Infer.Nulls, noinline expression: (T) -> R): DataColumn<R> =
source.map { expression(it) }.toColumn(infer = infer)

@Interpretable("ToDataFrameDslAdd")
public inline fun <reified R> add(name: String, noinline expression: (T) -> R): Unit =
add(source.map { expression(it) }.toColumn(name, Infer.Nulls))

Expand All @@ -202,6 +209,7 @@ public abstract class CreateDataFrameDsl<T> : TraversePropertiesDsl {
public inline infix fun <reified R> KProperty<R>.from(noinline expression: (T) -> R): Unit =
add(columnName, expression)

@Interpretable("ToDataFrameDslFromInferType")
public inline infix fun <reified R> String.from(inferType: InferType<T, R>): Unit =
add(DataColumn.createByInference(this, source.map { inferType.expression(it) }))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,25 @@ class CreateDataFrameTests {
df2.a.kind() shouldBe ColumnKind.Group
}

class ExcludeTestData(val s: String, val data: NestedData)

class NestedData(val i: Int, val nestedStr: String)

@Test
fun `preserve T test`() {
val data = listOf(
ExcludeTestData("test", NestedData(42, "nested")),
ExcludeTestData("test2", NestedData(43, "nested2")),
)

val res = data.toDataFrame {
preserve<NestedData>()
properties(maxDepth = 2)
}

res.schema() shouldBe data.toDataFrame(maxDepth = 0).schema()
}

enum class DummyEnum { A }

@Test
Expand Down