Beispiel #1
0
  private void parseMainModelClause(ModelClause modelClause) {
    MainModelClause mainModel = new MainModelClause();

    if (identifierEquals("MAIN")) {
      lexer.nextToken();
      mainModel.setMainModelName(expr());
    }

    ModelColumnClause modelColumnClause = new ModelColumnClause();
    parseQueryPartitionClause(modelColumnClause);
    mainModel.setModelColumnClause(modelColumnClause);

    acceptIdentifier("DIMENSION");
    accept(Token.BY);
    accept(Token.LPAREN);
    for (; ; ) {
      if (lexer.token() == Token.RPAREN) {
        lexer.nextToken();
        break;
      }

      ModelColumn column = new ModelColumn();
      column.setExpr(expr());
      column.setAlias(as());
      modelColumnClause.getDimensionByColumns().add(column);

      if (lexer.token() == Token.COMMA) {
        lexer.nextToken();
        continue;
      }
    }

    acceptIdentifier("MEASURES");
    accept(Token.LPAREN);
    for (; ; ) {
      if (lexer.token() == Token.RPAREN) {
        lexer.nextToken();
        break;
      }

      ModelColumn column = new ModelColumn();
      column.setExpr(expr());
      column.setAlias(as());
      modelColumnClause.getMeasuresColumns().add(column);

      if (lexer.token() == Token.COMMA) {
        lexer.nextToken();
        continue;
      }
    }
    mainModel.setModelColumnClause(modelColumnClause);

    parseCellReferenceOptions(mainModel.getCellReferenceOptions());

    parseModelRulesClause(mainModel);

    modelClause.setMainModel(mainModel);
  }
Beispiel #2
0
  private void parseModelRulesClause(MainModelClause mainModel) {
    ModelRulesClause modelRulesClause = new ModelRulesClause();
    if (identifierEquals("RULES")) {
      lexer.nextToken();
      if (lexer.token() == Token.UPDATE) {
        modelRulesClause.getOptions().add(ModelRuleOption.UPDATE);
        lexer.nextToken();
      } else if (identifierEquals("UPSERT")) {
        modelRulesClause.getOptions().add(ModelRuleOption.UPSERT);
        lexer.nextToken();
      }

      if (identifierEquals("AUTOMATIC")) {
        lexer.nextToken();
        accept(Token.ORDER);
        modelRulesClause.getOptions().add(ModelRuleOption.AUTOMATIC_ORDER);
      } else if (identifierEquals("SEQUENTIAL")) {
        lexer.nextToken();
        accept(Token.ORDER);
        modelRulesClause.getOptions().add(ModelRuleOption.SEQUENTIAL_ORDER);
      }
    }

    if (identifierEquals("ITERATE")) {
      lexer.nextToken();
      accept(Token.LPAREN);
      modelRulesClause.setIterate(expr());
      accept(Token.RPAREN);

      if (identifierEquals("UNTIL")) {
        lexer.nextToken();
        accept(Token.LPAREN);
        modelRulesClause.setUntil(expr());
        accept(Token.RPAREN);
      }
    }

    accept(Token.LPAREN);
    for (; ; ) {
      if (lexer.token() == Token.RPAREN) {
        lexer.nextToken();
        break;
      }

      CellAssignmentItem item = new CellAssignmentItem();
      if (lexer.token() == Token.UPDATE) {
        item.setOption(ModelRuleOption.UPDATE);
      } else if (identifierEquals("UPSERT")) {
        item.setOption(ModelRuleOption.UPSERT);
      }

      item.setCellAssignment(parseCellAssignment());
      item.setOrderBy(this.parseOrderBy());
      accept(Token.EQ);
      item.setExpr(expr());

      modelRulesClause.getCellAssignmentItems().add(item);
    }

    mainModel.setModelRulesClause(modelRulesClause);
  }