Giter Site home page Giter Site logo

Comments (10)

kanterov avatar kanterov commented on May 23, 2024

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.

imarios avatar imarios commented on May 23, 2024

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.

OlivierBlanvillain avatar OlivierBlanvillain commented on May 23, 2024

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.

OlivierBlanvillain avatar OlivierBlanvillain commented on May 23, 2024

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.

imarios avatar imarios commented on May 23, 2024

@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.

OlivierBlanvillain avatar OlivierBlanvillain commented on May 23, 2024

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.

kanterov avatar kanterov commented on May 23, 2024

@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.

OlivierBlanvillain avatar OlivierBlanvillain commented on May 23, 2024

Yes, we would need this PR to be merged to have singelton types in Lightbend Scala.

from frameless.

joan38 avatar joan38 commented on May 23, 2024

Wow, I'm looking forward to have this if one day Spark compiles with 2.13.0

from frameless.

cchantep avatar cchantep commented on May 23, 2024

Hi, closing it for now with #449 merged.

from frameless.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.