A Basic Programming Pattern: Filter First, Map Later

In recent days, I've seen a bit too much of this: someCollection .stream() .map(e -> someFunction(e)) .collect(Collectors.toList()) .subList(0, 2); Something is very wrong with the above example. Can you see it? No? Let me rename those variables for you. hugeCollection .stream() .map(e -> superExpensiveMapping(e)) .collect(Collectors.toList()) .subList(0, 2); Better now? Exactly. The above algorithm is O(N) … Continue reading A Basic Programming Pattern: Filter First, Map Later

ORMs Should Update “Changed” Values, Not Just “Modified” Ones

In this article, I will establish how the SQL language and its implementations distinguish between changed values and modified values, where a changed value is a value that has been "touched", but not necessarily modified, i.e. the value might be the same before and after the change. Many ORMs, unfortunately, either update all of a … Continue reading ORMs Should Update “Changed” Values, Not Just “Modified” Ones

jOOQ Tuesdays: Gerald Sangudi and Keshav Murthy Reveal the Secrets of N1QL (SQL on JSON)

Welcome to the jOOQ Tuesdays series. In this series, we’ll publish an article on the third Tuesday every other month where we interview someone we find exciting in our industry from a jOOQ perspective. This includes people who work with SQL, Java, Open Source, and a variety of other related topics. I'm very excited to … Continue reading jOOQ Tuesdays: Gerald Sangudi and Keshav Murthy Reveal the Secrets of N1QL (SQL on JSON)

Using Kotlin’s Apply Function for Dynamic SQL with jOOQ

It was hard to limit ourselves to 10 Nice Examples of Writing SQL in Kotlin With jOOQ, recently, because the Kotlin language has many nice little features that really help a lot when working with Java libraries. We've talked about the nice with() stdlib function, which allows to "import" a namespace for a local scope … Continue reading Using Kotlin’s Apply Function for Dynamic SQL with jOOQ

How to Use SQL INTERSECT to Work Around SQL’s NULL Logic

ANOTHER SQL Post this week? I got nerd-sniped: https://twitter.com/rafaelcodes/status/870574075244158980 Oooooh, challenge accepted! So, let's assume we have a table T with columns (A, B, C) like this: WITH t(a, b, c) AS ( SELECT 'a', 'b', null FROM dual UNION ALL SELECT 'a', null, 'c' FROM dual UNION ALL SELECT 'a', 'b', 'c' FROM dual … Continue reading How to Use SQL INTERSECT to Work Around SQL’s NULL Logic

How to Find Redundant Indexes in SQL

The following two indexes are redundant in most SQL databases: CREATE INDEX i_actor_1 ON actor (last_name); CREATE INDEX i_actor_2 ON actor (last_name, first_name); It is usually safe to drop the first index, because all queries that query the LAST_NAME column only can still profit from the second index I_ACTOR_2. The reason being that LAST_NAME is … Continue reading How to Find Redundant Indexes in SQL