Skip to content

Commit 9341771

Browse files
author
Innocent
committed
review
1 parent b01d585 commit 9341771

5 files changed

Lines changed: 25 additions & 31 deletions

File tree

src/iceberg/expression/json_serde.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ namespace iceberg {
3535
Result<std::shared_ptr<Expression>> ExpressionFromJson(const nlohmann::json& json) {
3636
// Handle boolean
3737
if (json.is_boolean()) {
38-
return json.get<bool>() ? std::static_pointer_cast<Expression>(True::Instance())
39-
: std::static_pointer_cast<Expression>(False::Instance());
38+
return json.get<bool>() ? std::dynamic_pointer_cast<Expression>(True::Instance())
39+
: std::dynamic_pointer_cast<Expression>(False::Instance());
4040
}
4141
return JsonParseError("Only boolean are currently supported");
4242
}

src/iceberg/expression/json_serde_internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "iceberg/iceberg_export.h"
2626
#include "iceberg/result.h"
2727

28-
/// \file iceberg/expression/json_internal.h
28+
/// \file iceberg/expression/json_serde_internal.h
2929
/// JSON serialization and deserialization for expressions.
3030

3131
namespace iceberg {
@@ -43,7 +43,7 @@ Result<Model> FromJson(const nlohmann::json& json);
4343
ICEBERG_EXPORT nlohmann::json ToJson(const Model& model);
4444

4545
/// \note Don't forget to add `ICEBERG_DEFINE_FROM_JSON` to the end of
46-
/// `json_internal.cc` to define the `FromJson` function for the model.
46+
/// `json_serde_internal.cc` to define the `FromJson` function for the model.
4747
ICEBERG_DECLARE_JSON_SERDE(Expression)
4848

4949
#undef ICEBERG_DECLARE_JSON_SERDE

src/iceberg/expression/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ install_headers(
2424
'expression_visitor.h',
2525
'expressions.h',
2626
'inclusive_metrics_evaluator.h',
27+
'json_serde_internal.h',
2728
'literal.h',
2829
'manifest_evaluator.h',
2930
'predicate.h',

src/iceberg/test/expression_json_test.cc

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,35 +34,27 @@
3434

3535
namespace iceberg {
3636

37-
class ExpressionJsonTest : public ::testing::Test {};
37+
class ExpressionJsonTest : public ::testing::Test {
38+
protected:
39+
void CheckBoolean(std::shared_ptr<Expression> expr, bool value) {
40+
auto json = ToJson(*expr);
41+
EXPECT_TRUE(json.is_boolean());
42+
EXPECT_EQ(json.get<bool>(), value);
43+
44+
auto result = ExpressionFromJson(json);
45+
ASSERT_THAT(result, IsOk());
46+
if (value) {
47+
EXPECT_EQ(result.value()->op(), Expression::Operation::kTrue);
48+
} else {
49+
EXPECT_EQ(result.value()->op(), Expression::Operation::kFalse);
50+
}
51+
}
52+
};
3853

3954
// Test boolean constant expressions
40-
TEST_F(ExpressionJsonTest, TrueExpression) {
41-
auto expr = True::Instance();
42-
auto json = ToJson(*expr);
43-
44-
// True should serialize as JSON boolean true
45-
EXPECT_TRUE(json.is_boolean());
46-
EXPECT_TRUE(json.get<bool>());
47-
48-
// Parse back
49-
auto result = ExpressionFromJson(json);
50-
ASSERT_THAT(result, IsOk());
51-
EXPECT_EQ(result.value()->op(), Expression::Operation::kTrue);
52-
}
53-
54-
TEST_F(ExpressionJsonTest, FalseExpression) {
55-
auto expr = False::Instance();
56-
auto json = ToJson(*expr);
57-
58-
// False should serialize as JSON boolean false
59-
EXPECT_TRUE(json.is_boolean());
60-
EXPECT_FALSE(json.get<bool>());
61-
62-
// Parse back
63-
auto result = ExpressionFromJson(json);
64-
ASSERT_THAT(result, IsOk());
65-
EXPECT_EQ(result.value()->op(), Expression::Operation::kFalse);
55+
TEST_F(ExpressionJsonTest, CheckBooleanExpression) {
56+
CheckBoolean(True::Instance(), true);
57+
CheckBoolean(False::Instance(), false);
6658
}
6759

6860
} // namespace iceberg

src/iceberg/test/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ iceberg_tests = {
6161
'expression_test': {
6262
'sources': files(
6363
'aggregate_test.cc',
64+
'expression_json_test.cc',
6465
'expression_test.cc',
6566
'expression_visitor_test.cc',
6667
'inclusive_metrics_evaluator_test.cc',

0 commit comments

Comments
 (0)