提交 7f5c3510 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Return long results from row number and rank functions

上级 59d222f5
...@@ -5335,10 +5335,10 @@ SELECT CUME_DIST() OVER (PARTITION BY CATEGORY ORDER BY ID), * FROM TEST; ...@@ -5335,10 +5335,10 @@ SELECT CUME_DIST() OVER (PARTITION BY CATEGORY ORDER BY ID), * FROM TEST;
" "
"Functions (Window)","NTILE"," "Functions (Window)","NTILE","
NTILE(int) OVER windowNameOrSpecification NTILE(long) OVER windowNameOrSpecification
"," ","
Distributes the rows into a specified number of groups. Distributes the rows into a specified number of groups.
Number of groups should be a positive integer value. Number of groups should be a positive long value.
NTILE returns the 1-based number of the group to which the current row belongs. NTILE returns the 1-based number of the group to which the current row belongs.
First groups will have more rows if number of rows is not divisible by number of groups. First groups will have more rows if number of rows is not divisible by number of groups.
For example, if 5 rows are distributed into 2 groups this function returns 1 for the first 3 row and 2 for the last 2 rows. For example, if 5 rows are distributed into 2 groups this function returns 1 for the first 3 row and 2 for the last 2 rows.
......
...@@ -18,7 +18,7 @@ import org.h2.table.ColumnResolver; ...@@ -18,7 +18,7 @@ import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter; import org.h2.table.TableFilter;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueDouble; import org.h2.value.ValueDouble;
import org.h2.value.ValueInt; import org.h2.value.ValueLong;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
/** /**
...@@ -184,7 +184,7 @@ public class WindowFunction extends DataAnalysisOperation { ...@@ -184,7 +184,7 @@ public class WindowFunction extends DataAnalysisOperation {
switch (type) { switch (type) {
case ROW_NUMBER: case ROW_NUMBER:
for (int i = 0, size = ordered.size(); i < size;) { for (int i = 0, size = ordered.size(); i < size;) {
result.put(ordered.get(i)[rowIdColumn].getInt(), ValueInt.get(++i)); result.put(ordered.get(i)[rowIdColumn].getInt(), ValueLong.get(++i));
} }
break; break;
case RANK: case RANK:
...@@ -231,7 +231,7 @@ public class WindowFunction extends DataAnalysisOperation { ...@@ -231,7 +231,7 @@ public class WindowFunction extends DataAnalysisOperation {
int nm = number - 1; int nm = number - 1;
v = nm == 0 ? ValueDouble.ZERO : ValueDouble.get((double) nm / (size - 1)); v = nm == 0 ? ValueDouble.ZERO : ValueDouble.get((double) nm / (size - 1));
} else { } else {
v = ValueInt.get(number); v = ValueLong.get(number);
} }
result.put(row[rowIdColumn].getInt(), v); result.put(row[rowIdColumn].getInt(), v);
} }
...@@ -260,20 +260,20 @@ public class WindowFunction extends DataAnalysisOperation { ...@@ -260,20 +260,20 @@ public class WindowFunction extends DataAnalysisOperation {
int size = orderedData.size(); int size = orderedData.size();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
Value[] array = orderedData.get(i); Value[] array = orderedData.get(i);
int buckets = array[0].getInt(); long buckets = array[0].getLong();
if (buckets <= 0) { if (buckets <= 0) {
throw DbException.getInvalidValueException("number of tiles", buckets); throw DbException.getInvalidValueException("number of tiles", buckets);
} }
int perTile = size / buckets; long perTile = size / buckets;
int numLarger = size - perTile * buckets; long numLarger = size - perTile * buckets;
int largerGroup = numLarger * (perTile + 1); long largerGroup = numLarger * (perTile + 1);
int v; long v;
if (i >= largerGroup) { if (i >= largerGroup) {
v = (i - largerGroup) / perTile + numLarger + 1; v = (i - largerGroup) / perTile + numLarger + 1;
} else { } else {
v = i / (perTile + 1) + 1; v = i / (perTile + 1) + 1;
} }
result.put(orderedData.get(i)[last].getInt(), ValueInt.get(v)); result.put(orderedData.get(i)[last].getInt(), ValueLong.get(v));
} }
} }
...@@ -441,7 +441,7 @@ public class WindowFunction extends DataAnalysisOperation { ...@@ -441,7 +441,7 @@ public class WindowFunction extends DataAnalysisOperation {
case RANK: case RANK:
case DENSE_RANK: case DENSE_RANK:
case NTILE: case NTILE:
return Value.INT; return Value.LONG;
case PERCENT_RANK: case PERCENT_RANK:
case CUME_DIST: case CUME_DIST:
return Value.DOUBLE; return Value.DOUBLE;
...@@ -477,7 +477,7 @@ public class WindowFunction extends DataAnalysisOperation { ...@@ -477,7 +477,7 @@ public class WindowFunction extends DataAnalysisOperation {
case RANK: case RANK:
case DENSE_RANK: case DENSE_RANK:
case NTILE: case NTILE:
return ValueInt.PRECISION; return ValueLong.PRECISION;
case PERCENT_RANK: case PERCENT_RANK:
case CUME_DIST: case CUME_DIST:
return ValueDouble.PRECISION; return ValueDouble.PRECISION;
...@@ -499,7 +499,7 @@ public class WindowFunction extends DataAnalysisOperation { ...@@ -499,7 +499,7 @@ public class WindowFunction extends DataAnalysisOperation {
case RANK: case RANK:
case DENSE_RANK: case DENSE_RANK:
case NTILE: case NTILE:
return ValueInt.DISPLAY_SIZE; return ValueLong.DISPLAY_SIZE;
case PERCENT_RANK: case PERCENT_RANK:
case CUME_DIST: case CUME_DIST:
return ValueDouble.DISPLAY_SIZE; return ValueDouble.DISPLAY_SIZE;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论