[ 
https://issues.apache.org/jira/browse/KYLIN-4327?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Yifei Wu updated KYLIN-4327:
----------------------------
    Description: 
in current TopN, it  should save top(k) result and keep it in double value, 
just like this:
```
public class Counter<T> implements Serializable{
    ...
    protected T item;
    protected double count;

    ...
}
```
But its Comparator method use  "=="  directly to compare the result, it may 
cause the error  "*violate its general contract*" when calling it.
```
          private static final Comparator ASC_COMPARATOR = new 
Comparator<Counter>() {
        @Override
        public int compare(Counter o1, Counter o2) {
            return o1.getCount() > o2.getCount() ? 1 : o1.getCount() == 
o2.getCount() ? 0 : -1;
        }

    };

```

  was:
in current TopN, it  should save top(k) result and keep it in double value, 
just like this:
```
public class Counter<T> implements Serializable{
    ...
    protected T item;
    protected double count;

    ...
}
```
But its Comparator method use  "=="  directly to compare the result, it may 
cause the error  "*violate its general contract*" when calling it 
```
            return o1.getCount() > o2.getCount() ? 1 : o1.getCount() == 
o2.getCount() ? 0 : -1;

```


> TOPN Comparator may  violate its general contract
> -------------------------------------------------
>
>                 Key: KYLIN-4327
>                 URL: https://issues.apache.org/jira/browse/KYLIN-4327
>             Project: Kylin
>          Issue Type: Improvement
>            Reporter: Yifei Wu
>            Assignee: Yifei Wu
>            Priority: Minor
>
> in current TopN, it  should save top(k) result and keep it in double value, 
> just like this:
> ```
> public class Counter<T> implements Serializable{
>     ...
>     protected T item;
>     protected double count;
>     ...
> }
> ```
> But its Comparator method use  "=="  directly to compare the result, it may 
> cause the error  "*violate its general contract*" when calling it.
> ```
>           private static final Comparator ASC_COMPARATOR = new 
> Comparator<Counter>() {
>         @Override
>         public int compare(Counter o1, Counter o2) {
>             return o1.getCount() > o2.getCount() ? 1 : o1.getCount() == 
> o2.getCount() ? 0 : -1;
>         }
>     };
> ```



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to