6363
6464import static org .apache .paimon .data .Timestamp .fromLocalDateTime ;
6565
66- public class PaimonPredicateConverter extends ScalarOperatorVisitor <Predicate , Void > {
66+ public class PaimonPredicateConverter extends ScalarOperatorVisitor <Predicate , PaimonPredicateContext > {
6767 private static final Logger LOG = LogManager .getLogger (PaimonPredicateConverter .class );
6868 private final PredicateBuilder builder ;
6969 private final List <String > fieldNames ;
@@ -83,35 +83,48 @@ public Predicate convert(ScalarOperator operator) {
8383 }
8484
8585 @ Override
86- public Predicate visit (ScalarOperator scalarOperator , Void context ) {
86+ public Predicate visit (ScalarOperator scalarOperator , PaimonPredicateContext context ) {
8787 return null ;
8888 }
8989
9090 @ Override
91- public Predicate visitCompoundPredicate (CompoundPredicateOperator operator , Void context ) {
91+ public Predicate visitCompoundPredicate (CompoundPredicateOperator operator , PaimonPredicateContext context ) {
9292 CompoundPredicateOperator .CompoundType op = operator .getCompoundType ();
9393 if (op == CompoundPredicateOperator .CompoundType .NOT ) {
9494 if (operator .getChild (0 ) instanceof LikePredicateOperator ) {
9595 return null ;
9696 }
97- Predicate expression = operator .getChild (0 ).accept (this , null );
98-
97+ PaimonPredicateContext paimonPredicateContext = new PaimonPredicateContext ();
98+ paimonPredicateContext .setParentPredicateOperator (operator );
99+ Predicate expression = operator .getChild (0 ).accept (this , paimonPredicateContext );
99100 if (expression != null ) {
100101 return expression .negate ().orElse (null );
101102 }
102103 } else {
103- Predicate left = operator .getChild (0 ).accept (this , null );
104- Predicate right = operator .getChild (1 ).accept (this , null );
104+ Predicate left = operator .getChild (0 ).accept (this , context );
105+ Predicate right = operator .getChild (1 ).accept (this , context );
106+ CompoundPredicateOperator parentPredicateOperator = null ;
107+ if (context != null && context .getParentPredicateOperator () != null ) {
108+ parentPredicateOperator = context .getParentPredicateOperator ();
109+ }
105110 if (left != null && right != null ) {
106111 return (op == CompoundPredicateOperator .CompoundType .OR ) ? PredicateBuilder .or (left , right ) :
107112 PredicateBuilder .and (left , right );
113+ } else if (parentPredicateOperator != null &&
114+ parentPredicateOperator .getCompoundType () == CompoundPredicateOperator .CompoundType .NOT ) {
115+ return null ;
116+ } else if (left != null && op == CompoundPredicateOperator .CompoundType .AND ) {
117+ //if op=and, return the predicates that are not null.
118+ return left ;
119+ } else if (right != null && op == CompoundPredicateOperator .CompoundType .AND ) {
120+ return right ;
108121 }
109122 }
110123 return null ;
111124 }
112125
113126 @ Override
114- public Predicate visitIsNullPredicate (IsNullPredicateOperator operator , Void context ) {
127+ public Predicate visitIsNullPredicate (IsNullPredicateOperator operator , PaimonPredicateContext context ) {
115128 String columnName = getColumnName (operator .getChild (0 ));
116129 if (columnName == null ) {
117130 return null ;
@@ -125,7 +138,7 @@ public Predicate visitIsNullPredicate(IsNullPredicateOperator operator, Void con
125138 }
126139
127140 @ Override
128- public Predicate visitBinaryPredicate (BinaryPredicateOperator operator , Void context ) {
141+ public Predicate visitBinaryPredicate (BinaryPredicateOperator operator , PaimonPredicateContext context ) {
129142 String columnName = getColumnName (operator .getChild (0 ));
130143 if (columnName == null ) {
131144 return null ;
@@ -157,7 +170,16 @@ public Predicate visitBinaryPredicate(BinaryPredicateOperator operator, Void con
157170 }
158171
159172 @ Override
173+ <<<<<<< HEAD
160174 public Predicate visitInPredicate (InPredicateOperator operator , Void context ) {
175+ =======
176+ public Predicate visitLargeInPredicate (LargeInPredicateOperator operator , PaimonPredicateContext context ) {
177+ throw new UnsupportedOperationException ("not support large in predicate in the PaimonPredicateConverter" );
178+ }
179+
180+ @ Override
181+ public Predicate visitInPredicate (InPredicateOperator operator , PaimonPredicateContext context ) {
182+ >>>>>>> 9313d 06 954 ([BugFix ] If the operator is AND , return the predicates that are not null for paimon (#66038 ))
161183 String columnName = getColumnName (operator .getChild (0 ));
162184 if (columnName == null ) {
163185 return null ;
@@ -184,7 +206,7 @@ public Predicate visitInPredicate(InPredicateOperator operator, Void context) {
184206 }
185207
186208 @ Override
187- public Predicate visitLikePredicateOperator (LikePredicateOperator operator , Void context ) {
209+ public Predicate visitLikePredicateOperator (LikePredicateOperator operator , PaimonPredicateContext context ) {
188210 String columnName = getColumnName (operator .getChild (0 ));
189211 if (columnName == null ) {
190212 return null ;
@@ -375,4 +397,4 @@ public String visitCastOperator(CastOperator operator, Void context) {
375397 return operator .getChild (0 ).accept (this , context );
376398 }
377399 }
378- }
400+ }
0 commit comments