Search in sources :

Example 16 with JexlContext

use of org.apache.commons.jexl2.JexlContext in project shifu by ShifuML.

the class JexlTest method testJavaExpressionNum.

@Test
public void testJavaExpressionNum() {
    JexlEngine jexl = new JexlEngine();
    String jexlExp = "bad_num == 2";
    Expression e = jexl.createExpression(jexlExp);
    JexlContext jc = new MapContext();
    jc.set("bad_num", 2);
    // Now evaluate the expression, getting the result
    Boolean isEqual = (Boolean) e.evaluate(jc);
    Assert.assertTrue(isEqual);
    jc.set("bad_num", null);
    isEqual = (Boolean) e.evaluate(jc);
    Assert.assertFalse(isEqual);
    jc.set("bad_num", "2");
    isEqual = (Boolean) e.evaluate(jc);
    Assert.assertTrue(isEqual);
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext) MapContext(org.apache.commons.jexl2.MapContext) Test(org.testng.annotations.Test)

Example 17 with JexlContext

use of org.apache.commons.jexl2.JexlContext in project shifu by ShifuML.

the class JexlTest method testJavaStrEmpty.

@Test
public void testJavaStrEmpty() {
    JexlEngine jexl = new JexlEngine();
    String jexlExp = "ARM17_score != null and !ARM17_score.isEmpty()";
    Expression e = jexl.createExpression(jexlExp);
    JexlContext jc = new MapContext();
    jc.set("ARM17_score", null);
    Assert.assertEquals(Boolean.FALSE, e.evaluate(jc));
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext) MapContext(org.apache.commons.jexl2.MapContext) Test(org.testng.annotations.Test)

Example 18 with JexlContext

use of org.apache.commons.jexl2.JexlContext in project shifu by ShifuML.

the class JexlTest method testJavaEqual.

@Test
public void testJavaEqual() {
    JexlEngine jexl = new JexlEngine();
    String jexlExp = "arm14_seg==1 and time_window=='DEV'";
    Expression e = jexl.createExpression(jexlExp);
    JexlContext jc = new MapContext();
    jc.set("arm14_seg", "1");
    jc.set("time_window", "DEV");
    Assert.assertEquals(Boolean.TRUE, e.evaluate(jc));
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext) MapContext(org.apache.commons.jexl2.MapContext) Test(org.testng.annotations.Test)

Example 19 with JexlContext

use of org.apache.commons.jexl2.JexlContext in project shifu by ShifuML.

the class JexlTest method testEvaluator.

@Test
public void testEvaluator() {
    String weightColumnName = "cg_dol_wgt";
    JexlEngine jexl = new JexlEngine();
    Expression e = jexl.createExpression(weightColumnName);
    JexlContext jc = new MapContext();
    jc.set("cg_dol_wgt", "1083.22500000");
    Object result = e.evaluate(jc);
    System.out.println((result instanceof Integer));
    System.out.println((result instanceof Double));
    System.out.println(result.toString());
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext) MapContext(org.apache.commons.jexl2.MapContext) Test(org.testng.annotations.Test)

Example 20 with JexlContext

use of org.apache.commons.jexl2.JexlContext in project shifu by ShifuML.

the class JexlTest method testJavaMode.

@Test
public void testJavaMode() {
    JexlEngine jexl = new JexlEngine();
    String jexlExp = "txn_id % 2 == 0 ";
    Expression e = jexl.createExpression(jexlExp);
    JexlContext jc = new MapContext();
    jc.set("txn_id", "1");
    Assert.assertEquals(Boolean.FALSE, e.evaluate(jc));
    jc.set("txn_id", "2");
    Assert.assertEquals(Boolean.TRUE, e.evaluate(jc));
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext) MapContext(org.apache.commons.jexl2.MapContext) Test(org.testng.annotations.Test)

Aggregations

JexlContext (org.apache.commons.jexl2.JexlContext)31 Expression (org.apache.commons.jexl2.Expression)25 MapContext (org.apache.commons.jexl2.MapContext)23 JexlContext (org.apache.commons.jexl3.JexlContext)21 JexlEngine (org.apache.commons.jexl2.JexlEngine)20 MapContext (org.apache.commons.jexl3.MapContext)17 Test (org.testng.annotations.Test)13 HashMap (java.util.HashMap)5 Map (java.util.Map)4 ArrayList (java.util.ArrayList)3 JexlException (org.apache.commons.jexl2.JexlException)3 ObjectContext (org.apache.commons.jexl2.ObjectContext)3 IOException (java.io.IOException)2 ReadonlyContext (org.apache.commons.jexl2.ReadonlyContext)2 JexlScript (org.apache.commons.jexl3.JexlScript)2 NumberUtils (org.apache.commons.lang.math.NumberUtils)2 FloatWritable (org.apache.hadoop.io.FloatWritable)2 IntWritable (org.apache.hadoop.io.IntWritable)2 Text (org.apache.hadoop.io.Text)2 VersionMismatchException (org.apache.hadoop.io.VersionMismatchException)2