Search in sources :

Example 6 with VariableManager

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());
}
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 7 with VariableManager

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());
}
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 8 with VariableManager

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;
}
Also used : VariableManager(com.teradata.jaqy.VariableManager) Variable(com.teradata.jaqy.interfaces.Variable)

Example 9 with VariableManager

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]);
        }
    }
}
Also used : VariableManager(com.teradata.jaqy.VariableManager)

Example 10 with VariableManager

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();
}
Also used : VariableManager(com.teradata.jaqy.VariableManager) Variable(com.teradata.jaqy.interfaces.Variable)

Aggregations

VariableManager (com.teradata.jaqy.VariableManager)14 ExpNode (com.teradata.jaqy.utils.exp.ExpNode)5 Globals (com.teradata.jaqy.Globals)4 JaqyInterpreter (com.teradata.jaqy.JaqyInterpreter)4 Variable (com.teradata.jaqy.interfaces.Variable)4 Test (org.junit.Test)4 AmazonS3ClientBuilder (com.amazonaws.services.s3.AmazonS3ClientBuilder)2 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)1 AnonymousAWSCredentials (com.amazonaws.auth.AnonymousAWSCredentials)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1