@@ -42,6 +42,36 @@ public inline fun <reified T> AnyFrame.castTo(
42
42
verify : Boolean = true,
43
43
): DataFrame <T > = cast<T >(verify = verify)
44
44
45
+ /* *
46
+ * With the compiler plugin, schema marker T of DataFrame can be a local type.
47
+ * You cannot refer to it directly from your code, like a type argument for cast.
48
+ * The example below shows a situation where you'd need to cast DataFrame<*> to DataFrame<plugin generated local type>.
49
+ * This function helps by inferring type from [schemaFrom]
50
+ * ```
51
+ *
52
+ * // parse listOf("b:1:abc", "c:2:bca")
53
+ * private fun convert(data: List<String>)/*: DataFrame<plugin generated local type>*/ = data.map { it.split(":") }.toDataFrame {
54
+ * "part1" from { it[0] }
55
+ * "part2" from { it[1].toInt() }
56
+ * "part3" from { it[2] }
57
+ * }
58
+ *
59
+ * fun serialize(data: List<String>, destination: File) {
60
+ * convert(data).writeJson(destination)
61
+ * }
62
+ *
63
+ * fun deserializeAndUse(file: File) {
64
+ * val df = DataFrame.readJson(file).castTo(schemaFrom = ::convert)
65
+ * // Possible to use properties
66
+ * df.part1.print()
67
+ * }
68
+ * ```
69
+ */
70
+ public inline fun <reified T > AnyFrame.castTo (
71
+ @Suppress(" UNUSED_PARAMETER" ) schemaFrom : Function <DataFrame <T >>,
72
+ verify : Boolean = true,
73
+ ): DataFrame <T > = cast<T >(verify = verify)
74
+
45
75
public fun <T > AnyRow.cast (): DataRow <T > = this as DataRow <T >
46
76
47
77
public inline fun <reified T > AnyRow.cast (verify : Boolean = true): DataRow <T > = df().cast<T >(verify)[0 ]
0 commit comments