cchighman commented on a change in pull request #28841:
URL: https://github.com/apache/spark/pull/28841#discussion_r475347166
##########
File path: docs/sql-data-sources-generic-options.md
##########
@@ -119,3 +119,48 @@ To load all files recursively, you can use:
{% include_example recursive_file_lookup r/RSparkSQLExample.R %}
</div>
</div>
+
+### Modification Time Path Filters
+`modifiedBefore` and `modifiedAfter` are options that can be
+applied together or separately in order to achieve greater
+granularity over which files may load during a Spark batch query.
+
+When the `timeZone` option is present, modified timestamps will be
+interpreted according to the specified zone. When a timezone option
+is not provided, modified timestamps will be interpreted according
+to the default zone specified within the Spark configuration. Without
+any timezone configuration, modified timestamps are interpreted as UTC.
+
+`modifiedBefore` will only allow files having last modified
+timestamps occurring before the specified time to load. For example,
+when`modifiedBefore` has the timestamp `2020-06-01T12:00:00` applied,
+all files modified after that time will not be considered when loading
+from a file data source.
+
+`modifiedAfter` only allows files having last modified timestamps
+occurring after the specified timestamp. For example, when`modifiedAfter`
+has the timestamp `2020-06-01T12:00:00` applied, only files modified after
+this time will be eligible when loading from a file data source. When both
+`modifiedBefore` and `modifiedAfter` are specified together, files having
+last modified timestamps within the resulting time range are the only files
+allowed to load.
Review comment:
Will update
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/PathFilterSuite.scala
##########
@@ -0,0 +1,501 @@
+/*
+ * 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.execution.datasources
+
+import java.io.File
+import java.time.{LocalDateTime, ZoneOffset}
+import java.time.format.DateTimeFormatter
+
+import org.apache.hadoop.fs.Path
+
+import org.apache.spark.sql.{AnalysisException, QueryTest, Row}
+import org.apache.spark.sql.catalyst.util.{stringToFile, CaseInsensitiveMap,
DateTimeUtils}
+import org.apache.spark.sql.test.SharedSparkSession
+
+class PathFilterSuite extends QueryTest with SharedSparkSession {
+ import testImplicits._
+
+ test("SPARK-31962: when modifiedAfter specified with a past date") {
+ withTempDir { dir =>
+ val path = new Path(dir.getCanonicalPath)
+ val file = new File(dir, "file1.csv")
+ stringToFile(file, "text")
+ file.setLastModified(DateTimeUtils.currentTimestamp())
+ val df = spark.read
+ .option("modifiedAfter", "2019-05-10T01:11:00")
+ .format("csv")
+ .load(path.toString)
+ assert(df.count() == 1)
+ }
+ }
+
+ test("SPARK-31962: when modifiedBefore specified with a future date") {
+ withTempDir { dir =>
+ val path = new Path(dir.getCanonicalPath)
+ val file = new File(dir, "file1.csv")
+ stringToFile(file, "text")
+ val df = spark.read
+ .option("modifiedBefore", "2090-05-10T01:11:00")
+ .format("csv")
+ .load(path.toString)
+ assert(df.count() == 1)
+ }
+ }
+
+ test("SPARK-31962: when modifiedBefore specified with a past date") {
+ withTempDir { dir =>
+ val path = new Path(dir.getCanonicalPath)
+ val file = new File(dir, "file1.csv")
+ stringToFile(file, "text")
+ file.setLastModified(DateTimeUtils.currentTimestamp())
+ val msg = intercept[AnalysisException] {
+ spark.read
+ .option("modifiedBefore", "1984-05-01T01:00:00")
+ .format("csv")
+ .load(path.toString)
+ }.getMessage
+ assert(msg.contains("Unable to infer schema for CSV"))
+ }
+ }
+
+ test("SPARK-31962: when modifiedAfter specified with a past date, multiple
files, one valid") {
+ withTempDir { dir =>
+ val path = new Path(dir.getCanonicalPath)
+ val file1 = new File(dir, "file1.csv")
+ val file2 = new File(dir, "file2.csv")
+ stringToFile(file1, "text")
+ stringToFile(file2, "text")
+ file1.setLastModified(DateTimeUtils.currentTimestamp())
Review comment:
Will Update
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]