Giter VIP home page Giter VIP logo

avro-json's Introduction

To Build:

mvn clean package

Hive Usage:

add jar avro-json-1.0-SNAPSHOT.jar;
CREATE TABLE doctors (foo string)
ROW FORMAT SERDE 'com.cloudera.science.avro.serde.AvroAsJSONSerde'
INPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat'
WITH SERDEPROPERTIES
('avro.schema.literal'='{
  "namespace": "testing.hive.avro.serde",
  "name": "doctors",
  "type": "record",
  "fields": [
    {
      "name":"number",
      "type":"int",
      "doc":"Order of playing the role"
    },
    {
      "name":"first_name",
      "type":"string",
      "doc":"first name of actor playing role"
    },
    {
      "name":"last_name",
      "type":"string",
      "doc":"last name of actor playing role"
    },
    {
      "name":"extra_field",
      "type":"string",
      "doc:":"an extra field not in the original file",
      "default":"fishfingers and custard"
    }
  ]
}');
DESCRIBE doctors;
SELECT * from doctors;
SELECT get_json_object(foo, '$.number') from doctors;

Streaming Usage:

hadoop jar hadoop-streaming-2.0.0-mr1-cdh4.1.2.jar \
-libjars avro-json-1.0-SNAPSHOT.jar \
-Dinput.schema.url=file:///doctors.avsc \
-Doutput.schema.url=file:///doctors.avsc \
-inputformat com.cloudera.science.avro.streaming.AvroAsJSONInputFormat \
-outputformat com.cloudera.science.avro.streaming.AvroAsJSONOutputFormat \
-mapper '/bin/cat' \
-input doctors.avro \
-output foo

Streaming Over Multiple Files with Different Schemas (Make sure that the ordering of the arguments to input.schema.url corresponds to the ordering of the -input args to streaming):

hadoop jar hadoop-streaming-2.0.0-mr1-cdh4.1.2.jar \
-libjars avro-json-1.0-SNAPSHOT.jar \
-Dinput.schema.url=file:///schemas/doctors.avsc,file:///schemas/episodes.avsc \
-inputformat com.cloudera.science.avro.streaming.AvroAsJSONInputFormat \
-mapper '/bin/cat' \
-input /data/doctors.avro \
-input /data/episodes.avro \
-output multijson

Streaming input from Parquet file (Parquet output not yet supported):

hadoop jar hadoop-streaming-2.0.0-mr1-cdh4.1.2.jar \
-libjars avro-json-1.0-SNAPSHOT.jar \
-Dinput.schema.url=file:///doctors.avsc \
-Doutput.schema.url=file:///doctors.avsc \
-Dparquet.read.support.class=parquet.avro.AvroReadSupport \
-inputformat com.cloudera.science.avro.streaming.ParquetAsJSONInputFormat \
-outputformat com.cloudera.science.avro.streaming.AvroAsJSONOutputFormat \
-mapper '/bin/cat' \
-input doctors.avro \
-output foo

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.