public Options getOptions() { if (this.globalState.options == null) { this.globalState.options = new Options(); } return this.globalState.options; }
@Override public Options getOptions() { if (options == null) { options = new Options(); } return options; }
public Options getOptions() { if (this.globalState.options == null) { this.globalState.options = new Options(); } return this.globalState.options; }
public Options getOptions() { if (this.globalState.options == null) { this.globalState.options = new Options(); } return this.globalState.options; }
@Override public Options getOptions() { if (options == null) { options = new Options(); } return options; }
@Override public Options getOptions() { if (options == null) { options = new Options(); } return options; }
@Test public void testSubqueryRewriteToJoinWithAggregate() throws Exception { CommandContext cc = new CommandContext(); cc.setOptions(new Options().subqueryUnnestDefault(true)); TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where pm3.g1.e2 < (select max(e2) FROM pm1.g1 where pm3.g1.e1 = e1)", "SELECT e1 FROM pm3.g1, (SELECT MAX(e2) AS expr1, e1 FROM pm1.g1 GROUP BY e1) AS X__1 WHERE (pm3.g1.e2 < X__1.expr1) AND (pm3.g1.e1 = X__1.e1)", RealMetadataFactory.example4(), cc); }
@Test public void testSubqueryRewriteToJoinWithGroupingExpression() throws Exception { CommandContext cc = new CommandContext(); cc.setOptions(new Options().subqueryUnnestDefault(true)); TestQueryRewriter.helpTestRewriteCommand("Select distinct e1 from pm3.g1 where exists (select 1 FROM pm1.g1 group by e4 || 'x' HAVING min(e3) || (e4 || 'x') = pm3.g1.e3)", "SELECT DISTINCT e1 FROM pm3.g1, (SELECT MIN(e3) AS expr1, concat(convert(e4, string), 'x') AS expr2, concat(convert(MIN(e3), string), concat(convert(e4, string), 'x')) AS expr FROM pm1.g1 GROUP BY concat(convert(e4, string), 'x')) AS X__1 WHERE convert(pm3.g1.e3, string) = X__1.expr", RealMetadataFactory.example4(), cc); }
@Test public void testSubqueryExpressionJoin() throws Exception { CommandContext cc = new CommandContext(); cc.setOptions(new Options().subqueryUnnestDefault(true)); TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where pm3.g1.e2 < (Select max(e2) from pm2.g2 where e1 = pm3.g1.e1 having convert(min(e2), string) > pm3.g1.e1)", "SELECT e1 FROM pm3.g1, (SELECT MAX(e2) AS expr1, e1, MIN(e2) AS expr3 FROM pm2.g2 GROUP BY e1) AS X__1 WHERE (convert(X__1.expr3, string) > pm3.g1.e1) AND (pm3.g1.e2 < X__1.expr1) AND (pm3.g1.e1 = X__1.e1)", RealMetadataFactory.example4(), cc); }
/** * Agg does not depend on cardinality */ @Test public void testSubqueryRewriteToJoinGroupBy() throws Exception { CommandContext cc = new CommandContext(); cc.setOptions(new Options().subqueryUnnestDefault(true)); TestQueryRewriter.helpTestRewriteCommand("Select max(e1) from pm1.g1 as x where exists (select pm1.g1.e1 FROM pm1.g1 where e1 = x.e1) group by e2", "SELECT MAX(e1) FROM pm1.g1 AS x, (SELECT e1 FROM pm1.g1) AS X__1 WHERE x.e1 = X__1.e1 GROUP BY e2", RealMetadataFactory.example1Cached(), cc); }
@Test public void testSubqueryDoNotRewriteToJoin() throws Exception { CommandContext cc = new CommandContext(); cc.setOptions(new Options().subqueryUnnestDefault(true)); TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where not exists (select pm1.g1.e1 FROM pm1.g1 where e1 = pm3.g1.e1)", "SELECT e1 FROM pm3.g1 WHERE NOT EXISTS (SELECT pm1.g1.e1 FROM pm1.g1 WHERE e1 = pm3.g1.e1 LIMIT 1)", RealMetadataFactory.example4(), cc); }
@Test public void testSubqueryRewriteToJoinDistinct1() throws Exception { CommandContext cc = new CommandContext(); cc.setOptions(new Options().subqueryUnnestDefault(true)); TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm1.g1 as x where exists (select pm1.g1.e1 FROM pm1.g1 where e1 = x.e1 and e2 < x.e2)", "SELECT e1 FROM pm1.g1 AS x WHERE EXISTS (SELECT pm1.g1.e1 FROM pm1.g1 WHERE (e1 = x.e1) AND (e2 < x.e2) LIMIT 1)", RealMetadataFactory.example1Cached(), cc); }
@Test public void testDontRewriteToJoinWithOtherCriteria() throws Exception { CommandContext cc = new CommandContext(); cc.setOptions(new Options().subqueryUnnestDefault(true)); TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where pm3.g1.e1 in /*+ NO_UNNEST */ (select pm1.g1.e1 FROM pm1.g1 where e2 < pm3.g1.e2)", "SELECT e1 FROM pm3.g1 WHERE pm3.g1.e1 IN /*+ NO_UNNEST */ (SELECT pm1.g1.e1 FROM pm1.g1 WHERE e2 < pm3.g1.e2)", RealMetadataFactory.example4(), cc); }
@Test public void testSubqueryRewriteToJoinExistsNoKey() throws Exception { CommandContext cc = new CommandContext(); cc.setOptions(new Options().subqueryUnnestDefault(true)); TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm1.g1 x where exists (select 1 FROM pm1.g2 where pm1.g2.e1 = x.e1)", "SELECT e1 FROM pm1.g1 AS x, (SELECT DISTINCT pm1.g2.e1 FROM pm1.g2) AS X__1 WHERE x.e1 = X__1.e1", RealMetadataFactory.example4(), cc); }
@Test public void testSubqueryDoNotRewriteToJoin2() throws Exception { CommandContext cc = new CommandContext(); cc.setOptions(new Options().subqueryUnnestDefault(true)); TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where e2 < some (select pm1.g1.e2 FROM pm1.g1)", "SELECT e1 FROM pm3.g1 WHERE e2 < (SELECT MAX(X.e2) FROM (SELECT pm1.g1.e2 FROM pm1.g1) AS X)", RealMetadataFactory.example4(), cc); }
@Test public void testSubqueryRewriteToJoin() throws Exception { CommandContext cc = new CommandContext(); cc.setOptions(new Options().subqueryUnnestDefault(true)); TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where exists (select pm1.g1.e1 FROM pm1.g1 where e1 = pm3.g1.e1)", "SELECT e1 FROM pm3.g1, (SELECT e1 FROM pm1.g1) AS X__1 WHERE pm3.g1.e1 = X__1.e1", RealMetadataFactory.example4(), cc); }
@Test public void testSubqueryRewriteToJoinWithAggregate2() throws Exception { CommandContext cc = new CommandContext(); cc.setOptions(new Options().subqueryUnnestDefault(true)); TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where pm3.g1.e2 < (select max(e2) FROM pm1.g1 WHERE pm3.g1.e1 = e1 HAVING min(e3) < pm3.g1.e3)", "SELECT e1 FROM pm3.g1, (SELECT MAX(e2) AS expr1, e1, MIN(e3) AS expr3 FROM pm1.g1 GROUP BY e1) AS X__1 WHERE (X__1.expr3 < pm3.g1.e3) AND (pm3.g1.e2 < X__1.expr1) AND (pm3.g1.e1 = X__1.e1)", RealMetadataFactory.example4(), cc); }
@Test public void testSubqueryRewriteToJoinDistinct() throws Exception { CommandContext cc = new CommandContext(); cc.setOptions(new Options().subqueryUnnestDefault(true)); TestQueryRewriter.helpTestRewriteCommand("Select distinct e1 from pm1.g1 as x where exists (select pm1.g1.e1 FROM pm1.g1 where e1 = x.e1)", "SELECT DISTINCT e1 FROM pm1.g1 AS x, (SELECT e1 FROM pm1.g1) AS X__1 WHERE x.e1 = X__1.e1", RealMetadataFactory.example1Cached(), cc); }
@Test public void testTracingEnabled() { TeiidTracingUtil ttu = new TeiidTracingUtil(); MockTracer tracer = new MockTracer(); ttu.setTracer(tracer); assertFalse(ttu.isTracingEnabled(new Options().tracingWithActiveSpanOnly(true), null)); }
@Test public void testSubqueryDoNotRewriteToJoin3() throws Exception { CommandContext cc = new CommandContext(); cc.setOptions(new Options().subqueryUnnestDefault(true)); TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where e2 < some (select pm1.g1.e2 FROM pm1.g1 where pm3.g1.e3 <> e3)", "SELECT e1 FROM pm3.g1 WHERE e2 < SOME (SELECT MAX(pm1.g1.e2) FROM pm1.g1 WHERE e3 <> pm3.g1.e3)", RealMetadataFactory.example4(), cc); //should rewrite as we have an equi join predicate TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where e2 < some (select pm1.g1.e2 FROM pm1.g1 where pm3.g1.e3 = e3)", "SELECT e1 FROM pm3.g1, (SELECT MAX(pm1.g1.e2) AS expr1, e3 FROM pm1.g1 GROUP BY e3) AS X__1 WHERE (e2 < X__1.expr1) AND (pm3.g1.e3 = X__1.e3)", RealMetadataFactory.example4(), cc); }