use of org.elasticsearch.common.io.stream.StreamInput in project elasticsearch by elastic.
the class FuzzinessTests method doSerializeRoundtrip.
private static Fuzziness doSerializeRoundtrip(Fuzziness in) throws IOException {
BytesStreamOutput output = new BytesStreamOutput();
in.writeTo(output);
StreamInput streamInput = output.bytes().streamInput();
return new Fuzziness(streamInput);
}
use of org.elasticsearch.common.io.stream.StreamInput in project crate by crate.
the class TDigestStateTest method testStreaming.
@Test
public void testStreaming() throws Exception {
TDigestState digestState1 = new TDigestState(250, new double[] { 0.5, 0.8 });
BytesStreamOutput out = new BytesStreamOutput();
TDigestStateType digestStateType = TDigestStateType.INSTANCE;
Streamer streamer = digestStateType.create().streamer();
streamer.writeValueTo(out, digestState1);
StreamInput in = StreamInput.wrap(out.bytes());
TDigestState digestState2 = (TDigestState) streamer.readValueFrom(in);
assertEquals(digestState1.compression(), digestState2.compression(), 0.001d);
assertEquals(digestState1.fractions()[0], digestState2.fractions()[0], 0.001d);
assertEquals(digestState1.fractions()[1], digestState2.fractions()[1], 0.001d);
}
use of org.elasticsearch.common.io.stream.StreamInput in project crate by crate.
the class PartitionName method decodeIdent.
/**
* decodes an encoded ident into it's values
*/
@Nullable
public static List<BytesRef> decodeIdent(@Nullable String ident) {
if (ident == null) {
return ImmutableList.of();
}
byte[] inputBytes = BASE32.decode(ident.toUpperCase(Locale.ROOT));
try (StreamInput in = StreamInput.wrap(inputBytes)) {
int size = in.readVInt();
List<BytesRef> values = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
values.add(StringType.INSTANCE.streamer().readValueFrom(in));
}
return values;
} catch (IOException e) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Invalid partition ident: %s", ident), e);
}
}
use of org.elasticsearch.common.io.stream.StreamInput 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.StreamInput 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