use of com.teradata.jaqy.Globals 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());
}
use of com.teradata.jaqy.Globals 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.Globals 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.Globals in project jaqy by Teradata.
the class UnAliasCommand method execute.
@Override
public void execute(String[] args, boolean silent, JaqyInterpreter interpreter) {
if (args.length == 0) {
interpreter.error("missing argument.");
} else {
String name = args[0];
Globals globals = interpreter.getGlobals();
if (globals.getAliasManager().getAlias(name) == null) {
interpreter.error("alias " + args[0] + " is not found.");
}
globals.getAliasManager().setAlias(name, null);
}
}
use of com.teradata.jaqy.Globals in project jaqy by Teradata.
the class ImportCommand method getLongDescription.
@Override
public String getLongDescription() {
Globals globals = getGlobals();
StringBuffer buffer = new StringBuffer();
buffer.append("usage: " + getCommand() + " [type] [type options] [path]\ntype:");
String[] names = globals.getImporterManager().getNames();
for (String name : names) buffer.append("\n ").append(name);
buffer.append("\n");
for (String name : names) {
String syntax = globals.getImporterManager().getHandlerFactory(name).getLongDescription();
if (syntax != null)
buffer.append('\n').append(syntax);
}
return buffer.toString();
}
Aggregations