code: def get_feature_group_as_dataframe(
      feature_group_name: str,
      athena_bucket: str,
      query: str = """SELECT * FROM "sagemaker_featurestore"."#{table}"
                      WHERE is_deleted=False """,
      role: str = None,
      region: str = None,
      session=None,
      event_time_feature_name: str = None,
      latest_ingestion: bool = True,
      verbose: bool = True,
      **kwargs,
  ) -> DataFrame:
      """:class:`sagemaker.feature_store.feature_group.FeatureGroup` as :class:`pandas.DataFrame`
  
      Examples:
          >>> from sagemaker.feature_store.feature_utils import get_feature_group_as_dataframe
          >>>
          >>> region = "eu-west-1"
          >>> fg_data = get_feature_group_as_dataframe(feature_group_name="feature_group",
          >>>                                          athena_bucket="s3://bucket/athena_queries",
          >>>                                          region=region,
          >>>                                          event_time_feature_name="EventTimeId"
          >>>                                          )
          >>>
          >>> type(fg_data)
          <class 'pandas.core.frame.DataFrame'>
  
      Description:
          Method to run an athena query over a
          :class:`sagemaker.feature_store.feature_group.FeatureGroup` in a Feature Store
          to retrieve its data. It needs the :class:`sagemaker.session.Session` linked to a role
          or the region and/or role used to work with Feature Stores (it uses the module
          `sagemaker.feature_store.feature_utils.get_session_from_role`
          to get the session).
  
      Args:
          region (str): region of the target Feature Store
          feature_group_name (str): feature store name
          query (str): query to run. By default, it will take the latest ingest with data that
                      wasn't deleted. If latest_ingestion is False it will take all the data
                      in the feature group that wasn't deleted. It needs to use the keyword
                      "#{table}" to refer to the FeatureGroup name. e.g.:
                      'SELECT * FROM "sagemaker_featurestore"."#{table}"'
                      It must not end by ';'.
          athena_bucket (str): Amazon S3 bucket for running the query
          role (str): role to be assumed to extract data from feature store. If not specified
                      the default sagemaker execution role will be used.
          session (str): :class:`sagemaker.session.Session`
                          of SageMaker used to work with the feature store. Optional, with
                          role and region parameters it will infer the session.
          event_time_feature_name (str): eventTimeId feature. Mandatory only if the
                                          latest ingestion is True.
          latest_ingestion (bool): if True it will get the data only from the latest ingestion.
                                   If False it will take whatever is specified in the query, or
                                   if not specify it, it will get all the data that wasn't deleted.
          verbose (bool): if True show messages, if False is silent.
          **kwargs (object): key arguments used for the method pandas.read_csv to be able to
                      have a better tuning on data. For more info read:
                      https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html
      Returns:
          :class:`pandas.DataFrame`: dataset with the data retrieved from feature group
      """
  
      logger.setLevel(logging.WARNING)
      if verbose:
          logger.setLevel(logging.INFO)
  
      if latest_ingestion:
          if event_time_feature_name is not None:
              query += str(
                  f"AND {event_time_feature_name}=(SELECT "
                  f"MAX({event_time_feature_name}) FROM "
                  '"sagemaker_featurestore"."#{table}")'
              )
          else:
              exc = Exception(
                  "Argument event_time_feature_name must be specified "
                  "when using latest_ingestion=True."
              )
              logger.exception(exc)
              raise exc
  
      query += ";"
  
      if session is not None:
          sagemaker_session = session
      elif region is not None:
          sagemaker_session = get_session_from_role(
              region=region, assume_role=role
          )
      else:
          exc = Exception(
              "Argument Session or role and region must be specified."
          )
          logger.exception(exc)
          raise exc
  
      msg = f"Feature Group used: {feature_group_name}"
      logger.info(msg)
  
      fg = FeatureGroup(
          name=feature_group_name, sagemaker_session=sagemaker_session
      )
  
      sample_query = fg.athena_query()
      query_string = re.sub(
          r"#\{(table)\}", sample_query.table_name, query
      )
  
      msg = f"Running query:\n\t{sample_query} \n\n\t-> Save on bucket {athena_bucket}\n"
      logger.info(msg)
  
      sample_query.run(
          query_string=query_string, output_location=athena_bucket
      )
  
      sample_query.wait()
  
      # run Athena query. The output is loaded to a Pandas dataframe.
      dataset = sample_query.as_dataframe(**kwargs)
  
      msg = f"Data shape retrieve from {feature_group_name}: {dataset.shape}"
      logger.info(msg)
  
      return dataset
  
file_path: sagemaker-python-sdk/src/sagemaker/feature_store/feature_utils.py
imports: from __future__ import absolute_import
  import re
  import logging
  from typing import Union
  from pathlib import Path
  import pandas
  import boto3
  from pandas import DataFrame, Series, read_csv
  from sagemaker.feature_store.feature_group import FeatureGroup
  from sagemaker.session import Session
label_desc: Use image node_id 2 for calling a global function with example usage: get_feature_group_as_dataframe(feature_group_name, athena_bucket, query, role, region, session, event_time_feature_name, latest_ingestion, verbose) and returns: dataset