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

Move stage constants to DataAnalysisOperation

上级 2e263d53
...@@ -25,7 +25,7 @@ import org.h2.expression.ExpressionColumn; ...@@ -25,7 +25,7 @@ import org.h2.expression.ExpressionColumn;
import org.h2.expression.ExpressionVisitor; import org.h2.expression.ExpressionVisitor;
import org.h2.expression.Parameter; import org.h2.expression.Parameter;
import org.h2.expression.Wildcard; import org.h2.expression.Wildcard;
import org.h2.expression.aggregate.Aggregate; import org.h2.expression.analysis.DataAnalysisOperation;
import org.h2.expression.analysis.Window; import org.h2.expression.analysis.Window;
import org.h2.index.Cursor; import org.h2.index.Cursor;
import org.h2.index.Index; import org.h2.index.Index;
...@@ -389,7 +389,7 @@ public class Select extends Query { ...@@ -389,7 +389,7 @@ public class Select extends Query {
private void queryWindow(int columnCount, LocalResult result, long offset, boolean quickOffset) { private void queryWindow(int columnCount, LocalResult result, long offset, boolean quickOffset) {
initGroupData(columnCount); initGroupData(columnCount);
try { try {
gatherGroup(columnCount, Aggregate.STAGE_WINDOW); gatherGroup(columnCount, DataAnalysisOperation.STAGE_WINDOW);
processGroupResult(columnCount, result, offset, quickOffset); processGroupResult(columnCount, result, offset, quickOffset);
} finally { } finally {
groupData.reset(); groupData.reset();
...@@ -399,12 +399,12 @@ public class Select extends Query { ...@@ -399,12 +399,12 @@ public class Select extends Query {
private void queryGroupWindow(int columnCount, LocalResult result, long offset, boolean quickOffset) { private void queryGroupWindow(int columnCount, LocalResult result, long offset, boolean quickOffset) {
initGroupData(columnCount); initGroupData(columnCount);
try { try {
gatherGroup(columnCount, Aggregate.STAGE_GROUP); gatherGroup(columnCount, DataAnalysisOperation.STAGE_GROUP);
try { try {
isGroupWindowStage2 = true; isGroupWindowStage2 = true;
while (groupData.next() != null) { while (groupData.next() != null) {
if (havingIndex < 0 || expressions.get(havingIndex).getBooleanValue(session)) { if (havingIndex < 0 || expressions.get(havingIndex).getBooleanValue(session)) {
updateAgg(columnCount, Aggregate.STAGE_WINDOW); updateAgg(columnCount, DataAnalysisOperation.STAGE_WINDOW);
} else { } else {
groupData.remove(); groupData.remove();
} }
...@@ -422,7 +422,7 @@ public class Select extends Query { ...@@ -422,7 +422,7 @@ public class Select extends Query {
private void queryGroup(int columnCount, LocalResult result, long offset, boolean quickOffset) { private void queryGroup(int columnCount, LocalResult result, long offset, boolean quickOffset) {
initGroupData(columnCount); initGroupData(columnCount);
try { try {
gatherGroup(columnCount, Aggregate.STAGE_GROUP); gatherGroup(columnCount, DataAnalysisOperation.STAGE_GROUP);
processGroupResult(columnCount, result, offset, quickOffset); processGroupResult(columnCount, result, offset, quickOffset);
} finally { } finally {
groupData.reset(); groupData.reset();
...@@ -433,7 +433,7 @@ public class Select extends Query { ...@@ -433,7 +433,7 @@ public class Select extends Query {
if (groupData == null) { if (groupData == null) {
groupData = SelectGroups.getInstance(session, expressions, isGroupQuery, groupIndex); groupData = SelectGroups.getInstance(session, expressions, isGroupQuery, groupIndex);
} else { } else {
updateAgg(columnCount, Aggregate.STAGE_RESET); updateAgg(columnCount, DataAnalysisOperation.STAGE_RESET);
} }
groupData.reset(); groupData.reset();
} }
...@@ -1742,7 +1742,7 @@ public class Select extends Query { ...@@ -1742,7 +1742,7 @@ public class Select extends Query {
groupData = SelectGroups.getInstance(getSession(), Select.this.expressions, isGroupQuery, groupIndex); groupData = SelectGroups.getInstance(getSession(), Select.this.expressions, isGroupQuery, groupIndex);
} else { } else {
// TODO is this branch possible? // TODO is this branch possible?
updateAgg(columnCount, Aggregate.STAGE_RESET); updateAgg(columnCount, DataAnalysisOperation.STAGE_RESET);
groupData.resetLazy(); groupData.resetLazy();
} }
} }
...@@ -1778,7 +1778,7 @@ public class Select extends Query { ...@@ -1778,7 +1778,7 @@ public class Select extends Query {
groupData.nextLazyGroup(); groupData.nextLazyGroup();
} }
groupData.nextLazyRow(); groupData.nextLazyRow();
updateAgg(columnCount, Aggregate.STAGE_GROUP); updateAgg(columnCount, DataAnalysisOperation.STAGE_GROUP);
if (row != null) { if (row != null) {
return row; return row;
} }
......
...@@ -155,21 +155,6 @@ public class Aggregate extends AbstractAggregate { ...@@ -155,21 +155,6 @@ public class Aggregate extends AbstractAggregate {
ENVELOPE, ENVELOPE,
} }
/**
* Reset stage. Used to reset internal data to its initial state.
*/
public static final int STAGE_RESET = 0;
/**
* Group stage, used for explicit or implicit GROUP BY operation.
*/
public static final int STAGE_GROUP = 1;
/**
* Window processing stage.
*/
public static final int STAGE_WINDOW = 2;
private static final HashMap<String, AggregateType> AGGREGATES = new HashMap<>(64); private static final HashMap<String, AggregateType> AGGREGATES = new HashMap<>(64);
private final AggregateType type; private final AggregateType type;
......
...@@ -16,7 +16,6 @@ import org.h2.command.dml.SelectOrderBy; ...@@ -16,7 +16,6 @@ import org.h2.command.dml.SelectOrderBy;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.expression.Expression; import org.h2.expression.Expression;
import org.h2.expression.ExpressionVisitor; import org.h2.expression.ExpressionVisitor;
import org.h2.expression.aggregate.Aggregate;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.result.SortOrder; import org.h2.result.SortOrder;
import org.h2.table.ColumnResolver; import org.h2.table.ColumnResolver;
...@@ -30,6 +29,21 @@ import org.h2.value.ValueInt; ...@@ -30,6 +29,21 @@ import org.h2.value.ValueInt;
*/ */
public abstract class DataAnalysisOperation extends Expression { public abstract class DataAnalysisOperation extends Expression {
/**
* Reset stage. Used to reset internal data to its initial state.
*/
public static final int STAGE_RESET = 0;
/**
* Group stage, used for explicit or implicit GROUP BY operation.
*/
public static final int STAGE_GROUP = 1;
/**
* Window processing stage.
*/
public static final int STAGE_WINDOW = 2;
protected final Select select; protected final Select select;
protected Window over; protected Window over;
...@@ -126,12 +140,12 @@ public abstract class DataAnalysisOperation extends Expression { ...@@ -126,12 +140,12 @@ public abstract class DataAnalysisOperation extends Expression {
@Override @Override
public final void updateAggregate(Session session, int stage) { public final void updateAggregate(Session session, int stage) {
if (stage == Aggregate.STAGE_RESET) { if (stage == STAGE_RESET) {
updateGroupAggregates(session, Aggregate.STAGE_RESET); updateGroupAggregates(session, STAGE_RESET);
lastGroupRowId = 0; lastGroupRowId = 0;
return; return;
} }
boolean window = stage == Aggregate.STAGE_WINDOW; boolean window = stage == STAGE_WINDOW;
if (window != (over != null)) { if (window != (over != null)) {
if (!window && select.isWindowQuery()) { if (!window && select.isWindowQuery()) {
updateGroupAggregates(session, stage); updateGroupAggregates(session, stage);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论