-
Notifications
You must be signed in to change notification settings - Fork 75
(internal MVP) Prototype new iteration of ImportDataSchema annotation #1416
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
base: master
Are you sure you want to change the base?
Conversation
6ab4ef8
to
dee09cf
Compare
dee09cf
to
9eacca5
Compare
@@ -43,6 +44,9 @@ public annotation class ImportDataSchema( | |||
val enableExperimentalOpenApi: Boolean = false, | |||
) | |||
|
|||
@Target(AnnotationTarget.CLASS) | |||
public annotation class DataSchemaSource(val source: String, val qualifier: String = SchemaReader.DEFAULT_QUALIFIER) |
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 can guess what source
does, but qualifier
is unclear for me. Some comments would be nice, even though it's just a proof-of-concept
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 think I remember vaguely from your demo that this allowed to make distinctions of some kind. But I don't remember exactly without a small example
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.
May be some KDocs here as well?
@@ -59,6 +59,36 @@ public interface SupportedDataFrameFormat : SupportedFormat { | |||
public fun readDataFrame(file: File, header: List<String> = emptyList()): DataFrame<*> | |||
} | |||
|
|||
/** | |||
* User-facing API implemented by a companion object of an imported schema [org.jetbrains.kotlinx.dataframe.annotations.DataSchemaSource] |
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.
*the companion object
|
||
/** | ||
* Handler of classes annotated with [org.jetbrains.kotlinx.dataframe.annotations.DataSchemaSource]. | ||
* Implementations must have a single zero-argument constructor |
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.
they could also be object
singletons maybe, since they have no state
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.
Good idea! It first needs to be adjusted in compiler plugin
|
||
public fun accepts(path: String, qualifier: String): Boolean = qualifier == DEFAULT_QUALIFIER | ||
|
||
public fun read(path: String): DataFrame<*> |
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.
we do need a way to pass extra arguments in the future. There are many ways to do this but we can figure that out later :)
|
||
public fun read(path: String): DataFrame<*> | ||
|
||
public fun default(path: String): DataFrame<*> = read(path) |
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'd still rename this to readDefault
or readSource
, something more imperative.
|
||
/** | ||
* Serializes data schema into a human-readable JSON format. | ||
* Input of compiler plugin for "imported data schema" feature |
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 add a tiny sample :) similar to what Nikita did in serialization_format.md It helps to see that this builds
* Input of compiler plugin for "imported data schema" feature | ||
*/ | ||
fun DataFrameSchema.toJsonString( | ||
json: Json = Json { prettyPrint = true }, |
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 be extracted to a private const
val configuration = DataFrameConfiguration( | ||
resolutionDir = environment.options["dataframe.resolutionDir"], | ||
importedSchemasOutput = environment.options[DATAFRAME_IMPORTED_SCHEMAS_OUTPUT], | ||
experimentalImportSchema = environment.options["dataframe.experimentalImportSchema"].equals( |
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.
probably better readable like:
environment.options["dataframe.experimentalImportSchema"]
.equals("true", ignoreCase = true)
This also satisfies KtLint :)
@@ -43,6 +44,9 @@ public annotation class ImportDataSchema( | |||
val enableExperimentalOpenApi: Boolean = false, | |||
) | |||
|
|||
@Target(AnnotationTarget.CLASS) | |||
public annotation class DataSchemaSource(val source: String, val qualifier: String = SchemaReader.DEFAULT_QUALIFIER) |
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.
May be some KDocs here as well?
This PR enables basic idea of a new workflow with imported schemas:
The goal for now is MVP for internal testing.
How this approach different:
What's new:
Approach to custom formats and generic schema preprocessing
We explore idea of service loader in KSP processor. Anyone can provide SchemaReader implementation in another module of their project and generate schemas for arbitrary data, for example
KSP plugin now has two new parameters:
disables old annotation processing for DataSchema and ImportDataSchema so they don't conflict with the compiler plugin
output directory where json files will be generated, serves as input of compiler plugin
Example setup: