Skip to content

Commit

Permalink
empty string to 0 in lower version
Browse files Browse the repository at this point in the history
Signed-off-by: Haoyang Li <[email protected]>
  • Loading branch information
thirtiseven committed Dec 27, 2023
1 parent e6d3f97 commit fa515ae
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,20 @@ case class GpuAscii(child: Expression) extends GpuUnaryExpression with ImplicitC
override def inputTypes: Seq[AbstractDataType] = Seq(StringType)

override def doColumnar(input: GpuColumnVector): ColumnVector = {
val emptyMask = withResource(Scalar.fromString("")) { emptyScalar =>
input.getBase.equalTo(emptyScalar)
}
val emptyReplaced = withResource(emptyMask) { _ =>
// replace empty strings with 'NUL' (which will convert to ascii 0)
withResource(Scalar.fromString('\u0000'.toString)) { zeroScalar =>
emptyMask.ifElse(zeroScalar, input.getBase)
}
}
// convert to byte lists
val firstBytes = withResource(input.getBase.asByteList) { bytes =>
val byteLists = withResource(emptyReplaced) { _ =>
emptyReplaced.asByteList()
}
val firstBytes = withResource(byteLists) { bytes =>
bytes.extractListElement(0)
}
val firstBytesInt = withResource(firstBytes) { _ =>
Expand Down

0 comments on commit fa515ae

Please sign in to comment.