[GitHub] [spark] cloud-fan commented on a change in pull request #26102: [SPARK-29448][SQL] Support the `INTERVAL` type by Parquet datasource

2019-11-17 Thread GitBox
cloud-fan commented on a change in pull request #26102: [SPARK-29448][SQL] 
Support the `INTERVAL` type by Parquet datasource
URL: https://github.com/apache/spark/pull/26102#discussion_r347223313
 
 

 ##
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetWriteSupport.scala
 ##
 @@ -207,7 +208,16 @@ class ParquetWriteSupport extends 
WriteSupport[InternalRow] with Logging {
 
   case t: UserDefinedType[_] => makeWriter(t.sqlType)
 
-  // TODO Adds IntervalType support
+  case CalendarIntervalType =>
+(row: SpecializedGetters, ordinal: Int) =>
+  val interval = row.getInterval(ordinal)
+  val buf = ByteBuffer.wrap(reusableBuffer)
+  buf.order(ByteOrder.LITTLE_ENDIAN)
+.putInt((interval.milliseconds()).toInt)
 
 Review comment:
   we should use strict toInt so that we can fail earlier if out of range.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] cloud-fan commented on a change in pull request #26102: [SPARK-29448][SQL] Support the `INTERVAL` type by Parquet datasource

2019-11-14 Thread GitBox
cloud-fan commented on a change in pull request #26102: [SPARK-29448][SQL] 
Support the `INTERVAL` type by Parquet datasource
URL: https://github.com/apache/spark/pull/26102#discussion_r344585132
 
 

 ##
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSource.scala
 ##
 @@ -498,10 +498,8 @@ case class DataSource(
   outputColumnNames: Seq[String],
   physicalPlan: SparkPlan): BaseRelation = {
 val outputColumns = DataWritingCommand.logicalPlanOutputWithNames(data, 
outputColumnNames)
-if 
(outputColumns.map(_.dataType).exists(_.isInstanceOf[CalendarIntervalType])) {
 
 Review comment:
   interval type is kind of an internal type for now. It's a big decision if we 
can read/write it from/to data sources.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] cloud-fan commented on a change in pull request #26102: [SPARK-29448][SQL] Support the `INTERVAL` type by Parquet datasource

2019-11-10 Thread GitBox
cloud-fan commented on a change in pull request #26102: [SPARK-29448][SQL] 
Support the `INTERVAL` type by Parquet datasource
URL: https://github.com/apache/spark/pull/26102#discussion_r344585132
 
 

 ##
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSource.scala
 ##
 @@ -498,10 +498,8 @@ case class DataSource(
   outputColumnNames: Seq[String],
   physicalPlan: SparkPlan): BaseRelation = {
 val outputColumns = DataWritingCommand.logicalPlanOutputWithNames(data, 
outputColumnNames)
-if 
(outputColumns.map(_.dataType).exists(_.isInstanceOf[CalendarIntervalType])) {
 
 Review comment:
   interval type is kind of an interval type for now. It's a big decision if we 
can read/write it from/to data sources.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] cloud-fan commented on a change in pull request #26102: [SPARK-29448][SQL] Support the `INTERVAL` type by Parquet datasource

2019-11-04 Thread GitBox
cloud-fan commented on a change in pull request #26102: [SPARK-29448][SQL] 
Support the `INTERVAL` type by Parquet datasource
URL: https://github.com/apache/spark/pull/26102#discussion_r341931042
 
 

 ##
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSource.scala
 ##
 @@ -498,10 +498,8 @@ case class DataSource(
   outputColumnNames: Seq[String],
   physicalPlan: SparkPlan): BaseRelation = {
 val outputColumns = DataWritingCommand.logicalPlanOutputWithNames(data, 
outputColumnNames)
-if 
(outputColumns.map(_.dataType).exists(_.isInstanceOf[CalendarIntervalType])) {
 
 Review comment:
   Let's do this change after we officially make `CalendarIntervalType` public. 
i.e. move it to a public package.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [spark] cloud-fan commented on a change in pull request #26102: [SPARK-29448][SQL] Support the `INTERVAL` type by Parquet datasource

2019-10-14 Thread GitBox
cloud-fan commented on a change in pull request #26102: [SPARK-29448][SQL] 
Support the `INTERVAL` type by Parquet datasource
URL: https://github.com/apache/spark/pull/26102#discussion_r334474170
 
 

 ##
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetRowConverter.scala
 ##
 @@ -325,6 +325,26 @@ private[parquet] class ParquetRowConverter(
 override def set(value: Any): Unit = 
updater.set(value.asInstanceOf[InternalRow].copy())
   })
 
+  case CalendarIntervalType
+if parquetType.asPrimitiveType().getPrimitiveTypeName == 
FIXED_LEN_BYTE_ARRAY =>
+new ParquetPrimitiveConverter(updater) {
+  override def addBinary(value: Binary): Unit = {
+assert(
+  value.length() == 12,
+  "Intervals are expected to be stored in 12-byte fixed len byte 
array, " +
+s"but got a ${value.length()}-byte array.")
+
+val buf = value.toByteBuffer.order(ByteOrder.LITTLE_ENDIAN)
+val milliseconds = buf.getInt
+var microseconds = milliseconds * DateTimeUtils.MICROS_PER_MILLIS
+val days = buf.getInt
+val daysInUs = Math.multiplyExact(days, 
DateTimeUtils.MICROS_PER_DAY)
 
 Review comment:
   Parquet stores # of days as a separated field because one logical day 
interval can be 23 or 24 or 25 hours in case of daylight saving. If we convert 
parquet interval to Spark interval, it's not a truncation but losing 
information.


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:
us...@infra.apache.org


With regards,
Apache Git Services

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