[jOOQ/jOOQ#12425] Removed ad-hoc tests
This commit is contained in:
parent
6ecb5b5cd8
commit
95153b184c
@ -2949,140 +2949,6 @@ public final class QOM {
|
||||
interface UEmptyStatement extends MStatement, UEmpty {}
|
||||
interface UEmptyQuery extends MQuery, UEmpty {}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: Tests
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("org.jooq.no-logo", "true");
|
||||
System.setProperty("org.jooq.no-tips", "true");
|
||||
|
||||
var t = new TableImpl<>(name("n"));
|
||||
var i = t.createField(name("i"), SQLDataType.INTEGER, "");
|
||||
var v1 = inline(1);
|
||||
var v2 = inline(2);
|
||||
var c = not(not(v1.eq(v2)).and(not(trueCondition())));
|
||||
|
||||
System.out.println("All parts");
|
||||
System.out.println(c.traverse("", (s, p) -> s + "\n" + p));
|
||||
|
||||
System.out.println();
|
||||
System.out.println("All parts: window function");
|
||||
System.out.println(sum(count(i).filterWhere(trueCondition())).filterWhere(trueCondition()).over(partitionBy(i).orderBy(i.desc()).groupsPreceding(3).excludeCurrentRow()).traverse("", (s, p) -> s + "\n" + p));
|
||||
|
||||
System.out.println();
|
||||
System.out.println("Nots");
|
||||
System.out.println(c.find(p -> p instanceof Not));
|
||||
|
||||
System.out.println();
|
||||
System.out.println("Params");
|
||||
System.out.println(c.find(p -> p instanceof MParam));
|
||||
|
||||
System.out.println();
|
||||
System.out.println("Optimised");
|
||||
System.out.println(c.replace(QOM::optimise));
|
||||
|
||||
System.out.println();
|
||||
System.out.println("Optimised: not(v1.isNotDistinctFrom(v2))");
|
||||
System.out.println(not(v1.isNotDistinctFrom(v2)).replace(QOM::optimise));
|
||||
|
||||
System.out.println();
|
||||
System.out.println("Optimised: not(v1.isDistinctFrom(v2))");
|
||||
System.out.println(not(v1.isDistinctFrom(v2)).replace(QOM::optimise));
|
||||
|
||||
System.out.println();
|
||||
System.out.println("Optimised: row(...)");
|
||||
System.out.println(row(field(c), field(not(c))).replace(QOM::optimise));
|
||||
|
||||
DSLContext ctx = DSL.using(POSTGRES);
|
||||
System.out.println();
|
||||
System.out.println("Correlated subquery to outer apply transformation");
|
||||
System.out.println(ctx.parser().parse("select b, (select a from t where t.x = u.y) a from u").replace(q -> {
|
||||
if (q instanceof MSelect) {
|
||||
MSelect<?> s = (MSelect<?>) q;
|
||||
MScalarSubquery<?> x = (MScalarSubquery<?>) s.$select().findAny(p -> p instanceof MScalarSubquery);
|
||||
|
||||
if (x != null) {
|
||||
Table<?> derivedTable = ((Select<?>) x.$arg1()).asTable("d", "c");
|
||||
|
||||
s = s.$select((MList<? extends MSelectFieldOrAsterisk>)
|
||||
s.$select().replace(y -> y == x ? derivedTable.field("c") : y)
|
||||
);
|
||||
s = s.$from((MList<? extends MTable<?>>)
|
||||
s.$from().replace(u -> u instanceof Table && ((Table<?>) u).getName().equals("u")
|
||||
? ((Table<?>) u).outerApply(derivedTable)
|
||||
: u)
|
||||
);
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
return q;
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
private static MQueryPart optimise(MQueryPart q) {
|
||||
if (q instanceof MEq<?> e) {
|
||||
if (e.$arg1() instanceof MParam<?> i1 && e.$arg2() instanceof MParam<?> i2)
|
||||
if (Objects.equals(i1.$value(), i2.$value()))
|
||||
return trueCondition();
|
||||
else
|
||||
return falseCondition();
|
||||
}
|
||||
else if (q instanceof MIsDistinctFrom<?> e) {
|
||||
if (e.$arg1() instanceof MParam<?> i1 && e.$arg2() instanceof MParam<?> i2)
|
||||
if (Objects.equals(i1.$value(), i2.$value()))
|
||||
return falseCondition();
|
||||
else
|
||||
return trueCondition();
|
||||
}
|
||||
else if (q instanceof MIsNotDistinctFrom<?> e) {
|
||||
if (e.$arg1() instanceof MParam<?> i1 && e.$arg2() instanceof MParam<?> i2)
|
||||
if (Objects.equals(i1.$value(), i2.$value()))
|
||||
return trueCondition();
|
||||
else
|
||||
return falseCondition();
|
||||
}
|
||||
else if (q instanceof MAnd a) {
|
||||
if (a.$arg1() instanceof MFalse || a.$arg2() instanceof MFalse)
|
||||
return falseCondition();
|
||||
else if (a.$arg1() instanceof MTrue && a.$arg2() instanceof MTrue)
|
||||
return trueCondition();
|
||||
else if (a.$arg1() instanceof MTrue)
|
||||
return a.$arg2();
|
||||
else if (a.$arg2() instanceof MTrue)
|
||||
return a.$arg1();
|
||||
}
|
||||
else if (q instanceof MOr o) {
|
||||
if (o.$arg1() instanceof MTrue || o.$arg2() instanceof MTrue)
|
||||
return trueCondition();
|
||||
else if (o.$arg1() instanceof MFalse || o.$arg2() instanceof MFalse)
|
||||
return falseCondition();
|
||||
}
|
||||
else if (q instanceof MNot n) {
|
||||
if (n.$arg1() instanceof MEq<?> e)
|
||||
return e.transform((arg1, arg2) -> ((Field) arg1).ne((Field) arg2));
|
||||
else if (n.$arg1() instanceof MNe<?> e)
|
||||
return e.transform((arg1, arg2) -> ((Field) arg1).eq((Field) arg2));
|
||||
else if (n.$arg1() instanceof MIsDistinctFrom<?> e)
|
||||
return e.transform((arg1, arg2) -> ((Field) arg1).isNotDistinctFrom((Field) arg2));
|
||||
else if (n.$arg1() instanceof MIsNotDistinctFrom<?> e)
|
||||
return e.transform((arg1, arg2) -> ((Field) arg1).isDistinctFrom((Field) arg2));
|
||||
else if (n.$arg1() instanceof MNot n2)
|
||||
return n2.$arg1();
|
||||
else if (n.$arg1() instanceof MTrue)
|
||||
return falseCondition();
|
||||
else if (n.$arg1() instanceof MFalse)
|
||||
return trueCondition();
|
||||
else if (n.$arg1() instanceof MOr a)
|
||||
return a.transform((arg1, arg2) -> ((Condition) arg1).not().and(((Condition) arg2).not()));
|
||||
}
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: Utilities
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user