Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.4合并排序有点问题 #336

Open
zhouwenbin2000 opened this issue Jun 4, 2015 · 3 comments · May be fixed by #1662
Open

1.4合并排序有点问题 #336

zhouwenbin2000 opened this issue Jun 4, 2015 · 3 comments · May be fixed by #1662

Comments

@zhouwenbin2000
Copy link

mysql> select create_time from test order by create_time limit 10;
+----------------------------+
| create_time |
+----------------------------+
| 2014-05-22 16:19:49 |
| 2014-05-28 20:44:58 |
| 2015-12-04 15:48:03 |
| 2014-05-28 11:18:49.91675 |
| 2014-05-26 18:27:22.434839 |
| 2014-05-26 18:40:48.106799 |
| 2014-05-26 18:49:25.626657 |
| 2014-05-26 18:53:31.944941 |
| 2014-05-26 19:04:00.222669 |
| 2014-05-26 21:10:37.869413 |
+----------------------------+
10 rows in set (0.02 sec)

从两个分片中取出数据,其中 2015-12-04 15:48:03 是native方式的mysql, 其他的是jdbc的postgresql

@magicdoom
Copy link
Contributor

估计跟这2种日期格式不一样有关系

@zhouwenbin2000
Copy link
Author

public static int compareNumberByte(byte[] b1, byte[] b2) {
if(b1 == null || b1.length == 0)
return -1;
else if(b2 == null || b2.length == 0)
return 1;
boolean isNegetive = b1[0] == 45 || b2[0] == 45;
if (isNegetive == false && b1.length != b2.length) {
return b1.length - b2.length;
}
int len = b1.length > b2.length ? b2.length : b1.length;
int result = 0;
int index = -1;
for (int i = 0; i < len; i++) {
int b1val = b1[i];
int b2val = b2[i];
if (b1val > b2val) {
result = 1;
index = i;
break;
} else if (b1val < b2val) {
index = i;
result = -1;
break;
}
}
if (index == 0) {
// first byte compare
return result;
} else {
if( b1.length != b2.length ) {

            int lenDelta = b1.length - b2.length;
            return isNegetive ? 0 - lenDelta : lenDelta;

        } else {
            return isNegetive ? 0 - result : result;
        }
    }
}

看了这块的比较逻辑,正数的话,只比较长度?? 这个逻辑有问题呀

@magicdoom
Copy link
Contributor

你可以修复下试试

@vantis-zh vantis-zh linked a pull request Oct 10, 2017 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants