-
Notifications
You must be signed in to change notification settings - Fork 73
Plugin example #1241
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
Merged
Merged
Plugin example #1241
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5f101e9
add a plugin example project
AndreiKingsley 741f7bc
add a plugin example project docs
AndreiKingsley 084f563
Merge branch 'master' into plugin_example
AndreiKingsley 43dc1b4
fix Compiler-Plugin.md
AndreiKingsley c5fba7c
rm csv
AndreiKingsley 1ab848f
compiler plugin example fixes
AndreiKingsley fbb39ce
compiler plugin docs fixes
AndreiKingsley 55101c1
lint fix
AndreiKingsley d99d3da
lint and build script fix
AndreiKingsley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,10 @@ | ||
# Kotlin DataFrame Compiler Plugin Example | ||
|
||
An IntelliJ IDEA project demonstrating the use of the | ||
[Kotlin DataFrame Compiler Plugin](https://kotlin.github.io/dataframe/compiler-plugin.html). | ||
|
||
> **Note:** This project uses **dev versions** of the Kotlin and the Kotlin DataFrame plugin. | ||
> See [build.gradle.kts](build.gradle.kts) for details. | ||
|
||
For proper functionality in IntelliJ IDEA requires version 2025.2 or higher | ||
(Currently available only in [IntelliJ IDEA EAP](https://www.jetbrains.com/idea/nextversion/?_gl=1*1ojxffu*_gcl_au*MTk5NzUwODYzOS4xNzQ2NzkxMDMz*_ga*MTE0ODQ1MzY3OS4xNzM4OTY1NzM3*_ga_9J976DJZ68*czE3NDkyMTM4MzkkbzE5OCRnMSR0MTc0OTIxMzg0MSRqNTgkbDAkaDA.)). |
This file contains hidden or 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,32 @@ | ||
import org.jlleitschuh.gradle.ktlint.KtlintExtension | ||
|
||
plugins { | ||
id("org.jlleitschuh.gradle.ktlint") version "12.3.0" | ||
kotlin("jvm") version "2.2.20-dev-3524" | ||
kotlin("plugin.dataframe") version "2.2.20-dev-3524" | ||
} | ||
|
||
group = "org.example" | ||
version = "1.0-SNAPSHOT" | ||
|
||
repositories { | ||
maven("https://packages.jetbrains.team/maven/p/kt/dev/") | ||
mavenCentral() | ||
} | ||
|
||
Jolanrensen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
dependencies { | ||
implementation("org.jetbrains.kotlinx:dataframe:1.0.0-Beta2") | ||
testImplementation(kotlin("test")) | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
} | ||
kotlin { | ||
jvmToolchain(11) | ||
} | ||
|
||
configure<KtlintExtension> { | ||
version = "1.6.0" | ||
// rules are set up through .editorconfig | ||
} |
This file contains hidden or 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,4 @@ | ||
kotlin.code.style=official | ||
# Disabling incremental compilation will no longer be necessary | ||
# when https://youtrack.jetbrains.com/issue/KT-66735 is resolved. | ||
kotlin.incremental=false | ||
AndreiKingsley marked this conversation as resolved.
Show resolved
Hide resolved
|
11 changes: 11 additions & 0 deletions
11
examples/kotlin-dataframe-plugin-example/settings.gradle.kts
This file contains hidden or 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,11 @@ | ||
pluginManagement { | ||
repositories { | ||
maven("https://packages.jetbrains.team/maven/p/kt/dev/") | ||
mavenCentral() | ||
gradlePluginPortal() | ||
} | ||
} | ||
plugins { | ||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" | ||
} | ||
rootProject.name = "kotlin-dataframe-plugin-example" |
93 changes: 93 additions & 0 deletions
93
...me-plugin-example/src/main/kotlin/org/jetbrains/kotlinx/dataframe/examples/plugin/Main.kt
This file contains hidden or 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,93 @@ | ||
package org.jetbrains.kotlinx.dataframe.examples.plugin | ||
|
||
import org.jetbrains.kotlinx.dataframe.DataFrame | ||
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema | ||
import org.jetbrains.kotlinx.dataframe.api.add | ||
import org.jetbrains.kotlinx.dataframe.api.convert | ||
import org.jetbrains.kotlinx.dataframe.api.convertTo | ||
import org.jetbrains.kotlinx.dataframe.api.filter | ||
import org.jetbrains.kotlinx.dataframe.api.into | ||
import org.jetbrains.kotlinx.dataframe.api.rename | ||
import org.jetbrains.kotlinx.dataframe.api.renameToCamelCase | ||
import org.jetbrains.kotlinx.dataframe.api.with | ||
import org.jetbrains.kotlinx.dataframe.io.readCsv | ||
import org.jetbrains.kotlinx.dataframe.io.writeCsv | ||
import java.net.URL | ||
|
||
// Declare data schema for the DataFrame from jetbrains_repositories.csv. | ||
@DataSchema | ||
data class Repositories( | ||
val full_name: String, | ||
val html_url: URL, | ||
val stargazers_count: Int, | ||
val topics: String, | ||
val watchers: Int, | ||
) | ||
|
||
// Define kinds of repositories. | ||
enum class RepoKind { | ||
Kotlin, | ||
IntelliJ, | ||
Other, | ||
} | ||
|
||
// A rule for determining the kind of repository based on its name and topics. | ||
fun getKind(fullName: String, topics: List<String>): RepoKind { | ||
fun checkContains(name: String) = name in topics || fullName.lowercase().contains(name) | ||
|
||
return when { | ||
checkContains("kotlin") -> RepoKind.Kotlin | ||
checkContains("idea") || checkContains("intellij") -> RepoKind.IntelliJ | ||
else -> RepoKind.Other | ||
} | ||
} | ||
|
||
Jolanrensen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fun main() { | ||
val repos = DataFrame | ||
// Read DataFrame from the CSV file. | ||
.readCsv("https://raw.githubusercontent.com/Kotlin/dataframe/master/data/jetbrains_repositories.csv") | ||
// And convert it to match the `Repositories` schema. | ||
.convertTo<Repositories>() | ||
|
||
// With Compiler Plugin, the DataFrame schema changes immediately after each operation: | ||
// For example, if a new column is added or the old one is renamed (or its type is changed) | ||
// during the operation, you can use the new name immediately in the following operations: | ||
repos | ||
// Add a new "name" column... | ||
.add("name") { full_name.substringAfterLast("/") } | ||
// ... and now we can use "name" extension in DataFrame operations, such as `filter`. | ||
.filter { name.lowercase().contains("kotlin") } | ||
|
||
// Let's update the DataFrame with some operations using these features. | ||
val reposUpdated = repos | ||
// Rename columns to CamelCase. | ||
// Note that after that, in the following operations, extension properties will have | ||
// new names corresponding to the column names. | ||
.renameToCamelCase() | ||
// Rename "stargazersCount" column to "stars". | ||
.rename { stargazersCount }.into("stars") | ||
// And we can immediately use the updated name in the filtering. | ||
.filter { stars > 50 } | ||
// Convert values in the "topic" column (which were `String` initially) | ||
// to the list of topics. | ||
.convert { topics }.with { | ||
val inner = it.removeSurrounding("[", "]") | ||
if (inner.isEmpty()) emptyList() else inner.split(',').map(String::trim) | ||
} | ||
// Now "topics" is a `List<String>` column. | ||
// Add a new column with the number of topics. | ||
.add("topicCount") { topics.size } | ||
Jolanrensen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Add a new column with the kind of repository. | ||
.add("kind") { getKind(fullName, topics) } | ||
|
||
// Write the updated DataFrame to a CSV file. | ||
reposUpdated.writeCsv("jetbrains_repositories_new.csv") | ||
|
||
// TODO: Add Kandy Plot | ||
// reposUpdated.groupBy { kind }.max { stargazersCount }.plot { | ||
// bars { | ||
// x(kind) | ||
// y(stargazersCount) | ||
// } | ||
// } | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uhm, maybe scrap "refactoring" for now. That does not work yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But will be :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope so :)