Examples of SerDe


Examples of org.apache.hadoop.hive.serde2.SerDe

   * Test the LazySimpleSerDe class.
   */
  public void testRegexSerDe() throws Throwable {
    try {
      // Create the SerDe
      SerDe serDe = createSerDe(
          "host,identity,user,time,request,status,size,referer,agent",
          "string,string,string,string,string,string,string,string,string",
          "([^ ]*) ([^ ]*) ([^ ]*) (-|\\[[^\\]]*\\]) ([^ \"]*|\"[^\"]*\") ([0-9]*) ([0-9]*) ([^ \"]*|\"[^\"]*\") ([^ \"]*|\"[^\"]*\")",
          "%1$s %2$s %3$s %4$s %5$s %6$s %7$s %8$s %9$s"
      );
     
      // Data
      Text t = new Text("127.0.0.1 - - [26/May/2009:00:00:00 +0000] "
          + "\"GET /someurl/?track=Blabla(Main) HTTP/1.1\" 200 5864 - "
          + "\"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.65 Safari/525.19\"");
     
      // Deserialize
      Object row = serDe.deserialize(t);
      ObjectInspector rowOI = serDe.getObjectInspector();

      System.out.println("Deserialized row: " + row);
     
      // Serialize
      Text serialized = (Text)serDe.serialize(row, rowOI);
      assertEquals(t, serialized);
     
      // Do some changes (optional)
      ObjectInspector standardWritableRowOI = ObjectInspectorUtils.getStandardObjectInspector(
          rowOI, ObjectInspectorCopyOption.WRITABLE);
      Object standardWritableRow = ObjectInspectorUtils.copyToStandardObject(row, rowOI,
          ObjectInspectorCopyOption.WRITABLE);
     
      // Serialize
      serialized = (Text)serDe.serialize(standardWritableRow, standardWritableRowOI);
      assertEquals(t, serialized);
       
    } catch (Throwable e) {
      e.printStackTrace();
      throw e;
View Full Code Here

Examples of org.apache.hadoop.hive.serde2.SerDe

   * Test the LazySimpleSerDe class.
   */
  public void testRegexSerDe() throws Throwable {
    try {
      // Create the SerDe
      SerDe serDe = createSerDe(
          "host,identity,user,time,request,status,size,referer,agent",
          "string,string,string,string,string,string,string,string,string",
          "([^ ]*) ([^ ]*) ([^ ]*) (-|\\[[^\\]]*\\]) ([^ \"]*|\"[^\"]*\") "
          + "([0-9]*) ([0-9]*) ([^ \"]*|\"[^\"]*\") ([^ \"]*|\"[^\"]*\")",
          "%1$s %2$s %3$s %4$s %5$s %6$s %7$s %8$s %9$s");

      // Data
      Text t = new Text(
          "127.0.0.1 - - [26/May/2009:00:00:00 +0000] "
              + "\"GET /someurl/?track=Blabla(Main) HTTP/1.1\" 200 5864 - "
              + "\"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) "
              + "AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.65 Safari/525.19\"");

      // Deserialize
      Object row = serDe.deserialize(t);
      ObjectInspector rowOI = serDe.getObjectInspector();

      System.out.println("Deserialized row: " + row);

      // Serialize
      Text serialized = (Text) serDe.serialize(row, rowOI);
      assertEquals(t, serialized);

      // Do some changes (optional)
      ObjectInspector standardWritableRowOI = ObjectInspectorUtils
          .getStandardObjectInspector(rowOI, ObjectInspectorCopyOption.WRITABLE);
      Object standardWritableRow = ObjectInspectorUtils.copyToStandardObject(
          row, rowOI, ObjectInspectorCopyOption.WRITABLE);

      // Serialize
      serialized = (Text) serDe.serialize(standardWritableRow,
          standardWritableRowOI);
      assertEquals(t, serialized);

    } catch (Throwable e) {
      e.printStackTrace();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.