Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler plugin #729

Merged
merged 339 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
339 commits
Select commit Hold shift + click to select a range
8763050
implement IR lowering for DataSchema generated APIs
koperagen Jul 19, 2022
8515366
support materialization of schemas with FrameColumns
koperagen Jul 22, 2022
db5d59f
Reuse dataframe class ids
koperagen Jul 22, 2022
ca0eab4
WIP
koperagen Jul 25, 2022
90210b3
Support materializing FrameColumn
koperagen Jul 25, 2022
17a37a5
remove duplicated code
koperagen Jul 25, 2022
6dc065f
reorganize test folder
koperagen Jul 26, 2022
616be38
generate tests for `add.kt`
koperagen Jul 28, 2022
8d72e51
setup df api tests
koperagen Aug 2, 2022
c75c208
Support vararg kproperties
koperagen Aug 2, 2022
68c6f87
don't use name "this" because it's a keyword and cannot be used as arg
koperagen Aug 3, 2022
0877e0c
support member functions
koperagen Aug 3, 2022
ecc6b5d
basic support for type arguments
koperagen Aug 5, 2022
8efa8b0
choose root marker based in file name to avoid ambiguity in convert.kt
koperagen Aug 8, 2022
2ac79b5
rearrange convert tests
koperagen Aug 8, 2022
0474323
test rowValueExpression
koperagen Aug 8, 2022
6dd4976
don't throw when optional argument is present in actual
koperagen Aug 8, 2022
e396d92
add tests
koperagen Aug 8, 2022
59be5fb
Support columnsSelector atom
koperagen Aug 10, 2022
5c22fb9
support nested schema atom and nested schema select
koperagen Aug 12, 2022
b582dbe
Prepare df api tests for new non-serializable TypeApproximation
koperagen Aug 23, 2022
068bfbf
Use KotlinType instead of fqn approximation
koperagen Aug 26, 2022
eeda19d
Better column extraction
koperagen Aug 31, 2022
54f44b1
Support `and` in columns selector
koperagen Aug 31, 2022
21fbdf6
Support `to` api
koperagen Aug 31, 2022
a680d04
Setup new df api tests
koperagen Aug 31, 2022
0a772eb
Tests for help with interpretation errors prototyping
koperagen Aug 31, 2022
67de729
Error reporting
koperagen Sep 1, 2022
478d2ed
refactoring
koperagen Sep 1, 2022
997db1b
working backend codegen for hardcoded property
koperagen Sep 5, 2022
78aa517
working backend codegen for hardcoded injected receiver
koperagen Sep 6, 2022
49f2034
fix backend codegen
koperagen Sep 6, 2022
98284e5
Merge step 1
koperagen Sep 9, 2022
87efcc5
Working tests in extensible-dataframes
koperagen Sep 12, 2022
2ec8b52
extensible-dataframes cleanup
koperagen Sep 12, 2022
cf68cd6
working tests in extensible-dataframes
koperagen Sep 12, 2022
4c88e5c
update kotlin
koperagen Sep 13, 2022
b6c0182
publish compiler plugin as a fat jar
koperagen Sep 13, 2022
5f73fc1
disable bridge-generator dependency due to cyclic task dependency
koperagen Oct 27, 2022
7be04d4
fix ide bugs
koperagen Oct 27, 2022
bdac193
working type refinement
koperagen Oct 27, 2022
34eff2f
make backend steps work
koperagen Oct 28, 2022
d69314f
remap symbols to newly generated function
koperagen Nov 3, 2022
ec6663b
fix inlining
koperagen Nov 4, 2022
fa6f422
tidy up tests
koperagen Nov 4, 2022
6296da0
explicitly name state and ids
koperagen Nov 4, 2022
b45ff86
working codegen for chained calls
koperagen Nov 7, 2022
e816907
extend names buffer for ide
koperagen Nov 7, 2022
61c790e
generate internal classes to avoid problems with copying attributes f…
koperagen Nov 9, 2022
9293dce
fix runtime for box tests
koperagen Nov 9, 2022
c4aac90
refactoring
koperagen Nov 9, 2022
d48358d
fix unit tests for interpretation functions
koperagen Nov 9, 2022
9d55686
fix exception
koperagen Nov 9, 2022
696952f
add failing tests to fix later
koperagen Nov 9, 2022
180fe3b
support applying column operations on row expression result in AddDsl
koperagen Nov 11, 2022
9e658d3
support add with dsl
koperagen Nov 11, 2022
ccbaa3a
rework support for chained calls by storing state in generated class
koperagen Nov 11, 2022
5362e71
support type provider style interpretation for read
koperagen Nov 17, 2022
6d665b3
work around exception in read inside intellij
koperagen Nov 17, 2022
baf26bb
provide clearer message in case of unexpected service loader problems
koperagen Nov 17, 2022
6d7a8a8
add test for explode
koperagen Nov 21, 2022
c5879c9
ensure checker and injector work identically
koperagen Nov 21, 2022
5b49026
provide user code a way to disable interpretation for specific expres…
koperagen Nov 22, 2022
3ad00c5
fix backend codegen for read* functions
koperagen Nov 22, 2022
26790b1
support type arguments in runtime schema -> compile time schema conve…
koperagen Nov 23, 2022
f8b34bd
fix select for dataframes and use correct scope to get generated prop…
koperagen Nov 24, 2022
209b98a
fix accessor IR codegen for ColumnGroup
koperagen Nov 24, 2022
a05c282
fix explode
koperagen Nov 28, 2022
144ef59
support basic join interpretation
koperagen Nov 28, 2022
20f7b2b
report only most specific errors
koperagen Nov 29, 2022
6f57883
check structural correctness of df cast
koperagen Nov 30, 2022
97f29f1
api to inject accessors in local scope for code reuse
koperagen Dec 1, 2022
7408cef
handle data schema properties with @DataSchema return type
koperagen Dec 2, 2022
ad01b41
handle data schema properties with @DataSchema return type in schema …
koperagen Dec 7, 2022
67d592f
refactoring
koperagen Dec 7, 2022
35e6d45
fix exception when typing expression
koperagen Dec 7, 2022
768dbd1
remove old type factory because now types are stored without conversi…
koperagen Dec 7, 2022
d04540d
fix conflicting jvm declarations
koperagen Jan 3, 2023
7aa7bd1
update target compiler version
koperagen Jan 3, 2023
2eee6df
fix black box tests
koperagen Jan 3, 2023
11128c3
fix diagnostic tests
koperagen Jan 4, 2023
1928c50
add cli option to specify resolution path for dataframe type providers
koperagen Jan 4, 2023
61571e2
avoid exception
koperagen Jan 4, 2023
90c55ba
add fir handlers
koperagen Jan 4, 2023
d5094f9
generate token ids on the fly
koperagen Jan 11, 2023
18ac601
generate scope ids on the fly
koperagen Jan 11, 2023
408ca94
use field names for generating leaf schemas names
koperagen Jan 11, 2023
e20293d
generate stable return type names
koperagen Jan 12, 2023
a6914b0
remove all pre-generated names for classes
koperagen Jan 12, 2023
de4ba26
explain why SimpleFrameColumn has anyFrameType
koperagen Jan 18, 2023
401cdb2
generate function names on the fly
koperagen Jan 18, 2023
7c8d599
compatibility with compiler version
koperagen Jan 18, 2023
ac3621d
rollback name generation
koperagen Jan 24, 2023
b0f1dba
Merge branch 'master' into solid-update
koperagen Feb 23, 2023
f4faff4
update test results to make them green
koperagen May 8, 2023
3b7cd7e
proof of concept function transformation
koperagen May 17, 2023
80ff321
split transformer test from box tests
koperagen May 19, 2023
452367d
move files copied from the Kotlin project
koperagen May 23, 2023
f208f8d
remove common name prefixes as project is no longer inside the Kotlin…
koperagen May 23, 2023
514c9d9
move size config
koperagen May 23, 2023
77ed33f
prepare entry points into two different plugin implementations
koperagen May 23, 2023
bf2de97
transformation with inline declaration
koperagen May 23, 2023
4a21c82
prototype ReturnTypeBasedReceiverInjector
koperagen May 23, 2023
859aaf3
get constructor directly from type instead of searching by class id
koperagen May 24, 2023
d16fe9e
generate scope references on the backend
koperagen May 24, 2023
4549ba8
insert function call at the last expression
koperagen May 25, 2023
bdc9d3d
switch off old global generators for experimental mode
koperagen May 25, 2023
6f8b7ef
make call to original function
koperagen May 26, 2023
18fba7a
transform functions based on the interpretation result
koperagen May 26, 2023
9c00736
generate data schema declarations and APIs
koperagen Jun 2, 2023
b68f62a
fix initialization for ide
koperagen Jun 14, 2023
1172d0e
bundle light tree for template compiler to work in ide
koperagen Jun 15, 2023
dfb36fc
switch plugin to experimental mode
koperagen Jun 15, 2023
466086c
choose lower bound type by default for platform types
koperagen Jun 27, 2023
aac8453
rework transformations to avoid loops in a tree
koperagen Jun 27, 2023
378dd7f
update test data
koperagen Jun 27, 2023
0aa9baf
fix issue where required data schema was unintentionally removed from…
koperagen Jun 28, 2023
db258e1
refactoring
koperagen Jun 28, 2023
72ac93d
update test data
koperagen Jun 28, 2023
daa4c63
suppress exception that directory cannot be created
koperagen Jun 28, 2023
2b13787
switch name generator strategy
koperagen Jun 29, 2023
1ca4bc6
update kotlin compiler version
koperagen Sep 5, 2023
1e9eb1f
update test data
koperagen Sep 6, 2023
e5b8aac
update to new extension point
koperagen Sep 7, 2023
317f485
update error message and clarify function behaviour
koperagen Sep 7, 2023
2f7d5bf
update lightTree
koperagen Sep 11, 2023
8db60a8
update compiler version
koperagen Oct 17, 2023
a2da35a
update test data
koperagen Oct 17, 2023
4d51b1a
fix some tests
koperagen Oct 31, 2023
df1168e
prototype new generation pipeline on the frontend
koperagen Oct 31, 2023
e05ec23
remove leftovers of implementation that generated top level scopes an…
koperagen Nov 2, 2023
22bfe3b
use scope to get properties generated by an extension
koperagen Nov 7, 2023
318f5cc
fix declarations codegen issues
koperagen Nov 7, 2023
77d80fd
update codegen to include original call in let
koperagen Nov 9, 2023
c6a1120
update original call receivers to properly handle call chains
koperagen Nov 9, 2023
3b556bd
support codegen for hierarchical schemas as a result of refined call
koperagen Nov 10, 2023
aa43d67
fix scope ids and set correct requires resolve phase
koperagen Nov 15, 2023
64eeee8
update EP implementation to use new parameter
koperagen Nov 16, 2023
9ffe91a
update versions
koperagen Dec 21, 2023
23cfaee
update to new compiler version
koperagen Dec 21, 2023
c682127
clean up
koperagen Jan 18, 2024
762b9fd
port deprecation fix
koperagen Jan 24, 2024
0256175
move interpretation logic to plugin
koperagen Jan 25, 2024
69ebef0
change generator according to interpretation API
koperagen Jan 26, 2024
daeb4e9
update tests
koperagen Jan 26, 2024
6a559c6
cleanup
koperagen Jan 26, 2024
f0fe217
remove outdated code
koperagen Jan 30, 2024
ebf5181
Rename NewCandidateInterceptor to CandidateInterceptor
koperagen Jan 30, 2024
d47e680
remove old stateful receiver injector code
koperagen Jan 30, 2024
136c5ee
remove id from Refine
koperagen Feb 1, 2024
93b4954
remove default arguments overloads needed for plugin
koperagen Feb 1, 2024
4a820a9
put test data files inside the project
koperagen Feb 1, 2024
1f97bc4
remove test for deleted functionality
koperagen Feb 1, 2024
12e7d1f
update compiler
koperagen Feb 20, 2024
18ab2ef
use FIR utilities instead of lower level FIR builders
koperagen Feb 22, 2024
bcc8581
remove some unsafe Name.identifier calls
koperagen Feb 22, 2024
5ed89f1
remove a prototype plugin for dataframe api introspection
koperagen Mar 4, 2024
fc20796
update compiler
koperagen Mar 4, 2024
f11b354
remove code generation that was needed to glue library and plugin tog…
koperagen Mar 4, 2024
6cf8f82
remove old plugin directory
koperagen Mar 4, 2024
0510c54
Merge branch 'refs/heads/master' into compiler-plugin
koperagen Mar 5, 2024
ea51d45
add dependency on a dev Kotlin compiler
koperagen Mar 8, 2024
e06e008
Revert type safe constructors prototype
koperagen Mar 13, 2024
ac25946
enable DataRowSchema based API for @DataSchema annotated classes
koperagen Mar 13, 2024
1746b65
fix build issues
koperagen Apr 2, 2024
6158048
update test data
koperagen Apr 2, 2024
3ce989c
update generated sources
koperagen Apr 2, 2024
20d4e21
remove outdated plugin api
koperagen Apr 2, 2024
9c725b3
remove plugin tests from core
koperagen Apr 2, 2024
6229eee
update compiler version
koperagen Apr 2, 2024
35bc4d1
temporary disable tests for CI
koperagen Apr 2, 2024
b1d9166
move most of the plugin tests in box category
koperagen Apr 3, 2024
dc9e54d
remove tests that used to compare compile time vs runtime
koperagen Apr 3, 2024
d94024b
update compiler
koperagen Apr 10, 2024
8b17f31
refactor test runner to use default setup from compiler
koperagen Apr 10, 2024
afd2db9
Avoid duplicating DataRowSchema
koperagen Apr 11, 2024
1f2674c
toDataFrame in compiler plugin
koperagen Apr 15, 2024
1c1e821
update kotlin compiler
koperagen Apr 16, 2024
14d31c2
fix tests
koperagen Apr 16, 2024
c20a65e
update kotlin compiler
koperagen Apr 23, 2024
b439fba
improve selection DSL support in the plugin
koperagen Apr 23, 2024
41f4de9
support remove in compiler plugin
koperagen Apr 24, 2024
0b78d7e
support selection of column groups
koperagen Apr 24, 2024
1b4569f
support group operation
koperagen Apr 25, 2024
371db12
support ungroup operation
koperagen Apr 25, 2024
4c3d130
support dropNulls operation
koperagen Apr 26, 2024
d932295
mute some tests
koperagen Apr 26, 2024
bfe0e2b
update compiler to 2.0.20-dev-2438
koperagen Apr 26, 2024
790f373
setup interpreters for toDataFrame with dsl
koperagen Apr 26, 2024
728e8d5
implement toDataFrame with DSL support in the plugin
koperagen Apr 30, 2024
985d48a
avoid throwing an exception for unsupported cases
koperagen Apr 30, 2024
171d5dd
enable cast checker
koperagen Apr 30, 2024
38cd853
move & rename refactoring
koperagen May 17, 2024
4ab5e44
remove unused code
koperagen May 17, 2024
7b2b8a4
avoid throwing exceptions in unsupported cases
koperagen May 17, 2024
1c7f510
refactor logic around hardcoded "Token" prefix
koperagen May 17, 2024
ddf30ba
remove unused code
koperagen May 17, 2024
6ab95c9
make scope properties distinct from structural properties for ide plugin
koperagen May 17, 2024
043ff52
generate shorter names for implicit data schema types
koperagen May 17, 2024
00c5c73
generate unique names for implicit data schema types
koperagen May 17, 2024
e577d28
update kotlin to 2.0.20-dev-2972
koperagen May 17, 2024
35e1d1f
add experimental function to work with idea plugin
koperagen May 17, 2024
232facc
[Compiler plugin] add basic rename support
koperagen May 18, 2024
7ed89eb
[Compiler plugin] prototype groupBy support
koperagen May 19, 2024
e8a52d8
[Compiler plugin] fix schema extraction from nested schemas
koperagen May 19, 2024
c4ae746
[Compiler plugin] require annotation for IO calls to be interpreted
koperagen May 20, 2024
6b9f668
[Compiler plugin] groupBy + moveToTop
koperagen May 20, 2024
86c40a2
[Compiler plugin] groupBy: DataRow into "name"
koperagen May 20, 2024
68e8380
[Compiler plugin] move groupBy implementation
koperagen May 20, 2024
e2b6b54
[Compiler plugin] fixes in join
koperagen May 20, 2024
6a748b9
[Compiler plugin] fix Void? type
koperagen May 20, 2024
36b6ad7
[Compiler plugin] partially support DataSchemas with type parameters
koperagen May 21, 2024
c1b1058
[Compiler plugin] fix cast
koperagen May 21, 2024
b94709e
[Compiler plugin] workaround network IO issues
koperagen May 22, 2024
bc1b2ad
[Compiler plugin] prototype solution to generate schemas during on bu…
koperagen May 22, 2024
2af163a
[Compiler plugin] properly handle the creation of FrameColumn column …
koperagen May 22, 2024
d9b2a25
[Compiler plugin] refactoring and cleanup
koperagen May 29, 2024
e141a6f
[Compiler plugin] ensure stable order of the generated properties
koperagen May 29, 2024
7e8b9fa
remove member aggregate in favor of an extension function
koperagen May 30, 2024
fd83676
[Compiler plugin] Basic support for read*Str functions
koperagen May 30, 2024
d95de74
[Compiler plugin] remove exceptions
koperagen May 30, 2024
2ddec23
[Compiler plugin] try to work around lazy resolve error for local Dat…
koperagen May 30, 2024
71240fb
[Compiler plugin] fix class cast exceptions
koperagen May 30, 2024
cb8e365
[Compiler plugin] cast checker makes sense only for DataFrame.cast. m…
koperagen May 31, 2024
0e7e3ee
Convert GroupBy.toDataFrame to an extension property
koperagen May 31, 2024
4ea764a
[Compiler plugin] GroupBy.toDataFrame
koperagen May 31, 2024
4a0a3bf
[Compiler plugin] Remove nullable property from SimpleFrameColumn
koperagen May 31, 2024
fb9f14e
[Compiler plugin] One can call DataFrame API on ColumnGroup. Make plu…
koperagen May 31, 2024
1fa0f33
[Compiler plugin] Handle star projection argument in DataSchema type
koperagen May 31, 2024
37da18f
[Compiler plugin] Handle star projection argument in columns' types
koperagen May 31, 2024
bf81949
[Compiler plugin] resolvedInitializer has LazyResolve contract. Avoid…
koperagen Jun 3, 2024
0e7b0bb
[Compiler plugin] Consider 'this' and 'it' when constructing a column…
koperagen Jun 3, 2024
1865e35
[Compiler plugin] Transform DataFrame calls in property initializers …
koperagen Jun 3, 2024
80eb563
[Compiler plugin] code cleanup
koperagen Jun 4, 2024
1296fe4
Merge branch 'refs/heads/master' into compiler-plugin
koperagen Jun 10, 2024
619798f
[Compiler plugin] update test data
koperagen Jun 10, 2024
acfc91d
[Compiler plugin] remove experimental api
koperagen Jun 10, 2024
e12278a
[Compiler plugin] update generated sources
koperagen Jun 10, 2024
6f999f2
[Compiler plugin] remove unused code
koperagen Jun 10, 2024
1182ac9
[Compiler plugin] move ConvertApproximation
koperagen Jun 10, 2024
cb0bd59
[Compiler plugin] move
koperagen Jun 10, 2024
f8d0fd3
[Compiler plugin] move to kotlinx package
koperagen Jun 10, 2024
3c1811b
[Compiler plugin] update test data
koperagen Jun 10, 2024
1a88d09
[Compiler plugin] remove unused code and outdated overload
koperagen Jun 10, 2024
72e7506
Rename classes related to generic insert implementation
koperagen Jun 10, 2024
b73bd04
[Compiler plugin] File with "cached" schemas can become corrupted. Fa…
koperagen Jun 10, 2024
b23828a
[Compiler plugin] toDataFrame from support
koperagen Jun 11, 2024
430e2fa
[Compiler plugin] move SimpleCol refactoring
koperagen Jun 11, 2024
f3e5738
[Compiler plugin] refactor SimpleCol to closed hierarchy
koperagen Jun 11, 2024
6a997f7
[Compiler plugin] review
koperagen Jun 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ dependencies {
api(project(":dataframe-jdbc"))
}

private enum class Version : Comparable<Version> {
enum class Version : Comparable<Version> {
SNAPSHOT, DEV, ALPHA, BETA, RC, STABLE;
}

private fun String.findVersion(): Version {
fun String.findVersion(): Version {
val version = this.lowercase()
return when {
"snapshot" in version -> Version.SNAPSHOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.jetbrains.kotlinx.dataframe

import org.jetbrains.kotlinx.dataframe.aggregation.Aggregatable
import org.jetbrains.kotlinx.dataframe.aggregation.AggregateGroupedBody
import org.jetbrains.kotlinx.dataframe.annotations.HasSchema
import org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl
import org.jetbrains.kotlinx.dataframe.api.add
import org.jetbrains.kotlinx.dataframe.api.cast
Expand Down Expand Up @@ -29,6 +30,7 @@ import kotlin.reflect.KType
*
* @param T Schema marker. It identifies column schema and is used to generate schema-specific extension properties for typed data access. It is covariant, so `DataFrame<A>` is assignable to variable of type `DataFrame<B>` if `A` is a subtype of `B`.
*/
@HasSchema(schemaArg = 0)
public interface DataFrame<out T> : Aggregatable<T>, ColumnsContainer<T> {

public companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ public interface DataRow<out T> {
return value as AnyRow
}

public fun getFrameColumn(columnName: String): AnyFrame {
val value = get(columnName)
if (value == null) {
val kind = df()[columnName].kind()
if (kind != ColumnKind.Frame) {
error("Cannot cast null value of a $kind to a ${DataFrame::class}")
}
}
return value as AnyFrame
}

public fun getOrNull(name: String): Any?
public fun <R> getValueOrNull(column: ColumnReference<R>): R?

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jetbrains.kotlinx.dataframe.aggregation

import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
import org.jetbrains.kotlinx.dataframe.api.ColumnSelectionDsl
import org.jetbrains.kotlinx.dataframe.api.pathOf
import org.jetbrains.kotlinx.dataframe.columns.ColumnAccessor
Expand All @@ -12,6 +13,7 @@ import kotlin.reflect.typeOf

public abstract class AggregateDsl<out T> : DataFrame<T>, ColumnSelectionDsl<T> {

@Interpretable("GroupByInto")
public inline infix fun <reified R> R.into(name: String): NamedValue = internal().yield(pathOf(name), this, typeOf<R>())

public inline infix fun <reified R> R.into(column: ColumnAccessor<R>): NamedValue = internal().yield(pathOf(column.name()), this, typeOf<R>())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.jetbrains.kotlinx.dataframe.annotations

@Target(AnnotationTarget.CLASS)
public annotation class HasSchema(val schemaArg: Int)

/**
* Compiler plugin will evaluate compile time value of the annotated function.
* Needed because some function calls only serve as a part of overall compile time DataSchema evaluation
* There's no need to update return type of such calls
*/
internal annotation class Interpretable(val interpreter: String)

/**
* Compiler plugin will replace return type of calls to the annotated function
*/
internal annotation class Refine

internal annotation class OptInRefine

@Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.FILE, AnnotationTarget.EXPRESSION)
public annotation class DisableInterpretation

@Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.EXPRESSION)
public annotation class Import

@Target(AnnotationTarget.PROPERTY)
public annotation class Order(val order: Int)

@Target(AnnotationTarget.FUNCTION)
internal annotation class Check
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.jetbrains.kotlinx.dataframe.api

import org.jetbrains.kotlinx.dataframe.DataFrame

public interface DataRowSchema

public inline fun <reified T : DataRowSchema> dataFrameOf(vararg rows: T): DataFrame<T> =
rows.asIterable().toDataFrame()

public inline fun <reified T : DataRowSchema> DataFrame<T>.append(vararg rows: T): DataFrame<T> =
concat(dataFrameOf(*rows))
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.jetbrains.kotlinx.dataframe.api

import org.jetbrains.kotlinx.dataframe.*
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
import org.jetbrains.kotlinx.dataframe.annotations.Refine
import org.jetbrains.kotlinx.dataframe.api.Update.UpdateOperationArg
import org.jetbrains.kotlinx.dataframe.columns.ColumnKind
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
Expand Down Expand Up @@ -918,6 +920,8 @@ public fun <T, C> DataFrame<T>.fillNA(vararg columns: ColumnReference<C>): Updat
* If `false`, rows are dropped if any of the selected cells is `null`.
* @param columns The [Columns Selector][org.jetbrains.kotlinx.dataframe.ColumnsSelector] used to select the columns of this [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to drop rows in.
*/
@Refine
@Interpretable("DropNulls0")
public fun <T> DataFrame<T>.dropNulls(whereAllNull: Boolean = false, columns: ColumnsSelector<T, *>): DataFrame<T> {
val cols = this[columns]
return if (whereAllNull) drop { row -> cols.all { col -> col[row] == null } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.DataRow
import org.jetbrains.kotlinx.dataframe.RowExpression
import org.jetbrains.kotlinx.dataframe.Selector
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
import org.jetbrains.kotlinx.dataframe.annotations.Refine
import org.jetbrains.kotlinx.dataframe.columns.BaseColumn
import org.jetbrains.kotlinx.dataframe.columns.ColumnAccessor
import org.jetbrains.kotlinx.dataframe.columns.ColumnPath
Expand Down Expand Up @@ -121,6 +123,8 @@ public typealias AddExpression<T, R> = Selector<AddDataRow<T>, R>
* @return new [DataFrame] with added column
* @throws DuplicateColumnNamesException if [DataFrame] already contains a column with given [name]
*/
@Refine
@Interpretable("Add")
public inline fun <reified R, T> DataFrame<T>.add(
name: String,
infer: Infer = Infer.Nulls,
Expand Down Expand Up @@ -178,7 +182,10 @@ public class AddDsl<T>(@PublishedApi internal val df: DataFrame<T>) : ColumnsCon
return df.mapToColumn("", infer, expression)
}

public inline infix fun <reified R> String.from(noinline expression: RowExpression<T, R>): Boolean =
@Interpretable("From")
public inline infix fun <reified R> String.from(
noinline expression: RowExpression<T, R>
): Boolean =
add(this, Infer.Nulls, expression)

// TODO: use path instead of name
Expand All @@ -192,6 +199,7 @@ public class AddDsl<T>(@PublishedApi internal val df: DataFrame<T>) : ColumnsCon
public inline infix fun <reified R> ColumnAccessor<R>.from(column: ColumnReference<R>): Boolean = name() from column
public inline infix fun <reified R> KProperty<R>.from(column: ColumnReference<R>): Boolean = name from column

@Interpretable("Into")
public infix fun AnyColumnReference.into(name: String): Boolean = add(rename(name))
public infix fun <R> ColumnReference<R>.into(column: ColumnAccessor<R>): Boolean = into(column.name())
public infix fun <R> ColumnReference<R>.into(column: KProperty<R>): Boolean = into(column.name)
Expand All @@ -212,6 +220,8 @@ public class AddDsl<T>(@PublishedApi internal val df: DataFrame<T>) : ColumnsCon
public infix fun AddGroup<T>.into(column: AnyColumnGroupAccessor): Unit = into(column.name())
}

@Refine
@Interpretable("AddWithDsl")
public fun <T> DataFrame<T>.add(body: AddDsl<T>.() -> Unit): DataFrame<T> {
val dsl = AddDsl(this)
body(dsl)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
package org.jetbrains.kotlinx.dataframe.api

import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.DataRow
import org.jetbrains.kotlinx.dataframe.Selector
import org.jetbrains.kotlinx.dataframe.aggregation.AggregateDsl
import org.jetbrains.kotlinx.dataframe.aggregation.AggregateGroupedBody
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
import org.jetbrains.kotlinx.dataframe.annotations.Refine
import org.jetbrains.kotlinx.dataframe.impl.aggregateGroupBy

// region Pivot

public fun <T, R> Pivot<T>.aggregate(separate: Boolean = false, body: Selector<AggregateDsl<T>, R>): DataRow<T> = delegate { aggregate(separate, body) }

// endregion

@Refine
@Interpretable("Aggregate")
public fun <T, R> Grouped<T>.aggregate(body: AggregateGroupedBody<T, R>): DataFrame<T> {
return aggregateGroupBy((this as GroupBy<*, *>).toDataFrame(), { groups.cast() }, removeColumns = true, body).cast<T>()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.jetbrains.kotlinx.dataframe.api

import org.jetbrains.kotlinx.dataframe.DataColumn
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
import org.jetbrains.kotlinx.dataframe.api.AndColumnsSelectionDsl.Grammar
import org.jetbrains.kotlinx.dataframe.api.AndColumnsSelectionDsl.Grammar.InfixName
import org.jetbrains.kotlinx.dataframe.api.AndColumnsSelectionDsl.Grammar.Name
Expand Down Expand Up @@ -216,6 +217,7 @@ public interface AndColumnsSelectionDsl {
* @return A [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] that contains all the columns from the [ColumnsResolvers][org.jetbrains.kotlinx.dataframe.columns.ColumnsResolver] on the left
* and right side of the [and][org.jetbrains.kotlinx.dataframe.api.AndColumnsSelectionDsl.and] operator.
*/
@Interpretable("And0")
public infix fun <C> ColumnsResolver<C>.and(other: ColumnsResolver<C>): ColumnSet<C> = ColumnsList(this, other)

/** ## And Operator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.jetbrains.kotlinx.dataframe.AnyRow
import org.jetbrains.kotlinx.dataframe.DataColumn
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.DataRow
import org.jetbrains.kotlinx.dataframe.annotations.Check
import org.jetbrains.kotlinx.dataframe.columns.ColumnAccessor
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
Expand All @@ -22,6 +23,7 @@ import org.jetbrains.kotlinx.dataframe.impl.columns.TransformableColumnSet
import org.jetbrains.kotlinx.dataframe.impl.columns.TransformableSingleColumn
import kotlin.reflect.typeOf

@Check
public fun <T> AnyFrame.cast(): DataFrame<T> = this as DataFrame<T>

public inline fun <reified T> AnyFrame.cast(verify: Boolean = true): DataFrame<T> = if (verify) convertToImpl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public fun <T> DataRow<T>.concat(vararg rows: DataRow<T>): DataFrame<T> = (listO

public fun <T> DataFrame<T>.concat(vararg frames: DataFrame<T>): DataFrame<T> = concatImpl(listOf(this) + frames)

public infix fun <T> DataFrame<T>.concat(frame: DataFrame<T>): DataFrame<T> = concatImpl(listOf(this) + frame)

@JvmName("concatT")
public fun <T> DataFrame<T>.concat(rows: Iterable<DataRow<T>>): DataFrame<T> = (rows() + rows).concat()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.jetbrains.kotlinx.dataframe.DataColumn
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.RowColumnExpression
import org.jetbrains.kotlinx.dataframe.RowValueExpression
import org.jetbrains.kotlinx.dataframe.annotations.*
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
import org.jetbrains.kotlinx.dataframe.dataTypes.IFRAME
Expand Down Expand Up @@ -40,12 +41,14 @@ import kotlin.reflect.full.isSubtypeOf
import kotlin.reflect.full.withNullability
import kotlin.reflect.typeOf

@Interpretable("Convert0")
public fun <T, C> DataFrame<T>.convert(columns: ColumnsSelector<T, C>): Convert<T, C> =
Convert(this, columns)

public fun <T, C> DataFrame<T>.convert(vararg columns: KProperty<C>): Convert<T, C> =
convert { columns.toColumnSet() }

@Interpretable("Convert2")
public fun <T> DataFrame<T>.convert(vararg columns: String): Convert<T, Any?> = convert { columns.toColumnSet() }

public fun <T, C> DataFrame<T>.convert(vararg columns: ColumnReference<C>): Convert<T, C> =
Expand All @@ -67,6 +70,7 @@ public inline fun <T, C, reified R> DataFrame<T>.convert(
): DataFrame<T> =
convert(*headPlusArray(firstCol, cols)).with(infer, expression)

@Interpretable("Convert6")
public inline fun <T, reified R> DataFrame<T>.convert(
firstCol: String,
vararg cols: String,
Expand All @@ -81,29 +85,38 @@ public inline fun <T, C, reified R> Convert<T, C?>.notNull(crossinline expressio
else expression(this, it)
}

@HasSchema(schemaArg = 0)
public data class Convert<T, out C>(val df: DataFrame<T>, val columns: ColumnsSelector<T, C>) {
public fun <R> cast(): Convert<T, R> = Convert(df, columns as ColumnsSelector<T, R>)

@Interpretable("To0")
public inline fun <reified D> to(): DataFrame<T> = to(typeOf<D>())
}

public fun <T> Convert<T, *>.to(type: KType): DataFrame<T> = to { it.convertTo(type) }

public fun <T, C> Convert<T, C>.to(columnConverter: DataFrame<T>.(DataColumn<C>) -> AnyBaseCol): DataFrame<T> =
df.replace(columns).with { columnConverter(df, it) }

@Interpretable("With0")
public inline fun <T, C, reified R> Convert<T, C>.with(
infer: Infer = Infer.Nulls,
noinline rowConverter: RowValueExpression<T, C, R>,
): DataFrame<T> =
withRowCellImpl(typeOf<R>(), infer, rowConverter)

@Refine
@Interpretable("With0")
public inline fun <T, C, reified R> Convert<T, C>.with(
noinline rowConverter: RowValueExpression<T, C, R>
): DataFrame<T> = with(Infer.Nulls, rowConverter)

public inline fun <T, C, reified R> Convert<T, C>.perRowCol(
infer: Infer = Infer.Nulls,
noinline expression: RowColumnExpression<T, C, R>,
): DataFrame<T> =
convertRowColumnImpl(typeOf<R>(), infer, expression)

public fun <T, C> Convert<T, C>.to(columnConverter: DataFrame<T>.(DataColumn<C>) -> AnyBaseCol): DataFrame<T> =
df.replace(columns).with { columnConverter(df, it) }

public inline fun <reified C> AnyCol.convertTo(): DataColumn<C> = convertTo(typeOf<C>()) as DataColumn<C>

public fun AnyCol.convertTo(newType: KType): AnyCol {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import org.jetbrains.kotlinx.dataframe.ColumnsSelector
import org.jetbrains.kotlinx.dataframe.DataColumn
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.DataRow
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
import org.jetbrains.kotlinx.dataframe.annotations.Refine
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
Expand All @@ -13,7 +15,8 @@ import kotlin.reflect.KProperty
private val defaultExplodeColumns: ColumnsSelector<*, *> = { colsAtAnyDepth { it.isList() || it.isFrameColumn() } }

// region explode DataFrame

@Refine
@Interpretable("Explode0")
public fun <T> DataFrame<T>.explode(
dropEmpty: Boolean = true,
selector: ColumnsSelector<T, *> = defaultExplodeColumns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.jetbrains.kotlinx.dataframe.api
import org.jetbrains.kotlinx.dataframe.ColumnsContainer
import org.jetbrains.kotlinx.dataframe.DataColumn
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
import org.jetbrains.kotlinx.dataframe.api.ExprColumnsSelectionDsl.Grammar
import org.jetbrains.kotlinx.dataframe.api.ExprColumnsSelectionDsl.Grammar.PlainDslName
import org.jetbrains.kotlinx.dataframe.documentation.ColumnExpression
Expand Down Expand Up @@ -91,6 +92,7 @@ public interface ExprColumnsSelectionDsl {
* @param [expression] An [AddExpression] to define what each new row of the temporary column should contain.
* @see [ColumnsContainer.mapToColumn]
*/
@Interpretable("Expr0")
public inline fun <T, reified R> ColumnsSelectionDsl<T>.expr(
name: String = "",
infer: Infer = Infer.Nulls,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import org.jetbrains.kotlinx.dataframe.AnyColumnGroupAccessor
import org.jetbrains.kotlinx.dataframe.AnyColumnReference
import org.jetbrains.kotlinx.dataframe.ColumnsSelector
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
import org.jetbrains.kotlinx.dataframe.annotations.Refine
import org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
import org.jetbrains.kotlinx.dataframe.impl.columnName
Expand All @@ -12,6 +14,7 @@ import kotlin.reflect.KProperty

// region DataFrame

@Interpretable("Group0")
public fun <T, C> DataFrame<T>.group(columns: ColumnsSelector<T, C>): GroupClause<T, C> = GroupClause(this, columns)

public fun <T> DataFrame<T>.group(vararg columns: String): GroupClause<T, Any?> = group { columns.toColumnSet() }
Expand Down Expand Up @@ -39,6 +42,8 @@ public fun <T, C> GroupClause<T, C>.into(column: ColumnsSelectionDsl<T>.(ColumnW
public fun <T, C> GroupClause<T, C>.into(column: ColumnsSelectionDsl<T>.(ColumnWithPath<C>) -> AnyColumnReference): DataFrame<T> =
df.move(columns).under(column)

@Refine
@Interpretable("Into0")
public fun <T, C> GroupClause<T, C>.into(column: String): DataFrame<T> = into(columnGroup().named(column))

public fun <T, C> GroupClause<T, C>.into(column: AnyColumnGroupAccessor): DataFrame<T> = df.move(columns).under(column)
Expand Down
Loading