-
Notifications
You must be signed in to change notification settings - Fork 73
Extend CS DSL support in compiler plugin #1079
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
Conversation
beb5c3e
to
c5680dd
Compare
@@ -61,3 +64,20 @@ public interface ColumnWithPath<out T> : DataColumn<T> { | |||
} | |||
|
|||
public val <T> ColumnWithPath<T>.depth: Int get() = path.depth() | |||
|
|||
public fun ColumnWithPath(column: DataColumn<*>, path: ColumnPath): ColumnWithPath<*> = |
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.
Duplicate logic to BaseColumn<T>.addPath(path: ColumnPath)
. They should probably call each other if we want to keep both
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.
That's a good point, thank you. I'll call addPath from ColumnWithPath
Wow really cool! :D That's so many supported functions :) Does the compiler plugin need to understand the entire expression or can it also just understand a part of it? Like: df.select { name and cols { false } }.name |
} | ||
|
||
interface ColumnsResolver { | ||
interface ColumnsResolver : org.jetbrains.kotlinx.dataframe.columns.ColumnSet<Any?> { |
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.
Why does this not inherit org.jetbrains.kotlinx.dataframe.columns.ColumnsResolver<Any?>
like the name suggests? I suspect this is gonna be confusing in the future (oh it's because I sealed it... oops... oh well, just have to be careful with instance checks for when some columnsResolver is a singlecolumn or columnset)
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.
Hmm, yes, i picked this name before i dig into CS DSL. Now it's kind of a legacy mode for compatibility with previously implemented functions, that needs to be refactored. After that i'd rename ColumnResolver (plugin) -> ColumnSetApproximation, and remove ColumnResolver (plugin) from supertypes of SingleColumnApproximation . Sounds good?
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.
sounds great :)
There's no such partial evaluation in place now |
c5680dd
to
8497e3e
Compare
} | ||
|
||
@DataSchema | ||
interface Person2 { |
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.
sometimes I suppose it's bad that some numerical types as Long/Double are not presented in this dataset
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.
true, I suppose weight could be a double actually, that's pretty realistic
} | ||
} | ||
|
||
internal class AllAfter2 : AbstractInterpreter<ColumnsResolver>() { |
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.
What's the difference between AllAfter1/AllAfter2
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.
CS DSL functions differ a little, but plugin implementation happened to be the same. You're right, i'll update it to use abstract class
val Arguments.receiver: ColumnsResolver by arg() | ||
val Arguments.column: SingleColumnApproximation by arg() | ||
override fun Arguments.interpret(): ColumnsResolver { | ||
return columnsResolver { receiver.allBefore(column) } |
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.
Seems like it could be one class with the reference on function in some cases
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.
Would be cool! I tried to get the reference to allBefore, but it's strange.. Hard to get the reference to an extension function inside interface, plus we have ambiguity. So this doesn't compile
public companion object {
internal val AllColumnsSelectionDsl<*>.a: ColumnSelectionDsl<*>.(ColumnSelector<*, *>) -> ColumnSet<*> get() = ColumnsSelectionDsl<*>::allBefore
}
} | ||
private fun List<AnyCol>.mapBack(): List<SimpleCol> = map { it.asSimpleColumn() } | ||
|
||
fun AnyCol.asSimpleColumn(): SimpleCol { |
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.
could you add some comment, when to use this function
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.
sure
public fun <T> DataFrame<T>.xs(vararg keyValues: Any?): DataFrame<T> = | ||
xs(*keyValues) { | ||
colsAtAnyDepth { !it.isColumnGroup() }.take(keyValues.size) | ||
} | ||
|
||
@Refine |
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.
Could you please explain, when we are using @refine and when are not using this
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.
Refine is needed when fuction returns dataframe, datarow or groupby. It indicated that type parameter of the return type will be updated by the plugin. interpretable indicated more general situation for CS DSL for example, where plugin doesn't touch return type
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.
Please answer my comments, before or after merging
I made adapter layer, so most implementations in compiler plugin just delegate to core. So most of this PR are tests for all different overloads, making sure they work