Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add short circuit path for get-json-object when there is separate wildcard path #10734

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,51 @@ case class GpuGetJsonObject(json: Expression, path: Expression)
}
}

/**
* get_json_object(any_json, '$.*') always return null.
* '$.*' will be parsed to be a single `Wildcard`.
* Check whether has separated `Wildcard`
*
* @param instructions query path instructions
* @return true if has separated `Wildcard`, false otherwise.
*/
private def hasSeparateWildcard(instructions: Option[List[PathInstruction]]): Boolean = {
import PathInstruction._
def hasSeparate(ins: List[PathInstruction], idx: Int): Boolean = {
if (idx == 0) {
ins(0) match {
case Wildcard => true
case _ => false
}
} else {
(ins(idx - 1), ins(idx)) match {
case (Key, Wildcard) => false
case (Subscript, Wildcard) => false
case (_, Wildcard) => true
case _ => false
}
}
}

if (instructions.isEmpty) {
false
} else {
val list = instructions.get
list.indices.exists { idx => hasSeparate(list, idx) }
}
}

override def doColumnar(lhs: GpuColumnVector, rhs: GpuScalar): ColumnVector = {
cachedInstructions.getOrElse {
val pathInstructions = parseJsonPath(rhs)
cachedInstructions = Some(pathInstructions)
pathInstructions
val checkedPathInstructions = if (hasSeparateWildcard(pathInstructions)) {
// If has separate wildcard path, should return all nulls
None
} else {
pathInstructions
}
cachedInstructions = Some(checkedPathInstructions)
checkedPathInstructions
} match {
case Some(instructions) => {
val jniInstructions = JsonPathParser.convertToJniObject(instructions)
Expand Down
Loading