Comments (10)
I was playing with this by trying implicit conversion from Symbol
to TypedColumn
but I wasn't able to capture symbol value on type level this way. It should be possible with implicit macro, but we should somehow minimize an amount of macro code we write ourselves and rely on tools from shapeless.
from frameless.
Hey guys, I think this is a great feature and it will make writing expressions much cleaner. I was able to get this working:
def select[A](column: Witness.Lt[Symbol])(
implicit
exists: TypedColumn.Exists[T, column.T, A],
encoder: TypedEncoder[A]): TypedDataset[A] = select(col(column))
It combines what the col
method does to get the typed column and then feed the column to the existing select
.
With this you can do select('foo) and it works.
Unfortunately this cause a strange issue when passing a TypedAggregateAndColumn
to select. For example, test("count") in AggregateFunctionsTests.scala stopped compiling.
Obviously, the solution is not perfect (since it's causing an issue), but the direction might be promising? What do you guys think? Any ideas?
from frameless.
The biggest challenge with this syntax (besides IDE support) is the support full scope of Spark Column
expressions, that is, being able to write stuff like select('foo + 1)
.
Early work on the lib made use of shapeless' SingletonProductArgs
macro to solve the non expression part of this problem, if you are interested here is the select
implementation and test from git's history.
from frameless.
I think we could make @kanterov idea of "implicit conversion from Symbol
to TypedColumn
" work in typelevel-scala:
scala> :paste
// Entering paste mode (ctrl-D to finish)
trait TypedColumn[S <: Singleton]
implicit def lift[S <: Singleton](s: S): TypedColumn[S] = new TypedColumn[S] {}
def select[A <: Singleton](p: TypedColumn[A]) = p
implicit class AddIntToTypedColumn(i: Int) {
def plus[S <: Singleton](s: TypedColumn[S]) = s
}
// Exiting paste mode, now interpreting.
defined trait TypedColumn
lift: [S <: Singleton](s: S)TypedColumn[S]
select: [A <: Singleton](p: TypedColumn[A])TypedColumn[A]
defined class AddIntToTypedColumn
scala> select("hello")
res0: TypedColumn["hello"] = $anon$1@7e40c3aa
scala> select(1 plus "hello")
res1: TypedColumn["hello"] = $anon$1@5d864a5
from frameless.
@OlivierBlanvillain yes, supporting expressions with select should definetly be part of ay solution.
Btw the above snippet gives this error for me:
// Exiting paste mode, now interpreting.
defined trait TypedColumn
lift: [S <: Singleton](s: S)TypedColumn[S]
select: [A <: Singleton](p: TypedColumn[A])TypedColumn[A]
defined class AddIntToTypedColumn
scala> select("hello")
<console>:19: error: type mismatch;
found : String("hello")
required: TypedColumn[?]
select("hello")
from frameless.
On my setup it works with the following:
$ cat build.sbt
scalaVersion := "2.11.8"
scalaOrganization := "org.typelevel"
libraryDependencies ++= Seq(
"org.typelevel" %% "cats" % "0.7.2",
"com.chuusai" %% "shapeless" % "2.3.2")
scalacOptions := Seq(
"-deprecation",
"-encoding", "UTF-8",
"-feature",
"-language:implicitConversions",
"-unchecked",
"-Xfuture",
"-Xlint",
"-Yinline-warnings",
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Ypartial-unification",
"-Yliteral-types",
"-Ywarn-value-discard")
$ cat project/build.properties
sbt.version=0.13.13-RC2
$ sbt console
[...]
from frameless.
@OlivierBlanvillain This is awesome. Does it require Typelevel Scala to compile user code? In this case, we might still want to investigate if we can reuse macro from shapeless somehow, it would be nice if we find cheap solution instead of forcing users to switch Scala compiler :).
from frameless.
Yes, we would need this PR to be merged to have singelton types in Lightbend Scala.
from frameless.
Wow, I'm looking forward to have this if one day Spark compiles with 2.13.0
from frameless.
Hi, closing it for now with #449 merged.
from frameless.
Related Issues (20)
- spark-sql 3.1.2 can't work with frameless-dataset 0.11.1 HOT 3
- Snapshot publish failed
- Compatibility with Spark 3.2.1 HOT 11
- Cats-effect 3 roadmap HOT 1
- CI release failure HOT 7
- How should parse and convert data from an external medium in a generic way? HOT 2
- Frameless 0.13 release HOT 2
- spark 3.4 support - replacing dataTypeFor logic HOT 8
- 3.4 AgnosticEncoder support - Spark Connect HOT 1
- [feature] DatasetT HOT 1
- AVG and KMeans tests fix HOT 1
- Add scalafmt HOT 1
- Add support for TypedDeltaTable
- use HOT 1
- Iterate over TypedColumns with evidence
- Spark 3.5 update HOT 10
- type inference for .opt no longer works without explicit type argument in Scala 2.13.x HOT 3
- Defective schema generation on array/seq column HOT 5
- scalafmt was not maintained for some of the code? HOT 2
- Add TypedEncoder for shapeless Record. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from frameless.