Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Scala's Symbol not accepted as a column reference?

Trying the examples of Spark SQL, they seem to work well except when expressions are needed:

scala> val teenagers = people.where('age >= 10).where('age <= 19).select('name)
<console>:23: error: value >= is not a member of Symbol
       val teenagers = people.where('age >= 10).where('age <= 19).select('name)

scala> val teenagers = people.select('name)
<console>:23: error: type mismatch;
 found   : Symbol
 required: org.apache.spark.sql.catalyst.expressions.Expression
       val teenagers = people.select('name)

It seems that I need an import not documented.

If I bulk importing everything

import org.apache.spark.sql.catalyst.analysis._
import org.apache.spark.sql.catalyst.dsl._
import org.apache.spark.sql.catalyst.errors._
import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.plans.logical._
import org.apache.spark.sql.catalyst.rules._ 
import org.apache.spark.sql.catalyst.types._
import org.apache.spark.sql.catalyst.util._
import org.apache.spark.sql.execution
import org.apache.spark.sql.hive._

EDIT: ... and

val sqlContext = new org.apache.spark.sql.SQLContext(sc)
import sqlContext._

it works.

like image 632
arivero Avatar asked Sep 09 '14 13:09

arivero


1 Answers

There is an implicit conversion you are lacking.

val sqlContext: org.apache.spark.sql.SQLContext = ???
import sqlContext._

That has however changed in the recent (and supported) versions of Spark.

like image 178
serejja Avatar answered Oct 06 '22 15:10

serejja