Skip to content

Commit be2a9b5

Browse files
fix: handle partition overwrite
Co-authored-by: Thomas Chow <[email protected]>
1 parent 7f9775e commit be2a9b5

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/BigQueryFormat.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,20 @@ case class GcpFormatProvider(sparkSession: SparkSession) extends FormatProvider
4141
override def writeFormat(tableName: String): Format = {
4242

4343
val tu = TableUtils(sparkSession)
44+
val isTableReachable = tu.tableReachable(tableName)
4445
val sparkOptions: Map[String, String] =
4546
Map(
46-
"partitionField" -> tu.partitionColumn,
4747
"temporaryGcsBucket" -> sparkSession.conf.get(
4848
"spark.chronon.table.gcs.temporary_gcs_bucket"
4949
), // todo(tchow): No longer needed after https://github.com/GoogleCloudDataproc/spark-bigquery-connector/pull/1320
5050
"writeMethod" -> "indirect"
5151
)
52-
BQuery(bqOptions.getProjectId, sparkOptions)
52+
53+
if (isTableReachable) {
54+
BQuery(bqOptions.getProjectId, sparkOptions + ("partitionField" -> tu.partitionColumn))
55+
} else {
56+
BQuery(bqOptions.getProjectId, sparkOptions)
57+
}
5358
}
5459

5560
private def format(tableName: String): Format = {

0 commit comments

Comments
 (0)