Skip to content

Commit

Permalink
Factor out HiveTableRelation read path
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirg-db committed Nov 1, 2024
1 parent 4e6b938 commit ec6837e
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import org.apache.spark.sql.catalyst.rules.Rule
import org.apache.spark.sql.errors.QueryCompilationErrors
import org.apache.spark.sql.execution._
import org.apache.spark.sql.execution.command.{CreateTableCommand, DDLUtils, InsertIntoDataSourceDirCommand}
import org.apache.spark.sql.execution.datasources.{CreateTable, DataSourceStrategy, HadoopFsRelation, InsertIntoHadoopFsRelationCommand, LogicalRelationWithTable}
import org.apache.spark.sql.execution.datasources.{CreateTable, DataSourceStrategy, HadoopFsRelation, InsertIntoHadoopFsRelationCommand, LogicalRelation, LogicalRelationWithTable}
import org.apache.spark.sql.hive.execution._
import org.apache.spark.sql.hive.execution.HiveScriptTransformationExec
import org.apache.spark.sql.hive.execution.InsertIntoHiveTable.BY_CTAS
Expand Down Expand Up @@ -240,9 +240,8 @@ case class RelationConversions(
query, overwrite, ifPartitionNotExists, byName)

// Read path
case relation: HiveTableRelation
if DDLUtils.isHiveTable(relation.tableMeta) && isConvertible(relation) =>
metastoreCatalog.convert(relation, isWrite = false)
case relation: HiveTableRelation if doConvertHiveTableRelationForRead(relation) =>
convertHiveTableRelationForRead(relation)

// CTAS path
// This `InsertIntoHiveTable` is derived from `CreateHiveTableAsSelectCommand`,
Expand Down Expand Up @@ -287,6 +286,15 @@ case class RelationConversions(
convertProvider(storage), query, overwrite)
}
}

private[hive] def doConvertHiveTableRelationForRead(relation: HiveTableRelation): Boolean = {
DDLUtils.isHiveTable(relation.tableMeta) && isConvertible(relation)
}

private[hive] def convertHiveTableRelationForRead(
relation: HiveTableRelation): LogicalRelation = {
metastoreCatalog.convert(relation, isWrite = false)
}
}

private[hive] trait HiveStrategies {
Expand Down

0 comments on commit ec6837e

Please sign in to comment.