MCPcopy Create free account
hub / github.com/feast-dev/feast / upload_df_to_athena

Function upload_df_to_athena

sdk/python/feast/infra/utils/aws_utils.py:954–1001  ·  view source on GitHub ↗

Uploads a Pandas DataFrame to S3(Athena) as a new table. The caller is responsible for deleting the table when no longer necessary. Args: athena_client: Athena API Service client data_source: Athena Data Source database: Athena Database Name workgroup: Athen

(
    athena_client,
    data_source: str,
    database: str,
    workgroup: str,
    s3_resource,
    s3_path: str,
    table_name: str,
    df: pd.DataFrame,
)

Source from the content-addressed store, hash-verified

952
953
954def upload_df_to_athena(
955 athena_client,
956 data_source: str,
957 database: str,
958 workgroup: str,
959 s3_resource,
960 s3_path: str,
961 table_name: str,
962 df: pd.DataFrame,
963):
964 """Uploads a Pandas DataFrame to S3(Athena) as a new table.
965
966 The caller is responsible for deleting the table when no longer necessary.
967
968 Args:
969 athena_client: Athena API Service client
970 data_source: Athena Data Source
971 database: Athena Database Name
972 workgroup: Athena Workgroup Name
973 s3_resource: S3 Resource object
974 s3_path: S3 path where the Parquet file is temporarily uploaded
975 table_name: The name of the new Data Catalog table where we copy the dataframe
976 df: The Pandas DataFrame to upload
977
978 Raises:
979 AthenaTableNameTooLong: The specified table name is too long.
980 """
981
982 # Drop the index so that we dont have unnecessary columns
983 df.reset_index(drop=True, inplace=True)
984
985 # Convert Pandas DataFrame into PyArrow table and compile the Athena table schema.
986 # Note, if the underlying data has missing values,
987 # pandas will convert those values to np.nan if the dtypes are numerical (floats, ints, etc.) or boolean.
988 # If the dtype is 'object', then missing values are inferred as python `None`s.
989 # More details at:
990 # https://pandas.pydata.org/pandas-docs/stable/user_guide/missing_data.html#values-considered-missing
991 table = pa.Table.from_pandas(df)
992 upload_arrow_table_to_athena(
993 table,
994 athena_client,
995 data_source=data_source,
996 database=database,
997 workgroup=workgroup,
998 s3_resource=s3_resource,
999 s3_path=s3_path,
1000 table_name=table_name,
1001 )
1002
1003
1004def upload_arrow_table_to_athena(

Callers

nothing calls this directly

Calls 2

from_pandasMethod · 0.45

Tested by

no test coverage detected