Package org.apache.pig.builtin.mock.Storage

Examples of org.apache.pig.builtin.mock.Storage.Data


    // See: https://issues.apache.org/jira/browse/PIG-3093
    @Test
    public void testIndirectSelfJoinRealias() throws Exception {
        setUp(ExecType.LOCAL);
        Data data = resetData(pigServer);

        Set<Tuple> tuples = Sets.newHashSet(tuple("a"), tuple("b"), tuple("c"));
        data.set("foo", Utils.getSchemaFromString("field1:chararray"), tuples);
        pigServer.registerQuery("A = load 'foo' using mock.Storage();");
        pigServer.registerQuery("B = foreach A generate *;");
        pigServer.registerQuery("C = join A by field1, B by field1;");
        assertEquals(Utils.getSchemaFromString("A::field1:chararray, B::field1:chararray"), pigServer.dumpSchema("C"));
        pigServer.registerQuery("D = foreach C generate B::field1, A::field1 as field2;");
        assertEquals(Utils.getSchemaFromString("B::field1:chararray, field2:chararray"), pigServer.dumpSchema("D"));
        pigServer.registerQuery("E = foreach D generate field1, field2;");
        assertEquals(Utils.getSchemaFromString("B::field1:chararray, field2:chararray"), pigServer.dumpSchema("E"));
        pigServer.registerQuery("F = foreach E generate field2;");
        pigServer.registerQuery("store F into 'foo_out' using mock.Storage();");
        List<Tuple> out = data.get("foo_out");
        assertEquals("Expected size was "+tuples.size()+" but was "+out.size(), tuples.size(), out.size());
        for (Tuple t : out) {
            assertTrue("Should have found tuple "+t+" in expected: "+tuples, tuples.remove(t));
        }
        assertTrue("All expected tuples should have been found, remaining: "+tuples, tuples.isEmpty());
View Full Code Here


    }

    @Test
    public void testIndirectSelfJoinData() throws Exception {
        setUp(ExecType.LOCAL);
        Data data = resetData(pigServer);

        Set<Tuple> tuples = Sets.newHashSet(tuple("a", 1), tuple("b", 2), tuple("c", 3));
        data.set("foo", Utils.getSchemaFromString("field1:chararray,field2:int"), tuples);
        pigServer.registerQuery("A = load 'foo' using mock.Storage();");
        pigServer.registerQuery("B = foreach A generate field1, field2*2 as field2;");
        pigServer.registerQuery("C = join A by field1, B by field1;");
        pigServer.registerQuery("D = foreach C generate A::field1 as field1_a, B::field1 as field1_b, A::field2 as field2_a, B::field2 as field2_b;");
        pigServer.registerQuery("store D into 'foo_out' using mock.Storage();");

        Set<Tuple> expected = Sets.newHashSet(tuple("a", "a", 1, 2), tuple("b", "b", 2, 4), tuple("c", "c", 3, 6));
        List<Tuple> out = data.get("foo_out");
        assertEquals("Expected size was "+expected.size()+" but was "+out.size(), expected.size(), out.size());
        for (Tuple t : out) {
            assertTrue("Should have found tuple "+t+" in expected: "+expected, expected.remove(t));
        }
        assertTrue("All expected tuples should have been found, remaining: "+expected, expected.isEmpty());
View Full Code Here

   * @throws Exception
   */
  @Test
  public void testPositive() throws Exception {
      PigServer pigServer = new PigServer(ExecType.LOCAL);
      Data data = resetData(pigServer);

      data.set("foo",
              tuple(1),
              tuple(2),
              tuple(3)
              );

      pigServer.setBatchOn();
      pigServer.registerQuery("A = LOAD 'foo' USING mock.Storage() AS (i:int);");
      pigServer.registerQuery("ASSERT A BY i > 0;");
      pigServer.registerQuery("STORE A INTO 'bar' USING mock.Storage();");

      pigServer.executeBatch();

      List<Tuple> out = data.get("bar");
      assertEquals(3, out.size());
      assertEquals(tuple(1), out.get(0));
      assertEquals(tuple(2), out.get(1));
      assertEquals(tuple(3), out.get(2));
  }
View Full Code Here

   * @throws Exception
   */
  @Test
  public void testInScript() throws Exception {
      PigServer pigServer = new PigServer(ExecType.LOCAL);
      Data data = resetData(pigServer);

      data.set("foo",
              tuple(1),
              tuple(2),
              tuple(3)
              );

      StringBuffer query = new StringBuffer();
      query.append("A = LOAD 'foo' USING mock.Storage() AS (i:int);\n");
      query.append("ASSERT A BY i > 0;\n");
      query.append("STORE A INTO 'bar' USING mock.Storage();");

      InputStream is = new ByteArrayInputStream(query.toString().getBytes());
      pigServer.registerScript(is);

      List<Tuple> out = data.get("bar");
      assertEquals(3, out.size());
      assertEquals(tuple(1), out.get(0));
      assertEquals(tuple(2), out.get(1));
      assertEquals(tuple(3), out.get(2));
  }
View Full Code Here

   * @throws Exception
   */
  @Test
  public void testNegative() throws Exception {
      PigServer pigServer = new PigServer(ExecType.LOCAL);
      Data data = resetData(pigServer);

      data.set("foo",
              tuple(1),
              tuple(2),
              tuple(3)
              );

View Full Code Here

   * @throws Exception
   */
  @Test
  public void testNegativeWithoutFetch() throws Exception {
      PigServer pigServer = new PigServer(ExecType.LOCAL);
      Data data = resetData(pigServer);

      data.set("foo",
              tuple(1),
              tuple(2),
              tuple(3)
              );

View Full Code Here

   * @throws Exception
   */
  @Test(expected=FrontendException.class)
  public void testNegativeWithAlias() throws Exception {
      PigServer pigServer = new PigServer(ExecType.LOCAL);
      Data data = resetData(pigServer);

      data.set("foo",
              tuple(1),
              tuple(2),
              tuple(3)
              );
      try {
View Full Code Here

        pig = new PigServer(ExecType.LOCAL);

        Schema s = new Schema();
        s.add(new Schema.FieldSchema(null, DataType.CHARARRAY));
        s.add(new Schema.FieldSchema(null, DataType.CHARARRAY));
        Data data = resetData(pig);
        data.set("foo1", s, genDataSetFile1());

        s = new Schema();
        s.add(new Schema.FieldSchema(null, DataType.CHARARRAY));
        s.add(new Schema.FieldSchema(null, DataType.CHARARRAY));
        data.set("foo2", s, genDataSetFile2());

        s = new Schema();
        s.add(new Schema.FieldSchema(null, DataType.CHARARRAY));
        s.add(new Schema.FieldSchema(null, DataType.CHARARRAY));
        data.set("foo3", s, genDataSetFile3());
    }
View Full Code Here

                "   return one + two"
        };
        Util.createLocalInputFile( "pyfile.py", pythonScript);

       
        Data data = resetData(pigServerLocal);
        Tuple t0 = tf.newTuple(2);
        t0.set(0, "field10");
        t0.set(1, "field11");
        Tuple t1 = tf.newTuple(2);
        t1.set(0, "field20");
        t1.set(1, "field21");
        data.set("testTuples", "c1:chararray,c2:chararray", t0, t1);
       
        pigServerLocal.registerQuery("REGISTER 'pyfile.py' USING streaming_python AS pf;");
        pigServerLocal.registerQuery("A = LOAD 'testTuples' USING mock.Storage();");
        pigServerLocal.registerQuery("B = FOREACH A generate pf.py_func(c1, c2);");
        pigServerLocal.registerQuery("STORE B INTO 'out' USING mock.Storage();");
       
        Tuple expected0 = tf.newTuple("field10field11");
        Tuple expected1 = tf.newTuple("field20field21");
       
        List<Tuple> out = data.get("out");
        assertEquals(expected0, out.get(0));
        assertEquals(expected1, out.get(1));
    }
View Full Code Here

                "   return '%s\\n%s' % (one,two)"
        };
        Util.createLocalInputFile( "pyfileNL.py", pythonScript);

       
        Data data = resetData(pigServerLocal);
        Tuple t0 = tf.newTuple(2);
        t0.set(0, "field10");
        t0.set(1, "field11");
        Tuple t1 = tf.newTuple(2);
        t1.set(0, "field20");
        t1.set(1, "field21");
        data.set("testTuplesNL", "c1:chararray,c2:chararray", t0, t1);
       
        pigServerLocal.registerQuery("REGISTER 'pyfileNL.py' USING streaming_python AS pf;");
        pigServerLocal.registerQuery("A = LOAD 'testTuplesNL' USING mock.Storage();");
        pigServerLocal.registerQuery("B = FOREACH A generate pf.py_func(c1, c2);");
        pigServerLocal.registerQuery("STORE B INTO 'outNL' USING mock.Storage();");
       
        Tuple expected0 = tf.newTuple("field10\nfield11");
        Tuple expected1 = tf.newTuple("field20\nfield21");
       
        List<Tuple> out = data.get("outNL");
        assertEquals(expected0, out.get(0));
        assertEquals(expected1, out.get(1));
    }
View Full Code Here

TOP

Related Classes of org.apache.pig.builtin.mock.Storage.Data

Copyright © 2018 www.massapicom. 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.