[ 
https://issues.apache.org/jira/browse/BEAM-5074?focusedWorklogId=131539&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-131539
 ]

ASF GitHub Bot logged work on BEAM-5074:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 06/Aug/18 19:44
            Start Date: 06/Aug/18 19:44
    Worklog Time Spent: 10m 
      Work Description: amaliujia commented on issue #6145: [BEAM-5074][SQL] 
improve BeamSqlRowComparator
URL: https://github.com/apache/beam/pull/6145#issuecomment-410830109
 
 
   @apilloud 
   
   `orientation` tells what should be the order on a field. If the query has 
`ASC` on a field, then `orientation` is true, and if the query has `DESC`, then 
`orientation` is false.
   
   However, if you observe what the code is written for `BeamSqlRowComparator` 
([code 
linik](https://github.com/apache/beam/blob/master/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rel/BeamSortRel.java#L320)),
 you can find this line:
   ```
   fieldRet *= (orientation.get(i) ? -1 : 1);
   ```
   
   The comparator will reverse the comparison result. For example, if it is 
`ASC` and `orientation` is true, and if fieldRet was `-1`, then fieldRet will 
become 1, which means smaller value will be put after the bigger value (the 
reversed order). 
   
   
   The reason this implementation is correct, as I tried to explain in the PR 
description, is that `ORDER BY LIMIT` uses `Top.of`. `Top` transform returns 
largest elements first (another reversed order), which finally made the SQL 
queries' results correct (ASC gives increasing order result and DESC gives 
decreasing order result). 
   
   
   The `isReversed`, in stead, allows we control the behavior of 
`BeamSqlRowComparator`.  The comparator will return -1 for `ASC` and 
1.compareTo(2) if `isReversed = false`, and 1 otherwise. Right now, the 
comparator returns 1 for `ASC` and 1.compareTo(2).
   
   It will be useful if I want to implement `ORDER BY ASC/DESC`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 131539)
    Time Spent: 40m  (was: 0.5h)

> Make BeamSqlRowComparator more general
> --------------------------------------
>
>                 Key: BEAM-5074
>                 URL: https://issues.apache.org/jira/browse/BEAM-5074
>             Project: Beam
>          Issue Type: Improvement
>          Components: dsl-sql
>            Reporter: Rui Wang
>            Assignee: Rui Wang
>            Priority: Major
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> BeamSqlRowComparator returns reversed comparison results (if a < b in terms 
> of value, BeamSqlRowComparator returns a > b). 
>  
> Add a flag to turn on/off this reversed effect. The reason of doing this is 
> to help implement ORDER BY ASC/DESC in the normal way.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to