Skip to content

Explore the possiblity to define schema and constunct object in Spring (DI framework) style #1321

@zaleslaw

Description

@zaleslaw

Motivation:

  • Nice to have an ability to hide reading the schema and object construction from the user in DI style where all the data sources and its life-cycle is managed by DI framework
  • Unified approach for Spring developers

We want to have something like

@DataSource(csvFile = "data.csv")
val df: DataFrame<MyRowType>

it should be, for example RUNTIME-annotation

@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY)
@Retention(AnnotationRetention.RUNTIME)
annotation class DataSource(val csvFile: String)

we need a DataFrame postprocessor in the style

@Component
class DataFramePostProcessor : BeanPostProcessor {

    override fun postProcessBeforeInitialization(bean: Any, beanName: String): Any? {
        bean::class.memberProperties.forEach { prop ->
            val annotation = prop.findAnnotation<DataSource>()
            if (annotation != null) {
                val csvPath = annotation.csvFile
                val dataFrame = DataFrame.readCSV(File(csvPath))


                val field = bean.javaClass.getDeclaredField(prop.name)
                field.isAccessible = true
                field.set(bean, dataFrame)
            }
        }
        return bean
    }
}

The usage of the bean could be like below

@Component
class MyDataService {

    @DataSource(csvFile = "data.csv")
    lateinit var df: DataFrame<MyRow>

    fun process() {
        println(df.rowsCount())
    }
}

Metadata

Metadata

Labels

researchThis requires a deeper dive to gather a better understanding

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions