Skip to content
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

[Spark] Make delta.dataSkippingStatsColumns more lenient for nested columns #2850

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
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 @@ -459,16 +459,22 @@ object StatisticsCollection extends DeltaCommand {
* @param name The name of the data skipping column for validating data type.
* @param dataType The data type of the data skipping column.
* @param columnPaths The column paths of all valid fields.
* @param insideStruct Tracks if we are inside a struct, in which case all types are valid
*/
private def validateDataSkippingType(
name: String,
dataType: DataType,
columnPaths: ArrayBuffer[String]): Unit = dataType match {
columnPaths: ArrayBuffer[String],
insideStruct: Boolean = false): Unit = dataType match {
case s: StructType =>
s.foreach { field =>
validateDataSkippingType(name + "." + field.name, field.dataType, columnPaths)
validateDataSkippingType(name + "." + field.name, field.dataType, columnPaths,
insideStruct = true)
}
case SkippingEligibleDataType(_) => columnPaths.append(name)
case d if insideStruct =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also make the non-struct field have the same behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up to you. The idea was if you directly specify an in-eligible type, throw an exception because you did something wrong. If you specify a struct, just work with the sub fields that are supported

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then, I am good about it.
Thank you

logWarning(s"Data skipping is not supported for column $name of type $dataType")
columnPaths.append(name)
case _ =>
throw new DeltaIllegalArgumentException(
errorClass = "DELTA_COLUMN_DATA_SKIPPING_NOT_SUPPORTED_TYPE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,33 @@ trait DataSkippingDeltaTestsBase extends DeltaExcludedBySparkVersionTestMixinShi
deltaStatsColNamesOpt = Some("b.c")
)

testSkipping(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider double struct test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a double nested struct as well

"indexed column names - naming a nested column allows nested complex types",
"""{
"a": {
"b": [1, 2, 3],
"c": [4, 5, 6],
"d": 7,
"e": 8,
"f": {
"g": 9
}
},
"i": 10
}""".replace("\n", ""),
hits = Seq(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have hit tests for elements inside struct and the double struct as well?

Btw click on re-request review so that I get notified.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added more hit tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that when we are inside struct, we gather stats for the valid datatypes inside the struct, but the invalid ones we still don't right? Would we want to test that we still don't skip the invalid datatypes inside the struct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if we can check another skipping valid type beside integer, like timestamp, string, ... that would be great

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically null counts are collected, but they can't be used for skipping. We could add that to the test, but seems kind of out of scope because you can't do min/max things with arrays/maps anyway, so it'd have to be like an element contains or something

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are other non-skipping eligible datatypes than lists datatypes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to specify a Binary type in the inferred JSON. Is that the only non-complex type?

"i < 0",
"a.d > 6",
"a.f.g < 10"
),
misses = Seq(
"a.d < 0",
"a.e < 0",
"a.f.g < 0"
),
deltaStatsColNamesOpt = Some("a")
)

testSkipping(
"indexed column names - index only a subset of leaf columns",
"""{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,14 +499,13 @@ class StatsCollectionSuite
("BINARY", "BinaryType"),
("BOOLEAN", "BooleanType"),
("ARRAY<TINYINT>", "ArrayType(ByteType,true)"),
Kimahriman marked this conversation as resolved.
Show resolved Hide resolved
("MAP<DATE, INT>", "MapType(DateType,IntegerType,true)"),
("STRUCT<c60:INT, c61:ARRAY<INT>>", "ArrayType(IntegerType,true)")
("MAP<DATE, INT>", "MapType(DateType,IntegerType,true)")
Kimahriman marked this conversation as resolved.
Show resolved Hide resolved
).foreach { case (invalidType, typename) =>
val tableName1 = "delta_table_1"
val tableName2 = "delta_table_2"
test(s"Delta statistic column: invalid data type $invalidType") {
withTable(tableName1, tableName2) {
val columnName = if (typename.equals("ArrayType(IntegerType,true)")) "c2.c61" else "c2"
val columnName = "c2"
val exceptOne = intercept[DeltaIllegalArgumentException] {
sql(
s"create table $tableName1 (c1 long, c2 $invalidType) using delta " +
Expand All @@ -530,7 +529,7 @@ class StatsCollectionSuite

test(s"Delta statistic column: invalid data type $invalidType in nested column") {
withTable(tableName1, tableName2) {
val columnName = if (typename == "ArrayType(IntegerType,true)") "c2.c21.c61" else "c2.c21"
val columnName = "c2.c21"
val exceptOne = intercept[DeltaIllegalArgumentException] {
sql(
s"create table $tableName1 (c1 long, c2 STRUCT<c20:INT, c21:$invalidType>) " +
Expand All @@ -541,16 +540,6 @@ class StatsCollectionSuite
exceptOne.getErrorClass == "DELTA_COLUMN_DATA_SKIPPING_NOT_SUPPORTED_TYPE" &&
exceptOne.getMessageParametersArray.toSeq == Seq(columnName, typename)
)
val exceptTwo = intercept[DeltaIllegalArgumentException] {
sql(
s"create table $tableName1 (c1 long, c2 STRUCT<c20:INT, c21:$invalidType>) " +
s"using delta TBLPROPERTIES('delta.dataSkippingStatsColumns' = 'c2')"
)
}
assert(
exceptTwo.getErrorClass == "DELTA_COLUMN_DATA_SKIPPING_NOT_SUPPORTED_TYPE" &&
exceptTwo.getMessageParametersArray.toSeq == Seq(columnName, typename)
)
sql(s"create table $tableName2 (c1 long, c2 STRUCT<c20:INT, c21:$invalidType>) using delta")
val exceptThree = interceptWithUnwrapping[DeltaIllegalArgumentException] {
sql(
Expand All @@ -561,13 +550,6 @@ class StatsCollectionSuite
exceptThree.getErrorClass == "DELTA_COLUMN_DATA_SKIPPING_NOT_SUPPORTED_TYPE" &&
exceptThree.getMessageParametersArray.toSeq == Seq(columnName, typename)
)
val exceptFour = interceptWithUnwrapping[DeltaIllegalArgumentException] {
sql(s"ALTER TABLE $tableName2 SET TBLPROPERTIES('delta.dataSkippingStatsColumns'='c2')")
}
assert(
exceptFour.getErrorClass == "DELTA_COLUMN_DATA_SKIPPING_NOT_SUPPORTED_TYPE" &&
exceptFour.getMessageParametersArray.toSeq == Seq(columnName, typename)
)
}
}
}
Expand Down Expand Up @@ -608,7 +590,8 @@ class StatsCollectionSuite

Seq(
"BIGINT", "DATE", "DECIMAL(3, 2)", "DOUBLE", "FLOAT", "INT", "SMALLINT", "STRING",
"TIMESTAMP", "TIMESTAMP_NTZ", "TINYINT"
"TIMESTAMP", "TIMESTAMP_NTZ", "TINYINT", "STRUCT<c3: BIGINT>",
Copy link
Contributor

@longvu-db longvu-db Aug 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there are relevant tests in DataSkippingDeltaTests as well

, could you take a look at this whole file as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those tests are for specifying the number of indexed columns, not columns by name

"STRUCT<c3: BIGINT, c4: ARRAY<BIGINT>>"
).foreach { validType =>
val tableName1 = "delta_table_1"
val tableName2 = "delta_table_2"
Expand Down
Loading