SQLxD Part 7 — WHERE with simple predicates

This is the seventh part of the SQLxD series. For your convenience you can find other parts in the table of contents in Part 1 – XML Transformation

Last time we saw how to handle FROM clause. Today we are going to implement filtering logic for handling WHERE.

We start with the clause logic:

As we can see, we simply iterate over rows, execute predicate and keep or remove row. That’s all, the most important stuff is hidden in IPredicate.

Predicate interface is very short:

Now come implementations. We start with abstract class for comparing predicates (e.g., less or equal predicate):

We can see that predicate works on expressions. What is that? Well, we need to be able to extract value from row or create constant. For this we have these expressions:

Having this code we can easily implement multiple predicates:

Of course we can do it other way, e.g., like this:

Last but not least we implement IS NULL predicate: