groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Sun (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8258) Create a LINQ-like DSL
Date Tue, 18 Jul 2017 00:09:00 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-8258?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16090835#comment-16090835
] 

Daniel Sun commented on GROOVY-8258:
------------------------------------

> But in terms of merging into the main branches, we could merge a PR that was improving
the underlying APIs to make them stream-aware (without any DSL)
Agreed.

Paul, maybe I did not express the proposal clearly. The DSL should consist of not only syntactic
sugar layer but also the backend, so it will be a big work ;)
We can design DSL and implement the underlying APIs at first and then implement the DSL, in
other words, the API design is driven by the DSL. e.g. In the following sample code, we can
find we need linq, from, of, join, on, where, orderBy, limit, offset, select methods, which
will appear in our underlying APIs.

{code:java}
linq { // return an Iterator<Map<String, Object>>
    from c of categories
    join a of articles on a.categoryName == c.name // join
    where c.name == 'Groovy'
    orderBy a.voteCount desc // order by
    limit 100 offset 50 // pagination
    select { // create a map, its keys: articleName, voteNum, categoryName
        articleName = a.name
        a.voteCount 
        categoryName = c.name
    }
}
{code}


> Create a LINQ-like DSL
> ----------------------
>
>                 Key: GROOVY-8258
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8258
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Daniel Sun
>
> *Pojos:*
> {code:java}
> class Category {
>    String name
>    List<Article> articles
> }
> class Article {
>   String name
>   Integer voteCount
>   String categoryName
> }
> {code}
> *Example1:*
> {code:java}
> linq { // return an Iterator<Map<String, Object>>
>     from c of categories
>     join a of articles on a.categoryName == c.name // join
>     where c.name == 'Groovy'
>     orderBy a.voteCount desc // order by
>     limit 100 offset 50 // pagination
>     select { // create a map, its keys: articleName, voteNum, categoryName
>         articleName = a.name
>         a.voteCount 
>         categoryName = c.name
>     }
> }
> {code}
> *Example2:*
> {code:java}
> linq { // return an Iterator<Map<String, Object>>
>     from c of categories
>     join a of {
>         from tempA of articles
>         where tempA.voteCount > 10
>         select tempA
>     } on a.categoryName == c.name // join
>     where c.name == 'Groovy'
>     orderBy a.voteCount desc // order by
>     limit 100 offset 50 // pagination
>     select { // create a map, its keys: articleName, voteNum, categoryName
>         articleName = a.name
>         a.voteCount 
>         categoryName = c.name
>     }
> }
> {code}
> *Example3:*
> {code:java}
> linq { // return an Iterator<Article>
>     from c of categories
>     from a of c.articles  // another join
>     where c.name == 'Groovy'
>     orderBy a.voteCount desc // order by
>     select Article { // create an Article instance
>         a.name
>         a.voteCount 
>         categoryName = c.name
>     }
> }
> {code}
> *TO BE CONTINUED...*



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message