techaddict commented on code in PR #39104: URL: https://github.com/apache/spark/pull/39104#discussion_r1051389905
########## core/src/main/scala/org/apache/spark/status/protobuf/RDDStorageInfoWrapperSerializer.scala: ########## @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.spark.status.protobuf + +import scala.collection.JavaConverters._ + +import org.apache.spark.status.RDDStorageInfoWrapper +import org.apache.spark.status.api.v1.{RDDDataDistribution, RDDPartitionInfo, RDDStorageInfo} +import org.apache.spark.status.protobuf.Utils.getOptional + +object RDDStorageInfoWrapperSerializer { + def serialize(input: RDDStorageInfoWrapper): Array[Byte] = { + val builder = StoreTypes.RDDStorageInfoWrapper.newBuilder() + builder.setInfo(serializeRDDStorageInfo(input.info)) + builder.build().toByteArray + } + + def deserialize(bytes: Array[Byte]): RDDStorageInfoWrapper = { + val wrapper = StoreTypes.RDDStorageInfoWrapper.parseFrom(bytes) + new RDDStorageInfoWrapper( + info = deserializeRDDStorageInfo(wrapper.getInfo) + ) + } + + private def serializeRDDStorageInfo(info: RDDStorageInfo): StoreTypes.RDDStorageInfo = { + val builder = StoreTypes.RDDStorageInfo.newBuilder() + builder.setId(info.id) + builder.setName(info.name) + builder.setNumPartitions(info.numPartitions) + builder.setNumCachedPartitions(info.numCachedPartitions) + builder.setStorageLevel(info.storageLevel) + builder.setMemoryUsed(info.memoryUsed) + builder.setDiskUsed(info.diskUsed) + + if (info.dataDistribution.isDefined) { + info.dataDistribution.get.foreach { dd => + val dataDistributionBuilder = StoreTypes.RDDDataDistribution.newBuilder() + dataDistributionBuilder.setAddress(dd.address) + dataDistributionBuilder.setMemoryUsed(dd.memoryUsed) + dataDistributionBuilder.setMemoryRemaining(dd.memoryRemaining) + dataDistributionBuilder.setDiskUsed(dd.diskUsed) + dd.onHeapMemoryUsed.foreach(dataDistributionBuilder.setOnHeapMemoryUsed) + dd.offHeapMemoryUsed.foreach(dataDistributionBuilder.setOffHeapMemoryUsed) + dd.onHeapMemoryRemaining.foreach(dataDistributionBuilder.setOnHeapMemoryRemaining) + dd.offHeapMemoryRemaining.foreach(dataDistributionBuilder.setOffHeapMemoryRemaining) + builder.addDataDistribution(dataDistributionBuilder.build()) + } + } + + if (info.partitions.isDefined) { + info.partitions.get.foreach { p => + val partitionsBuilder = StoreTypes.RDDPartitionInfo.newBuilder() + partitionsBuilder.setBlockName(p.blockName) + partitionsBuilder.setStorageLevel(p.storageLevel) + partitionsBuilder.setMemoryUsed(p.memoryUsed) + partitionsBuilder.setDiskUsed(p.diskUsed) + p.executors.foreach(partitionsBuilder.addExecutors) + builder.addPartitions(partitionsBuilder.build()) + } + } + + builder.build() + } + + private def deserializeRDDStorageInfo(info: StoreTypes.RDDStorageInfo): RDDStorageInfo = { + new RDDStorageInfo( + id = info.getId, + name = info.getName, + numPartitions = info.getNumPartitions, + numCachedPartitions = info.getNumCachedPartitions, + storageLevel = info.getStorageLevel, + memoryUsed = info.getMemoryUsed, + diskUsed = info.getDiskUsed, + dataDistribution = + if (info.getDataDistributionList.isEmpty) { Review Comment: this assignment is based on https://github.com/apache/spark/blob/d95fb4c33f6f061190fae091868117d182659147/core/src/main/scala/org/apache/spark/status/LiveEntity.scala#L645 dataDistribution is None for empty seq, and partitions is always Some() even when underlying collection is empty ########## core/src/main/scala/org/apache/spark/status/protobuf/RDDStorageInfoWrapperSerializer.scala: ########## @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.spark.status.protobuf + +import scala.collection.JavaConverters._ + +import org.apache.spark.status.RDDStorageInfoWrapper +import org.apache.spark.status.api.v1.{RDDDataDistribution, RDDPartitionInfo, RDDStorageInfo} +import org.apache.spark.status.protobuf.Utils.getOptional + +object RDDStorageInfoWrapperSerializer { + def serialize(input: RDDStorageInfoWrapper): Array[Byte] = { + val builder = StoreTypes.RDDStorageInfoWrapper.newBuilder() + builder.setInfo(serializeRDDStorageInfo(input.info)) + builder.build().toByteArray + } + + def deserialize(bytes: Array[Byte]): RDDStorageInfoWrapper = { + val wrapper = StoreTypes.RDDStorageInfoWrapper.parseFrom(bytes) + new RDDStorageInfoWrapper( + info = deserializeRDDStorageInfo(wrapper.getInfo) + ) + } + + private def serializeRDDStorageInfo(info: RDDStorageInfo): StoreTypes.RDDStorageInfo = { + val builder = StoreTypes.RDDStorageInfo.newBuilder() + builder.setId(info.id) + builder.setName(info.name) + builder.setNumPartitions(info.numPartitions) + builder.setNumCachedPartitions(info.numCachedPartitions) + builder.setStorageLevel(info.storageLevel) + builder.setMemoryUsed(info.memoryUsed) + builder.setDiskUsed(info.diskUsed) + + if (info.dataDistribution.isDefined) { + info.dataDistribution.get.foreach { dd => + val dataDistributionBuilder = StoreTypes.RDDDataDistribution.newBuilder() + dataDistributionBuilder.setAddress(dd.address) + dataDistributionBuilder.setMemoryUsed(dd.memoryUsed) + dataDistributionBuilder.setMemoryRemaining(dd.memoryRemaining) + dataDistributionBuilder.setDiskUsed(dd.diskUsed) + dd.onHeapMemoryUsed.foreach(dataDistributionBuilder.setOnHeapMemoryUsed) + dd.offHeapMemoryUsed.foreach(dataDistributionBuilder.setOffHeapMemoryUsed) + dd.onHeapMemoryRemaining.foreach(dataDistributionBuilder.setOnHeapMemoryRemaining) + dd.offHeapMemoryRemaining.foreach(dataDistributionBuilder.setOffHeapMemoryRemaining) + builder.addDataDistribution(dataDistributionBuilder.build()) + } + } + + if (info.partitions.isDefined) { + info.partitions.get.foreach { p => + val partitionsBuilder = StoreTypes.RDDPartitionInfo.newBuilder() + partitionsBuilder.setBlockName(p.blockName) + partitionsBuilder.setStorageLevel(p.storageLevel) + partitionsBuilder.setMemoryUsed(p.memoryUsed) + partitionsBuilder.setDiskUsed(p.diskUsed) + p.executors.foreach(partitionsBuilder.addExecutors) + builder.addPartitions(partitionsBuilder.build()) + } + } + + builder.build() + } + + private def deserializeRDDStorageInfo(info: StoreTypes.RDDStorageInfo): RDDStorageInfo = { + new RDDStorageInfo( + id = info.getId, + name = info.getName, + numPartitions = info.getNumPartitions, + numCachedPartitions = info.getNumCachedPartitions, + storageLevel = info.getStorageLevel, + memoryUsed = info.getMemoryUsed, + diskUsed = info.getDiskUsed, + dataDistribution = + if (info.getDataDistributionList.isEmpty) { Review Comment: this implementation is based on https://github.com/apache/spark/blob/d95fb4c33f6f061190fae091868117d182659147/core/src/main/scala/org/apache/spark/status/LiveEntity.scala#L645 dataDistribution is None for empty seq, and partitions is always Some() even when underlying collection is empty -- 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]
