Example #1
0
  @Test
  public void testRun_setsErrorThrowableForParamSubstitution() {
    File outputFile = null;
    try {
      String filename =
          this.getClass().getSimpleName() + "_" + "testRun_setsErrorThrowableForParamSubstitution";
      outputFile = File.createTempFile(filename, ".out");
      outputFile.delete();

      File scriptFile = File.createTempFile(filename, ".pig");
      BufferedWriter bw = new BufferedWriter(new FileWriter(scriptFile));
      bw.write("a = load '$NOEXIST';\n");
      bw.write("b = group a by $0\n");
      bw.write("c = foreach b generate group, COUNT(a) as cnt;\n");
      bw.write("store c into 'out'\n");
      bw.close();

      Main.run(new String[] {"-x", "local", scriptFile.getAbsolutePath()}, null);
      PigStats stats = PigStats.get();

      Throwable t = stats.getErrorThrowable();
      assertTrue(t instanceof IOException);

      Throwable cause = t.getCause();
      assertTrue(cause instanceof ParameterSubstitutionException);

      ParameterSubstitutionException pse = (ParameterSubstitutionException) cause;
      assertTrue(pse.getMessage().contains("NOEXIST"));
    } catch (Exception e) {
      log.error("Encountered exception", e);
      fail("Encountered Exception");
    }
  }
Example #2
0
  @Test
  public void testRun_setsErrorThrowableOnPigStats() {
    File outputFile = null;
    try {
      String filename =
          this.getClass().getSimpleName() + "_" + "testRun_setsErrorThrowableOnPigStats";
      outputFile = File.createTempFile(filename, ".out");
      outputFile.delete();

      File scriptFile = File.createTempFile(filename, ".pig");
      BufferedWriter bw = new BufferedWriter(new FileWriter(scriptFile));
      bw.write("a = load 'test/org/apache/pig/test/data/passwd';\n");
      bw.write("b = group a by $0\n");
      bw.write("c = foreach b generate group, COUNT(a) as cnt;\n");
      bw.write("store c into 'out'\n");
      bw.close();

      Main.run(new String[] {"-x", "local", scriptFile.getAbsolutePath()}, null);
      PigStats stats = PigStats.get();

      Throwable t = stats.getErrorThrowable();
      assertTrue(t instanceof FrontendException);

      FrontendException fe = (FrontendException) t;
      SourceLocation sl = fe.getSourceLocation();
      assertEquals(2, sl.line());
      assertEquals(15, sl.offset());

      Throwable cause = fe.getCause();
      assertTrue(cause instanceof ParserException);

    } catch (Exception e) {
      log.error("Encountered exception", e);
      fail("Encountered Exception");
    }
  }