Loading JSON data to AWS Redshift results in NULL values

前端 未结 3 1039
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-17 17:14

I am trying to perform a load/copy operation to import data from JSON files in an S3 bucket directly to Redshift. The COPY operation succeeds, and after the COPY, the table

3条回答
  •  半阙折子戏
    2020-12-17 17:38

    COPY maps the data elements in the JSON source data to the columns in the target table by matching object keys, or names, in the source name/value pairs to the names of columns in the target table. The matching is case-sensitive. Column names in Amazon Redshift tables are always lowercase, so when you use the ‘auto’ option, matching JSON field names must also be lowercase. If the JSON field name keys aren't all lowercase, you can use a JSONPaths file to explicitly map column names to JSON field name keys.

    The solution would be to use jsonpath

    Example json:

    {
    "Name": "Major",
    "Age": 19,
    "Add": {
    "street":{
    "st":"5 maint st",
    "ci":"Dub"
    },
    "city":"Dublin"
    },
    
    "Category_Name": ["MLB","GBM"]
    
    }
    

    Example table:

    (
    name varchar,
    age int,
    address varchar,
    catname varchar
    );
    

    Example jsonpath:

    {
    "jsonpaths": [
    "$['Name']",
    "$['Age']",
    "$['Add']",
    "$['Category_Name']"
    ]
    }
    

    Example copy code:

    copy customer --redshift code
    from 's3://mybucket/customer.json'
    iam_role 'arn:aws:iam::0123456789012:role/MyRedshiftRole'
    json from 's3://mybucket/jpath.json' ; -- Jsonpath file to map fields
    

    Examples are taken from here

提交回复
热议问题