Ejemplo n.º 1
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")));
  }
 @Test
 public void readWithoutSchemaTestSchema() throws IOException {
   registerLoadQuery(IntWritableConverter.class, TextConverter.class, null);
   Schema schema = pigServer.dumpSchema("A");
   Assert.assertNotNull(schema);
   Assert.assertEquals("key", schema.getField(0).alias);
   Assert.assertEquals(DataType.INTEGER, schema.getField(0).type);
   Assert.assertEquals("value", schema.getField(1).alias);
   Assert.assertEquals(DataType.CHARARRAY, schema.getField(1).type);
 }
 @Test(expected = Exception.class)
 public void writableConverterArguments05() throws IOException {
   registerLoadQuery(VarArgsConstructorIntWritableConverter.class, "");
   pigServer.dumpSchema("A");
 }
 @Test
 public void writableConverterArguments07() throws IOException {
   registerLoadQuery(VarArgsConstructorIntWritableConverter.class, "1 2 3 4 5");
   pigServer.dumpSchema("A");
 }
 @Test
 public void writableConverterArguments04() throws IOException {
   registerLoadQuery(FixedArgsConstructorIntWritableConverter.class, "-- -123 -456");
   pigServer.dumpSchema("A");
 }