Package com.odiago.flumebase.parser

Examples of com.odiago.flumebase.parser.Expr


  }

  @Test
  public void testPromotion1() throws VisitException {
    // Test that INT can promote to BIGINT.
    Expr binopExpr = new BinExpr(
      new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(2)),
      BinOp.Add, new ConstExpr(Type.getPrimitive(Type.TypeName.BIGINT), Integer.valueOf(3)));
    TypeChecker tc = new TypeChecker(new HashSymbolTable());
    binopExpr.accept(tc);
  }
View Full Code Here


  }

  @Test
  public void testPromotion2() throws VisitException {
    // Test that INT can promote to BIGINT on the lhs.
    Expr binopExpr = new BinExpr(
      new ConstExpr(Type.getPrimitive(Type.TypeName.BIGINT), Integer.valueOf(2)),
      BinOp.Add, new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(3)));
    TypeChecker tc = new TypeChecker(new HashSymbolTable());
    binopExpr.accept(tc);
  }
View Full Code Here

    // Test that we can look up an identifier in the symbol table.
    SymbolTable symbols = new HashSymbolTable();
    symbols.addSymbol(new AssignedSymbol("x", Type.getPrimitive(Type.TypeName.INT), "x",
        IdentifierExpr.AccessType.FIELD));

    Expr binopExpr = new BinExpr(
      new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(2)),
      BinOp.Add, new IdentifierExpr("x"));
    TypeChecker tc = new TypeChecker(symbols);
    binopExpr.accept(tc);
  }
View Full Code Here

    // Test that an identifier's type can promote to a constant.
    SymbolTable symbols = new HashSymbolTable();
    symbols.addSymbol(new AssignedSymbol("x", Type.getPrimitive(Type.TypeName.INT), "x",
        IdentifierExpr.AccessType.FIELD));

    Expr binopExpr = new BinExpr(
      new ConstExpr(Type.getPrimitive(Type.TypeName.BIGINT), Integer.valueOf(2)),
      BinOp.Add, new IdentifierExpr("x"));
    TypeChecker tc = new TypeChecker(symbols);
    binopExpr.accept(tc);
  }
View Full Code Here

    // Test that a const's type can promote to an identifier's.
    SymbolTable symbols = new HashSymbolTable();
    symbols.addSymbol(new AssignedSymbol("x", Type.getPrimitive(Type.TypeName.BIGINT), "x",
        IdentifierExpr.AccessType.FIELD));

    Expr binopExpr = new BinExpr(
      new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(2)),
      BinOp.Add, new IdentifierExpr("x"));
    TypeChecker tc = new TypeChecker(symbols);
    binopExpr.accept(tc);
  }
View Full Code Here

          createSymbols(outTable, stmtAlias, name, aliasedExpr.getAvroLabel(), type);
        }
      }

      // Check the where clause for validity if it's non-null.
      Expr where = s.getWhereConditions();
      if (null != where) {
        where.accept(this);
        // The where clause must evaluate to a boolean value.
        Type whereType = where.getType(exprTable);
        if (!whereType.promotesTo(Type.getNullable(Type.TypeName.BOOLEAN))) {
          throw new TypeCheckException("Expected where clause with boolean type, not "
              + whereType);
        }
      }

      // Check the GROUP BY clause for validity if it's non-null.
      GroupBy groupBy = s.getGroupBy();
      if (null != groupBy) {
        groupBy.accept(this);
      }

      // Check the OVER clause for validity if it's non-null.
      // This must evaluate to a value of type WINDOW.
      Expr windowOver = s.getWindowOver();
      if (null != windowOver) {
        windowOver.accept(this);
        Type winType = windowOver.getType(exprTable);
        if (!winType.equals(Type.getPrimitive(Type.TypeName.WINDOW))) {
          throw new TypeCheckException("SELECT ... OVER clause requires a window, not an "
              + "identifier of type " + winType);
        }
      }
    } finally {
      // Pop the source symbol tables from the stack.
      mSymTableContext.reset(symbolStackHeight);
      mSelectNestingDepth--;
    }

    // Push our output symbols on the stack so any higher-level select stmt can
    // type check against them. Memorize the symbols for this statement in the
    // statement object itself.
    if (null != outTable) {
      mSymTableContext.push(outTable);
      s.setFieldSymbols(outTable.cloneLevel());
    }

    // HAVING clause uses the output symbol names. It can only operate on
    // fields already explicitly selected by the user -- if these are not
    // already present, this will fail.
    Expr having = s.getHaving();
    if (null != having) {
      having.accept(this);
      // The having clause must evaluate to a boolean value.
      Type havingType = having.getType(outTable);
      if (!havingType.promotesTo(Type.getNullable(Type.TypeName.BOOLEAN))) {
        throw new TypeCheckException("Expected having clause with boolean type, not "
            + havingType);
      }
    }
View Full Code Here

        mSymTableContext.top());
    s.setJoinedSymbols(symTab);
    mSymTableContext.push(symTab);

    // Verify that the join expression is BOOLEAN.
    Expr joinExpr = s.getJoinExpr();
    joinExpr.accept(this);
    Type joinType = joinExpr.getType(symTab);
    if (!joinType.promotesTo(Type.getNullable(Type.TypeName.BOOLEAN))) {
      throw new TypeCheckException("JOIN ... ON clause requires boolean test expression, not "
          + joinExpr.toStringOneLine());
    }

    // Make sure the "OVER" clause joins over a Window.
    Expr windowExpr = s.getWindowExpr();
    windowExpr.accept(this);
    Type winType = windowExpr.getType(symTab);
    if (!winType.equals(Type.getPrimitive(Type.TypeName.WINDOW))) {
      throw new TypeCheckException("JOIN ... OVER clause requires a window, not an "
          + "identifier of type " + winType);
    }
  }
View Full Code Here

    s.getChildStmt().accept(this);
  }

  @Override
  protected void visit(AliasedExpr e) throws VisitException {
    Expr subExpr = e.getExpr();
    String userAlias = e.getUserAlias();

    // If the sub-expression is just a '*', this can't have an alias.
    // ("SELECT * AS bla FROM ..." is illegal.)
    if (subExpr instanceof AllFieldsExpr && userAlias != null) {
      throw new TypeCheckException("Cannot assign field label to '*' operator.");
    }

    if (userAlias != null && userAlias.contains(".")) {
      // Can't "SELECT x AS y.x", it confuses our name promotion.
      throw new TypeCheckException("Cannot use the '.' character in a field alias ("
          + userAlias + ")");
    }

    // Typecheck the sub-expression.
    subExpr.accept(this);
  }
View Full Code Here

  }

  protected void visit(RangeSpec spec) throws VisitException {
    // Expressions within a range specification for a window must be constant,
    // and numeric.
    Expr after = spec.getAfterSize();
    Expr prev = spec.getPrevSize();
    after.accept(this);
    prev.accept(this);


    SymbolTable symTab = mSymTableContext.top();
   
    Type prevType = prev.getType(symTab);
    Type afterType = after.getType(symTab);
    if (null == prevType) {
      throw new TypeCheckException("Cannot resolve type for expression: "
          + prev.toStringOneLine());
    } else if (null == afterType) {
      throw new TypeCheckException("Cannot resolve type for expression: "
          + after.toStringOneLine());
    } else if (!prevType.isNumeric()) {
      throw new TypeCheckException("Expression " + prev.toStringOneLine()
          + " should have numeric type.");
    } else if (!afterType.isNumeric()) {
      throw new TypeCheckException("Expression " + after.toStringOneLine()
          + " should have numeric type.");
    } else if (!prev.isConstant()) {
      throw new TypeCheckException("Expression " + prev.toStringOneLine() + " is not constant");
    } else if (!after.isConstant()) {
      throw new TypeCheckException("Expression " + after.toStringOneLine() + " is not constant");
    }
  }
View Full Code Here

        throw new DAGOperatorException("Unhandled stream source type: "
            + streamSymbol.getSourceType());
      }
    } else if (node instanceof FilterNode) {
      FilterNode filterNode = (FilterNode) node;
      Expr filterExpr = filterNode.getFilterExpr();
      newElem = new FilterElement(newContext, filterExpr);
    } else if (node instanceof ProjectionNode) {
      ProjectionNode projNode = (ProjectionNode) node;
      Schema outSchema = (Schema) projNode.getAttr(PlanNode.OUTPUT_SCHEMA_ATTR);
      newElem = new ProjectionElement(newContext, outSchema, projNode.getInputFields(),
View Full Code Here

TOP

Related Classes of com.odiago.flumebase.parser.Expr

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.