@@ -11,36 +11,28 @@ import org.jetbrains.kotlinx.dataframe.DataColumn
11
11
import org.jetbrains.kotlinx.dataframe.DataFrame
12
12
import org.jetbrains.kotlinx.dataframe.DataRow
13
13
import org.jetbrains.kotlinx.dataframe.Predicate
14
- import org.jetbrains.kotlinx.dataframe.columns.ColumnAccessor
15
- import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
16
- import org.jetbrains.kotlinx.dataframe.columns.ColumnPath
17
- import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
18
- import org.jetbrains.kotlinx.dataframe.columns.ColumnResolutionContext
19
- import org.jetbrains.kotlinx.dataframe.columns.ColumnSet
20
- import org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath
21
- import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
22
- import org.jetbrains.kotlinx.dataframe.columns.SingleColumn
23
- import org.jetbrains.kotlinx.dataframe.columns.renamedReference
14
+ import org.jetbrains.kotlinx.dataframe.columns.*
15
+ import org.jetbrains.kotlinx.dataframe.documentation.AccessApi
24
16
import org.jetbrains.kotlinx.dataframe.hasNulls
25
17
import org.jetbrains.kotlinx.dataframe.impl.columnName
26
- import org.jetbrains.kotlinx.dataframe.impl.columns.ColumnsList
27
- import org.jetbrains.kotlinx.dataframe.impl.columns.DistinctColumnSet
28
- import org.jetbrains.kotlinx.dataframe.impl.columns.addPath
29
- import org.jetbrains.kotlinx.dataframe.impl.columns.allColumnsExcept
30
- import org.jetbrains.kotlinx.dataframe.impl.columns.changePath
31
- import org.jetbrains.kotlinx.dataframe.impl.columns.createColumnSet
32
- import org.jetbrains.kotlinx.dataframe.impl.columns.getAt
33
- import org.jetbrains.kotlinx.dataframe.impl.columns.getChildrenAt
34
- import org.jetbrains.kotlinx.dataframe.impl.columns.single
35
- import org.jetbrains.kotlinx.dataframe.impl.columns.toColumns
36
- import org.jetbrains.kotlinx.dataframe.impl.columns.top
37
- import org.jetbrains.kotlinx.dataframe.impl.columns.transform
38
- import org.jetbrains.kotlinx.dataframe.impl.columns.transformSingle
18
+ import org.jetbrains.kotlinx.dataframe.impl.columns.*
39
19
import org.jetbrains.kotlinx.dataframe.impl.columns.tree.dfs
40
20
import kotlin.reflect.KProperty
41
21
import kotlin.reflect.KType
42
22
import kotlin.reflect.typeOf
43
23
24
+ /* *
25
+ * Referring to a column in the selection DSL can be done in several ways corresponding to all
26
+ * [Access APIs][AccessApi]:
27
+ * TODO
28
+ */
29
+ private interface CommonColumnSelectionExamples
30
+
31
+
32
+ /* * [Column Selection DSL][ColumnSelectionDsl] */
33
+ internal interface ColumnSelectionDslLink
34
+
35
+ /* * TODO: Put examples and explanations here */
44
36
public interface ColumnSelectionDsl <out T > : ColumnsContainer <T > {
45
37
46
38
public operator fun <C > ColumnReference<C>.invoke (): DataColumn <C > = get(this )
@@ -56,6 +48,10 @@ public interface ColumnSelectionDsl<out T> : ColumnsContainer<T> {
56
48
public operator fun String.get (column : String ): ColumnPath = pathOf(this , column)
57
49
}
58
50
51
+ /* * [Columns Selection DSL][ColumnsSelectionDsl] */
52
+ internal interface ColumnsSelectionDslLink
53
+
54
+ /* * TODO: Put examples and explanations here */
59
55
public interface ColumnsSelectionDsl <out T > : ColumnSelectionDsl <T >, SingleColumn <DataRow <T >> {
60
56
61
57
public fun <C > ColumnSet<C>.first (condition : ColumnFilter <C >): SingleColumn <C > =
@@ -70,24 +66,26 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
70
66
71
67
public fun ColumnsContainer <* >.group (name : String ): ColumnGroupReference = name.toColumnOf()
72
68
73
- public operator fun String.rangeTo (endInclusive : String ): ColumnSet <* > = toColumnAccessor().rangeTo(endInclusive.toColumnAccessor())
74
-
75
- public operator fun AnyColumnReference.rangeTo (endInclusive : AnyColumnReference ): ColumnSet <* > = object : ColumnSet <Any ?> {
76
- override fun resolve (context : ColumnResolutionContext ): List <ColumnWithPath <Any ?>> {
77
- val startPath = this @rangeTo.resolveSingle(context)!! .path
78
- val endPath = endInclusive.resolveSingle(context)!! .path
79
- val parentPath = startPath.parent()!!
80
- require(parentPath == endPath.parent()) { " Start and end columns have different parent column paths" }
81
- val parentCol = context.df.getColumnGroup(parentPath)
82
- val startIndex = parentCol.getColumnIndex(startPath.name)
83
- val endIndex = parentCol.getColumnIndex(endPath.name)
84
- return (startIndex.. endIndex).map {
85
- parentCol.getColumn(it).let {
86
- it.addPath(parentPath + it.name)
69
+ public operator fun String.rangeTo (endInclusive : String ): ColumnSet <* > =
70
+ toColumnAccessor().rangeTo(endInclusive.toColumnAccessor())
71
+
72
+ public operator fun AnyColumnReference.rangeTo (endInclusive : AnyColumnReference ): ColumnSet <* > =
73
+ object : ColumnSet <Any ?> {
74
+ override fun resolve (context : ColumnResolutionContext ): List <ColumnWithPath <Any ?>> {
75
+ val startPath = this @rangeTo.resolveSingle(context)!! .path
76
+ val endPath = endInclusive.resolveSingle(context)!! .path
77
+ val parentPath = startPath.parent()!!
78
+ require(parentPath == endPath.parent()) { " Start and end columns have different parent column paths" }
79
+ val parentCol = context.df.getColumnGroup(parentPath)
80
+ val startIndex = parentCol.getColumnIndex(startPath.name)
81
+ val endIndex = parentCol.getColumnIndex(endPath.name)
82
+ return (startIndex.. endIndex).map {
83
+ parentCol.getColumn(it).let {
84
+ it.addPath(parentPath + it.name)
85
+ }
87
86
}
88
87
}
89
88
}
90
- }
91
89
92
90
public fun none (): ColumnSet <* > = ColumnsList <Any ?>(emptyList())
93
91
@@ -115,7 +113,8 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
115
113
116
114
public fun <C > ColumnSet<DataRow<C>>.select (vararg columns : String ): ColumnSet <* > = select { columns.toColumns() }
117
115
118
- public fun <C , R > ColumnSet<DataRow<C>>.select (vararg columns : KProperty <R >): ColumnSet <R > = select { columns.toColumns() }
116
+ public fun <C , R > ColumnSet<DataRow<C>>.select (vararg columns : KProperty <R >): ColumnSet <R > =
117
+ select { columns.toColumns() }
119
118
120
119
public fun <C , R > ColumnSet<DataRow<C>>.select (selector : ColumnsSelector <C , R >): ColumnSet <R > = createColumnSet {
121
120
this @select.resolve(it).flatMap { group ->
@@ -145,7 +144,8 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
145
144
146
145
// region allDfs
147
146
148
- public fun ColumnSet <* >.allDfs (includeGroups : Boolean = false): ColumnSet <Any ?> = if (includeGroups) dfs { true } else dfs { ! it.isColumnGroup() }
147
+ public fun ColumnSet <* >.allDfs (includeGroups : Boolean = false): ColumnSet <Any ?> =
148
+ if (includeGroups) dfs { true } else dfs { ! it.isColumnGroup() }
149
149
150
150
public fun String.allDfs (includeGroups : Boolean = false): ColumnSet <Any ?> = toColumnAccessor().allDfs(includeGroups)
151
151
@@ -242,7 +242,9 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
242
242
243
243
public fun <C > col (property : KProperty <C >): ColumnAccessor <C > = property.toColumnAccessor()
244
244
245
- public operator fun ColumnSet <* >.get (colName : String ): ColumnSet <Any ?> = transform { it.mapNotNull { it.getChild(colName) } }
245
+ public operator fun ColumnSet <* >.get (colName : String ): ColumnSet <Any ?> =
246
+ transform { it.mapNotNull { it.getChild(colName) } }
247
+
246
248
public operator fun <C > ColumnSet <* >.get (column : ColumnReference <C >): ColumnSet <C > = cols(column)
247
249
248
250
public fun SingleColumn<AnyRow>.take (n : Int ): ColumnSet <* > = transformSingle { it.children().take(n) }
@@ -288,8 +290,11 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
288
290
public infix fun <C > ColumnReference<C>.into (column : KProperty <* >): ColumnReference <C > = named(column.columnName)
289
291
290
292
public infix fun String.into (newName : String ): ColumnReference <Any ?> = toColumnAccessor().into(newName)
291
- public infix fun String.into (column : ColumnAccessor <* >): ColumnReference <Any ?> = toColumnAccessor().into(column.name())
292
- public infix fun String.into (column : KProperty <* >): ColumnReference <Any ?> = toColumnAccessor().into(column.columnName)
293
+ public infix fun String.into (column : ColumnAccessor <* >): ColumnReference <Any ?> =
294
+ toColumnAccessor().into(column.name())
295
+
296
+ public infix fun String.into (column : KProperty <* >): ColumnReference <Any ?> =
297
+ toColumnAccessor().into(column.columnName)
293
298
294
299
public infix fun <C > ColumnReference<C>.named (newName : String ): ColumnReference <C > = renamedReference(newName)
295
300
public infix fun <C > ColumnReference<C>.named (name : KProperty <* >): ColumnReference <C > = named(name.columnName)
@@ -311,6 +316,7 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
311
316
public infix fun <C > KProperty<C>.and (other : String ): ColumnSet <Any ?> = toColumnAccessor() and other
312
317
public infix fun <C > KProperty<C>.and (other : KProperty <C >): ColumnSet <C > =
313
318
toColumnAccessor() and other.toColumnAccessor()
319
+
314
320
public infix fun <C > KProperty<C>.and (other : ColumnsSelector <T , C >): ColumnSet <C > = toColumnAccessor() and other()
315
321
316
322
// endregion
@@ -339,7 +345,7 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
339
345
public inline fun <T , reified R > ColumnsSelectionDsl<T>.expr (
340
346
name : String = "",
341
347
infer : Infer = Infer .Nulls ,
342
- noinline expression : AddExpression <T , R >
348
+ noinline expression : AddExpression <T , R >,
343
349
): DataColumn <R > = mapToColumn(name, infer, expression)
344
350
345
351
internal fun <T , C > ColumnsSelector <T , C >.filter (predicate : (ColumnWithPath <C >) -> Boolean ): ColumnsSelector <T , C > =
0 commit comments