Skip to content

Commit 01f1692

Browse files
authored
Merge pull request #8 from datastax/375
375 - Added CLs to graph query options and timestamp to graph statement
2 parents 74d1864 + 8470e21 commit 01f1692

File tree

13 files changed

+686
-88
lines changed

13 files changed

+686
-88
lines changed

cpp-driver

include/dse.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,32 @@ DSE_EXPORT CassError
361361
dse_graph_options_set_graph_name_n(DseGraphOptions* options,
362362
const char* name, size_t name_length);
363363

364+
/**
365+
* Set the read consistency used by graph queries.
366+
*
367+
* @public @memberof DseGraphOptions
368+
*
369+
* @param[in] options
370+
* @param[in] consistency
371+
* @return CASS_OK if successful, otherwise an error occurred.
372+
*/
373+
DSE_EXPORT CassError
374+
dse_graph_options_set_read_consistency(DseGraphOptions* options,
375+
CassConsistency consistency);
376+
377+
/**
378+
* Set the write consistency used by graph queries.
379+
*
380+
* @public @memberof DseGraphOptions
381+
*
382+
* @param[in] options
383+
* @param[in] consistency
384+
* @return CASS_OK if successful, otherwise an error occurred.
385+
*/
386+
DSE_EXPORT CassError
387+
dse_graph_options_set_write_consistency(DseGraphOptions* options,
388+
CassConsistency consistency);
389+
364390
/**
365391
* Set the request timeout used by graph queries. Only use this if you want
366392
* graph queries to wait less than the server's default timeout (defined in
@@ -438,6 +464,20 @@ DSE_EXPORT CassError
438464
dse_graph_statement_bind_values(DseGraphStatement* statement,
439465
const DseGraphObject* values);
440466

467+
468+
/**
469+
* Sets the graph statement's timestamp.
470+
*
471+
* @public @memberof DseGraphStatement
472+
*
473+
* @param[in] statement
474+
* @param[in] timestamp
475+
* @return CASS_OK if successful, otherwise an error occurred.
476+
*/
477+
CASS_EXPORT CassError
478+
dse_graph_statement_set_timestamp(DseGraphStatement* statement,
479+
cass_int64_t timestamp);
480+
441481
/***********************************************************************************
442482
*
443483
* Graph Object

src/graph.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ CassError dse_graph_options_set_graph_name_n(DseGraphOptions* options,
7878
return CASS_OK;
7979
}
8080

81+
CassError dse_graph_options_set_read_consistency(DseGraphOptions* options,
82+
CassConsistency consistency) {
83+
options->set_graph_read_consistency(consistency);
84+
return CASS_OK;
85+
}
86+
87+
CassError dse_graph_options_set_write_consistency(DseGraphOptions* options,
88+
CassConsistency consistency) {
89+
options->set_graph_write_consistency(consistency);
90+
return CASS_OK;
91+
}
92+
8193
CassError dse_graph_options_set_request_timeout(DseGraphOptions* options,
8294
cass_int64_t timeout_ms) {
8395
if (timeout_ms < 0) return CASS_ERROR_LIB_BAD_PARAMS;
@@ -110,6 +122,11 @@ CassError dse_graph_statement_bind_values(DseGraphStatement* statement,
110122
return statement->bind_values(values);
111123
}
112124

125+
CassError dse_graph_statement_set_timestamp(DseGraphStatement* statement,
126+
cass_int64_t timestamp) {
127+
return statement->set_timestamp(timestamp);
128+
}
129+
113130
DseGraphObject* dse_graph_object_new() {
114131
return DseGraphObject::to(new dse::GraphObject());
115132
}

src/graph.hpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
#include <string>
1717
#include <vector>
1818

19-
#define DSE_GRAPH_OPTION_LANGUAGE_KEY "graph-language"
20-
#define DSE_GRAPH_OPTION_SOURCE_KEY "graph-source"
21-
#define DSE_GRAPH_OPTION_NAME_KEY "graph-name"
22-
#define DSE_GRAPH_REQUEST_TIMEOUT "request-timeout"
19+
#define DSE_GRAPH_OPTION_LANGUAGE_KEY "graph-language"
20+
#define DSE_GRAPH_OPTION_SOURCE_KEY "graph-source"
21+
#define DSE_GRAPH_OPTION_NAME_KEY "graph-name"
22+
#define DSE_GRAPH_OPTION_READ_CONSISTENCY_KEY "graph-read-consistency"
23+
#define DSE_GRAPH_OPTION_WRITE_CONSISTENCY_KEY "graph-write-consistency"
24+
#define DSE_GRAPH_REQUEST_TIMEOUT "request-timeout"
2325

2426
#define DSE_GRAPH_DEFAULT_LANGUAGE "gremlin-groovy"
2527
#define DSE_GRAPH_DEFAULT_SOURCE "g"
@@ -62,6 +64,20 @@ class GraphOptions {
6264
reinterpret_cast<const cass_byte_t*>(graph_name.data()), graph_name.size());
6365
}
6466

67+
void set_graph_read_consistency(CassConsistency consistency) {
68+
const char* name = cass_consistency_string(consistency);
69+
cass_custom_payload_set_n(payload_,
70+
DSE_GRAPH_OPTION_READ_CONSISTENCY_KEY, sizeof(DSE_GRAPH_OPTION_READ_CONSISTENCY_KEY) - 1,
71+
reinterpret_cast<const cass_byte_t*>(name), strlen(name));
72+
}
73+
74+
void set_graph_write_consistency(CassConsistency consistency) {
75+
const char* name = cass_consistency_string(consistency);
76+
cass_custom_payload_set_n(payload_,
77+
DSE_GRAPH_OPTION_WRITE_CONSISTENCY_KEY, sizeof(DSE_GRAPH_OPTION_WRITE_CONSISTENCY_KEY) - 1,
78+
reinterpret_cast<const cass_byte_t*>(name), strlen(name));
79+
}
80+
6581
int64_t request_timeout_ms() const { return request_timeout_ms_; }
6682

6783
void set_request_timeout_ms(int64_t timeout_ms);
@@ -185,6 +201,10 @@ class GraphStatement {
185201
}
186202
}
187203

204+
CassError set_timestamp(int64_t timestamp) {
205+
return cass_statement_set_timestamp(wrapped_, timestamp);
206+
}
207+
188208
private:
189209
std::string query_;
190210
CassStatement* wrapped_;

tests/src/integration/dse_integration.cpp

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,31 @@
1515
#define GRAPH_ENABLE_STRICT \
1616
"schema.config().option('graph.schema_mode').set('production')"
1717

18+
#define GRAPH_SCHEMA \
19+
"schema.propertyKey('name').Text().ifNotExists().create();" \
20+
"schema.propertyKey('age').Int().ifNotExists().create();" \
21+
"schema.propertyKey('lang').Text().ifNotExists().create();" \
22+
"schema.propertyKey('weight').Float().ifNotExists().create();" \
23+
"schema.vertexLabel('person').properties('name', 'age').ifNotExists().create();" \
24+
"schema.vertexLabel('software').properties('name', 'lang').ifNotExists().create();" \
25+
"schema.edgeLabel('created').properties('weight').connection('person', 'software').ifNotExists().create();" \
26+
"schema.edgeLabel('created').connection('software', 'software').add();" \
27+
"schema.edgeLabel('knows').properties('weight').connection('person', 'person').ifNotExists().create();"
28+
29+
#define GRAPH_DATA \
30+
"Vertex marko = graph.addVertex(label, 'person', 'name', 'marko', 'age', 29);" \
31+
"Vertex vadas = graph.addVertex(label, 'person', 'name', 'vadas', 'age', 27);" \
32+
"Vertex lop = graph.addVertex(label, 'software', 'name', 'lop', 'lang', 'java');" \
33+
"Vertex josh = graph.addVertex(label, 'person', 'name', 'josh', 'age', 32);" \
34+
"Vertex ripple = graph.addVertex(label, 'software', 'name', 'ripple', 'lang', 'java');" \
35+
"Vertex peter = graph.addVertex(label, 'person', 'name', 'peter', 'age', 35);" \
36+
"marko.addEdge('knows', vadas, 'weight', 0.5f);" \
37+
"marko.addEdge('knows', josh, 'weight', 1.0f);" \
38+
"marko.addEdge('created', lop, 'weight', 0.4f);" \
39+
"josh.addEdge('created', ripple, 'weight', 1.0f);" \
40+
"josh.addEdge('created', lop, 'weight', 0.4f);" \
41+
"peter.addEdge('created', lop, 'weight', 0.2f);"
42+
1843
DseIntegration::DseIntegration()
1944
: Integration()
2045
, dse_session_() {}
@@ -42,27 +67,37 @@ void DseIntegration::connect() {
4267
void DseIntegration::create_graph(const std::string& graph_name,
4368
const std::string& replication_strategy,
4469
const std::string& duration) {
45-
// Create the graph statement using the pre-determined replication config
46-
test::driver::DseGraphObject graph_object;
47-
graph_object.add<std::string>("name", graph_name);
48-
graph_object.add<std::string>("replication", replication_strategy);
49-
graph_object.add<std::string>("duration", duration);
50-
test::driver::DseGraphStatement graph_statement(GRAPH_CREATE);
51-
graph_statement.bind(graph_object);
52-
CHECK_FAILURE;
70+
// Create the graph statement using the pre-determined replication config
71+
test::driver::DseGraphObject graph_object;
72+
graph_object.add<std::string>("name", graph_name);
73+
graph_object.add<std::string>("replication", replication_strategy);
74+
graph_object.add<std::string>("duration", duration);
75+
test::driver::DseGraphStatement graph_statement(GRAPH_CREATE);
76+
graph_statement.bind(graph_object);
77+
CHECK_FAILURE;
5378

54-
// Execute the graph statement and ensure it was created
55-
dse_session_.execute(graph_statement);
56-
CHECK_FAILURE;
79+
// Execute the graph statement and ensure it was created
80+
dse_session_.execute(graph_statement);
81+
CHECK_FAILURE;
5782

58-
// Enable testing functionality for the graph
59-
test::driver::DseGraphOptions options;
60-
options.set_name(graph_name);
61-
dse_session_.execute(GRAPH_ALLOW_SCANS, options);
62-
CHECK_FAILURE;
63-
dse_session_.execute(GRAPH_ENABLE_STRICT, options);
64-
CHECK_FAILURE;
65-
}
83+
// Enable testing functionality for the graph
84+
test::driver::DseGraphOptions options;
85+
options.set_name(graph_name);
86+
dse_session_.execute(GRAPH_ALLOW_SCANS, options);
87+
CHECK_FAILURE;
88+
dse_session_.execute(GRAPH_ENABLE_STRICT, options);
89+
CHECK_FAILURE;
90+
}
91+
92+
void DseIntegration::populate_classic_graph(const std::string& graph_name) {
93+
// Initialize the graph pre-populated data
94+
test::driver::DseGraphOptions options;
95+
options.set_name(graph_name);
96+
dse_session_.execute(GRAPH_SCHEMA, options);
97+
CHECK_FAILURE;
98+
dse_session_.execute(GRAPH_DATA, options);
99+
CHECK_FAILURE;
100+
}
66101

67102
void DseIntegration::create_graph(const std::string& duration /*= "PT30S"*/) {
68103
create_graph(test_name_, replication_strategy_, duration);

tests/src/integration/dse_integration.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class DseIntegration : public Integration {
6161
* @param duration Maximum duration to wait for a traversal to evaluate
6262
* @see replication_factor_
6363
*/
64-
void DseIntegration::create_graph(const std::string& graph_name,
64+
void create_graph(const std::string& graph_name,
6565
const std::string& replication_strategy,
6666
const std::string& duration);
6767

@@ -73,7 +73,17 @@ class DseIntegration : public Integration {
7373
* @see test_name_
7474
* @see replication_strategy_
7575
*/
76-
void DseIntegration::create_graph(const std::string& duration = "PT30S");
76+
void create_graph(const std::string& duration = "PT30S");
77+
78+
/**
79+
* Populate the graph with the classic graph structure examples used in the
80+
* TinkerPop documentation.
81+
*
82+
* @see http://tinkerpop.apache.org/docs/3.1.0-incubating/#intro
83+
*
84+
* @param graph_name Name of the graph to initialize
85+
*/
86+
void populate_classic_graph(const std::string& graph_name);
7787
};
7888

7989
#endif //__DSE_INTEGRATION_HPP__

0 commit comments

Comments
 (0)