You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by Gefei Li <ge...@gmail.com> on 2014/08/14 10:23:10 UTC
how to use the method saveAsTextFile of a RDD like javaRDD
Hello,
I wrote a class named BooleanPair:
public static class BooleanPairet implements Serializable{
public Boolean elementBool1;
public Boolean elementBool2;
BooleanPair(Boolean bool1, Boolean bool2){elementBool1 = bool1;
elementBool2 = bool2;}
public String toString(){return new String("(" + elementBool1 + ","
+ elementBool2 + ")");}
}
And I create a RDD like this: javaRDD<BooleanPair[]>, a RDD of a
BooleanPair array, when I use the method saveAsTextFile, and it gives me
something like this"[Lmy.package.name.MyClassName$BooleanPair;@5b777a88",
while it goes well with a javaRDD<BooleanPair>, just a value instead of an
array.
What should I do to save it in a format like "(true, false), (false,
false)..."?
My Spark version is 1.0.0, and I use the CDH-5.1.0 distribution.
Thanks & Best Regards,
Gefei
Re: how to use the method saveAsTextFile of a RDD like javaRDD
Posted by Gefei Li <ge...@gmail.com>.
It is interesting to save a RDD on a disk or HDFS or somethings else as a
set of objects, but I think it's more useful to save it as a text file for
debugging or just as an output file. If we want to reuse a RDD, text file
also works, but perhaps a set of object files will bring a decrease on
executive time. I wonder how much time it can decrease compared with
transforming a text file to a RDD you want, need time to try :)
Re: how to use the method saveAsTextFile of a RDD like javaRDD
Posted by Hoai-Thu Vuong <th...@gmail.com>.
I've found a method saveAsObjectFile in RDD (or JavaRDD). I think we can
save this array to file and load back to object when read these file.
However, I've known the way to load back and cast RDD<generic object> to
specific object, need time to try.
On Thu, Aug 14, 2014 at 3:48 PM, Gefei Li <ge...@gmail.com> wrote:
> Thank you! It works so well for me!
>
> Regards,
> Gefei
>
>
> On Thu, Aug 14, 2014 at 4:25 PM, Tathagata Das <
> tathagata.das1565@gmail.com> wrote:
>
>> FlatMap the JavaRDD<BooleanPair[]> to JavaRDD<BooleanPair>. Then it
>> should work.
>>
>> TD
>>
>>
>> On Thu, Aug 14, 2014 at 1:23 AM, Gefei Li <ge...@gmail.com> wrote:
>>
>>> Hello,
>>> I wrote a class named BooleanPair:
>>>
>>> public static class BooleanPairet implements Serializable{
>>> public Boolean elementBool1;
>>> public Boolean elementBool2;
>>> BooleanPair(Boolean bool1, Boolean bool2){elementBool1 = bool1;
>>> elementBool2 = bool2;}
>>> public String toString(){return new String("(" + elementBool1 +
>>> "," + elementBool2 + ")");}
>>> }
>>>
>>> And I create a RDD like this: javaRDD<BooleanPair[]>, a RDD of a
>>> BooleanPair array, when I use the method saveAsTextFile, and it gives me
>>> something like this"[Lmy.package.name.MyClassName$BooleanPair;@5b777a88",
>>> while it goes well with a javaRDD<BooleanPair>, just a value instead of an
>>> array.
>>>
>>> What should I do to save it in a format like "(true, false), (false,
>>> false)..."?
>>>
>>> My Spark version is 1.0.0, and I use the CDH-5.1.0 distribution.
>>>
>>> Thanks & Best Regards,
>>> Gefei
>>>
>>
>>
>
--
Thu.
Re: how to use the method saveAsTextFile of a RDD like javaRDD
Posted by Gefei Li <ge...@gmail.com>.
Thank you! It works so well for me!
Regards,
Gefei
On Thu, Aug 14, 2014 at 4:25 PM, Tathagata Das <ta...@gmail.com>
wrote:
> FlatMap the JavaRDD<BooleanPair[]> to JavaRDD<BooleanPair>. Then it should
> work.
>
> TD
>
>
> On Thu, Aug 14, 2014 at 1:23 AM, Gefei Li <ge...@gmail.com> wrote:
>
>> Hello,
>> I wrote a class named BooleanPair:
>>
>> public static class BooleanPairet implements Serializable{
>> public Boolean elementBool1;
>> public Boolean elementBool2;
>> BooleanPair(Boolean bool1, Boolean bool2){elementBool1 = bool1;
>> elementBool2 = bool2;}
>> public String toString(){return new String("(" + elementBool1 +
>> "," + elementBool2 + ")");}
>> }
>>
>> And I create a RDD like this: javaRDD<BooleanPair[]>, a RDD of a
>> BooleanPair array, when I use the method saveAsTextFile, and it gives me
>> something like this"[Lmy.package.name.MyClassName$BooleanPair;@5b777a88",
>> while it goes well with a javaRDD<BooleanPair>, just a value instead of an
>> array.
>>
>> What should I do to save it in a format like "(true, false), (false,
>> false)..."?
>>
>> My Spark version is 1.0.0, and I use the CDH-5.1.0 distribution.
>>
>> Thanks & Best Regards,
>> Gefei
>>
>
>
Re: how to use the method saveAsTextFile of a RDD like javaRDD
Posted by Tathagata Das <ta...@gmail.com>.
FlatMap the JavaRDD<BooleanPair[]> to JavaRDD<BooleanPair>. Then it should
work.
TD
On Thu, Aug 14, 2014 at 1:23 AM, Gefei Li <ge...@gmail.com> wrote:
> Hello,
> I wrote a class named BooleanPair:
>
> public static class BooleanPairet implements Serializable{
> public Boolean elementBool1;
> public Boolean elementBool2;
> BooleanPair(Boolean bool1, Boolean bool2){elementBool1 = bool1;
> elementBool2 = bool2;}
> public String toString(){return new String("(" + elementBool1 +
> "," + elementBool2 + ")");}
> }
>
> And I create a RDD like this: javaRDD<BooleanPair[]>, a RDD of a
> BooleanPair array, when I use the method saveAsTextFile, and it gives me
> something like this"[Lmy.package.name.MyClassName$BooleanPair;@5b777a88",
> while it goes well with a javaRDD<BooleanPair>, just a value instead of an
> array.
>
> What should I do to save it in a format like "(true, false), (false,
> false)..."?
>
> My Spark version is 1.0.0, and I use the CDH-5.1.0 distribution.
>
> Thanks & Best Regards,
> Gefei
>