@@ -284,12 +284,12 @@ class TableUtils(@transient val sparkSession: SparkSession) extends Serializable
284
284
tableProperties : Map [String , String ] = null ,
285
285
fileFormat : String ,
286
286
autoExpand : Boolean = false ): Unit = {
287
+ val writeFormat = tableFormatProvider.writeFormat(tableName)
287
288
288
289
if (! tableReachable(tableName)) {
289
290
290
291
try {
291
292
292
- val writeFormat = tableFormatProvider.writeFormat(tableName)
293
293
val createTableOperation =
294
294
writeFormat.createTable(df, tableName, partitionColumns, tableProperties, fileFormat)
295
295
@@ -309,11 +309,13 @@ class TableUtils(@transient val sparkSession: SparkSession) extends Serializable
309
309
310
310
// TODO: we need to also allow for bigquery tables to have their table properties (or tags) to be persisted too.
311
311
// https://app.asana.com/0/1208949807589885/1209111629687568/f
312
- if (tableProperties != null && tableProperties.nonEmpty) {
313
- sql(alterTablePropertiesSql(tableName, tableProperties))
314
- }
315
- if (autoExpand) {
316
- expandTable(tableName, df.schema)
312
+ if (writeFormat.name.toUpperCase != " BIGQUERY" ) {
313
+ if (tableProperties != null && tableProperties.nonEmpty) {
314
+ sql(alterTablePropertiesSql(tableName, tableProperties))
315
+ }
316
+ if (autoExpand) {
317
+ expandTable(tableName, df.schema)
318
+ }
317
319
}
318
320
}
319
321
@@ -328,12 +330,12 @@ class TableUtils(@transient val sparkSession: SparkSession) extends Serializable
328
330
stats : Option [DfStats ] = None ,
329
331
sortByCols : Seq [String ] = Seq .empty): Unit = {
330
332
// partitions to the last
331
- val dfRearranged : DataFrame = if ( ! df.columns.endsWith (partitionColumns)) {
332
- val colOrder = df.columns.diff(partitionColumns) ++ partitionColumns
333
- df.select(colOrder.map(df.col) : _* )
334
- } else {
335
- df
336
- }
333
+ val colOrder = df.columns.diff (partitionColumns) ++ partitionColumns
334
+ val dfRearranged : DataFrame = df.select(colOrder.map {
335
+ case c if c == partitionColumn =>
336
+ to_date(df.col(c), partitionFormat).as(partitionColumn)
337
+ case c => df.col(c)
338
+ }: _* )
337
339
338
340
createTable(dfRearranged, tableName, partitionColumns, tableProperties, fileFormat, autoExpand)
339
341
@@ -526,11 +528,6 @@ class TableUtils(@transient val sparkSession: SparkSession) extends Serializable
526
528
val dataPointer = DataPointer .from(tableName, sparkSession)
527
529
528
530
saltedDf
529
- .select(saltedDf.columns.map {
530
- case c if c == partitionColumn && dataPointer.writeFormat.map(_.toUpperCase).exists(" BIGQUERY" .equals) =>
531
- to_date(saltedDf.col(c), partitionFormat).as(partitionColumn)
532
- case c => saltedDf.col(c)
533
- }.toList: _* )
534
531
.repartition(shuffleParallelism, repartitionCols.map(saltedDf.col): _* )
535
532
.drop(saltCol)
536
533
.sortWithinPartitions(partitionSortCols.map(col): _* )
0 commit comments