Thursday 2 May 2024

Stream.sorted() - For unordered streams, no stability guarantees are made.

So I was writing code, and I had to sort a stream, because originally I had a Set, and everyone knows Sets are unordered by default.

But my eye fell on the javadoc on .sorted(). To be more specific:

For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.

And the sentence kind of made me nervous.

Example

An example of an unstable sort is visible in the unit test below. The unit test will sometimes pass and sometimes fail.

The reason for this is that Ken Thompson and Simon Thompson are equivalent in the sorting and, as it is an unsorted stream to begin with, its order can change between program runs.

Something to keep in mind.

References

Oracle Javadoc - Stream (Java SE 21 & JDK 21)
https://docs.oracle.com/en%2Fjava%2Fjavase%2F21%2Fdocs%2Fapi%2F%2F/java.base/java/util/stream/Stream.html#sorted()

Friday 23 February 2024

Migrating Oracle to PostgreSQL

So at work we're currently trying to see if we can move away from Oracle and onto PostgreSQL.

I expect this to be a long process.

This blog post is here to document some of the issues we ran into and also remember references I found.

Migrating schema and data

There are several tools that can migrate the schema and the data from Oracle to Postgres.

There are some differences in what both database support. See reference [1].

Make changes to SQL Scripts

References

[1] Hackermoon - How to Migrate from Oracle to PostgreSQL
https://hackernoon.com/how-to-migrate-from-oracle-to-postgresql
Postgres Wiki - Oracle to Postgres Conversion
https://wiki.postgresql.org/wiki/Oracle_to_Postgres_Conversion
PostgreSQL Manuals
https://www.postgresql.org/docs/
Ora2Pg - Moves Oracle and MySQL database to PostgreSQL
https://ora2pg.darold.net/
Life in USA - install ora2pg on mac osx
https://vcfvct.wordpress.com/2016/10/18/install-ora2pg-on-mac-osx/