Skip to content

The limitations of RawSqlBuild.parse #3649

@wenzhihong2003

Description

@wenzhihong2003

The RawSqlBuild.parse() method of Ebean can only handle very simple SQL structures. The reason for this is that during the parsing of the SQL, it only parses based on the keywords in the string. For example, the following SQL will cause an error when parsed by RawSqlBuild.parse().

String sql = """
            WITH AggregatedData AS (
              select
                  company_id,
                  company_name,
                  spool_type,
                  sum(lend_num) as lend_num,
                  sum(return_num) as return_num,
                  sum(remain_num) as remain_num,
                  sum(sum(remain_num)) over (partition by company_id) as company_total_remain
              from
                  reelnoreturn_view
              ${where}
              group by  company_id, company_name, spool_type
          )
          select
              company_id,
              company_name,
              spool_type,
              lend_num,
              return_num,
              remain_num
          from
              AggregatedData
          order by
              company_total_remain desc,  company_id,  spool_type
          """;
        RawSql rawSql = RawSqlBuilder.parse(sql).create();
        Query<EReelNoReturnAgg> query = db.createQuery(EReelNoReturnAgg.class).setRawSql(rawSql);
        if (isNotEmpty(companyName)) {
            query.where().contains("company_name", companyName);
       
        }

Is there any plan to enhance this part? For example, introducing a library like jsqlparse to parse the SQL into an abstract syntax tree(ASM), and then modifying the syntax nodes based on the query?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions