Пример #1
0
 @BeforeClass
 public static void setUpBeforeClass() throws Exception {
   cluster = MiniCluster.buildCluster();
   pc = new PigContext(ExecType.LOCAL, new Properties());
   pcMR = new PigContext(ExecType.MAPREDUCE, cluster.getProperties());
   pc.connect();
 }
Пример #2
0
  private void checkParsedConstContent(
      PigServer pigServer, PigContext pigContext, String query, String expectedContent)
      throws Exception {
    pigContext.connect();
    LogicalPlan lp = Util.buildLp(pigServer, query + "store B into 'output';");
    // Digging down the tree
    Operator load = lp.getSources().get(0);
    Operator filter = lp.getSuccessors(load).get(0);
    LogicalExpressionPlan comparisonPlan = ((LOFilter) filter).getFilterPlan();
    List<Operator> comparisonPlanRoots = comparisonPlan.getSinks();
    Operator compRootOne = comparisonPlanRoots.get(0);
    Operator compRootTwo = comparisonPlanRoots.get(1);

    // Here is the actual check logic
    if (compRootOne instanceof ConstantExpression) {
      assertTrue(
          "Must be equal",
          ((String) ((ConstantExpression) compRootOne).getValue()).equals(expectedContent));
    }
    // If not left, it must be right.
    else {
      assertTrue(
          "Must be equal",
          ((String) ((ConstantExpression) compRootTwo).getValue()).equals(expectedContent));
    }
  }
Пример #3
0
 {
   try {
     pigContext.connect();
   } catch (ExecException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Пример #4
0
 static {
   pc = new PigContext();
   try {
     pc.connect();
   } catch (ExecException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   r = new Random(SEED);
 }
Пример #5
0
 public static void oneTimeSetUp() throws Exception {
   cluster = MiniGenericCluster.buildCluster();
   pc = new PigContext(cluster.getExecType(), cluster.getProperties());
   try {
     pc.connect();
   } catch (ExecException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   GenPhyOp.setPc(pc);
   Util.copyFromLocalToCluster(cluster, "test/org/apache/pig/test/data/passwd", "/passwd");
 }
Пример #6
0
  @Test
  public void testParserWithEscapeCharacters() throws Exception {

    // All the needed variables
    PigContext pigContext = new PigContext(ExecType.LOCAL, new Properties());
    PigServer pigServer = new PigServer(pigContext);
    pigContext.connect();

    String tempFile = this.prepareTempFile();

    String query = String.format("A = LOAD '%s' ;", Util.encodeEscape(tempFile));
    // Start the real parsing job
    {
      // Initial statement
      Util.buildLp(pigServer, query);
    }

    {
      // Normal condition
      String q = query + "B = filter A by $0 eq 'This is a test string' ;";
      checkParsedConstContent(pigServer, pigContext, q, "This is a test string");
    }

    {
      // single-quote condition
      String q = query + "B = filter A by $0 eq 'This is a test \\'string' ;";
      checkParsedConstContent(pigServer, pigContext, q, "This is a test 'string");
    }

    {
      // escaping dot
      // the reason we have 4 backslashes below is we really want to put two backslashes but
      // since this is to be represented in a Java String, we escape each backslash with one more
      // backslash - hence 4. In a pig script in a file, this would be
      // \\.string
      String q = query + "B = filter A by $0 eq 'This is a test \\\\.string' ;";
      checkParsedConstContent(pigServer, pigContext, q, "This is a test \\.string");
    }

    {
      // newline condition
      String q = query + "B = filter A by $0 eq 'This is a test \\nstring' ;";
      checkParsedConstContent(pigServer, pigContext, q, "This is a test \nstring");
    }

    {
      // Unicode
      String q = query + "B = filter A by $0 eq 'This is a test \\uD30C\\uC774string' ;";
      checkParsedConstContent(pigServer, pigContext, q, "This is a test \uD30C\uC774string");
    }
  }