-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Use pattern matching for instanceof in iceberg connector #15488
Use pattern matching for instanceof in iceberg connector #15488
Conversation
Do address also:
|
99a5ab6
to
a115789
Compare
1a50cbd
to
db023e7
Compare
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergPageSourceProvider.java
Outdated
Show resolved
Hide resolved
4a67cb1
to
1835cde
Compare
1835cde
to
572015a
Compare
CI hit #15293 |
Description
Use pattern matching for
instanceof
in iceberg connectorPattern matching for
instanceof
introduced in Java 16 (https://openjdk.org/jeps/394)Motivation (copied from https://openjdk.org/jeps/394)
Nearly every program includes some sort of logic that combines testing if an expression has a certain type or structure, and then conditionally extracting components of its state for further processing. For example, all Java programmers are familiar with the instanceof-and-cast idiom:
There are three things going on here: a test (is obj a String?), a conversion (casting obj to String), and the declaration of a new local variable (s) so that we can use the string value. This pattern is straightforward and understood by all Java programmers, but is suboptimal for several reasons. It is tedious; doing both the type test and cast should be unnecessary (what else would you do after an instanceof test?). This boilerplate — in particular, the three occurrences of the type String — obfuscates the more significant logic that follows. But most importantly, the repetition provides opportunities for errors to creep unnoticed into programs.
Rather than reach for ad-hoc solutions, we believe it is time for Java to embrace pattern matching. Pattern matching allows the desired "shape" of an object to be expressed concisely (the pattern), and for various statements and expressions to test that "shape" against their input (the matching). Many languages, from Haskell to C#, have embraced pattern matching for its brevity and safety.
Additional context and related issues
NA
Release notes
(X) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text: