복붙노트

[HADOOP] hadoop에서 json을 읽는 사용자 입력 형식

HADOOP

hadoop에서 json을 읽는 사용자 입력 형식

나는 hadoop의 초보자이다. 나는 json 데이터를 읽는 커스텀 inputformat 클래스를 생성하라는 말을 들었다. 나는 googled를했고 file.but에서 데이터를 읽는 커스텀 inputformat 클래스를 생성하는 법을 배웠다. 나는 json을 파싱하는데 박혀있다. 데이터. 내 json 데이터는 다음과 같이 보입니다.

[
    {
        "_count": 30,
        "_start": 0,
        "_total": 180,
        "values": [
            {
                "attachment": {
                    "contentDomain": "techcarnival2013.eventbrite.com",
                    "contentUrl": "http://techcarnival2013.eventbrite.com/",
                    "imageUrl": "http://ebmedia.eventbrite.com/s3-s3/static/images/django/logos/eb_home_tm-trans-fb.png",
                    "summary": "Get to know a few thousand of Silicon Valley's best and brightest while enjoying unparalleled access to Candlestick Park,\u00a0games, food, music and more. We'll have carnival games you haven't played since you were ten, giant inflatable obstacle...",
                    "title": "Tech Carnival @ Candlestick Park"
                },
                "comments": {
                    "_total": 0
                },
                "creationTimestamp": 1373908436000,
                "creator": {
                    "firstName": "Clayton",
                    "headline": "Director of Operations",
             "secondname":{
                "name":"myname"
                },
                    "lastName": "K.",
                    "pictureUrl": "http://m.c.lnkd.licdn.com/mpr/mprx/0_R7Vm6_RqBDHaHCDzJHRA6hsNcwOfECjzMeaA6heqHeo0v6ovBWoCe8pVJiYrd5pJVu4KdbnQQ3Lj"
                },
                "likes": {
                    "_total": 0
                },
                "relationToViewer": {
                    "availableActions": {
                        "_total": 7,
                        "values": [
                            {
                                "code": "add-comment"
                            },
                            {
                                "code": "categorize-as-job"
                            },
                            {
                                "code": "categorize-as-promotion"
                            },
                            {
                                "code": "flag-as-inappropriate"
                            },
                            {
                                "code": "follow"
                            },
                            {
                                "code": "like"
                            },
                            {
                                "code": "reply-privately"
                            }
                        ]
                    },
                    "isFollowing": false,
                    "isLiked": false
                },
                "summary": "Network with 4,000+ from the tech community, including folks from DFJ, Google, LinkedIn, Square, Uber, Y Combinator, 500 Startups, etc. $10 ticket gets you all-you-can-ride access to the pop-up Tech Carnival, will be the biggest Wednesday night of the tech summer.",
                "title": "Tech Event @ Candlestick Park on Wednesday, July 17th! Come play carnival games with ~4,000 of the Bay area's best and brightest!"
            },
            {
                "attachment": {
                    "contentDomain": "lifebeyondnumbers.com",
                    "contentUrl": "http://bit.ly/10VTqMu",
                    "imageUrl": "http://lifebeyondnumbers.com/wp-content/uploads/2013/07/lurnq_Online_Courses.jpg",
                    "summary": "LurnQ offers a platform for learning and teaching that is free for everyone. It caters to a diverse online audience and is relevant to everyone in general. The key segment that we address now is of life long learners.",
                    "title": "LurnQ - making lifelong learning clutter free, fun and a social..."
                },
                "comments": {
                    "_total": 0
                },
                "creationTimestamp": 1373883177000,
                "creator": {
                    "firstName": "Syed",
                    "headline": "Founder and CEO at QubiqSquare",
                    "lastName": "Muksit",
                    "pictureUrl": "http://m.c.lnkd.licdn.com/mpr/mprx/0_Y5gdzlRCbQBTqIa-pXYnz-01b6KinDO-pFWnz-ZCZLk1WWdt-_SLUt2uWmrpzo0OxQxcVv6pRjbE"
                },
                "likes": {
                    "_total": 0
                },
                "relationToViewer": {
                    "availableActions": {
                        "_total": 7,
                        "values": [
                            {
                                "code": "add-comment"
                            },
                            {
                                "code": "categorize-as-job"
                            },
                            {
                                "code": "categorize-as-promotion"
                            },
                            {
                                "code": "flag-as-inappropriate"
                            },
                            {
                                "code": "follow"
                            },
                            {
                                "code": "like"
                            },
                            {
                                "code": "reply-privately"
                            }
                        ]
                    },
                    "isFollowing": false,
                    "isLiked": false
                },
                "summary": "LurnQ offers a platform for learning and teaching that is free for everyone. It caters to a diverse online audience and is relevant to everyone in general. The key segment that we address now is of life long learners.",
                "title": "There is so much to learn and most of the times, we don\u2019t even know that this-and-that good stuff exists.  http://bit.ly/10VTqMu"
            },
            {
                "attachment": {
                    "contentDomain": "techcarnival2013.eventbrite.com",
                    "contentUrl": "http://techcarnival2013.eventbrite.com/",
                    "imageUrl": "http://ebmedia.eventbrite.com/s3-s3/static/images/django/logos/eb_home_tm-trans-fb.png",
                    "summary": "Get to know a few thousand of Silicon Valley's best and brightest while enjoying unparalleled access to Candlestick Park,\u00a0games, food, music and more. We'll have carnival games you haven't played since you were ten, giant inflatable obstacle...",
                    "title": "Tech Carnival @ Candlestick Park"
                },
                "comments": {
                    "_total": 0
                },
                "creationTimestamp": 1373654758000,
                "creator": {
                    "firstName": "Clayton",
                    "headline": "Director of Operations",
                    "lastName": "K.",
                    "pictureUrl": "http://m.c.lnkd.licdn.com/mpr/mprx/0_R7Vm6_RqBDHaHCDzJHRA6hsNcwOfECjzMeaA6heqHeo0v6ovBWoCe8pVJiYrd5pJVu4KdbnQQ3Lj"
                },
                "likes": {
                    "_total": 0
                },
                "relationToViewer": {
                    "availableActions": {
                        "_total": 7,
                        "values": [
                            {
                                "code": "add-comment"
                            },
                            {
                                "code": "categorize-as-job"
                            },
                            {
                                "code": "categorize-as-promotion"
                            },
                            {
                                "code": "flag-as-inappropriate"
                            },
                            {
                                "code": "follow"
                            },
                            {
                                "code": "like"
                            },
                            {
                                "code": "reply-privately"
                            }
                        ]
                    },
                    "isFollowing": false,
                    "isLiked": false
                },
                "summary": "Network with 4,000+ from the tech community, including folks from DFJ, Google, LinkedIn, Square, Uber, Y Combinator, 500 Startups, etc. $10 ticket gets you all-you-can-ride access to the pop-up Tech Carnival, will be the biggest Wednesday night of the tech summer.",
                "title": "Tech Event @ Candlestick Park on Wednesday, July 17th! Come play carnival games with ~4,000 of the Bay area's best and brightest!"
            }
..........
........ so on

]

그래서 혼란에 어떻게 내 사용자 지정 inputformat 클래스에서 json 개체를 읽을 수 있습니다.이 구문 분석하는 방법에 대한 모든 아이디어? json 배열 내의 개별 json 개체를 읽고 싶습니다. 적절한 json 문자열을 읽은 다음 문자열을 지도 어디에 내 자신의 키 값 pair.any 도움이지도 내부에 json 파서를 사용하는 것이 사전에 감사드립니다

해결법

  1. ==============================

    1.귀하의 질문에 Magham Ravi가 언급 한 내용과 일치하는 경우, 답변은 정상입니다.

    귀하의 질문에 Magham Ravi가 언급 한 내용과 일치하는 경우, 답변은 정상입니다.

    그러나 위에서 언급 한 것처럼 모든 JSON 데이터가있는 단일 파일이있는 경우 전체 파일을 읽고지도의 값 부분 (BytesWritable 값)에서 String으로 검색하여 JSON 파서로 가져올 수 있습니다 동일한 map () 함수 내에서 사용할 수 있습니다.

    WholeFileInputFormat을 살펴보십시오.

    또한 단일 파일에 여러 개의 JSON 오브젝트 데이터가 있고 각 JSON 오브젝트 데이터를 매퍼의 값으로 가져 오는 경우 시작 태그와 종료 태그가 정의 된 XMLInputFormat과 같은 것을 사용할 수 있습니다. JSON의 경우에는 원하는 단일 JSON 데이터 객체의 시작과 끝을 정확히 나타내는 고유 한 시작 및 끝 태그가 있어야합니다. 단순히 이미 혼란 스러울 수있는 중첩 된 객체가 많이 있기 때문에 start-tag = "[{"및 end-tag = "}]"를 사용하면 위와 같은 전체 JSON 객체를 값으로 반환하기를 원할 경우 도움이되지 않을 수 있습니다 InputFormat

    위의 경우를 달성 할 수없는 경우 TextInputFormat에 정의 된 LineReader를 무시하고 사용자 정의 TextInputFormat을 작성하십시오.

    LineReader 클래스에서는이 두 세트를 잘 처리 할 것입니다. (구성 속성을 사용하여 구성 가능한지 조금만 확인하십시오. CDH가이를 재정의했는지 확인하십시오.

    private static final byte CR = '\r';
    private static final byte LF = '\n';
    

    그리고 CR을 놓고 LF가 "] \ n ["을 가리 키도록 변경할 수 있습니다. 개별 JSON 데이터가 표시된대로 양식에 존재할 것이거나 더 잘 알 수 있습니까?

    [

    ... JSON 1

    ]

    [

    ... JSON 2

    ]

    [

    ... JSON N

    ]

    (참고 : 중간에 \ n이 있고 [다른 JSON 객체의 데이터 사이의 경계로 표시됩니다]).

    희망이 의미가 있습니다.

  2. from https://stackoverflow.com/questions/18593595/custom-inputformat-for-reading-json-in-hadoop by cc-by-sa and MIT license