aokolnychyi commented on code in PR #57487:
URL: https://github.com/apache/spark/pull/57487#discussion_r3686287837
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Relation.scala:
##########
@@ -419,22 +438,24 @@ object DataSourceV2Relation {
*/
def transformV2Stats(
v2Statistics: V2Statistics,
- defaultRowCount: Option[BigInt],
defaultSizeInBytes: Long,
output: Seq[Attribute] = Seq.empty): Statistics = {
val numRows: Option[BigInt] = if (v2Statistics.numRows().isPresent) {
Some(v2Statistics.numRows().getAsLong)
} else {
- defaultRowCount
+ None
}
var colStats: Seq[(Attribute, ColumnStat)] = Seq.empty[(Attribute,
ColumnStat)]
- if (!v2Statistics.columnStats().isEmpty) {
- val v2ColumnStat = v2Statistics.columnStats()
- val keys = v2ColumnStat.keySet()
+ // columnStats() may be null even when numRows/sizeInBytes are present, so
normalize it to an
+ // empty map before conversion to avoid an NPE.
+ val v2ColumnStats = Option(v2Statistics.columnStats())
+ .getOrElse(java.util.Collections.emptyMap[NamedReference,
ColumnStatistics]())
Review Comment:
Not a big fan of a fully qualified import given that we already have imports
for some other Java classes. I would also consider a constant like
EMPTY_V2_COLUMN_STATS or something.
--
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]