The trick here is getting the scala compiler to do the implicit conversion
from Symbol -> Column.  In your second example, the compiler doesn't know
that you are going to try and use the Seq[Symbol] as a Seq[Column] and so
doesn't do the conversion.  The following are other ways to provide enough
info to make sure it happens:

// Explicitly create columns
val columnList = Seq($"field1", $"field2")

// Explicitly type the Seq
val columnList: Seq[Column] = Seq('field1, 'field2)


On Thu, Feb 19, 2015 at 12:09 PM, Cesar Flores <ces...@gmail.com> wrote:

> Well:
>
> I think that I solved my issue in the next way:
>
>
> val variable_fieldsStr = List("field1","field2")
> val variable_argument_list= variable_fieldsStr.map(f => Alias(Symbol(f),
> f)())
>
> val schm2 = myschemaRDD.select(variable_argument_list:_*)
>
>
> schm2 seems to have the required fields, but would like to hear the
> opinion of an expert about it.
>
>
>
> Thanks
>
> On Thu, Feb 19, 2015 at 12:01 PM, Cesar Flores <ces...@gmail.com> wrote:
>
>>
>> I am trying to pass a variable number of arguments to the select function
>> of a SchemaRDD I created, as I want to select the fields in run time:
>>
>>
>> val variable_argument_list = List('field1,'field2')
>>
>> val schm1 = myschemaRDD.select('field1,'field2) // works
>> val schm2 = myschemaRDD.select(variable_argument_list:_*) // do not work
>>
>>
>> I am interested in selecting in run time the fields
>> from myschemaRDD variable. However, the usual way of passing variable
>> number of arguments as a List in Scala fails.
>>
>> Is there a way of selecting a variable number of arguments in the select
>> function? If not, what will be a better approach for selecting the required
>> fields in run time?
>>
>>
>>
>> Thanks in advance for your help
>> --
>> Cesar Flores
>>
>
>
>
> --
> Cesar Flores
>

Reply via email to