maropu commented on a change in pull request #28841:
URL: https://github.com/apache/spark/pull/28841#discussion_r463954939



##########
File path: docs/sql-data-sources-generic-options.md
##########
@@ -119,3 +119,37 @@ 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. <br/>
+<br/>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.<br/><br/>
+`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.
+ <br/><br/>
+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.
+<br/><br/>
+Both options expect a timestamp in the following format: 
`YYYY-MM-DDTHH:mm:ss`.<br/>
+
+<b>Example</b> - <i>Load files between 6/1 and 7/1 time range:</i><br/>
+`spark`<br/>
+`.read` <br/>
+` .format("csv")`<br/>
+` .option('modifiedBefore','2020-07-01T08:33:05`)<br/>
+` .option('modifiedAfter','2020-06-01T08:33:05`)<br/>
+` .option('timeZone','PST`)<br/>

Review comment:
       Could you follow the format by referring the other `.md` docs? You can 
generate a html doc and check it via `SKIP_API=1 jekyll build`.
   
   <img width="1030" alt="Screen Shot 2020-08-01 at 20 49 50" 
src="https://user-images.githubusercontent.com/692303/89101208-b0577480-d438-11ea-8021-d7a9555d3bcf.png";>
   

##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/pathfilters/ModifiedAfterFilter.scala
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.pathfilters
+
+import org.apache.hadoop.conf.Configuration
+import org.apache.hadoop.fs._
+
+import org.apache.spark.sql.SparkSession
+import org.apache.spark.sql.catalyst.util.{CaseInsensitiveMap, DateTimeUtils}
+
+/**
+ * [SPARK-31962]
+ * Filter used to determine whether file was modified
+ * after the provided timestamp.
+ *
+ * @param sparkSession SparkSession
+ * @param hadoopConf Hadoop Configuration object
+ * @param options Map containing options
+ */
+case class ModifiedAfterFilter(sparkSession: SparkSession,
+                               hadoopConf: Configuration,
+                               options: CaseInsensitiveMap[String])
+    extends ModifiedDateFilter(sparkSession, hadoopConf, options)

Review comment:
       Could you check the style guide again?
   https://github.com/databricks/scala-style-guide#spacing-and-indentation
   ```
   case class ModifiedAfterFilter(
       sparkSession: SparkSession,
       hadoopConf: Configuration,
       options: CaseInsensitiveMap[String])
     extends ModifiedDateFilter(sparkSession, hadoopConf, options) with 
FileIndexFilter {
   ```

##########
File path: python/pyspark/sql/readwriter.py
##########
@@ -114,6 +114,14 @@ def option(self, key, value):
             * ``pathGlobFilter``: an optional glob pattern to only include 
files with paths matching
                 the pattern. The syntax follows 
org.apache.hadoop.fs.GlobFilter.
                 It does not change the behavior of partition discovery.
+            * ``modifiedBefore``: an optional timestamp to only include files 
with
+                modification times occurring before the specified time.  The 
provided timestamp
+                must be in the following format:  YYYY-MM-DDTHH:mm:ss

Review comment:
       Could you use a single space in `format:  YYYY-`?

##########
File path: docs/sql-data-sources-generic-options.md
##########
@@ -119,3 +119,37 @@ 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. <br/>
+<br/>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.<br/><br/>
+`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.
+ <br/><br/>
+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.
+<br/><br/>
+Both options expect a timestamp in the following format: 
`YYYY-MM-DDTHH:mm:ss`.<br/>
+
+<b>Example</b> - <i>Load files between 6/1 and 7/1 time range:</i><br/>
+`spark`<br/>
+`.read` <br/>
+` .format("csv")`<br/>
+` .option('modifiedBefore','2020-07-01T08:33:05`)<br/>
+` .option('modifiedAfter','2020-06-01T08:33:05`)<br/>
+` .option('timeZone','PST`)<br/>

Review comment:
       Also, please add `{% include_example load_with_modified_time_filter... `

##########
File path: sql/core/src/main/scala/org/apache/spark/sql/DataFrameReader.scala
##########
@@ -467,6 +467,14 @@ class DataFrameReader private[sql](sparkSession: 
SparkSession) extends Logging {
    * <li>`pathGlobFilter`: an optional glob pattern to only include files with 
paths matching
    * the pattern. The syntax follows 
<code>org.apache.hadoop.fs.GlobFilter</code>.
    * It does not change the behavior of partition discovery.</li>
+   * <li>`modifiedBefore`: an optional timestamp to only include files with
+   * modification times  occurring before the specified time.  The provided 
timestamp
+   * must be in the following form:  <code>YYYY-MM-DDTHH:mm:ss</code>  Example:

Review comment:
       ditto: Could you use a single space in `form:  <code>`?

##########
File path: 
sql/core/src/test/scala/org/apache/spark/sql/FileBasedDataSourceSuite.scala
##########
@@ -561,6 +564,367 @@ class FileBasedDataSourceSuite extends QueryTest
     }
   }
 
+  test("SPARK-31962 - when modifiedAfter specified " +

Review comment:
       nit: `SPARK-31962 -` -> `SPARK-31962: `

##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/pathfilters/ModifiedAfterFilter.scala
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.pathfilters
+
+import org.apache.hadoop.conf.Configuration
+import org.apache.hadoop.fs._
+
+import org.apache.spark.sql.SparkSession
+import org.apache.spark.sql.catalyst.util.{CaseInsensitiveMap, DateTimeUtils}
+
+/**
+ * [SPARK-31962]

Review comment:
       Could you remove the jira ID? I think we don't need it here.

##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/pathfilters/FileIndexFilter.scala
##########
@@ -0,0 +1,26 @@
+/*
+ * 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.pathfilters
+
+import org.apache.hadoop.fs.{FileStatus, PathFilter}
+
+
+trait FileIndexFilter extends PathFilter with Serializable {
+  def accept(fileStatus: FileStatus): Boolean
+  def strategy(): String

Review comment:
       We need `def strategy(): String`? Looks we can use a class name instead.

##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/pathfilters/FileIndexFilter.scala
##########
@@ -0,0 +1,26 @@
+/*
+ * 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.pathfilters
+
+import org.apache.hadoop.fs.{FileStatus, PathFilter}
+
+
+trait FileIndexFilter extends PathFilter with Serializable {

Review comment:
       Could you make a file 
`org/apache/spark/sql/execution/datasources/pathFilters.scala`, then move all 
the related classes into the file? I think each new file has less code.

##########
File path: sql/core/src/main/scala/org/apache/spark/sql/DataFrameReader.scala
##########
@@ -467,6 +467,14 @@ class DataFrameReader private[sql](sparkSession: 
SparkSession) extends Logging {
    * <li>`pathGlobFilter`: an optional glob pattern to only include files with 
paths matching
    * the pattern. The syntax follows 
<code>org.apache.hadoop.fs.GlobFilter</code>.
    * It does not change the behavior of partition discovery.</li>
+   * <li>`modifiedBefore`: an optional timestamp to only include files with
+   * modification times  occurring before the specified time.  The provided 
timestamp
+   * must be in the following form:  <code>YYYY-MM-DDTHH:mm:ss</code>  Example:
+   * <code>2020-06-01T13:00:00</code>
+   * <li>`modifiedAfter`: an optional timestamp to only include files with
+   * modification times occurring after the specified time.  The provided 
timestamp

Review comment:
       ditto: `time.  The`




----------------------------------------------------------------
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]

Reply via email to