partiql / partiql-lang-kotlin

PartiQL libraries and tools in Kotlin.
https://partiql.org/
Apache License 2.0
539 stars 61 forks source link

Redesign ExprValue to support alternative backends #1188

Open vgapeyev opened 1 year ago

vgapeyev commented 1 year ago

ExprValue class is the implementation of the PartiQL data model. Most ExprValue subclasses constitute a "vanilla", or direct, implementation of the data model, while there are a couple subclasses that address consuming other data: CsvRowExprValue for CVS and IonStructExprValue for Ion. While there is some lazyness/on-demand in their implementations, data originating as Ion or CSV is translated into the vanilla data model before PartiQL queries are executed on it.

A few shortcomings of the current ExprValue design have become apparent lately:

It should be possible to execute PartiQL queries directly on various "PartiQL-datamodel-like" data, by translating the queries into calls to the native APIs for the data. A technical approach to this can be by redesigning ExprValue as an API that can have multiple implementations: one being the vanilla PartiQL data model, while others being wrappers over the native APIs for other kinds of data.

The pursued solution amounts to reimagining the PartiQL data model as a collection of data construction and deconstruction requirements, which could be fulfilled by alternative concrete data models -- possibly partially and possibly by data models with additional features. The concrete data models mentioned above should probably be included in proving this redesign:

Technically, this will amount to re-designing ExprValue as an API (a collection of interfaces) and providing several implementations of it. The current ExprValue implementation can be seen as an amalgamation of at least 3 implementations (vanilla, Ion, and CSV-backed). These will be teased apart.

It is likely that the API will have to be structured to explicitly address value construction vs value deconstruction/exploration, with the overall architecture providing for a possibility of the two from different data models being used in conjunction. This could be essential, for example, for performing aggregation into collections of data coming from CSV.

It is also anticipated that ExprValue redesign will imply reconsidering the the very high-level APIs of constructing an evaluation environment (EvaluationSession) and evaluating a query within an environment.

RCHowell commented 1 month ago

See V1 Datum

https://github.com/partiql/partiql-lang-kotlin/pull/1451