-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Process pure ordering changes with windowing operators (#15241)
- adds a new query build path: DruidQuery#toScanAndSortQuery which: - builds a ScanQuery without considering the current ordering - builds an operator to execute the sort - fixes a null string to "null" literal string conversion in the frame serializer code - fixes some DrillWindowQueryTest cases - fix NPE in NaiveSortOperator in case there was no input - enables back CoreRules.AGGREGATE_REMOVE - adds a processing level OffsetLimit class and uses that instead of just the limit in the rac parts - earlier window expressions on top of a subquery with an offset may have ignored the offset
- Loading branch information
Showing
45 changed files
with
2,367 additions
and
345 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
processing/src/main/java/org/apache/druid/query/operator/OffsetLimit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.druid.query.operator; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.base.Preconditions; | ||
import java.util.Objects; | ||
|
||
public class OffsetLimit | ||
{ | ||
protected final long offset; | ||
protected final long limit; | ||
|
||
public static final OffsetLimit NONE = new OffsetLimit(0, -1); | ||
|
||
@JsonCreator | ||
public OffsetLimit( | ||
@JsonProperty("offset") long offset, | ||
@JsonProperty("limit") long limit) | ||
{ | ||
Preconditions.checkArgument(offset >= 0, "offset >= 0"); | ||
this.offset = offset; | ||
this.limit = limit < 0 ? -1 : limit; | ||
} | ||
|
||
@JsonProperty("offset") | ||
public long getOffset() | ||
{ | ||
return offset; | ||
} | ||
|
||
@JsonProperty("limit") | ||
public long getLimit() | ||
{ | ||
return limit; | ||
} | ||
|
||
public boolean isPresent() | ||
{ | ||
return hasOffset() || hasLimit(); | ||
} | ||
|
||
public boolean hasOffset() | ||
{ | ||
return offset > 0; | ||
} | ||
|
||
public boolean hasLimit() | ||
{ | ||
return limit >= 0; | ||
} | ||
|
||
public static OffsetLimit limit(int limit2) | ||
{ | ||
return new OffsetLimit(0, limit2); | ||
} | ||
|
||
public long getLimitOrMax() | ||
{ | ||
if (limit < 0) { | ||
return Long.MAX_VALUE; | ||
} else { | ||
return limit; | ||
} | ||
} | ||
|
||
@Override | ||
public final boolean equals(Object o) | ||
{ | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof OffsetLimit)) { | ||
return false; | ||
} | ||
OffsetLimit that = (OffsetLimit) o; | ||
return limit == that.limit && offset == that.offset; | ||
} | ||
|
||
@Override | ||
public final int hashCode() | ||
{ | ||
return Objects.hash(limit, offset); | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return "OffsetLimit{" + | ||
"offset=" + offset + | ||
", limit=" + limit + | ||
'}'; | ||
} | ||
|
||
/** | ||
* Returns the first row index to fetch. | ||
* | ||
* @param maxIndex maximal index accessible | ||
*/ | ||
public long getFromIndex(long maxIndex) | ||
{ | ||
if (maxIndex <= offset) { | ||
return 0; | ||
} | ||
return offset; | ||
} | ||
|
||
/** | ||
* Returns the last row index to fetch (non-inclusive). | ||
* | ||
* @param maxIndex maximal index accessible | ||
*/ | ||
public long getToIndex(long maxIndex) | ||
{ | ||
if (maxIndex <= offset) { | ||
return 0; | ||
} | ||
if (hasLimit()) { | ||
long toIndex = limit + offset; | ||
return Math.min(maxIndex, toIndex); | ||
} else { | ||
return maxIndex; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.