Java Code Examples for org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject

The following examples show how to use org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject. 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: yauaa   Source File: TestParseUserAgent.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testBasic() throws HiveException {
    // This is an edge case where the webview fields are calulcated AND wiped again.
    String userAgent = "Mozilla/5.0 (Linux; Android 5.1.1; KFFOWI Build/LMY47O) AppleWebKit/537.36 (KHTML, like Gecko) " +
        "Version/4.0 Chrome/41.51020.2250.0246 Mobile Safari/537.36 cordova-amazon-fireos/3.4.0 AmazonWebAppPlatform/3.4.0;2.0";

    ParseUserAgent parseUserAgent = new ParseUserAgent();

    StandardStructObjectInspector resultInspector = (StandardStructObjectInspector) parseUserAgent
        .initialize(new ObjectInspector[]{
            PrimitiveObjectInspectorFactory.javaStringObjectInspector
        });

    for (int i = 0; i < 100000; i++) {
        Object row = parseUserAgent.evaluate(new DeferredObject[]{new DeferredJavaObject(userAgent)});
        checkField(resultInspector, row, "DeviceClass", "Tablet");
        checkField(resultInspector, row, "OperatingSystemNameVersion", "FireOS 3.4.0");
        checkField(resultInspector, row, "WebviewAppName", "Unknown");
    }
}
 
Example 2
Source Project: hive-third-functions   Source File: UDFMapBuildTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMapBuild() throws Exception {
    UDFMapBuild udf = new UDFMapBuild();
    ObjectInspector keyArrayOI = ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.javaStringObjectInspector);
    ObjectInspector valueArrayOI = ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.javaStringObjectInspector);
    ObjectInspector[] arguments = {keyArrayOI, valueArrayOI};
    udf.initialize(arguments);

    List<String> keyArray = ImmutableList.of("key1", "key2", "key3");
    List<String> valueArray = ImmutableList.of("value1", "value2", "value3");
    DeferredObject keyArrayObj = new DeferredJavaObject(keyArray);
    DeferredObject valueArrayObj = new DeferredJavaObject(valueArray);
    DeferredObject[] args = {keyArrayObj, valueArrayObj};
    LinkedHashMap<String, String> output = (LinkedHashMap<String, String>) udf.evaluate(args);
    LinkedHashMap<String, String> expect = Maps.newLinkedHashMap();
    expect.putAll(ImmutableMap.<String, String>of("key1", "value1", "key2", "value2", "key3", "value3"));

    Assert.assertEquals("map_build() test", true, MapUtils.mapEquals(output, expect));
}
 
Example 3
Source Project: hive-third-functions   Source File: UDFMapConcatTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMapConcat() throws Exception {
    UDFMapConcat udf = new UDFMapConcat();
    ObjectInspector leftMapOI = ObjectInspectorFactory.getStandardMapObjectInspector(PrimitiveObjectInspectorFactory.javaStringObjectInspector, PrimitiveObjectInspectorFactory.javaStringObjectInspector);
    ObjectInspector rightMapOI = ObjectInspectorFactory.getStandardMapObjectInspector(PrimitiveObjectInspectorFactory.javaStringObjectInspector, PrimitiveObjectInspectorFactory.javaStringObjectInspector);
    ObjectInspector[] arguments = {leftMapOI, rightMapOI};
    udf.initialize(arguments);

    LinkedHashMap<String, String> leftMap = Maps.newLinkedHashMap();
    leftMap.putAll(ImmutableMap.<String, String>of("key1", "11", "key2", "12", "key3", "13"));
    LinkedHashMap<String, String> rightMap = Maps.newLinkedHashMap();
    rightMap.putAll(ImmutableMap.<String, String>of("key3", "21", "key4", "22", "key5", "23"));

    DeferredObject leftMapObj = new DeferredJavaObject(leftMap);
    DeferredObject rightMapObj = new DeferredJavaObject(rightMap);
    DeferredObject[] args = {leftMapObj, rightMapObj};
    LinkedHashMap<String, String> output = (LinkedHashMap<String, String>) udf.evaluate(args);
    LinkedHashMap<String, String> expect = Maps.newLinkedHashMap();
    expect.putAll(ImmutableMap.<String, String>of("key1", "11", "key2", "12", "key3", "21", "key4", "22", "key5", "23"));

    Assert.assertEquals("map_concat() test", true, MapUtils.mapEquals(output, expect));
}
 
Example 4
@Test
public void testKilometers1() throws HiveException, IOException {
    HaversineDistanceUDF udf = new HaversineDistanceUDF();
    udf.initialize(
        new ObjectInspector[] {PrimitiveObjectInspectorFactory.javaDoubleObjectInspector,
                PrimitiveObjectInspectorFactory.javaDoubleObjectInspector,
                PrimitiveObjectInspectorFactory.javaDoubleObjectInspector,
                PrimitiveObjectInspectorFactory.javaDoubleObjectInspector});

    // Tokyo
    double lat1 = 35.6833d, lon1 = 139.7667d;
    // Osaka
    double lat2 = 34.6603d, lon2 = 135.5232d;

    DoubleWritable result1 = udf.evaluate(
        new DeferredObject[] {new DeferredJavaObject(lat1), new DeferredJavaObject(lon1),
                new DeferredJavaObject(lat2), new DeferredJavaObject(lon2)});
    Assert.assertEquals(402.092d, result1.get(), 0.001d);

    udf.close();
}
 
Example 5
@Test
public void testKilometers2() throws HiveException, IOException {
    HaversineDistanceUDF udf = new HaversineDistanceUDF();
    udf.initialize(
        new ObjectInspector[] {PrimitiveObjectInspectorFactory.javaDoubleObjectInspector,
                PrimitiveObjectInspectorFactory.javaDoubleObjectInspector,
                PrimitiveObjectInspectorFactory.javaDoubleObjectInspector,
                PrimitiveObjectInspectorFactory.javaDoubleObjectInspector,
                ObjectInspectorUtils.getConstantObjectInspector(
                    PrimitiveObjectInspectorFactory.javaBooleanObjectInspector, false)});

    // Tokyo
    double lat1 = 35.6833d, lon1 = 139.7667d;
    // Osaka
    double lat2 = 34.6603d, lon2 = 135.5232d;

    DoubleWritable result1 = udf.evaluate(
        new DeferredObject[] {new DeferredJavaObject(lat1), new DeferredJavaObject(lon1),
                new DeferredJavaObject(lat2), new DeferredJavaObject(lon2)});
    Assert.assertEquals(402.092d, result1.get(), 0.001d);

    udf.close();
}
 
Example 6
@Test
public void testMiles() throws HiveException, IOException {
    HaversineDistanceUDF udf = new HaversineDistanceUDF();
    udf.initialize(
        new ObjectInspector[] {PrimitiveObjectInspectorFactory.javaDoubleObjectInspector,
                PrimitiveObjectInspectorFactory.javaDoubleObjectInspector,
                PrimitiveObjectInspectorFactory.javaDoubleObjectInspector,
                PrimitiveObjectInspectorFactory.javaDoubleObjectInspector,
                ObjectInspectorUtils.getConstantObjectInspector(
                    PrimitiveObjectInspectorFactory.javaBooleanObjectInspector, true)});

    // Tokyo
    double lat1 = 35.6833d, lon1 = 139.7667d;
    // Osaka
    double lat2 = 34.6603d, lon2 = 135.5232d;

    DoubleWritable result1 = udf.evaluate(new DeferredObject[] {new DeferredJavaObject(lat1),
            new DeferredJavaObject(lon1), new DeferredJavaObject(lat2),
            new DeferredJavaObject(lon2), new DeferredJavaObject(true)});
    Assert.assertEquals(249.84d, result1.get(), 0.1d);

    udf.close();
}
 
Example 7
Source Project: incubator-hivemall   Source File: TreePredictUDFv1Test.java    License: Apache License 2.0 6 votes vote down vote up
private static int evalPredict(DecisionTree tree, double[] x)
        throws HiveException, IOException {
    String opScript = tree.predictOpCodegen(StackMachine.SEP);
    debugPrint(opScript);

    TreePredictUDFv1 udf = new TreePredictUDFv1();
    udf.initialize(
        new ObjectInspector[] {PrimitiveObjectInspectorFactory.javaStringObjectInspector,
                PrimitiveObjectInspectorFactory.javaIntObjectInspector,
                PrimitiveObjectInspectorFactory.javaStringObjectInspector,
                ObjectInspectorFactory.getStandardListObjectInspector(
                    PrimitiveObjectInspectorFactory.javaDoubleObjectInspector),
                ObjectInspectorUtils.getConstantObjectInspector(
                    PrimitiveObjectInspectorFactory.javaBooleanObjectInspector, true)});
    DeferredObject[] arguments = new DeferredObject[] {new DeferredJavaObject("model_id#1"),
            new DeferredJavaObject(ModelType.opscode.getId()), new DeferredJavaObject(opScript),
            new DeferredJavaObject(ArrayUtils.toList(x)), new DeferredJavaObject(true)};

    IntWritable result = (IntWritable) udf.evaluate(arguments);
    udf.close();
    return result.get();
}
 
Example 8
Source Project: incubator-hivemall   Source File: TreePredictUDFv1Test.java    License: Apache License 2.0 6 votes vote down vote up
private static double evalPredict(RegressionTree tree, double[] x)
        throws HiveException, IOException {
    String opScript = tree.predictOpCodegen(StackMachine.SEP);
    debugPrint(opScript);

    TreePredictUDFv1 udf = new TreePredictUDFv1();
    udf.initialize(
        new ObjectInspector[] {PrimitiveObjectInspectorFactory.javaStringObjectInspector,
                PrimitiveObjectInspectorFactory.javaIntObjectInspector,
                PrimitiveObjectInspectorFactory.javaStringObjectInspector,
                ObjectInspectorFactory.getStandardListObjectInspector(
                    PrimitiveObjectInspectorFactory.javaDoubleObjectInspector),
                ObjectInspectorUtils.getConstantObjectInspector(
                    PrimitiveObjectInspectorFactory.javaBooleanObjectInspector, false)});
    DeferredObject[] arguments = new DeferredObject[] {new DeferredJavaObject("model_id#1"),
            new DeferredJavaObject(ModelType.opscode.getId()), new DeferredJavaObject(opScript),
            new DeferredJavaObject(ArrayUtils.toList(x)), new DeferredJavaObject(false)};

    DoubleWritable result = (DoubleWritable) udf.evaluate(arguments);
    udf.close();
    return result.get();
}
 
Example 9
Source Project: incubator-hivemall   Source File: TreePredictUDFTest.java    License: Apache License 2.0 6 votes vote down vote up
private static int evalPredict(DecisionTree tree, double[] x)
        throws HiveException, IOException {
    byte[] b = tree.serialize(true);
    byte[] encoded = Base91.encode(b);
    Text model = new Text(encoded);

    TreePredictUDF udf = new TreePredictUDF();
    udf.initialize(
        new ObjectInspector[] {PrimitiveObjectInspectorFactory.javaStringObjectInspector,
                PrimitiveObjectInspectorFactory.writableStringObjectInspector,
                ObjectInspectorFactory.getStandardListObjectInspector(
                    PrimitiveObjectInspectorFactory.javaDoubleObjectInspector),
                ObjectInspectorUtils.getConstantObjectInspector(
                    PrimitiveObjectInspectorFactory.javaBooleanObjectInspector, true)});
    DeferredObject[] arguments = new DeferredObject[] {new DeferredJavaObject("model_id#1"),
            new DeferredJavaObject(model), new DeferredJavaObject(ArrayUtils.toList(x)),
            new DeferredJavaObject(true)};

    Object[] result = (Object[]) udf.evaluate(arguments);
    udf.close();
    return ((IntWritable) result[0]).get();
}
 
Example 10
Source Project: incubator-hivemall   Source File: TreePredictUDFTest.java    License: Apache License 2.0 6 votes vote down vote up
private static double evalPredict(RegressionTree tree, double[] x)
        throws HiveException, IOException {
    byte[] b = tree.serialize(true);
    byte[] encoded = Base91.encode(b);
    Text model = new Text(encoded);

    TreePredictUDF udf = new TreePredictUDF();
    udf.initialize(
        new ObjectInspector[] {PrimitiveObjectInspectorFactory.javaStringObjectInspector,
                PrimitiveObjectInspectorFactory.writableStringObjectInspector,
                ObjectInspectorFactory.getStandardListObjectInspector(
                    PrimitiveObjectInspectorFactory.javaDoubleObjectInspector),
                ObjectInspectorUtils.getConstantObjectInspector(
                    PrimitiveObjectInspectorFactory.javaBooleanObjectInspector, false)});
    DeferredObject[] arguments = new DeferredObject[] {new DeferredJavaObject("model_id#1"),
            new DeferredJavaObject(model), new DeferredJavaObject(ArrayUtils.toList(x)),
            new DeferredJavaObject(false)};

    DoubleWritable result = (DoubleWritable) udf.evaluate(arguments);
    udf.close();
    return result.get();
}
 
Example 11
@Test
public void testOneArgument() throws HiveException, IOException {
    VectorizeFeaturesUDF udf = new VectorizeFeaturesUDF();
    ObjectInspector[] argOIs = new ObjectInspector[2];
    List<String> featureNames = Arrays.asList("a");
    argOIs[0] = ObjectInspectorFactory.getStandardConstantListObjectInspector(
        PrimitiveObjectInspectorFactory.javaStringObjectInspector, featureNames);
    argOIs[1] = PrimitiveObjectInspectorFactory.javaDoubleObjectInspector;
    udf.initialize(argOIs);

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

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

    udf.close();
}
 
Example 12
@Test
public void testTwoArguments() 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.javaStringObjectInspector;
    udf.initialize(argOIs);

    DeferredObject[] arguments = new DeferredObject[3];
    arguments[1] = new DeferredJavaObject(new Double(0.1));
    arguments[2] = new DeferredJavaObject("1.1");

    List<Text> actuals = udf.evaluate(arguments);
    //System.out.println(actuals);
    List<Text> expected = WritableUtils.val("a:0.1", "b:1.1");
    Assert.assertEquals(expected, actuals);

    udf.close();
}
 
Example 13
@Test
public void testAvoidZeroWeight() 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.javaStringObjectInspector;
    udf.initialize(argOIs);

    DeferredObject[] arguments = new DeferredObject[3];
    arguments[1] = new DeferredJavaObject(new Double(0.1));
    arguments[2] = new DeferredJavaObject("0");

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

    udf.close();
}
 
Example 14
Source Project: incubator-hivemall   Source File: ToLibSVMFormatUDFTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFeatureOnly() throws IOException, HiveException {
    ToLibSVMFormatUDF udf = new ToLibSVMFormatUDF();

    udf.initialize(new ObjectInspector[] {
            ObjectInspectorFactory.getStandardListObjectInspector(
                PrimitiveObjectInspectorFactory.javaStringObjectInspector),
            ObjectInspectorUtils.getConstantObjectInspector(
                PrimitiveObjectInspectorFactory.javaStringObjectInspector, "-features 10")});

    Assert.assertEquals("3:2.1 7:3.4", udf.evaluate(new DeferredObject[] {
            new DeferredJavaObject(Arrays.asList("apple:3.4", "orange:2.1"))}));

    Assert.assertEquals("3:2.1 7:3.4", udf.evaluate(
        new DeferredObject[] {new DeferredJavaObject(Arrays.asList("7:3.4", "3:2.1"))}));

    udf.close();
}
 
Example 15
Source Project: incubator-hivemall   Source File: ToLibSVMFormatUDFTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFeatureAndIntLabel() throws IOException, HiveException {
    ToLibSVMFormatUDF udf = new ToLibSVMFormatUDF();

    udf.initialize(
        new ObjectInspector[] {
                ObjectInspectorFactory.getStandardListObjectInspector(
                    PrimitiveObjectInspectorFactory.javaStringObjectInspector),
                PrimitiveObjectInspectorFactory.javaIntObjectInspector,
                ObjectInspectorUtils.getConstantObjectInspector(
                    PrimitiveObjectInspectorFactory.javaStringObjectInspector,
                    "-features 10")});

    Assert.assertEquals("5 3:2.1 7:3.4",
        udf.evaluate(new DeferredObject[] {
                new DeferredJavaObject(Arrays.asList("apple:3.4", "orange:2.1")),
                new DeferredJavaObject(5)}));

    udf.close();
}
 
Example 16
Source Project: incubator-hivemall   Source File: ToLibSVMFormatUDFTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFeatureAndFloatLabel() throws IOException, HiveException {
    ToLibSVMFormatUDF udf = new ToLibSVMFormatUDF();

    udf.initialize(
        new ObjectInspector[] {
                ObjectInspectorFactory.getStandardListObjectInspector(
                    PrimitiveObjectInspectorFactory.javaStringObjectInspector),
                PrimitiveObjectInspectorFactory.javaFloatObjectInspector,
                ObjectInspectorUtils.getConstantObjectInspector(
                    PrimitiveObjectInspectorFactory.javaStringObjectInspector,
                    "-features 10")});

    Assert.assertEquals("5.0 3:2.1 7:3.4",
        udf.evaluate(
            new DeferredObject[] {new DeferredJavaObject(Arrays.asList("7:3.4", "3:2.1")),
                    new DeferredJavaObject(5.f)}));

    udf.close();
}
 
Example 17
Source Project: yauaa   Source File: TestParseUserAgentBadInput.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testBadInputNull() throws HiveException {
    parseUserAgent
        .initialize(new ObjectInspector[]{
            PrimitiveObjectInspectorFactory.javaStringObjectInspector
        });

    assertNull(parseUserAgent.evaluate(new DeferredObject[]{new DeferredJavaObject(null)}));
}
 
Example 18
Source Project: incubator-hivemall   Source File: Lat2TileYUDFTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEvaluate() throws HiveException, IOException {
    Lat2TileYUDF udf = new Lat2TileYUDF();
    udf.initialize(
        new ObjectInspector[] {PrimitiveObjectInspectorFactory.javaDoubleObjectInspector,
                PrimitiveObjectInspectorFactory.javaIntObjectInspector});

    IntWritable result1 = udf.evaluate(
        new DeferredObject[] {new DeferredJavaObject(49.60055d), new DeferredJavaObject(13)});
    Assert.assertEquals(2792, result1.get());

    udf.close();
}
 
Example 19
Source Project: incubator-hivemall   Source File: Lon2TileXUDFTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEvaluate() throws HiveException, IOException {
    Lon2TileXUDF udf = new Lon2TileXUDF();
    udf.initialize(
        new ObjectInspector[] {PrimitiveObjectInspectorFactory.javaDoubleObjectInspector,
                PrimitiveObjectInspectorFactory.javaIntObjectInspector});

    IntWritable result1 = udf.evaluate(
        new DeferredObject[] {new DeferredJavaObject(11.01296d), new DeferredJavaObject(13)});
    Assert.assertEquals(4346, result1.get());

    udf.close();
}
 
Example 20
Source Project: incubator-hivemall   Source File: TileY2LatUDFTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEvaluate() throws IOException, HiveException {
    TileY2LatUDF udf = new TileY2LatUDF();
    udf.initialize(
        new ObjectInspector[] {PrimitiveObjectInspectorFactory.javaIntObjectInspector,
                PrimitiveObjectInspectorFactory.javaIntObjectInspector});

    DoubleWritable result = udf.evaluate(
        new DeferredObject[] {new DeferredJavaObject(503), new DeferredJavaObject(14)});
    Assert.assertEquals(83.99996604d, result.get(), 0.001);

    udf.close();
}
 
Example 21
Source Project: incubator-hivemall   Source File: TileX2LonUDFTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEvaluate() throws IOException, HiveException {
    TileX2LonUDF udf = new TileX2LonUDF();
    udf.initialize(
        new ObjectInspector[] {PrimitiveObjectInspectorFactory.javaIntObjectInspector,
                PrimitiveObjectInspectorFactory.javaIntObjectInspector});

    DoubleWritable result = udf.evaluate(
        new DeferredObject[] {new DeferredJavaObject(3551), new DeferredJavaObject(13)});
    Assert.assertEquals(-23.95019531d, result.get(), 0.001);

    udf.close();
}
 
Example 22
@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 23
@Test
public void testCategoricalVariable() 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.javaStringObjectInspector;
    udf.initialize(argOIs);

    DeferredObject[] arguments = new DeferredObject[3];
    arguments[1] = new DeferredJavaObject(new Double(0.1));
    arguments[2] = new DeferredJavaObject("dayofweek");

    List<Text> actuals = udf.evaluate(arguments);
    //System.out.println(actuals);
    List<Text> expected = WritableUtils.val("a:0.1", "b#dayofweek");
    Assert.assertEquals(expected, actuals);

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

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

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

    udf.close();
}
 
Example 24
Source Project: incubator-hivemall   Source File: FeatureUDFTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testIntInt() throws Exception {
    ObjectInspector featureOI = PrimitiveObjectInspectorFactory.javaIntObjectInspector;
    ObjectInspector weightOI = PrimitiveObjectInspectorFactory.javaIntObjectInspector;
    udf.initialize(new ObjectInspector[] {featureOI, weightOI});

    Text ret = udf.evaluate(
        new GenericUDF.DeferredObject[] {new DeferredJavaObject(1), new DeferredJavaObject(2)});

    Assert.assertEquals("1:2", ret.toString());
}
 
Example 25
Source Project: incubator-hivemall   Source File: FeatureUDFTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testIntLong() throws Exception {
    ObjectInspector featureOI = PrimitiveObjectInspectorFactory.javaIntObjectInspector;
    ObjectInspector weightOI = PrimitiveObjectInspectorFactory.javaLongObjectInspector;
    udf.initialize(new ObjectInspector[] {featureOI, weightOI});

    Text ret = udf.evaluate(new GenericUDF.DeferredObject[] {new DeferredJavaObject(1),
            new DeferredJavaObject(2L)});

    Assert.assertEquals("1:2", ret.toString());
}
 
Example 26
Source Project: incubator-hivemall   Source File: FeatureUDFTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testIntFloat() throws Exception {
    ObjectInspector featureOI = PrimitiveObjectInspectorFactory.javaIntObjectInspector;
    ObjectInspector weightOI = PrimitiveObjectInspectorFactory.javaFloatObjectInspector;
    udf.initialize(new ObjectInspector[] {featureOI, weightOI});

    Text ret = udf.evaluate(new GenericUDF.DeferredObject[] {new DeferredJavaObject(1),
            new DeferredJavaObject(2.5f)});

    Assert.assertEquals("1:2.5", ret.toString());
}
 
Example 27
Source Project: incubator-hivemall   Source File: FeatureUDFTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testIntDouble() throws Exception {
    ObjectInspector featureOI = PrimitiveObjectInspectorFactory.javaIntObjectInspector;
    ObjectInspector weightOI = PrimitiveObjectInspectorFactory.javaDoubleObjectInspector;
    udf.initialize(new ObjectInspector[] {featureOI, weightOI});

    Text ret = udf.evaluate(new GenericUDF.DeferredObject[] {new DeferredJavaObject(1),
            new DeferredJavaObject(2.5d)});

    Assert.assertEquals("1:2.5", ret.toString());
}
 
Example 28
Source Project: incubator-hivemall   Source File: FeatureUDFTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testLongInt() throws Exception {
    ObjectInspector featureOI = PrimitiveObjectInspectorFactory.javaLongObjectInspector;
    ObjectInspector weightOI = PrimitiveObjectInspectorFactory.javaIntObjectInspector;
    udf.initialize(new ObjectInspector[] {featureOI, weightOI});

    Text ret = udf.evaluate(new GenericUDF.DeferredObject[] {new DeferredJavaObject(1L),
            new DeferredJavaObject(2)});

    Assert.assertEquals("1:2", ret.toString());
}
 
Example 29
Source Project: incubator-hivemall   Source File: FeatureUDFTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testLongLong() throws Exception {
    ObjectInspector featureOI = PrimitiveObjectInspectorFactory.javaLongObjectInspector;
    ObjectInspector weightOI = PrimitiveObjectInspectorFactory.javaLongObjectInspector;
    udf.initialize(new ObjectInspector[] {featureOI, weightOI});

    Text ret = udf.evaluate(new GenericUDF.DeferredObject[] {new DeferredJavaObject(1L),
            new DeferredJavaObject(2L)});

    Assert.assertEquals("1:2", ret.toString());
}
 
Example 30
Source Project: incubator-hivemall   Source File: FeatureUDFTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testLongFloat() throws Exception {
    ObjectInspector featureOI = PrimitiveObjectInspectorFactory.javaLongObjectInspector;
    ObjectInspector weightOI = PrimitiveObjectInspectorFactory.javaFloatObjectInspector;
    udf.initialize(new ObjectInspector[] {featureOI, weightOI});

    Text ret = udf.evaluate(new GenericUDF.DeferredObject[] {new DeferredJavaObject(1L),
            new DeferredJavaObject(2.5f)});

    Assert.assertEquals("1:2.5", ret.toString());
}