You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "cashmand (via GitHub)" <gi...@apache.org> on 2023/11/23 18:11:53 UTC
[PR] [SPARK-45827] Variant fixes with codegen and vectorized reader disabled [spark]
cashmand opened a new pull request, #43984:
URL: https://github.com/apache/spark/pull/43984
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the guideline first in
'core/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
Fix two issues with the new Variant type:
1) In `InterpretedUnsafeProjection`, define element size to be 8, since Variant has variable length, so it is categorized as a reference type, which always has size 8. This only manifests as an issue when codegen is disabled and an array or struct contains Variant values.
2) Define and use a `ParquetGroupConverter` for Variant. The previous tests used the vectorized reader, so this issue didn't manifest.
### Why are the changes needed?
Fixes crashes when Variant is used.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Added a unit test that writes and reads an array of Variant values with codegen and the vectorized reader disabled. Reverting either of the two fixes causes the test to fail.
### Was this patch authored or co-authored using generative AI tooling?
No.
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-45827][SQL] Variant fixes with codegen and vectorized reader disabled [spark]
Posted by "cashmand (via GitHub)" <gi...@apache.org>.
cashmand commented on code in PR #43984:
URL: https://github.com/apache/spark/pull/43984#discussion_r1403906938
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetRowConverter.scala:
##########
@@ -498,6 +498,9 @@ private[parquet] class ParquetRowConverter(
int96RebaseSpec,
wrappedUpdater)
+ case t: VariantType =>
Review Comment:
I think because the vectorized parquet reader is used by default, and I guess the vectorized reader doesn't use these converters. I had to set `PARQUET_VECTORIZED_READER_ENABLED` to false in the unit test to trigger the failure that this part of the change fixes.
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-45827][SQL] Variant fixes with codegen and vectorized reader disabled [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #43984:
URL: https://github.com/apache/spark/pull/43984#discussion_r1403903137
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/InterpretedUnsafeProjection.scala:
##########
@@ -294,7 +294,7 @@ object InterpretedUnsafeProjection {
*/
@scala.annotation.tailrec
private def getElementSize(dataType: DataType): Int = dataType match {
- case NullType | StringType | BinaryType | CalendarIntervalType |
+ case NullType | StringType | BinaryType | CalendarIntervalType | VariantType |
_: DecimalType | _: StructType | _: ArrayType | _: MapType => 8
Review Comment:
not related to this PR, but I think there are similar code in other places. Shall we unify them and always call `UnsafeRow.isFixedLength`?
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-45827][SQL] Variant fixes with codegen and vectorized reader disabled [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #43984:
URL: https://github.com/apache/spark/pull/43984#discussion_r1403785582
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetRowConverter.scala:
##########
@@ -810,6 +813,40 @@ private[parquet] class ParquetRowConverter(
}
}
+ /** Parquet converter for Variant */
+ private final class ParquetVariantConverter(
+ parquetType: GroupType,
+ updater: ParentContainerUpdater)
+ extends ParquetGroupConverter(updater) {
+
+ private[this] var currentValue: Any = _
+ private[this] var currentMetadata: Any = _
+
+ private[this] val converters = Array(
+ // Converter for value
+ newConverter(parquetType.getType(0), BinaryType, new ParentContainerUpdater {
+ override def set(value: Any): Unit = currentValue = value
+ }),
+
+ // Converter for metadata
+ newConverter(parquetType.getType(1), BinaryType, new ParentContainerUpdater {
+ override def set(value: Any): Unit = currentMetadata = value
+ }))
+
+ override def getConverter(fieldIndex: Int): Converter = converters(fieldIndex)
+
+ override def end(): Unit = {
+ updater.set(
+ new VariantVal(currentValue.asInstanceOf[Array[Byte]],
+ currentMetadata.asInstanceOf[Array[Byte]]))
Review Comment:
```suggestion
new VariantVal(currentValue.asInstanceOf[Array[Byte]],
currentMetadata.asInstanceOf[Array[Byte]]))
```
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-45827][SQL] Variant fixes with codegen and vectorized reader disabled [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #43984:
URL: https://github.com/apache/spark/pull/43984#discussion_r1403907703
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetRowConverter.scala:
##########
@@ -498,6 +498,9 @@ private[parquet] class ParquetRowConverter(
int96RebaseSpec,
wrappedUpdater)
+ case t: VariantType =>
Review Comment:
oh I see
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-45827][SQL] Variant fixes with codegen and vectorized reader disabled [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #43984:
URL: https://github.com/apache/spark/pull/43984#discussion_r1403903557
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetRowConverter.scala:
##########
@@ -498,6 +498,9 @@ private[parquet] class ParquetRowConverter(
int96RebaseSpec,
wrappedUpdater)
+ case t: VariantType =>
Review Comment:
I'm surprised. Without this case match, why did variant ever work in parquet before?
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-45827][SQL] Variant fixes with codegen and vectorized reader disabled [spark]
Posted by "cashmand (via GitHub)" <gi...@apache.org>.
cashmand commented on code in PR #43984:
URL: https://github.com/apache/spark/pull/43984#discussion_r1403927026
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/InterpretedUnsafeProjection.scala:
##########
@@ -294,7 +294,7 @@ object InterpretedUnsafeProjection {
*/
@scala.annotation.tailrec
private def getElementSize(dataType: DataType): Int = dataType match {
- case NullType | StringType | BinaryType | CalendarIntervalType |
+ case NullType | StringType | BinaryType | CalendarIntervalType | VariantType |
_: DecimalType | _: StructType | _: ArrayType | _: MapType => 8
Review Comment:
Let me know if you want me to make the `UnsafeRow.isFixedLength` change as part of this PR (and if so, what to do about NullType).
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-45827][SQL] Variant fixes with codegen and vectorized reader disabled [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #43984:
URL: https://github.com/apache/spark/pull/43984#issuecomment-1830163199
thanks, merging to master!
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-45827][SQL] Variant fixes with codegen and vectorized reader disabled [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #43984:
URL: https://github.com/apache/spark/pull/43984#discussion_r1403785515
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetRowConverter.scala:
##########
@@ -810,6 +813,40 @@ private[parquet] class ParquetRowConverter(
}
}
+ /** Parquet converter for Variant */
+ private final class ParquetVariantConverter(
+ parquetType: GroupType,
+ updater: ParentContainerUpdater)
Review Comment:
```suggestion
private final class ParquetVariantConverter(
parquetType: GroupType,
updater: ParentContainerUpdater)
```
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-45827][SQL] Variant fixes with codegen and vectorized reader disabled [spark]
Posted by "cashmand (via GitHub)" <gi...@apache.org>.
cashmand commented on code in PR #43984:
URL: https://github.com/apache/spark/pull/43984#discussion_r1403909452
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/InterpretedUnsafeProjection.scala:
##########
@@ -294,7 +294,7 @@ object InterpretedUnsafeProjection {
*/
@scala.annotation.tailrec
private def getElementSize(dataType: DataType): Int = dataType match {
- case NullType | StringType | BinaryType | CalendarIntervalType |
+ case NullType | StringType | BinaryType | CalendarIntervalType | VariantType |
_: DecimalType | _: StructType | _: ArrayType | _: MapType => 8
Review Comment:
I agree, that makes sense. From code inspection, one case that I think might produce a different result here is NullType, which I think would instead result in its default size, which is 1. I don't really understand why NullType is being explicitly set to 8 here, so I'm not sure if that would be a problem.
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-45827][SQL] Variant fixes with codegen and vectorized reader disabled [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan closed pull request #43984: [SPARK-45827][SQL] Variant fixes with codegen and vectorized reader disabled
URL: https://github.com/apache/spark/pull/43984
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org