提交 85a79304 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add ValueArray.getEmpty()

上级 d185228a
...@@ -64,12 +64,6 @@ public abstract class SelectGroups { ...@@ -64,12 +64,6 @@ public abstract class SelectGroups {
*/ */
private Iterator<Entry<ValueArray, Object[]>> cursor; private Iterator<Entry<ValueArray, Object[]>> cursor;
/**
* The key for the default group.
*/
// Can be static, but TestClearReferences complains about it
private final ValueArray defaultGroup = ValueArray.get(new Value[0]);
Grouped(Session session, ArrayList<Expression> expressions, int[] groupIndex) { Grouped(Session session, ArrayList<Expression> expressions, int[] groupIndex) {
super(session, expressions); super(session, expressions);
this.groupIndex = groupIndex; this.groupIndex = groupIndex;
...@@ -86,7 +80,7 @@ public abstract class SelectGroups { ...@@ -86,7 +80,7 @@ public abstract class SelectGroups {
@Override @Override
public void nextSource() { public void nextSource() {
if (groupIndex == null) { if (groupIndex == null) {
currentGroupsKey = defaultGroup; currentGroupsKey = ValueArray.getEmpty();
} else { } else {
Value[] keyValues = new Value[groupIndex.length]; Value[] keyValues = new Value[groupIndex.length];
// update group // update group
...@@ -120,7 +114,7 @@ public abstract class SelectGroups { ...@@ -120,7 +114,7 @@ public abstract class SelectGroups {
public void done() { public void done() {
super.done(); super.done();
if (groupIndex == null && groupByData.size() == 0) { if (groupIndex == null && groupByData.size() == 0) {
groupByData.put(defaultGroup, createRow()); groupByData.put(ValueArray.getEmpty(), createRow());
} }
cursor = groupByData.entrySet().iterator(); cursor = groupByData.entrySet().iterator();
} }
...@@ -185,10 +179,9 @@ public abstract class SelectGroups { ...@@ -185,10 +179,9 @@ public abstract class SelectGroups {
@Override @Override
public ValueArray next() { public ValueArray next() {
if (cursor.hasNext()) { if (cursor.hasNext()) {
Object[] values = cursor.next(); currentGroupByExprData = cursor.next();
currentGroupByExprData = values;
currentGroupRowId++; currentGroupRowId++;
return ValueArray.get(new Value[0]); return ValueArray.getEmpty();
} }
return null; return null;
} }
......
...@@ -54,7 +54,7 @@ class AggregateDataHistogram extends AggregateData { ...@@ -54,7 +54,7 @@ class AggregateDataHistogram extends AggregateData {
@Override @Override
Value getValue(Database database, int dataType) { Value getValue(Database database, int dataType) {
if (distinctValues == null) { if (distinctValues == null) {
return ValueArray.get(new Value[0]).convertTo(dataType); return ValueArray.getEmpty().convertTo(dataType);
} }
ValueArray[] values = new ValueArray[distinctValues.size()]; ValueArray[] values = new ValueArray[distinctValues.size()];
int i = 0; int i = 0;
......
...@@ -20,6 +20,11 @@ import org.h2.util.StatementBuilder; ...@@ -20,6 +20,11 @@ import org.h2.util.StatementBuilder;
*/ */
public class ValueArray extends Value { public class ValueArray extends Value {
/**
* Empty array.
*/
private static final Object EMPTY = get(new Value[0]);
private final Class<?> componentType; private final Class<?> componentType;
private final Value[] values; private final Value[] values;
private int hash; private int hash;
...@@ -52,6 +57,15 @@ public class ValueArray extends Value { ...@@ -52,6 +57,15 @@ public class ValueArray extends Value {
return new ValueArray(componentType, list); return new ValueArray(componentType, list);
} }
/**
* Returns empty array.
*
* @return empty array
*/
public static ValueArray getEmpty() {
return (ValueArray) EMPTY;
}
@Override @Override
public int hashCode() { public int hashCode() {
if (hash != 0) { if (hash != 0) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论