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

Add ValueArray.getEmpty()

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