-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1055 from Kotlin/group-by-shortcuts
[Compiler plugin] Support more GroupBy shortcuts
- Loading branch information
Showing
18 changed files
with
194 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...ns/kotlin-dataframe/src/org/jetbrains/kotlinx/dataframe/plugin/impl/api/ReducedGroupBy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.jetbrains.kotlinx.dataframe.plugin.impl.api | ||
|
||
import org.jetbrains.kotlinx.dataframe.plugin.impl.AbstractInterpreter | ||
import org.jetbrains.kotlinx.dataframe.plugin.impl.AbstractSchemaModificationInterpreter | ||
import org.jetbrains.kotlinx.dataframe.plugin.impl.Arguments | ||
import org.jetbrains.kotlinx.dataframe.plugin.impl.PluginDataFrameSchema | ||
import org.jetbrains.kotlinx.dataframe.plugin.impl.SimpleColumnGroup | ||
import org.jetbrains.kotlinx.dataframe.plugin.impl.groupBy | ||
import org.jetbrains.kotlinx.dataframe.plugin.impl.ignore | ||
import org.jetbrains.kotlinx.dataframe.plugin.impl.makeNullable | ||
|
||
class GroupByReducePredicate : AbstractInterpreter<GroupBy>() { | ||
val Arguments.receiver by groupBy() | ||
val Arguments.predicate by ignore() | ||
override fun Arguments.interpret(): GroupBy { | ||
return receiver | ||
} | ||
} | ||
|
||
class GroupByReduceExpression : AbstractInterpreter<GroupBy>() { | ||
val Arguments.receiver by groupBy() | ||
val Arguments.rowExpression by ignore() | ||
override fun Arguments.interpret(): GroupBy { | ||
return receiver | ||
} | ||
} | ||
|
||
class GroupByReduceInto : AbstractSchemaModificationInterpreter() { | ||
val Arguments.receiver by groupBy() | ||
val Arguments.columnName: String by arg() | ||
override fun Arguments.interpret(): PluginDataFrameSchema { | ||
val group = makeNullable(SimpleColumnGroup(columnName, receiver.groups.columns())) | ||
return PluginDataFrameSchema(receiver.keys.columns() + group) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
plugins/kotlin-dataframe/src/org/jetbrains/kotlinx/dataframe/plugin/impl/api/count.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.jetbrains.kotlinx.dataframe.plugin.impl.api | ||
|
||
import org.jetbrains.kotlinx.dataframe.plugin.impl.AbstractSchemaModificationInterpreter | ||
import org.jetbrains.kotlinx.dataframe.plugin.impl.Arguments | ||
import org.jetbrains.kotlinx.dataframe.plugin.impl.PluginDataFrameSchema | ||
import org.jetbrains.kotlinx.dataframe.plugin.impl.Present | ||
import org.jetbrains.kotlinx.dataframe.plugin.impl.add | ||
import org.jetbrains.kotlinx.dataframe.plugin.impl.groupBy | ||
import org.jetbrains.kotlinx.dataframe.plugin.impl.ignore | ||
|
||
class GroupByCount0 : AbstractSchemaModificationInterpreter() { | ||
val Arguments.receiver by groupBy() | ||
val Arguments.resultName: String by arg(defaultValue = Present("count")) | ||
val Arguments.predicate by ignore() | ||
|
||
override fun Arguments.interpret(): PluginDataFrameSchema { | ||
return receiver.keys.add(resultName, session.builtinTypes.intType.type, context = this) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import org.jetbrains.kotlinx.dataframe.* | ||
import org.jetbrains.kotlinx.dataframe.annotations.* | ||
import org.jetbrains.kotlinx.dataframe.api.* | ||
import org.jetbrains.kotlinx.dataframe.io.* | ||
|
||
fun box(): String { | ||
val df = dataFrameOf("a")(1, 1, 2, 3, 3).groupBy { a }.count() | ||
val i: Int = df.count[0] | ||
|
||
val df1 = dataFrameOf("a")(1, 1, 2, 3, 3).groupBy { a }.count { a > 1 } | ||
val i1: Int = df1.count[0] | ||
|
||
val df2 = dataFrameOf("a")(1, 1, 2, 3, 3).groupBy { a }.count("myCol") { a > 1 } | ||
val i2: Int = df2.myCol[0] | ||
return "OK" | ||
} |
22 changes: 22 additions & 0 deletions
22
plugins/kotlin-dataframe/testData/box/groupBy_maxOfMinOf.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import org.jetbrains.kotlinx.dataframe.* | ||
import org.jetbrains.kotlinx.dataframe.annotations.* | ||
import org.jetbrains.kotlinx.dataframe.api.* | ||
import org.jetbrains.kotlinx.dataframe.io.* | ||
|
||
fun box(): String { | ||
val df = dataFrameOf("a")(1, 1, 2, 3, 3).groupBy { a }.add("id") { index() }.maxOf { 123 } | ||
val df1 = dataFrameOf("a")(1, 1, 2, 3, 3).groupBy { a }.add("id") { index() }.minOf { 123 } | ||
|
||
val max = df.max[0] | ||
val min = df1.min[0] | ||
|
||
df.compareSchemas() | ||
df1.compareSchemas() | ||
|
||
val df2 = dataFrameOf("a")(1, 1, 2, 3, 3).groupBy { a }.add("id") { index() }.maxOf("myMax") { 123 } | ||
val df3 = dataFrameOf("a")(1, 1, 2, 3, 3).groupBy { a }.add("id") { index() }.minOf("myMin") { 123 } | ||
|
||
df2.myMax | ||
df3.myMin | ||
return "OK" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import org.jetbrains.kotlinx.dataframe.* | ||
import org.jetbrains.kotlinx.dataframe.annotations.* | ||
import org.jetbrains.kotlinx.dataframe.api.* | ||
import org.jetbrains.kotlinx.dataframe.io.* | ||
|
||
fun box(): String { | ||
val groupBy = dataFrameOf("a")(1, 1, 2, 3, 3).groupBy { a }.add("id") { index() } | ||
groupBy.maxBy { id }.into("group").compareSchemas() | ||
groupBy.maxBy { id }.into("group").compareSchemas() | ||
groupBy.first { id == 1 }.into("group").compareSchemas() | ||
groupBy.first().into("group").compareSchemas() | ||
groupBy.last { id == 1 }.into("group").compareSchemas() | ||
groupBy.last().into("group").compareSchemas() | ||
groupBy.minBy { id == 1 }.into("group").compareSchemas() | ||
return "OK" | ||
} |
Oops, something went wrong.