yadavay-amzn commented on code in PR #56550:
URL: https://github.com/apache/spark/pull/56550#discussion_r3432151512
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala:
##########
@@ -354,6 +354,60 @@ object JdbcUtils extends Logging with SQLConfHelper {
internalRows.map(fromRow)
}
+ /**
+ * Estimates the size in bytes of a row given its schema. For
variable-length types
+ * (String, Binary), uses actual value size; for fixed-width types, uses
defaultSize.
+ * Null fields contribute 0 bytes.
+ */
+ private[jdbc] def estimateInternalRowSize(row: InternalRow, schema:
StructType): Long = {
+ var size = 0L
+ var i = 0
+ while (i < schema.length) {
+ if (!row.isNullAt(i)) {
+ schema.fields(i).dataType match {
+ case _: StringType =>
+ size += row.getUTF8String(i).numBytes()
+ case BinaryType =>
+ size += row.getBinary(i).length
+ case at: ArrayType =>
+ size += row.getArray(i).numElements().toLong *
at.elementType.defaultSize
Review Comment:
Thanks for the suggestion.
Now measures actual element content for variable-length elements
(`numBytes()`/array
length for String/Binary), allocation-free; fixed-width elements still use
`numElements * defaultSize`. So
`ARRAY(TEXT)/ARRAY(BYTEA)` are no longer estimated via defaultSize.
--
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]