<commit_before>package datafu.test.pig.util;

import java.util.List;

import org.adrianwalker.multilinestring.Multiline;
import org.apache.pig.data.DataBag;
import org.apache.pig.data.Tuple;
import org.apache.pig.pigunit.PigTest;
import org.testng.Assert;
import org.testng.annotations.Test;

import datafu.test.pig.PigTests;

public class TransposeTest extends PigTests
{
  /**
  register $JAR_PATH

  define Transpose datafu.pig.util.Transpose();
  
  data = LOAD 'input' using PigStorage(',') AS (testcase:INT,val1:INT,val2:INT,val3:INT);
  
  data2 = FOREACH data GENERATE testcase, Transpose(val1 .. val3) as transposed;
  
  describe data2;
  
  data3 = FOREACH data2 GENERATE testcase, transposed;
  
  STORE data3 INTO 'output';
  */
  @Multiline private static String transposeTest;
  
  @Test
  public void transposeTest() throws Exception
  { 
    PigTest test = createPigTestFromString(transposeTest);
    writeLinesToFile("input", "1,10,11,12",
                              "2,20,21,22");
    test.runScript();
    
    List<Tuple> output = getLinesForAlias(test, "data3");
    for (Tuple tuple : output) {
      int testCase = (Integer)tuple.get(0);
      DataBag bag = (DataBag)tuple.get(1);
      Assert.assertEquals(bag.size(), 3);
      int i=0;
      for (Tuple t : bag) {
        String expectedKey = String.format("val%d",i+1);
        Assert.assertEquals((String)t.get(0), expectedKey);
        int actualValue = (Integer)t.get(1); 
        Assert.assertEquals(actualValue, testCase*10+i);
        i++;
      }
    }
  }
  
  /**
  register $JAR_PATH

  define Transpose datafu.pig.util.Transpose();
  
  data = LOAD 'input' using PigStorage(',') AS (testcase:INT,val1:INT,val2:INT,val3:DOUBLE);
  
  data2 = FOREACH data GENERATE testcase, Transpose(val1 .. val3) as transposed;
  
  describe data2;
  
  data3 = FOREACH data2 GENERATE testcase, transposed;
  
  STORE data3 INTO 'output';
  */
  @Multiline private static String transposeBadTypeTest;
  
  @Test(expectedExceptions={RuntimeException.class})
  public void transposeBadTypeTest() throws Exception
  { 
    PigTest test = createPigTestFromString(transposeBadTypeTest);
    writeLinesToFile("input", "1,10,11,12.0",
                              "2,20,21,22.0");
    test.runScript();
    
    List<Tuple> output = getLinesForAlias(test, "data3");
    for (Tuple tuple : output) {
      int testCase = (Integer)tuple.get(0);
      DataBag bag = (DataBag)tuple.get(1);
      Assert.assertEquals(bag.size(), 3);
      int i=0;
      for (Tuple t : bag) {
        String expectedKey = String.format("val%d",i+1);
        Assert.assertEquals((String)t.get(0), expectedKey);
        int actualValue = (Integer)t.get(1); 
        Assert.assertEquals(actualValue, testCase*10+i);
        i++;<commit_msg>fix exception class to frontend<commit_after>package datafu.test.pig.util;

import java.util.List;

import org.adrianwalker.multilinestring.Multiline;
import org.apache.pig.data.DataBag;
import org.apache.pig.data.Tuple;
import org.apache.pig.pigunit.PigTest;
import org.testng.Assert;
import org.testng.annotations.Test;

import datafu.test.pig.PigTests;

public class TransposeTest extends PigTests
{
  /**
  register $JAR_PATH

  define Transpose datafu.pig.util.Transpose();
  
  data = LOAD 'input' using PigStorage(',') AS (testcase:INT,val1:INT,val2:INT,val3:INT);
  
  data2 = FOREACH data GENERATE testcase, Transpose(val1 .. val3) as transposed;
  
  describe data2;
  
  data3 = FOREACH data2 GENERATE testcase, transposed;
  
  STORE data3 INTO 'output';
  */
  @Multiline private static String transposeTest;
  
  @Test
  public void transposeTest() throws Exception
  { 
    PigTest test = createPigTestFromString(transposeTest);
    writeLinesToFile("input", "1,10,11,12",
                              "2,20,21,22");
    test.runScript();
    
    List<Tuple> output = getLinesForAlias(test, "data3");
    for (Tuple tuple : output) {
      int testCase = (Integer)tuple.get(0);
      DataBag bag = (DataBag)tuple.get(1);
      Assert.assertEquals(bag.size(), 3);
      int i=0;
      for (Tuple t : bag) {
        String expectedKey = String.format("val%d",i+1);
        Assert.assertEquals((String)t.get(0), expectedKey);
        int actualValue = (Integer)t.get(1); 
        Assert.assertEquals(actualValue, testCase*10+i);
        i++;
      }
    }
  }
  
  /**
  register $JAR_PATH

  define Transpose datafu.pig.util.Transpose();
  
  data = LOAD 'input' using PigStorage(',') AS (testcase:INT,val1:INT,val2:INT,val3:DOUBLE);
  
  data2 = FOREACH data GENERATE testcase, Transpose(val1 .. val3) as transposed;
  
  describe data2;
  
  data3 = FOREACH data2 GENERATE testcase, transposed;
  
  STORE data3 INTO 'output';
  */
  @Multiline private static String transposeBadTypeTest;
  
  @Test(expectedExceptions={org.apache.pig.impl.logicalLayer.FrontendException.class})
  public void transposeBadTypeTest() throws Exception
  { 
    PigTest test = createPigTestFromString(transposeBadTypeTest);
    writeLinesToFile("input", "1,10,11,12.0",
                              "2,20,21,22.0");
    test.runScript();
    
    List<Tuple> output = getLinesForAlias(test, "data3");
    for (Tuple tuple : output) {
      int testCase = (Integer)tuple.get(0);
      DataBag bag = (DataBag)tuple.get(1);
      Assert.assertEquals(bag.size(), 3);
      int i=0;
      for (Tuple t : bag) {
        String expectedKey = String.format("val%d",i+1);
        Assert.assertEquals((String)t.get(0), expectedKey);
        int actualValue = (Integer)t.get(1); 
        Assert.assertEquals(actualValue, testCase*10+i);
        i++;
{'fraction_non_alphanumeric': 0.1282918149466192, 'fraction_numerical': 0.02491103202846975, 'mean_word_length': 3.2518910741301057, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2134097', 'n_tokens_mistral': 1970, 'n_tokens_neox': 1891, 'n_words': 385}