You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by "Reuven Lax (JIRA)" <ji...@apache.org> on 2017/09/13 03:01:13 UTC

[jira] [Commented] (BEAM-2952) How to use KV.OrderByKey

    [ https://issues.apache.org/jira/browse/BEAM-2952?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16164081#comment-16164081 ] 

Reuven Lax commented on BEAM-2952:
----------------------------------

I'm not sure how you want to use it. A PCollection is not ordered, so you cannot use it there. You can use it in tests to sort the output of a test pipeline for comparison; in that case you would use it like you would use any other Java Comparable.

> How to use KV.OrderByKey
> ------------------------
>
>                 Key: BEAM-2952
>                 URL: https://issues.apache.org/jira/browse/BEAM-2952
>             Project: Beam
>          Issue Type: New Feature
>          Components: examples-java
>            Reporter: Rick Lin
>            Assignee: Reuven Lax
>             Fix For: 2.1.0
>
>
> Hi all,
> I  have a question how to use the beam java sdk: KV.OrderByKey
> My java code is as:
> int[] key=new int[] {2,1,3,4,5};
> double[] value=new double[] {1.0,1.0,1.0,1.0,1.0};
> List<KV<Integer, Double>> KVlist = new ArrayList<>();
> List<KV<Integer, Double>> KVtest = new ArrayList<>();
> int n=value.length;
> for (int i=0; i<n; i++){			
>   KVlist.add(KV.of(i, value[i]));
>   System.out.println(KVlist.get(i));
> 	}
> PipelineOptions options = PipelineOptionsFactory.create();		
> Pipeline p = Pipeline.create(options);		
> PCollection<KV<Integer, Double>> t1=p.apply("create data",Create.of(KVlist));
> p.run;
> Thanks
> Rick



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)