>
> Seq(Text(0, "hello"), Text(1, "world")).toDF.as[Text]


Use toDS() and you can skip the .as[Text]


> Sure! It works with map, but not with select. Wonder if it's by design
> or...will soon be fixed? Thanks again for your help.


This is by design.  select is relational and works with column expressions.
 map is functional and works with lambda functions.

scala> ds.select('id.as[Int], 'text.as[String]).show
> +---+-----+
> | _1|   _2|
> +---+-----+
> |  0|hello|
> |  1|world|
> +---+-----+
>

This is trickier.  In general we try to ensure that the type signatures for
typed functions always match the schema.  The typed version of select with
two arguments returns a tuple (and has to because the scala compiler does
not know the names of the columns you are specifying), so the schema should
be _1, _2.  If we propagated the names then  datasets with the same type
signature in scala would have different schema, which I think would be
confusing.

Reply via email to