Search in sources :

Example 1 with RawBytesQuery

use of com.datastax.dse.protocol.internal.request.RawBytesQuery in project java-driver by datastax.

the class GraphConversions method createContinuousMessageFromGraphStatement.

public static Message createContinuousMessageFromGraphStatement(GraphStatement<?> statement, GraphProtocol subProtocol, DriverExecutionProfile config, InternalDriverContext context, GraphBinaryModule graphBinaryModule) {
    final List<ByteBuffer> encodedQueryParams;
    if (!(statement instanceof ScriptGraphStatement) || ((ScriptGraphStatement) statement).getQueryParams().isEmpty()) {
        encodedQueryParams = Collections.emptyList();
    } else {
        try {
            Map<String, Object> queryParams = ((ScriptGraphStatement) statement).getQueryParams();
            if (subProtocol.isGraphBinary()) {
                Buffer graphBinaryParams = graphBinaryModule.serialize(queryParams);
                encodedQueryParams = Collections.singletonList(graphBinaryParams.nioBuffer());
                graphBinaryParams.release();
            } else {
                encodedQueryParams = Collections.singletonList(GraphSONUtils.serializeToByteBuffer(queryParams, subProtocol));
            }
        } catch (IOException e) {
            throw new UncheckedIOException("Couldn't serialize parameters for GraphStatement: " + statement, e);
        }
    }
    int consistencyLevel = DefaultConsistencyLevel.valueOf(config.getString(DefaultDriverOption.REQUEST_CONSISTENCY)).getProtocolCode();
    long timestamp = statement.getTimestamp();
    if (timestamp == Statement.NO_DEFAULT_TIMESTAMP) {
        timestamp = context.getTimestampGenerator().next();
    }
    int pageSize = config.getInt(DseDriverOption.GRAPH_CONTINUOUS_PAGING_PAGE_SIZE);
    int maxPages = config.getInt(DseDriverOption.GRAPH_CONTINUOUS_PAGING_MAX_PAGES);
    int maxPagesPerSecond = config.getInt(DseDriverOption.GRAPH_CONTINUOUS_PAGING_MAX_PAGES_PER_SECOND);
    int maxEnqueuedPages = config.getInt(DseDriverOption.GRAPH_CONTINUOUS_PAGING_MAX_ENQUEUED_PAGES);
    ContinuousPagingOptions options = new ContinuousPagingOptions(maxPages, maxPagesPerSecond, maxEnqueuedPages);
    DseQueryOptions queryOptions = new DseQueryOptions(consistencyLevel, encodedQueryParams, // ignored by the DSE Graph server
    Collections.emptyMap(), // also ignored
    true, pageSize, null, // also ignored
    ProtocolConstants.ConsistencyLevel.LOCAL_SERIAL, timestamp, // also ignored
    null, // graph CP does not support sizeInBytes
    false, options);
    if (statement instanceof ScriptGraphStatement) {
        return new Query(((ScriptGraphStatement) statement).getScript(), queryOptions);
    } else {
        return new RawBytesQuery(getQueryBytes(statement, subProtocol), queryOptions);
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) Buffer(org.apache.tinkerpop.gremlin.structure.io.Buffer) RawBytesQuery(com.datastax.dse.protocol.internal.request.RawBytesQuery) RawBytesQuery(com.datastax.dse.protocol.internal.request.RawBytesQuery) Query(com.datastax.oss.protocol.internal.request.Query) ContinuousPagingOptions(com.datastax.dse.protocol.internal.request.query.ContinuousPagingOptions) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ByteBuffer(java.nio.ByteBuffer) ScriptGraphStatement(com.datastax.dse.driver.api.core.graph.ScriptGraphStatement) DseQueryOptions(com.datastax.dse.protocol.internal.request.query.DseQueryOptions)

Example 2 with RawBytesQuery

use of com.datastax.dse.protocol.internal.request.RawBytesQuery in project java-driver by datastax.

the class GraphRequestHandlerTest method should_create_query_message_from_batch_statement.

@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "supportedGraphProtocols")
public void should_create_query_message_from_batch_statement(GraphProtocol graphProtocol) throws IOException {
    // initialization
    GraphRequestHandlerTestHarness harness = GraphRequestHandlerTestHarness.builder().build();
    @SuppressWarnings("rawtypes") List<GraphTraversal> traversalsTest = ImmutableList.of(// GraphDataTypesTest
    DseGraph.g.addV("person").property("p1", 2.3f).property("p2", LocalDateTime.now(ZoneOffset.UTC)), DseGraph.g.addV("software").property("p3", new BigInteger("123456789123456789123456789123456789")).property("p4", ImmutableList.of(Point.fromCoordinates(30.4, 25.63746284))));
    GraphStatement<?> graphStatement = BatchGraphStatement.builder().addTraversals(traversalsTest).build();
    GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
    // when
    DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(graphStatement, harness.getContext());
    Message m = GraphConversions.createMessageFromGraphStatement(graphStatement, graphProtocol, executionProfile, harness.getContext(), module);
    Map<String, ByteBuffer> createdCustomPayload = GraphConversions.createCustomPayload(graphStatement, graphProtocol, executionProfile, harness.getContext(), module);
    // checks
    assertThat(m).isInstanceOf(RawBytesQuery.class);
    testQueryRequestAndPayloadContents(((RawBytesQuery) m), createdCustomPayload, GraphConversions.bytecodeToSerialize(graphStatement), graphProtocol, module);
}
Also used : RawBytesQuery(com.datastax.dse.protocol.internal.request.RawBytesQuery) Message(com.datastax.oss.protocol.internal.Message) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) GraphTestUtils.createGraphBinaryModule(com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule) GraphBinaryModule(com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule) ByteBuffer(java.nio.ByteBuffer) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) BigInteger(java.math.BigInteger) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 3 with RawBytesQuery

use of com.datastax.dse.protocol.internal.request.RawBytesQuery in project java-driver by datastax.

the class GraphRequestHandlerTest method should_create_query_message_from_fluent_statement.

@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "supportedGraphProtocols")
public void should_create_query_message_from_fluent_statement(GraphProtocol graphProtocol) throws IOException {
    // initialization
    GraphRequestHandlerTestHarness harness = GraphRequestHandlerTestHarness.builder().build();
    GraphTraversal<?, ?> traversalTest = DseGraph.g.V().has("person", "name", "marko").has("p1", 1L).has("p2", Uuids.random());
    GraphStatement<?> graphStatement = FluentGraphStatement.newInstance(traversalTest);
    GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
    // when
    DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(graphStatement, harness.getContext());
    Message m = GraphConversions.createMessageFromGraphStatement(graphStatement, graphProtocol, executionProfile, harness.getContext(), module);
    Map<String, ByteBuffer> createdCustomPayload = GraphConversions.createCustomPayload(graphStatement, graphProtocol, executionProfile, harness.getContext(), module);
    // checks
    assertThat(m).isInstanceOf(RawBytesQuery.class);
    testQueryRequestAndPayloadContents(((RawBytesQuery) m), createdCustomPayload, GraphConversions.bytecodeToSerialize(graphStatement), graphProtocol, module);
}
Also used : RawBytesQuery(com.datastax.dse.protocol.internal.request.RawBytesQuery) Message(com.datastax.oss.protocol.internal.Message) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) GraphTestUtils.createGraphBinaryModule(com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule) GraphBinaryModule(com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 4 with RawBytesQuery

use of com.datastax.dse.protocol.internal.request.RawBytesQuery in project java-driver by datastax.

the class GraphConversions method createMessageFromGraphStatement.

static Message createMessageFromGraphStatement(GraphStatement<?> statement, GraphProtocol subProtocol, DriverExecutionProfile config, InternalDriverContext context, GraphBinaryModule graphBinaryModule) {
    final List<ByteBuffer> encodedQueryParams;
    if (!(statement instanceof ScriptGraphStatement) || ((ScriptGraphStatement) statement).getQueryParams().isEmpty()) {
        encodedQueryParams = Collections.emptyList();
    } else {
        try {
            Map<String, Object> queryParams = ((ScriptGraphStatement) statement).getQueryParams();
            if (subProtocol.isGraphBinary()) {
                Buffer graphBinaryParams = graphBinaryModule.serialize(queryParams);
                encodedQueryParams = Collections.singletonList(graphBinaryParams.nioBuffer());
                graphBinaryParams.release();
            } else {
                encodedQueryParams = Collections.singletonList(GraphSONUtils.serializeToByteBuffer(queryParams, subProtocol));
            }
        } catch (IOException e) {
            throw new UncheckedIOException("Couldn't serialize parameters for GraphStatement: " + statement, e);
        }
    }
    ConsistencyLevel consistency = statement.getConsistencyLevel();
    int consistencyLevel = (consistency == null) ? context.getConsistencyLevelRegistry().nameToCode(config.getString(DefaultDriverOption.REQUEST_CONSISTENCY)) : consistency.getProtocolCode();
    long timestamp = statement.getTimestamp();
    if (timestamp == Statement.NO_DEFAULT_TIMESTAMP) {
        timestamp = context.getTimestampGenerator().next();
    }
    DseQueryOptions queryOptions = new DseQueryOptions(consistencyLevel, encodedQueryParams, // ignored by the DSE Graph server
    Collections.emptyMap(), // also ignored
    true, // also ignored
    50, // also ignored
    null, // also ignored
    ProtocolConstants.ConsistencyLevel.LOCAL_SERIAL, timestamp, // also ignored
    null, // also ignored
    false, // also ignored
    null);
    if (statement instanceof ScriptGraphStatement) {
        return new Query(((ScriptGraphStatement) statement).getScript(), queryOptions);
    } else {
        return new RawBytesQuery(getQueryBytes(statement, subProtocol), queryOptions);
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) Buffer(org.apache.tinkerpop.gremlin.structure.io.Buffer) RawBytesQuery(com.datastax.dse.protocol.internal.request.RawBytesQuery) RawBytesQuery(com.datastax.dse.protocol.internal.request.RawBytesQuery) Query(com.datastax.oss.protocol.internal.request.Query) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ByteBuffer(java.nio.ByteBuffer) DefaultConsistencyLevel(com.datastax.oss.driver.api.core.DefaultConsistencyLevel) ConsistencyLevel(com.datastax.oss.driver.api.core.ConsistencyLevel) ScriptGraphStatement(com.datastax.dse.driver.api.core.graph.ScriptGraphStatement) DseQueryOptions(com.datastax.dse.protocol.internal.request.query.DseQueryOptions)

Aggregations

RawBytesQuery (com.datastax.dse.protocol.internal.request.RawBytesQuery)4 ByteBuffer (java.nio.ByteBuffer)4 ScriptGraphStatement (com.datastax.dse.driver.api.core.graph.ScriptGraphStatement)2 GraphTestUtils.createGraphBinaryModule (com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule)2 GraphBinaryModule (com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule)2 DseQueryOptions (com.datastax.dse.protocol.internal.request.query.DseQueryOptions)2 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)2 Message (com.datastax.oss.protocol.internal.Message)2 Query (com.datastax.oss.protocol.internal.request.Query)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 Buffer (org.apache.tinkerpop.gremlin.structure.io.Buffer)2 Test (org.junit.Test)2 ContinuousPagingOptions (com.datastax.dse.protocol.internal.request.query.ContinuousPagingOptions)1 ConsistencyLevel (com.datastax.oss.driver.api.core.ConsistencyLevel)1 DefaultConsistencyLevel (com.datastax.oss.driver.api.core.DefaultConsistencyLevel)1 BigInteger (java.math.BigInteger)1 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)1