Skip to content
Merged
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 @@ -206,7 +206,7 @@ class MetastoreImpl(appConfig: Config,

if (recreate) {
log.info(s"Recreating Hive table '$fullTableName'")
hiveHelper.createOrUpdateHiveTable(effectivePath, format, effectiveSchema, Seq(mt.infoDateColumn), mt.hiveConfig.database, hiveTable, neverRepairPartitions)
hiveHelper.createOrUpdateHiveTable(effectivePath, format, effectiveSchema, Seq(mt.infoDateColumn), mt.hiveConfig.database, hiveTable, !neverRepairPartitions)
} else {
if (hiveHelper.doesTableExist(mt.hiveConfig.database, hiveTable)) {
if (updateSchema) {
Expand All @@ -218,15 +218,15 @@ class MetastoreImpl(appConfig: Config,
} catch {
case NonFatal(ex) =>
log.warn(s"Could not update Hive schema via ${hiveHelper.getClass.getName}. Recreating Hive table '$fullTableName'", ex)
hiveHelper.createOrUpdateHiveTable(effectivePath, format, effectiveSchema, Seq(mt.infoDateColumn), mt.hiveConfig.database, hiveTable, neverRepairPartitions)
hiveHelper.createOrUpdateHiveTable(effectivePath, format, effectiveSchema, Seq(mt.infoDateColumn), mt.hiveConfig.database, hiveTable, !neverRepairPartitions)
}
} else {
// Schema didn't change, but we need to add the new partition
needAddPartition = true
}
} else {
log.info(s"The table '$fullTableName' does not exist. Creating it.")
hiveHelper.createOrUpdateHiveTable(effectivePath, format, effectiveSchema, Seq(mt.infoDateColumn), mt.hiveConfig.database, hiveTable, neverRepairPartitions)
hiveHelper.createOrUpdateHiveTable(effectivePath, format, effectiveSchema, Seq(mt.infoDateColumn), mt.hiveConfig.database, hiveTable, !neverRepairPartitions)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ abstract class HiveHelper {
partitionBy: Seq[String],
databaseName: Option[String],
tableName: String,
neverRepairPartitions: Boolean = false): Unit
autoRepairPartitions: Boolean = true): Unit

def createOrUpdateHiveTable(path: String,
format: HiveFormat,
schema: StructType,
partitionBy: Seq[String],
databaseName: Option[String],
tableName: String,
neverRepairPartitions: Boolean = false): Unit
autoRepairPartitions: Boolean = true): Unit

def replaceHiveTableSchema(schema: StructType,
partitionBy: Seq[String],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ class HiveHelperSparkCatalog(spark: SparkSession) extends HiveHelper {
partitionBy: Seq[String],
databaseName: Option[String],
tableName: String,
neverRepairPartitions: Boolean): Unit = {
autoRepairPartitions: Boolean): Unit = {
val fullTableName = HiveHelper.getFullTable(databaseName, tableName)

createCatalogTable(fullTableName, path, format)

if (partitionBy.nonEmpty && !neverRepairPartitions) {
if (partitionBy.nonEmpty && autoRepairPartitions) {
repairHiveTable(databaseName, tableName, format)
} else {
if (partitionBy.isEmpty)
log.info(s"Skipping repairing partition for $fullTableName because the table is not partitioned.")
else
log.info(s"Skipping repairing partition for $fullTableName because repairing partitions is disabled.")
log.info(s"Skipping repairing partition for $fullTableName as requested.")
}

if (!doesTableExist(databaseName, tableName)) {
Expand All @@ -58,7 +58,7 @@ class HiveHelperSparkCatalog(spark: SparkSession) extends HiveHelper {
partitionBy: Seq[String],
databaseName: Option[String],
tableName: String,
neverRepairPartitions: Boolean): Unit = {
autoRepairPartitions: Boolean): Unit = {
val fullTableName = HiveHelper.getFullTable(databaseName, tableName)

if (doesTableExist(databaseName, tableName)) {
Expand All @@ -68,13 +68,13 @@ class HiveHelperSparkCatalog(spark: SparkSession) extends HiveHelper {

createCatalogTable(fullTableName, path, format)

if (partitionBy.nonEmpty && !neverRepairPartitions) {
if (partitionBy.nonEmpty && autoRepairPartitions) {
repairHiveTable(databaseName, tableName, format)
} else {
if (partitionBy.isEmpty)
log.info(s"Skipping repairing partition for $fullTableName because the table is not partitioned.")
else
log.info(s"Skipping repairing partition for $fullTableName because repairing partitions is disabled.")
log.info(s"Skipping repairing partition for $fullTableName as requested.")
}

if (!doesTableExist(databaseName, tableName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ class HiveHelperSql(val queryExecutor: QueryExecutor,
partitionBy: Seq[String],
databaseName: Option[String],
tableName: String,
neverRepairPartitions: Boolean): Unit = {
autoRepairPartitions: Boolean): Unit = {
val fullTableName = HiveHelper.getFullTable(databaseName, tableName)

createHiveTable(fullTableName, path, format, schema, partitionBy, failIfExists = true)
if (partitionBy.nonEmpty && !neverRepairPartitions) {
if (partitionBy.nonEmpty && autoRepairPartitions) {
repairHiveTable(fullTableName)
} else {
if (partitionBy.isEmpty)
log.info(s"Skipping repairing partition for $fullTableName because the table is not partitioned.")
else
log.info(s"Skipping repairing partition for $fullTableName because repairing partitions is disabled.")
log.info(s"Skipping repairing partition for $fullTableName as requested.")
}
}

Expand All @@ -51,18 +51,18 @@ class HiveHelperSql(val queryExecutor: QueryExecutor,
partitionBy: Seq[String],
databaseName: Option[String],
tableName: String,
neverRepairPartitions: Boolean): Unit = {
autoRepairPartitions: Boolean): Unit = {
val fullTableName = HiveHelper.getFullTable(databaseName, tableName)

dropHiveTable(fullTableName)
createHiveTable(fullTableName, path, format, schema, partitionBy, failIfExists = false)
if (partitionBy.nonEmpty && !neverRepairPartitions) {
if (partitionBy.nonEmpty && autoRepairPartitions) {
repairHiveTable(fullTableName)
} else {
if (partitionBy.isEmpty)
log.info(s"Skipping repairing partition for $fullTableName because the table is not partitioned.")
else
log.info(s"Skipping repairing partition for $fullTableName because repairing partitions is disabled.")
log.info(s"Skipping repairing partition for $fullTableName as requested.")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ class HiveHelperSparkCatalogSuite extends AnyWordSpec with SparkTestBase with Te
val hiveHelper = new HiveHelperSparkCatalog(spark)
val schema = spark.read.parquet(path).schema

hiveHelper.createHiveTable(path, HiveFormat.Parquet, schema, Nil, Some("default"), "tbl1", neverRepairPartitions = false)
hiveHelper.createHiveTable(path, HiveFormat.Parquet, schema, Nil, Some("default"), "tbl1")
assert(spark.catalog.tableExists("default.tbl1"))

// If the table exists an exception should be thrown
assertThrows[AnalysisException] {
hiveHelper.createHiveTable(path, HiveFormat.Parquet, schema, Nil, Some("default"), "tbl1", neverRepairPartitions = false)
hiveHelper.createHiveTable(path, HiveFormat.Parquet, schema, Nil, Some("default"), "tbl1")
}
}
}
Expand All @@ -55,13 +55,13 @@ class HiveHelperSparkCatalogSuite extends AnyWordSpec with SparkTestBase with Te
val hiveHelper = new HiveHelperSparkCatalog(spark)
val schema = spark.read.parquet(path).withColumn("b", lit(1)).schema

hiveHelper.createHiveTable(path, HiveFormat.Parquet, schema, "a" :: "b" :: Nil, Some("default"), "tbl2", neverRepairPartitions = false)
hiveHelper.createHiveTable(path, HiveFormat.Parquet, schema, "a" :: "b" :: Nil, Some("default"), "tbl2")
assert(hiveHelper.doesTableExist(Some("default"), "tbl2"))

spark.sql(s"DROP TABLE default.tbl2").collect()
assert(!hiveHelper.doesTableExist(Some("default"), "tbl2"))

hiveHelper.createHiveTable(path, HiveFormat.Parquet, schema, "a" :: "b" :: Nil, Some("default"), "tbl2", neverRepairPartitions = false)
hiveHelper.createHiveTable(path, HiveFormat.Parquet, schema, "a" :: "b" :: Nil, Some("default"), "tbl2")
assert(hiveHelper.doesTableExist(Some("default"), "tbl2"))
}
}
Expand All @@ -73,7 +73,7 @@ class HiveHelperSparkCatalogSuite extends AnyWordSpec with SparkTestBase with Te
val hiveHelper = new HiveHelperSparkCatalog(spark)
val schema = spark.read.parquet(path).withColumn("b", lit(1)).schema

hiveHelper.createHiveTable(path, HiveFormat.Parquet, schema, "a" :: "b" :: Nil, Some("default"), "tbl3", neverRepairPartitions = false)
hiveHelper.createHiveTable(path, HiveFormat.Parquet, schema, "a" :: "b" :: Nil, Some("default"), "tbl3")
assert(hiveHelper.doesTableExist(Some("default"), "tbl3"))

assertThrows[AnalysisException] {
Expand All @@ -91,11 +91,11 @@ class HiveHelperSparkCatalogSuite extends AnyWordSpec with SparkTestBase with Te
val hiveHelper = new HiveHelperSparkCatalog(spark)
val schema = spark.read.parquet(path).schema

hiveHelper.createOrUpdateHiveTable(path, HiveFormat.Parquet, schema, Nil, Some("default"), "tbl1", neverRepairPartitions = false)
hiveHelper.createOrUpdateHiveTable(path, HiveFormat.Parquet, schema, Nil, Some("default"), "tbl1")
assert(spark.catalog.tableExists("default.tbl1"))

// If the table exists it should be re-created
hiveHelper.createOrUpdateHiveTable(path, HiveFormat.Parquet, schema, Nil, Some("default"), "tbl1", neverRepairPartitions = false)
hiveHelper.createOrUpdateHiveTable(path, HiveFormat.Parquet, schema, Nil, Some("default"), "tbl1")
assert(spark.catalog.tableExists("default.tbl1"))
}
}
Expand All @@ -107,13 +107,13 @@ class HiveHelperSparkCatalogSuite extends AnyWordSpec with SparkTestBase with Te
val hiveHelper = new HiveHelperSparkCatalog(spark)
val schema = spark.read.parquet(path).withColumn("b", lit(1)).schema

hiveHelper.createOrUpdateHiveTable(path, HiveFormat.Parquet, schema, "a" :: "b" :: Nil, Some("default"), "tbl2", neverRepairPartitions = false)
hiveHelper.createOrUpdateHiveTable(path, HiveFormat.Parquet, schema, "a" :: "b" :: Nil, Some("default"), "tbl2")
assert(hiveHelper.doesTableExist(Some("default"),"tbl2"))

spark.sql(s"DROP TABLE default.tbl2").collect()
assert(!hiveHelper.doesTableExist(Some("default"),"tbl2"))

hiveHelper.createOrUpdateHiveTable(path, HiveFormat.Parquet, schema, "a" :: "b" :: Nil, Some("default"), "tbl2", neverRepairPartitions = false)
hiveHelper.createOrUpdateHiveTable(path, HiveFormat.Parquet, schema, "a" :: "b" :: Nil, Some("default"), "tbl2")
assert(hiveHelper.doesTableExist(Some("default"),"tbl2"))
}
}
Expand All @@ -125,7 +125,7 @@ class HiveHelperSparkCatalogSuite extends AnyWordSpec with SparkTestBase with Te
val hiveHelper = new HiveHelperSparkCatalog(spark)
val schema = spark.read.format("delta").load(path).withColumn("b", lit(1)).schema

hiveHelper.createOrUpdateHiveTable(path, HiveFormat.Delta, schema, "b" :: Nil, Some("default"), "tbl3", neverRepairPartitions = false)
hiveHelper.createOrUpdateHiveTable(path, HiveFormat.Delta, schema, "b" :: Nil, Some("default"), "tbl3")
assert(hiveHelper.doesTableExist(Some("default"), "tbl3"))

assert(spark.table("default.tbl3").count() == 3)
Expand All @@ -139,7 +139,7 @@ class HiveHelperSparkCatalogSuite extends AnyWordSpec with SparkTestBase with Te
val hiveHelper = new HiveHelperSparkCatalog(spark)
val schema = spark.read.parquet(path).withColumn("b", lit(1)).schema

hiveHelper.createOrUpdateHiveTable(path, HiveFormat.Parquet, schema, "a" :: "b" :: Nil, Some("default"), "tbl4", neverRepairPartitions = true)
hiveHelper.createOrUpdateHiveTable(path, HiveFormat.Parquet, schema, "a" :: "b" :: Nil, Some("default"), "tbl4")
assert(hiveHelper.doesTableExist(Some("default"), "tbl4"))

hiveHelper.dropTable(Some("default"), "tbl4")
Expand All @@ -155,7 +155,7 @@ class HiveHelperSparkCatalogSuite extends AnyWordSpec with SparkTestBase with Te
val hiveHelper = new HiveHelperSparkCatalog(spark)
val schema = spark.read.parquet(path).withColumn("b", lit(1)).schema

hiveHelper.createOrUpdateHiveTable(path, HiveFormat.Parquet, schema, "a" :: "b" :: Nil, Some("default"), "tbl5", neverRepairPartitions = false)
hiveHelper.createOrUpdateHiveTable(path, HiveFormat.Parquet, schema, "a" :: "b" :: Nil, Some("default"), "tbl5")
assert(hiveHelper.doesTableExist(Some("default"),"tbl5"))

val df = List(("D", 40)).toDF("a", "c")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class HiveHelperSqlSuite extends AnyWordSpec with SparkTestBase with TempDirFixt
val hiveHelper = new HiveHelperSql(qe, defaultHiveConfig, false)
val schema = spark.read.parquet(path).schema

hiveHelper.createOrUpdateHiveTable(path, HiveFormat.Parquet, schema, Nil, Some("db"), "tbl", neverRepairPartitions = false)
hiveHelper.createOrUpdateHiveTable(path, HiveFormat.Parquet, schema, Nil, Some("db"), "tbl", autoRepairPartitions = false)

qe.close()

Expand Down Expand Up @@ -86,7 +86,7 @@ class HiveHelperSqlSuite extends AnyWordSpec with SparkTestBase with TempDirFixt
val hiveHelper = new HiveHelperSql(qe, defaultHiveConfig, true)
val schema = spark.read.parquet(path).withColumn("b", lit(1)).schema

hiveHelper.createOrUpdateHiveTable(path, HiveFormat.Parquet, schema, "a" :: "b" :: Nil, Some("db"), "tbl", neverRepairPartitions = false)
hiveHelper.createOrUpdateHiveTable(path, HiveFormat.Parquet, schema, "a" :: "b" :: Nil, Some("db"), "tbl")

val actual = qe.queries.mkString("\n")

Expand All @@ -113,7 +113,7 @@ class HiveHelperSqlSuite extends AnyWordSpec with SparkTestBase with TempDirFixt
val hiveHelper = new HiveHelperSql(qe, defaultHiveConfig, true)
val schema = spark.read.parquet(path).withColumn("b", lit(1)).schema

hiveHelper.createOrUpdateHiveTable(path, HiveFormat.Parquet, schema, "a" :: "b" :: Nil, Some("db"), "tbl", neverRepairPartitions = true)
hiveHelper.createOrUpdateHiveTable(path, HiveFormat.Parquet, schema, "a" :: "b" :: Nil, Some("db"), "tbl", autoRepairPartitions = false)

val actual = qe.queries.mkString("\n")

Expand Down Expand Up @@ -141,7 +141,7 @@ class HiveHelperSqlSuite extends AnyWordSpec with SparkTestBase with TempDirFixt
val hiveHelper = new HiveHelperSql(qe, defaultHiveConfig, true)
val schema = spark.read.parquet(path).withColumn("b", lit(1)).schema

hiveHelper.createHiveTable(path, HiveFormat.Parquet, schema, "a" :: "b" :: Nil, Some("db"), "tbl", neverRepairPartitions = false)
hiveHelper.createHiveTable(path, HiveFormat.Parquet, schema, "a" :: "b" :: Nil, Some("db"), "tbl")

val actual = qe.queries.mkString("\n")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ class EnceladusSink(sinkConfig: Config,

val schema = dfForHiveSchema.schema

hiveHelper.createOrUpdateHiveTable(publishBase, HiveFormat.Parquet, schema, Seq("enceladus_info_date", "enceladus_info_version"), enceladusConfig.hiveDatabase, hiveTable, neverRepairPartitions)
hiveHelper.createOrUpdateHiveTable(publishBase, HiveFormat.Parquet, schema, Seq("enceladus_info_date", "enceladus_info_version"), enceladusConfig.hiveDatabase, hiveTable, !neverRepairPartitions)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ class StandardizationSink(sinkConfig: Config,
fullSchema,
partitionBy,
standardizationConfig.hiveDatabase,
hiveTable,
neverRepairPartitions = false)
hiveTable)
(Seq.empty[String], Seq(fullTableName))
} catch {
case NonFatal(ex) =>
Expand Down
Loading