Skip to content
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

It is complicated to filter a table's column on several conditions #2

Open
echebbi opened this issue Nov 12, 2017 · 1 comment
Open

Comments

@echebbi
Copy link
Owner

echebbi commented Nov 12, 2017

The Query DSL does not allow to express easily OR conditions.

For instance, in order to keep the rows where the value of the column "A" is either null or a string in lower case, we have to write :

Query
    .select()
    .from(table)
    .where("A").asStr().match(str -> str == null || str.equals(str.toLowerCase());

The built-in methods such as isInstanceOf,in or isTrue cannot be used anymore and must be re-written by the user.

It would be better to write something like :

Query
    .select()
    .from(table)
    .where("A").isNull().or().asStr().isInLowerCase();

or even :

Query
    .select()
    .from(table)
    .where("A").asStr().match(str -> str.isNull() || str.isInLowerCase());

instead.

Either way, the current DSL makes predicate composition difficult and should be adapted.

@echebbi
Copy link
Owner Author

echebbi commented Jan 9, 2018

With the upcoming type-safe features, this issue will soon be resolved. Indeed, the previous code can now be written as:

private static final ColumnId<String> A = id(String.class, "a");

table.filter(row ->
    row.get(A) == null 
 || row.get(A).equals(row.get(A).toLowerCase())
);

In my opinion, it is clear enough.

The Query API should also be enhanced to support the following syntax;

Query
    .select()
    .from(table)
    .where(A).isNull().or().isInLowerCase();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant