@@ -361,6 +361,16 @@ final class DataFrameWriter[T] private[sql](ds: Dataset[T]) {
361361 def insertInto (tableName : String ): Unit = {
362362 import df .sparkSession .sessionState .analyzer .{AsTableIdentifier , CatalogObjectIdentifier }
363363
364+ assertNotBucketed(" insertInto" )
365+
366+ if (partitioningColumns.isDefined) {
367+ throw new AnalysisException (
368+ " insertInto() can't be used together with partitionBy(). " +
369+ " Partition columns have already been defined for the table. " +
370+ " It is not necessary to use partitionBy()."
371+ )
372+ }
373+
364374 df.sparkSession.sessionState.sqlParser.parseMultipartIdentifier(tableName) match {
365375 case CatalogObjectIdentifier (Some (catalog), ident) =>
366376 insertInto(catalog, ident)
@@ -372,16 +382,6 @@ final class DataFrameWriter[T] private[sql](ds: Dataset[T]) {
372382 private def insertInto (catalog : CatalogPlugin , ident : Identifier ): Unit = {
373383 import org .apache .spark .sql .catalog .v2 .CatalogV2Implicits ._
374384
375- assertNotBucketed(" insertInto" )
376-
377- if (partitioningColumns.isDefined) {
378- throw new AnalysisException (
379- " insertInto() can't be used together with partitionBy(). " +
380- " Partition columns have already been defined for the table. " +
381- " It is not necessary to use partitionBy()."
382- )
383- }
384-
385385 val table = DataSourceV2Relation .create(catalog.asTableCatalog.loadTable(ident))
386386
387387 val command = modeForDSV2 match {
@@ -410,16 +410,6 @@ final class DataFrameWriter[T] private[sql](ds: Dataset[T]) {
410410 }
411411
412412 private def insertInto (tableIdent : TableIdentifier ): Unit = {
413- assertNotBucketed(" insertInto" )
414-
415- if (partitioningColumns.isDefined) {
416- throw new AnalysisException (
417- " insertInto() can't be used together with partitionBy(). " +
418- " Partition columns have already been defined for the table. " +
419- " It is not necessary to use partitionBy()."
420- )
421- }
422-
423413 runCommand(df.sparkSession, " insertInto" ) {
424414 InsertIntoTable (
425415 table = UnresolvedRelation (tableIdent),
0 commit comments