示例#1
0
def _do_get_featuregroup_partitions(featuregroup_name, featurestore_metadata, featurestore=None, featuregroup_version=1,
                                    online=False):
    """
    Gets the partitions of a featuregroup

     Args:
        :featuregroup_name: the featuregroup to get partitions for
        :featurestore: the featurestore where the featuregroup resides, defaults to the project's featurestore
        :featuregroup_version: the version of the featuregroup, defaults to 1
        :online: a boolean flag whether to fetch the online feature or the offline one (assuming that the
                 feature group that the feature is stored in has online serving enabled)
                 (for cached feature groups only)

     Returns:
        a dataframe with the partitions of the featuregroup
     """
    fg = query_planner._find_featuregroup(
        featurestore_metadata.featuregroups, featuregroup_name, featuregroup_version)
    if fg.featuregroup_type == featurestore_metadata.settings.on_demand_featuregroup_type:
        raise CannotGetPartitionsOfOnDemandFeatureGroup("The feature group with name: {} , and version: {} "
                                                        "is an on-demand feature group. "
                                                        "Get partitions operation is only supported for "
                                                        "cached feature groups."
                                                        .format(featuregroup_name, featuregroup_version))

    sql_str = "SHOW PARTITIONS " + \
        fs_utils._get_table_name(featuregroup_name, featuregroup_version)
    result = _run_and_log_sql(sql_str, featurestore, online)
    return result
示例#2
0
def _do_get_featuregroup_partitions(featuregroup_name,
                                    featurestore_metadata,
                                    featurestore=None,
                                    featuregroup_version=1):
    """
    Gets the partitions of a featuregroup

     Args:
        :featuregroup_name: the featuregroup to get partitions for
        :featurestore: the featurestore where the featuregroup resides, defaults to the project's featurestore
        :featuregroup_version: the version of the featuregroup, defaults to 1

     Returns:
        a dataframe with the partitions of the featuregroup
     """
    fg = query_planner._find_featuregroup(featurestore_metadata.featuregroups,
                                          featuregroup_name,
                                          featuregroup_version)
    if fg.featuregroup_type == featurestore_metadata.settings.on_demand_featuregroup_type:
        raise CannotGetPartitionsOfOnDemandFeatureGroup(
            "The feature group with name: {} , and version: {} "
            "is an on-demand feature group. "
            "Get partitions operation is only supported for "
            "cached feature groups.".format(featuregroup_name,
                                            featuregroup_version))
    hive = util._create_hive_connection(featurestore)

    sql_str = "SHOW PARTITIONS " + fs_utils._get_table_name(
        featuregroup_name, featuregroup_version)
    result = _run_and_log_sql(hive, sql_str)
    return result
示例#3
0
def _do_get_featuregroup(featuregroup_name, featurestore_metadata, featurestore=None, featuregroup_version=1, online=False):
    """
    Gets a featuregroup from a featurestore as a pandas dataframe

    Args:
        :featuregroup_name: name of the featuregroup to get
        :featurestore_metadata: featurestore metadata
        :featurestore: the featurestore where the featuregroup resides, defaults to the project's featurestore
        :featuregroup_version: (Optional) the version of the featuregroup
        :online: a boolean flag whether to fetch the online feature or the offline one (assuming that the
                 feature group that the feature is stored in has online serving enabled)
                 (for cached feature groups only)

    Returns:
        a pandas dataframe with the contents of the featurestore

    """
    if featurestore is None:
        featurestore = fs_utils._do_get_project_featurestore()
    fg = query_planner._find_featuregroup(
        featurestore_metadata.featuregroups, featuregroup_name, featuregroup_version)

    if fg.featuregroup_type == featurestore_metadata.settings.cached_featuregroup_type:
        return _do_get_cached_featuregroup(featuregroup_name, featurestore, featuregroup_version, online)

    raise ValueError("The feature group type: "
                     + fg.featuregroup_type + " was not recognized. Recognized types include: {} and {}"
                     .format(featurestore_metadata.settings.on_demand_featuregroup_type,
                             featurestore_metadata.settings.cached_featuregroup_type))
示例#4
0
def _do_get_featuregroup(featuregroup_name,
                         featurestore_metadata,
                         featurestore=None,
                         featuregroup_version=1):
    """
    Gets a featuregroup from a featurestore as a pandas dataframe

    Args:
        :featuregroup_name: name of the featuregroup to get
        :featurestore_metadata: featurestore metadata
        :featurestore: the featurestore where the featuregroup resides, defaults to the project's featurestore
        :featuregroup_version: (Optional) the version of the featuregroup

    Returns:
        a pandas dataframe with the contents of the featurestore

    """
    if featurestore is None:
        featurestore = fs_utils._do_get_project_featurestore()
    fg = query_planner._find_featuregroup(featurestore_metadata.featuregroups,
                                          featuregroup_name,
                                          featuregroup_version)

    if fg.featuregroup_type == featurestore_metadata.settings.cached_featuregroup_type:
        return _do_get_cached_featuregroup(featuregroup_name, featurestore,
                                           featuregroup_version)

    raise ValueError("The feature group type: "
                     + fg.featuregroup_type + " was not recognized. Recognized types include: {} and {}" \
                     .format(featurestore_metadata.settings.on_demand_featuregroup_type,
                             featurestore_metadata.settings.cached_featuregroup_type))