Search in sources :

Example 76 with StreamInput

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);
}
Also used : StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Example 77 with 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);
}
Also used : Streamer(io.crate.Streamer) StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test)

Example 78 with StreamInput

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);
    }
}
Also used : StreamInput(org.elasticsearch.common.io.stream.StreamInput) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BytesRef(org.apache.lucene.util.BytesRef) Nullable(org.elasticsearch.common.Nullable)

Example 79 with StreamInput

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));
}
Also used : StreamInput(org.elasticsearch.common.io.stream.StreamInput) Routing(io.crate.metadata.Routing) Map(java.util.Map) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 80 with StreamInput

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()));
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) StreamInput(org.elasticsearch.common.io.stream.StreamInput) TopNProjection(io.crate.planner.projection.TopNProjection) UUID(java.util.UUID) SqlExpressions(io.crate.testing.SqlExpressions) NestedLoopPhase(io.crate.planner.node.dql.join.NestedLoopPhase) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

StreamInput (org.elasticsearch.common.io.stream.StreamInput)183 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)146 Test (org.junit.Test)52 CrateUnitTest (io.crate.test.integration.CrateUnitTest)37 NamedWriteableAwareStreamInput (org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput)30 BytesArray (org.elasticsearch.common.bytes.BytesArray)24 Version (org.elasticsearch.Version)21 IOException (java.io.IOException)13 BytesReference (org.elasticsearch.common.bytes.BytesReference)10 UUID (java.util.UUID)9 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)9 Symbol (io.crate.analyze.symbol.Symbol)8 BytesRef (org.apache.lucene.util.BytesRef)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ShardId (org.elasticsearch.index.shard.ShardId)6 List (java.util.List)5 AliasFilter (org.elasticsearch.search.internal.AliasFilter)5 Aggregation (io.crate.analyze.symbol.Aggregation)4