示例#1
0
  public static void main(String[] args) throws IOException {
    // get the information of table address
    DatabaseCatalog databaseCatalog = DatabaseCatalog.getInstance();
    databaseCatalog.autogetTableInfo();
    Schema schema = Schema.getInstance();
    schema.getSchemaInfor("samples/input/db/schema.txt");
    Aliases aliases = Aliases.getInstance();
    //		aliases.addaliase("S", "Sailors");
    //		ScanOperator scanOperator = new ScanOperator("S");
    //		scanOperator.dump();

    try {
      CCJSqlParser parser =
          new CCJSqlParser(new FileReader("/Users/hanwenwang/Desktop/queries.sql"));
      Statement statement;
      while ((statement = parser.Statement()) != null) {
        Select select = (Select) statement;
        System.out.println("Select body is " + select.getSelectBody());
        PlainSelect plainSelect = (PlainSelect) select.getSelectBody();
        String aliasName = ((Table) plainSelect.getFromItem()).getAlias();
        String tableName = ((Table) plainSelect.getFromItem()).getName();
        aliases.addaliase(aliasName, tableName);
        ScanOperator scanOperator1 = new ScanOperator(aliasName);
        //				scanOperator1.dump();
        ProjectOperator projectOperator =
            new ProjectOperator(scanOperator1, plainSelect.getSelectItems());
        projectOperator.dump();
      }
    } catch (Exception e) {
      System.err.println("Exception occurred during parsing");
      e.printStackTrace();
    }
  }
  public static void main(String[] args) throws IOException {
    DatabaseCatalog tableMap = DatabaseCatalog.getInstance();
    tableMap.autogetTableInfo();
    System.out.println(tableMap.getTableLocated("Sailors"));
    Schema schema = Schema.getInstance();
    schema.getSchemaInfor("/Users/hanwenwang/Desktop/samples/input/db/schema.txt");

    try {
      CCJSqlParser parser =
          new CCJSqlParser(new FileReader("/Users/hanwenwang/Desktop/queries 2.sql"));

      Statement statement;
      while ((statement = parser.Statement()) != null) {

        Select select = (Select) statement;
        System.out.println("Select body is " + select.getSelectBody());
        PlainSelect plainSelect = (PlainSelect) select.getSelectBody();
        System.out.println(plainSelect.getSelectItems().toString());

        ScanOperator scanOperator = new ScanOperator(plainSelect.getFromItem().toString());
        SelectOperator selectOperator = new SelectOperator(scanOperator, plainSelect.getWhere());

        ProjectOperator projectOperator =
            new ProjectOperator(selectOperator, plainSelect.getSelectItems());
        projectOperator.dump();
      }
    } catch (Exception e) {
      System.err.println("Exception occurred during parsing");
      e.printStackTrace();
    }
  }