Skip to content

Commit

Permalink
Merge e7dbf18 into c65cc12
Browse files Browse the repository at this point in the history
  • Loading branch information
ravipesala committed Jul 23, 2019
2 parents c65cc12 + e7dbf18 commit 9833b77
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.apache.spark.sql.carbondata.execution.datasources
import scala.collection.JavaConverters._

import org.apache.spark.sql._
import org.apache.spark.sql.catalyst.util.DateTimeUtils
import org.apache.spark.sql.types._

import org.apache.carbondata.core.constants.CarbonCommonConstants
Expand Down Expand Up @@ -200,6 +201,10 @@ object CarbonSparkDataSourceUtil {
val dataValue = if (dataTypeOfAttribute.equals(CarbonDataTypes.BINARY)
&& Option(value).isDefined) {
new String(value.asInstanceOf[Array[Byte]])
} else if (dataTypeOfAttribute.equals(CarbonDataTypes.DATE) &&
value.isInstanceOf[java.sql.Date]) {
// In case of Date object , convert back to int.
DateTimeUtils.fromJavaDate(value.asInstanceOf[java.sql.Date])
} else {
value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,19 @@ class SparkCarbonDataSourceTest extends FunSuite with BeforeAndAfterAll {
spark.sql("drop table if exists date_parquet_table")
}

test("test date filter datatype") {
spark.sql("drop table if exists date_table")
spark.sql("drop table if exists date_parquet_table")
spark.sql("create table date_table(empno int, empname string, projdate Date) using carbon")
spark.sql("insert into date_table select 11, 'ravi', '2017-11-11'")
spark.sql("select * from date_table where projdate=cast('2017-11-11' as date)").show()
spark.sql("create table date_parquet_table(empno int, empname string, projdate Date) using parquet")
spark.sql("insert into date_parquet_table select 11, 'ravi', '2017-11-11'")
checkAnswer(spark.sql("select * from date_table where projdate=cast('2017-11-11' as date)"), spark.sql("select * from date_parquet_table where projdate=cast('2017-11-11' as date)"))
spark.sql("drop table if exists date_table")
spark.sql("drop table if exists date_parquet_table")
}

test("test read and write with date datatype with wrong format") {
spark.sql("drop table if exists date_table")
spark.sql("drop table if exists date_parquet_table")
Expand Down

0 comments on commit 9833b77

Please sign in to comment.