1818package org .apache .ignite .internal .processors .query .calcite .planner ;
1919
2020import java .util .List ;
21+ import java .util .function .Predicate ;
22+
2123import org .apache .calcite .plan .RelOptUtil ;
22- import org .apache .calcite .rel .type . RelDataTypeFactory ;
24+ import org .apache .calcite .rel .RelNode ;
2325import org .apache .calcite .rex .RexFieldAccess ;
2426import org .apache .ignite .internal .processors .query .calcite .prepare .bounds .ExactBounds ;
2527import org .apache .ignite .internal .processors .query .calcite .prepare .bounds .SearchBounds ;
28+ import org .apache .ignite .internal .processors .query .calcite .rel .IgniteCorrelatedNestedLoopJoin ;
29+ import org .apache .ignite .internal .processors .query .calcite .rel .IgniteFilter ;
2630import org .apache .ignite .internal .processors .query .calcite .rel .IgniteIndexScan ;
2731import org .apache .ignite .internal .processors .query .calcite .rel .IgniteRel ;
2832import org .apache .ignite .internal .processors .query .calcite .schema .IgniteSchema ;
29- import org .apache .ignite .internal .processors .query .calcite .trait .IgniteDistribution ;
3033import org .apache .ignite .internal .processors .query .calcite .trait .IgniteDistributions ;
31- import org .apache .ignite .internal .processors .query .calcite .type .IgniteTypeFactory ;
32- import org .apache .ignite .internal .processors .query .calcite .type .IgniteTypeSystem ;
3334import org .junit .Test ;
3435
3536/**
@@ -42,39 +43,9 @@ public class CorrelatedNestedLoopJoinPlannerTest extends AbstractPlannerTest {
4243 */
4344 @ Test
4445 public void testValidIndexExpressions () throws Exception {
45- IgniteSchema publicSchema = new IgniteSchema ("PUBLIC" );
46- IgniteTypeFactory f = new IgniteTypeFactory (IgniteTypeSystem .INSTANCE );
47-
48- publicSchema .addTable (
49- "T0" ,
50- new TestTable (
51- new RelDataTypeFactory .Builder (f )
52- .add ("ID" , f .createJavaType (Integer .class ))
53- .add ("JID" , f .createJavaType (Integer .class ))
54- .add ("VAL" , f .createJavaType (String .class ))
55- .build ()) {
56-
57- @ Override public IgniteDistribution distribution () {
58- return IgniteDistributions .broadcast ();
59- }
60- }
61- );
62-
63- publicSchema .addTable (
64- "T1" ,
65- new TestTable (
66- new RelDataTypeFactory .Builder (f )
67- .add ("ID" , f .createJavaType (Integer .class ))
68- .add ("JID" , f .createJavaType (Integer .class ))
69- .add ("VAL" , f .createJavaType (String .class ))
70- .build ()) {
71-
72- @ Override public IgniteDistribution distribution () {
73- return IgniteDistributions .broadcast ();
74- }
75- }
76- .addIndex ("t1_jid_idx" , 1 , 0 )
77- );
46+ IgniteSchema publicSchema = createSchema (
47+ testTable ("T0" ),
48+ testTable ("T1" ).addIndex ("t1_jid_idx" , 1 , 0 ));
7849
7950 String sql = "select * " +
8051 "from t0 " +
@@ -111,40 +82,9 @@ public void testValidIndexExpressions() throws Exception {
11182 */
11283 @ Test
11384 public void testInvalidIndexExpressions () throws Exception {
114- IgniteSchema publicSchema = new IgniteSchema ("PUBLIC" );
115- IgniteTypeFactory f = new IgniteTypeFactory (IgniteTypeSystem .INSTANCE );
116-
117- publicSchema .addTable (
118- "T0" ,
119- new TestTable (
120- new RelDataTypeFactory .Builder (f )
121- .add ("ID" , f .createJavaType (Integer .class ))
122- .add ("JID" , f .createJavaType (Integer .class ))
123- .add ("VAL" , f .createJavaType (String .class ))
124- .build ()) {
125-
126- @ Override public IgniteDistribution distribution () {
127- return IgniteDistributions .broadcast ();
128- }
129- }
130- .addIndex ("t0_jid_idx" , 1 , 0 )
131- );
132-
133- publicSchema .addTable (
134- "T1" ,
135- new TestTable (
136- new RelDataTypeFactory .Builder (f )
137- .add ("ID" , f .createJavaType (Integer .class ))
138- .add ("JID" , f .createJavaType (Integer .class ))
139- .add ("VAL" , f .createJavaType (String .class ))
140- .build ()) {
141-
142- @ Override public IgniteDistribution distribution () {
143- return IgniteDistributions .broadcast ();
144- }
145- }
146- .addIndex ("t1_jid_idx" , 1 , 0 )
147- );
85+ IgniteSchema publicSchema = createSchema (
86+ testTable ("T0" ).addIndex ("t0_jid_idx" , 1 , 0 ),
87+ testTable ("T1" ).addIndex ("t1_jid_idx" , 1 , 0 ));
14888
14989 String sql = "select * " +
15090 "from t0 " +
@@ -160,4 +100,28 @@ public void testInvalidIndexExpressions() throws Exception {
160100
161101 checkSplitAndSerialization (phys , publicSchema );
162102 }
103+
104+ /** */
105+ @ Test
106+ public void testFilterPushDown () throws Exception {
107+ IgniteSchema publicSchema = createSchema (
108+ testTable ("T0" ),
109+ testTable ("T1" ));
110+
111+ String sql = "select * " +
112+ "from t0 " +
113+ "where t0.val > 'value' and exists (select * from t1 where t0.jid = t1.jid);" ;
114+
115+ Predicate <RelNode > check =
116+ hasChildThat (isInstanceOf (IgniteCorrelatedNestedLoopJoin .class )
117+ .and (input (0 , isTableScan ("T0" ).and (n -> n .condition () != null ))))
118+ .and (hasChildThat (isInstanceOf (IgniteFilter .class )).negate ());
119+
120+ assertPlan (sql , publicSchema , check );
121+ }
122+
123+ /** */
124+ private TestTable testTable (String name ) {
125+ return createTable (name , IgniteDistributions .broadcast (), "ID" , Integer .class , "JID" , Integer .class , "VAL" , String .class );
126+ }
163127}
0 commit comments