spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ueshin <...@git.apache.org>
Subject [GitHub] spark pull request #18664: [SPARK-21375][PYSPARK][SQL][WIP] Add Date and Tim...
Date Tue, 18 Jul 2017 04:18:30 GMT
Github user ueshin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18664#discussion_r127879502
  
    --- Diff: sql/core/src/test/scala/org/apache/spark/sql/execution/arrow/ArrowConvertersSuite.scala
---
    @@ -792,6 +793,76 @@ class ArrowConvertersSuite extends SharedSQLContext with BeforeAndAfterAll
{
         collectAndValidate(df, json, "binaryData.json")
       }
     
    +  test("date type conversion") {
    +    val json =
    +      s"""
    +         |{
    +         |  "schema" : {
    +         |    "fields" : [ {
    +         |      "name" : "date",
    +         |      "type" : {
    +         |        "name" : "date",
    +         |        "unit" : "DAY"
    +         |      },
    +         |      "nullable" : true,
    +         |      "children" : [ ],
    +         |      "typeLayout" : {
    +         |        "vectors" : [ {
    +         |          "type" : "VALIDITY",
    +         |          "typeBitWidth" : 1
    +         |        }, {
    +         |          "type" : "DATA",
    +         |          "typeBitWidth" : 32
    +         |        } ]
    +         |      }
    +         |    } ]
    +         |  },
    +         |  "batches" : [ {
    +         |    "count" : 4,
    +         |    "columns" : [ {
    +         |      "name" : "date",
    +         |      "count" : 4,
    +         |      "VALIDITY" : [ 1, 1, 1, 1 ],
    +         |      "DATA" : [ -1, 0, 16533, 16930 ]
    +         |    } ]
    +         |  } ]
    +         |}
    +       """.stripMargin
    +
    +    val sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z", Locale.US)
    +    val d1 = new Date(-1)  // "1969-12-31 13:10:15.000 UTC"
    +    val d2 = new Date(0)  // "1970-01-01 13:10:15.000 UTC"
    +    val d3 = new Date(sdf.parse("2015-04-08 13:10:15.000 UTC").getTime)
    +    val d4 = new Date(sdf.parse("2016-05-09 12:01:01.000 UTC").getTime)
    +
    +    // Date is created unaware of timezone, but DateTimeUtils force defaultTimeZone()
    +    assert(DateTimeUtils.toJavaDate(DateTimeUtils.fromJavaDate(d2)).getTime == d2.getTime)
    --- End diff --
    
    We handle `DateType` value as days from `1970-01-01` internally.
    
    When converting from/to `Date` to/from internal value, we assume the `Date` instance contains
the timestamp of `00:00:00` time of the day in `TimeZone.getDefault()` timezone, which is
the offset of the timezone. e.g. in JST (GMT+09:00):
    
    ```
    scala> TimeZone.setDefault(TimeZone.getTimeZone("JST"))
    
    scala> Date.valueOf("1970-01-01").getTime()
    res6: Long = -32400000
    ```
    
    whereas in PST (GMT-08:00):
    
    ```
    scala> TimeZone.setDefault(TimeZone.getTimeZone("PST"))
    
    scala> Date.valueOf("1970-01-01").getTime()
    res8: Long = 28800000
    ```
    
    We use `DateTimeUtils.defaultTimeZone()` to adjust the offset.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


Mime
View raw message