Amazon Neputune에서 loader 명령으로 데이터 가져오기

16556 단어 AWSNeptune
개시하다
저번 보도에서 Amazon Neptune을 구축하고 SPARQL을 통해 검색했습니다.이번 기사에서는 인터넷에 공개된 RDF 데이터를 네프타운 클러스터로 가져오는 절차를 확인해 보겠습니다.
Amazon Neptune에는 S3 Bucket에 저장된 데이터를 Neptune으로 가져올 수 있는 Loader 명령이 준비되어 있습니다.개요도는 이런 느낌입니다.

URL : https://docs.aws.amazon.com/ja_jp/neptune/latest/userguide/bulk-load.html
대응하는 문서는 다음과 같은 네 가지 형식이 있다.
  • N -Triples ( ntriples ) from the specification at https://www.w3.org/TR/n-triples/
  • N-Quads ( nquads ) from the specification at https://www.w3.org/TR/n-quads/
  • RDF/XML ( rdfxml ) from the specification at https://www.w3.org/TR/rdf-syntax-grammar/
  • Turtle ( turtle ) from the specification at https://www.w3.org/TR/turtle/
  • 또한 인코딩에는 UTF8이 필요합니다.자세한 내용은 다음 Doctument에 기록됩니다.
    URL : https://docs.aws.amazon.com/ja_jp/neptune/latest/userguide/bulk-load-tutorial-format-rdf.html
    그럼 데이터 가져오기를 시작합시다.
    RDF 파일을 다운로드하여 S3에 저장
    다음 URL에 공개된 RDF 데이터 세트를 다운로드합니다.
    curl -O http://rdf.geospecies.org/geospecies.rdf.gz
    
    S3 버킷을 적절히 제작해 다운로드한 파일을 저장했다.

    IAM Role의 프로듀싱.
    Neptune은 S3 액세스를 위해 IAM Role을 제작했습니다.Create Role 키를 누릅니다.

    정책에 다음 문자열을 추가하려면 Custom Trust Policy 를 선택합니다.
    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Sid": "",
          "Effect": "Allow",
          "Principal": {
            "Service": [
              "rds.amazonaws.com"
            ]
          },
          "Action": "sts:AssumeRole"
        }
      ]
    }
    
    AmazonS3ReadOnlyAccess를 선택한 후 Next 키를 누릅니다.

    Role 이름 등 입력

    Create 키를 누릅니다.

    생성됨

    Neptune에서 IAM Role 링크
    Neptune 클러스터를 선택하고 Manage IAM roles를 선택합니다.

    제작된 IAM Role을 선택하고 Done 키를 누릅니다.

    S3Endpoint(Gateway 유형) 작성
    Neptune에서 S3에 액세스하려면 S3Endpoint Gateway가 필요합니다.문장의 환경이 이미 설정되어 있기 때문에 상세한 절차를 생략한다.

    설정할 내용
  • VSC Endpoint의 S3 제작용
  • Route Table에 반영
  • Loader를 사용하여 Neptune에서 가져오기
    S3 Bucket에 업로드된 RDF 데이터 세트를 가져옵니다.Neptune 클러스터와 동일한 VPC의 EC2 인스턴스에서 다음 명령을 실행합니다.
    curl -X POST \
        -H 'Content-Type: application/json' \
        https://neptune-test.cluster-chuxmuzmrpgx.ap-northeast-1.neptune.amazonaws.com:8182/loader -d '
        {
          "source" : "s3://neptune-loader-test01/geospecies.rdf.gz", 
          "format" : "rdfxml",
          "iamRoleArn" : "arn:aws:iam::xxxxxxxxxxxx:role/Neptune-S3-Role",
          "region" : "ap-northeast-1",
          "failOnError" : "FALSE",
          "parallelism" : "HIGH"
        }'
    
    실행 예
  • Status:200이 응답으로 반환
  • {
        "status" : "200 OK",
        "payload" : {
            "loadId" : "2943d79e-dfba-4aa4-8ab7-4c2e21029234"
        }
    }
    
    진행 상황을 확인하다
    curl -G 'https://neptune-test.cluster-chuxmuzmrpgx.ap-northeast-1.neptune.amazonaws.com:8182/loader/2943d79e-dfba-4aa4-8ab7-4c2e21029234'
    
    실행 예: 불러오는 중입니다.status는 LOAD_IN_PROGRESS
    {
        "status" : "200 OK",
        "payload" : {
            "feedCount" : [
                {
                    "LOAD_IN_PROGRESS" : 1
                }
            ],
            "overallStatus" : {
                "fullUri" : "s3://neptune-loader-test01/geospecies.rdf.gz",
                "runNumber" : 1,
                "retryNumber" : 0,
                "status" : "LOAD_IN_PROGRESS",
                "totalTimeSpent" : 130,
                "startTime" : 1646489330,
                "totalRecords" : 1350000,
                "totalDuplicates" : 0,
                "parsingErrors" : 0,
                "datatypeMismatchErrors" : 0,
                "insertErrors" : 0
            }
        }
    }
    
    로드 완료 상태입니다.status는 LOAD_COMPLETED
    {
        "status" : "200 OK",
        "payload" : {
            "feedCount" : [
                {
                    "LOAD_COMPLETED" : 1
                }
            ],
            "overallStatus" : {
                "fullUri" : "s3://neptune-loader-test01/geospecies.rdf.gz",
                "runNumber" : 1,
                "retryNumber" : 0,
                "status" : "LOAD_COMPLETED",
                "totalTimeSpent" : 199,
                "startTime" : 1646489330,
                "totalRecords" : 2201532,
                "totalDuplicates" : 0,
                "parsingErrors" : 0,
                "datatypeMismatchErrors" : 0,
                "insertErrors" : 0
            }
        }
    }
    
    Neptune Workbench에서 질의 확인
    마지막 단계에 따라 작성된 Jupter Notebook의 Neptune Workbench에서 SPARQL 질의를 통해 가져온 데이터를 확인합니다.
    다음 명령을 실행하여 모든 데이터에서 10개를 가져옵니다.
    %%sparql
    
    SELECT ?s ?p ?o WHERE {?s ?p ?o} LIMIT 10
    

    다음 질의를 수행합니다.송이경(신지현): 이 조회의 뜻이 무엇인지 알아내지 못했습니다.
    %%sparql
    
    PREFIX geospecies: <http://rdf.geospecies.org/ont/geospecies#>
    SELECT DISTINCT ?kingdom ?commonName WHERE{
    
      ?node geospecies:hasKingdomName ?kingdom;
      a geospecies:KingdomConcept;
      geospecies:hasCommonName ?commonName .
    
    }
    

    다음 쿼리 실행
    %%sparql
    
    PREFIX geospecies: <http://rdf.geospecies.org/ont/geospecies#>
    SELECT DISTINCT ?commonName WHERE{
    
      ?node geospecies:hasFamilyName ?familyName;
      geospecies:hasCommonName ?commonName;
      FILTER regex(?familyName, "Strigidae") .    
    } LIMIT 10
    

    참조 링크

    좋은 웹페이지 즐겨찾기