Search in sources :

Example 1 with ExpNode

use of com.teradata.jaqy.utils.exp.ExpNode in project jaqy by Teradata.

the class WhereParserTest method test3.

@Test
public void test3() throws Exception {
    Globals globals = new Globals();
    JaqyInterpreter interpreter = new JaqyInterpreter(globals, null, null);
    VariableManager vm = interpreter.getVariableManager();
    ExpNode exp;
    exp = WhereParser.getExp("1 is NULL");
    exp.bind(null, vm, interpreter);
    Assert.assertFalse((Boolean) exp.get());
    exp = WhereParser.getExp("1 is not NULL");
    exp.bind(null, vm, interpreter);
    Assert.assertTrue((Boolean) exp.get());
}
Also used : Globals(com.teradata.jaqy.Globals) VariableManager(com.teradata.jaqy.VariableManager) JaqyInterpreter(com.teradata.jaqy.JaqyInterpreter) ExpNode(com.teradata.jaqy.utils.exp.ExpNode) Test(org.junit.Test)

Example 2 with ExpNode

use of com.teradata.jaqy.utils.exp.ExpNode in project jaqy by Teradata.

the class WhereParserTest method test2.

@Test
public void test2() throws Exception {
    Globals globals = new Globals();
    JaqyInterpreter interpreter = new JaqyInterpreter(globals, null, null);
    VariableManager vm = interpreter.getVariableManager();
    ExpNode exp;
    exp = WhereParser.getExp("1 < any (1, 2)");
    exp.bind(null, vm, interpreter);
    Assert.assertTrue((Boolean) exp.get());
    exp = WhereParser.getExp("1 < some (1, 2)");
    exp.bind(null, vm, interpreter);
    Assert.assertTrue((Boolean) exp.get());
    exp = WhereParser.getExp("1 <= some (1, 2)");
    exp.bind(null, vm, interpreter);
    Assert.assertTrue((Boolean) exp.get());
    exp = WhereParser.getExp("1 = some (1, 2)");
    exp.bind(null, vm, interpreter);
    Assert.assertTrue((Boolean) exp.get());
    exp = WhereParser.getExp("1 <> some (1, 2)");
    exp.bind(null, vm, interpreter);
    Assert.assertTrue((Boolean) exp.get());
    exp = WhereParser.getExp("1 > some (1, 2)");
    exp.bind(null, vm, interpreter);
    Assert.assertFalse((Boolean) exp.get());
    exp = WhereParser.getExp("1 >= some (1, 2)");
    exp.bind(null, vm, interpreter);
    Assert.assertTrue((Boolean) exp.get());
    exp = WhereParser.getExp("1 < ALL (1, 2)");
    exp.bind(null, vm, interpreter);
    Assert.assertFalse((Boolean) exp.get());
    exp = WhereParser.getExp("1 <= ALL (1, 2)");
    exp.bind(null, vm, interpreter);
    Assert.assertTrue((Boolean) exp.get());
    exp = WhereParser.getExp("1 = ALL (1, 2)");
    exp.bind(null, vm, interpreter);
    Assert.assertFalse((Boolean) exp.get());
    exp = WhereParser.getExp("1 <> ALL (1, 2)");
    exp.bind(null, vm, interpreter);
    Assert.assertFalse((Boolean) exp.get());
    exp = WhereParser.getExp("1 > ALL (1, 2)");
    exp.bind(null, vm, interpreter);
    Assert.assertFalse((Boolean) exp.get());
    exp = WhereParser.getExp("1 >= ALL (1, 2)");
    exp.bind(null, vm, interpreter);
    Assert.assertFalse((Boolean) exp.get());
    exp = WhereParser.getExp("1 IN (1, 2)");
    exp.bind(null, vm, interpreter);
    Assert.assertTrue((Boolean) exp.get());
    exp = WhereParser.getExp("'abc' like 'a'");
    exp.bind(null, vm, interpreter);
    Assert.assertTrue((Boolean) exp.get());
    exp = WhereParser.getExp("'abc' like 'a$'");
    exp.bind(null, vm, interpreter);
    Assert.assertFalse((Boolean) exp.get());
    exp = WhereParser.getExp("'abc' like 'a.*'");
    exp.bind(null, vm, interpreter);
    Assert.assertTrue((Boolean) exp.get());
}
Also used : Globals(com.teradata.jaqy.Globals) VariableManager(com.teradata.jaqy.VariableManager) JaqyInterpreter(com.teradata.jaqy.JaqyInterpreter) ExpNode(com.teradata.jaqy.utils.exp.ExpNode) Test(org.junit.Test)

Example 3 with ExpNode

use of com.teradata.jaqy.utils.exp.ExpNode in project jaqy by Teradata.

the class WhereParserTest method test4.

@Test
public void test4() throws Exception {
    Globals globals = new Globals();
    JaqyInterpreter interpreter = new JaqyInterpreter(globals, null, null);
    VariableManager vm = interpreter.getVariableManager();
    ExpNode exp;
    exp = WhereParser.getExp("1 > 0 AND 2 < 4");
    exp.bind(null, vm, interpreter);
    Assert.assertTrue((Boolean) exp.get());
    exp = WhereParser.getExp("1 > 0 OR 4 < 2");
    exp.bind(null, vm, interpreter);
    Assert.assertTrue((Boolean) exp.get());
}
Also used : Globals(com.teradata.jaqy.Globals) VariableManager(com.teradata.jaqy.VariableManager) JaqyInterpreter(com.teradata.jaqy.JaqyInterpreter) ExpNode(com.teradata.jaqy.utils.exp.ExpNode) Test(org.junit.Test)

Example 4 with ExpNode

use of com.teradata.jaqy.utils.exp.ExpNode in project jaqy by Teradata.

the class WhereParserTest method test1.

@Test
public void test1() throws Exception {
    Globals globals = new Globals();
    JaqyInterpreter interpreter = new JaqyInterpreter(globals, null, null);
    VariableManager vm = interpreter.getVariableManager();
    ExpNode exp;
    exp = WhereParser.getExp("1");
    exp.bind(null, vm, interpreter);
    Assert.assertEquals(new Integer(1), exp.get());
    exp = WhereParser.getExp("1--1");
    exp.bind(null, vm, interpreter);
    Assert.assertEquals(new Integer(2), exp.get());
    exp = WhereParser.getExp("1-1");
    exp.bind(null, vm, interpreter);
    Assert.assertEquals(new Integer(0), exp.get());
    exp = WhereParser.getExp("1 + 2 * 3 % 5 * 2 / 1");
    exp.bind(null, vm, interpreter);
    Assert.assertEquals(new Integer(3), exp.get());
    exp = WhereParser.getExp("-1 + 2 * 3 % 5 * -2.125 - 2");
    exp.bind(null, vm, interpreter);
    Assert.assertEquals(new Double(-5.125), exp.get());
    exp = WhereParser.getExp("4 & 8 | 3");
    exp.bind(null, vm, interpreter);
    Assert.assertEquals(new Integer(3), exp.get());
    exp = WhereParser.getExp("1 ^ 2");
    exp.bind(null, vm, interpreter);
    Assert.assertEquals(new Integer(3), exp.get());
    exp = WhereParser.getExp("~2");
    exp.bind(null, vm, interpreter);
    Assert.assertEquals(new Integer(-3), exp.get());
    exp = WhereParser.getExp("'abc'");
    exp.bind(null, vm, interpreter);
    Assert.assertEquals("abc", exp.get());
    exp = WhereParser.getExp("1 < 2");
    exp.bind(null, vm, interpreter);
    Assert.assertTrue((Boolean) exp.get());
    exp = WhereParser.getExp("1 <= (2)");
    exp.bind(null, vm, interpreter);
    Assert.assertTrue((Boolean) exp.get());
    exp = WhereParser.getExp("1 = 2");
    exp.bind(null, vm, interpreter);
    Assert.assertFalse((Boolean) exp.get());
    exp = WhereParser.getExp("1 <> 2");
    exp.bind(null, vm, interpreter);
    Assert.assertTrue((Boolean) exp.get());
    exp = WhereParser.getExp("1 > 2");
    exp.bind(null, vm, interpreter);
    Assert.assertFalse((Boolean) exp.get());
    exp = WhereParser.getExp("1 >= 2");
    exp.bind(null, vm, interpreter);
    Assert.assertFalse((Boolean) exp.get());
    exp = WhereParser.getExp("Math.sqrt(4)");
    exp.bind(null, vm, interpreter);
    Assert.assertEquals(new Double(2), exp.get());
    exp = WhereParser.getExp("Math.random()");
    exp.bind(null, vm, interpreter);
    Assert.assertEquals(Double.class, exp.get().getClass());
    exp = WhereParser.getExp("1 || 2");
    exp.bind(null, vm, interpreter);
    Assert.assertEquals("12", exp.get());
    exp = WhereParser.getExp("'abc' || 2");
    exp.bind(null, vm, interpreter);
    Assert.assertEquals("abc2", exp.get());
    exp = WhereParser.getExp("'abc' || 1 || 2");
    exp.bind(null, vm, interpreter);
    Assert.assertEquals("abc12", exp.get());
}
Also used : Globals(com.teradata.jaqy.Globals) VariableManager(com.teradata.jaqy.VariableManager) JaqyInterpreter(com.teradata.jaqy.JaqyInterpreter) ExpNode(com.teradata.jaqy.utils.exp.ExpNode) Test(org.junit.Test)

Example 5 with ExpNode

use of com.teradata.jaqy.utils.exp.ExpNode in project jaqy by Teradata.

the class ExpNodeProject method bind.

@Override
public void bind(JaqyResultSet rs, JaqyInterpreter interpreter) throws Exception {
    m_vm = new VariableManager(interpreter.getVariableManager());
    m_vm.setVariable(ExpNodePredicate.RS_VAR, rs);
    for (ExpNode exp : m_expList) exp.bind(rs, m_vm, interpreter);
}
Also used : VariableManager(com.teradata.jaqy.VariableManager) ExpNode(com.teradata.jaqy.utils.exp.ExpNode)

Aggregations

ExpNode (com.teradata.jaqy.utils.exp.ExpNode)7 VariableManager (com.teradata.jaqy.VariableManager)5 Globals (com.teradata.jaqy.Globals)4 JaqyInterpreter (com.teradata.jaqy.JaqyInterpreter)4 Test (org.junit.Test)4 JaqyResultSetMetaData (com.teradata.jaqy.connection.JaqyResultSetMetaData)1 JaqyHelper (com.teradata.jaqy.interfaces.JaqyHelper)1 InMemoryResultSetMetaData (com.teradata.jaqy.resultset.InMemoryResultSetMetaData)1 FullColumnInfo (com.teradata.jaqy.schema.FullColumnInfo)1 ExpNodePredicate (com.teradata.jaqy.utils.ExpNodePredicate)1 ColumnNode (com.teradata.jaqy.utils.exp.ColumnNode)1 ResultSetMetaData (java.sql.ResultSetMetaData)1