Skip to content

Fix timestamp spark calculation #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ object OsmPbfRowIterator {

private def populateInfo(info: Info): InternalRow = InternalRow.fromSeq(infoSchema.fieldNames.map{
case FIELD_INFO_VERSION => info.version.getOrElse(null)
case FIELD_INFO_TIMESTAMP => info.timestamp.map(inst => inst.toEpochMilli).getOrElse(null)
case FIELD_INFO_TIMESTAMP => info.timestamp.map(inst => inst.toEpochMilli * 1000).getOrElse(null)
case FIELD_INFO_CHANGESET => info.changeset.getOrElse(null)
case FIELD_INFO_USER_ID => info.userId.getOrElse(null)
case FIELD_INFO_USER_NAME => info.userName.map(UTF8String.fromString).orNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.wordspec.AnyWordSpec

import java.io.File
import java.sql.Timestamp
import scala.util.Random

object SourcesForTesting {
Expand Down Expand Up @@ -145,6 +146,21 @@ class OsmPbfFormatSpec extends AnyWordSpec with Matchers with SparkSessionBefore
node171946.getAs[Long]("id") shouldBe 171946L
}

"read info" in {
// <node id="1699777711" version="2" timestamp="2018-03-26T07:24:26Z" lat="43.7402163" lon="7.4281505"/>
// Epoch 1522049066000 = Monday, March 26, 2018 7:24:26 AM
val node1699777711 = loadOsmPbf(spark, monacoPath)
.select(
col("id"),
col("info.version") as "version",
col("info.timestamp") as "timestamp"
).filter("id == 1699777711").collect()(0)

node1699777711.getAs[Long]("id") shouldBe 1699777711L
node1699777711.getAs[Integer]("version") should be(2)
node1699777711.getAs[Timestamp]("timestamp").toInstant.toEpochMilli shouldBe 1522049066000L
}

"read null info" in {
val node171946 = loadOsmPbf(spark, madridPath).select("id", "info").filter("id == 171946").collect()(0)
node171946.getAs[Long]("id") shouldBe 171946L
Expand Down