Esempio n. 1
0
  /**
   * エイリアス指定付きの結合モデルの確認。
   *
   * @throws Exception 例外が発生した場合
   */
  @Test
  public void parseJoin_withAlias() throws Exception {
    ViewDefinition def =
        def(
            "select"
                + "  `a`.`pk` AS `pk`,"
                + "  `a`.`val1` AS `val1`,"
                + "  `b`.`val2` AS `val2`"
                + "from `test`.`t1` `a`"
                + "join `test`.`t2` `b`"
                + "where"
                + "  (`test`.`a`.`pk` = `test`.`b`.`pk`)");

    CreateView model = ViewParser.parse(def);
    assertThat(
        model,
        is(
            new CreateView(
                n("test"),
                Arrays.asList(
                    new Select[] {
                      new Select(n("a.pk"), Aggregator.IDENT, n("pk")),
                      new Select(n("a.val1"), Aggregator.IDENT, n("val1")),
                      new Select(n("b.val2"), Aggregator.IDENT, n("val2")),
                    }),
                new From(
                    n("t1"),
                    "a",
                    new Join(n("t2"), "b", Arrays.asList(new On(n("a.pk"), n("b.pk"))))),
                Arrays.<Name>asList())));
  }
Esempio n. 2
0
  /**
   * 集計モデルの確認。
   *
   * @throws Exception 例外が発生した場合
   */
  @Test
  public void parseSummarize_multiGroupCoulmns() throws Exception {
    ViewDefinition def =
        def(
            "select"
                + "  `test`.`t1`.`pk` AS `pk`,"
                + "  count(`test`.`t1`.`pk`) AS `count`,"
                + "  max(`test`.`t1`.`pk`) AS `max`,"
                + "  sum(`test`.`t1`.`pk`) AS `sum`"
                + "from"
                + "  `test`.`t1`"
                + "group by"
                + "  `test`.`t1`.`val1` , `test`.`t1`.`val2`");

    CreateView model = ViewParser.parse(def);
    assertThat(
        model,
        is(
            new CreateView(
                n("test"),
                Arrays.asList(
                    new Select[] {
                      new Select(n("t1.pk"), Aggregator.IDENT, n("pk")),
                      new Select(n("t1.pk"), Aggregator.COUNT, n("count")),
                      new Select(n("t1.pk"), Aggregator.MAX, n("max")),
                      new Select(n("t1.pk"), Aggregator.SUM, n("sum")),
                    }),
                new From(n("t1"), null, null),
                Arrays.<Name>asList(n("t1.val1"), n("t1.val2")))));
  }