提交 f3ac8c41 authored 作者: thomasmueller's avatar thomasmueller

Javadocs

上级 145b71b5
...@@ -311,7 +311,7 @@ public class Aggregate extends Expression { ...@@ -311,7 +311,7 @@ public class Aggregate extends Expression {
return v; return v;
} }
case MEDIAN: { case MEDIAN: {
return AggregateDataMedian.getFromIndex(session, on, dataType); return AggregateDataMedian.getResultFromIndex(session, on, dataType);
} }
default: default:
DbException.throwInternalError("type=" + type); DbException.throwInternalError("type=" + type);
......
...@@ -49,6 +49,12 @@ class AggregateDataMedian extends AggregateData { ...@@ -49,6 +49,12 @@ class AggregateDataMedian extends AggregateData {
|| (sortType & SortOrder.DESCENDING) != 0 && (sortType & SortOrder.NULLS_FIRST) == 0; || (sortType & SortOrder.DESCENDING) != 0 && (sortType & SortOrder.NULLS_FIRST) == 0;
} }
/**
* Get the index (if any) for the column specified in the median aggregate.
*
* @param on the expression (usually a column expression)
* @return the index, or null
*/
static Index getMedianColumnIndex(Expression on) { static Index getMedianColumnIndex(Expression on) {
if (on instanceof ExpressionColumn) { if (on instanceof ExpressionColumn) {
ExpressionColumn col = (ExpressionColumn) on; ExpressionColumn col = (ExpressionColumn) on;
...@@ -68,8 +74,8 @@ class AggregateDataMedian extends AggregateData { ...@@ -68,8 +74,8 @@ class AggregateDataMedian extends AggregateData {
if (!index.isFirstColumn(column)) { if (!index.isFirstColumn(column)) {
continue; continue;
} }
if (result == null || result.getColumns().length > index.getColumns().length
// Prefer index without nulls last for nullable columns // Prefer index without nulls last for nullable columns
if (result == null || result.getColumns().length > index.getColumns().length
|| nullable && isNullsLast(result) && !isNullsLast(index)) { || nullable && isNullsLast(result) && !isNullsLast(index)) {
result = index; result = index;
} }
...@@ -81,7 +87,15 @@ class AggregateDataMedian extends AggregateData { ...@@ -81,7 +87,15 @@ class AggregateDataMedian extends AggregateData {
return null; return null;
} }
static Value getFromIndex(Session session, Expression on, int dataType) { /**
* Get the result from the index.
*
* @param session the session
* @param on the expression
* @param dataType the data type
* @return the result
*/
static Value getResultFromIndex(Session session, Expression on, int dataType) {
Index index = getMedianColumnIndex(on); Index index = getMedianColumnIndex(on);
long count = index.getRowCount(session); long count = index.getRowCount(session);
if (count == 0) { if (count == 0) {
...@@ -94,10 +108,8 @@ class AggregateDataMedian extends AggregateData { ...@@ -94,10 +108,8 @@ class AggregateDataMedian extends AggregateData {
if (expr.getColumn().isNullable()) { if (expr.getColumn().isNullable()) {
boolean hasNulls = false; boolean hasNulls = false;
SearchRow row; SearchRow row;
/* // Try to skip nulls from the start first with the same cursor that
* Try to skip nulls from the start first with the same cursor that will be used // will be used to read values.
* to read values.
*/
while (count > 0) { while (count > 0) {
row = cursor.getSearchRow(); row = cursor.getSearchRow();
if (row == null) { if (row == null) {
...@@ -113,10 +125,8 @@ class AggregateDataMedian extends AggregateData { ...@@ -113,10 +125,8 @@ class AggregateDataMedian extends AggregateData {
if (count == 0) { if (count == 0) {
return ValueNull.INSTANCE; return ValueNull.INSTANCE;
} }
/* // If no nulls found and if index orders nulls last create a second
* If no nulls found and if index orders nulls last create a second cursor to // cursor to count nulls at the end.
* count nulls at the end.
*/
if (!hasNulls && isNullsLast(index)) { if (!hasNulls && isNullsLast(index)) {
TableFilter tableFilter = expr.getTableFilter(); TableFilter tableFilter = expr.getTableFilter();
SearchRow check = tableFilter.getTable().getTemplateSimpleRow(true); SearchRow check = tableFilter.getTable().getTemplateSimpleRow(true);
...@@ -196,7 +206,7 @@ class AggregateDataMedian extends AggregateData { ...@@ -196,7 +206,7 @@ class AggregateDataMedian extends AggregateData {
return getMedian(a[idx - 1], v1, dataType, mode); return getMedian(a[idx - 1], v1, dataType, mode);
} }
static Value getMedian(Value v0, Value v1, int dataType, CompareMode mode) { private static Value getMedian(Value v0, Value v1, int dataType, CompareMode mode) {
if (v0.compareTo(v1, mode) == 0) { if (v0.compareTo(v1, mode) == 0) {
return v0.convertTo(dataType); return v0.convertTo(dataType);
} }
......
...@@ -57,7 +57,7 @@ public class ConditionInParameter extends Condition { ...@@ -57,7 +57,7 @@ public class ConditionInParameter extends Condition {
private Expression left; private Expression left;
final Parameter parameter; private final Parameter parameter;
/** /**
* Create a new {@code = ANY(?)} condition. * Create a new {@code = ANY(?)} condition.
......
...@@ -17,7 +17,20 @@ import org.h2.test.TestBase; ...@@ -17,7 +17,20 @@ import org.h2.test.TestBase;
*/ */
public abstract class AbstractBaseForCommonTableExpressions extends TestBase { public abstract class AbstractBaseForCommonTableExpressions extends TestBase {
protected void testRepeatedQueryWithSetup(int maxRetries, String[] expectedRowData, String[] expectedColumnNames, /**
* Test a query.
*
* @param maxRetries the number of times the query is run
* @param expectedRowData the expected result data
* @param expectedColumnNames the expected columns of the result
* @param expectedNumberOfRows the expected number of rows
* @param setupSQL the SQL statement used for setup
* @param withQuery the query
* @param closeAndReopenDatabaseConnectionOnIteration whether the connection
* should be re-opened each time
* @param expectedColumnTypes the expected datatypes of the result
*/
void testRepeatedQueryWithSetup(int maxRetries, String[] expectedRowData, String[] expectedColumnNames,
int expectedNumberOfRows, String setupSQL, String withQuery, int expectedNumberOfRows, String setupSQL, String withQuery,
int closeAndReopenDatabaseConnectionOnIteration, String[] expectedColumnTypes) throws SQLException { int closeAndReopenDatabaseConnectionOnIteration, String[] expectedColumnTypes) throws SQLException {
......
...@@ -63,7 +63,8 @@ public class TestDateTimeUtils extends TestBase { ...@@ -63,7 +63,8 @@ public class TestDateTimeUtils extends TestBase {
int isoDow = (dow + 5) % 7 + 1; int isoDow = (dow + 5) % 7 + 1;
assertEquals(isoDow, DateTimeUtils.getIsoDayOfWeek(dateValue)); assertEquals(isoDow, DateTimeUtils.getIsoDayOfWeek(dateValue));
assertEquals(gc.get(Calendar.WEEK_OF_YEAR), assertEquals(gc.get(Calendar.WEEK_OF_YEAR),
DateTimeUtils.getWeekOfYear(dateValue, gc.getFirstDayOfWeek() - 1, gc.getMinimalDaysInFirstWeek())); DateTimeUtils.getWeekOfYear(dateValue, gc.getFirstDayOfWeek() - 1,
gc.getMinimalDaysInFirstWeek()));
} }
} }
...@@ -83,7 +84,8 @@ public class TestDateTimeUtils extends TestBase { ...@@ -83,7 +84,8 @@ public class TestDateTimeUtils extends TestBase {
gc.clear(); gc.clear();
gc.setTimeInMillis(i * 86400000L); gc.setTimeInMillis(i * 86400000L);
assertEquals(gc.get(Calendar.DAY_OF_YEAR), DateTimeUtils.getDayOfYear(dateValue)); assertEquals(gc.get(Calendar.DAY_OF_YEAR), DateTimeUtils.getDayOfYear(dateValue));
assertEquals(gc.get(Calendar.WEEK_OF_YEAR), DateTimeUtils.getWeekOfYear(dateValue, firstDay - 1, minimalDays)); assertEquals(gc.get(Calendar.WEEK_OF_YEAR),
DateTimeUtils.getWeekOfYear(dateValue, firstDay - 1, minimalDays));
assertEquals(gc.getWeekYear(), DateTimeUtils.getWeekYear(dateValue, firstDay - 1, minimalDays)); assertEquals(gc.getWeekYear(), DateTimeUtils.getWeekYear(dateValue, firstDay - 1, minimalDays));
} }
} }
......
...@@ -763,3 +763,6 @@ assorted reimplemented hangups confirmation predefined ...@@ -763,3 +763,6 @@ assorted reimplemented hangups confirmation predefined
mdy destfile hclf forbids spellchecking selfdestruct expects accident jacocoagent cli historic mitigate mdy destfile hclf forbids spellchecking selfdestruct expects accident jacocoagent cli historic mitigate
jacoco xdata invokes sourcefiles classfiles duplication crypto stacktraces prt directions handled overly asm hardcoded jacoco xdata invokes sourcefiles classfiles duplication crypto stacktraces prt directions handled overly asm hardcoded
interpolated thead interpolated thead
die weekdiff osx subprocess dow proleptic
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论