|
| 1 | +/* |
| 2 | + * Copyright (c) Facebook, Inc. and its affiliates. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +#pragma once |
| 17 | + |
| 18 | +#include "velox/connectors/hive/HiveConnector.h" |
| 19 | + |
| 20 | +namespace facebook::velox::connector::hive::iceberg { |
| 21 | + |
| 22 | +/// TODO Add IcebergConfig class and Move these configuration properties to |
| 23 | +/// IcebergConfig.h |
| 24 | +static constexpr std::string_view kIcebergFunctionPrefixConfig{ |
| 25 | + "presto.iceberg-namespace"}; |
| 26 | +static constexpr std::string_view kDefaultIcebergFunctionPrefix{ |
| 27 | + "$internal$.iceberg."}; |
| 28 | + |
| 29 | +/// Provides Iceberg table format support. |
| 30 | +/// - Creates HiveDataSource instances that use IcebergSplitReader for reading |
| 31 | +/// Iceberg tables with support for delete files and schema evolution. |
| 32 | +/// - Creates IcebergDataSink instances for writing data with Iceberg-specific |
| 33 | +/// partition transforms and commit metadata. |
| 34 | +class IcebergConnector final : public HiveConnector { |
| 35 | + public: |
| 36 | + IcebergConnector( |
| 37 | + const std::string& id, |
| 38 | + std::shared_ptr<const config::ConfigBase> config, |
| 39 | + folly::Executor* ioExecutor); |
| 40 | + |
| 41 | + /// Creates IcebergDataSink for writing to Iceberg tables. |
| 42 | + /// |
| 43 | + /// @param inputType The schema of the input data to write. |
| 44 | + /// @param connectorInsertTableHandle Must be an IcebergInsertTableHandle |
| 45 | + /// containing Iceberg-specific write configuration. |
| 46 | + /// @param connectorQueryCtx Query context for the write operation. |
| 47 | + /// @param commitStrategy Strategy for committing the write operation. Only |
| 48 | + /// CommitStrategy::kNoCommit is supported for Iceberg tables. Files |
| 49 | + /// are written directly with their final names and commit metadata is |
| 50 | + /// returned for the coordinator to update the Iceberg metadata tables. |
| 51 | + /// @return IcebergDataSink instance configured for the write operation. |
| 52 | + std::unique_ptr<DataSink> createDataSink( |
| 53 | + RowTypePtr inputType, |
| 54 | + ConnectorInsertTableHandlePtr connectorInsertTableHandle, |
| 55 | + ConnectorQueryCtx* connectorQueryCtx, |
| 56 | + CommitStrategy commitStrategy) override; |
| 57 | + |
| 58 | + private: |
| 59 | + const std::string functionPrefix_; |
| 60 | +}; |
| 61 | + |
| 62 | +class IcebergConnectorFactory final : public ConnectorFactory { |
| 63 | + public: |
| 64 | + static constexpr const char* kIcebergConnectorName = "iceberg"; |
| 65 | + |
| 66 | + IcebergConnectorFactory() : ConnectorFactory(kIcebergConnectorName) {} |
| 67 | + |
| 68 | + /// Creates a new IcebergConnector instance. |
| 69 | + /// |
| 70 | + /// @param id Unique identifier for this connector instance (typically the |
| 71 | + /// catalog name). |
| 72 | + /// @param config Connector configuration properties |
| 73 | + /// @param ioExecutor Optional executor for asynchronous I/O operations such |
| 74 | + /// as split preloading and file prefetching. When provided, enables |
| 75 | + /// background file operations off the main driver thread. If nullptr, I/O |
| 76 | + /// operations run synchronously. |
| 77 | + /// @param cpuExecutor ConnectorFactory interface to support other connector |
| 78 | + /// types that may need CPU-bound async work. Currently unused by |
| 79 | + /// IcebergConnector. |
| 80 | + /// @return Shared pointer to the newly created IcebergConnector instance |
| 81 | + std::shared_ptr<Connector> newConnector( |
| 82 | + const std::string& id, |
| 83 | + std::shared_ptr<const config::ConfigBase> config, |
| 84 | + folly::Executor* ioExecutor = nullptr, |
| 85 | + [[maybe_unused]] folly::Executor* cpuExecutor = nullptr) override { |
| 86 | + return std::make_shared<IcebergConnector>(id, config, ioExecutor); |
| 87 | + } |
| 88 | +}; |
| 89 | + |
| 90 | +} // namespace facebook::velox::connector::hive::iceberg |
0 commit comments