Apache Beam: Filter
Use Apache Beam's built-in Filter Transform to Simplify your Pipelines
Search for a command to run...
Use Apache Beam's built-in Filter Transform to Simplify your Pipelines
No comments yet. Be the first to comment.
Dive into the world of scalable data processing with our comprehensive series on Apache Beam and Google Cloud Dataflow.
Use Built-in Apache Beam functions to simplify your pipelines
Everything you need to ingest, store, and analyze billions of IPv4 & IPv6 addresses at interactive speed. Why a native IP data type? Storing every address as a plain string inflates segment size, hurts bitmap selectivity, and forces costly runtime ...
Apache Druid is a high-performance, real-time analytics database designed for large-scale data processing. Among its powerful features is the ability to handle geospatial data, enabling fast and efficient queries over latitude and longitude coordinat...
In today's DevOps landscape, automating tasks and deployments is essential for efficiency and reliability. One powerful way to achieve this is by leveraging GitHub Actions to connect with Google Cloud Platform (GCP) using the gcloud CLI. In this post...
Overview Why would you want to run a scheduled Bash script in the cloud? Couldn’t you just run cron on your local machine? Running a bash script in the cloud rather than on a local machine offers developers a multitude of advantages that can enhance ...
What is Streaming Engine "By default, the Dataflow pipeline runner executes the steps of your streaming pipeline entirely on worker virtual machines, consuming worker CPU, memory, and Persistent Disk storage. Dataflow's Streaming Engine moves pipelin...
Have you ever wanted to filter data from a PCollection?
With the Filter transform, you can!
Given a function that takes an input element and returns True or False, the Filter transform will only allow elements that return True to proceed through the pipeline and to the next transform. Also, if the elements of the input PCollection are Java Objects that are Comparable, you can use built-in Filters which will filter out elements based on the elements' natural ordering (see below for examples).
You should use the Filter transform whenever you need to clean a PCollection based on certain criteria.
Using this transform is quite easy. All you need is a function which returns a boolean (which includes lambda functions) for whether you want to keep the input element (True) or discard the element (False). It will then allow all elements which returned True to go to the next transform in the pipeline.
PCollection<String> allStrings = Create.of("Hello", "world", "hi");
PCollection<String> longStrings = allStrings
.apply(Filter.by(new SerializableFunction<String, Boolean>() {
@Override
public Boolean apply(String input) {
return input.length() > 3;
}
}));
PCollection<Long> numbers = Create.of(2L, 3L, 4L, 5L);
PCollection<Long> bigNumbers = numbers.apply(Filter.greaterThan(3));
PCollection<Long> smallNumbers = numbers.apply(Filter.lessThanEq(3));
PCollection<Long> numbers = Create.of(2L, 3L, 4L, 5L);
PCollection<Long> bigNumbers = numbers.apply(Filter.by(number -> number > 3));
Instead of writing a custom Do Function to filter elements in a PCollection, you should use the Filter Transform.
Check out other useful transforms from the official Apache Beam documentation.