Skip to content

Commit

Permalink
Addressing Dongjoon's review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGekk committed Nov 7, 2018
1 parent 6ab8501 commit 759bca6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class CsvExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper with P
)
}

test("take into account locale while parsing date") {
test("parse date with locale") {
Seq("en-US", "ru-RU").foreach { langTag =>
val locale = Locale.forLanguageTag(langTag)
val date = new SimpleDateFormat("yyyy-MM-dd").parse("2018-11-05")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ class JsonExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper with
"struct<col:bigint>")
}

test("take into account locale while parsing date") {
test("parse date with locale") {
Seq("en-US", "ru-RU").foreach { langTag =>
val locale = Locale.forLanguageTag(langTag)
val date = new SimpleDateFormat("yyyy-MM-dd").parse("2018-11-05")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,17 @@ class CsvFunctionsSuite extends QueryTest with SharedSQLContext {
}
}

test("use locale while parsing timestamps") {
test("parse timestamps with locale") {
Seq("en-US", "ko-KR", "zh-CN", "ru-RU").foreach { langTag =>
val locale = Locale.forLanguageTag(langTag)
val ts = new SimpleDateFormat("dd/MM/yyyy HH:mm").parse("06/11/2018 18:00")
val timestampFormat = "dd MMM yyyy HH:mm"
val sdf = new SimpleDateFormat(timestampFormat, locale)
val input = Seq(s"""${sdf.format(ts)}""").toDS()
val schema = new StructType().add("time", TimestampType)
val options = Map("timestampFormat" -> timestampFormat, "locale" -> langTag)
val df = input.select(from_csv($"value", schema, options))
val df = input.select(from_csv($"value", lit("time timestamp"), options.asJava))

checkAnswer(df,
Row(Row(java.sql.Timestamp.valueOf("2018-11-06 18:00:00.0"))))
checkAnswer(df, Row(Row(java.sql.Timestamp.valueOf("2018-11-06 18:00:00.0"))))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -582,19 +582,17 @@ class JsonFunctionsSuite extends QueryTest with SharedSQLContext {
}
}

test("use locale while parsing timestamps") {
test("parse timestamps with locale") {
Seq("en-US", "ko-KR", "zh-CN", "ru-RU").foreach { langTag =>
val locale = Locale.forLanguageTag(langTag)
val ts = new SimpleDateFormat("dd/MM/yyyy HH:mm").parse("06/11/2018 18:00")
val timestampFormat = "dd MMM yyyy HH:mm"
val sdf = new SimpleDateFormat(timestampFormat, locale)
val input = Seq(s"""{"time": "${sdf.format(ts)}"}""").toDS()
val schema = new StructType().add("time", TimestampType)
val options = Map("timestampFormat" -> timestampFormat, "locale" -> langTag)
val df = input.select(from_json($"value", schema, options))
val df = input.select(from_json($"value", "time timestamp", options))

checkAnswer(df,
Row(Row(java.sql.Timestamp.valueOf("2018-11-06 18:00:00.0"))))
checkAnswer(df, Row(Row(java.sql.Timestamp.valueOf("2018-11-06 18:00:00.0"))))
}
}
}

0 comments on commit 759bca6

Please sign in to comment.