Calculated fields from a REST API call

0

is it possible to have a calculated field being populated from a REST call? If yes then please share steps

질문됨 2년 전717회 조회
1개 답변
0

Thank you for posting your question, you can use the following API calls to create calculated fields:

describe_data_set

update_data_set

Step 1: get the parameters required for update_data_set API call using describe_data_set API call

import json
import boto3
client = boto3.client('quicksight')
response = client.describe_data_set(
    AwsAccountId='AWS Account ID',
    DataSetId='DatasetID'
)
print(response)

Step 2: Get the PhysicalTableMap and LogicalMap for the existing Dataset from the response in step 1

import json
import boto3
client = boto3.client('quicksight')
response = client.update_data_set(
AwsAccountId='Account ID',
DataSetId='DatsetID',
Name='Web and Social Media Analytics',
PhysicalTableMap = {
            "String": {
                "S3Source": {
                    "DataSourceArn": "arn:aws:quicksight:us-east-1:<AccountID>:datasource/<DatsetID>",
                    "UploadSettings": {
                        "Format": "CSV",
                        "StartFromRow": 1,
                        "ContainsHeader": True,
                        "TextQualifier": "DOUBLE_QUOTE",
                        "Delimiter": ","
                    },
                    "InputColumns": [
                        {
                            "Name": "ColumnId-1",
                            "Type": "STRING"
                        },
                        {
                            "Name": "ColumnId-2",
                            "Type": "STRING"
                        },
                        {
                            "Name": "ColumnId-3",
                            "Type": "STRING"
                        },
                        {
                            "Name": "ColumnId-4",
                            "Type": "STRING"
                        },
                        {
                            "Name": "ColumnId-5",
                            "Type": "STRING"
                        },
                        {
                            "Name": "ColumnId-6",
                            "Type": "STRING"
                        },
                        {
                            "Name": "ColumnId-7",
                            "Type": "STRING"
                        },
                        {
                            "Name": "ColumnId-8",
                            "Type": "STRING"
                        },
                        {
                            "Name": "ColumnId-9",
                            "Type": "STRING"
                        },
                        {
                            "Name": "ColumnId-10",
                            "Type": "STRING"
                        },
                        {
                            "Name": "ColumnId-11",
                            "Type": "STRING"
                        },
                        {
                            "Name": "ColumnId-12",
                            "Type": "STRING"
                        },
                        {
                            "Name": "ColumnId-13",
                            "Type": "STRING"
                        },
                        {
                            "Name": "ColumnId-14",
                            "Type": "STRING"
                        },
                        {
                            "Name": "ColumnId-15",
                            "Type": "STRING"
                        },
                        {
                            "Name": "ColumnId-16",
                            "Type": "STRING"
                        },
                        {
                            "Name": "ColumnId-17",
                            "Type": "STRING"
                        },
                        {
                            "Name": "ColumnId-18",
                            "Type": "STRING"
                        },
                        {
                            "Name": "ColumnId-19",
                            "Type": "STRING"
                        }
                    ]
                }
            }
        },
        LogicalTableMap = {
            "String": {
                "Alias": "Web and Social Media Analytics",
              "DataTransforms": [
                    {
                        "RenameColumnOperation": {
                            "ColumnName": "ColumnId-1",
                            "NewColumnName": "Date"
                        }
                    },
#adding a calculated field, you can use a string for the column identifier
                    {
                        "CreateColumnsOperation": {
                            "Columns": [
                                {
                                    "ColumnName": "maxVisits2",
                                    "ColumnId": "<columID string identifier string>",
                                    "Expression": "max({Website Visits})"
                                }
                            ]
                        }
                    }
                    ,
                    {
                        "CastColumnTypeOperation": {
                            "ColumnName": "Date",
                            "NewColumnType": "DATETIME",
                            "Format": "M/d/yyyy"
                        }
                    },
                    {
                        "RenameColumnOperation": {
                            "ColumnName": "ColumnId-2",
                            "NewColumnName": "New visitors SEO"
                        }
                    },
                    {
                        "CastColumnTypeOperation": {
                            "ColumnName": "New visitors SEO",
                            "NewColumnType": "INTEGER"
                        }
                    },
                    {
                        "RenameColumnOperation": {
                            "ColumnName": "ColumnId-3",
                            "NewColumnName": "New visitors CPC"
                        }
                    },
                    {
                        "CastColumnTypeOperation": {
                            "ColumnName": "New visitors CPC",
                            "NewColumnType": "INTEGER"
                        }
                    },
                    {
                        "RenameColumnOperation": {
                            "ColumnName": "ColumnId-4",
                            "NewColumnName": "New visitors Social Media"
                        }
                    },
                    {
                        "CastColumnTypeOperation": {
                            "ColumnName": "New visitors Social Media",
                            "NewColumnType": "INTEGER"
                        }
                    },
                    {
                        "RenameColumnOperation": {
                            "ColumnName": "ColumnId-5",
                            "NewColumnName": "Return visitors"
                        }
                    },
{
                        "ProjectOperation": {
                            "ProjectedColumns": [
                                "Date",
                                "New visitors SEO",
                                "New visitors CPC",
                                "New visitors Social Media",
                                "Return visitors",
                                "Twitter mentions",
                                "Twitter followers adds",
                                "Twitter followers cumulative",
                                "Mailing list adds ",
                                "Mailing list cumulative",
                                "Website Pageviews",
                                "Website Visits",
                                "Website Unique Visits",
                                "Mobile uniques",
                                "Tablet uniques",
                                "Desktop uniques",
                                "Free sign up",
                                "Paid conversion",
                                "Events",
                                "maxVisits",
                                "minVisits",
                                "minmaxdiff",
                                "percntileAgg",
                                "maxVisits2"
                            ]
                        }
                    }
                ],
                "Source": {
                    "PhysicalTableId": "<ID>"
                }
            }
        },
        ImportMode =  "SPICE"
)    
print(response)

I have used boto3 in this example but you can use any API from the supported list.

지원 엔지니어
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠