This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-cpp.git


The following commit(s) were added to refs/heads/main by this push:
     new 06ce20f  refactor: add expression subdirectory (#81)
06ce20f is described below

commit 06ce20f39753c92de38355a4263abb455d6acf14
Author: Gang Wu <[email protected]>
AuthorDate: Fri Apr 18 12:55:50 2025 +0800

    refactor: add expression subdirectory (#81)
---
 src/iceberg/CMakeLists.txt                 |  3 ++-
 src/iceberg/expression/CMakeLists.txt      | 18 ++++++++++++++++++
 src/iceberg/{ => expression}/expression.cc |  7 ++++---
 src/iceberg/{ => expression}/expression.h  |  0
 src/iceberg/result.h                       |  8 ++++++++
 test/expression_test.cc                    |  2 +-
 6 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/src/iceberg/CMakeLists.txt b/src/iceberg/CMakeLists.txt
index cd7276e..1f52118 100644
--- a/src/iceberg/CMakeLists.txt
+++ b/src/iceberg/CMakeLists.txt
@@ -20,6 +20,7 @@ set(ICEBERG_INCLUDES 
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/src>"
 set(ICEBERG_SOURCES
     arrow_c_data_internal.cc
     demo.cc
+    expression/expression.cc
     json_internal.cc
     partition_field.cc
     partition_spec.cc
@@ -35,7 +36,6 @@ set(ICEBERG_SOURCES
     transform_function.cc
     type.cc
     snapshot.cc
-    expression.cc
     util/murmurhash3_internal.cc)
 
 set(ICEBERG_STATIC_BUILD_INTERFACE_LIBS)
@@ -68,6 +68,7 @@ add_iceberg_lib(iceberg
 
 iceberg_install_all_headers(iceberg)
 
+add_subdirectory(expression)
 add_subdirectory(util)
 
 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/iceberg_export.h
diff --git a/src/iceberg/expression/CMakeLists.txt 
b/src/iceberg/expression/CMakeLists.txt
new file mode 100644
index 0000000..b06b1d7
--- /dev/null
+++ b/src/iceberg/expression/CMakeLists.txt
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+iceberg_install_all_headers(iceberg/expression)
diff --git a/src/iceberg/expression.cc b/src/iceberg/expression/expression.cc
similarity index 93%
rename from src/iceberg/expression.cc
rename to src/iceberg/expression/expression.cc
index d53cef3..2914c81 100644
--- a/src/iceberg/expression.cc
+++ b/src/iceberg/expression/expression.cc
@@ -17,10 +17,12 @@
  * under the License.
  */
 
-#include "expression.h"
+#include "iceberg/expression/expression.h"
 
 #include <format>
 
+#include "iceberg/result.h"
+
 namespace iceberg {
 
 // True implementation
@@ -49,8 +51,7 @@ std::string And::ToString() const {
 
 Result<std::shared_ptr<Expression>> And::Negate() const {
   // TODO(yingcai-cy): Implement Or expression
-  return unexpected(
-      Error(ErrorKind::kInvalidExpression, "And negation not yet 
implemented"));
+  return InvalidExpressionError("And negation not yet implemented");
 }
 
 bool And::Equals(const Expression& expr) const {
diff --git a/src/iceberg/expression.h b/src/iceberg/expression/expression.h
similarity index 100%
rename from src/iceberg/expression.h
rename to src/iceberg/expression/expression.h
diff --git a/src/iceberg/result.h b/src/iceberg/result.h
index 06c7874..f8b3740 100644
--- a/src/iceberg/result.h
+++ b/src/iceberg/result.h
@@ -78,4 +78,12 @@ auto JsonParseError(const std::format_string<Args...> fmt, 
Args&&... args)
                             .message = std::format(fmt, 
std::forward<Args>(args)...)});
 }
 
+/// \brief Create an unexpected error with kInvalidExpression
+template <typename... Args>
+auto InvalidExpressionError(const std::format_string<Args...> fmt, Args&&... 
args)
+    -> unexpected<Error> {
+  return unexpected<Error>({.kind = ErrorKind::kInvalidExpression,
+                            .message = std::format(fmt, 
std::forward<Args>(args)...)});
+}
+
 }  // namespace iceberg
diff --git a/test/expression_test.cc b/test/expression_test.cc
index 1ca50cb..f722d62 100644
--- a/test/expression_test.cc
+++ b/test/expression_test.cc
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-#include "iceberg/expression.h"
+#include "iceberg/expression/expression.h"
 
 #include <memory>
 

Reply via email to