Exemplo n.º 1
0
  @Test
  public void test_one() throws Exception {
    String sql =
        "create table hp_db.g20_relationship_communication_daily(                   "
            + " a_iden_string    varchar,"
            + " b_iden_string    varchar,"
            + " counter          bigint,"
            + " durationtime     bigint"
            + ") "
            + "\nPARTITION BY HASH KEY(a_iden_string) PARTITION NUM 100"
            + "\nSUBPARTITION BY LIST(bdt bigint)"
            + "\nSUBPARTITION OPTIONS(available_Partition_Num=90)"
            + "\nTABLEGROUP g20_test_group;";

    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseCreateTable();

    MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
    stmt.accept(visitor);

    {
      String output = SQLUtils.toMySqlString(stmt);
      Assert.assertEquals(
          "CREATE TABLE hp_db.g20_relationship_communication_daily ("
              + "\n\ta_iden_string varchar, "
              + "\n\tb_iden_string varchar, "
              + "\n\tcounter bigint, "
              + "\n\tdurationtime bigint"
              + "\n)"
              + "\nPARTITION BY HASH KEY(a_iden_string) PARTITION NUM 100"
              + "\nSUBPARTITION BY LIST (bdt bigint)"
              + "\nSUBPARTITION OPTIONS (available_Partition_Num = 90)"
              + "\nTABLEGROUP g20_test_group",
          output);
    }
    {
      String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
      Assert.assertEquals(
          "create table hp_db.g20_relationship_communication_daily ("
              + "\n\ta_iden_string varchar, "
              + "\n\tb_iden_string varchar, "
              + "\n\tcounter bigint, "
              + "\n\tdurationtime bigint"
              + "\n)"
              + "\npartition by hash key(a_iden_string) partition num 100"
              + "\nsubpartition by list (bdt bigint)"
              + "\nsubpartition options (available_Partition_Num = 90)"
              + "\ntablegroup g20_test_group",
          output);
    }
  }
Exemplo n.º 2
0
  @Test
  public void test_two() throws Exception {
    String sql =
        "CREATE TABLE `t_cpi_driskconfig_bak` ("
            + "`Sequence` bigint(20) NOT NULL AUTO_INCREMENT,"
            + "`comcode` binary(20) NOT NULL,"
            + "`riskcode` varchar(10) binary NOT NULL,"
            + "`configcodehead` varchar(30) binary NOT NULL,"
            + "`configcodebody` varchar(100) binary,"
            + "`configvalue` varchar(200) binary ,"
            + "`inputdate` datetime NOT NULL,"
            + "`validstatus` char(1) NOT NULL,"
            + "`remark` varchar(3000),"
            + "`flag` varchar(10) ,"
            + "PRIMARY KEY (`Sequence`)"
            + ") ENGINE=InnoDB AUTO_INCREMENT=49 DEFAULT CHARSET=utf8;";

    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseCreateTable();

    MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
    stmt.accept(visitor);

    //        System.out.println("Tables : " + visitor.getTables());
    //        System.out.println("fields : " + visitor.getColumns());
    //        System.out.println("coditions : " + visitor.getConditions());

    Assert.assertEquals(1, visitor.getTables().size());
    Assert.assertEquals(10, visitor.getColumns().size());
    Assert.assertEquals(0, visitor.getConditions().size());

    String output = SQLUtils.toMySqlString(stmt);
    Assert.assertEquals(
        "CREATE TABLE `t_cpi_driskconfig_bak` ("
            + "\n\t`Sequence` bigint(20) NOT NULL AUTO_INCREMENT, "
            + "\n\t`comcode` binary(20) NOT NULL, "
            + "\n\t`riskcode` varchar(10) BINARY  NOT NULL, "
            + "\n\t`configcodehead` varchar(30) BINARY  NOT NULL, "
            + "\n\t`configcodebody` varchar(100) BINARY , "
            + "\n\t`configvalue` varchar(200) BINARY , "
            + "\n\t`inputdate` datetime NOT NULL, "
            + "\n\t`validstatus` char(1) NOT NULL, "
            + "\n\t`remark` varchar(3000), "
            + "\n\t`flag` varchar(10), "
            + "\n\tPRIMARY KEY (`Sequence`)"
            + "\n) ENGINE = InnoDB AUTO_INCREMENT = 49 CHARSET = utf8",
        output);
  }
Exemplo n.º 3
0
  @Test
  public void test_one() throws Exception {
    String sql =
        "CREATE TABLE t (pk int auto_increment primary key, a TIMESTAMP, KEY ( a DESC ) );";

    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseCreateTable();

    MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
    stmt.accept(visitor);

    String output = SQLUtils.toMySqlString(stmt);
    Assert.assertEquals(
        "CREATE TABLE t ("
            + "\n\tpk int PRIMARY KEY AUTO_INCREMENT, "
            + "\n\ta TIMESTAMP, "
            + "\n\tKEY (a DESC)"
            + "\n)",
        output);
  }