Search in sources :

Example 61 with IntWritable

use of org.apache.hadoop.io.IntWritable in project hadoop by apache.

the class TestCombineSequenceFileInputFormat method testFormat.

@Test(timeout = 10000)
public void testFormat() throws Exception {
    JobConf job = new JobConf(conf);
    Reporter reporter = Reporter.NULL;
    Random random = new Random();
    long seed = random.nextLong();
    LOG.info("seed = " + seed);
    random.setSeed(seed);
    localFs.delete(workDir, true);
    FileInputFormat.setInputPaths(job, workDir);
    final int length = 10000;
    final int numFiles = 10;
    // create a file with various lengths
    createFiles(length, numFiles, random);
    // create a combine split for the files
    InputFormat<IntWritable, BytesWritable> format = new CombineSequenceFileInputFormat<IntWritable, BytesWritable>();
    IntWritable key = new IntWritable();
    BytesWritable value = new BytesWritable();
    for (int i = 0; i < 3; i++) {
        int numSplits = random.nextInt(length / (SequenceFile.SYNC_INTERVAL / 20)) + 1;
        LOG.info("splitting: requesting = " + numSplits);
        InputSplit[] splits = format.getSplits(job, numSplits);
        LOG.info("splitting: got =        " + splits.length);
        // we should have a single split as the length is comfortably smaller than
        // the block size
        assertEquals("We got more than one splits!", 1, splits.length);
        InputSplit split = splits[0];
        assertEquals("It should be CombineFileSplit", CombineFileSplit.class, split.getClass());
        // check each split
        BitSet bits = new BitSet(length);
        RecordReader<IntWritable, BytesWritable> reader = format.getRecordReader(split, job, reporter);
        try {
            while (reader.next(key, value)) {
                assertFalse("Key in multiple partitions.", bits.get(key.get()));
                bits.set(key.get());
            }
        } finally {
            reader.close();
        }
        assertEquals("Some keys in no partition.", length, bits.cardinality());
    }
}
Also used : CombineSequenceFileInputFormat(org.apache.hadoop.mapred.lib.CombineSequenceFileInputFormat) BitSet(java.util.BitSet) BytesWritable(org.apache.hadoop.io.BytesWritable) Random(java.util.Random) IntWritable(org.apache.hadoop.io.IntWritable) Test(org.junit.Test)

Example 62 with IntWritable

use of org.apache.hadoop.io.IntWritable in project storm by apache.

the class TestHdfsSpout method createSeqFile.

private static void createSeqFile(FileSystem fs, Path file, int rowCount) throws IOException {
    Configuration conf = new Configuration();
    try {
        if (fs.exists(file)) {
            fs.delete(file, false);
        }
        SequenceFile.Writer w = SequenceFile.createWriter(fs, conf, file, IntWritable.class, Text.class);
        for (int i = 0; i < rowCount; i++) {
            w.append(new IntWritable(i), new Text("line " + i));
        }
        w.close();
        System.out.println("done");
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) SequenceFile(org.apache.hadoop.io.SequenceFile) Text(org.apache.hadoop.io.Text) IOException(java.io.IOException) IntWritable(org.apache.hadoop.io.IntWritable)

Example 63 with IntWritable

use of org.apache.hadoop.io.IntWritable in project hive by apache.

the class MaskTransformer method getCharArg.

int getCharArg(ObjectInspector[] arguments, int index, int defaultValue) {
    int ret = defaultValue;
    ObjectInspector arg = (arguments != null && arguments.length > index) ? arguments[index] : null;
    if (arg != null) {
        if (arg instanceof WritableConstantIntObjectInspector) {
            IntWritable value = ((WritableConstantIntObjectInspector) arg).getWritableConstantValue();
            if (value != null) {
                ret = value.get();
            }
        } else if (arg instanceof WritableConstantLongObjectInspector) {
            LongWritable value = ((WritableConstantLongObjectInspector) arg).getWritableConstantValue();
            if (value != null) {
                ret = (int) value.get();
            }
        } else if (arg instanceof WritableConstantShortObjectInspector) {
            ShortWritable value = ((WritableConstantShortObjectInspector) arg).getWritableConstantValue();
            if (value != null) {
                ret = value.get();
            }
        } else if (arg instanceof ConstantObjectInspector) {
            Object value = ((ConstantObjectInspector) arg).getWritableConstantValue();
            if (value != null) {
                String strValue = value.toString();
                if (strValue != null && strValue.length() > 0) {
                    ret = strValue.charAt(0);
                }
            }
        }
    }
    return ret;
}
Also used : ConstantObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) LongWritable(org.apache.hadoop.io.LongWritable) ConstantObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector) ShortWritable(org.apache.hadoop.hive.serde2.io.ShortWritable) IntWritable(org.apache.hadoop.io.IntWritable)

Example 64 with IntWritable

use of org.apache.hadoop.io.IntWritable in project hive by apache.

the class TestVectorDateExpressions method compareToUDFWeekOfYearDate.

private void compareToUDFWeekOfYearDate(long t, int y) {
    UDFWeekOfYear udf = new UDFWeekOfYear();
    TimestampWritable tsw = toTimestampWritable(t);
    IntWritable res = udf.evaluate(tsw);
    Assert.assertEquals(res.get(), y);
}
Also used : UDFWeekOfYear(org.apache.hadoop.hive.ql.udf.UDFWeekOfYear) TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable) IntWritable(org.apache.hadoop.io.IntWritable)

Example 65 with IntWritable

use of org.apache.hadoop.io.IntWritable in project hive by apache.

the class TestVectorExpressionWriters method testStructLong.

private void testStructLong(TypeInfo type) throws HiveException {
    LongColumnVector icv = VectorizedRowGroupGenUtil.generateLongColumnVector(true, false, vectorSize, new Random(10));
    icv.isNull[3] = true;
    LongColumnVector bcv = VectorizedRowGroupGenUtil.generateLongColumnVector(true, false, vectorSize, new Random(10));
    bcv.isNull[2] = true;
    ArrayList<Object>[] values = (ArrayList<Object>[]) new ArrayList[this.vectorSize];
    StructObjectInspector soi = genStructOI();
    VectorExpressionWriter[] vew = VectorExpressionWriterFactory.getExpressionWriters(soi);
    for (int i = 0; i < vectorSize; i++) {
        values[i] = new ArrayList<Object>(2);
        values[i].add(null);
        values[i].add(null);
        vew[0].setValue(values[i], icv, i);
        vew[1].setValue(values[i], bcv, i);
        Object theInt = values[i].get(0);
        if (theInt == null) {
            Assert.assertTrue(icv.isNull[i]);
        } else {
            IntWritable w = (IntWritable) theInt;
            Assert.assertEquals((int) icv.vector[i], w.get());
        }
        Object theBool = values[i].get(1);
        if (theBool == null) {
            Assert.assertTrue(bcv.isNull[i]);
        } else {
            BooleanWritable w = (BooleanWritable) theBool;
            Assert.assertEquals(bcv.vector[i] == 0 ? false : true, w.get());
        }
    }
}
Also used : Random(java.util.Random) BooleanWritable(org.apache.hadoop.io.BooleanWritable) ArrayList(java.util.ArrayList) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) IntWritable(org.apache.hadoop.io.IntWritable) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)

Aggregations

IntWritable (org.apache.hadoop.io.IntWritable)338 Test (org.junit.Test)120 Text (org.apache.hadoop.io.Text)115 LongWritable (org.apache.hadoop.io.LongWritable)79 Path (org.apache.hadoop.fs.Path)66 FloatWritable (org.apache.hadoop.io.FloatWritable)58 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)56 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)56 BooleanWritable (org.apache.hadoop.io.BooleanWritable)51 ShortWritable (org.apache.hadoop.hive.serde2.io.ShortWritable)50 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)47 BytesWritable (org.apache.hadoop.io.BytesWritable)45 SequenceFile (org.apache.hadoop.io.SequenceFile)41 ArrayList (java.util.ArrayList)40 Writable (org.apache.hadoop.io.Writable)39 TimestampWritable (org.apache.hadoop.hive.serde2.io.TimestampWritable)37 Configuration (org.apache.hadoop.conf.Configuration)35 IOException (java.io.IOException)30 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)29 Random (java.util.Random)28