Package org.apache.hadoop.hive.serde2.io

Examples of org.apache.hadoop.hive.serde2.io.DoubleWritable


*/
public class LazyBinaryDouble extends LazyBinaryPrimitive<WritableDoubleObjectInspector, DoubleWritable> {

  LazyBinaryDouble(WritableDoubleObjectInspector oi) {
    super(oi);
    data = new DoubleWritable();
  }
View Full Code Here


    data = new DoubleWritable();
  }
 
  LazyBinaryDouble(LazyBinaryDouble copy) {
    super(copy);
    data = new DoubleWritable(copy.data.get());
  }
View Full Code Here

*/
public class LazyDouble extends LazyPrimitive<LazyDoubleObjectInspector, DoubleWritable> {

  public LazyDouble(LazyDoubleObjectInspector oi) {
    super(oi);
    data = new DoubleWritable();
  }
View Full Code Here

    data = new DoubleWritable();
  }

  public LazyDouble(LazyDouble copy) {
    super(copy);
    data = new DoubleWritable(copy.data.get());
 
View Full Code Here

      // Data
      Text t = new Text("123\t456\t789\t1000\t5.3\thive and hadoop\t1.\tNULL");
      String s = "123\t456\t789\t1000\t5.3\thive and hadoop\tNULL\tNULL";
      Object[] expectedFieldsData = { new ByteWritable((byte)123),
          new ShortWritable((short)456), new IntWritable(789),
          new LongWritable(1000), new DoubleWritable(5.3), new Text("hive and hadoop"), null,
          null
      };
     
      // Test
      deserializeAndSerialize(serDe, t, s, expectedFieldsData);
View Full Code Here

      // Data
      Text t = new Text("123\t456\t789\t1000\t5.3\thive and hadoop\t1.\ta\tb\t");
      String s = "123\t456\t789\t1000\t5.3\thive and hadoop\tNULL\ta\tb\t";
      Object[] expectedFieldsData = { new ByteWritable((byte)123),
          new ShortWritable((short)456), new IntWritable(789),
          new LongWritable(1000), new DoubleWritable(5.3), new Text("hive and hadoop"), null,
          new Text("a\tb\t")
      };
     
      // Test
      deserializeAndSerialize(serDe, t, s, expectedFieldsData);
View Full Code Here

            }
            r.set(Float.intBitsToFloat(v));
            return r;
          }
          case DOUBLE: {
            DoubleWritable r = reuse == null ? new DoubleWritable() : (DoubleWritable)reuse;
            long v = 0;
            for (int i=0; i<8; i++) {
              v = (v << 8) + (buffer.read(invert) & 0xff);
            }
            if ((v & (1L<<63)) == 0) {
              // negative number, flip all bits
              v = ~v;
            } else {
              // positive number, flip the first bit
              v = v ^ (1L<<63);
            }
            r.set(Double.longBitsToDouble(v));
            return r;
          }
          case STRING: {
            Text r = reuse == null ? new Text() : (Text)reuse;
            // Get the actual length first
            int start = buffer.tell();
            int length = 0;
            do {
              byte b = buffer.read(invert);
              if (b == 0) {
                // end of string
                break;
              }
              if (b == 1) {
                // the last char is an escape char. read the actual char
                buffer.read(invert);
              }
              length ++;
            } while (true);
           
            if (length == buffer.tell() - start) {
              // No escaping happened, so we are already done.
              r.set(buffer.getData(), start, length);
            } else {
              // Escaping happened, we need to copy byte-by-byte.
              // 1. Set the length first.
              r.set(buffer.getData(), start, length);
              // 2. Reset the pointer.
              buffer.seek(start);
              // 3. Copy the data.
              byte[] rdata = r.getBytes();
              for (int i=0; i<length; i++) {
                byte b = buffer.read(invert);
                if (b == 1) {
                  // The last char is an escape char, read the actual char.
                  // The serialization format escape \0 to \1, and \1 to \2,
                  // to make sure the string is null-terminated.
                  b = (byte)(buffer.read(invert) - 1);
                }
                rdata[i] = b;
              }
              // 4. Read the null terminator.
              byte b = buffer.read(invert);
              assert(b == 0);
            }
            return r;
          }
          default: {
            throw new RuntimeException("Unrecognized type: " + ptype.getPrimitiveCategory());
          }
        }
      }
      case LIST: {
        ListTypeInfo ltype = (ListTypeInfo)type;
        TypeInfo etype = ltype.getListElementTypeInfo();
       
        // Create the list if needed
        ArrayList<Object> r = reuse == null ? new ArrayList<Object>() : (ArrayList<Object>)reuse;

        // Read the list
        int size = 0;
        while (true) {
          int more = buffer.read(invert);
          if (more == 0) {
            // \0 to terminate
            break;
          }
          // \1 followed by each element
          assert(more == 1);
          if (size == r.size()) {
            r.add(null);
          }
          r.set(size, deserialize(buffer, etype, invert, r.get(size)));
          size++;
        }
        // Remove additional elements if the list is reused
        while (r.size() > size) {
          r.remove(r.size()-1);
        }
        return r;
      }     
      case MAP: {
        MapTypeInfo mtype = (MapTypeInfo)type;
        TypeInfo ktype = mtype.getMapKeyTypeInfo();
        TypeInfo vtype = mtype.getMapValueTypeInfo();
       
        // Create the map if needed
        Map<Object, Object> r;
        if (reuse == null) {
          r = new HashMap<Object, Object>();
        } else {
          r = (HashMap<Object, Object>)reuse;
          r.clear();
        }

        // Read the map
        int size = 0;
        while (true) {
          int more = buffer.read(invert);
          if (more == 0) {
            // \0 to terminate
            break;
          }
          // \1 followed by each key and then each value
          assert(more == 1);
          Object k = deserialize(buffer, ktype, invert, null);
          Object v = deserialize(buffer, vtype, invert, null);
          r.put(k, v);
        }
        return r;
      }
      case STRUCT: {
        StructTypeInfo stype = (StructTypeInfo)type;
        List<TypeInfo> fieldTypes = stype.getAllStructFieldTypeInfos();
        int size = fieldTypes.size();
        // Create the struct if needed
        ArrayList<Object> r = reuse == null ? new ArrayList<Object>(size) : (ArrayList<Object>)reuse;
        assert(r.size() <= size);
        // Set the size of the struct
        while (r.size() < size) {
          r.add(null);
        }
        // Read one field by one field
        for (int eid = 0; eid < size; eid++) {
          r.set(eid, deserialize(buffer, fieldTypes.get(eid), invert, r.get(eid)));
        }
        return r;
      }
      default: {
        throw new RuntimeException("Unrecognized type: " + type.getCategory());
View Full Code Here

    writer.append(bytes);
    writer.close();

    Object[] expectedRecord_1 = { new ByteWritable((byte) 123),
        new ShortWritable((short) 456), new IntWritable(789),
        new LongWritable(1000), new DoubleWritable(5.3),
        new Text("hive and hadoop"), null, null };

    Object[] expectedRecord_2 = { new ByteWritable((byte) 100),
        new ShortWritable((short) 200), new IntWritable(123),
        new LongWritable(1000), new DoubleWritable(5.3),
        new Text("hive and hadoop"), null, null };

    RCFile.Reader reader = new RCFile.Reader(fs, file, conf);

    LongWritable rowID = new LongWritable();
View Full Code Here

      }
      return true;
    }

    public DoubleWritable terminatePartial() {
      return mEmpty ? null : new DoubleWritable(mMin);
    }
View Full Code Here

    public boolean merge(DoubleWritable o) {
      return iterate(o);
    }

    public DoubleWritable terminate() {
      return mEmpty ? null : new DoubleWritable(mMin);
    }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.serde2.io.DoubleWritable

Copyright © 2018 www.massapicom. 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.