Package com.odiago.flumebase.lang

Examples of com.odiago.flumebase.lang.TypeChecker


        return new QuerySubmitResponse(msgBuilder.toString(), null);
      }

      stmt.accept(new AssignFieldLabelsVisitor());
      stmt.accept(new CountStarVisitor()); // Must be after assign labels, before TC.
      stmt.accept(new TypeChecker(mRootSymbolTable));
      stmt.accept(new ReplaceWindows()); // Must be after TC.
      stmt.accept(new JoinKeyVisitor()); // Must be after TC.
      stmt.accept(new JoinNameVisitor());
      stmt.accept(new IdentifyAggregates()); // Must be after TC.
      PlanContext planContext = new PlanContext();
View Full Code Here


public class TestUnaryExpr extends ExprTestCase {

  @Test
  public void testNot() throws Exception {
    Expr unaryExpr;
    TypeChecker checker;
    Object value;

    unaryExpr = new UnaryExpr(UnaryOp.Not,
        new ConstExpr(Type.getPrimitive(Type.TypeName.BOOLEAN), Boolean.FALSE));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.TRUE, value);

    unaryExpr = new UnaryExpr(UnaryOp.Not,
        new ConstExpr(Type.getPrimitive(Type.TypeName.BOOLEAN), Boolean.TRUE));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.FALSE, value);

    unaryExpr = new UnaryExpr(UnaryOp.Not,
        new ConstExpr(Type.getNullable(Type.TypeName.BOOLEAN), null));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(null, value);

    unaryExpr = new UnaryExpr(UnaryOp.Not,
        new UnaryExpr(UnaryOp.Not,
          new ConstExpr(Type.getPrimitive(Type.TypeName.BOOLEAN), Boolean.TRUE)));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.TRUE, value);

    try {
      unaryExpr = new UnaryExpr(UnaryOp.Not,
          new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(42)));
      checker = new TypeChecker(new HashSymbolTable());
      unaryExpr.accept(checker);
      fail("Expected typechecker error on NOT(INTEGER)");
    } catch (TypeCheckException tce) {
      // expected this -- ok.
    }
View Full Code Here

  }

  @Test
  public void testNegate() throws Exception {
    Expr unaryExpr;
    TypeChecker checker;
    Object value;

    unaryExpr = new UnaryExpr(UnaryOp.Minus,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(10)));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Integer.valueOf(-10), value);

    unaryExpr = new UnaryExpr(UnaryOp.Minus,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(-42)));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Integer.valueOf(42), value);

    unaryExpr = new UnaryExpr(UnaryOp.Minus,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(0)));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Integer.valueOf(0), value);

    unaryExpr = new UnaryExpr(UnaryOp.Minus,
        new ConstExpr(Type.getPrimitive(Type.TypeName.BIGINT), Long.valueOf(-42)));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Long.valueOf(42), value);

    unaryExpr = new UnaryExpr(UnaryOp.Minus,
        new ConstExpr(Type.getPrimitive(Type.TypeName.FLOAT), Float.valueOf(-42f)));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Float.valueOf(42f), value);

    unaryExpr = new UnaryExpr(UnaryOp.Minus,
        new ConstExpr(Type.getPrimitive(Type.TypeName.DOUBLE), Double.valueOf(-42)));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Double.valueOf(42), value);

    unaryExpr = new UnaryExpr(UnaryOp.Minus,
        new ConstExpr(Type.getNullable(Type.TypeName.DOUBLE), null));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(null, value);

    unaryExpr = new UnaryExpr(UnaryOp.Minus,
        new UnaryExpr(UnaryOp.Minus,
          new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(12))));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Integer.valueOf(12), value);

    try {
      unaryExpr = new UnaryExpr(UnaryOp.Minus,
          new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), "hello"));
      checker = new TypeChecker(new HashSymbolTable());
      unaryExpr.accept(checker);
      fail("Expected typechecker error on -(STRING)");
    } catch (TypeCheckException tce) {
      // expected this -- ok.
    }
View Full Code Here

  }

  @Test
  public void testIsNull() throws Exception {
    Expr unaryExpr;
    TypeChecker checker;
    Object value;

    unaryExpr = new UnaryExpr(UnaryOp.IsNull,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(10)));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.FALSE, value);

    unaryExpr = new UnaryExpr(UnaryOp.IsNull,
        new ConstExpr(Type.getNullable(Type.TypeName.INT), Integer.valueOf(10)));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.FALSE, value);

    unaryExpr = new UnaryExpr(UnaryOp.IsNull,
        new ConstExpr(Type.getNullable(Type.TypeName.INT), null));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.TRUE, value);

    unaryExpr = new UnaryExpr(UnaryOp.IsNull,
        new ConstExpr(Type.getNullable(Type.TypeName.STRING), null));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.TRUE, value);
  }
View Full Code Here

  }

  @Test
  public void testIsNotNull() throws Exception {
    Expr unaryExpr;
    TypeChecker checker;
    Object value;

    unaryExpr = new UnaryExpr(UnaryOp.IsNotNull,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(10)));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.TRUE, value);

    unaryExpr = new UnaryExpr(UnaryOp.IsNotNull,
        new ConstExpr(Type.getNullable(Type.TypeName.INT), Integer.valueOf(10)));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.TRUE, value);

    unaryExpr = new UnaryExpr(UnaryOp.IsNotNull,
        new ConstExpr(Type.getNullable(Type.TypeName.INT), null));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.FALSE, value);

    unaryExpr = new UnaryExpr(UnaryOp.IsNotNull,
        new ConstExpr(Type.getNullable(Type.TypeName.STRING), null));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.FALSE, value);
  }
View Full Code Here

  }

  @Test
  public void testPositive() throws Exception {
    Expr unaryExpr;
    TypeChecker checker;
    Object value;

    unaryExpr = new UnaryExpr(UnaryOp.Plus,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(10)));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Integer.valueOf(10), value);

    unaryExpr = new UnaryExpr(UnaryOp.Plus,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(-42)));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Integer.valueOf(-42), value);

    unaryExpr = new UnaryExpr(UnaryOp.Plus,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(0)));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Integer.valueOf(0), value);

    unaryExpr = new UnaryExpr(UnaryOp.Plus,
        new ConstExpr(Type.getPrimitive(Type.TypeName.BIGINT), Long.valueOf(-42)));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Long.valueOf(-42), value);

    unaryExpr = new UnaryExpr(UnaryOp.Plus,
        new ConstExpr(Type.getPrimitive(Type.TypeName.FLOAT), Float.valueOf(-42f)));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Float.valueOf(-42f), value);

    unaryExpr = new UnaryExpr(UnaryOp.Plus,
        new ConstExpr(Type.getPrimitive(Type.TypeName.DOUBLE), Double.valueOf(-42)));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Double.valueOf(-42), value);

    unaryExpr = new UnaryExpr(UnaryOp.Plus,
        new UnaryExpr(UnaryOp.Plus,
          new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(12))));
    checker = new TypeChecker(new HashSymbolTable());
    unaryExpr.accept(checker);
    value = unaryExpr.eval(getEmptyEventWrapper());
    assertEquals(Integer.valueOf(12), value);

    try {
      unaryExpr = new UnaryExpr(UnaryOp.Plus,
          new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), "hello"));
      checker = new TypeChecker(new HashSymbolTable());
      unaryExpr.accept(checker);
      fail("Expected typechecker error on +(STRING)");
    } catch (TypeCheckException tce) {
      // expected this -- ok.
    }
View Full Code Here

public class TestFnCallExpr extends ExprTestCase {

  @Test
  public void testLengthFn() throws Exception {
    FnCallExpr fnCallExpr;
    TypeChecker checker;
    Object value;
    SymbolTable symbols = new HashSymbolTable(new BuiltInSymbolTable());

    // This is expected to succeed.
    fnCallExpr = new FnCallExpr("length");
    fnCallExpr.addArg(new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), "meep"));
    checker = new TypeChecker(symbols);
    fnCallExpr.accept(checker);
    value = fnCallExpr.eval(getEmptyEventWrapper());

    assertEquals(Integer.valueOf(4), value);
  }
View Full Code Here

public class TestIdentifierExpr extends ExprTestCase {

  @Test
  public void testIdentifiers() throws Exception {
    Expr binExpr;
    TypeChecker checker;
    Object value;
    SymbolTable symbols = new HashSymbolTable();
    symbols.addSymbol(new AssignedSymbol("x", Type.getPrimitive(Type.TypeName.INT), "x",
        IdentifierExpr.AccessType.FIELD));

    ArrayList<String> symbolNames = new ArrayList<String>();
    symbolNames.add("x");
    EventWrapper wrapper = new ParsingEventWrapper(new DelimitedEventParser(),
        symbolNames);
    wrapper.reset(new EventImpl("4".getBytes()));

    // This is expected to succeed.
    binExpr = new BinExpr(
        new IdentifierExpr("x"),
        BinOp.Times,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(2)));
    checker = new TypeChecker(symbols);
    binExpr.accept(checker);
    value = binExpr.eval(wrapper);
    assertEquals(Integer.valueOf(8), value);

    // This should fail; 'y' is not a registered symbol.
    try {
      binExpr = new BinExpr(
          new IdentifierExpr("y"),
          BinOp.Times,
          new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(2)));
      checker = new TypeChecker(symbols);
      binExpr.accept(checker);
      fail("Expected type checker error; no symbol 'y'.");
    } catch (VisitException ve) {
      // expected; ok.
    }
View Full Code Here

public class TestBinExpr extends ExprTestCase {

  @Test
  public void testTimes() throws Exception {
    Expr binExpr;
    TypeChecker checker;
    Object value;

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)),
        BinOp.Times,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(2)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Integer.valueOf(8), value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getNullable(Type.TypeName.INT), Integer.valueOf(4)),
        BinOp.Times,
        new ConstExpr(Type.getNullable(Type.TypeName.INT), Integer.valueOf(2)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Integer.valueOf(8), value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getNullable(Type.TypeName.INT), null),
        BinOp.Times,
        new ConstExpr(Type.getNullable(Type.TypeName.INT), Integer.valueOf(2)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(null, value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getNullable(Type.TypeName.INT), Integer.valueOf(4)),
        BinOp.Times,
        new ConstExpr(Type.getNullable(Type.TypeName.INT), null));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(null, value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)),
        BinOp.Times,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(-2)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Integer.valueOf(-8), value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.BIGINT), Long.valueOf(4)),
        BinOp.Times,
        new ConstExpr(Type.getPrimitive(Type.TypeName.BIGINT), Long.valueOf(2)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Long.valueOf(8), value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)),
        BinOp.Times,
        new ConstExpr(Type.getPrimitive(Type.TypeName.BIGINT), Long.valueOf(2)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Long.valueOf(8), value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.BIGINT), Long.valueOf(4)),
        BinOp.Times,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(2)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Long.valueOf(8), value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.FLOAT), Float.valueOf(12f)),
        BinOp.Times,
        new ConstExpr(Type.getPrimitive(Type.TypeName.FLOAT), Float.valueOf(2.5f)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Float.valueOf(12f * 2.5f), value);

    try {
      binExpr = new UnaryExpr(UnaryOp.Not,
          new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(42)));
      checker = new TypeChecker(new HashSymbolTable());
      binExpr.accept(checker);
      fail("Expected typechecker error on NOT(INTEGER)");
    } catch (TypeCheckException tce) {
      // expected this -- ok.
    }
View Full Code Here

  }

  @Test
  public void testPlus() throws Exception {
    Expr binExpr;
    TypeChecker checker;
    Object value;

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)),
        BinOp.Add,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(2)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Integer.valueOf(6), value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)),
        BinOp.Add,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(-2)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Integer.valueOf(2), value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), new Utf8("abc")),
        BinOp.Add,
        new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), new Utf8("def")));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals("abcdef", value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), new Utf8("abc")),
        BinOp.Add,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(3)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals("abc3", value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(3)),
        BinOp.Add,
        new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), new Utf8("xyz")));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals("3xyz", value);
  }
View Full Code Here

TOP

Related Classes of com.odiago.flumebase.lang.TypeChecker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.