Beispiel #1
0
  @Test
  public void testNewNormalNestedMerge2() throws Exception {
    LogicalSchema a =
        org.apache.pig.newplan.logical.Util.translateSchema(
            Utils.getSchemaFromString(
                "a1:(a11:chararray, a12:float), b1:(b11:chararray, b12:float), c1:long"));
    LogicalSchema b =
        org.apache.pig.newplan.logical.Util.translateSchema(
            Utils.getSchemaFromString("a2:bytearray, b2:(b21:double, b22:long), c2:chararray"));

    LogicalSchema mergedSchema = LogicalSchema.merge(a, b, LogicalSchema.MergeMode.Union);
    LogicalSchema expected =
        org.apache.pig.newplan.logical.Util.translateSchema(
            Utils.getSchemaFromString("a1:(a11:chararray, a12:float), b1:(), c1:bytearray"));
    expected.getField(1).schema = new LogicalSchema();
    Assert.assertTrue(LogicalSchema.equals(mergedSchema, expected, false, false));

    mergedSchema = LogicalSchema.merge(a, b, LogicalSchema.MergeMode.LoadForEach);
    expected =
        org.apache.pig.newplan.logical.Util.translateSchema(
            Utils.getSchemaFromString(
                "a1:(a11:chararray, a12:float), b1:(b11:chararray, b12:float), c1:long"));
    Assert.assertTrue(LogicalSchema.equals(mergedSchema, expected, false, false));

    mergedSchema = LogicalSchema.merge(b, a, LogicalSchema.MergeMode.LoadForEach);
    expected =
        org.apache.pig.newplan.logical.Util.translateSchema(
            Utils.getSchemaFromString(
                "a2:(a11:chararray, a12:float), b2:(b21:double, b22:long), c2:chararray"));
    Assert.assertTrue(LogicalSchema.equals(mergedSchema, expected, false, false));
  }
Beispiel #2
0
  @Test
  public void testNewMergeMismatchType2() throws Throwable {
    LogicalSchema a =
        org.apache.pig.newplan.logical.Util.translateSchema(
            Utils.getSchemaFromString("a1:chararray, b1:(b11:double, b12:(b121:int)), c1:long"));
    LogicalSchema b =
        org.apache.pig.newplan.logical.Util.translateSchema(
            Utils.getSchemaFromString("a2:bytearray, b2:(b21:double, b22:long), c2:int"));

    LogicalSchema mergedSchema = LogicalSchema.merge(a, b, LogicalSchema.MergeMode.Union);
    LogicalSchema expected =
        org.apache.pig.newplan.logical.Util.translateSchema(
            Utils.getSchemaFromString("a1:chararray, b1:(), c1:long"));
    expected.getField(1).schema = new LogicalSchema();
    Assert.assertTrue(LogicalSchema.equals(mergedSchema, expected, false, false));

    try {
      LogicalSchema.merge(a, b, LogicalSchema.MergeMode.LoadForEach);
      Assert.fail();
    } catch (FrontendException e) {
      Assert.assertTrue(e.getErrorCode() == 1031);
    }

    try {
      LogicalSchema.merge(b, a, LogicalSchema.MergeMode.LoadForEach);
      Assert.fail();
    } catch (FrontendException e) {
      Assert.assertTrue(e.getErrorCode() == 1031);
    }
  }
Beispiel #3
0
  // See PIG-1434
  @Test
  public void testScalarAliasesJoinClause() throws Exception {
    String[] inputA = {"1\t5", "2\t10", "3\t20"};
    String[] inputB = {"Total3\tthree", "Total2\ttwo", "Total1\tone"};

    // Test the use of scalars in expressions
    String inputPathA = BUILD_TEST_TMP + "table_testScalarAliasesJoinClauseA";
    TestScalarAliases.createLocalInputFile(inputPathA, inputA);
    String inputPathB = BUILD_TEST_TMP + "table_testScalarAliasesJoinClauseB";
    TestScalarAliases.createLocalInputFile(inputPathB, inputB);
    // Test in script mode
    pigServer.registerQuery("A = LOAD '" + inputPathA + "' as (a0, a1);");
    pigServer.registerQuery("G = group A all;");
    pigServer.registerQuery("C = foreach G generate COUNT(A) as count;");

    pigServer.registerQuery("B = LOAD '" + inputPathB + "' as (b0:chararray, b1:chararray);");
    pigServer.registerQuery("Y = join A by CONCAT('Total', (chararray)C.count), B by $0;");

    Iterator<Tuple> iter = pigServer.openIterator("Y");

    String[] expected =
        new String[] {"(1,5,Total3,three)", "(2,10,Total3,three)", "(3,20,Total3,three)"};

    Util.checkQueryOutputsAfterSortRecursive(
        iter,
        expected,
        org.apache.pig.newplan.logical.Util.translateSchema(pigServer.dumpSchema("Y")));
  }
Beispiel #4
0
 @Test
 // See PIG-730
 public void testMergeSchemaWithTwoLevelAccess3() throws Exception {
   // Generate two schemas
   LogicalSchema ls1 = Utils.parseSchema("a:{t:(a0:int, a1:int)}");
   LogicalSchema ls2 = Utils.parseSchema("b:{t:(b0:int, b1:int)}");
   LogicalSchema ls3 = LogicalSchema.merge(ls1, ls2, MergeMode.LoadForEach);
   Assert.assertTrue(
       org.apache.pig.newplan.logical.Util.translateSchema(ls3)
           .toString()
           .equals("{a: {(a0: int,a1: int)}}"));
 }