Package org.apache.pig.backend.executionengine

Examples of org.apache.pig.backend.executionengine.ExecJob


      Schema dumpedASchema = server.dumpSchema("A");
      server.registerQuery("STORE A into '"+tablename+"' using org.apache.hcatalog.pig.HCatStorer("
          + (provideSchemaToStorer ? "'', '"+pigSchema+"'" : "")
          + ");");
     
      ExecJob execJob = server.executeBatch().get(0);
      if (!execJob.getStatistics().isSuccessful()) {
        throw new RuntimeException("Import failed", execJob.getException());
      }
      // test that schema was loaded correctly
      server.registerQuery("X = load '"+tablename+"' using org.apache.hcatalog.pig.HCatLoader();");
      server.dumpSchema("X");
      Iterator<Tuple> it = server.openIterator("X");
View Full Code Here


     * @return iterator of tuples returned from the script
     * @throws IOException
     */
    public Iterator<Tuple> openIterator(String id) throws IOException {
        try {
            ExecJob job = store(id, FileLocalizer.getTemporaryPath(pigContext)
                    .toString(), Utils.getTmpFileCompressorName(pigContext)
                    + "()");

            // invocation of "execute" is synchronous!

            if (job.getStatus() == JOB_STATUS.COMPLETED) {
                return job.getResults();
            } else if (job.getStatus() == JOB_STATUS.FAILED
                    && job.getException() != null) {
                // throw the backend exception in the failed case
                Exception e = job.getException();
                int errCode = 1066;
                String msg = "Unable to open iterator for alias " + id
                        + ". Backend error : " + e.getMessage();
                throw new FrontendException(msg, errCode, PigException.INPUT, e);
            } else {
                throw new IOException("Job terminated with anomalous status "
                        + job.getStatus().toString());
            }
        } catch (FrontendException e) {
            throw e;
        } catch (Exception e) {
            int errCode = 1066;
View Full Code Here

        pigServer.registerQuery(
                "A = LOAD '" + input.getAbsolutePath() + "' using PigStorage();\n"
            +    "B = GROUP A BY $0;\n"
            +   "A = FOREACH B GENERATE COUNT(A);\n"
            "STORE A INTO '" + output.getAbsolutePath() + "';");
        ExecJob job = pigServer.executeBatch().get(0);
        List<OriginalLocation> originalLocations = job.getPOStore().getOriginalLocations();
        Assert.assertEquals(1, originalLocations.size());
        OriginalLocation originalLocation = originalLocations.get(0);
        Assert.assertEquals(4, originalLocation.getLine());
        Assert.assertEquals(0, originalLocation.getOffset());
        Assert.assertEquals("A", originalLocation.getAlias());
        JobStats jStats = (JobStats)job.getStatistics().getJobGraph().getSinks().get(0);
        Assert.assertEquals("M: A[1,4],A[3,4],B[2,4] C: A[3,4],B[2,4] R: A[3,4]", jStats.getAliasLocation());
    }
View Full Code Here

    String dbStore = "org.apache.pig.piggybank.storage.DBStorage('" + driver                                                                                                                      
              + "', '" + url + "', '" + insertQuery + "');";
    pigServer.registerQuery("A = LOAD '" + INPUT_FILE
        + "' as (id:int, fruit:chararray, ratio:double, dt : datetime);");
    pigServer.registerQuery("STORE A INTO 'dummy' USING " + dbStore);
    ExecJob job = pigServer.executeBatch().get(0);
    try {
      while(!job.hasCompleted()) Thread.sleep(1000);
    } catch(InterruptedException ie) {// ignore
    }
   
    assertNotSame("Failed: " + job.getException(), job.getStatus(),
            ExecJob.JOB_STATUS.FAILED);
   
    Connection con = null;
    String selectQuery = "select id, name, ratio, dt from ttt order by name";
    try {
View Full Code Here

            outputFile = File.createTempFile(fileName, ".out");
            String filePath = outputFile.getAbsolutePath();
            outputFile.delete();
            PigServer pig = new PigServer(ExecType.LOCAL);
            pig.registerQuery("A = load 'test/org/apache/pig/test/data/passwd';");
            ExecJob job = pig.store("A", filePath);
            PigStats stats = job.getStatistics();
            File dataFile = new File( outputFile.getAbsoluteFile() + File.separator + "part-00000" );
            assertEquals(dataFile.length(), stats.getBytesWritten());
        } catch (IOException e) {
            LOG.error("Error while generating file", e);
            fail("Encountered IOException");
View Full Code Here

            pigServer.registerQuery("a = load 'test/org/apache/pig/test/data/passwd';");
            pigServer.registerQuery("b = group a by $0;");
            pigServer.registerQuery("c = foreach b generate group, COUNT(a) as cnt;");
            pigServer.registerQuery("d = group c by cnt;");
            pigServer.registerQuery("e = foreach d generate group;");
            ExecJob job = pigServer.store("e", filePath);
            JobGraph jobGraph = job.getStatistics().getJobGraph();
            assertEquals(2, jobGraph.getJobList().size());

        } catch (IOException e) {
            LOG.error("IOException while creating file ", e);
            fail("Encountered IOException");
View Full Code Here

            }

            if (currDAG.isBatchOn()) {
                currDAG.execute();
            }
            ExecJob job = store(id, FileLocalizer.getTemporaryPath(null, pigContext).toString(), BinStorage.class.getName() + "()");
           
            // invocation of "execute" is synchronous!

            if (job.getStatus() == JOB_STATUS.COMPLETED) {
                return job.getResults();
            } else if (job.getStatus() == JOB_STATUS.FAILED
                       && job.getException() != null) {
                // throw the backend exception in the failed case
                throw job.getException();
            } else {
                throw new IOException("Job terminated with anomalous status "
                    + job.getStatus().toString());
            }
        } catch (Exception e) {
            int errCode = 1066;
            String msg = "Unable to open iterator for alias " + id;
            throw new FrontendException(msg, errCode, PigException.INPUT, e);
View Full Code Here

      Schema dumpedASchema = server.dumpSchema("A");
      server.registerQuery("STORE A into '" + tablename + "' using org.apache.hive.hcatalog.pig.HCatStorer("
        + (provideSchemaToStorer ? "'', '" + pigSchema + "'" : "")
        + ");");

      ExecJob execJob = server.executeBatch().get(0);
      if (!execJob.getStatistics().isSuccessful()) {
        throw new RuntimeException("Import failed", execJob.getException());
      }
      // test that schema was loaded correctly
      server.registerQuery("X = load '" + tablename + "' using org.apache.hive.hcatalog.pig.HCatLoader();");
      server.dumpSchema("X");
      Iterator<Tuple> it = server.openIterator("X");
View Full Code Here

      Schema dumpedASchema = server.dumpSchema("A");
      server.registerQuery("STORE A into '" + tablename + "' using org.apache.hcatalog.pig.HCatStorer("
        + (provideSchemaToStorer ? "'', '" + pigSchema + "'" : "")
        + ");");

      ExecJob execJob = server.executeBatch().get(0);
      if (!execJob.getStatistics().isSuccessful()) {
        throw new RuntimeException("Import failed", execJob.getException());
      }
      // test that schema was loaded correctly
      server.registerQuery("X = load '" + tablename + "' using org.apache.hcatalog.pig.HCatLoader();");
      server.dumpSchema("X");
      Iterator<Tuple> it = server.openIterator("X");
View Full Code Here

            pigServer.registerQuery("A = load 'table_testCrossAfterGroupAll' as (a0:int, a1:chararray);");
            pigServer.registerQuery("B = group A all;");
            pigServer.registerQuery("C = foreach B generate COUNT(A);");
            pigServer.registerQuery("D = cross A, C;");
            Path output = FileLocalizer.getTemporaryPath(pigServer.getPigContext());
            ExecJob job = pigServer.store("D", output.toString());
            FileSystem fs = output.getFileSystem(cluster.getConfiguration());
            FileStatus[] partFiles = fs.listStatus(output, new PathFilter() {
                @Override
                public boolean accept(Path path) {
                    if (path.getName().startsWith("part")) {
                        return true;
                    }
                    return false;
                }
            });
            // auto-parallelism is 2 in MR, 20 in Tez, so check >=2
            Assert.assertTrue(partFiles.length >= 2);
            // Check the output
            Iterator<Tuple> iter = job.getResults();
            List<Tuple> results = new ArrayList<Tuple>();
            while (iter.hasNext()) {
                results.add(iter.next());
            }
            Collections.sort(results);
View Full Code Here

TOP

Related Classes of org.apache.pig.backend.executionengine.ExecJob

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.