Skip to content

[Spark] Add Filters section for Java #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions source/batch-mode/batch-read.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ Filters

tabs:

- id: java-sync
content: |

.. include:: /java/filters.rst

- id: python
content: |

Expand Down
35 changes: 35 additions & 0 deletions source/java/filters.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.. include:: /includes/pushed-filters.rst

You can use :driver:`Java Aggregation Expressions
</java/sync/upcoming/fundamentals/aggregation-expression-operations/>` to filter
your data.

.. include:: /includes/example-load-dataframe.rst

First, create a DataFrame to connect to your default MongoDB data source:

.. code-block:: java

Dataset<Row> df = spark.read()
.format("mongodb")
.option("database", "food")
.option("collection", "fruit")
.load();

The following example retrieves only records in which the value of ``qty`` field
is greater than or equal to ``10``:

.. code-block:: java

df.filter(df.col("qty").gte(10))

The operation outputs the following:

.. code-block:: none

+---+----+------+
|_id| qty| type|
+---+----+------+
|2.0|10.0|orange|
|3.0|15.0|banana|
+---+----+------+
Comment on lines +22 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: convert into IO code block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, this formatting was odd to me too, but I'm matching the formatting of the other tabs and other example on this page. I think I'll open a separate PR to fix them all at one after this is merged. (There's like 10+ on this page and I don't want to clutter up this PR).

Loading