Code Monkey home page Code Monkey logo

teraslice_hdfs_reader's Introduction

Reader - teraslice_hdfs_reader

To install from the root of your teraslice instance.

npm install terascope/teraslice_hdfs_reader

Description

Teraslice reader to process JSON data stored in text files in HDFS.

Output

An array of JSON format records

Parameters

Name Description Default Required
user User to use when reading the files hdfs N
path HDFS location to process. Most of the time this will be a directory that contains multiple files Y
size How big of a slice in bytes to take out of each file 100000 N
format Format of the records that are stored in the file. Currently json_lines is the only option. json_lines N
connection Name of the terafoundation HDFS connection to use default N

Job configuration example

Read a directory in HDFS and send the results to an elasticsearch index.

{
    "name": "Process",
    "lifecycle": "once",
    "workers": 2,
    "operations": [
        {
          "_op": "teraslice_hdfs_reader",
          "path": "/testpath/test-2017.04.24",
          "size": 5000000
        },
        {
            "_op": "elasticsearch_index_selector",
            "type": "change",
            "index": "example-logs-from-hdfs"
        },
        {
          "_op": "elasticsearch_bulk",
          "size": 10000
        }
    ]
}

teraslice_hdfs_reader's People

Contributors

jsnoble avatar kstaken avatar

Watchers

Austin Godber avatar  avatar James Cloos avatar  avatar

Forkers

jsnoble

teraslice_hdfs_reader's Issues

Needs to support connection

Supporting the 'connection' parameter should be a standard feature of all modules that read or store data.

Better handling of parsing errors

If the source data isn't formatted correctly you receive an error similar to the following. The error is caught but it's not very clear what's causing it. I'm sure we can handle this more gracefully.

   failed to process { worker_id: '10.0.1.8__8',
      slice:
       { slice_id: '7acc3f0f-5872-4e69-af11-6e022ce0cfe1',
         request:
          { path: '/test/kstaken-2017.04/kteramac.local.4',
            offset: 12000000,
            length: 500000,
            total: 13843536 },
         slicer_id: 0,
         slicer_order: 25 },
      error: 'SyntaxError: Unexpected token {\n    at Object.parse (native)\n    at /Users/kstaken/projects/opensource/teraslice_hdfs_reader/index.js:245:36\n    at Array.map (native)\n    at json_lines (/Users/kstaken/projects/opensource/teraslice_hdfs_reader/index.js:245:17)\n    at /Users/kstaken/projects/opensource/teraslice_hdfs_reader/index.js:111:24\n    at tryCatcher (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/util.js:16:23)\n    at Promise._settlePromiseFromHandler (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:510:31)\n    at Promise._settlePromise (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:567:18)\n    at Promise._settlePromise0 (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:612:10)\n    at Promise._settlePromises (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:691:18)\n    at Promise._fulfill (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:636:18)\n    at Promise._settlePromise (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:580:21)\n    at Promise._settlePromise0 (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:612:10)\n    at Promise._settlePromises (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:691:18)\n    at Promise._fulfill (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:636:18)\n    at Promise._settlePromise (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:580:21)\n    at Promise._settlePromise0 (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:612:10)\n    at Promise._settlePromises (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:691:18)\n    at Promise._fulfill (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:636:18)\n    at Promise._resolveCallback (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:431:57)\n    at Promise._settlePromiseFromHandler (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:522:17)\n    at Promise._settlePromise (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:567:18)\n    at Promise._settlePromise0 (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:612:10)\n    at Promise._settlePromises (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:691:18)\n    at Promise._fulfill (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:636:18)\n    at Promise._resolveCallback (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:431:57)\n    at Promise._settlePromiseFromHandler (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:522:17)\n    at Promise._settlePromise (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:567:18)' } and has slice state is marked as error

Automate and be consistent

  • Add Travis-CI Automation
  • Report Code Coverage to CodeCov, or a similar service.
  • Support eslint and use the configuration from teraslice
  • NPM Publish using the name teraslice-hdfs-reader

Reader algorithm

Configuration

  • path - HDFS location to process. Most of the time this will be a directory that contains multiple files. Ideally should also support direct reference to a single file.
  • size - How big of a slice to take out of each file. Default 10GB.
  • format - For now just supporting json_lines but other formats may make sense later.

Slicer

  • Slicer should create slices starting with the list of files. If the file exceeds the size boundary then the file should be split based on size.
  • Reader will need to be handed the full path to a file, starting offset and ending offset.

Reader

  • Reader will need to read a complete set of records for the slice.
  • If starting offset is 0 then the first line is kept.
    • This will only occur on the first slice for each file.
  • If starting offset is NOT 0 then the first line is dropped in all cases.
  • If the last line is incomplete then enough additional data needs to be read to complete it.
    • If should be possible to estimate a record size based on the records already seen in the slice.
    • It is better to err on the side of reading too much data than too little.
    • Any extra data that is read beyond what's required to complete the record is just thrown away.
  • If the last line is COMPLETE then enough additional data should be read to add one additional complete record to the set.
    • This is done because the next slice on the file is going to automatically drop the first record even though it will actually be complete.
    • Again any extra data beyond a single record should just be thrown away.

Edge case failure

Appears something isn't quite joining correctly. I believe this may be happening at the end of the file but still digging.

   failed to process { worker_id: '10.0.1.8__8',
      slice:
       { slice_id: '7acc3f0f-5872-4e69-af11-6e022ce0cfe1',
         request:
          { path: '/test/kstaken-2017.04/kteramac.local.4',
            offset: 12000000,
            length: 500000,
            total: 13843536 },
         slicer_id: 0,
         slicer_order: 25 },
      error: 'SyntaxError: Unexpected token {\n    at Object.parse (native)\n    at /Users/kstaken/projects/opensource/teraslice_hdfs_reader/index.js:245:36\n    at Array.map (native)\n    at json_lines (/Users/kstaken/projects/opensource/teraslice_hdfs_reader/index.js:245:17)\n    at /Users/kstaken/projects/opensource/teraslice_hdfs_reader/index.js:111:24\n    at tryCatcher (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/util.js:16:23)\n    at Promise._settlePromiseFromHandler (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:510:31)\n    at Promise._settlePromise (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:567:18)\n    at Promise._settlePromise0 (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:612:10)\n    at Promise._settlePromises (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:691:18)\n    at Promise._fulfill (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:636:18)\n    at Promise._settlePromise (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:580:21)\n    at Promise._settlePromise0 (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:612:10)\n    at Promise._settlePromises (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:691:18)\n    at Promise._fulfill (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:636:18)\n    at Promise._settlePromise (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:580:21)\n    at Promise._settlePromise0 (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:612:10)\n    at Promise._settlePromises (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:691:18)\n    at Promise._fulfill (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:636:18)\n    at Promise._resolveCallback (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:431:57)\n    at Promise._settlePromiseFromHandler (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:522:17)\n    at Promise._settlePromise (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:567:18)\n    at Promise._settlePromise0 (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:612:10)\n    at Promise._settlePromises (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:691:18)\n    at Promise._fulfill (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:636:18)\n    at Promise._resolveCallback (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:431:57)\n    at Promise._settlePromiseFromHandler (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:522:17)\n    at Promise._settlePromise (/Users/kstaken/projects/opensource/terafoundation/node_modules/bluebird/js/release/promise.js:567:18)' } and has slice state is marked as error

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.