Java Code Examples for org.apache.pig.pigunit.PigTest#assertOutput()

The following examples show how to use org.apache.pig.pigunit.PigTest#assertOutput() . 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: TestPigTest.java    From spork with Apache License 2.0 6 votes vote down vote up
@Test
public void testNtoN() throws ParseException, IOException {
    String[] args = {
                    "n=3",
                    "reducers=1",
                    "input=top_queries_input_data.txt",
                    "output=top_3_queries",
    };
    test = new PigTest(PIG_SCRIPT, args);

    String[] output = {
                    "(yahoo,25)",
                    "(facebook,15)",
                    "(twitter,7)",
    };

    test.assertOutput("queries_limit", output);
}
 
Example 2
Source File: TestPigTest.java    From spork with Apache License 2.0 6 votes vote down vote up
@Test
public void testImplicitNtoN() throws ParseException, IOException {
    String[] args = {
                    "n=3",
                    "reducers=1",
                    "input=top_queries_input_data.txt",
                    "output=top_3_queries",
    };
    test = new PigTest(PIG_SCRIPT, args);

    String[] output = {
                    "(yahoo,25)",
                    "(facebook,15)",
                    "(twitter,7)",
    };

    test.assertOutput(output);
}
 
Example 3
Source File: TestPigTest.java    From spork with Apache License 2.0 6 votes vote down vote up
@Test
public void testOverride() throws ParseException, IOException {
    String[] args = {
                    "n=3",
                    "reducers=1",
                    "input=top_queries_input_data.txt",
                    "output=top_3_queries",
    };
    test = new PigTest(PIG_SCRIPT, args);

    test.override("queries_limit", "queries_limit = LIMIT queries_ordered 2;");

    String[] output = {
                    "(yahoo,25)",
                    "(facebook,15)",
    };

    test.assertOutput(output);
}
 
Example 4
Source File: TestPigTest.java    From spork with Apache License 2.0 6 votes vote down vote up
@Test
public void testInlinePigScript() throws ParseException, IOException {
    String[] script = {
                    "data = LOAD 'top_queries_input_data.txt' AS (query:CHARARRAY, count:INT);",
                    "queries_group = GROUP data BY query PARALLEL 1;",
                    "queries_sum = FOREACH queries_group GENERATE group AS query, SUM(data.count) AS count;",
                    "queries_ordered = ORDER queries_sum BY count DESC PARALLEL 1;",
                    "queries_limit = LIMIT queries_ordered 3;",
                    "STORE queries_limit INTO 'top_3_queries';",
    };

    test = new PigTest(script);

    String[] output = {
                    "(yahoo,25)",
                    "(facebook,15)",
                    "(twitter,7)",
    };

    test.assertOutput(output);
}
 
Example 5
Source File: TestPigTest.java    From spork with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithUdf() throws ParseException, IOException {
    String[] script = {
                    // "REGISTER myIfNeeded.jar;",
                    "DEFINE TOKENIZE TOKENIZE();",
                    "data = LOAD 'top_queries_input_data.txt' AS (query:CHARARRAY, count:INT);",
                    "queries = FOREACH data GENERATE query, TOKENIZE(query) AS query_tokens;",
                    "queries_ordered = ORDER queries BY query DESC PARALLEL 1;",
                    "queries_limit = LIMIT queries_ordered 3;",
                    "STORE queries_limit INTO 'top_3_queries';",
    };

    test = new PigTest(script);

    String[] output = {
                    "(yahoo,{(yahoo)})",
                    "(yahoo,{(yahoo)})",
                    "(twitter,{(twitter)})",
    };

    test.assertOutput(output);
}
 
Example 6
Source File: TestPigTest.java    From spork with Apache License 2.0 6 votes vote down vote up
@Ignore("Not ready yet")
@Test
public void testWithMock() throws ParseException, IOException {
    String[] args = {
                    "n=3",
                    "reducers=1",
                    "input=top_queries_input_data.txt",
                    "output=top_3_queries",
    };

    PigServer mockServer = null;
    Cluster mockCluster = null;

    test = new PigTest(PIG_SCRIPT, args, mockServer, mockCluster);

    test.assertOutput(new File("data/top_queries_expected_top_3.txt"));
}
 
Example 7
Source File: BagTests.java    From datafu with Apache License 2.0 6 votes vote down vote up
@Test
public void unorderedPairsTest() throws Exception
{
  PigTest test = createPigTestFromString(unorderedPairsTest);

  String[] input = {
    "{(1),(2),(3),(4),(5)}"
  };

  String[] output = {
      "(1,2)",
      "(1,3)",
      "(1,4)",
      "(1,5)",
      "(2,3)",
      "(2,4)",
      "(2,5)",
      "(3,4)",
      "(3,5)",
      "(4,5)"
    };

  test.assertOutput("data",input,"data4",output);
}
 
Example 8
Source File: IntBoolConversionPigTests.java    From datafu with Apache License 2.0 6 votes vote down vote up
@Test
public void intToBoolTest() throws Exception
{
  PigTest test = createPigTestFromString(intToBoolTest);
      
  String[] input = {
    "", // null
    "0",
    "1"
  };
  
  String[] output = {
      "(false)",
      "(false)",
      "(true)"
    };
  
  test.assertOutput("data",input,"data2",output);
}
 
Example 9
Source File: TestPigTest.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testTextInput() throws ParseException, IOException {
    String[] args = {
                    "n=3",
                    "reducers=1",
                    "input=top_queries_input_data.txt",
                    "output=top_3_queries",
    };
    test = new PigTest(PIG_SCRIPT, args);

    String[] input = {
                    "yahoo\t10",
                    "twitter\t7",
                    "facebook\t10",
                    "yahoo\t15",
                    "facebook\t5",
                    "a\t1",
                    "b\t2",
                    "c\t3",
                    "d\t4",
                    "e\t5",
    };

    String[] output = {
                    "(yahoo,25)",
                    "(facebook,15)",
                    "(twitter,7)",
    };

    test.assertOutput("data", input, "queries_limit", output);
}
 
Example 10
Source File: TestPigTest.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testDelimiter() throws ParseException, IOException {
    String[] args = {
                    "n=3",
                    "reducers=1",
                    "input=top_queries_input_data.txt",
                    "output=top_3_queries",
    };
    test = new PigTest(PIG_SCRIPT, args);

    String[] input = {
                    "yahoo,10",
                    "twitter,7",
                    "facebook,10",
                    "yahoo,15",
                    "facebook,5",
                    "a,1",
                    "b,2",
                    "c,3",
                    "d,4",
                    "e,5",
    };

    String[] output = {
                    "(yahoo,25)",
                    "(facebook,15)",
                    "(twitter,7)",
    };

    test.assertOutput("data", input, "queries_limit", output, ",");
}
 
Example 11
Source File: TestPigTest.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubset() throws ParseException, IOException {
    String[] args = {
                    "n=3",
                    "reducers=1",
                    "input=top_queries_input_data.txt",
                    "output=top_3_queries",
    };
    test = new PigTest(PIG_SCRIPT, args);

    String[] input = {
                    "yahoo\t10",
                    "twitter\t7",
                    "facebook\t10",
                    "yahoo\t15",
                    "facebook\t5",
                    "a\t1",
                    "b\t2",
                    "c\t3",
                    "d\t4",
                    "e\t5",
    };

    String[] output = {
                    "(yahoo,25)",
                    "(facebook,15)",
                    "(twitter,7)",
    };

    test.assertOutput("data", input, "queries_limit", output);
}
 
Example 12
Source File: TestPigTest.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testFileOutput() throws ParseException, IOException {
    String[] args = {
                    "n=3",
                    "reducers=1",
                    "input=top_queries_input_data.txt",
                    "output=top_3_queries",
    };
    test = new PigTest(PIG_SCRIPT, args);

    test.assertOutput(new File("test/data/pigunit/top_queries_expected_top_3.txt"));
}
 
Example 13
Source File: TestPigTest.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testArgFiles() throws ParseException, IOException {
    String[] argsFile = {
                    "test/data/pigunit/top_queries_params.txt"
    };

    test = new PigTest(PIG_SCRIPT, null, argsFile);

    test.assertOutput(new File("test/data/pigunit/top_queries_expected_top_3.txt"));
}
 
Example 14
Source File: SessionTests.java    From datafu with Apache License 2.0 5 votes vote down vote up
@Test
public void sessionCountPageViewsTest() throws Exception
{
  PigTest test = createPigTestFromString(sessionCountPageViewsTest,
                               "TIME_WINDOW=30m");
      
  String[] input = {
    "1\t100\t2010-01-01T01:00:00Z",
    "1\t100\t2010-01-01T01:15:00Z",
    "1\t100\t2010-01-01T01:31:00Z",
    "1\t100\t2010-01-01T01:35:00Z",
    "1\t100\t2010-01-01T02:30:00Z",

    "1\t101\t2010-01-01T01:00:00Z",
    "1\t101\t2010-01-01T01:31:00Z",
    "1\t101\t2010-01-01T02:10:00Z",
    "1\t101\t2010-01-01T02:40:30Z",
    "1\t101\t2010-01-01T03:30:00Z",      

    "1\t102\t2010-01-01T01:00:00Z",
    "1\t102\t2010-01-01T01:01:00Z",
    "1\t102\t2010-01-01T01:02:00Z",
    "1\t102\t2010-01-01T01:10:00Z",
    "1\t102\t2010-01-01T01:15:00Z",
    "1\t102\t2010-01-01T01:25:00Z",
    "1\t102\t2010-01-01T01:30:00Z"
  };
  
  String[] output = {
      "(1,100,2)",
      "(1,101,5)",
      "(1,102,1)"
    };
  
  test.assertOutput("views",input,"view_counts",output);
}
 
Example 15
Source File: IntBoolConversionPigTests.java    From datafu with Apache License 2.0 5 votes vote down vote up
@Test
public void intToBoolToIntTest() throws Exception
{
  PigTest test = createPigTestFromString(intToBoolToIntTest);
      
  String[] input = {
    "", // null
    "0",
    "1",
    "2",
    "-1",
    "-2",
    "0",
    ""
  };
  
  String[] output = {
      "(0)",
      "(0)",
      "(1)",
      "(1)",
      "(1)",
      "(1)",
      "(0)",
      "(0)"
    };
  
  test.assertOutput("data",input,"data3",output);
}
 
Example 16
Source File: UserAgentTest.java    From datafu with Apache License 2.0 5 votes vote down vote up
@Test
public void userAgentTest() throws Exception
{
  PigTest test = createPigTestFromString(userAgentTest);

  String[] input = {
      "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5",
      "Mozilla/5.0 (compatible; Konqueror/3.5; Linux; X11; de) KHTML/3.5.2 (like Gecko) Kubuntu 6.06 Dapper",
      "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.2a1pre) Gecko/20110331 Firefox/4.2a1pre Fennec/4.1a1pre",
      "Opera/9.00 (X11; Linux i686; U; en)",
      "Wget/1.10.2",
      "Opera/9.80 (Android; Linux; Opera Mobi/ADR-1012221546; U; pl) Presto/2.7.60 Version/10.5",
      "Mozilla/5.0 (Linux; U; Android 2.2; en-us; DROID2 Build/VZW) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"
  };
  
  String[] output = {
      "(mobile)",
      "(desktop)",
      "(mobile)",
      "(desktop)",
      "(desktop)",
      "(mobile)",
      "(mobile)",
    };
  
  test.assertOutput("data",input,"data_out",output);
}