Java Code Examples for org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyStringObjectInspector

The following examples show how to use org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyStringObjectInspector. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: incubator-hivemall   Source File: HiveUtils.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
public static LazyString lazyString(@Nonnull final String str,
        @Nonnull final LazyStringObjectInspector oi) {
    LazyString lazy = new LazyString(oi);
    ByteArrayRef ref = new ByteArrayRef();
    byte[] data = str.getBytes(StandardCharsets.UTF_8);
    ref.setData(data);
    lazy.init(ref, 0, data.length);
    return lazy;
}
 
Example 2
@Test
public void testLazyStringFeature() throws Exception {
    LazyStringObjectInspector oi =
            LazyPrimitiveObjectInspectorFactory.getLazyStringObjectInspector(false, (byte) 0);
    List<LazyString> x = Arrays.asList(lazyString("テスト:-2", oi), lazyString("漢字:-333.0", oi),
        lazyString("test:-1"));
    testFeature(x, oi, LazyString.class, String.class);
}
 
Example 3
@Test
public void testLazyStringFeature() throws Exception {
    LazyStringObjectInspector oi =
            LazyPrimitiveObjectInspectorFactory.getLazyStringObjectInspector(false, (byte) 0);
    List<LazyString> x = Arrays.asList(lazyString("テスト:-2", oi), lazyString("漢字:-333.0", oi),
        lazyString("test:-1"));
    testFeature(x, oi, LazyString.class, String.class);
}
 
Example 4
Source Project: Hive-Cassandra   Source File: CassandraLazyFactory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a lazy primitive class given the type name. For Long and INT we use CassandraLazyLong and CassandraLazyInt
 * instead of the LazyObject from Hive.
 */
public static LazyObject createLazyPrimitiveClass(
    PrimitiveObjectInspector oi) {
  PrimitiveCategory p = oi.getPrimitiveCategory();

  switch (p) {
    case BOOLEAN:
      return new CassandraLazyBoolean((LazyBooleanObjectInspector) oi);
    case BYTE:
      return new LazyByte((LazyByteObjectInspector) oi);
    case SHORT:
      return new LazyShort((LazyShortObjectInspector) oi);
    case INT:
      return new CassandraLazyInteger((LazyIntObjectInspector) oi);
    case LONG:
      return new CassandraLazyLong((LazyLongObjectInspector) oi);
    case FLOAT:
      return new CassandraLazyFloat((LazyFloatObjectInspector) oi);
    case DOUBLE:
      return new CassandraLazyDouble((LazyDoubleObjectInspector) oi);
    case STRING:
      return new LazyString((LazyStringObjectInspector) oi);
    case BINARY:
      return new CassandraLazyBinary((LazyBinaryObjectInspector) oi);
    case TIMESTAMP:
      return new CassandraLazyTimestamp((LazyTimestampObjectInspector) oi);
    default:
      throw new RuntimeException("Internal error: no LazyObject for " + p);
  }
}
 
Example 5
Source Project: incubator-hivemall   Source File: HiveUtils.java    License: Apache License 2.0 4 votes vote down vote up
@Nonnull
public static LazyString lazyString(@Nonnull final String str, final byte escapeChar) {
    LazyStringObjectInspector oi =
            LazyPrimitiveObjectInspectorFactory.getLazyStringObjectInspector(false, escapeChar);
    return lazyString(str, oi);
}
 
Example 6
@Test
public void TestColumnTypes() throws Exception {
       ArrayList<Object> stuff = new ArrayList<Object>();
	Properties proptab = new Properties();
	proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMNS, "flag,num1,num2,text");
	proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMN_TYPES, "boolean,tinyint,smallint,string");
	AbstractSerDe jserde = mkSerDe(proptab);
       StructObjectInspector rowOI = (StructObjectInspector)jserde.getObjectInspector();

	// {"attributes":{"flag":false,"num":"5","text":"Point(15.0 5.0)"}}
       addWritable(stuff, false);
       addWritable(stuff, (byte)2);
       addWritable(stuff, (short)5);
       addWritable(stuff, "Point(15.0 5.0)");
	Object row = runSerDe(stuff, jserde, rowOI);
	Object fieldData = getField("flag", row, rowOI);
	Assert.assertEquals(false, ((BooleanWritable)fieldData).get());
	fieldData = getField("num1", row, rowOI);
	Assert.assertEquals((byte)2, ((ByteWritable)fieldData).get());
	fieldData = getField("num2", row, rowOI);
	Assert.assertEquals((short)5, ((ShortWritable)fieldData).get());
	fieldData = getField("text", row, rowOI);
	Assert.assertEquals("Point(15.0 5.0)", ((Text)fieldData).toString());

	stuff.set(0, new BooleanWritable(true));
	stuff.set(1, new ByteWritable((byte)4));
	stuff.set(2, new ShortWritable((short)4));
	//stuff.set(3, new Text("other"));
	LazyStringObjectInspector loi = LazyPrimitiveObjectInspectorFactory.
		getLazyStringObjectInspector(false, (byte)'\0');
	LazyString lstr = new LazyString(loi);
	ByteArrayRef bar = new ByteArrayRef();
	bar.setData("other".getBytes());
	lstr.init(bar, 0, 5);
	stuff.set(3, lstr);
	row = runSerDe(stuff, jserde, rowOI);
	fieldData = getField("flag", row, rowOI);
	Assert.assertEquals(true, ((BooleanWritable)fieldData).get());
	fieldData = getField("num1", row, rowOI);
	Assert.assertEquals((byte)4, ((ByteWritable)fieldData).get());
	fieldData = getField("num2", row, rowOI);
	Assert.assertEquals((short)4, ((ShortWritable)fieldData).get());
	fieldData = getField("text", row, rowOI);
	Assert.assertEquals("other", ((Text)fieldData).toString());
}