use of com.teradata.jaqy.VariableManager 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());
}
use of com.teradata.jaqy.VariableManager 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());
}
use of com.teradata.jaqy.VariableManager in project jaqy by Teradata.
the class ClientRSUtils method getSortNull.
public static boolean getSortNull(JaqyInterpreter interpreter) {
VariableManager vm = interpreter.getVariableManager();
Variable var = vm.getVariable(NULLSORT_VAR);
if (var == null) {
vm.setVariable(NULLSORT_VAR, DEFAULT_NULLSORT_VALUE);
return DEFAULT_NULLSORT_VALUE;
}
Object v = var.get();
if (v instanceof Boolean) {
return ((Boolean) v).booleanValue();
}
return DEFAULT_NULLSORT_VALUE;
}
use of com.teradata.jaqy.VariableManager in project jaqy by Teradata.
the class TimerCommand method execute.
@Override
public void execute(String[] args, boolean silent, JaqyInterpreter interpreter) throws SQLException {
if (args.length == 0) {
long startTime = getStartTime(interpreter);
if (startTime == 0) {
interpreter.println("-- timer not yet set.");
} else {
printTime(startTime, interpreter);
}
} else {
if ("set".equals(args[0])) {
VariableManager vm = interpreter.getVariableManager();
vm.setVariable(TIMER, System.nanoTime());
interpreter.println("-- timer started.");
} else {
interpreter.error("Invalid argument: " + args[0]);
}
}
}
use of com.teradata.jaqy.VariableManager in project jaqy by Teradata.
the class TimerCommand method getStartTime.
private long getStartTime(JaqyInterpreter interpreter) {
VariableManager vm = interpreter.getVariableManager();
Variable var = vm.getVariable("timer");
if (var == null)
return 0;
Object o = var.get();
if (o == null)
return 0;
if (!(o instanceof Number))
return 0;
return ((Number) o).longValue();
}
Aggregations