Skip to content

Commit ae7e806

Browse files
committed
Convert MetastoreRelation in InsertIntoTable and InsertIntoHiveTable.
1 parent ba543cd commit ae7e806

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveMetastoreCatalog.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,17 @@ private[hive] class HiveMetastoreCatalog(hive: HiveContext) extends Catalog with
440440
val attributedRewrites = relation.output.zip(parquetRelation.output)
441441
(relation, parquetRelation, attributedRewrites)
442442

443+
// Write path
444+
case InsertIntoHiveTable(relation: MetastoreRelation, _, _, _)
445+
// Inserting into partitioned table is not supported in Parquet data source (yet).
446+
if !relation.hiveQlTable.isPartitioned &&
447+
hive.convertMetastoreParquet &&
448+
hive.conf.parquetUseDataSourceApi &&
449+
relation.tableDesc.getSerdeClassName.toLowerCase.contains("parquet") =>
450+
val parquetRelation = convertToParquetRelation(relation)
451+
val attributedRewrites = relation.output.zip(parquetRelation.output)
452+
(relation, parquetRelation, attributedRewrites)
453+
443454
// Read path
444455
case p @ PhysicalOperation(_, _, relation: MetastoreRelation)
445456
if hive.convertMetastoreParquet &&
@@ -464,6 +475,16 @@ private[hive] class HiveMetastoreCatalog(hive: HiveContext) extends Catalog with
464475

465476
withAlias
466477
}
478+
case InsertIntoTable(r: MetastoreRelation, partition, child, overwrite)
479+
if relationMap.contains(r) => {
480+
val parquetRelation = relationMap(r)
481+
InsertIntoTable(parquetRelation, partition, child, overwrite)
482+
}
483+
case InsertIntoHiveTable(r: MetastoreRelation, partition, child, overwrite)
484+
if relationMap.contains(r) => {
485+
val parquetRelation = relationMap(r)
486+
InsertIntoTable(parquetRelation, partition, child, overwrite)
487+
}
467488
case other => other.transformExpressions {
468489
case a: Attribute if a.resolved => attributedRewrites.getOrElse(a, a)
469490
}

0 commit comments

Comments
 (0)