Skip to content

Commit edebb11

Browse files
szehon-hoHyukjinKwon
authored andcommitted
[SQL][MINOR] Fix warnings in DataSource/WriterV2Suites
### What changes were proposed in this pull request? Fix compiler warnings in some DSV2 tests: method schema in trait Table is deprecated (since 3.4.0) Also some simplification (use analysisException() method in cases where its possible) ### Why are the changes needed? Code hygiene to remove reference to deprecated method ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Existing unit test ### Was this patch authored or co-authored using generative AI tooling? No Closes #50523 from szehon-ho/fix_warnings. Authored-by: Szehon Ho <szehon.apache@gmail.com> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
1 parent 554d678 commit edebb11

File tree

3 files changed

+205
-241
lines changed

3 files changed

+205
-241
lines changed

sql/core/src/test/scala/org/apache/spark/sql/DataFrameWriterV2Suite.scala

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import org.apache.spark.sql.catalyst.TableIdentifier
2727
import org.apache.spark.sql.catalyst.analysis.{CannotReplaceMissingTableException, TableAlreadyExistsException}
2828
import org.apache.spark.sql.catalyst.plans.logical.{AppendData, LogicalPlan, OverwriteByExpression, OverwritePartitionsDynamic}
2929
import org.apache.spark.sql.connector.InMemoryV1Provider
30-
import org.apache.spark.sql.connector.catalog.{Identifier, InMemoryTable, InMemoryTableCatalog, TableCatalog}
30+
import org.apache.spark.sql.connector.catalog.{Column, Identifier, InMemoryTable, InMemoryTableCatalog, TableCatalog}
3131
import org.apache.spark.sql.connector.catalog.CatalogManager.SESSION_CATALOG_NAME
3232
import org.apache.spark.sql.connector.expressions.{BucketTransform, ClusterByTransform, DaysTransform, FieldReference, HoursTransform, IdentityTransform, LiteralValue, MonthsTransform, YearsTransform}
3333
import org.apache.spark.sql.execution.QueryExecution
@@ -409,7 +409,8 @@ class DataFrameWriterV2Suite extends QueryTest with SharedSparkSession with Befo
409409
val table = catalog("testcat").loadTable(Identifier.of(Array(), "table_name"))
410410

411411
assert(table.name === "testcat.table_name")
412-
assert(table.schema === new StructType().add("id", LongType).add("data", StringType))
412+
assert(table.columns sameElements
413+
Array(Column.create("id", LongType), Column.create("data", StringType)))
413414
assert(table.partitioning.isEmpty)
414415
assert(table.properties == defaultOwnership.asJava)
415416
}
@@ -424,7 +425,8 @@ class DataFrameWriterV2Suite extends QueryTest with SharedSparkSession with Befo
424425
val table = catalog("testcat").loadTable(Identifier.of(Array(), "table_name"))
425426

426427
assert(table.name === "testcat.table_name")
427-
assert(table.schema === new StructType().add("id", LongType).add("data", StringType))
428+
assert(table.columns sameElements
429+
Array(Column.create("id", LongType), Column.create("data", StringType)))
428430
assert(table.partitioning.isEmpty)
429431
assert(table.properties === (Map("provider" -> "foo") ++ defaultOwnership).asJava)
430432
}
@@ -439,7 +441,8 @@ class DataFrameWriterV2Suite extends QueryTest with SharedSparkSession with Befo
439441
val table = catalog("testcat").loadTable(Identifier.of(Array(), "table_name"))
440442

441443
assert(table.name === "testcat.table_name")
442-
assert(table.schema === new StructType().add("id", LongType).add("data", StringType))
444+
assert(table.columns sameElements
445+
Array(Column.create("id", LongType), Column.create("data", StringType)))
443446
assert(table.partitioning.isEmpty)
444447
assert(table.properties === (Map("prop" -> "value") ++ defaultOwnership).asJava)
445448
}
@@ -454,7 +457,8 @@ class DataFrameWriterV2Suite extends QueryTest with SharedSparkSession with Befo
454457
val table = catalog("testcat").loadTable(Identifier.of(Array(), "table_name"))
455458

456459
assert(table.name === "testcat.table_name")
457-
assert(table.schema === new StructType().add("id", LongType).add("data", StringType))
460+
assert(table.columns sameElements
461+
Array(Column.create("id", LongType), Column.create("data", StringType)))
458462
assert(table.partitioning === Seq(IdentityTransform(FieldReference("id"))))
459463
assert(table.properties == defaultOwnership.asJava)
460464
}
@@ -550,7 +554,8 @@ class DataFrameWriterV2Suite extends QueryTest with SharedSparkSession with Befo
550554

551555
// table should not have been changed
552556
assert(table.name === "testcat.table_name")
553-
assert(table.schema === new StructType().add("id", LongType).add("data", StringType))
557+
assert(table.columns sameElements
558+
Array(Column.create("id", LongType), Column.create("data", StringType)))
554559
assert(table.partitioning === Seq(IdentityTransform(FieldReference("id"))))
555560
assert(table.properties === (Map("provider" -> "foo") ++ defaultOwnership).asJava)
556561
}
@@ -586,7 +591,8 @@ class DataFrameWriterV2Suite extends QueryTest with SharedSparkSession with Befo
586591

587592
// validate the initial table
588593
assert(table.name === "testcat.table_name")
589-
assert(table.schema === new StructType().add("id", LongType).add("data", StringType))
594+
assert(table.columns sameElements
595+
Array(Column.create("id", LongType), Column.create("data", StringType)))
590596
assert(table.partitioning === Seq(IdentityTransform(FieldReference("id"))))
591597
assert(table.properties === (Map("provider" -> "foo") ++ defaultOwnership).asJava)
592598

@@ -602,10 +608,10 @@ class DataFrameWriterV2Suite extends QueryTest with SharedSparkSession with Befo
602608

603609
// validate the replacement table
604610
assert(replaced.name === "testcat.table_name")
605-
assert(replaced.schema === new StructType()
606-
.add("id", LongType)
607-
.add("data", StringType)
608-
.add("even_or_odd", StringType))
611+
assert(replaced.columns sameElements Array(
612+
Column.create("id", LongType),
613+
Column.create("data", StringType),
614+
Column.create("even_or_odd", StringType)))
609615
assert(replaced.partitioning.isEmpty)
610616
assert(replaced.properties === defaultOwnership.asJava)
611617
}
@@ -622,7 +628,8 @@ class DataFrameWriterV2Suite extends QueryTest with SharedSparkSession with Befo
622628

623629
// validate the initial table
624630
assert(table.name === "testcat.table_name")
625-
assert(table.schema === new StructType().add("id", LongType).add("data", StringType))
631+
assert(table.columns sameElements
632+
Array(Column.create("id", LongType), Column.create("data", StringType)))
626633
assert(table.partitioning.isEmpty)
627634
assert(table.properties === (Map("provider" -> "foo") ++ defaultOwnership).asJava)
628635

@@ -638,10 +645,10 @@ class DataFrameWriterV2Suite extends QueryTest with SharedSparkSession with Befo
638645

639646
// validate the replacement table
640647
assert(replaced.name === "testcat.table_name")
641-
assert(replaced.schema === new StructType()
642-
.add("id", LongType)
643-
.add("data", StringType)
644-
.add("even_or_odd", StringType))
648+
assert(replaced.columns sameElements Array(
649+
Column.create("id", LongType),
650+
Column.create("data", StringType),
651+
Column.create("even_or_odd", StringType)))
645652
assert(replaced.partitioning === Seq(IdentityTransform(FieldReference("id"))))
646653
assert(replaced.properties === defaultOwnership.asJava)
647654
}
@@ -658,7 +665,8 @@ class DataFrameWriterV2Suite extends QueryTest with SharedSparkSession with Befo
658665

659666
// validate the initial table
660667
assert(table.name === "testcat.table_name")
661-
assert(table.schema === new StructType().add("id", LongType).add("data", StringType))
668+
assert(table.columns sameElements
669+
Array(Column.create("id", LongType), Column.create("data", StringType)))
662670
assert(table.partitioning.isEmpty)
663671
assert(table.properties === (Map("provider" -> "foo") ++ defaultOwnership).asJava)
664672

@@ -674,10 +682,10 @@ class DataFrameWriterV2Suite extends QueryTest with SharedSparkSession with Befo
674682

675683
// validate the replacement table
676684
assert(replaced.name === "testcat.table_name")
677-
assert(replaced.schema === new StructType()
678-
.add("id", LongType)
679-
.add("data", StringType)
680-
.add("even_or_odd", StringType))
685+
assert(replaced.columns sameElements
686+
Array(Column.create("id", LongType),
687+
Column.create("data", StringType),
688+
Column.create("even_or_odd", StringType)))
681689
assert(replaced.partitioning === Seq(ClusterByTransform(Seq(FieldReference("id")))))
682690
assert(replaced.properties === defaultOwnership.asJava)
683691
}
@@ -701,7 +709,8 @@ class DataFrameWriterV2Suite extends QueryTest with SharedSparkSession with Befo
701709

702710
// validate the replacement table
703711
assert(replaced.name === "testcat.table_name")
704-
assert(replaced.schema === new StructType().add("id", LongType).add("data", StringType))
712+
assert(replaced.columns sameElements
713+
Array(Column.create("id", LongType), Column.create("data", StringType)))
705714
assert(replaced.partitioning.isEmpty)
706715
assert(replaced.properties === defaultOwnership.asJava)
707716
}
@@ -719,7 +728,8 @@ class DataFrameWriterV2Suite extends QueryTest with SharedSparkSession with Befo
719728

720729
// validate the initial table
721730
assert(table.name === "testcat.table_name")
722-
assert(table.schema === new StructType().add("id", LongType).add("data", StringType))
731+
assert(table.columns sameElements
732+
Array(Column.create("id", LongType), Column.create("data", StringType)))
723733
assert(table.partitioning === Seq(IdentityTransform(FieldReference("id"))))
724734
assert(table.properties === (Map("provider" -> "foo") ++ defaultOwnership).asJava)
725735

@@ -735,10 +745,10 @@ class DataFrameWriterV2Suite extends QueryTest with SharedSparkSession with Befo
735745

736746
// validate the replacement table
737747
assert(replaced.name === "testcat.table_name")
738-
assert(replaced.schema === new StructType()
739-
.add("id", LongType)
740-
.add("data", StringType)
741-
.add("even_or_odd", StringType))
748+
assert(replaced.columns sameElements Array(
749+
Column.create("id", LongType),
750+
Column.create("data", StringType),
751+
Column.create("even_or_odd", StringType)))
742752
assert(replaced.partitioning.isEmpty)
743753
assert(replaced.properties === defaultOwnership.asJava)
744754
}

0 commit comments

Comments
 (0)