pvary commented on a change in pull request #538: HIVE-21217: Optimize range
calculation for PTF
URL: https://github.com/apache/hive/pull/538#discussion_r257278647
##########
File path:
ql/src/java/org/apache/hadoop/hive/ql/udf/ptf/ValueBoundaryScanner.java
##########
@@ -44,10 +49,207 @@ public ValueBoundaryScanner(BoundaryDef start,
BoundaryDef end, boolean nullsLas
this.nullsLast = nullsLast;
}
+ public abstract Object computeValue(Object row) throws HiveException;
+
+ /**
+ * Checks if the distance of v2 to v1 is greater than the given amt.
+ * @return True if the value of v1 - v2 is greater than amt or either value
is null.
+ */
+ public abstract boolean isDistanceGreater(Object v1, Object v2, int amt);
+
+ /**
+ * Checks if the values of v1 or v2 are the same.
+ * @return True if both values are the same or both are nulls.
+ */
+ public abstract boolean isEqual(Object v1, Object v2);
+
public abstract int computeStart(int rowIdx, PTFPartition p) throws
HiveException;
public abstract int computeEnd(int rowIdx, PTFPartition p) throws
HiveException;
+ /**
+ * Checks and maintains cache content - optimizes cache window to always be
around current row
+ * thereby makes it follow the current progress.
+ * @param rowIdx current row
+ * @param p current partition for the PTF operator
+ * @throws HiveException
+ */
+ public void handleCache(int rowIdx, PTFPartition p) throws HiveException {
+ BoundaryCache cache = p.getBoundaryCache();
+ if (cache == null) {
+ return;
+ }
+
+ //Start of partition
+ if (rowIdx == 0) {
+ cache.clear();
+ }
+ if (cache.isComplete()) {
+ return;
+ }
+
+ int cachePos = cache.approxCachePositionOf(rowIdx);
+
+ if (cache.isEmpty()) {
+ fillCacheUntilEndOrFull(rowIdx, p);
+ } else if (cachePos > 50 && cachePos <= 75) {
Review comment:
This is strange to me. Do we know the size of the window in advance? Shall
we not use our cache accordingly? If the window size is 5 then we should cache
the 7 values (1 before, 1 after, and the 5 values)?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services