Skip to content

Commit 8a9b23d

Browse files
Abigale KimKiterLuc
andauthored
Remove serialization non C.41 constructors from query condition. (#4684)
This change removes non C.41 constructors from condition_from_capnp. --- TYPE: NO_HISTORY DESC: Remove serialization non C.41 constructors from query condition. --------- Co-authored-by: KiterLuc <[email protected]>
1 parent 1578755 commit 8a9b23d

File tree

6 files changed

+18
-35
lines changed

6 files changed

+18
-35
lines changed

test/src/unit-QueryCondition-serialization.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ TEST_CASE(
5151
"QueryCondition serialization: Test serialization",
5252
"[QueryCondition][serialization]") {
5353
QueryCondition query_condition;
54-
QueryCondition query_condition_clone;
5554

5655
SECTION("Test serialization, basic") {
5756
std::string field_name = "x";
@@ -271,9 +270,8 @@ TEST_CASE(
271270
REQUIRE(tiledb::sm::serialization::condition_to_capnp(
272271
query_condition, &condition_builder)
273272
.ok());
274-
REQUIRE(tiledb::sm::serialization::condition_from_capnp(
275-
condition_builder, &query_condition_clone)
276-
.ok());
273+
auto query_condition_clone =
274+
tiledb::sm::serialization::condition_from_capnp(condition_builder);
277275
REQUIRE(tiledb::test::ast_equal(
278276
query_condition.ast(), query_condition_clone.ast()));
279277
}

test/src/unit-cppapi-query-condition-sets.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ QueryCondition CPPQueryConditionFx::serialize_deserialize_qc(
924924
throw_if_not_ok(condition_to_capnp(*qc_ptr, &builder));
925925

926926
// Deserialize the query condition.
927-
throw_if_not_ok(condition_from_capnp(builder, ret_ptr));
927+
*ret_ptr = condition_from_capnp(builder);
928928
REQUIRE(tiledb::test::ast_equal(ret_ptr->ast(), qc_ptr->ast()));
929929

930930
return ret;

tiledb/sm/query/query_condition.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2757,10 +2757,6 @@ uint64_t QueryCondition::condition_index() const {
27572757
return condition_index_;
27582758
}
27592759

2760-
void QueryCondition::set_ast(tdb_unique_ptr<ASTNode>&& ast) {
2761-
tree_ = std::move(ast);
2762-
}
2763-
27642760
// Explicit template instantiations.
27652761
template Status QueryCondition::apply_sparse<uint8_t>(
27662762
const ArraySchema& array_schema, ResultTile&, std::vector<uint8_t>&);

tiledb/sm/query/query_condition.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ class QueryCondition {
5959
/* CONSTRUCTORS & DESTRUCTORS */
6060
/* ********************************* */
6161

62-
/** Default constructor. */
62+
/** Default constructor. Should be used only in the C API. */
6363
QueryCondition();
6464

65-
/** Constructor for a set membership QueryCondition */
65+
/** Constructor for a set membership QueryCondition. */
6666
QueryCondition(
6767
const std::string& field_name,
6868
const void* data,
@@ -247,12 +247,6 @@ class QueryCondition {
247247
*/
248248
QueryCondition negated_condition();
249249

250-
/**
251-
* Sets the AST. This is internal state to only be used in
252-
* the serialization path.
253-
*/
254-
void set_ast(tdb_unique_ptr<ASTNode>&& ast);
255-
256250
/**
257251
* Returns the AST object. This is internal state to only be used in testing
258252
* and the serialization path.

tiledb/sm/serialization/query.cc

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,9 +1068,8 @@ tdb_unique_ptr<ASTNode> condition_ast_from_capnp(
10681068
tdb_new(ASTNodeExpr, std::move(ast_nodes), combination_op));
10691069
}
10701070

1071-
Status condition_from_capnp(
1072-
const capnp::Condition::Reader& condition_reader,
1073-
QueryCondition* const condition) {
1071+
QueryCondition condition_from_capnp(
1072+
const capnp::Condition::Reader& condition_reader) {
10741073
if (condition_reader.hasClauses()) { // coming from older API
10751074
// Accumulating the AST value nodes from the clause list.
10761075
std::vector<tdb_unique_ptr<ASTNode>> ast_nodes;
@@ -1104,19 +1103,20 @@ Status condition_from_capnp(
11041103
// Constructing the tree from the list of AST nodes.
11051104
assert(ast_nodes.size() > 0);
11061105
if (ast_nodes.size() == 1) {
1107-
condition->set_ast(std::move(ast_nodes[0]));
1106+
return QueryCondition(std::move(ast_nodes[0]));
11081107
} else {
11091108
auto tree_ptr = tdb_unique_ptr<ASTNode>(tdb_new(
11101109
ASTNodeExpr, std::move(ast_nodes), QueryConditionCombinationOp::AND));
1111-
condition->set_ast(std::move(tree_ptr));
1110+
return QueryCondition(std::move(tree_ptr));
11121111
}
11131112
} else if (condition_reader.hasTree()) {
11141113
// Constructing the query condition from the AST representation.
11151114
// We assume that the deserialized values of the AST are validated properly.
11161115
auto ast_reader = condition_reader.getTree();
1117-
condition->set_ast(condition_ast_from_capnp(ast_reader));
1116+
return QueryCondition(condition_ast_from_capnp(ast_reader));
11181117
}
1119-
return Status::Ok();
1118+
throw std::runtime_error(
1119+
"condition_from_capnp: serialized QC has no tree or clauses.");
11201120
}
11211121

11221122
Status reader_from_capnp(
@@ -1144,8 +1144,7 @@ Status reader_from_capnp(
11441144
// Query condition
11451145
if (reader_reader.hasCondition()) {
11461146
auto condition_reader = reader_reader.getCondition();
1147-
QueryCondition condition;
1148-
RETURN_NOT_OK(condition_from_capnp(condition_reader, &condition));
1147+
QueryCondition condition = condition_from_capnp(condition_reader);
11491148
RETURN_NOT_OK(query->set_condition(condition));
11501149
}
11511150

@@ -1186,8 +1185,7 @@ Status index_reader_from_capnp(
11861185
// Query condition
11871186
if (reader_reader.hasCondition()) {
11881187
auto condition_reader = reader_reader.getCondition();
1189-
QueryCondition condition;
1190-
RETURN_NOT_OK(condition_from_capnp(condition_reader, &condition));
1188+
QueryCondition condition = condition_from_capnp(condition_reader);
11911189
RETURN_NOT_OK(query->set_condition(condition));
11921190
}
11931191

@@ -1229,8 +1227,7 @@ Status dense_reader_from_capnp(
12291227
// Query condition
12301228
if (reader_reader.hasCondition()) {
12311229
auto condition_reader = reader_reader.getCondition();
1232-
QueryCondition condition;
1233-
RETURN_NOT_OK(condition_from_capnp(condition_reader, &condition));
1230+
QueryCondition condition = condition_from_capnp(condition_reader);
12341231
RETURN_NOT_OK(query->set_condition(condition));
12351232
}
12361233

@@ -1253,8 +1250,7 @@ Status delete_from_capnp(
12531250
// Query condition
12541251
if (delete_reader.hasCondition()) {
12551252
auto condition_reader = delete_reader.getCondition();
1256-
QueryCondition condition;
1257-
RETURN_NOT_OK(condition_from_capnp(condition_reader, &condition));
1253+
QueryCondition condition = condition_from_capnp(condition_reader);
12581254
RETURN_NOT_OK(query->set_condition(condition));
12591255
}
12601256

tiledb/sm/serialization/query.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,8 @@ Status unordered_write_state_from_capnp(
239239
UnorderedWriter* runordered_writer,
240240
SerializationContext context);
241241

242-
Status condition_from_capnp(
243-
const capnp::Condition::Reader& condition_reader,
244-
QueryCondition* const condition);
242+
QueryCondition condition_from_capnp(
243+
const capnp::Condition::Reader& condition_reader);
245244

246245
Status condition_to_capnp(
247246
const QueryCondition& condition,

0 commit comments

Comments
 (0)