Skip to content

Conversation

@evindj
Copy link

@evindj evindj commented Jan 24, 2026

Summary

This is the first PR aimed a addressing #331
Because doing it in one go will be more error prone and will make review harder, I am splitting the change across several PR.
This first one covers:

  • Template definition to help generate ToJson and FromJson implementations.
  • basic support for only boolean expressions.
  • Unit tests for the case that we was added.

Test

  • Added some unit tests that cover the change and ensured the pass
     ~/Documents/my_iceberg/iceberg-cpp   bool_expressio_serde  ./build/src/iceberg/test/expression_test --gtest_filter="ExpressionJson*"  ✔  1297  13:53:47
    Running main() from gmock_main.cc
    Note: Google Test filter = ExpressionJson*
    [==========] Running 2 tests from 1 test suite.
    [----------] Global test environment set-up.
    [----------] 2 tests from ExpressionJsonTest
    [ RUN ] ExpressionJsonTest.TrueExpression
    [ OK ] ExpressionJsonTest.TrueExpression (0 ms)
    [ RUN ] ExpressionJsonTest.FalseExpression
    [ OK ] ExpressionJsonTest.FalseExpression (0 ms)
    [----------] 2 tests from ExpressionJsonTest (0 ms total)

[----------] Global test environment tear-down
[==========] 2 tests from 1 test suite ran. (0 ms total)
[ PASSED ] 2 tests.
idjiofack@Innocents-MacBook-Pro-2  ~/Documents/my_iceberg/iceberg-cpp   bool_expressio_serde 

@evindj evindj changed the title [PR 1/X] basic plumbing for serde support for expressions [Serde - PR 1/X] basic plumbing for serde support for expressions Jan 25, 2026
@evindj evindj changed the title [Serde - PR 1/X] basic plumbing for serde support for expressions [Expr Serde] [PR 1/X] basic plumbing for serde support for expressions Jan 25, 2026
#include "iceberg/iceberg_export.h"
#include "iceberg/result.h"

/// \file iceberg/expression/json_internal.h
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep the comment in sync

expression/expression.cc
expression/expressions.cc
expression/inclusive_metrics_evaluator.cc
expression/json_serde.cc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to update meson.build for any new file.

ICEBERG_EXPORT nlohmann::json ToJson(const Model& model);

/// \note Don't forget to add `ICEBERG_DEFINE_FROM_JSON` to the end of
/// `json_internal.cc` to define the `FromJson` function for the model.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

add_iceberg_test(expression_test
SOURCES
aggregate_test.cc
expression_json_test.cc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment for meson.build

Result<std::shared_ptr<Expression>> ExpressionFromJson(const nlohmann::json& json) {
// Handle boolean
if (json.is_boolean()) {
return json.get<bool>() ? std::static_pointer_cast<Expression>(True::Instance())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use checked_pointer_cast

EXPECT_EQ(result.value()->op(), Expression::Operation::kTrue);
}

TEST_F(ExpressionJsonTest, FalseExpression) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two cases share a lot of similarities. Can we use a single test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants