@@ -14,83 +14,9 @@ Generate useful Kotlin definitions based on your DataFrame structure.
14
14
15
15
<!-- -IMPORT org.jetbrains.kotlinx.dataframe.samples.api.Generate-->
16
16
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 ` )
18
18
based on the current ` DataFrame ` schema.
19
19
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
-
94
20
## generateDataClasses
95
21
96
22
``` kotlin
@@ -103,29 +29,37 @@ inline fun <reified T> DataFrame<T>.generateDataClasses(
103
29
): CodeString
104
30
```
105
31
106
- Generates Kotlin data classes corresponding to the ` DataFrame ` schema
32
+ Generates Kotlin data classes corresponding to the ` DataFrame ` schema
107
33
(including all nested ` DataFrame ` columns and column groups).
108
34
109
35
Useful when you want to:
110
36
111
37
- Work with the data as regular Kotlin data classes.
38
+ - Convert a dataframe to instantiated data classes with ` df.toListOf<DataClassType>() ` .
112
39
- Work with data classes serialization.
113
40
- Extract structured types for further use in your application.
114
41
115
42
### Arguments {id="generateDataClasses-arguments"}
43
+
116
44
* ` markerName ` : ` String? ` — The base name to use for generated data classes.
117
45
If ` null ` , uses the ` T ` type argument of ` DataFrame ` simple name.
118
46
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.
120
51
Default: ` false ` .
121
52
* ` visibility ` : ` MarkerVisibility ` – Visibility modifier for the generated declarations.
122
53
Default: ` MarkerVisibility.IMPLICIT_PUBLIC ` .
123
54
* ` useFqNames ` : ` Boolean ` – If ` true ` , fully qualified type names will be used in generated code.
124
55
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.
126
59
Default: ` NameNormalizer.default ` .
127
60
128
61
### Returns {id="generateDataClasses-returns"}
62
+
129
63
* ` CodeString ` – A value class wrapper for ` String ` , containing
130
64
the generated Kotlin code of ` data class ` declarations and optionally extension properties.
131
65
@@ -140,6 +74,7 @@ df.generateDataClasses("Customer")
140
74
<!-- -END-->
141
75
142
76
Output:
77
+
143
78
``` kotlin
144
79
@DataSchema
145
80
data class Customer1 (
@@ -164,90 +99,93 @@ val customers: List<Customer> = df.cast<Customer>().toList()
164
99
165
100
<!-- -END-->
166
101
167
- ## generateCode
102
+ ## generateInterfaces
168
103
169
104
``` 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
174
106
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
181
108
```
182
109
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.
186
139
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"}
196
141
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-->
200
149
201
- ### Examples {id="generateCode-examples"}
150
+ < inline-frame src = " ./resources/notebook_test_generate_docs_1.html " width = " 100% " height = " 500px " ></ inline-frame >
202
151
203
- <!-- -FUN notebook_test_generate_docs_6 -->
152
+ <!-- -FUN notebook_test_generate_docs_2 -->
204
153
205
154
``` kotlin
206
- df.generateCode( " Customer " )
155
+ df.generateInterfaces( )
207
156
```
208
157
209
158
<!-- -END-->
210
159
211
160
Output:
161
+
212
162
``` kotlin
213
163
@DataSchema(isOpen = false )
214
- interface Customer1 {
164
+ interface _DataFrameType11 {
215
165
val amount: kotlin.Double
216
166
val orderId: kotlin.Int
217
167
}
218
168
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
-
224
169
@DataSchema
225
- interface Customer {
226
- val orders: List <Customer1 >
170
+ interface _DataFrameType1 {
171
+ val orders: List <_DataFrameType11 >
227
172
val user: kotlin.String
228
173
}
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
234
174
```
235
175
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 .
238
178
239
179
Use [ ` cast ` ] ( cast.md ) to apply the generated schema to a ` DataFrame ` :
240
180
241
- <!-- -FUN notebook_test_generate_docs_7 -->
181
+ <!-- -FUN notebook_test_generate_docs_3 -->
242
182
243
183
``` 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 } }
248
185
```
249
186
250
187
<!-- -END-->
251
188
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
+
253
191
0 commit comments