Github user jackylk commented on a diff in the pull request: https://github.com/apache/carbondata/pull/1261#discussion_r133689326 --- Diff: integration/spark/src/main/scala/org/apache/carbondata/spark/rdd/CarbonDataRDDFactory.scala --- @@ -657,26 +652,53 @@ object CarbonDataRDDFactory { val updateRdd = dataFrame.get.rdd + // return directly if no rows to update + val noRowsToUpdate = updateRdd.isEmpty() + if (noRowsToUpdate) { + res = Array[List[(String, (LoadMetadataDetails, ExecutionErrors))]]() + return + } + // splitting as (key, value) i.e., (segment, updatedRows) val keyRDD = updateRdd.map(row => - // splitting as (key, value) i.e., (segment, updatedRows) - (row.get(row.size - 1).toString, Row(row.toSeq.slice(0, row.size - 1): _*)) - ) - val groupBySegmentRdd = keyRDD.groupByKey() + (row.get(row.size - 1).toString, Row(row.toSeq.slice(0, row.size - 1): _*))) + + val loadMetadataDetails = SegmentStatusManager + .readLoadMetadata(carbonTable.getMetaDataFilepath) + val segmentIds = loadMetadataDetails.map(_.getLoadName) + val segmentIdIndex = segmentIds.zipWithIndex.toMap + val carbonTablePath = CarbonStorePath.getCarbonTablePath(carbonLoadModel.getStorePath, + carbonTable.getCarbonTableIdentifier) + val segmentId2maxTaskNo = segmentIds + .map(segId => + (segId, CarbonUpdateUtil.getLatestTaskIdForSegment(segId, carbonTablePath))) + .toMap + + class SegmentPartitioner(segIdIndex: Map[String, Int], parallelism: Int) + extends org.apache.spark.Partitioner { + override def numPartitions: Int = segmentIdIndex.size * parallelism + + override def getPartition(key: Any): Int = { + val segId = key.asInstanceOf[String] + // partitionId + segmentIdIndex(segId) * parallelism + Random.nextInt(parallelism) + } + } - val nodeNumOfData = groupBySegmentRdd.partitions.flatMap[String, Array[String]] { p => - DataLoadPartitionCoalescer.getPreferredLocs(groupBySegmentRdd, p).map(_.host) - }.distinct.size - val nodes = DistributionUtil.ensureExecutorsByNumberAndGetNodeList(nodeNumOfData, - sqlContext.sparkContext) - val groupBySegmentAndNodeRdd = - new UpdateCoalescedRDD[(String, scala.Iterable[Row])](groupBySegmentRdd, - nodes.distinct.toArray) + val partitionByRdd = keyRDD + .partitionBy(new SegmentPartitioner(segmentIdIndex, segmentUpdateParallelism)) - res = groupBySegmentAndNodeRdd.map(x => - triggerDataLoadForSegment(x._1, x._2.toIterator).toList - ).collect() + // because partitionId=segmentIdIndex*parallelism+RandomPart and RandomPart<parallelism, + // so segmentIdIndex=partitionId/parallelism, this has been verified. + res = partitionByRdd.map(_._2).mapPartitions(p => { --- End diff -- change `.mapPartitions(p => {` to `.mapPartitions{ partition =>`
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---