Package cascading.tuple.hadoop.collect

Examples of cascading.tuple.hadoop.collect.HadoopSpillableTupleList


    Configuration jobConf = new Configuration();

    jobConf.set( "io.serializations", TestSerialization.class.getName() + "," + WritableSerialization.class.getName() ); // disable/replace WritableSerialization class
    jobConf.set( "cascading.serialization.tokens", "1000=" + BooleanWritable.class.getName() + ",10001=" + Text.class.getName() ); // not using Text, just testing parsing

    HadoopSpillableTupleList list = new HadoopSpillableTupleList( threshold, codec, jobConf );

    for( int i = 0; i < size; i++ )
      {
      String aString = "string number " + i;
      double random = Math.random();

      list.add( new Tuple( i, aString, random, new Text( aString ), new TestText( aString ), new Tuple( "inner tuple", new BytesWritable( aString.getBytes() ) ) ) );
      }

    assertEquals( "not equal: list.size();", size, list.size() );

    assertEquals( "not equal: list.getNumFiles()", spills, list.spillCount() );

    int i = -1;
    int count = 0;
    for( Tuple tuple : list )
      {
      int value = tuple.getInteger( 0 );
      assertTrue( "wrong diff", value - i == 1 );
      assertEquals( "wrong value", "string number " + count, tuple.getObject( 3 ).toString() );
      assertEquals( "wrong value", "string number " + count, tuple.getObject( 4 ).toString() );
      assertTrue( "wrong type", tuple.getObject( 5 ) instanceof Tuple );

      BytesWritable bytesWritable = (BytesWritable) ( (Tuple) tuple.getObject( 5 ) ).getObject( 1 );
      byte[] bytes = bytesWritable.getBytes();
      String actual = new String( bytes, 0, bytesWritable.getLength() );

      assertEquals( "wrong value", "string number " + count, actual );

      i = value;
      count++;
      }

    assertEquals( "not equal: list.size();", size, count );

    Iterator<Tuple> iterator = list.iterator();

    assertEquals( "not equal: iterator.next().get(1)", "string number 0", iterator.next().getObject( 1 ) );
    assertEquals( "not equal: iterator.next().get(1)", "string number 1", iterator.next().getObject( 1 ) );
    }
View Full Code Here

TOP

Related Classes of cascading.tuple.hadoop.collect.HadoopSpillableTupleList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.