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]?

Shaido
  • 27,497
  • 23
  • 70
  • 73
user1803467
  • 125
  • 2
  • 10
  • I have tried the method you mentioned in the link as "select(columnArray.head, columnArray.tail: _*)", it shows "Type mismatch, expected: ColumnRef, Actual: ColumnName". – user1803467 Jan 08 '18 at 09:11
  • 2
    Try this one instead: https://stackoverflow.com/questions/38778104/pass-columnnames-dynamically-to-cassandratable-select. Basically, try using `.select(columnArray.map(ColumnName(_)):_*)`. – Shaido Jan 08 '18 at 09:15
  • This works, thanks a lot. – user1803467 Jan 08 '18 at 09:23

0 Answers0