use of org.elasticsearch.common.io.stream.BytesStreamOutput in project crate by crate.
the class ParameterSymbolTest method testSerialization.
@Test
public void testSerialization() throws Exception {
ParameterSymbol ps1 = new ParameterSymbol(2, DataTypes.INTEGER);
BytesStreamOutput out = new BytesStreamOutput();
ps1.writeTo(out);
StreamInput in = StreamInput.wrap(out.bytes());
ParameterSymbol ps2 = new ParameterSymbol(in);
assertThat(ps2.index(), is(ps1.index()));
assertThat(ps2.valueType(), is(ps1.valueType()));
}
use of org.elasticsearch.common.io.stream.BytesStreamOutput in project crate by crate.
the class FulltextAnalyzerResolver method encodeSettings.
public static BytesReference encodeSettings(Settings settings) {
try {
BytesStreamOutput bso = new BytesStreamOutput();
XContentBuilder builder = XContentFactory.jsonBuilder(bso);
builder.startObject();
for (Map.Entry<String, String> entry : settings.getAsMap().entrySet()) {
builder.field(entry.getKey(), entry.getValue());
}
builder.endObject();
builder.flush();
return bso.bytes();
} catch (IOException e) {
// this is a memory stream so no real I/O happens and a IOException can't really happen at runtime
throw Throwables.propagate(e);
}
}
use of org.elasticsearch.common.io.stream.BytesStreamOutput in project crate by crate.
the class PartitionName method encodeIdent.
@Nullable
public static String encodeIdent(Collection<? extends BytesRef> values) {
if (values.size() == 0) {
return null;
}
BytesStreamOutput streamOutput = new BytesStreamOutput(estimateSize(values));
try {
streamOutput.writeVInt(values.size());
for (BytesRef value : values) {
StringType.INSTANCE.streamer().writeValueTo(streamOutput, value);
}
} catch (IOException e) {
throw Throwables.propagate(e);
}
String identBase32 = BASE32.encodeAsString(streamOutput.bytes().toBytes()).toLowerCase(Locale.ROOT);
// decode doesn't need padding, remove it
int idx = identBase32.indexOf('=');
if (idx > -1) {
return identBase32.substring(0, idx);
}
return identBase32;
}
use of org.elasticsearch.common.io.stream.BytesStreamOutput in project crate by crate.
the class CountPhaseTest method testStreaming.
@Test
public void testStreaming() throws Exception {
Routing routing = new Routing(TreeMapBuilder.<String, Map<String, List<Integer>>>newMapBuilder().put("n1", TreeMapBuilder.<String, List<Integer>>newMapBuilder().put("i1", Arrays.asList(1, 2)).put("i2", Arrays.asList(1, 2)).map()).put("n2", TreeMapBuilder.<String, List<Integer>>newMapBuilder().put("i1", Collections.singletonList(3)).map()).map());
CountPhase countPhase = new CountPhase(1, routing, WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_BROADCAST);
BytesStreamOutput out = new BytesStreamOutput(10);
countPhase.writeTo(out);
StreamInput in = StreamInput.wrap(out.bytes());
CountPhase streamedNode = CountPhase.FACTORY.create();
streamedNode.readFrom(in);
assertThat(streamedNode.phaseId(), is(1));
assertThat(streamedNode.nodeIds(), containsInAnyOrder("n1", "n2"));
assertThat(streamedNode.routing(), equalTo(routing));
assertThat(streamedNode.distributionInfo(), equalTo(DistributionInfo.DEFAULT_BROADCAST));
}
use of org.elasticsearch.common.io.stream.BytesStreamOutput in project crate by crate.
the class NestedLoopPhaseTest method testSerialization.
@Test
public void testSerialization() throws Exception {
TopNProjection topNProjection = new TopNProjection(10, 0, Collections.emptyList());
UUID jobId = UUID.randomUUID();
MergePhase mp1 = new MergePhase(jobId, 2, "merge", 1, Collections.emptyList(), ImmutableList.<DataType>of(DataTypes.STRING), ImmutableList.of(), DistributionInfo.DEFAULT_BROADCAST, null);
MergePhase mp2 = new MergePhase(jobId, 3, "merge", 1, Collections.emptyList(), ImmutableList.<DataType>of(DataTypes.STRING), ImmutableList.of(), DistributionInfo.DEFAULT_BROADCAST, null);
SqlExpressions sqlExpressions = new SqlExpressions(T3.SOURCES, T3.TR_1);
Symbol joinCondition = sqlExpressions.normalize(sqlExpressions.asSymbol("t1.x = t1.i"));
NestedLoopPhase node = new NestedLoopPhase(jobId, 1, "nestedLoop", ImmutableList.of(topNProjection), mp1, mp2, Sets.newHashSet("node1", "node2"), JoinType.INNER, joinCondition, 1, 1);
BytesStreamOutput output = new BytesStreamOutput();
node.writeTo(output);
StreamInput input = StreamInput.wrap(output.bytes());
NestedLoopPhase node2 = new NestedLoopPhase();
node2.readFrom(input);
assertThat(node.nodeIds(), Is.is(node2.nodeIds()));
assertThat(node.jobId(), Is.is(node2.jobId()));
assertThat(node.name(), is(node2.name()));
assertThat(node.outputTypes(), is(node2.outputTypes()));
assertThat(node.joinType(), is(node2.joinType()));
assertThat(node.numLeftOutputs(), is(node2.numLeftOutputs()));
assertThat(node.numRightOutputs(), is(node2.numRightOutputs()));
}
Aggregations