Skip to content

Commit fcd76d0

Browse files
committed
updated DataSchemaGenerationMethods.md on the website to reflect the changes
1 parent 43b7d2b commit fcd76d0

File tree

2 files changed

+67
-129
lines changed

2 files changed

+67
-129
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private interface Params {
6565
* @param extensionProperties Whether to generate [extension properties (column accessors)][ExtensionPropertiesApi]
6666
* in addition to data schema declarations (markers).
6767
* Useful if you don't use the compiler plugin, otherwise they are not needed;
68-
* the compiler plugin and older Gradle/KSP plugin generate them automatically.
68+
* the compiler plugin, notebooks, and older Gradle/KSP plugin generate them automatically.
6969
* Default is `false`.
7070
*/
7171
interface ExtensionProperties

docs/StardustDocs/topics/concepts/DataSchemaGenerationMethods.md

Lines changed: 66 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -14,83 +14,9 @@ Generate useful Kotlin definitions based on your DataFrame structure.
1414

1515
<!---IMPORT org.jetbrains.kotlinx.dataframe.samples.api.Generate-->
1616

17-
Special utility functions that generate code of useful Kotlin definitions (returned as a `String`)
17+
Special utility functions that generate code of useful Kotlin definitions (returned as a `String`)
1818
based on the current `DataFrame` schema.
1919

20-
21-
## generateInterfaces
22-
23-
```kotlin
24-
inline fun <reified T> DataFrame<T>.generateInterfaces(): CodeString
25-
26-
fun <T> DataFrame<T>.generateInterfaces(markerName: String): CodeString
27-
```
28-
29-
Generates [`@DataSchema`](schemas.md) interfaces for this `DataFrame`
30-
(including all nested `DataFrame` columns and column groups) as Kotlin interfaces.
31-
32-
This is useful when working with the [compiler plugin](Compiler-Plugin.md)
33-
in cases where the schema cannot be inferred automatically from the source.
34-
35-
### Arguments {id="generateInterfaces-arguments"}
36-
* `markerName`: `String` – The base name to use for generated interfaces.
37-
If not specified, uses the `T` type argument of `DataFrame` simple name.
38-
39-
### Returns {id="generateInterfaces-returns"}
40-
* `CodeString` – A value class wrapper for `String`, containing
41-
the generated Kotlin code of `@DataSchema` interfaces without extension properties.
42-
43-
### Examples {id="generateInterfaces-examples"}
44-
45-
46-
<!---FUN notebook_test_generate_docs_1-->
47-
48-
```kotlin
49-
df
50-
```
51-
52-
<!---END-->
53-
54-
<inline-frame src="./resources/notebook_test_generate_docs_1.html" width="100%" height="500px"></inline-frame>
55-
56-
<!---FUN notebook_test_generate_docs_2-->
57-
58-
```kotlin
59-
df.generateInterfaces()
60-
```
61-
62-
<!---END-->
63-
64-
Output:
65-
```kotlin
66-
@DataSchema(isOpen = false)
67-
interface _DataFrameType11 {
68-
val amount: kotlin.Double
69-
val orderId: kotlin.Int
70-
}
71-
72-
@DataSchema
73-
interface _DataFrameType1 {
74-
val orders: List<_DataFrameType11>
75-
val user: kotlin.String
76-
}
77-
```
78-
79-
By adding these interfaces to your project with the [compiler plugin](Compiler-Plugin.md) enabled,
80-
you'll gain full support for the [extension properties API](extensionPropertiesApi.md) and type-safe operations.
81-
82-
Use [`cast`](cast.md) to apply the generated schema to a `DataFrame`:
83-
84-
<!---FUN notebook_test_generate_docs_3-->
85-
86-
```kotlin
87-
df.cast<_DataFrameType1>().filter { orders.all { orderId >= 102 } }
88-
```
89-
90-
<!---END-->
91-
92-
<!--inline-frame src="./resources/notebook_test_generate_docs_3.html" width="100%" height="500px"></inline-frame>-->
93-
9420
## generateDataClasses
9521

9622
```kotlin
@@ -103,29 +29,37 @@ inline fun <reified T> DataFrame<T>.generateDataClasses(
10329
): CodeString
10430
```
10531

106-
Generates Kotlin data classes corresponding to the `DataFrame` schema
32+
Generates Kotlin data classes corresponding to the `DataFrame` schema
10733
(including all nested `DataFrame` columns and column groups).
10834

10935
Useful when you want to:
11036

11137
- Work with the data as regular Kotlin data classes.
38+
- Convert a dataframe to instantiated data classes with `df.toListOf<DataClassType>()`.
11239
- Work with data classes serialization.
11340
- Extract structured types for further use in your application.
11441

11542
### Arguments {id="generateDataClasses-arguments"}
43+
11644
* `markerName`: `String?` — The base name to use for generated data classes.
11745
If `null`, uses the `T` type argument of `DataFrame` simple name.
11846
Default: `null`.
119-
* `extensionProperties`: `Boolean` – Whether to generate extension properties in addition to `data class` declarations.
47+
* `extensionProperties`: `Boolean` – Whether to generate extension properties in addition to `interface` declarations.
48+
Useful if you don't use the [compiler plugin](Compiler-Plugin.md), otherwise they are not needed;
49+
the [compiler plugin](Compiler-Plugin.md), [notebooks](schemasJupyter.md),
50+
and older [Gradle/KSP plugin](schemasGradle.md) generate them automatically.
12051
Default: `false`.
12152
* `visibility`: `MarkerVisibility` – Visibility modifier for the generated declarations.
12253
Default: `MarkerVisibility.IMPLICIT_PUBLIC`.
12354
* `useFqNames`: `Boolean` – If `true`, fully qualified type names will be used in generated code.
12455
Default: `false`.
125-
* `nameNormalizer`: `NameNormalizer` – Strategy for converting column names (with spaces, underscores, etc.) to valid Kotlin identifiers.
56+
* `nameNormalizer`: `NameNormalizer` – Strategy for converting column names (with spaces, underscores, etc.) to
57+
Kotlin-style identifiers.
58+
Generated properties will still refer to columns by their actual name using the `@ColumnName` annotation.
12659
Default: `NameNormalizer.default`.
12760

12861
### Returns {id="generateDataClasses-returns"}
62+
12963
* `CodeString` – A value class wrapper for `String`, containing
13064
the generated Kotlin code of `data class` declarations and optionally extension properties.
13165

@@ -140,6 +74,7 @@ df.generateDataClasses("Customer")
14074
<!---END-->
14175

14276
Output:
77+
14378
```kotlin
14479
@DataSchema
14580
data class Customer1(
@@ -164,90 +99,93 @@ val customers: List<Customer> = df.cast<Customer>().toList()
16499

165100
<!---END-->
166101

167-
## generateCode
102+
## generateInterfaces
168103

169104
```kotlin
170-
inline fun <reified T> DataFrame<T>.generateCode(
171-
fields: Boolean = true,
172-
extensionProperties: Boolean = true,
173-
): CodeString
105+
inline fun <reified T> DataFrame<T>.generateInterfaces(): CodeString
174106

175-
fun <T> DataFrame<T>.generateCode(
176-
markerName: String,
177-
fields: Boolean = true,
178-
extensionProperties: Boolean = true,
179-
visibility: MarkerVisibility = MarkerVisibility.IMPLICIT_PUBLIC,
180-
): CodeString
107+
fun <T> DataFrame<T>.generateInterfaces(markerName: String): CodeString
181108
```
182109

183-
Generates a data schema interface as [`generateInterfaces()`](#generateinterfaces),
184-
along with explicit [extension properties](extensionPropertiesApi.md).
185-
Useful if you don't use the [compiler plugin](Compiler-Plugin.md).
110+
Generates [`@DataSchema`](schemas.md) interfaces for this `DataFrame`
111+
(including all nested `DataFrame` columns and column groups) as Kotlin interfaces.
112+
113+
This is useful when working with the [compiler plugin](Compiler-Plugin.md)
114+
in cases where the schema cannot be inferred automatically from the source.
115+
116+
### Arguments {id="generateInterfaces-arguments"}
117+
118+
* `markerName`: `String?` — The base name to use for generated interfaces.
119+
If `null`, uses the `T` type argument of `DataFrame` simple name.
120+
Default: `null`.
121+
* `extensionProperties`: `Boolean` – Whether to generate extension properties in addition to `interface` declarations.
122+
Useful if you don't use the [compiler plugin](Compiler-Plugin.md), otherwise they are not needed;
123+
the [compiler plugin](Compiler-Plugin.md), [notebooks](schemasJupyter.md),
124+
and older [Gradle/KSP plugin](schemasGradle.md) generate them automatically.
125+
Default: `false`.
126+
* `visibility`: `MarkerVisibility` – Visibility modifier for the generated declarations.
127+
Default: `MarkerVisibility.IMPLICIT_PUBLIC`.
128+
* `useFqNames`: `Boolean` – If `true`, fully qualified type names will be used in generated code.
129+
Default: `false`.
130+
* `nameNormalizer`: `NameNormalizer` – Strategy for converting column names (with spaces, underscores, etc.) to
131+
Kotlin-style identifiers.
132+
Generated properties will still refer to columns by their actual name using the `@ColumnName` annotation.
133+
Default: `NameNormalizer.default`.
134+
135+
### Returns {id="generateInterfaces-returns"}
136+
137+
* `CodeString` – A value class wrapper for `String`, containing
138+
the generated Kotlin code of `@DataSchema` interfaces without extension properties.
186139

187-
### Arguments {id="generateCode-arguments"}
188-
* `markerName`: `String` – The base name to use for generated interfaces.
189-
If not specified, uses the `T` type argument of `DataFrame` simple name.
190-
* `fields`: `Boolean` – Whether to generate fields (`val ...`) inside interfaces.
191-
Default: `true`.
192-
* `extensionProperties`: `Boolean` – Whether to generate extension properties for the schema.
193-
Default: `true`.
194-
* `visibility`: `MarkerVisibility` – Visibility modifier for the generated declarations.
195-
Default: `MarkerVisibility.IMPLICIT_PUBLIC`.
140+
### Examples {id="generateInterfaces-examples"}
196141

197-
### Returns {id="generateCode-returns"}
198-
* `CodeString` – A value class wrapper for `String`, containing
199-
the generated Kotlin code of `@DataSchema` interfaces and/or extension properties.
142+
<!---FUN notebook_test_generate_docs_1-->
143+
144+
```kotlin
145+
df
146+
```
147+
148+
<!---END-->
200149

201-
### Examples {id="generateCode-examples"}
150+
<inline-frame src="./resources/notebook_test_generate_docs_1.html" width="100%" height="500px"></inline-frame>
202151

203-
<!---FUN notebook_test_generate_docs_6-->
152+
<!---FUN notebook_test_generate_docs_2-->
204153

205154
```kotlin
206-
df.generateCode("Customer")
155+
df.generateInterfaces()
207156
```
208157

209158
<!---END-->
210159

211160
Output:
161+
212162
```kotlin
213163
@DataSchema(isOpen = false)
214-
interface Customer1 {
164+
interface _DataFrameType11 {
215165
val amount: kotlin.Double
216166
val orderId: kotlin.Int
217167
}
218168

219-
val org.jetbrains.kotlinx.dataframe.ColumnsContainer<Customer1>.amount: org.jetbrains.kotlinx.dataframe.DataColumn<kotlin.Double> @JvmName("Customer1_amount") get() = this["amount"] as org.jetbrains.kotlinx.dataframe.DataColumn<kotlin.Double>
220-
val org.jetbrains.kotlinx.dataframe.DataRow<Customer1>.amount: kotlin.Double @JvmName("Customer1_amount") get() = this["amount"] as kotlin.Double
221-
val org.jetbrains.kotlinx.dataframe.ColumnsContainer<Customer1>.orderId: org.jetbrains.kotlinx.dataframe.DataColumn<kotlin.Int> @JvmName("Customer1_orderId") get() = this["orderId"] as org.jetbrains.kotlinx.dataframe.DataColumn<kotlin.Int>
222-
val org.jetbrains.kotlinx.dataframe.DataRow<Customer1>.orderId: kotlin.Int @JvmName("Customer1_orderId") get() = this["orderId"] as kotlin.Int
223-
224169
@DataSchema
225-
interface Customer {
226-
val orders: List<Customer1>
170+
interface _DataFrameType1 {
171+
val orders: List<_DataFrameType11>
227172
val user: kotlin.String
228173
}
229-
230-
val org.jetbrains.kotlinx.dataframe.ColumnsContainer<Customer>.orders: org.jetbrains.kotlinx.dataframe.DataColumn<org.jetbrains.kotlinx.dataframe.DataFrame<Customer1>> @JvmName("Customer_orders") get() = this["orders"] as org.jetbrains.kotlinx.dataframe.DataColumn<org.jetbrains.kotlinx.dataframe.DataFrame<Customer1>>
231-
val org.jetbrains.kotlinx.dataframe.DataRow<Customer>.orders: org.jetbrains.kotlinx.dataframe.DataFrame<Customer1> @JvmName("Customer_orders") get() = this["orders"] as org.jetbrains.kotlinx.dataframe.DataFrame<Customer1>
232-
val org.jetbrains.kotlinx.dataframe.ColumnsContainer<Customer>.user: org.jetbrains.kotlinx.dataframe.DataColumn<kotlin.String> @JvmName("Customer_user") get() = this["user"] as org.jetbrains.kotlinx.dataframe.DataColumn<kotlin.String>
233-
val org.jetbrains.kotlinx.dataframe.DataRow<Customer>.user: kotlin.String @JvmName("Customer_user") get() = this["user"] as kotlin.String
234174
```
235175

236-
By adding this generated code to your project, you can use the [extension properties API](extensionPropertiesApi.md)
237-
for fully type-safe column access and transformations.
176+
By adding these interfaces to your project with the [compiler plugin](Compiler-Plugin.md) enabled,
177+
you'll gain full support for the [extension properties API](extensionPropertiesApi.md) and type-safe operations.
238178

239179
Use [`cast`](cast.md) to apply the generated schema to a `DataFrame`:
240180

241-
<!---FUN notebook_test_generate_docs_7-->
181+
<!---FUN notebook_test_generate_docs_3-->
242182

243183
```kotlin
244-
df.cast<Customer>()
245-
.add("ordersTotal") { orders.sumOf { it.amount } }
246-
.filter { user.startsWith("A") }
247-
.rename { user }.into("customer")
184+
df.cast<_DataFrameType1>().filter { orders.all { orderId >= 102 } }
248185
```
249186

250187
<!---END-->
251188

252-
<!--inline-frame src="./resources/notebook_test_generate_docs_7.html" width="100%" height="500px"></inline-frame>-->
189+
<!--inline-frame src="./resources/notebook_test_generate_docs_3.html" width="100%" height="500px"></inline-frame>-->
190+
253191

0 commit comments

Comments
 (0)