Search in sources :

Example 1 with Output

use of com.esotericsoftware.kryo.io.Output in project hive by apache.

the class TestInputOutputFormat method toKryo.

public static String toKryo(SearchArgument sarg) {
    Output out = new Output(4 * 1024, 10 * 1024 * 1024);
    new Kryo().writeObject(out, sarg);
    out.close();
    return Base64.encodeBase64String(out.toBytes());
}
Also used : DataOutput(java.io.DataOutput) Output(com.esotericsoftware.kryo.io.Output) Kryo(com.esotericsoftware.kryo.Kryo)

Example 2 with Output

use of com.esotericsoftware.kryo.io.Output in project hive by apache.

the class KryoSerializer method serialize.

public static byte[] serialize(Object object) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    Output output = new Output(stream);
    Kryo kryo = SerializationUtilities.borrowKryo();
    kryo.setClassLoader(Thread.currentThread().getContextClassLoader());
    try {
        kryo.writeObject(output, object);
    } finally {
        SerializationUtilities.releaseKryo(kryo);
    }
    // close() also calls flush()
    output.close();
    return stream.toByteArray();
}
Also used : Output(com.esotericsoftware.kryo.io.Output) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Kryo(com.esotericsoftware.kryo.Kryo)

Example 3 with Output

use of com.esotericsoftware.kryo.io.Output in project hive by apache.

the class HiveKVResultCache method setupOutput.

private void setupOutput() throws IOException {
    if (parentFile == null) {
        while (true) {
            parentFile = File.createTempFile("hive-resultcache", "");
            if (parentFile.delete() && parentFile.mkdir()) {
                parentFile.deleteOnExit();
                break;
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug("Retry creating tmp result-cache directory...");
            }
        }
    }
    if (tmpFile == null || input != null) {
        tmpFile = File.createTempFile("ResultCache", ".tmp", parentFile);
        LOG.info("ResultCache created temp file " + tmpFile.getAbsolutePath());
        tmpFile.deleteOnExit();
    }
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(tmpFile);
        output = new Output(fos);
    } finally {
        if (output == null && fos != null) {
            fos.close();
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) Output(com.esotericsoftware.kryo.io.Output)

Example 4 with Output

use of com.esotericsoftware.kryo.io.Output in project hive by apache.

the class ExternalCache method getSerializedSargForMetastore.

private ByteBuffer getSerializedSargForMetastore(boolean isOriginal) {
    if (sarg == null)
        return null;
    ByteBuffer serializedSarg = isOriginal ? sargIsOriginal : sargNotIsOriginal;
    if (serializedSarg != null)
        return serializedSarg;
    SearchArgument sarg2 = sarg;
    Kryo kryo = SerializationUtilities.borrowKryo();
    try {
        if ((isOriginal ? sargNotIsOriginal : sargIsOriginal) == null) {
            // In case we need it for the other case.
            sarg2 = kryo.copy(sarg2);
        }
        translateSargToTableColIndexes(sarg2, conf, OrcInputFormat.getRootColumn(isOriginal));
        ExternalCache.Baos baos = new Baos();
        Output output = new Output(baos);
        kryo.writeObject(output, sarg2);
        output.flush();
        serializedSarg = baos.get();
        if (isOriginal) {
            sargIsOriginal = serializedSarg;
        } else {
            sargNotIsOriginal = serializedSarg;
        }
    } finally {
        SerializationUtilities.releaseKryo(kryo);
    }
    return serializedSarg;
}
Also used : Output(com.esotericsoftware.kryo.io.Output) SearchArgument(org.apache.hadoop.hive.ql.io.sarg.SearchArgument) ByteBuffer(java.nio.ByteBuffer) Kryo(com.esotericsoftware.kryo.Kryo)

Example 5 with Output

use of com.esotericsoftware.kryo.io.Output in project hive by apache.

the class FSStatsPublisher method closeConnection.

@Override
public boolean closeConnection(StatsCollectionContext context) {
    List<String> statsDirs = context.getStatsTmpDirs();
    assert statsDirs.size() == 1 : "Found multiple stats dirs: " + statsDirs;
    Path statsDir = new Path(statsDirs.get(0));
    try {
        Path statsFile = null;
        if (context.getIndexForTezUnion() != -1) {
            statsFile = new Path(statsDir, StatsSetupConst.STATS_FILE_PREFIX + conf.getInt("mapred.task.partition", 0) + "_" + context.getIndexForTezUnion());
        } else {
            statsFile = new Path(statsDir, StatsSetupConst.STATS_FILE_PREFIX + conf.getInt("mapred.task.partition", 0));
        }
        LOG.debug("About to create stats file for this task : " + statsFile);
        Output output = new Output(statsFile.getFileSystem(conf).create(statsFile, true));
        LOG.debug("Created file : " + statsFile);
        LOG.debug("Writing stats in it : " + statsMap);
        Kryo kryo = SerializationUtilities.borrowKryo();
        try {
            kryo.writeObject(output, statsMap);
        } finally {
            SerializationUtilities.releaseKryo(kryo);
        }
        output.close();
        return true;
    } catch (IOException e) {
        LOG.error("Failed to persist stats on filesystem", e);
        return false;
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Output(com.esotericsoftware.kryo.io.Output) IOException(java.io.IOException) Kryo(com.esotericsoftware.kryo.Kryo)

Aggregations

Output (com.esotericsoftware.kryo.io.Output)51 Kryo (com.esotericsoftware.kryo.Kryo)29 ByteArrayOutputStream (java.io.ByteArrayOutputStream)22 Input (com.esotericsoftware.kryo.io.Input)21 ByteArrayInputStream (java.io.ByteArrayInputStream)12 Test (org.junit.Test)8 FileOutputStream (java.io.FileOutputStream)7 Test (org.testng.annotations.Test)6 IOException (java.io.IOException)5 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)5 KryoException (com.esotericsoftware.kryo.KryoException)4 StdInstantiatorStrategy (org.objenesis.strategy.StdInstantiatorStrategy)4 SAMFileHeader (htsjdk.samtools.SAMFileHeader)3 Schema (co.cask.cdap.api.data.schema.Schema)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 HashMap (java.util.HashMap)2 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)2 StructuredRecord (co.cask.cdap.api.data.format.StructuredRecord)1 ClassIdPair (com.datatorrent.stram.codec.DefaultStatefulStreamCodec.ClassIdPair)1