实战指南:用DataHub管理Hive元数据

发布于:2025-06-19 ⋅ 阅读:(19) ⋅ 点赞:(0)

在这里插入图片描述

通过DataHub提取和管理hive元数据


本文由「大千AI助手」原创发布,专注用真话讲AI,回归技术本质。拒绝神话或妖魔化。搜索「大千AI助手」关注我,一起撕掉过度包装,学习真实的AI技术!

简介

  • 通过DataHub的Hive数据源连接器可以接入Hive的库、表、列、存储信息、统计信息等元数据
  • 哪些元数据
    • 库、表的元数据
    • 列的类型的元数据
    • 详细的表属性和存储的元数据
    • 表、行、列的统计信息的元数据(需要SQL Profiling功能)
  • DataHub中的功能点
    • 资产容器(Asset Containers)
    • 描述信息(Descriptions)
    • 平台实例(Platform Instance)
    • Schema元数据(Schema Metadata)
    • 分类(Classification)
      • 需要设置classification.enabled
    • 删除实体检测(Detect Deleted Entities)
      • 需要设置stateful_ingestion.remove_stale_metadata
    • 领域(Domains)
      • 需要设置domain
  • 底层通过Python的pyhive库进行提取

往期文章推荐:

配置

基本配置

从哪里取
  • sqlalchemy_uri- string, 连接URI. 优先级最高(高于其他连接参数).
    • 参考 - https://docs.sqlalchemy.org/en/14/core/engines.html#database-urls.
  • host_port- string, hive地址和端口, 默认hive:9083, 腾讯云emr为ip:7001
  • username- string, 用户名
  • password- string(password), 密码
  • options- map, 该配置都会作为kwargs参数传给SQLAlchemy.create_engine
    • 设置URL中的连接参数,可以通过connect_args参数指定
    • 比如设置认证方式为LDAP, connect_args: auth: LDAP
取什么
  • include_tables- boolean, 是否提取tables的元数据, 默认 True
  • include_views- boolean, 是否提取views的元数据. 默认 True
  • include_view_lineage- boolean, 是否自动提取view->view和table->view的血缘关系(通过DataHub的sql parser从view的创建语句中提取). 默认 True
  • include_column_lineage- boolean, 是否提取列级血缘关系(从storage中提取), 默认 True
  • include_view_column_lineage- boolean, 是否自动提取view->view和table->view的列级血缘关系(通过DataHub的sql parser从view的创建语句中提取), 依赖include_view_lineage, 默认 True
  • emit_storage_lineage- boolean, 是否生成storage-to-Hive的血缘, 默认False
  • hive_storage_lineage_direction- string, upstream则storage是Hive的上游, downstream则storage是Hive的下游, 默认 upstream
  • database- string, database (catalog), 如果不设置则从所有数据库取(可通过database_pattern过滤)
  • database_pattern- AllowDenyPattern, 要提取的数据库的正则表达式, 默认 {'allow': ['.*'], 'deny': [], 'ignoreCase': True}
    • database_pattern.ignoreCase- boolean, 正则匹配时是否忽略大小写, 默认 True
    • database_pattern.allow- array, 要提取的数据库的正则表达式, 默认 ['.*']
    • database_pattern.allow.string- string
    • database_pattern.deny- array, 不提取的数据库的正则表达式, 默认 []
    • database_pattern.deny.string- string
  • table_pattern- AllowDenyPattern, 要提取的表的正则表达式, 全名匹配database.schema.table, 默认 {'allow': ['.*'], 'deny': [], 'ignoreCase': True}
    • 示例'Customer.public.customer.*'
    • 实际验证还是<database>.<table>的格式
    • table_pattern.ignoreCase- boolean, 正则匹配时是否忽略大小写, 默认 True
    • table_pattern.allow- array, 要提取的表的正则表达式, 默认 ['.*']
    • table_pattern.allow.string- string
    • table_pattern.deny- array, 不提取的表的正则表达式, 默认 []
    • table_pattern.deny.string- string
  • view_pattern- AllowDenyPattern, 要提取的视图的正则表达式, 全名匹配database.schema.table, 默认取值同table_pattern
    • 示例'Customer.public.customer.*'
    • view_pattern.ignoreCase- boolean, 正则匹配时是否忽略大小写, 默认 True
    • view_pattern.allow- array, 要提取的视图的正则表达式, 默认 ['.*']
    • view_pattern.allow.string- string
    • view_pattern.deny- array, 不提取的视图的正则表达式, 默认 []
    • view_pattern.deny.string- string
  • column_pattern- AllowDenyPattern, 要提取的列的正则表达式, 全名匹配database.schema.table.column, 默认 {'allow': ['.*'], 'deny': [], 'ignoreCase': True}
    • column_pattern.ignoreCase- boolean, 正则匹配时是否忽略大小写, 默认 True
    • column_pattern.allow- Array of string, 要提取的列的正则表达式列表, 默认 ['.*']
    • column_pattern.allow.string- string
    • column_pattern.deny- Array of string, 不要提取的列的正则表达式列表, 默认 []
    • column_pattern.deny.string- string
  • profile_pattern- AllowDenyPattern, 用来提取profile的表或列的正则表达式(与table_pattern取交集), 默认 {'allow': ['.*'], 'deny': [], 'ignoreCase': True}
  • profiling- profile的配置, 默认 {'enabled': False, 'operation_config': {'lower_freq_profile_enabled': False, 'profile_day_of_week': None, 'profile_date_of_month': None}, 'limit': None, 'offset': None, 'profile_table_level_only': False, 'include_field_null_count': True, 'include_field_distinct_count': True, 'include_field_min_value': True, 'include_field_max_value': True, 'include_field_mean_value': True, 'include_field_median_value': True, 'include_field_stddev_value': True, 'include_field_quantiles': False, 'include_field_distinct_value_frequencies': False, 'include_field_histogram': False, 'include_field_sample_values': True, 'max_workers': 20, 'report_dropped_profiles': False, 'turn_off_expensive_profiling_metrics': False, 'field_sample_values_limit': 20, 'max_number_of_fields_to_profile': None, 'profile_if_updated_since_days': None, 'profile_table_size_limit': 5, 'profile_table_row_limit': 5000000, 'profile_table_row_count_estimate_only': False, 'query_combiner_enabled': True, 'catch_exceptions': True, 'partition_profiling_enabled': True, 'partition_datetime': None, 'use_sampling': True, 'sample_size': 10000, 'profile_external_tables': False, 'tags_to_ignore_sampling': None, 'profile_nested_fields': False}
特殊标识
  • platform_instance- string, 平台实例(该配置获取的所有资产所属的平台实例)
    • 参考 - https://datahubproject.io/docs/platform-instances/
  • storage_platform_instance- string, storage系统的平台实例
  • env- string, 环境名(该配置获取的所有资产所属的环境), 默认 PROD
    • 比如从多个Hive实例获取数据,则可以设置env为不同的值
  • domain- map(str,AllowDenyPattern)
  • classification- ClassificationConfig, 分类信息, 默认{'enabled': False, 'sample_size': 100, 'max_workers': 4, 'table_pattern': {'allow': ['.*'], 'deny': [], 'ignoreCase': True}, 'column_pattern': {'allow': ['.*'], 'deny': [], 'ignoreCase': True}, 'info_type_to_term': {}, 'classifiers': [{'type': 'datahub', 'config': None}]}
    • 参考 - https://datahubproject.io/docs/0.15.0/metadata-ingestion/docs/dev_guides/classification/
    • 参考datahub-classification
怎么取
  • incremental_lineage- boolean, 是否增量更新DataHub中已有的血缘关系, 默认 False
  • convert_urns_to_lowercase- boolean, 是否转换dataset的urns为全小写, 默认 False
  • use_file_backed_cache- boolean, 是否对view定义使用基于文件的缓存, 默认 True
  • stateful_ingestion- StatefulStaleMetadataRemovalConfig, 提取状态设置
    • stateful_ingestion.enabled- boolean, 是否有状态的提取,默认如果设置pipeline_name且指定datahub-restdatahub_api则为True, 否则False
    • stateful_ingestion.fail_safe_threshold- number, 阻止状态改变的阈值(和之前的entity相比如果新提取的entity变化的比例超过该阈值则主动失败), 取值0-100, 默认75.0
    • stateful_ingestion.remove_stale_metadata- boolean, 是否软删除上次成功运行提取的有但本次提取没有的实体, 默认True
      • 依赖stateful_ingestion.enabled=True

实例配置

基本配置

source:
  type: hive
  config:
    host_port: localhost:10000
    database: DemoDatabase
    username: user
    password: pass

    # For more details on authentication, see the PyHive docs:
    # https://github.com/dropbox/PyHive#passing-session-configuration.
    # LDAP, Kerberos, etc. are supported using connect_args, which can be
    # added under the `options` config parameter.
    #options:
    #  connect_args:
    #    auth: KERBEROS
    #    kerberos_service_name: hive
    #scheme: 'hive+http' # set this if Thrift should use the HTTP transport
    #scheme: 'hive+https' # set this if Thrift should use the HTTP with SSL transport
    #scheme: 'sparksql' # set this for Spark Thrift Server

参考

  • https://datahubproject.io/docs/generated/ingestion/sources/hive/

本文由「大千AI助手」原创发布,专注用真话讲AI,回归技术本质。拒绝神话或妖魔化。搜索「大千AI助手」关注我,一起撕掉过度包装,学习真实的AI技术!


网站公告

今日签到

点亮在社区的每一天
去签到