Skip to content

Commit

Permalink
[SPARK-50204][SQL] Factor out HiveTableRelation read path resolution
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

Factor out `HiveTableRelation` resolution into a separate `RelationConversions` method to reuse it in the single-pass Analyzer.

### Why are the changes needed?

Context: https://issues.apache.org/jira/browse/SPARK-49834

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Existing tests.

### Was this patch authored or co-authored using generative AI tooling?

copilot.vim.

Closes #48738 from vladimirg-db/vladimirg-db/refactor-relation-converters.

Authored-by: Vladimir Golubev <[email protected]>
Signed-off-by: Max Gekk <[email protected]>
  • Loading branch information
vladimirg-db authored and MaxGekk committed Nov 1, 2024
1 parent d6b7334 commit fc77b14
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 fc77b14

Please sign in to comment.