org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyPrimitiveObjectInspectorFactory Java Examples

The following examples show how to use org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyPrimitiveObjectInspectorFactory. 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 File: HiveDynamoDBTypeTest.java    From emr-dynamodb-connector with Apache License 2.0 6 votes vote down vote up
@Test
public void testString() {
  String val = STRING_LIST.get(0);
  HiveDynamoDBType ddType = HiveDynamoDBTypeFactory.getTypeObjectFromHiveType(STRING_OBJECT_INSPECTOR);
  AttributeValue expectedAV = new AttributeValue().withS(val);
  LazyString ls = new LazyString(LazyPrimitiveObjectInspectorFactory
      .getLazyStringObjectInspector(false, (byte) 0));
  initLazyObject(ls, val.getBytes(), 0, val.length());

  for (Object o : new Object[]{val, new Text(val), ls}) {
    AttributeValue actualAV = ddType.getDynamoDBData(o, STRING_OBJECT_INSPECTOR, false);
    assertEquals(expectedAV, actualAV);
    Object actualStr = ddType.getHiveData(actualAV, STRING_OBJECT_INSPECTOR);
    assertEquals(val, actualStr);
  }
}
 
Example #2
Source File: HiveUtils.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static LazyInteger lazyInteger(@Nonnull final int v) {
    LazyInteger lazy =
            new LazyInteger(LazyPrimitiveObjectInspectorFactory.LAZY_INT_OBJECT_INSPECTOR);
    lazy.getWritableObject().set(v);
    return lazy;
}
 
Example #3
Source File: HiveUtils.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static LazyLong lazyLong(@Nonnull final long v) {
    LazyLong lazy =
            new LazyLong(LazyPrimitiveObjectInspectorFactory.LAZY_LONG_OBJECT_INSPECTOR);
    lazy.getWritableObject().set(v);
    return lazy;
}
 
Example #4
Source File: GeneralClassifierUDTFTest.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@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 #5
Source File: GeneralRegressorUDTFTest.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@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 #6
Source File: HiveUtils.java    From incubator-hivemall with 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 #7
Source File: GeneralClassifierUDTFTest.java    From incubator-hivemall with Apache License 2.0 4 votes vote down vote up
@Test
public void testLazyIntegerFeature() throws Exception {
    List<LazyInteger> x = Arrays.asList(lazyInteger(111), lazyInteger(222));
    ObjectInspector featureOI = LazyPrimitiveObjectInspectorFactory.LAZY_INT_OBJECT_INSPECTOR;
    testFeature(x, featureOI, LazyInteger.class, Integer.class);
}
 
Example #8
Source File: GeneralClassifierUDTFTest.java    From incubator-hivemall with Apache License 2.0 4 votes vote down vote up
@Test
public void testLazyLongFeature() throws Exception {
    List<LazyLong> x = Arrays.asList(lazyLong(111), lazyLong(222));
    ObjectInspector featureOI = LazyPrimitiveObjectInspectorFactory.LAZY_LONG_OBJECT_INSPECTOR;
    testFeature(x, featureOI, LazyLong.class, Long.class);
}
 
Example #9
Source File: GeneralRegressorUDTFTest.java    From incubator-hivemall with Apache License 2.0 4 votes vote down vote up
@Test
public void testLazyIntegerFeature() throws Exception {
    List<LazyInteger> x = Arrays.asList(lazyInteger(111), lazyInteger(222));
    ObjectInspector featureOI = LazyPrimitiveObjectInspectorFactory.LAZY_INT_OBJECT_INSPECTOR;
    testFeature(x, featureOI, LazyInteger.class, Integer.class);
}
 
Example #10
Source File: GeneralRegressorUDTFTest.java    From incubator-hivemall with Apache License 2.0 4 votes vote down vote up
@Test
public void testLazyLongFeature() throws Exception {
    List<LazyLong> x = Arrays.asList(lazyLong(111), lazyLong(222));
    ObjectInspector featureOI = LazyPrimitiveObjectInspectorFactory.LAZY_LONG_OBJECT_INSPECTOR;
    testFeature(x, featureOI, LazyLong.class, Long.class);
}
 
Example #11
Source File: TestEsriJsonSerDe.java    From spatial-framework-for-hadoop with Apache License 2.0 4 votes vote down vote up
@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());
}