关注 spark技术分享,
撸spark源码 玩spark最佳实践

HiveExternalCatalog — Hive-Aware Metastore of Permanent Relational Entities

HiveExternalCatalog — Hive-Aware Metastore of Permanent Relational Entities

HiveExternalCatalog is a external catalog of permanent relational entities (aka metastore) that is used when SparkSession was created with Hive support enabled.

spark sql HiveExternalCatalog.png
Figure 1. HiveExternalCatalog and SharedState

HiveExternalCatalog is created exclusively when SharedState is requested for the ExternalCatalog for the first time (and spark.sql.catalogImplementation internal configuration property is hive).

Note
The Hadoop configuration to create a HiveExternalCatalog is the default Hadoop configuration from Spark Core’s SparkContext.hadoopConfiguration with the Spark properties with spark.hadoop prefix.

HiveExternalCatalog uses the internal HiveClient to retrieve metadata from a Hive metastore.

Note

spark.sql.catalogImplementation configuration property is in-memory by default.

Use Builder.enableHiveSupport to enable Hive support (that sets spark.sql.catalogImplementation internal configuration property to hive when the Hive classes are available).

Tip

Use spark.sql.warehouse.dir Spark property to change the location of Hive’s hive.metastore.warehouse.dir property, i.e. the location of the Hive local/embedded metastore database (using Derby).

Refer to SharedState to learn about (the low-level details of) Spark SQL support for Apache Hive.

See also the official Hive Metastore Administration document.

Table 1. HiveExternalCatalog’s Internal Properties (e.g. Registries, Counters and Flags)
Name Description

client

HiveClient for retrieving metadata from a Hive metastore

Created by requesting HiveUtils for a new HiveClientImpl (with the current SparkConf and Hadoop Configuration)

getRawTable Method

getRawTable…​FIXME

Note
getRawTable is used when…​FIXME

doAlterTableStats Method

Note
doAlterTableStats is part of ExternalCatalog Contract to alter the statistics of a table.

doAlterTableStats…​FIXME

Converting Table Statistics to Properties — statsToProperties Internal Method

statsToProperties converts the table statistics to properties (i.e. key-value pairs that will be persisted as properties in the table metadata to a Hive metastore using the Hive client).

statsToProperties adds the following properties to the properties:

statsToProperties takes the column statistics and for every column (field) in schema converts the column statistics to properties and adds the properties (as column statistic property) to the properties.

Note

statsToProperties is used when HiveExternalCatalog is requested for:

Restoring Table Statistics from Properties (from Hive Metastore) — statsFromProperties Internal Method

statsFromProperties collects statistics-related properties, i.e. the properties with their keys with spark.sql.statistics prefix.

statsFromProperties returns None if there are no keys with the spark.sql.statistics prefix in properties.

If there are keys with spark.sql.statistics prefix, statsFromProperties creates a ColumnStat that is the column statistics for every column in schema.

For every column name in schema statsFromProperties collects all the keys that start with spark.sql.statistics.colStats.[name] prefix (after having checked that the key spark.sql.statistics.colStats.[name].version exists that is a marker that the column statistics exist in the statistics properties) and converts them to a ColumnStat (for the column name).

In the end, statsFromProperties creates a CatalogStatistics with the following properties:

  • sizeInBytes as spark.sql.statistics.totalSize property

  • rowCount as spark.sql.statistics.numRows property

  • colStats as the collection of the column names and their ColumnStat (calculated above)

Note
statsFromProperties is used when HiveExternalCatalog is requested for restoring table and partition metadata.

listPartitionsByFilter Method

Note
listPartitionsByFilter is part of ExternalCatalog Contract to…​FIXME.

listPartitionsByFilter…​FIXME

alterPartitions Method

Note
alterPartitions is part of ExternalCatalog Contract to…​FIXME.

alterPartitions…​FIXME

getTable Method

Note
getTable is part of ExternalCatalog Contract to…​FIXME.

getTable…​FIXME

doAlterTable Method

Note
doAlterTable is part of ExternalCatalog Contract to alter a table.

doAlterTable…​FIXME

restorePartitionMetadata Internal Method

restorePartitionMetadata…​FIXME

Note

restorePartitionMetadata is used when HiveExternalCatalog is requested for:

getPartition Method

Note
getPartition is part of ExternalCatalog Contract to…​FIXME.

getPartition…​FIXME

getPartitionOption Method

Note
getPartitionOption is part of ExternalCatalog Contract to…​FIXME.

getPartitionOption…​FIXME

Creating HiveExternalCatalog Instance

HiveExternalCatalog takes the following when created:

Building Property Name for Column and Statistic Key — columnStatKeyPropName Internal Method

columnStatKeyPropName builds a property name of the form spark.sql.statistics.colStats.[columnName].[statKey] for the input columnName and statKey.

Note
columnStatKeyPropName is used when HiveExternalCatalog is requested to statsToProperties and statsFromProperties.

getBucketSpecFromTableProperties Internal Method

getBucketSpecFromTableProperties…​FIXME

Note
getBucketSpecFromTableProperties is used when HiveExternalCatalog is requested to restoreHiveSerdeTable or restoreDataSourceTable.

Restoring Hive Serde Table — restoreHiveSerdeTable Internal Method

restoreHiveSerdeTable…​FIXME

Note
restoreHiveSerdeTable is used exclusively when HiveExternalCatalog is requested to restoreTableMetadata (when there is no provider specified in table properties, which means this is a Hive serde table).

Restoring Data Source Table — restoreDataSourceTable Internal Method

restoreDataSourceTable…​FIXME

Note
restoreDataSourceTable is used exclusively when HiveExternalCatalog is requested to restoreTableMetadata (for regular data source table with provider specified in table properties).

restoreTableMetadata Internal Method

restoreTableMetadata…​FIXME

Note

restoreTableMetadata is used when HiveExternalCatalog is requested for:

Retrieving CatalogTablePartition of Table — listPartitions Method

Note
listPartitions is part of the ExternalCatalog Contract to list partitions of a table.

listPartitions…​FIXME

doCreateTable Method

Note
doCreateTable is part of the ExternalCatalog Contract to…​FIXME.

doCreateTable…​FIXME

tableMetaToTableProps Internal Method

tableMetaToTableProps…​FIXME

Note
tableMetaToTableProps is used when HiveExternalCatalog is requested to doAlterTableDataSchema and doCreateTable (and createDataSourceTable).

doAlterTableDataSchema Method

Note
doAlterTableDataSchema is part of the ExternalCatalog Contract to…​FIXME.

doAlterTableDataSchema…​FIXME

createDataSourceTable Internal Method

createDataSourceTable…​FIXME

Note
createDataSourceTable is used exclusively when HiveExternalCatalog is requested to doCreateTable (for non-hive providers).
赞(0) 打赏
未经允许不得转载:spark技术分享 » HiveExternalCatalog — Hive-Aware Metastore of Permanent Relational Entities
分享到: 更多 (0)

关注公众号:spark技术分享

联系我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏