Search in sources :

Example 1 with DseRowsMetadata

use of com.datastax.dse.protocol.internal.response.result.DseRowsMetadata in project java-driver by datastax.

the class ContinuousCqlRequestHandler method createResultSet.

@NonNull
@Override
protected DefaultContinuousAsyncResultSet createResultSet(@NonNull Statement<?> statement, @NonNull Rows rows, @NonNull ExecutionInfo executionInfo, @NonNull ColumnDefinitions columnDefinitions) {
    Queue<List<ByteBuffer>> data = rows.getData();
    CountingIterator<Row> iterator = new CountingIterator<Row>(data.size()) {

        @Override
        protected Row computeNext() {
            List<ByteBuffer> rowData = data.poll();
            return (rowData == null) ? endOfData() : new DefaultRow(columnDefinitions, rowData, context);
        }
    };
    DseRowsMetadata metadata = (DseRowsMetadata) rows.getMetadata();
    return new DefaultContinuousAsyncResultSet(iterator, columnDefinitions, metadata.continuousPageNumber, !metadata.isLastContinuousPage, executionInfo, this);
}
Also used : CountingIterator(com.datastax.oss.driver.internal.core.util.CountingIterator) List(java.util.List) Row(com.datastax.oss.driver.api.core.cql.Row) DefaultRow(com.datastax.oss.driver.internal.core.cql.DefaultRow) DseRowsMetadata(com.datastax.dse.protocol.internal.response.result.DseRowsMetadata) DefaultRow(com.datastax.oss.driver.internal.core.cql.DefaultRow) ByteBuffer(java.nio.ByteBuffer) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 2 with DseRowsMetadata

use of com.datastax.dse.protocol.internal.response.result.DseRowsMetadata in project java-driver by datastax.

the class DseTestFixtures method tenDseRows.

// Returns 10 rows, each with a single "message" column with the value "hello, world"
public static Rows tenDseRows(int page, boolean last) {
    DseRowsMetadata metadata = new DseRowsMetadata(ImmutableList.of(new ColumnSpec("ks", "table", "message", 0, RawType.PRIMITIVES.get(ProtocolConstants.DataType.VARCHAR))), last ? null : ByteBuffer.wrap(new byte[] { (byte) page }), new int[] {}, null, page, last);
    Queue<List<ByteBuffer>> data = new ArrayDeque<>();
    for (int i = 0; i < 10; i++) {
        data.add(ImmutableList.of(Bytes.fromHexString("0x68656C6C6F2C20776F726C64")));
    }
    return new DefaultRows(metadata, data);
}
Also used : ColumnSpec(com.datastax.oss.protocol.internal.response.result.ColumnSpec) DefaultRows(com.datastax.oss.protocol.internal.response.result.DefaultRows) ImmutableList(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList) List(java.util.List) DseRowsMetadata(com.datastax.dse.protocol.internal.response.result.DseRowsMetadata) ArrayDeque(java.util.ArrayDeque)

Example 3 with DseRowsMetadata

use of com.datastax.dse.protocol.internal.response.result.DseRowsMetadata in project java-driver by datastax.

the class GraphTestUtils method singleGraphRow.

public static Message singleGraphRow(GraphProtocol graphProtocol, GraphBinaryModule module) throws IOException {
    Vertex value = DetachedVertex.build().setId(1).setLabel("person").addProperty(DetachedVertexProperty.build().setId(11).setLabel("name").setValue("marko").create()).create();
    DseRowsMetadata metadata = new DseRowsMetadata(ImmutableList.of(new ColumnSpec("ks", "table", "gremlin", 0, graphProtocol.isGraphBinary() ? RawType.PRIMITIVES.get(ProtocolConstants.DataType.BLOB) : RawType.PRIMITIVES.get(ProtocolConstants.DataType.VARCHAR))), null, new int[] {}, null, 1, true);
    Queue<List<ByteBuffer>> data = new ArrayDeque<>();
    data.add(ImmutableList.of(serialize(graphProtocol.isGraphBinary() ? // GraphBinary returns results directly inside a Traverser
    new DefaultRemoteTraverser<>(value, 1) : ImmutableMap.of("result", value), graphProtocol, module)));
    return new DefaultRows(metadata, data);
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DetachedVertex(org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex) ColumnSpec(com.datastax.oss.protocol.internal.response.result.ColumnSpec) DefaultRows(com.datastax.oss.protocol.internal.response.result.DefaultRows) ImmutableList(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList) List(java.util.List) DseRowsMetadata(com.datastax.dse.protocol.internal.response.result.DseRowsMetadata) DefaultRemoteTraverser(org.apache.tinkerpop.gremlin.process.remote.traversal.DefaultRemoteTraverser) ArrayDeque(java.util.ArrayDeque)

Example 4 with DseRowsMetadata

use of com.datastax.dse.protocol.internal.response.result.DseRowsMetadata in project java-driver by datastax.

the class GraphTestUtils method tenGraphRows.

// Returns 10 rows, each with a vertex
public static Rows tenGraphRows(GraphProtocol graphProtocol, GraphBinaryModule module, int page, boolean last) throws IOException {
    DseRowsMetadata metadata = new DseRowsMetadata(ImmutableList.of(new ColumnSpec("ks", "table", "gremlin", 0, graphProtocol.isGraphBinary() ? RawType.PRIMITIVES.get(ProtocolConstants.DataType.BLOB) : RawType.PRIMITIVES.get(ProtocolConstants.DataType.VARCHAR))), null, new int[] {}, null, page, last);
    Queue<List<ByteBuffer>> data = new ArrayDeque<>();
    int start = (page - 1) * 10;
    for (int i = start; i < start + 10; i++) {
        Vertex v = DetachedVertex.build().setId("vertex" + i).setLabel("person").addProperty(DetachedVertexProperty.build().setId("property" + i).setLabel("name").setValue("user" + i).create()).create();
        data.add(ImmutableList.of(serialize(graphProtocol.isGraphBinary() ? // GraphBinary returns results directly inside a Traverser
        new DefaultRemoteTraverser<>(v, 1) : ImmutableMap.of("result", v), graphProtocol, module)));
    }
    return new DefaultRows(metadata, data);
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DetachedVertex(org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex) ColumnSpec(com.datastax.oss.protocol.internal.response.result.ColumnSpec) DefaultRows(com.datastax.oss.protocol.internal.response.result.DefaultRows) ImmutableList(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList) List(java.util.List) DseRowsMetadata(com.datastax.dse.protocol.internal.response.result.DseRowsMetadata) DefaultRemoteTraverser(org.apache.tinkerpop.gremlin.process.remote.traversal.DefaultRemoteTraverser) ArrayDeque(java.util.ArrayDeque)

Example 5 with DseRowsMetadata

use of com.datastax.dse.protocol.internal.response.result.DseRowsMetadata in project java-driver by datastax.

the class ContinuousGraphRequestHandler method createResultSet.

@NonNull
@Override
protected ContinuousAsyncGraphResultSet createResultSet(@NonNull GraphStatement<?> statement, @NonNull Rows rows, @NonNull ExecutionInfo executionInfo, @NonNull ColumnDefinitions columnDefinitions) throws IOException {
    DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(statement, context);
    GraphProtocol subProtocol = graphSupportChecker.inferGraphProtocol(statement, executionProfile, context);
    Queue<GraphNode> graphNodes = new ArrayDeque<>();
    for (List<ByteBuffer> row : rows.getData()) {
        if (subProtocol.isGraphBinary()) {
            graphNodes.offer(GraphConversions.createGraphBinaryGraphNode(row, this.graphBinaryModule));
        } else {
            graphNodes.offer(GraphSONUtils.createGraphNode(row, subProtocol));
        }
    }
    DseRowsMetadata metadata = (DseRowsMetadata) rows.getMetadata();
    return new ContinuousAsyncGraphResultSet(executionInfo, graphNodes, metadata.continuousPageNumber, !metadata.isLastContinuousPage, this, subProtocol);
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) DseRowsMetadata(com.datastax.dse.protocol.internal.response.result.DseRowsMetadata) ByteBuffer(java.nio.ByteBuffer) ArrayDeque(java.util.ArrayDeque) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Aggregations

DseRowsMetadata (com.datastax.dse.protocol.internal.response.result.DseRowsMetadata)6 ArrayDeque (java.util.ArrayDeque)5 List (java.util.List)5 ImmutableList (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList)4 ColumnSpec (com.datastax.oss.protocol.internal.response.result.ColumnSpec)4 DefaultRows (com.datastax.oss.protocol.internal.response.result.DefaultRows)4 NonNull (edu.umd.cs.findbugs.annotations.NonNull)2 ByteBuffer (java.nio.ByteBuffer)2 DefaultRemoteTraverser (org.apache.tinkerpop.gremlin.process.remote.traversal.DefaultRemoteTraverser)2 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)2 DetachedVertex (org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex)2 GraphNode (com.datastax.dse.driver.api.core.graph.GraphNode)1 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)1 Row (com.datastax.oss.driver.api.core.cql.Row)1 DefaultRow (com.datastax.oss.driver.internal.core.cql.DefaultRow)1 CountingIterator (com.datastax.oss.driver.internal.core.util.CountingIterator)1