Examples of PigTest


Examples of org.apache.pig.pigunit.PigTest

  }
 
  @Test
  public void markovPairMultipleInput() throws Exception
  {   
    PigTest test = createPigTest("datafu/stats/markovPairDefault.pig",
                                 "schema=(data: bag {t: tuple(val1:int,val2:int)})");
   
    writeLinesToFile("input", "{(10,100),(20,200),(30,300),(40,400),(50,500),(60,600)}");
   
    String[] expectedOutput = {
        "({((10,100),(20,200)),((20,200),(30,300)),((30,300),(40,400)),((40,400),(50,500)),((50,500),(60,600))})"
      };   
   
   
    test.runScript();
   
    Iterator<Tuple> actualOutput = test.getAlias("data_out");
   
    assertTuplesMatch(expectedOutput, actualOutput);
  }
View Full Code Here

Examples of org.apache.pig.pigunit.PigTest

  }
 
  @Test
  public void markovPairLookaheadTest() throws Exception
  {
    PigTest test = createPigTest("datafu/stats/markovPairLookahead.pig",
                                 "schema=(data: bag {t: tuple(val:int)})",
                                 "lookahead=3");
   
    writeLinesToFile("input", "{(10),(20),(30),(40),(50)}");
   
    String[] expectedOutput = {
        "({((10),(20)),((10),(30)),((10),(40)),((20),(30)),((20),(40)),((20),(50)),((30),(40)),((30),(50)),((40),(50))})"
      };
   
    test.runScript();
   
    Iterator<Tuple> actualOutput = test.getAlias("data_out");
   
    assertTuplesMatch(expectedOutput, actualOutput);
  }
View Full Code Here

Examples of org.apache.pig.pigunit.PigTest

public class PageRankTests extends PigTests
{
  @Test
  public void pigPageRankTest() throws Exception
  {
    PigTest test = createPigTest("datafu/linkanalysis/pageRankTest.pig");

    String[] edges = PageRankTest.getWikiExampleEdges();

    Map<String,Integer> nodeIds = new HashMap<String,Integer>();
    Map<Integer,String> nodeIdsReversed = new HashMap<Integer,String>();
    Map<String,Float> expectedRanks = PageRankTest.parseExpectedRanks(PageRankTest.getWikiExampleExpectedRanks());

    File f = new File(System.getProperty("user.dir"), "input").getAbsoluteFile();
    if (f.exists())
    {
      f.delete();
    }

    FileWriter writer = new FileWriter(f);
    BufferedWriter bufferedWriter = new BufferedWriter(writer);

    for (String edge : edges)
    {
      String[] edgeParts = edge.split(" ");
      String source = edgeParts[0];
      String dest = edgeParts[1];
      if (!nodeIds.containsKey(source))
      {
        int id = nodeIds.size();
        nodeIds.put(source,id);
        nodeIdsReversed.put(id, source);
      }
      if (!nodeIds.containsKey(dest))
      {
        int id = nodeIds.size();
        nodeIds.put(dest,id);
        nodeIdsReversed.put(id, dest);
      }
      Integer sourceId = nodeIds.get(source);
      Integer destId = nodeIds.get(dest);

      StringBuffer sb = new StringBuffer();

      sb.append("1\t"); // topic
      sb.append(sourceId.toString() + "\t");
      sb.append(destId.toString() + "\t");
      sb.append("1.0\n"); // weight

      bufferedWriter.write(sb.toString());
    }

    bufferedWriter.close();

    test.runScript();
    Iterator<Tuple> tuples = test.getAlias("data_grouped3");

    System.out.println("Final node ranks:");
    int nodeCount = 0;
    while (tuples.hasNext())
    {
View Full Code Here

Examples of org.apache.pig.pigunit.PigTest

public class TimeTests extends PigTests
  @Test
  public void timeCountPageViewsTest() throws Exception
  {
    PigTest test = createPigTest("datafu/date/timeCountPageViewsTest.pig",
                                 "TIME_WINDOW=30m",
                                 "JAR_PATH=" + getJarPath());
       
    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);
  }
View Full Code Here

Examples of org.apache.pig.pigunit.PigTest

   * @throws Exception
   */
  @Test
  public void randomIntRangeTest() throws Exception
  {
    PigTest test = createPigTest("datafu/numbers/randomIntRangeTest.pig",
                                 "MIN=1", "MAX=10");
       
    List<String> input = new ArrayList<String>();
    for (int i=0; i<100; i++)
    {
      input.add(String.format("(%d)", i));
    }
   
    writeLinesToFile("input",
                     input.toArray(new String[0]));
           
    test.runScript();
       
    List<Tuple> tuples = getLinesForAlias(test, "data2", false);
    for (Tuple tuple : tuples)
    {
      Integer randValue = (Integer)tuple.get(1);
View Full Code Here

Examples of org.apache.pig.pigunit.PigTest

public class HashTests  extends PigTests
{
  @Test
  public void md5Test() throws Exception
  {
    PigTest test = createPigTest("datafu/hash/md5Test.pig");
   
    writeLinesToFile("input",
                     "ladsljkasdglk",
                     "lkadsljasgjskdjks",
                     "aladlasdgjks");
           
    test.runScript();
       
    assertOutput(test, "data_out",
                 "(d9a82575758bb4978949dc0659205cc6)",
                 "(9ec37f02fae0d8d6a7f4453a62272f1f)",
                 "(cb94139a8b9f3243e68a898ec6bd9b3d)");
View Full Code Here

Examples of org.apache.pig.pigunit.PigTest

  }
 
  @Test
  public void md5Base64Test() throws Exception
  {
    PigTest test = createPigTest("datafu/hash/md5Base64Test.pig");
   
    writeLinesToFile("input",
                     "ladsljkasdglk",
                     "lkadsljasgjskdjks",
                     "aladlasdgjks");
           
    test.runScript();
       
    assertOutput(test, "data_out",
                 "(2agldXWLtJeJSdwGWSBcxg==)",
                 "(nsN/Avrg2Nan9EU6YicvHw==)",
                 "(y5QTmoufMkPmiomOxr2bPQ==)");
View Full Code Here

Examples of org.apache.pig.pigunit.PigTest

{
 
  @Test
  public void userAgentTest() throws Exception
  {
    PigTest test = createPigTest("datafu/urls/userAgentTest.pig");
 
    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);
  }
View Full Code Here

Examples of org.apache.pig.pigunit.PigTest

public class BagTests extends PigTests
{
  @Test
  public void nullToEmptyBagTest() throws Exception
  {
    PigTest test = createPigTest("datafu/bags/nullToEmptyBagTest.pig");
           
    writeLinesToFile("input",
                     "({(1),(2),(3),(4),(5)})",
                     "()",
                     "{(4),(5)})");
           
    test.runScript();
       
    assertOutput(test, "data2",
                 "({(1),(2),(3),(4),(5)})",
                 "({})",
                 "({(4),(5)})");
View Full Code Here

Examples of org.apache.pig.pigunit.PigTest

  }
 
  @Test
  public void appendToBagTest() throws Exception
  {
    PigTest test = createPigTest("datafu/bags/appendToBagTest.pig");
   
    writeLinesToFile("input",
                     "1\t{(1),(2),(3)}\t(4)",
                     "2\t{(10),(20),(30),(40),(50)}\t(60)");
                 
    test.runScript();
           
    assertOutput(test, "data2",
                 "(1,{(1),(2),(3),(4)})",
                 "(2,{(10),(20),(30),(40),(50),(60)})");
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.