# Partition

Separates elements in a collection into multiple output collections. The partitioning function contains the logic that determines how to separate the elements of the input collection into each resulting partition output collection.

The number of partitions must be determined at graph construction time. You cannot determine the number of partitions in mid-pipeline.

## Examples

Example: dividing a `PCollection` into percentile groups

``````// Provide an int value with the desired number of result partitions, and a PartitionFn that represents the
// partitioning function. In this example, we define the PartitionFn in-line. Returns a PCollectionList
// containing each of the resulting partitions as individual PCollection objects.
PCollection<Student> students = ...;
// Split students up into 10 partitions, by percentile:
PCollectionList<Student> studentsByPercentile =
students.apply(Partition.of(10, new PartitionFn<Student>() {
public int partitionFor(Student student, int numPartitions) {
return student.getPercentile()  // 0..99
* numPartitions / 100;
}}));

// You can extract each partition from the PCollectionList using the get method, as follows:
PCollection<Student> fortiethPercentile = studentsByPercentile.get(4);
``````
• Filter is useful if the function is just deciding whether to output an element or not.
• ParDo is the most general element-wise mapping operation, and includes other abilities such as multiple output collections and side-inputs.
• CoGroupByKey performs a per-key equijoin.
{"ft_lang_label":"__label__en","ft_lang_prob":0.74351174,"math_prob":0.85804707,"size":1576,"snap":"2019-51-2020-05","text_gpt3_token_len":316,"char_repetition_ratio":0.1908397,"word_repetition_ratio":0.0,"special_character_ratio":0.1928934,"punctuation_ratio":0.13821138,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9617853,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-01-28T22:54:40Z\",\"WARC-Record-ID\":\"<urn:uuid:35cea9f2-f3fb-4a82-bb75-22d6f6546b40>\",\"Content-Length\":\"34372\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:9038b24e-9859-4b02-9f3f-029e957f77fa>\",\"WARC-Concurrent-To\":\"<urn:uuid:31fbe0c6-b64e-49a7-9a7c-bc0aa5339034>\",\"WARC-IP-Address\":\"40.79.78.1\",\"WARC-Target-URI\":\"https://beam.apache.org/documentation/transforms/java/elementwise/partition/\",\"WARC-Payload-Digest\":\"sha1:7LZ73VGDHC3DMEPMEZXP3JYRDXGLB7FG\",\"WARC-Block-Digest\":\"sha1:Y5ZR76PSB54XHGNJ2NWU6DUY5UOXQ4RN\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-05/CC-MAIN-2020-05_segments_1579251783342.96_warc_CC-MAIN-20200128215526-20200129005526-00218.warc.gz\"}"}