當前位置: 首頁>>代碼示例>>Java>>正文


Java PrimitiveObjectInspectorFactory類代碼示例

本文整理匯總了Java中org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory的典型用法代碼示例。如果您正苦於以下問題:Java PrimitiveObjectInspectorFactory類的具體用法?Java PrimitiveObjectInspectorFactory怎麽用?Java PrimitiveObjectInspectorFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PrimitiveObjectInspectorFactory類屬於org.apache.hadoop.hive.serde2.objectinspector.primitive包,在下文中一共展示了PrimitiveObjectInspectorFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: MDSMapObjectInspector

import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; //導入依賴的package包/類
public MDSMapObjectInspector( final MapTypeInfo typeInfo ){
  TypeInfo keyTypeInfo = typeInfo.getMapKeyTypeInfo();
  if( keyTypeInfo.getCategory() == ObjectInspector.Category.PRIMITIVE && ( (PrimitiveTypeInfo)keyTypeInfo ).getPrimitiveCategory() == PrimitiveCategory.STRING ){
    keyObjectInspector = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
  }
  else{
    throw new RuntimeException( "Map key type is string only." );
  }

  valueObjectInspector = MDSObjectInspectorFactory.craeteObjectInspectorFromTypeInfo( typeInfo.getMapValueTypeInfo() ); 

  if( valueObjectInspector.getCategory() == ObjectInspector.Category.PRIMITIVE ){
    getField = new PrimitiveGetField( (PrimitiveObjectInspector)valueObjectInspector );
  }
  else if( valueObjectInspector.getCategory() == ObjectInspector.Category.UNION ){
    getField = new UnionGetField( (UnionTypeInfo)( typeInfo.getMapValueTypeInfo() ) );
  }
  else{
    getField = new NestedGetField();
  }
}
 
開發者ID:yahoojapan,項目名稱:multiple-dimension-spread,代碼行數:22,代碼來源:MDSMapObjectInspector.java

示例2: initialize

import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; //導入依賴的package包/類
public StructObjectInspector initialize(ObjectInspector[] arg0) throws UDFArgumentException {
    if (arg0.length != 1) {
        //throw new UDFArgumentLengthException("ExplodeMap takes only one argument");
    }
    if (arg0[0].getCategory() != ObjectInspector.Category.PRIMITIVE) {
        //throw new UDFArgumentException("ExplodeMap takes string as a parameter");
    }
    ArrayList<String> fieldNames = new ArrayList<String>();
    ArrayList<ObjectInspector> fieldOIs = new ArrayList<ObjectInspector>();
    fieldNames.add("col1");
    fieldOIs.add(PrimitiveObjectInspectorFactory.javaStringObjectInspector);
    fieldNames.add("col2");
    fieldOIs.add(PrimitiveObjectInspectorFactory.javaStringObjectInspector);

    return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldOIs);
}
 
開發者ID:Transwarp-DE,項目名稱:Transwarp-Sample-Code,代碼行數:17,代碼來源:InceptorUDTF.java

示例3: initialize

import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; //導入依賴的package包/類
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
  if (arguments.length != 1) {
    throw new UDFArgumentLengthException(String.format("%s needs 1 argument, got %d", udfName, arguments.length));
  }

  if (arguments[0].getCategory() != Category.PRIMITIVE ||
      ((PrimitiveObjectInspector) arguments[0]).getPrimitiveCategory() != inputType) {
    String actual = arguments[0].getCategory() + (arguments[0].getCategory() == Category.PRIMITIVE ?
        "[" + ((PrimitiveObjectInspector) arguments[0]).getPrimitiveCategory() + "]" : "");
    throw new UDFArgumentException(
        String.format("%s only takes primitive type %s, got %s", udfName, inputType, actual));
  }
  argumentOI = arguments[0];
  return PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(outputType);
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:17,代碼來源:HiveTestUDFImpls.java

示例4: initialize

import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; //導入依賴的package包/類
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
  checkArgsSize(arguments, 2, 2);

  checkArgPrimitive(arguments, 0);
  checkArgPrimitive(arguments, 1);

  checkArgGroups(arguments, 0, inputTypes, STRING_GROUP, DATE_GROUP, VOID_GROUP);
  checkArgGroups(arguments, 1, inputTypes, STRING_GROUP, VOID_GROUP);

  obtainDateConverter(arguments, 0, inputTypes, converters);
  obtainStringConverter(arguments, 1, inputTypes, converters);

  if (arguments[1] instanceof ConstantObjectInspector) {
    String dayOfWeek = getConstantStringValue(arguments, 1);
    isDayOfWeekConst = true;
    dayOfWeekIntConst = getIntDayOfWeek(dayOfWeek);
  }

  ObjectInspector outputOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
  return outputOI;
}
 
開發者ID:myui,項目名稱:hive-udf-backports,代碼行數:23,代碼來源:GenericUDFNextDay.java

示例5: initialize

import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; //導入依賴的package包/類
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
  checkArgsSize(arguments, 2, 2);

  checkArgPrimitive(arguments, 0);
  checkArgPrimitive(arguments, 1);

  checkArgGroups(arguments, 0, inputTypes, STRING_GROUP, VOID_GROUP);
  checkArgGroups(arguments, 1, inputTypes, STRING_GROUP, VOID_GROUP);

  obtainStringConverter(arguments, 0, inputTypes, converters);
  obtainStringConverter(arguments, 1, inputTypes, converters);

  ObjectInspector outputOI = PrimitiveObjectInspectorFactory.writableIntObjectInspector;
  return outputOI;
}
 
開發者ID:myui,項目名稱:hive-udf-backports,代碼行數:17,代碼來源:GenericUDFLevenshtein.java

示例6: initialize

import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; //導入依賴的package包/類
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
  checkArgsSize(arguments, 2, 2);

  checkArgPrimitive(arguments, 0);
  checkArgPrimitive(arguments, 1);

  checkArgGroups(arguments, 0, inputTypes, STRING_GROUP, DATE_GROUP, VOID_GROUP);
  checkArgGroups(arguments, 1, inputTypes, NUMERIC_GROUP, VOID_GROUP);

  obtainDateConverter(arguments, 0, inputTypes, converters);
  obtainIntConverter(arguments, 1, inputTypes, converters);

  if (arguments[1] instanceof ConstantObjectInspector) {
    numMonthsConst = getConstantIntValue(arguments, 1);
    isNumMonthsConst = true;
  }

  ObjectInspector outputOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
  return outputOI;
}
 
開發者ID:myui,項目名稱:hive-udf-backports,代碼行數:22,代碼來源:GenericUDFAddMonths.java

示例7: obtainIntConverter

import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; //導入依賴的package包/類
public static void obtainIntConverter(ObjectInspector[] arguments, int i,
        PrimitiveCategory[] inputTypes, Converter[] converters) throws UDFArgumentTypeException {
    PrimitiveObjectInspector inOi = (PrimitiveObjectInspector) arguments[i];
    PrimitiveCategory inputType = inOi.getPrimitiveCategory();
    switch (inputType) {
        case BYTE:
        case SHORT:
        case INT:
        case VOID:
            break;
        default:
            throw new UDFArgumentTypeException(i, "_FUNC_ only takes INT/SHORT/BYTE types as "
                    + getArgOrder(i) + " argument, got " + inputType);
    }

    Converter converter = ObjectInspectorConverters.getConverter(arguments[i],
        PrimitiveObjectInspectorFactory.writableIntObjectInspector);
    converters[i] = converter;
    inputTypes[i] = inputType;
}
 
開發者ID:myui,項目名稱:hive-udf-backports,代碼行數:21,代碼來源:BackportUtils.java

示例8: obtainLongConverter

import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; //導入依賴的package包/類
public static void obtainLongConverter(ObjectInspector[] arguments, int i,
        PrimitiveCategory[] inputTypes, Converter[] converters) throws UDFArgumentTypeException {
    PrimitiveObjectInspector inOi = (PrimitiveObjectInspector) arguments[i];
    PrimitiveCategory inputType = inOi.getPrimitiveCategory();
    switch (inputType) {
        case BYTE:
        case SHORT:
        case INT:
        case LONG:
            break;
        default:
            throw new UDFArgumentTypeException(i,
                "_FUNC_ only takes LONG/INT/SHORT/BYTE types as " + getArgOrder(i)
                        + " argument, got " + inputType);
    }

    Converter converter = ObjectInspectorConverters.getConverter(arguments[i],
        PrimitiveObjectInspectorFactory.writableIntObjectInspector);
    converters[i] = converter;
    inputTypes[i] = inputType;
}
 
開發者ID:myui,項目名稱:hive-udf-backports,代碼行數:22,代碼來源:BackportUtils.java

示例9: obtainDateConverter

import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; //導入依賴的package包/類
public static void obtainDateConverter(ObjectInspector[] arguments, int i,
        PrimitiveCategory[] inputTypes, Converter[] converters) throws UDFArgumentTypeException {
    PrimitiveObjectInspector inOi = (PrimitiveObjectInspector) arguments[i];
    PrimitiveCategory inputType = inOi.getPrimitiveCategory();
    ObjectInspector outOi;
    switch (inputType) {
        case STRING:
        case VARCHAR:
        case CHAR:
            outOi = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
            break;
        case TIMESTAMP:
        case DATE:
        case VOID:
            outOi = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
            break;
        default:
            throw new UDFArgumentTypeException(i,
                "_FUNC_ only takes STRING_GROUP or DATE_GROUP types as " + getArgOrder(i)
                        + " argument, got " + inputType);
    }
    converters[i] = ObjectInspectorConverters.getConverter(inOi, outOi);
    inputTypes[i] = inputType;
}
 
開發者ID:myui,項目名稱:hive-udf-backports,代碼行數:25,代碼來源:BackportUtils.java

示例10: obtainTimestampConverter

import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; //導入依賴的package包/類
public static void obtainTimestampConverter(ObjectInspector[] arguments, int i,
        PrimitiveCategory[] inputTypes, Converter[] converters) throws UDFArgumentTypeException {
    PrimitiveObjectInspector inOi = (PrimitiveObjectInspector) arguments[i];
    PrimitiveCategory inputType = inOi.getPrimitiveCategory();
    ObjectInspector outOi;
    switch (inputType) {
        case STRING:
        case VARCHAR:
        case CHAR:
        case TIMESTAMP:
        case DATE:
            break;
        default:
            throw new UDFArgumentTypeException(i,
                "_FUNC_ only takes STRING_GROUP or DATE_GROUP types as " + getArgOrder(i)
                        + " argument, got " + inputType);
    }
    outOi = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
    converters[i] = ObjectInspectorConverters.getConverter(inOi, outOi);
    inputTypes[i] = inputType;
}
 
開發者ID:myui,項目名稱:hive-udf-backports,代碼行數:22,代碼來源:BackportUtils.java

示例11: testSingleColumn2

import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; //導入依賴的package包/類
@Test
public void testSingleColumn2() throws HiveException {
	final JsonQueryUDTF sut = new JsonQueryUDTF();
	final StructObjectInspector oi = sut.initialize(new ObjectInspector[] {
			PrimitiveObjectInspectorFactory.writableStringObjectInspector,
			toConstantOI(".region as $region | .timezones[] | {name: ($region + \"/\" + .name), offset}"),
			toConstantOI("struct<name:string,offset:int>"),
	});
	assertEquals("struct<col1:struct<name:string,offset:int>>", oi.getTypeName());

	final List<Object> results = evaluate(sut, toObject(TEST_JSON));
	assertEquals(3, results.size());

	final HivePath namePath = new HivePath(oi, ".col1.name");
	final HivePath offsetPath = new HivePath(oi, ".col1.offset");

	assertEquals("Asia/Tokyo", namePath.extract(results.get(0)).asString());
	assertEquals(540, offsetPath.extract(results.get(0)).asInt());

	assertEquals("Asia/Taipei", namePath.extract(results.get(1)).asString());
	assertEquals(480, offsetPath.extract(results.get(1)).asInt());

	assertEquals("Asia/Kamchatka", namePath.extract(results.get(2)).asString());
	assertEquals(720, offsetPath.extract(results.get(2)).asInt());
}
 
開發者ID:CyberAgent,項目名稱:hive-jq-udtf,代碼行數:26,代碼來源:JsonQueryUDTFTest.java

示例12: testMultiColumn

import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; //導入依賴的package包/類
@Test
public void testMultiColumn() throws HiveException {
	final JsonQueryUDTF sut = new JsonQueryUDTF();
	final StructObjectInspector oi = sut.initialize(new ObjectInspector[] {
			PrimitiveObjectInspectorFactory.writableStringObjectInspector,
			toConstantOI(".region as $region | .timezones[] | {name: ($region + \"/\" + .name), offset}"),
			toConstantOI("name:string"),
			toConstantOI("offset:int"),
	});
	assertEquals("struct<name:string,offset:int>", oi.getTypeName());

	final List<Object> results = evaluate(sut, toObject(TEST_JSON));
	assertEquals(3, results.size());

	final HivePath namePath = new HivePath(oi, ".name");
	final HivePath offsetPath = new HivePath(oi, ".offset");

	assertEquals("Asia/Tokyo", namePath.extract(results.get(0)).asString());
	assertEquals(540, offsetPath.extract(results.get(0)).asInt());

	assertEquals("Asia/Taipei", namePath.extract(results.get(1)).asString());
	assertEquals(480, offsetPath.extract(results.get(1)).asInt());

	assertEquals("Asia/Kamchatka", namePath.extract(results.get(2)).asString());
	assertEquals(720, offsetPath.extract(results.get(2)).asInt());
}
 
開發者ID:CyberAgent,項目名稱:hive-jq-udtf,代碼行數:27,代碼來源:JsonQueryUDTFTest.java

示例13: testAbortOnError

import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; //導入依賴的package包/類
@Test
public void testAbortOnError() throws HiveException {
	final JsonQueryUDTF sut = new JsonQueryUDTF();
	@SuppressWarnings("unused")
	final StructObjectInspector oi = sut.initialize(new ObjectInspector[] {
			PrimitiveObjectInspectorFactory.writableStringObjectInspector,
			toConstantOI("if $error then error($error.message) else . end"),
			toConstantOI("string"),
	});

	try {
		evaluate(sut, toObject("\"corrupt \"string"));
		fail("should fail");
	} catch (final HiveException e) {
		assertTrue(e.getMessage().contains("Unrecognized token 'string'"));
	}
}
 
開發者ID:CyberAgent,項目名稱:hive-jq-udtf,代碼行數:18,代碼來源:JsonQueryUDTFTest.java

示例14: testMoreOnStringOutputConversions

import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; //導入依賴的package包/類
@Test
public void testMoreOnStringOutputConversions() throws HiveException {
	final JsonQueryUDTF sut = new JsonQueryUDTF();

	final StructObjectInspector oi = sut.initialize(new ObjectInspector[] {
			PrimitiveObjectInspectorFactory.writableStringObjectInspector,
			toConstantOI("{foo: {a: 1}, bar: null, baz: \"baz\"}"),
			toConstantOI("foo:string"),
			toConstantOI("bar:string"),
			toConstantOI("baz:string"),
	});

	final List<Object> results = evaluate(sut, toObject("null"));
	assertEquals(1, results.size());

	final Object obj = results.get(0);
	assertEquals("{\"a\":1}", new HivePath(oi, ".foo").extract(obj).asString());
	assertTrue(new HivePath(oi, ".bar").extract(obj).isNull());
	assertEquals("baz", new HivePath(oi, ".baz").extract(obj).asString());
}
 
開發者ID:CyberAgent,項目名稱:hive-jq-udtf,代碼行數:21,代碼來源:JsonQueryUDTFTest.java

示例15: testNullInputs

import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; //導入依賴的package包/類
@Test
public void testNullInputs() throws HiveException {
	final JsonQueryUDTF sut = new JsonQueryUDTF();

	final StructObjectInspector oi = sut.initialize(new ObjectInspector[] {
			PrimitiveObjectInspectorFactory.writableStringObjectInspector,
			toConstantOI("."),
			toConstantOI("string"),
	});

	final List<Object> results = evaluate(sut, toObject("null"), null, toObject(null));
	assertEquals(3, results.size());

	assertTrue(new HivePath(oi, ".col1").extract(results.get(0)).isNull());
	assertTrue(new HivePath(oi, ".col1").extract(results.get(1)).isNull());
	assertTrue(new HivePath(oi, ".col1").extract(results.get(2)).isNull());
}
 
開發者ID:CyberAgent,項目名稱:hive-jq-udtf,代碼行數:18,代碼來源:JsonQueryUDTFTest.java


注:本文中的org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。