/** Test the LazyString class. */
  public void testLazyString() throws Throwable {
    try {
      LazyString b =
          new LazyString(
              LazyPrimitiveObjectInspectorFactory.getLazyStringObjectInspector(false, (byte) 0));
      initLazyObject(b, new byte[] {'0'}, 0, 0);
      assertEquals(new Text(""), b.getWritableObject());
      initLazyObject(b, new byte[] {'0'}, 0, 1);
      assertEquals(new Text("0"), b.getWritableObject());
      initLazyObject(b, new byte[] {'0', '1', '2'}, 1, 1);
      assertEquals(new Text("1"), b.getWritableObject());

    } catch (Throwable e) {
      e.printStackTrace();
      throw e;
    }
  }
Beispiel #2
0
 public static Text asText(@Nullable final Object o) {
   if (o == null) {
     return null;
   }
   if (o instanceof Text) {
     return (Text) o;
   }
   if (o instanceof LazyString) {
     LazyString l = (LazyString) o;
     return l.getWritableObject();
   }
   if (o instanceof String) {
     String s = (String) o;
     return new Text(s);
   }
   String s = o.toString();
   return new Text(s);
 }