-
Notifications
You must be signed in to change notification settings - Fork 912
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KYUUBI #360] Correct handle getNextRowSet with FETCH_PRIOR FETCH_FIRST
![pan3793](https://badgen.net/badge/Hello/pan3793/green) [![Closes #370](https://badgen.net/badge/Preview/Closes%20%23370/blue)](https://github.com/yaooqinn/kyuubi/pull/370) ![332](https://badgen.net/badge/%2B/332/red) ![24](https://badgen.net/badge/-/24/green) ![8](https://badgen.net/badge/commits/8/yellow) ![Feature](https://badgen.net/badge/Label/Feature/) ![Bug](https://badgen.net/badge/Label/Bug/) [❨?❩](https://pullrequestbadge.com/?utm_medium=github&utm_source=yaooqinn&utm_campaign=badge_info)<!-- PR-BADGE: PLEASE DO NOT REMOVE THIS COMMENT --> <!-- Thanks for sending a pull request! Here are some tips for you: 1. If this is your first time, please read our contributor guidelines: https://kyuubi.readthedocs.io/en/latest/community/contributions.html 2. If the PR is related to an issue in https://github.com/yaooqinn/kyuubi/issues, add '[KYUUBI #XXXX]' in your PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'. 3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][KYUUBI #XXXX] Your PR title ...'. --> ### _Why are the changes needed?_ <!-- Please clarify why the changes are needed. For instance, 1. If you add a feature, you can talk about the use case of it. 2. If you fix a bug, you can clarify why it is a bug. --> close #360 Ref: apache/spark#30600 ### _How was this patch tested?_ - [x] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [x] [Run test](https://kyuubi.readthedocs.io/en/latest/tools/testing.html#running-tests) locally before make a pull request Closes #370 from pan3793/KYUUBI-360. e79b8cb [Cheng Pan] [KYUUBI #360] comments 0fae3db [Cheng Pan] fix import 3d1b2a6 [Cheng Pan] [KYUUBI #360] fix ut eda3e59 [Cheng Pan] [KYUUBI #360] fix import 16178d6 [Cheng Pan] [KYUUBI #360] ut 179404d [Cheng Pan] [KYUUBI #360] nit 455af6b [Cheng Pan] [KYUUBI #360] correct getNextRowSet with FETCH_PRIOR FETCH_FIRST 2307f1f [Cheng Pan] [KYUUBI #360] move ThriftUtils to kyuubi-common Authored-by: Cheng Pan <379377944@qq.com> Signed-off-by: Kent Yao <yao@apache.org>
- Loading branch information
Showing
19 changed files
with
332 additions
and
24 deletions.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
...kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/FetchIterator.scala
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,110 @@ | ||
/* | ||
* 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.kyuubi.engine.spark | ||
|
||
/** | ||
* Borrowed from Apache Spark, see SPARK-33655 | ||
*/ | ||
private[engine] sealed trait FetchIterator[A] extends Iterator[A] { | ||
/** | ||
* Begin a fetch block, forward from the current position. | ||
* Resets the fetch start offset. | ||
*/ | ||
def fetchNext(): Unit | ||
|
||
/** | ||
* Begin a fetch block, moving the iterator back by offset from the start of the previous fetch | ||
* block start. | ||
* Resets the fetch start offset. | ||
* | ||
* @param offset the amount to move a fetch start position toward the prior direction. | ||
*/ | ||
def fetchPrior(offset: Long): Unit = fetchAbsolute(getFetchStart - offset) | ||
|
||
/** | ||
* Begin a fetch block, moving the iterator to the given position. | ||
* Resets the fetch start offset. | ||
* | ||
* @param pos index to move a position of iterator. | ||
*/ | ||
def fetchAbsolute(pos: Long): Unit | ||
|
||
def getFetchStart: Long | ||
|
||
def getPosition: Long | ||
} | ||
|
||
private[engine] class ArrayFetchIterator[A](src: Array[A]) extends FetchIterator[A] { | ||
private var fetchStart: Long = 0 | ||
|
||
private var position: Long = 0 | ||
|
||
override def fetchNext(): Unit = fetchStart = position | ||
|
||
override def fetchAbsolute(pos: Long): Unit = { | ||
position = (pos max 0) min src.length | ||
fetchStart = position | ||
} | ||
|
||
override def getFetchStart: Long = fetchStart | ||
|
||
override def getPosition: Long = position | ||
|
||
override def hasNext: Boolean = position < src.length | ||
|
||
override def next(): A = { | ||
position += 1 | ||
src(position.toInt - 1) | ||
} | ||
} | ||
|
||
private[engine] class IterableFetchIterator[A](iterable: Iterable[A]) extends FetchIterator[A] { | ||
private var iter: Iterator[A] = iterable.iterator | ||
|
||
private var fetchStart: Long = 0 | ||
|
||
private var position: Long = 0 | ||
|
||
override def fetchNext(): Unit = fetchStart = position | ||
|
||
override def fetchAbsolute(pos: Long): Unit = { | ||
val newPos = pos max 0 | ||
if (newPos < position) resetPosition() | ||
while (position < newPos && hasNext) next() | ||
fetchStart = position | ||
} | ||
|
||
override def getFetchStart: Long = fetchStart | ||
|
||
override def getPosition: Long = position | ||
|
||
override def hasNext: Boolean = iter.hasNext | ||
|
||
override def next(): A = { | ||
position += 1 | ||
iter.next() | ||
} | ||
|
||
private def resetPosition(): Unit = { | ||
if (position != 0) { | ||
iter = iterable.iterator | ||
position = 0 | ||
fetchStart = 0 | ||
} | ||
} | ||
} |
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
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
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.