-
Notifications
You must be signed in to change notification settings - Fork 9
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
Allow selection of nested members of StructType #7
Comments
Amy pointers to how this could be implemented? If I find the time, I would give it a try. |
I experimented with that already quite some time ago so I might not remember the problems I had with that in detail. But in general I would expect it to look more or less like that: Somewhere in iskra: //> using scala "3.2.1"
import scala.language.implicitConversions
trait UntypedColumn
trait DataType
trait StringType extends DataType
trait StructType[Schema <: Tuple] extends DataType
type Label = String & Singleton
class Column[+T <: DataType](val untyped: UntypedColumn)
object Column:
// We should prefer `given Conversion` over `implicit def`
// but that would require importing `scala.language.implicitConversions` at use site rather than at definition site
// or enabling `-language:implicitConversions` option globally by the library's users
// but that's probably not what we would like
// given [T <: Tuple](using cv: ColumnView[T]): Conversion[Column[StructType[T]], cv.Out] = cv.view(_)
implicit def structColumnAsSchemaView[T <: Tuple](column: Column[StructType[T]])(using cv: ColumnView[T]): cv.Out = cv.view(column)
@annotation.showAsInfix
class :=[L <: Label, T <: DataType](untyped: UntypedColumn) extends Column[T](untyped)
trait SchemaView extends Selectable:
def selectDynamic(name: String): Any = ???
trait ColumnView[T <: Tuple]:
type Out <: SchemaView
def view(column: Column[StructType[T]]): Out
object ColumnView:
// hard coded example
given ColumnView[("first" := StringType, "last" := StringType)] with
type Out = SchemaView {
def first: "first" := StringType
def last: "last" := StringType
}
def view(column: Column[StructType[("first" := StringType, "last" := StringType)]]): Out =
new SchemaView:
def first: "first" := StringType = ???
def last: "last" := StringType = ???
// Generic macro implementation for any tuple type
// The macro should probably be easily extractable from `schemaViewExpr`
//transparent inline given [T <: Tuple]: ColumnView[T] = ${ /* ... */ } At use site - this should still compile when : case class Name(first: String, last: String)
@main def test =
val fullName: Column[StructType[("first" := StringType, "last" := StringType)]] = ???
val firstName = fullName.first The example is self contained and has proper IDE support in metals (showing exact types on hover, code completions, etc.). This should still work when we replace the hard coded given instance of |
@prolativ does that still apply for the |
Actually
df.select(($.x, $.y) ++ $.z.*) (easier to implement) df.select($.x, $.y, $.z.*) (more like traditional spark syntax)? |
The main purpose of
df.groupBy($.string).agg(sum(sum($.ints))) (trying to sum a sum would cause a runtime error)
(2) seems to require more effort than I originally expected so I might try to extract the changes needed for (1) and get them merged into the main branch and leave further exploration of (2) for more distant future. Beside what was mentioned above I don't think there's much that would change with regard to |
I haven't done much Scala 3 development yet, but would an opaque type that wraps a tuple be an option?
Imo Iskra should continue to explore how nice of an API one can get with Scala 3 features without being burdened by cross-compatibility.
If there's any possibility to implement it, I would say the version with just |
I don't think opaque types would be any help here unfortunately. The main advantages of tuples come from the fact that the compiler actually sees them as tuples, not some other type.
Both these libraries have a different approach than iskra and I think we could do it better but the question is how much effort this would require
Inlined varargs seem like an interesting alternative but some more experiments would be necessary to assess the advantages and drawbacks of this approach |
No description provided.
The text was updated successfully, but these errors were encountered: