Search in sources :

Example 1 with InvokeForString

use of com.twitter.elephantbird.pig.piggybank.InvokeForString in project elephant-bird by twitter.

the class TestInvoker method testArrayConversion.

@Test
public void testArrayConversion() throws SecurityException, ClassNotFoundException, NoSuchMethodException, IOException {
    InvokeForInt id = new InvokeForInt(TestInvoker.class.getName() + ".avg", "double[]");
    DataBag nums = newSimpleBag(1.0, 2.0, 3.0);
    assertEquals(Integer.valueOf(2), id.exec(tf_.newTuple(nums)));
    InvokeForString is = new InvokeForString(TestInvoker.class.getName() + ".concatStringArray", "string[]");
    DataBag strings = newSimpleBag("foo", "bar", "baz");
    assertEquals("foobarbaz", is.exec(tf_.newTuple(strings)));
}
Also used : InvokeForString(com.twitter.elephantbird.pig.piggybank.InvokeForString) DataBag(org.apache.pig.data.DataBag) NonSpillableDataBag(org.apache.pig.data.NonSpillableDataBag) InvokeForInt(com.twitter.elephantbird.pig.piggybank.InvokeForInt) Test(org.junit.Test)

Example 2 with InvokeForString

use of com.twitter.elephantbird.pig.piggybank.InvokeForString in project elephant-bird by twitter.

the class TestInvoker method testStringInvoker.

@Test
public void testStringInvoker() throws SecurityException, ClassNotFoundException, NoSuchMethodException, IOException {
    // Test non-static method
    InvokeForString is = new InvokeForString("java.lang.String.toUpperCase", "String", "false");
    assertEquals("FOO", is.exec(tf_.newTuple("foo")));
    // both "static" and "true" should work
    // Test static method
    is = new InvokeForString("java.lang.String.valueOf", "int", "true");
    Tuple t = tf_.newTuple(1);
    t.set(0, 231);
    assertEquals("231", is.exec(t));
    // test default (should be static)
    is = new InvokeForString("java.lang.String.valueOf", "int");
    assertEquals("231", is.exec(t));
    // Test method with multiple args
    is = new InvokeForString(TestInvoker.class.getName() + ".concatStrings", "String String");
    t = tf_.newTuple(2);
    t.set(0, "foo");
    t.set(1, "bar");
    assertEquals("foobar", is.exec(t));
}
Also used : InvokeForString(com.twitter.elephantbird.pig.piggybank.InvokeForString) Tuple(org.apache.pig.data.Tuple) Test(org.junit.Test)

Aggregations

InvokeForString (com.twitter.elephantbird.pig.piggybank.InvokeForString)2 Test (org.junit.Test)2 InvokeForInt (com.twitter.elephantbird.pig.piggybank.InvokeForInt)1 DataBag (org.apache.pig.data.DataBag)1 NonSpillableDataBag (org.apache.pig.data.NonSpillableDataBag)1 Tuple (org.apache.pig.data.Tuple)1