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());
}
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();
}
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();
}
}
}
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;
}
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;
}
}
Aggregations