提交 b3f9834d authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Remember expression index in window frame bound

上级 05ea7099
...@@ -95,13 +95,12 @@ public abstract class AbstractAggregate extends DataAnalysisOperation { ...@@ -95,13 +95,12 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
boolean grouped = frame == null boolean grouped = frame == null
|| frame.getUnits() != WindowFrameUnits.ROWS && frame.getExclusion().isGroupOrNoOthers(); || frame.getUnits() != WindowFrameUnits.ROWS && frame.getExclusion().isGroupOrNoOthers();
if (frame == null) { if (frame == null) {
aggregateFastPartition(session, result, ordered, -1, rowIdColumn, grouped); aggregateFastPartition(session, result, ordered, rowIdColumn, grouped);
return; return;
} }
int frameParametersOffset = getWindowFrameParametersOffset();
boolean variableBounds = frame.isVariableBounds(); boolean variableBounds = frame.isVariableBounds();
if (variableBounds) { if (variableBounds) {
variableBounds = checkVariableBounds(frame, ordered, frameParametersOffset); variableBounds = checkVariableBounds(frame, ordered);
} }
if (variableBounds) { if (variableBounds) {
grouped = false; grouped = false;
...@@ -113,12 +112,12 @@ public abstract class AbstractAggregate extends DataAnalysisOperation { ...@@ -113,12 +112,12 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
if (unboundedFollowing) { if (unboundedFollowing) {
aggregateWholePartition(session, result, ordered, rowIdColumn); aggregateWholePartition(session, result, ordered, rowIdColumn);
} else { } else {
aggregateFastPartition(session, result, ordered, frameParametersOffset, rowIdColumn, grouped); aggregateFastPartition(session, result, ordered, rowIdColumn, grouped);
} }
return; return;
} }
if (unboundedFollowing) { if (unboundedFollowing) {
aggregateFastPartitionInReverse(session, result, ordered, frameParametersOffset, rowIdColumn, grouped); aggregateFastPartitionInReverse(session, result, ordered, rowIdColumn, grouped);
return; return;
} }
} }
...@@ -126,8 +125,8 @@ public abstract class AbstractAggregate extends DataAnalysisOperation { ...@@ -126,8 +125,8 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
int size = ordered.size(); int size = ordered.size();
for (int i = 0; i < size;) { for (int i = 0; i < size;) {
Object aggregateData = createAggregateData(); Object aggregateData = createAggregateData();
for (Iterator<Value[]> iter = WindowFrame.iterator(over, session, ordered, getOverOrderBySort(), for (Iterator<Value[]> iter = WindowFrame.iterator(over, session, ordered, getOverOrderBySort(), i,
frameParametersOffset, i, false); iter.hasNext();) { false); iter.hasNext();) {
updateFromExpressions(session, aggregateData, iter.next()); updateFromExpressions(session, aggregateData, iter.next());
} }
Value r = getAggregatedValue(session, aggregateData); Value r = getAggregatedValue(session, aggregateData);
...@@ -135,20 +134,21 @@ public abstract class AbstractAggregate extends DataAnalysisOperation { ...@@ -135,20 +134,21 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
} }
} }
private static boolean checkVariableBounds(WindowFrame frame, ArrayList<Value[]> ordered, private static boolean checkVariableBounds(WindowFrame frame, ArrayList<Value[]> ordered) {
int frameParametersOffset) {
int size = ordered.size(); int size = ordered.size();
int offset = frameParametersOffset; WindowFrameBound bound = frame.getStarting();
if (frame.getStarting().isVariable()) { if (bound.isVariable()) {
int offset = bound.getExpressionIndex();
Value v = ordered.get(0)[offset]; Value v = ordered.get(0)[offset];
for (int i = 1; i < size; i++) { for (int i = 1; i < size; i++) {
if (!v.equals(ordered.get(i)[offset])) { if (!v.equals(ordered.get(i)[offset])) {
return true; return true;
} }
} }
offset++;
} }
if (frame.getFollowing() != null && frame.getFollowing().isVariable()) { bound = frame.getFollowing();
if (bound != null && bound.isVariable()) {
int offset = bound.getExpressionIndex();
Value v = ordered.get(0)[offset]; Value v = ordered.get(0)[offset];
for (int i = 1; i < size; i++) { for (int i = 1; i < size; i++) {
if (!v.equals(ordered.get(i)[offset])) { if (!v.equals(ordered.get(i)[offset])) {
...@@ -160,14 +160,13 @@ public abstract class AbstractAggregate extends DataAnalysisOperation { ...@@ -160,14 +160,13 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
} }
private void aggregateFastPartition(Session session, HashMap<Integer, Value> result, ArrayList<Value[]> ordered, private void aggregateFastPartition(Session session, HashMap<Integer, Value> result, ArrayList<Value[]> ordered,
int frameParametersOffset, int rowIdColumn, boolean grouped) { int rowIdColumn, boolean grouped) {
Object aggregateData = createAggregateData(); Object aggregateData = createAggregateData();
int size = ordered.size(); int size = ordered.size();
int lastIncludedRow = -1; int lastIncludedRow = -1;
Value r = null; Value r = null;
for (int i = 0; i < size;) { for (int i = 0; i < size;) {
int newLast = WindowFrame.getEndIndex(over, session, ordered, frameParametersOffset, getOverOrderBySort(), int newLast = WindowFrame.getEndIndex(over, session, ordered, getOverOrderBySort(), i);
i);
assert newLast >= lastIncludedRow; assert newLast >= lastIncludedRow;
if (newLast > lastIncludedRow) { if (newLast > lastIncludedRow) {
for (int j = lastIncludedRow + 1; j <= newLast; j++) { for (int j = lastIncludedRow + 1; j <= newLast; j++) {
...@@ -183,13 +182,12 @@ public abstract class AbstractAggregate extends DataAnalysisOperation { ...@@ -183,13 +182,12 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
} }
private void aggregateFastPartitionInReverse(Session session, HashMap<Integer, Value> result, private void aggregateFastPartitionInReverse(Session session, HashMap<Integer, Value> result,
ArrayList<Value[]> ordered, int frameParametersOffset, int rowIdColumn, boolean grouped) { ArrayList<Value[]> ordered, int rowIdColumn, boolean grouped) {
Object aggregateData = createAggregateData(); Object aggregateData = createAggregateData();
int firstIncludedRow = ordered.size(); int firstIncludedRow = ordered.size();
Value r = null; Value r = null;
for (int i = firstIncludedRow - 1; i >= 0;) { for (int i = firstIncludedRow - 1; i >= 0;) {
int newLast = over.getWindowFrame().getStartIndex(session, ordered, frameParametersOffset, int newLast = over.getWindowFrame().getStartIndex(session, ordered, getOverOrderBySort(), i);
getOverOrderBySort(), i);
assert newLast <= firstIncludedRow; assert newLast <= firstIncludedRow;
if (newLast < firstIncludedRow) { if (newLast < firstIncludedRow) {
for (int j = firstIncludedRow - 1; j >= newLast; j--) { for (int j = firstIncludedRow - 1; j >= newLast; j--) {
......
...@@ -161,12 +161,19 @@ public abstract class DataAnalysisOperation extends Expression { ...@@ -161,12 +161,19 @@ public abstract class DataAnalysisOperation extends Expression {
} }
WindowFrame frame = over.getWindowFrame(); WindowFrame frame = over.getWindowFrame();
if (frame != null) { if (frame != null) {
int index = getNumExpressions();
if (orderBy != null) {
index += orderBy.size();
}
int n = 0; int n = 0;
if (frame.getStarting().isVariable()) { WindowFrameBound bound = frame.getStarting();
if (bound.isVariable()) {
bound.setExpressionIndex(index);
n++; n++;
} }
WindowFrameBound following = frame.getFollowing(); bound = frame.getFollowing();
if (following != null && following.isVariable()) { if (bound != null && bound.isVariable()) {
bound.setExpressionIndex(index + n);
n++; n++;
} }
numFrameExpressions = n; numFrameExpressions = n;
...@@ -358,20 +365,6 @@ public abstract class DataAnalysisOperation extends Expression { ...@@ -358,20 +365,6 @@ public abstract class DataAnalysisOperation extends Expression {
: getWindowResult(session, groupData); : getWindowResult(session, groupData);
} }
/**
* Returns offset of window frame parameters.
*
* @return offset of window frame parameters
*/
protected final int getWindowFrameParametersOffset() {
int frameParametersOffset = getNumExpressions();
ArrayList<SelectOrderBy> orderBy = over.getOrderBy();
if (orderBy != null) {
frameParametersOffset += orderBy.size();
}
return frameParametersOffset;
}
/** /**
* Returns result of this window function or window aggregate. This method * Returns result of this window function or window aggregate. This method
* is not used for plain aggregates. * is not used for plain aggregates.
......
...@@ -202,8 +202,6 @@ public final class WindowFrame { ...@@ -202,8 +202,6 @@ public final class WindowFrame {
* ordered rows * ordered rows
* @param sortOrder * @param sortOrder
* sort order * sort order
* @param frameParametersOffset
* offset of window frame parameters
* @param currentRow * @param currentRow
* index of the current row * index of the current row
* @param reverse * @param reverse
...@@ -211,10 +209,10 @@ public final class WindowFrame { ...@@ -211,10 +209,10 @@ public final class WindowFrame {
* @return iterator * @return iterator
*/ */
public static Iterator<Value[]> iterator(Window over, Session session, ArrayList<Value[]> orderedRows, public static Iterator<Value[]> iterator(Window over, Session session, ArrayList<Value[]> orderedRows,
SortOrder sortOrder, int frameParametersOffset, int currentRow, boolean reverse) { SortOrder sortOrder, int currentRow, boolean reverse) {
WindowFrame frame = over.getWindowFrame(); WindowFrame frame = over.getWindowFrame();
if (frame != null) { if (frame != null) {
return frame.iterator(session, orderedRows, sortOrder, frameParametersOffset, currentRow, reverse); return frame.iterator(session, orderedRows, sortOrder, currentRow, reverse);
} }
int endIndex = orderedRows.size() - 1; int endIndex = orderedRows.size() - 1;
return plainIterator(orderedRows, 0, return plainIterator(orderedRows, 0,
...@@ -232,8 +230,6 @@ public final class WindowFrame { ...@@ -232,8 +230,6 @@ public final class WindowFrame {
* the session * the session
* @param orderedRows * @param orderedRows
* ordered rows * ordered rows
* @param frameParametersOffset
* offset of window frame parameters
* @param sortOrder * @param sortOrder
* sort order * sort order
* @param currentRow * @param currentRow
...@@ -243,11 +239,11 @@ public final class WindowFrame { ...@@ -243,11 +239,11 @@ public final class WindowFrame {
* if over is not null and its exclusion clause is not EXCLUDE * if over is not null and its exclusion clause is not EXCLUDE
* NO OTHERS * NO OTHERS
*/ */
public static int getEndIndex(Window over, Session session, ArrayList<Value[]> orderedRows, public static int getEndIndex(Window over, Session session, ArrayList<Value[]> orderedRows, SortOrder sortOrder,
int frameParametersOffset, SortOrder sortOrder, int currentRow) { int currentRow) {
WindowFrame frame = over.getWindowFrame(); WindowFrame frame = over.getWindowFrame();
if (frame != null) { if (frame != null) {
return frame.getEndIndex(session, orderedRows, frameParametersOffset, sortOrder, currentRow); return frame.getEndIndex(session, orderedRows, sortOrder, currentRow);
} }
int endIndex = orderedRows.size() - 1; int endIndex = orderedRows.size() - 1;
return over.getOrderBy() == null ? endIndex : toGroupEnd(orderedRows, sortOrder, currentRow, endIndex); return over.getOrderBy() == null ? endIndex : toGroupEnd(orderedRows, sortOrder, currentRow, endIndex);
...@@ -291,8 +287,8 @@ public final class WindowFrame { ...@@ -291,8 +287,8 @@ public final class WindowFrame {
return offset; return offset;
} }
private static int getIntOffset(WindowFrameBound bound, Value[] values, int parameterOffset, Session session) { private static int getIntOffset(WindowFrameBound bound, Value[] values, Session session) {
Value v = bound.isVariable() ? values[parameterOffset] : bound.getValue().getValue(session); Value v = bound.isVariable() ? values[bound.getExpressionIndex()] : bound.getValue().getValue(session);
int value = v.getInt(); int value = v.getInt();
if (value < 0) { if (value < 0) {
throw DbException.getInvalidValueException("unsigned", value); throw DbException.getInvalidValueException("unsigned", value);
...@@ -301,20 +297,20 @@ public final class WindowFrame { ...@@ -301,20 +297,20 @@ public final class WindowFrame {
} }
private static Value[] getCompareRow(Session session, ArrayList<Value[]> orderedRows, SortOrder sortOrder, private static Value[] getCompareRow(Session session, ArrayList<Value[]> orderedRows, SortOrder sortOrder,
int currentRow, WindowFrameBound bound, int parameterOffset, boolean add) { int currentRow, WindowFrameBound bound, boolean add) {
int sortIndex = sortOrder.getQueryColumnIndexes()[0]; int sortIndex = sortOrder.getQueryColumnIndexes()[0];
OpType opType = add ^ (sortOrder.getSortTypes()[0] & SortOrder.DESCENDING) != 0 ? OpType.PLUS : OpType.MINUS; OpType opType = add ^ (sortOrder.getSortTypes()[0] & SortOrder.DESCENDING) != 0 ? OpType.PLUS : OpType.MINUS;
Value[] row = orderedRows.get(currentRow); Value[] row = orderedRows.get(currentRow);
Value[] newRow = row.clone(); Value[] newRow = row.clone();
newRow[sortIndex] = new BinaryOperation(opType, // newRow[sortIndex] = new BinaryOperation(opType, //
ValueExpression.get(row[sortIndex]), ValueExpression.get(row[sortIndex]),
ValueExpression.get(getValueOffset(bound, orderedRows.get(currentRow), parameterOffset, session))) ValueExpression.get(getValueOffset(bound, orderedRows.get(currentRow), session))) //
.optimize(session).getValue(session); .optimize(session).getValue(session);
return newRow; return newRow;
} }
private static Value getValueOffset(WindowFrameBound bound, Value[] values, int parameterOffset, Session session) { private static Value getValueOffset(WindowFrameBound bound, Value[] values, Session session) {
Value value = bound.isVariable() ? values[parameterOffset] : bound.getValue().getValue(session); Value value = bound.isVariable() ? values[bound.getExpressionIndex()] : bound.getValue().getValue(session);
if (value.getSignum() < 0) { if (value.getSignum() < 0) {
throw DbException.getInvalidValueException("unsigned", value.getTraceSQL()); throw DbException.getInvalidValueException("unsigned", value.getTraceSQL());
} }
...@@ -463,8 +459,6 @@ public final class WindowFrame { ...@@ -463,8 +459,6 @@ public final class WindowFrame {
* ordered rows * ordered rows
* @param sortOrder * @param sortOrder
* sort order * sort order
* @param frameParametersOffset
* offset of window frame parameters
* @param currentRow * @param currentRow
* index of the current row * index of the current row
* @param reverse * @param reverse
...@@ -472,14 +466,9 @@ public final class WindowFrame { ...@@ -472,14 +466,9 @@ public final class WindowFrame {
* @return iterator * @return iterator
*/ */
public Iterator<Value[]> iterator(Session session, ArrayList<Value[]> orderedRows, SortOrder sortOrder, public Iterator<Value[]> iterator(Session session, ArrayList<Value[]> orderedRows, SortOrder sortOrder,
int frameParametersOffset, int currentRow, boolean reverse) { int currentRow, boolean reverse) {
int followingOffset = frameParametersOffset; int startIndex = getIndex(session, orderedRows, sortOrder, currentRow, starting, false);
if (starting.isVariable()) { int endIndex = following != null ? getIndex(session, orderedRows, sortOrder, currentRow, following, true)
followingOffset++;
}
int startIndex = getIndex(session, orderedRows, sortOrder, currentRow, starting, frameParametersOffset, false);
int endIndex = following != null
? getIndex(session, orderedRows, sortOrder, currentRow, following, followingOffset, true)
: units == WindowFrameUnits.ROWS ? currentRow : units == WindowFrameUnits.ROWS ? currentRow
: toGroupEnd(orderedRows, sortOrder, currentRow, orderedRows.size() - 1); : toGroupEnd(orderedRows, sortOrder, currentRow, orderedRows.size() - 1);
if (endIndex < startIndex) { if (endIndex < startIndex) {
...@@ -507,8 +496,6 @@ public final class WindowFrame { ...@@ -507,8 +496,6 @@ public final class WindowFrame {
* the session * the session
* @param orderedRows * @param orderedRows
* ordered rows * ordered rows
* @param frameParametersOffset
* offset of window frame parameters
* @param sortOrder * @param sortOrder
* sort order * sort order
* @param currentRow * @param currentRow
...@@ -517,12 +504,11 @@ public final class WindowFrame { ...@@ -517,12 +504,11 @@ public final class WindowFrame {
* @throws UnsupportedOperationException * @throws UnsupportedOperationException
* if exclusion clause is not EXCLUDE NO OTHERS * if exclusion clause is not EXCLUDE NO OTHERS
*/ */
public int getStartIndex(Session session, ArrayList<Value[]> orderedRows, int frameParametersOffset, public int getStartIndex(Session session, ArrayList<Value[]> orderedRows, SortOrder sortOrder, int currentRow) {
SortOrder sortOrder, int currentRow) {
if (exclusion != WindowFrameExclusion.EXCLUDE_NO_OTHERS) { if (exclusion != WindowFrameExclusion.EXCLUDE_NO_OTHERS) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
int startIndex = getIndex(session, orderedRows, sortOrder, currentRow, starting, frameParametersOffset, false); int startIndex = getIndex(session, orderedRows, sortOrder, currentRow, starting, false);
if (startIndex < 0) { if (startIndex < 0) {
startIndex = 0; startIndex = 0;
} }
...@@ -536,8 +522,6 @@ public final class WindowFrame { ...@@ -536,8 +522,6 @@ public final class WindowFrame {
* the session * the session
* @param orderedRows * @param orderedRows
* ordered rows * ordered rows
* @param frameParametersOffset
* offset of window frame parameters
* @param sortOrder * @param sortOrder
* sort order * sort order
* @param currentRow * @param currentRow
...@@ -546,17 +530,11 @@ public final class WindowFrame { ...@@ -546,17 +530,11 @@ public final class WindowFrame {
* @throws UnsupportedOperationException * @throws UnsupportedOperationException
* if exclusion clause is not EXCLUDE NO OTHERS * if exclusion clause is not EXCLUDE NO OTHERS
*/ */
private int getEndIndex(Session session, ArrayList<Value[]> orderedRows, int frameParametersOffset, private int getEndIndex(Session session, ArrayList<Value[]> orderedRows, SortOrder sortOrder, int currentRow) {
SortOrder sortOrder, int currentRow) {
if (exclusion != WindowFrameExclusion.EXCLUDE_NO_OTHERS) { if (exclusion != WindowFrameExclusion.EXCLUDE_NO_OTHERS) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
int followingOffset = frameParametersOffset; int endIndex = following != null ? getIndex(session, orderedRows, sortOrder, currentRow, following, true)
if (starting.isVariable()) {
followingOffset++;
}
int endIndex = following != null
? getIndex(session, orderedRows, sortOrder, currentRow, following, followingOffset, true)
: units == WindowFrameUnits.ROWS ? currentRow : units == WindowFrameUnits.ROWS ? currentRow
: toGroupEnd(orderedRows, sortOrder, currentRow, orderedRows.size() - 1); : toGroupEnd(orderedRows, sortOrder, currentRow, orderedRows.size() - 1);
int size = orderedRows.size(); int size = orderedRows.size();
...@@ -567,7 +545,7 @@ public final class WindowFrame { ...@@ -567,7 +545,7 @@ public final class WindowFrame {
} }
private int getIndex(Session session, ArrayList<Value[]> orderedRows, SortOrder sortOrder, int currentRow, private int getIndex(Session session, ArrayList<Value[]> orderedRows, SortOrder sortOrder, int currentRow,
WindowFrameBound bound, int parameterOffset, boolean forFollowing) { WindowFrameBound bound, boolean forFollowing) {
int size = orderedRows.size(); int size = orderedRows.size();
int last = size - 1; int last = size - 1;
int index; int index;
...@@ -578,12 +556,12 @@ public final class WindowFrame { ...@@ -578,12 +556,12 @@ public final class WindowFrame {
case PRECEDING: case PRECEDING:
switch (units) { switch (units) {
case ROWS: { case ROWS: {
int value = getIntOffset(bound, orderedRows.get(currentRow), parameterOffset, session); int value = getIntOffset(bound, orderedRows.get(currentRow), session);
index = value > currentRow ? -1 : currentRow - value; index = value > currentRow ? -1 : currentRow - value;
break; break;
} }
case GROUPS: { case GROUPS: {
int value = getIntOffset(bound, orderedRows.get(currentRow), parameterOffset, session); int value = getIntOffset(bound, orderedRows.get(currentRow), session);
if (!forFollowing) { if (!forFollowing) {
index = toGroupStart(orderedRows, sortOrder, currentRow, 0); index = toGroupStart(orderedRows, sortOrder, currentRow, 0);
while (value > 0 && index > 0) { while (value > 0 && index > 0) {
...@@ -608,7 +586,7 @@ public final class WindowFrame { ...@@ -608,7 +586,7 @@ public final class WindowFrame {
} }
case RANGE: { case RANGE: {
index = currentRow; index = currentRow;
Value[] row = getCompareRow(session, orderedRows, sortOrder, index, bound, parameterOffset, false); Value[] row = getCompareRow(session, orderedRows, sortOrder, index, bound, false);
index = Collections.binarySearch(orderedRows, row, sortOrder); index = Collections.binarySearch(orderedRows, row, sortOrder);
if (index >= 0) { if (index >= 0) {
if (!forFollowing) { if (!forFollowing) {
...@@ -653,13 +631,13 @@ public final class WindowFrame { ...@@ -653,13 +631,13 @@ public final class WindowFrame {
case FOLLOWING: case FOLLOWING:
switch (units) { switch (units) {
case ROWS: { case ROWS: {
int value = getIntOffset(bound, orderedRows.get(currentRow), parameterOffset, session); int value = getIntOffset(bound, orderedRows.get(currentRow), session);
int rem = last - currentRow; int rem = last - currentRow;
index = value > rem ? size : currentRow + value; index = value > rem ? size : currentRow + value;
break; break;
} }
case GROUPS: { case GROUPS: {
int value = getIntOffset(bound, orderedRows.get(currentRow), parameterOffset, session); int value = getIntOffset(bound, orderedRows.get(currentRow), session);
if (forFollowing) { if (forFollowing) {
index = toGroupEnd(orderedRows, sortOrder, currentRow, last); index = toGroupEnd(orderedRows, sortOrder, currentRow, last);
while (value > 0 && index < last) { while (value > 0 && index < last) {
...@@ -684,7 +662,7 @@ public final class WindowFrame { ...@@ -684,7 +662,7 @@ public final class WindowFrame {
} }
case RANGE: { case RANGE: {
index = currentRow; index = currentRow;
Value[] row = getCompareRow(session, orderedRows, sortOrder, index, bound, parameterOffset, true); Value[] row = getCompareRow(session, orderedRows, sortOrder, index, bound, true);
index = Collections.binarySearch(orderedRows, row, sortOrder); index = Collections.binarySearch(orderedRows, row, sortOrder);
if (index >= 0) { if (index >= 0) {
if (forFollowing) { if (forFollowing) {
......
...@@ -20,6 +20,8 @@ public class WindowFrameBound { ...@@ -20,6 +20,8 @@ public class WindowFrameBound {
private boolean isVariable; private boolean isVariable;
private int expressionIndex = -1;
/** /**
* Creates new instance of window frame bound. * Creates new instance of window frame bound.
* *
...@@ -65,6 +67,25 @@ public class WindowFrameBound { ...@@ -65,6 +67,25 @@ public class WindowFrameBound {
return isVariable; return isVariable;
} }
/**
* Returns the index of preserved expression.
*
* @return the index of preserved expression, or -1
*/
public int getExpressionIndex() {
return expressionIndex;
}
/**
* Sets the index of preserved expression.
*
* @param expressionIndex
* the index to set
*/
void setExpressionIndex(int expressionIndex) {
this.expressionIndex = expressionIndex;
}
/** /**
* Map the columns of the resolver to expression columns. * Map the columns of the resolver to expression columns.
* *
......
...@@ -349,19 +349,18 @@ public class WindowFunction extends DataAnalysisOperation { ...@@ -349,19 +349,18 @@ public class WindowFunction extends DataAnalysisOperation {
private void getNth(Session session, HashMap<Integer, Value> result, ArrayList<Value[]> ordered, int rowIdColumn) { private void getNth(Session session, HashMap<Integer, Value> result, ArrayList<Value[]> ordered, int rowIdColumn) {
int size = ordered.size(); int size = ordered.size();
int frameParametersOffset = getWindowFrameParametersOffset();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
Value[] row = ordered.get(i); Value[] row = ordered.get(i);
int rowId = row[rowIdColumn].getInt(); int rowId = row[rowIdColumn].getInt();
Value v; Value v;
switch (type) { switch (type) {
case FIRST_VALUE: case FIRST_VALUE:
v = getNthValue(WindowFrame.iterator(over, session, ordered, getOverOrderBySort(), v = getNthValue(WindowFrame.iterator(over, session, ordered, getOverOrderBySort(), i, false), 0,
frameParametersOffset, i, false), 0, ignoreNulls); ignoreNulls);
break; break;
case LAST_VALUE: case LAST_VALUE:
v = getNthValue(WindowFrame.iterator(over, session, ordered, getOverOrderBySort(), v = getNthValue(WindowFrame.iterator(over, session, ordered, getOverOrderBySort(), i, true), 0,
frameParametersOffset, i, true), 0, ignoreNulls); ignoreNulls);
break; break;
case NTH_VALUE: { case NTH_VALUE: {
int n = row[1].getInt(); int n = row[1].getInt();
...@@ -369,8 +368,8 @@ public class WindowFunction extends DataAnalysisOperation { ...@@ -369,8 +368,8 @@ public class WindowFunction extends DataAnalysisOperation {
throw DbException.getInvalidValueException("nth row", n); throw DbException.getInvalidValueException("nth row", n);
} }
n--; n--;
Iterator<Value[]> iter = WindowFrame.iterator(over, session, ordered, getOverOrderBySort(), Iterator<Value[]> iter = WindowFrame.iterator(over, session, ordered, getOverOrderBySort(), i,
frameParametersOffset, i, fromLast); fromLast);
v = getNthValue(iter, n, ignoreNulls); v = getNthValue(iter, n, ignoreNulls);
break; break;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论