Java Code Examples for org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory#javaBooleanObjectInspector()

The following examples show how to use org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory#javaBooleanObjectInspector() . 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
@Override
public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    if (argOIs.length != 2 && argOIs.length != 3) {
        throw new UDFArgumentLengthException("str_contains expects two or three arguments");
    }

    this.queryOI = HiveUtils.asStringOI(argOIs, 0);
    if (!HiveUtils.isStringListOI(argOIs[1])) {
        throw new UDFArgumentTypeException(1,
            "Expected array<string> for the second argument but got "
                    + argOIs[1].getTypeName());
    }
    this.searchTermsOI = HiveUtils.asListOI(argOIs, 1);

    if (argOIs.length == 3) {
        this.orQueryOI = HiveUtils.asBooleanOI(argOIs, 2);
    }

    return PrimitiveObjectInspectorFactory.javaBooleanObjectInspector;
}
 
Example 2
@Override
public ObjectInspector initialize(ObjectInspector[] OIs)
		throws UDFArgumentException {

	opSimpleRelation = getRelationOperator();
	
	if (OIs.length != NUM_ARGS) {
		throw new UDFArgumentException("The " + opSimpleRelation.getType().toString().toLowerCase() + " relationship operator takes exactly two arguments");
	}

	geomHelper1 = HiveGeometryOIHelper.create(OIs[GEOM_1], GEOM_1);
	geomHelper2 = HiveGeometryOIHelper.create(OIs[GEOM_2], GEOM_2);
	
	if (LOG.isDebugEnabled()) {
		LOG.debug("OI[0]=" + geomHelper1);
		LOG.debug("OI[1]=" + geomHelper2);
	}

	firstRun = true;
	geom1IsAccelerated = false;
	
	return PrimitiveObjectInspectorFactory.javaBooleanObjectInspector;
}
 
Example 3
@Test
public void testBooleanWeight() throws HiveException, IOException {
    VectorizeFeaturesUDF udf = new VectorizeFeaturesUDF();
    ObjectInspector[] argOIs = new ObjectInspector[3];
    List<String> featureNames = Arrays.asList("a", "b");
    argOIs[0] = ObjectInspectorFactory.getStandardConstantListObjectInspector(
        PrimitiveObjectInspectorFactory.javaStringObjectInspector, featureNames);
    argOIs[1] = PrimitiveObjectInspectorFactory.javaDoubleObjectInspector;
    argOIs[2] = PrimitiveObjectInspectorFactory.javaBooleanObjectInspector;
    udf.initialize(argOIs);

    DeferredObject[] arguments = new DeferredObject[3];
    arguments[1] = new DeferredJavaObject(new Double(0.1));
    arguments[2] = new DeferredJavaObject(new Boolean(false));

    List<Text> actuals = udf.evaluate(arguments);
    //System.out.println(actuals);
    List<Text> expected = WritableUtils.val(new String[] {"a:0.1"});
    Assert.assertEquals(expected, actuals);

    arguments[2] = new DeferredJavaObject(new Boolean(true));
    actuals = udf.evaluate(arguments);
    //System.out.println(actuals);
    expected = WritableUtils.val("a:0.1", "b:1.0");
    Assert.assertEquals(expected, actuals);

    udf.close();
}
 
Example 4
@Test
public void testReverseOrder() throws Exception {
    ReverseOrderedMapEvaluator evaluator = new ReverseOrderedMapEvaluator();
    ReverseOrderedMapEvaluator.MapAggregationBuffer agg =
            (ReverseOrderedMapEvaluator.MapAggregationBuffer) evaluator.getNewAggregationBuffer();

    ObjectInspector[] inputOIs =
            new ObjectInspector[] {PrimitiveObjectInspectorFactory.javaDoubleObjectInspector,
                    PrimitiveObjectInspectorFactory.javaStringObjectInspector,
                    PrimitiveObjectInspectorFactory.javaBooleanObjectInspector};

    final double[] keys = new double[] {0.7, 0.5, 0.8};
    final String[] values = new String[] {"banana", "apple", "candy"};

    evaluator.init(GenericUDAFEvaluator.Mode.PARTIAL1, inputOIs);
    evaluator.reset(agg);

    for (int i = 0; i < keys.length; i++) {
        evaluator.iterate(agg, new Object[] {keys[i], values[i]});
    }

    Map<Object, Object> res = evaluator.terminate(agg);
    Object[] sortedValues = res.values().toArray();

    Assert.assertEquals(3, sortedValues.length);
    Assert.assertEquals("candy", sortedValues[0]);
    Assert.assertEquals("banana", sortedValues[1]);
    Assert.assertEquals("apple", sortedValues[2]);

    evaluator.close();
}
 
Example 5
public static ObjectInspector getObjectInspector(Type kuduType,
                                                 String hiveType) throws SerDeException {
    switch (kuduType) {
        case STRING:
            return PrimitiveObjectInspectorFactory.javaStringObjectInspector;
        case FLOAT:
            return PrimitiveObjectInspectorFactory.javaFloatObjectInspector;
        case DOUBLE:
            return PrimitiveObjectInspectorFactory.javaDoubleObjectInspector;
        case BOOL:
            return PrimitiveObjectInspectorFactory.javaBooleanObjectInspector;
        case INT8:
            return PrimitiveObjectInspectorFactory.javaByteObjectInspector;
        case INT16:
            return PrimitiveObjectInspectorFactory.javaShortObjectInspector;
        case INT32:
            return PrimitiveObjectInspectorFactory.javaIntObjectInspector;
        case INT64:
            return PrimitiveObjectInspectorFactory.javaLongObjectInspector;
        case TIMESTAMP:
            return PrimitiveObjectInspectorFactory.javaTimestampObjectInspector;
        case BINARY:
            return PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector;
        default:
            throw new SerDeException("Cannot find getObjectInspector for: "
                    + hiveType);
    }
}
 
Example 6
public static ObjectInspector getObjectInspector(int sqlType, String hiveType)
        throws SerDeException {
    switch(sqlType) {
        case Types.VARCHAR:
            return PrimitiveObjectInspectorFactory.javaStringObjectInspector;
        case Types.FLOAT:
            return PrimitiveObjectInspectorFactory.javaFloatObjectInspector;
        case Types.DOUBLE:
            return PrimitiveObjectInspectorFactory.javaDoubleObjectInspector;
        case Types.BOOLEAN:
            return PrimitiveObjectInspectorFactory.javaBooleanObjectInspector;
        case Types.TINYINT:
            return PrimitiveObjectInspectorFactory.javaByteObjectInspector;
        case Types.SMALLINT:
            return PrimitiveObjectInspectorFactory.javaShortObjectInspector;
        case Types.INTEGER:
            return PrimitiveObjectInspectorFactory.javaIntObjectInspector;
        case Types.BIGINT:
            return PrimitiveObjectInspectorFactory.javaLongObjectInspector;
        case Types.TIMESTAMP:
            return PrimitiveObjectInspectorFactory.javaTimestampObjectInspector;
        case Types.BINARY:
            return PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector;
        case Types.ARRAY:
            String hiveElemType = hiveType.substring(hiveType.indexOf('<') + 1, hiveType.indexOf('>')).trim();
            int sqlElemType = hiveTypeToSqlType(hiveElemType);
            ObjectInspector listElementOI = getObjectInspector(sqlElemType, hiveElemType);
            return ObjectInspectorFactory.getStandardListObjectInspector(listElementOI);
        default:
            throw new SerDeException("Cannot find getObjectInspecto for: " + hiveType);
    }
}
 
Example 7
@Override
protected ObjectInspector createBooleanType() {
  return PrimitiveObjectInspectorFactory.javaBooleanObjectInspector;
}
 
Example 8
@Override
public StdBoolean createBoolean(boolean value) {
  return new HiveBoolean(value, PrimitiveObjectInspectorFactory.javaBooleanObjectInspector, this);
}
 
Example 9
Source Project: spork   File: OrcUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static ObjectInspector createObjectInspector(TypeInfo info) {
    switch (info.getCategory()) {
    case PRIMITIVE:
      switch (((PrimitiveTypeInfo) info).getPrimitiveCategory()) {
        case FLOAT:
          return PrimitiveObjectInspectorFactory.javaFloatObjectInspector;
        case DOUBLE:
          return PrimitiveObjectInspectorFactory.javaDoubleObjectInspector;
        case BOOLEAN:
          return PrimitiveObjectInspectorFactory.javaBooleanObjectInspector;
        case INT:
          return PrimitiveObjectInspectorFactory.javaIntObjectInspector;
        case LONG:
          return PrimitiveObjectInspectorFactory.javaLongObjectInspector;
        case STRING:
          return PrimitiveObjectInspectorFactory.javaStringObjectInspector;
        case TIMESTAMP:
          return new PigJodaTimeStampObjectInspector();
        case DECIMAL:
          return new PigDecimalObjectInspector();
        case BINARY:
          return new PigDataByteArrayObjectInspector();
        case DATE:
        case VARCHAR:
        case BYTE:
        case SHORT:
            throw new IllegalArgumentException("Should never happen, " + 
                    (((PrimitiveTypeInfo) info).getPrimitiveCategory()) +
                    "is not valid Pig primitive data type");
        default:
            throw new IllegalArgumentException("Unknown primitive type " +
                    ((PrimitiveTypeInfo) info).getPrimitiveCategory());
      }
    case STRUCT:
      return new PigStructInspector((StructTypeInfo) info);
    case MAP:
      return new PigMapObjectInspector((MapTypeInfo) info);
    case LIST:
      return new PigListObjectInspector((ListTypeInfo) info);
    default:
      throw new IllegalArgumentException("Unknown type " +
        info.getCategory());
  }
}