Skip to content

Commit 0ee3faa

Browse files
committed
review edits
1 parent d4a16f9 commit 0ee3faa

2 files changed

Lines changed: 41 additions & 30 deletions

File tree

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/annotations/DataSchema.kt

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,53 @@ import org.jetbrains.kotlinx.dataframe.api.cast
44
import org.jetbrains.kotlinx.dataframe.api.convertTo
55

66
/**
7-
* Annotation to generate extension properties API for a given declaration, according to its properties.
8-
* Annotated declaration should be non-local and non-private interface or a class.
9-
* The aim here is to provide convenient syntax for working with a dataframe instance right after reading from it CSV, JSON, Databases, Arrow, etc.
10-
* After `val df = DataFrame.read*` operation, `df` is a source of truth for the DataSchema.
11-
* One way to look at it, DataSchema "tells" the compiler what's already there. It doesn't affect reading.
12-
* See the list below of code generation methods to simplify the process of getting what we call an initial dataschema.
13-
* Given the initial schema of the data you read, the compiler plugin will provide a typed result for most operations.
7+
* This annotation marks an interface or data class as a [data schema](https://kotlin.github.io/dataframe/schemas.html).
8+
*
9+
* This annotation generates an extension properties API for a declaration according to its properties.
10+
* An annotated declaration should be a non-local and non-private interface or class.
11+
* The aim is to provide a convenient syntax for working with a dataframe instance right after reading it from CSV,
12+
* JSON, databases, Arrow, or other sources.
13+
*
14+
* After a `val df = DataFrame.read*` operation, `df` is the source of truth for the data schema.
15+
* One way to look at it is that a data schema tells the compiler what is already there; it does not affect reading.
16+
* See the related operations in the See also section.
17+
* Given the initial schema of the data you read, the
18+
* [compiler plugin](https://github.com/JetBrains/kotlin/tree/master/plugins/kotlin-dataframe) provides a typed result
19+
* for most operations.
1420
*
1521
* Example:
16-
* ```
22+
* ```kotlin
1723
* @DataSchema
1824
* data class Group(
19-
* val id: String,
20-
* val participants: List<Person>
25+
* val id: String, // DataColumn<String>
26+
* val participants: List<Person>, // FrameColumn<Person>
2127
* )
2228
*
2329
* @DataSchema
2430
* data class Person(
25-
* val name: Name,
26-
* val age: Int,
27-
* val city: String?
31+
* val name: Name, // ColumnGroup<Name>
32+
* val age: Int, // DataColumn<Int>
33+
* val city: String?, // DataColumn<String?>
2834
* )
2935
*
3036
* @DataSchema
3137
* data class Name(
32-
* val firstName: String,
33-
* val lastName: String,
38+
* val firstName: String, // DataColumn<String>
39+
* val lastName: String, // DataColumn<String>
3440
* )
3541
*
3642
* fun main() {
37-
* val url = "https://raw.githubusercontent.com/Kotlin/dataframe/refs/heads/master/data/participants.json"
38-
* val df = DataFrame.readJson(url).cast<Group>()
39-
* val i: Int = df.id[0] // properties style access to columns and values
40-
*
41-
* val df1 = df.asGroupBy { participants }.aggregate {
42-
* count() into "groupSize"
43-
* distinct { city } into "cities"
44-
* }
45-
*
46-
* // now compiler plugin uses previous knowledge of `Group` combined with its understanding of aggregate operation
47-
* // to help you access new columns
48-
* val l: List<String> = df1.cities[0]
43+
* val url = "https://raw.githubusercontent.com/Kotlin/dataframe/refs/heads/master/data/participants.json"
44+
* val df = DataFrame.readJson(url).cast<Group>()
45+
* val groupId: String = df.id[0] // Properties-style access to columns and values.
46+
*
47+
* val df1 = df.asGroupBy { participants }.aggregate {
48+
* count() into "groupSize"
49+
* distinct { city } into "cities"
50+
* }
51+
*
52+
* // The compiler plugin uses prior knowledge of `Group` and the aggregate operation to infer new columns.
53+
* val cities: List<String> = df1.cities[0]
4954
* }
5055
* ```
5156
*

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/DataRowSchemaApi.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@ import org.jetbrains.kotlinx.dataframe.DataFrame
44
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
55

66
/**
7-
* Marker interface that's automatically added to classes annotated with [DataSchema]
7+
* Marker interface added as a supertype to classes annotated with [DataSchema] by the Kotlin DataFrame compiler
8+
* plugin.
9+
*
10+
* This lets instances of annotated classes represent dataframe rows, so they can be passed to [dataFrameOf] and
11+
* appended with [append]. The compiler plugin does not add this supertype to annotated interfaces because interfaces
12+
* don't have constructors.
813
*/
914
public interface DataRowSchema
1015

1116
/**
1217
* Example:
13-
* ```
18+
* ```kotlin
1419
* @DataSchema
1520
* data class Person(val name: String, val age: Int)
1621
*
1722
* fun main() {
18-
* val df = dataFrameOf(Person("Alice", 30), Person("Bob", 25))
23+
* val df = dataFrameOf(Person("Alice", 30), Person("Bob", 25))
24+
* val dfWithCarol = df.append(Person("Carol", 25))
1925
* }
2026
* ```
2127
*/

0 commit comments

Comments
 (0)