LuciferYang commented on code in PR #52988:
URL: https://github.com/apache/spark/pull/52988#discussion_r2513025321
##########
sql/connect/client/jdbc/src/main/scala/org/apache/spark/sql/connect/client/jdbc/SparkConnectResultSet.scala:
##########
@@ -76,6 +76,24 @@ class SparkConnectResultSet(
}
}
+ private[jdbc] def getColumnValue[T](columnIndex: Int, defaultVal: T)(getter:
Int => T): T = {
Review Comment:
Does this function need to be visible in `jdbc`?
##########
sql/connect/client/jdbc/src/main/scala/org/apache/spark/sql/connect/client/jdbc/SparkConnectResultSet.scala:
##########
@@ -85,75 +103,35 @@ class SparkConnectResultSet(
}
override def getString(columnIndex: Int): String = {
- if (currentRow.isNullAt(columnIndex - 1)) {
- _wasNull = true
- return null
- }
- _wasNull = false
- String.valueOf(currentRow.get(columnIndex - 1))
+ getColumnValue(columnIndex, null: String) { idx =>
String.valueOf(currentRow.get(idx)) }
}
override def getBoolean(columnIndex: Int): Boolean = {
- if (currentRow.isNullAt(columnIndex - 1)) {
- _wasNull = true
- return false
- }
- _wasNull = false
- currentRow.getBoolean(columnIndex - 1)
+ getColumnValue(columnIndex, false) { idx => currentRow.getBoolean(idx) }
}
override def getByte(columnIndex: Int): Byte = {
- if (currentRow.isNullAt(columnIndex - 1)) {
- _wasNull = true
- return 0.toByte
- }
- _wasNull = false
- currentRow.getByte(columnIndex - 1)
+ getColumnValue(columnIndex, 0.toByte) { idx => currentRow.getByte(idx) }
}
override def getShort(columnIndex: Int): Short = {
- if (currentRow.isNullAt(columnIndex - 1)) {
- _wasNull = true
- return 0.toShort
- }
- _wasNull = false
- currentRow.getShort(columnIndex - 1)
+ getColumnValue(columnIndex, 0.toShort) { idx => currentRow.getShort(idx) }
}
override def getInt(columnIndex: Int): Int = {
- if (currentRow.isNullAt(columnIndex - 1)) {
- _wasNull = true
- return 0
- }
- _wasNull = false
- currentRow.getInt(columnIndex - 1)
+ getColumnValue(columnIndex, 0.toInt) { idx => currentRow.getInt(idx) }
Review Comment:
```suggestion
getColumnValue(columnIndex, 0) { idx => currentRow.getInt(idx) }
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]