HeartSaVioR commented on a change in pull request #35343:
URL: https://github.com/apache/spark/pull/35343#discussion_r794053306



##########
File path: 
external/kafka-0-10-sql/src/main/scala/org/apache/spark/sql/kafka010/KafkaTimeUtils.scala
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.sql.kafka010
+
+import MockedSystemTime.currentMockSystemTime
+
+/**

Review comment:
       FYI, there are Clock / ManualClock / SystemClock in 
`org.apache.spark.util` package. We still need to have a singleton to do the 
trick anyway, but we can leverage these implementations and only expose the 
method to advance the manual time.

##########
File path: 
external/kafka-0-10-sql/src/main/scala/org/apache/spark/sql/kafka010/KafkaSourceProvider.scala
##########
@@ -562,6 +562,7 @@ private[kafka010] object KafkaSourceProvider extends 
Logging {
     "startingoffsetsbytimestampstrategy"
   private val GROUP_ID_PREFIX = "groupidprefix"
   private[kafka010] val INCLUDE_HEADERS = "includeheaders"
+  private[kafka010] val MOCK_SYSTEM_TIME = "mockSystemTime"

Review comment:
       It might be good to have a prefix that this is internal and test only, 
something like `__` or `testonly-` or any better prefix?
   Leaving a code comment saying "this is test-only internal and won't be 
documented" would help as well.

##########
File path: 
external/kafka-0-10-sql/src/main/scala/org/apache/spark/sql/kafka010/KafkaSource.scala
##########
@@ -188,6 +192,8 @@ private[kafka010] class KafkaSource(
         // checking if we need to skip batch based on minOffsetPerTrigger 
criteria
         val skipBatch = delayBatch(
           limit.minRows, latest, currentOffsets.get, limit.maxTriggerDelayMs)
+
+        println(s"skipBatch: $skipBatch limit.minRows: ${limit.minRows} 
latest: $latest limit.maxTriggerDelayMs: ${limit.maxTriggerDelayMs}")

Review comment:
       Btw I'd like to see this be added in micro batch stream as well if we 
want to retain this here.

##########
File path: 
external/kafka-0-10-sql/src/main/scala/org/apache/spark/sql/kafka010/KafkaSource.scala
##########
@@ -188,6 +192,8 @@ private[kafka010] class KafkaSource(
         // checking if we need to skip batch based on minOffsetPerTrigger 
criteria
         val skipBatch = delayBatch(
           limit.minRows, latest, currentOffsets.get, limit.maxTriggerDelayMs)
+
+        println(s"skipBatch: $skipBatch limit.minRows: ${limit.minRows} 
latest: $latest limit.maxTriggerDelayMs: ${limit.maxTriggerDelayMs}")

Review comment:
       Please change this to logDebug, or delete this if you think it's no 
longer needed. It seems to me worth to leave as debug or trace log message for 
further debugging.

##########
File path: 
external/kafka-0-10-sql/src/main/scala/org/apache/spark/sql/kafka010/KafkaTimeUtils.scala
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.sql.kafka010
+
+import MockedSystemTime.currentMockSystemTime
+
+/**
+ * A class to get the current epoch time in millis.
+ * Having this class allows us the flexibility to use read epoch time or 
mocked epoch time
+ * for testing purposes so that we can advance epoch time in tests in a 
deterministic fashion
+ */
+trait Time {
+  def getCurrentTimeMillis: Long
+}
+
+/**
+ * To get the real epoch time
+ */
+class RealSystemTime extends Time {
+  override def getCurrentTimeMillis: Long = {
+    System.currentTimeMillis()
+  }
+}
+
+/**
+ * To return a mocked epoch time
+ */
+class MockedSystemTime extends Time{
+  override def getCurrentTimeMillis: Long = {
+    currentMockSystemTime
+  }
+}
+
+object MockedSystemTime {
+  var currentMockSystemTime = 0L

Review comment:
       The functionality is concise, it's great. It might be beneficial to 
expose a way to reset the time as well as get the time, but if you feel we can 
defer this unless required, that's OK.




-- 
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-unsubscr...@spark.apache.org

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



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

Reply via email to