Beispiel #1
0
def delete_all_data_sources(
        account_id: Optional[str] = None,
        boto3_session: Optional[boto3.Session] = None) -> None:
    """Delete all data sources.

    Parameters
    ----------
    account_id : str, optional
        If None, the account ID will be inferred from your boto3 session.
    boto3_session : boto3.Session(), optional
        Boto3 Session. The default boto3 session will be used if boto3_session receive None.

    Returns
    -------
    None
        None.

    Examples
    --------
    >>> import awswrangler as wr
    >>> wr.quicksight.delete_all_data_sources()
    """
    session: boto3.Session = _utils.ensure_session(session=boto3_session)
    if account_id is None:
        account_id = sts.get_account_id(boto3_session=session)
    for data_source in list_data_sources(account_id=account_id,
                                         boto3_session=session):
        delete_data_source(data_source_id=data_source["DataSourceId"],
                           account_id=account_id,
                           boto3_session=session)
Beispiel #2
0
def extract_athena_query_columns(
        sql: str, data_source_arn: str, account_id: str,
        boto3_session: boto3.Session) -> List[Dict[str, str]]:
    """Extract athena columns data types from a SQL query."""
    data_sources: List[Dict[str, Any]] = list_data_sources(
        account_id=account_id, boto3_session=boto3_session)
    data_source: Dict[str, Any] = [
        x for x in data_sources if x["Arn"] == data_source_arn
    ][0]
    workgroup: str = data_source["DataSourceParameters"]["AthenaParameters"][
        "WorkGroup"]
    sql_wrapped: str = f"/* QuickSight */\nSELECT ds.* FROM ( {sql} ) ds LIMIT 0"
    query_id: str = athena.start_query_execution(sql=sql_wrapped,
                                                 workgroup=workgroup,
                                                 boto3_session=boto3_session)
    athena.wait_query(query_execution_id=query_id, boto3_session=boto3_session)
    dtypes: Dict[str, str] = athena.get_query_columns_types(
        query_execution_id=query_id, boto3_session=boto3_session)
    return [{
        "Name": name,
        "Type": _data_types.athena2quicksight(dtype=dtype)
    } for name, dtype in dtypes.items()]