1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package edu.caltech.nanodb.queryeval;
/**
* This class holds some useful statistics for a specific column. At present
* this consists of the following:
* <ul>
* <li>the number of unique values in the column (not including <tt>NULL</tt>
* in the count)</li>
* <li>the number of <tt>NULL</tt> values in the column</li>
* <li>the minimum value for the column</li>
* <li>the maximum value for the column</li>
* </ul>
* The {@link ColumnStatsCollector} class can be used to easily collect these
* statistics for a particular column of a table.
*/
public class ColumnStats {
/**
* The total number of unique values for this column in the table, or -1 if
* the total number of unique values is unknown.
*/
private int numUniqueValues;
/**
* The total number of <tt>NULL</tt> values for this column in the table,
* or -1 if the total number of <tt>NULL</tt> values is unknown.
*/
private int numNullValues;
/**
* The minimum value of this column in the table, or <tt>null</tt> if the
* minimum value is unknown.
*/
private Object minValue;
/**
* The maximum value of this column in the table, or <tt>null</tt> if the
* maximum value is unknown.
*/
private Object maxValue;
/**
* Initializes a column-stats object with the specified values.
*
* @param numUniqueValues the number of unique values in the column, or -1
* if unknown
* @param numNullValues the number of <tt>NULL</tt> values in the column, or
* -1 if unknown
* @param minValue the minimum value in the column, or <tt>null</tt> if
* unknown
* @param maxValue the maximum value in the column, or <tt>null</tt> if
* unknown
*/
public ColumnStats(int numUniqueValues, int numNullValues,
Object minValue, Object maxValue) {
setNumUniqueValues(numUniqueValues);
setNumNullValues(numNullValues);
setMinValue(minValue);
setMaxValue(maxValue);
}
/** Initializes a column-stats object to all "unknown" values. */
public ColumnStats() {
this(-1, -1, null, null);
}
/** Copies another column-stats object into this object. */
public ColumnStats(ColumnStats stats) {
this(stats.numUniqueValues, stats.numNullValues,
stats.minValue, stats.maxValue);
}
/**
* Returns the number of unique values for the column, or -1 if the number
* is unknown
*
* @return the number of unique values for the column, or -1 if the number
* is unknown
*/
public int getNumUniqueValues() {
return numUniqueValues;
}
/**
* Sets the number of unique values for the column.
*
* @param num the number of unique values in the table for the column, or
* -1 if the number if unknown
*/
public void setNumUniqueValues(int num) {
if (num < -1) {
throw new IllegalArgumentException(
"Number of unique values must be >= -1; got " + num);
}
numUniqueValues = num;
}
/**
* Returns the number of <tt>NULL</tt> values for the column, or -1 if the
* number is unknown
*
* @return the number of <tt>NULL</tt> values for the column, or -1 if the
* number is unknown
*/
public int getNumNullValues() {
return numNullValues;
}
/**
* Sets the number of <tt>NULL</tt> values for the column.
*
* @param num the number of <tt>NULL</tt> values in the table for the
* column, or -1 if the number if unknown
*/
public void setNumNullValues(int num) {
if (num < -1) {
throw new IllegalArgumentException(
"Number of NULL values must be >= -1; got " + num);
}
numNullValues = num;
}
/**
* Returns the minimum value for the column.
*
* @return the minimum value in the table for the column
*/
public Object getMinValue() {
return minValue;
}
/**
* Sets the minimum value for the column.
*
* @param minValue the minimum value in the table for the column
*/
public void setMinValue(Object minValue) {
this.minValue = minValue;
}
/**
* Returns the maximum value for the column.
*
* @return the maximum value in the table for the column
*/
public Object getMaxValue() {
return maxValue;
}
/**
* Sets the maximum value for the column.
*
* @param maxValue the maximum value in the table for the column
*/
public void setMaxValue(Object maxValue) {
this.maxValue = maxValue;
}
/**
* Returns <tt>true</tt> if this column-stats object has both minimum and
* maximum values.
*
* @return <tt>true</tt> if this column-stats object has both minimum and
* maximum values
*/
public boolean hasMinMaxValues() {
return (minValue != null && maxValue != null);
}
/**
* Returns <tt>true</tt> if this column-stats object has both minimum and
* maximum values, and they are actually different values.
*
* @return <tt>true</tt> if this column-stats object has both minimum and
* maximum values, and they are actually different values.
*/
public boolean hasDifferentMinMaxValues() {
return hasMinMaxValues() && (!minValue.equals(maxValue));
}
}