Skip to content

3.4+ #218

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

Draft
wants to merge 40 commits into
base: main
Choose a base branch
from
Draft

3.4+ #218

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
cda9548
updating version range to 3.4.2 and 3.5.1
Jolanrensen Mar 17, 2024
42ba339
(re)moving some stuff from the decoupled :core module
Jolanrensen Mar 17, 2024
4896354
adding initial new KotlinTypeInference Encoder generator, this time p…
Jolanrensen Mar 17, 2024
e234f40
updating all references to the old encoder<>() function in favor of t…
Jolanrensen Mar 17, 2024
66a42ac
updating tests tests
Jolanrensen Mar 17, 2024
3e9261f
made name hack optional as it is not waterproof
Jolanrensen Mar 17, 2024
0d061b6
added tests and fixed name hack
Jolanrensen Mar 17, 2024
0c8f4b1
Map support
Jolanrensen Mar 17, 2024
9149607
disable name hack by default again, added JCP case for auto-applying …
Jolanrensen Mar 18, 2024
4364022
udt fix
Jolanrensen Mar 18, 2024
2c875ff
enabled core as scala-helpers with VarargUnwrapper. Removed name hack…
Jolanrensen Mar 20, 2024
d60e4dc
enabled core as scala-helpers with VarargUnwrapper. Removed name hack…
Jolanrensen Mar 20, 2024
4f8d874
updating some build parameters
Jolanrensen Mar 21, 2024
2a878f1
bumped to kotlin 2.0.0-Beta5, included the compiler plugin with tests…
Jolanrensen Mar 21, 2024
c0a3140
Added gradle plugin and fixed package naming errors
Jolanrensen Mar 22, 2024
1b0b316
enabling the compiler plugin on modules, sparkifying data classes
Jolanrensen Mar 22, 2024
b7c1711
bumping down to kotlin 1.9.23 to make lambda's serializable again
Jolanrensen Mar 22, 2024
7069a9a
fixing tests
Jolanrensen Mar 22, 2024
df021c0
fixing more tests. Can now remain at Kotlin 2.0 if we set -Xlambdas=c…
Jolanrensen Mar 23, 2024
4c17859
added conversion for @Sparkify'ed classes to scala.Product with tests.
Jolanrensen Mar 24, 2024
2f62d07
started WIP fir plugin, disabled for now
Jolanrensen Mar 24, 2024
770698b
disabled RddTest "Work with any number" for now: Caused by: java.lang…
Jolanrensen Mar 24, 2024
5d5fe84
Merge branch 'main' into 3.4+
Jolanrensen Mar 25, 2024
24952b7
added publishToMavenLocal for the plugins in gh actions build.yml
Jolanrensen Mar 25, 2024
ffedb29
Merge remote-tracking branch 'origin/3.4+' into 3.4+
Jolanrensen Mar 25, 2024
6b63c96
editing build so that
Jolanrensen Mar 25, 2024
4e5438b
fixing compiler-plugin tests
Jolanrensen Mar 25, 2024
723152b
fixed conversions for scala 2.12
Jolanrensen Mar 25, 2024
0db290a
small fixes, disabled jupyter module for now
Jolanrensen Mar 25, 2024
37eec64
spark 3.4/3.5 compatibility issue with ProductEncoder
Jolanrensen Mar 25, 2024
0ab212b
fixed streaming test scala 2.12
Jolanrensen Mar 25, 2024
1c34429
added checkIsSparkified warnings when building an encoder
Jolanrensen Mar 27, 2024
68e830a
updated compiler plugin to make @Sparkify classes Serializable too, p…
Jolanrensen Mar 27, 2024
48db819
added java bean class fallback support
Jolanrensen Mar 30, 2024
ab4c455
added encoding for DatePeriod, DateTimePeriod, Instant, LocalDateTime…
Jolanrensen Apr 7, 2024
e05feac
kotlin 2.0.0-RC1, enabled jupyter module. Added basic Sparkify conver…
Jolanrensen Apr 10, 2024
7fd77be
make render in jupyter use show instead
Jolanrensen Apr 10, 2024
92b699d
disabled jupyter tests relying on DISPLAY(), update jupyter to latest…
Jolanrensen May 18, 2024
eae0196
disabled unsupported rddtests
Jolanrensen May 18, 2024
22fa5ae
added spark connect example which does not yet work with kotlin-spark…
Jolanrensen Jun 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bumped to kotlin 2.0.0-Beta5, included the compiler plugin with tests…
… as separate module
  • Loading branch information
Jolanrensen committed Mar 21, 2024
commit 2a878f14cbe9151dd761a65dc1d3d0965236da09
38 changes: 38 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
@file:Suppress("UnstableApiUsage")

import Projects.compilerPlugin
import Projects.gradlePlugin
import com.github.gmazzo.buildconfig.BuildConfigExtension


buildscript {
repositories {
mavenCentral()
Expand All @@ -15,6 +20,7 @@ plugins {
dokka version Versions.dokka
idea
kotlin version Versions.kotlin apply false
buildconfig version Versions.buildconfig apply false
}

group = Versions.groupID
Expand Down Expand Up @@ -113,4 +119,36 @@ allprojects {
}
}
}
}

subprojects {
afterEvaluate {
extensions.findByType<BuildConfigExtension>()?.apply {
val projectVersion = Versions.project
val groupId = Versions.groupID

val compilerPluginId = "$groupId.compilerPlugin"

val compilerPluginArtifactId = compilerPlugin.name
val gradlePluginArtifactId = gradlePlugin.name

val defaultSparkifyFqName = "$groupId.plugin.annotations.Sparkify"
val defaultColumnNameFqName = "$groupId.plugin.annotations.ColumnName"

val projectRoot = project.rootDir.absolutePath

packageName(groupId)
className("Artifacts")

buildConfigField("compilerPluginId", compilerPluginId)
buildConfigField("groupId", groupId)
buildConfigField("gradlePluginArtifactId", gradlePluginArtifactId)
buildConfigField("projectVersion", projectVersion)
buildConfigField("compilerPluginArtifactId", compilerPluginArtifactId)

buildConfigField("defaultSparkifyFqName", defaultSparkifyFqName)
buildConfigField("defaultColumnNameFqName", defaultColumnNameFqName)
buildConfigField("projectRoot", projectRoot)
}
}
}
15 changes: 14 additions & 1 deletion buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ object Dependencies {
inline val hadoopClient get() = "org.apache.hadoop:hadoop-client:${Versions.hadoop}"
inline val sparkRepl get() = "org.apache.spark:spark-repl_${Versions.scalaCompat}:${Versions.spark}"
inline val jupyter get() = "org.jetbrains.kotlinx:kotlin-jupyter-api:${Versions.jupyter}"
inline val junit get() = "org.junit.jupiter:junit-jupiter-engine:5.8.1"
inline val junitJupiterEngine get() = "org.junit.jupiter:junit-jupiter-engine:${Versions.junitJupiterEngine}"
// must be platform()
inline val junitBom get() = "org.junit:junit-bom:${Versions.junitJupiterEngine}"
inline val junitJupiter get() = "org.junit.jupiter:junit-jupiter"
inline val junitPlatformCommons get() = "org.junit.platform:junit-platform-commons"
inline val junitPlatformLauncher get() = "org.junit.platform:junit-platform-launcher"
inline val junitPlatformRunner get() = "org.junit.platform:junit-platform-runner"
inline val junitPlatformSuiteApi get() = "org.junit.platform:junit-platform-suite-api"

inline val junit get() = "junit:junit:${Versions.junit}"
inline val sparkStreamingKafka get() = "org.apache.spark:spark-streaming-kafka-0-10_${Versions.scalaCompat}:${Versions.spark}"
inline val kotest get() = "io.kotest:kotest-runner-junit5:${Versions.kotest}"
inline val kotestTestcontainers get() = "io.kotest.extensions:kotest-extensions-testcontainers:${Versions.kotestTestContainers}"
Expand All @@ -22,6 +31,10 @@ object Dependencies {
inline val kotlinScriptingJvm get() = "org.jetbrains.kotlin:kotlin-scripting-jvm"
inline val jacksonDatabind get() = "com.fasterxml.jackson.core:jackson-databind:${Versions.jacksonDatabind}"
inline val kotlinDateTime get() = "org.jetbrains.kotlinx:kotlinx-datetime:${Versions.kotlinxDateTime}"
inline val kotlinCompiler get() = "org.jetbrains.kotlin:kotlin-compiler:${Versions.kotlin}"
inline val kotlinScriptRuntime get() = "org.jetbrains.kotlin:kotlin-script-runtime:${Versions.kotlin}"
inline val kotlinAnnotationsJvm get() = "org.jetbrains.kotlin:kotlin-annotations-jvm:${Versions.kotlin}"
inline val kotlinCompilerInternalTestFramework get() = "org.jetbrains.kotlin:kotlin-compiler-internal-test-framework:${Versions.kotlin}"
}


Expand Down
5 changes: 5 additions & 0 deletions buildSrc/src/main/kotlin/Helpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ fun DependencyHandler.testImplementation(vararg dependencyNotations: Any): List<
add("testImplementation", it)
}

fun DependencyHandler.testRuntimeOnly(vararg dependencyNotations: Any): List<Dependency?> =
dependencyNotations.map {
add("testRuntimeOnly", it)
}

fun DependencyHandler.implementation(vararg dependencyNotations: Any): List<Dependency?> =
dependencyNotations.map {
add("implementation", it)
Expand Down
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/Plugins.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ inline val Project.mavenPublishBase
inline val PluginDependenciesSpec.jupyter
get() = kotlin("jupyter.api") version Versions.jupyter

inline val PluginDependenciesSpec.buildconfig
get() = id("com.github.gmazzo.buildconfig")

6 changes: 6 additions & 0 deletions buildSrc/src/main/kotlin/Projects.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@ object Projects {

inline val Project.scalaTuplesInKotlin
get() = searchProject("scala-tuples-in-kotlin")

inline val Project.compilerPlugin
get() = searchProject("compiler-plugin")

inline val Project.gradlePlugin
get() = searchProject("gradle-plugin")
}
11 changes: 7 additions & 4 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
object Versions {
const val project = "1.2.5-SNAPSHOT"
const val groupID = "org.jetbrains.kotlinx.spark"
const val kotlin = "1.9.22"
const val kotlin = "2.0.0-Beta5"
const val jvmTarget = "8"
const val jupyterJvmTarget = "8"
inline val spark get() = System.getProperty("spark") as String

inline val scala get() = System.getProperty("scala") as String
inline val sparkMinor get() = spark.substringBeforeLast('.')
inline val scalaCompat get() = scala.substringBeforeLast('.')

inline val scalaCompat get() = scala.substringBeforeLast('.')
// TODO
inline val sparkConnect get() = System.getProperty("sparkConnect", "false").toBoolean()

const val jupyter = "0.12.0-32-1"

const val kotest = "5.5.4"

const val buildconfig = "5.3.5"

const val junitJupiterEngine = "5.8.1"
const val junit = "4.13.2"
const val kotestTestContainers = "1.3.3"
const val dokka = "1.8.20"
const val jcp = "7.0.5"
Expand Down
92 changes: 92 additions & 0 deletions compiler-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
java
kotlin
mavenPublishBase
buildconfig
}

group = Versions.groupID
version = Versions.project

repositories {
mavenCentral()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
}

sourceSets {
test {
val srcDirs = listOf("src/test-gen/kotlin")
kotlin.srcDirs(srcDirs)
java.srcDirs(srcDirs)
}
}

dependencies {
with(Dependencies) {
compileOnly(kotlinCompiler)

testRuntimeOnly(
kotlinTest,
kotlinScriptRuntime,
kotlinAnnotationsJvm,
)

testImplementation(
kotlinCompiler,
reflect,
kotlinCompilerInternalTestFramework,
junit,

platform(junitBom),
junitJupiter,
junitPlatformCommons,
junitPlatformLauncher,
junitPlatformRunner,
junitPlatformSuiteApi,
)
}
}

tasks.test {
useJUnitPlatform()
doFirst {
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-stdlib", "kotlin-stdlib")
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-stdlib-jdk8", "kotlin-stdlib-jdk8")
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-reflect", "kotlin-reflect")
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-test", "kotlin-test")
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-script-runtime", "kotlin-script-runtime")
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-annotations-jvm", "kotlin-annotations-jvm")
}
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
languageVersion = "2.0"
freeCompilerArgs = freeCompilerArgs +
"-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi" +
"-Xcontext-receivers"
}
}

val generateTests by tasks.creating(JavaExec::class) {
classpath = sourceSets.test.get().runtimeClasspath
mainClass.set("org.jetbrains.kotlinx.spark.compilerPlugin.GenerateTestsKt")
}

val compileTestKotlin by tasks.getting {
doLast {
generateTests.exec()
}
}

fun Test.setLibraryProperty(propName: String, jarName: String) {
val path = project.configurations
.testRuntimeClasspath.get()
.files
.find { """$jarName-\d.*jar""".toRegex().matches(it.name) }
?.absolutePath
?: return
systemProperty(propName, path)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.jetbrains.kotlinx.spark.compilerPlugin

import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar

// Potential future K2 FIR hook
class SimplePluginRegistrar(private val sparkifyAnnotationFqNames: List<String>) : FirExtensionRegistrar() {
override fun ExtensionRegistrarContext.configurePlugin() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.jetbrains.kotlinx.spark.compilerPlugin

import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption
import org.jetbrains.kotlin.compiler.plugin.CliOption
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.CompilerConfigurationKey
import org.jetbrains.kotlinx.spark.Artifacts

open class SparkifyCommandLineProcessor : CommandLineProcessor {

init {
println("SparkifyCommandLineProcessor loaded")
}

override val pluginId: String = Artifacts.compilerPluginId

override val pluginOptions: Collection<AbstractCliOption> = listOf(
OPTION_ENABLED,
OPTION_SPARKIFY_ANNOTATION_FQ_NAMES,
OPTION_COLUMN_NAME_ANNOTATION_FQ_NAMES,
)

override fun processOption(option: AbstractCliOption, value: String, configuration: CompilerConfiguration) {
when (val optionName = option.optionName) {
OPTION_ENABLED.optionName ->
configuration.put(KEY_ENABLED, value.toBoolean())

OPTION_SPARKIFY_ANNOTATION_FQ_NAMES.optionName ->
configuration.put(KEY_SPARKIFY_ANNOTATION_FQ_NAMES, value.split(",").map { it.trim() })

OPTION_COLUMN_NAME_ANNOTATION_FQ_NAMES.optionName ->
configuration.put(KEY_COLUMN_NAME_ANNOTATION_FQ_NAMES, value.split(",").map { it.trim() })

else -> error("Unexpected option: $optionName")
}
}
}

internal val KEY_ENABLED = CompilerConfigurationKey<Boolean>("Whether to enable Sparkify")

internal val OPTION_ENABLED = CliOption(
optionName = "enabled",
valueDescription = "<true|false>",
description = "Whether to enable Sparkify",
required = false,
allowMultipleOccurrences = false,
)

internal val KEY_SPARKIFY_ANNOTATION_FQ_NAMES = CompilerConfigurationKey<List<String>>(
"Fully qualified names of annotations for Sparkify"
)

internal val OPTION_SPARKIFY_ANNOTATION_FQ_NAMES = CliOption(
optionName = "sparkifyAnnotationFqNames",
valueDescription = "<fqName1,fqName2,...>",
description = "Fully qualified names of annotations to sparkify",
required = false,
allowMultipleOccurrences = false,
)

internal val KEY_COLUMN_NAME_ANNOTATION_FQ_NAMES = CompilerConfigurationKey<List<String>>(
"Fully qualified names of annotations for ColumnName"
)

internal val OPTION_COLUMN_NAME_ANNOTATION_FQ_NAMES = CliOption(
optionName = "columnNameAnnotationFqNames",
valueDescription = "<fqName1,fqName2,...>",
description = "Fully qualified names of annotations for ColumnName",
required = false,
allowMultipleOccurrences = false,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.jetbrains.kotlinx.spark.compilerPlugin

import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlinx.spark.Artifacts
import org.jetbrains.kotlinx.spark.compilerPlugin.ir.SparkifyIrGenerationExtension

open class SparkifyCompilerPluginRegistrar: CompilerPluginRegistrar() {
init {
println("SparkifyCompilerPluginRegistrar loaded")
}

override val supportsK2: Boolean
get() = true

override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
if (configuration.get(KEY_ENABLED) != true) return

val sparkifyAnnotationFqNames = configuration.get(KEY_SPARKIFY_ANNOTATION_FQ_NAMES)
?: listOf(Artifacts.defaultSparkifyFqName)

val columnNameAnnotationFqNames = configuration.get(KEY_COLUMN_NAME_ANNOTATION_FQ_NAMES)
?: listOf(Artifacts.defaultColumnNameFqName)

IrGenerationExtension.registerExtension(
SparkifyIrGenerationExtension(
sparkifyAnnotationFqNames = sparkifyAnnotationFqNames,
columnNameAnnotationFqNames = columnNameAnnotationFqNames,
)
)
}
}
Loading