You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/12/06 23:52:17 UTC

[GitHub] [spark] rangadi commented on a diff in pull request #38911: [SPARK-41387][SS] Assert current end offset from Kafka data source for Trigger.AvailableNow

rangadi commented on code in PR #38911:
URL: https://github.com/apache/spark/pull/38911#discussion_r1041594443


##########
connector/kafka-0-10-sql/src/main/scala/org/apache/spark/sql/kafka010/KafkaMicroBatchStream.scala:
##########
@@ -316,6 +320,54 @@ private[kafka010] class KafkaMicroBatchStream(
     }
   }
 
+  private def assertEndOffsetForTriggerAvailableNow(
+      endPartitionOffsets: Map[TopicPartition, Long]): Unit = {
+    val tpsForPrefetched = allDataForTriggerAvailableNow.keySet
+    val tpsForEndOffset = endPartitionOffsets.keySet
+    assert(tpsForPrefetched == tpsForEndOffset,
+      "Kafka data source in Trigger.AvailableNow should provide the same topic partitions in " +
+        "pre-fetched offset to end offset for each microbatch. " +
+        s"topic-partitions for pre-fetched offset: $tpsForPrefetched, " +
+        s"topic-partitions for end offset: $tpsForEndOffset.")
+
+    val endOffsetHasGreaterOrEqualOffsetComparedToPrefetched = {
+      allDataForTriggerAvailableNow.keySet.forall { tp =>
+        val offsetFromPrefetched = allDataForTriggerAvailableNow(tp)
+        val offsetFromEndOffset = endPartitionOffsets(tp)
+        offsetFromEndOffset <= offsetFromPrefetched
+      }
+    }
+    assert(endOffsetHasGreaterOrEqualOffsetComparedToPrefetched,

Review Comment:
   Is assert a good way to pass useful error message to the user?
   Other parts throw compilation or executor errors. 
   E.g. https://github.com/apache/spark/blob/master/connector/protobuf/src/main/scala/org/apache/spark/sql/protobuf/ProtobufDataToCatalyst.scala#L73
   
   I think assert is only for cases that are not expected at runtime.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org