@@ -139,20 +139,72 @@ public virtual with sharing class Interpreter implements Visitor {
139139 return ((Decimal )left ).pow (Integer .valueOf (right ));
140140 }
141141 when GREATER {
142- checkNumberOperand (binary .operator , left , right );
143- return (Decimal )left > (Decimal )right ;
142+ // Check for numbers
143+ if (left instanceof Decimal && right instanceof Decimal ) {
144+ return (Decimal )left > (Decimal )right ;
145+ }
146+
147+ if (left instanceof Date && right instanceof Date ) {
148+ return (Date )left > (Date )right ;
149+ }
150+
151+ if (left instanceof Datetime && right instanceof Datetime ) {
152+ return (Datetime )left > (Datetime )right ;
153+ }
154+
155+ throw new Exceptions .RuntimeException (
156+ binary .operator ,
157+ ' Error executing ' + binary .operator .lexeme + ' operator: operands must be numbers, dates, or datetimes.'
158+ );
144159 }
145160 when GREATER_EQUAL {
146- checkNumberOperand (binary .operator , left , right );
147- return (Decimal )left >= (Decimal )right ;
161+ if (left instanceof Decimal && right instanceof Decimal ) {
162+ return (Decimal )left >= (Decimal )right ;
163+ }
164+
165+ if (left instanceof Date && right instanceof Date ) {
166+ return (Date )left >= (Date )right ;
167+ }
168+
169+ if (left instanceof Datetime && right instanceof Datetime ) {
170+ return (Datetime )left >= (Datetime )right ;
171+ }
172+
173+ throw new Exceptions .RuntimeException (
174+ binary .operator ,
175+ ' Error executing ' + binary .operator .lexeme + ' operator: operands must be numbers, dates, or datetimes.'
176+ );
148177 }
149178 when LESS {
150- checkNumberOperand (binary .operator , left , right );
151- return (Decimal )left < (Decimal )right ;
179+ if (left instanceof Decimal && right instanceof Decimal ) {
180+ return (Decimal )left < (Decimal )right ;
181+ }
182+
183+ if (left instanceof Date && right instanceof Date ) {
184+ return (Date )left < (Date )right ;
185+ }
186+
187+ if (left instanceof Datetime && right instanceof Datetime ) {
188+ return (Datetime )left < (Datetime )right ;
189+ }
190+
191+ throw new Exceptions .RuntimeException (
192+ binary .operator ,
193+ ' Error executing ' + binary .operator .lexeme + ' operator: operands must be numbers, dates, or datetimes.'
194+ );
152195 }
153196 when LESS_EQUAL {
154- checkNumberOperand (binary .operator , left , right );
155- return (Decimal )left <= (Decimal )right ;
197+ if (left instanceof Decimal && right instanceof Decimal ) {
198+ return (Decimal )left <= (Decimal )right ;
199+ }
200+
201+ if (left instanceof Date && right instanceof Date ) {
202+ return (Date )left <= (Date )right ;
203+ }
204+
205+ if (left instanceof Datetime && right instanceof Datetime ) {
206+ return (Datetime )left <= (Datetime )right ;
207+ }
156208 }
157209 when EQUAL , EQUAL_EQUAL {
158210 return left == right ;
@@ -567,7 +619,7 @@ public virtual with sharing class Interpreter implements Visitor {
567619
568620 return new ShouldNotAdd ();
569621 }
570-
622+
571623 public Object visit (Expr.PipelineFunction pipelineFunction ) {
572624 throw new Exceptions .UnknownException (
573625 ' Pipelines should first be desugared by the PipeResolver before reaching the Interpreter.'
0 commit comments