2929import org .apache .wayang .api .sql .calcite .converter .WayangFilterVisitor ;
3030import org .apache .wayang .basic .data .Record ;
3131
32- public class FilterEvaluateCondition extends RexVisitorImpl <Boolean > {
32+ public class FilterEvaluateCondition extends RexVisitorImpl <Boolean > {
3333 final Record record ;
3434
3535 protected FilterEvaluateCondition (final boolean deep , final Record record ) {
36- super (deep );
37- this .record = record ;
38- }
36+ super (deep );
37+ this .record = record ;
38+ }
3939
4040 @ Override
4141 public Boolean visitCall (final RexCall call ) {
@@ -64,7 +64,6 @@ public Boolean visitCall(final RexCall call) {
6464
6565 public boolean eval (final Record record , final SqlKind kind , final RexNode leftOperand ,
6666 final RexNode rightOperand ) {
67-
6867 if (leftOperand instanceof RexInputRef && rightOperand instanceof RexLiteral ) {
6968 final RexInputRef rexInputRef = (RexInputRef ) leftOperand ;
7069 final int index = rexInputRef .getIndex ();
@@ -85,13 +84,25 @@ public boolean eval(final Record record, final SqlKind kind, final RexNode leftO
8584 case LESS_THAN_OR_EQUAL :
8685 return isLessThan (field , rexLiteral ) || isEqualTo (field , rexLiteral );
8786 default :
88- throw new IllegalStateException ("Predicate not supported yet" );
87+ throw new IllegalStateException ("Predicate not supported yet: " + kind );
8988 }
89+ } else if (leftOperand instanceof RexInputRef && rightOperand instanceof RexInputRef ) {
90+ final RexInputRef leftRexInputRef = (RexInputRef ) leftOperand ;
91+ final int leftIndex = leftRexInputRef .getIndex ();
92+ final RexInputRef righRexInputRef = (RexInputRef ) rightOperand ;
93+ final int rightIndex = righRexInputRef .getIndex ();
9094
95+ switch (kind ) {
96+ case EQUALS :
97+ return isEqualTo (record .getField (leftIndex ), record .getField (rightIndex ));
98+ default :
99+ throw new IllegalStateException ("Predicate not supported yet, kind: " + kind + " left field: "
100+ + record .getField (leftIndex ) + " right field: " + record .getField (rightIndex ));
101+ }
91102 } else {
92- throw new IllegalStateException ("Predicate not supported yet" );
103+ throw new IllegalStateException ("Predicate not supported with types yet, predicate: " + kind + ", type1: "
104+ + leftOperand .getClass () + ", type2: " + rightOperand .getClass ());
93105 }
94-
95106 }
96107
97108 private boolean isGreaterThan (final Object o , final RexLiteral rexLiteral ) {
@@ -111,4 +122,14 @@ private boolean isEqualTo(final Object o, final RexLiteral rexLiteral) {
111122 throw new IllegalStateException ("Predicate not supported yet" );
112123 }
113124 }
125+
126+ private boolean isEqualTo (final Object o1 , final Object o2 ) {
127+ System .out .println ("comparing: " + o1 + " with " + o2 );
128+ System .out .println ("true: " + ((Comparable ) o1 ).compareTo (o2 ));
129+ try {
130+ return ((Comparable ) o1 ).compareTo (o2 ) == 0 ;
131+ } catch (final Exception e ) {
132+ throw new IllegalStateException ("Predicate not supported yet" );
133+ }
134+ }
114135}
0 commit comments