1 / 30

Data Formats

Data Formats. CMSC 491/691 Hadoop-Based Distributed Computing Spring 2014 Adam Shook. Agenda. Apache Avro Parquet. Apache Avro. Overview. Avro is a data serialization system Implemented in C, C++, C#, Java, PHP, Python, and Ruby. Avro Provides. Rich data structures

helena
Download Presentation

Data Formats

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data Formats CMSC 491/691 Hadoop-Based Distributed Computing Spring 2014 Adam Shook

  2. Agenda • Apache Avro • Parquet

  3. Apache Avro

  4. Overview • Avro is a data serialization system • Implemented in C, C++, C#, Java, PHP, Python, and Ruby

  5. Avro Provides • Rich data structures • Compact, fast, binary data format • A container file to store persistent data • Remote Procedure Call (RPC) • Simple integration with dynamic languages

  6. Schema Declaration • A JSON string • A JSON object • {"type": "typeName"...attributes...} • A JSON array, representing a union of types

  7. Primitive Types • Null • Boolean • Int • Long • Float • Double • Bytes • String

  8. Complex Types • Records • Enums • Arrays • Maps • Unions • Fixed

  9. Record Example - LinkedList { "type": "record", "name": "LongList", "aliases": ["LinkedLongs"], // old name for this "fields" : [ {"name": "value", "type": "long"}, // each element has a long {"name": "next", "type": ["LongList", "null"]} // optional next element ] }

  10. Enum Example – Playing Cards { "type": "enum", "name": "Suit", "symbols" : ["SPADES", "HEARTS", "DIAMONDS", "CLUBS"] }

  11. Array { "type": "array", "items": "string" }

  12. Maps { "type": "map", "values": "long" }

  13. Unions • Represented using JSON arrays • ["string", "null"] declares a schema which may be a string or null • May not contain more than one schema with the same type, except in the case of named types like record, fixed, and enum. • Two arrays or maps? No. But two record types? Yes! • Cannot contain other unions

  14. Fixed { "type": "fixed", "size": 16, "name": "md5" }

  15. A bit on Naming • Records, enums, and fixed types are all named • The full name is composed of the name and a namespace • Names start with [A-Za-z_] and can only contain [A-Za-z0-9_] • Namespaces are dot-separated sequence of names • Named types can be aliased to map a writer’s schema to a reader

  16. Encodings! • Binary • JSON • One is more readable by the machines, one is more readable by the humans • Details of how they are encoded can be found at http://avro.apache.org/docs/current/spec.html

  17. Compression • Null • Deflate • Snappy (optional)

  18. Other Features • RPC via Protocols • Message passing between readers and writers • Schema Resolution • When schema and data don’t align • Parsing Canonical Form • Transform schemas into PCF to determine “sameness” between schemas • Schema Fingerprints • To “uniquely” identify schemas

  19. Code Generation! [shadam1@491vm ~]$ cat user.avsc { "namespace": "example.avro", "type": "record", "name": "User", "fields": [ {"name": "name", "type": "string"}, {"name": "favorite_number", "type": ["int", "null"]}, {"name": "favorite_color", "type": ["string", "null"]} ] }

  20. Code Generation! [shadam1@491vm ~]$ java -jar avro-tools-1.7.6.jar compile \ schema user.avsc. Input files to compile: user.avsc [shadam1@491vm ~]$ vi example/avro/User.java

  21. Java and Python Demo! • See my VM

  22. Parquet

  23. Overview • Parquet is an open-source columnar storage format for Hadoop • Based off the Google Dremel paper and created largely by Twitter and Cloudera • Supports very efficient compression and encoding schemes

  24. Serialization • Objects are serialized to Parquet format by ReadSupport and WriteSupport implementations • Support for Avro, Thrift, Pig, Hive SerDe, MapReduce • Can write your own, but it’s easier to leverage what exists today

  25. File Hierarchy • Row Group – logical horizontal partitioning of data into rows • Column Chunk – Chunk of the data for a particular column, living in a row group and contiguous in the file • Page – Chunks are divided up into pages • One or more Row Groups per file, exactly one Column Chunk per column

  26. File Format 4-byte magic number "PAR1 <Column 1 Chunk 1 + Column Metadata> <Column 2 Chunk 1 + Column Metadata> ... <Column N Chunk 1 + Column Metadata> <Column 1 Chunk 2 + Column Metadata> <Column 2 Chunk 2 + Column Metadata> ... <Column N Chunk 2 + Column Metadata> ... <Column 1 Chunk M + Column Metadata> <Column 2 Chunk M + Column Metadata> ... <Column N Chunk M + Column Metadata> File Metadata 4-byte length in bytes of file metadata 4-byte magic number "PAR1"

  27. File Format 4-byte magic number "PAR1" <Column 1 Chunk 1 + Column Metadata> <Column 2 Chunk 1 + Column Metadata> ... <Column N Chunk 1 + Column Metadata> <Column 1 Chunk 2 + Column Metadata> <Column 2 Chunk 2 + Column Metadata> ... <Column N Chunk 2 + Column Metadata> ... <Column 1 Chunk M + Column Metadata> <Column 2 Chunk M + Column Metadata> ... <Column N Chunk M + Column Metadata> File Metadata 4-byte length in bytes of file metadata 4-byte magic number "PAR1"

  28. Data Types • Boolean • Int 32, 64, 96 • Float • Double • Byte Array

  29. Parquet Example - Avro • See my VM

  30. References • http://avro.apache.org • http://parquet.io

More Related