wgtmac commented on code in PR #30: URL: https://github.com/apache/iceberg-cpp/pull/30#discussion_r2020479441
########## src/iceberg/file_io.h: ########## @@ -0,0 +1,81 @@ +/* + * 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. + */ + +#pragma once + +#include <optional> +#include <string> +#include <string_view> + +#include "iceberg/error.h" +#include "iceberg/expected.h" +#include "iceberg/iceberg_export.h" + +namespace iceberg { + +/// \brief Pluggable module for reading, writing, and deleting metadata files. Review Comment: ```suggestion /// \brief Pluggable module for reading, writing, and deleting files. ``` ########## src/iceberg/file_io.h: ########## @@ -0,0 +1,81 @@ +/* + * 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. + */ + +#pragma once + +#include <optional> +#include <string> +#include <string_view> + +#include "iceberg/error.h" +#include "iceberg/expected.h" +#include "iceberg/iceberg_export.h" + +namespace iceberg { + +/// \brief Pluggable module for reading, writing, and deleting metadata files. +/// +/// This module only handle metadata files, not data files. The metadata files +/// are typically small and are used to store schema, partition information, +/// and other metadata about the table. +class ICEBERG_EXPORT FileIO { + public: + FileIO() = default; + virtual ~FileIO() = default; + + /// \brief Read the content of the file at the given location. + /// + /// \param file_location The location of the file to read. + /// \param length The number of bytes to read. Some object storage need to specify + /// the length to read, e.g. S3 `GetObject` has a Range parameter. + /// \return The content of the file if the read succeeded, an error code if the read + /// failed. + virtual expected<std::string, Error> ReadFile(const std::string& file_location, + std::optional<size_t> length) { + // The following line is to avoid Windows linker error LNK2019. + // If this function is defined as pure virtual function, the `unexpected<Error>` will + // not be instantiated and exported in libiceberg. + return unexpected<Error>{ Review Comment: Why not leaving them pure virtual just like `DeleteFile`? ########## src/iceberg/arrow/arrow_error_transform_internal.h: ########## @@ -0,0 +1,61 @@ +/* + * 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. + */ + +#pragma once + +#include <arrow/result.h> +#include <arrow/status.h> + +#include "iceberg/error.h" +#include "iceberg/expected.h" + +namespace iceberg::arrow::internal { + +inline ErrorKind ToErrorKind(const ::arrow::Status& status) { + switch (status.code()) { + case ::arrow::StatusCode::IOError: + return ErrorKind::kIOError; + default: + return ErrorKind::kUnknownError; + } +} + +#define ICEBERG_INTERNAL_ASSIGN_OR_RETURN_IMPL(result_name, lhs, rexpr, error_transform) \ Review Comment: Perhaps `ICEBERG_ASSIGN_OR_RETURN_IMPL` or `ICEBERG_ARROW_ASSIGN_OR_RETURN_IMPL` is enough? ########## src/iceberg/arrow/io/local_file_io.h: ########## @@ -0,0 +1,57 @@ +/* + * 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. + */ + +#pragma once + +#include <memory> + +#include <arrow/filesystem/localfs.h> + +#include "iceberg/file_io.h" +#include "iceberg/iceberg_bundle_export.h" + +namespace iceberg::arrow::io { + +/// \brief A concrete implementation of FileIO for file system. +class ICEBERG_BUNDLE_EXPORT LocalFileIO : public FileIO { Review Comment: Do we need to special case a `LocalFileIO`? I was thinking that we can just add `class ArrowFileSystemIO : public FileIO` which holds a `std::shared_ptr<arrow::FileSystem>`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org