0

I read data from cassandra in a scala spark program with com.datastax.spark.connector like the follows:

val data = sc.cassandraTable("keyspace", "tablename").select("columnA", "columnB", ...)

The column names are defined in a Array[String] as:

val columnArray: Array[String] = Array("columnA", "columnB", ...)

There are too many columns in columnArray that I need to construct a parameter for select function with columnArray.

How to construct a ColumnRef type parameter for select with Array[String]?

3
  • I have tried the method you mentioned in the link as "select(columnArray.head, columnArray.tail: _*)", it shows "Type mismatch, expected: ColumnRef, Actual: ColumnName". Commented Jan 8, 2018 at 9:11
  • 2
    Try this one instead: stackoverflow.com/questions/38778104/…. Basically, try using .select(columnArray.map(ColumnName(_)):_*). Commented Jan 8, 2018 at 9:15
  • This works, thanks a lot. Commented Jan 8, 2018 at 9:23

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.