| 
 | 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 | + | 
 | 17 | +#include "ConnectorConfigBase.h"  | 
 | 18 | + | 
 | 19 | +#include "velox/common/config/Config.h"  | 
 | 20 | + | 
 | 21 | +namespace facebook::velox::connector::lakehouse::base {  | 
 | 22 | + | 
 | 23 | +std::string ConnectorConfigBase::gcsEndpoint() const {  | 
 | 24 | +  return config_->get<std::string>(kGcsEndpoint, std::string(""));  | 
 | 25 | +}  | 
 | 26 | + | 
 | 27 | +std::string ConnectorConfigBase::gcsCredentialsPath() const {  | 
 | 28 | +  return config_->get<std::string>(kGcsCredentialsPath, std::string(""));  | 
 | 29 | +}  | 
 | 30 | + | 
 | 31 | +std::optional<int> ConnectorConfigBase::gcsMaxRetryCount() const {  | 
 | 32 | +  return static_cast<std::optional<int>>(config_->get<int>(kGcsMaxRetryCount));  | 
 | 33 | +}  | 
 | 34 | + | 
 | 35 | +std::optional<std::string> ConnectorConfigBase::gcsMaxRetryTime() const {  | 
 | 36 | +  return static_cast<std::optional<std::string>>(  | 
 | 37 | +      config_->get<std::string>(kGcsMaxRetryTime));  | 
 | 38 | +}  | 
 | 39 | + | 
 | 40 | +bool ConnectorConfigBase::isOrcUseColumnNames(  | 
 | 41 | +    const config::ConfigBase* session) const {  | 
 | 42 | +  return session->get<bool>(  | 
 | 43 | +      kOrcUseColumnNamesSession, config_->get<bool>(kOrcUseColumnNames, false));  | 
 | 44 | +}  | 
 | 45 | + | 
 | 46 | +bool ConnectorConfigBase::isParquetUseColumnNames(  | 
 | 47 | +    const config::ConfigBase* session) const {  | 
 | 48 | +  return session->get<bool>(  | 
 | 49 | +      kParquetUseColumnNamesSession,  | 
 | 50 | +      config_->get<bool>(kParquetUseColumnNames, false));  | 
 | 51 | +}  | 
 | 52 | + | 
 | 53 | +bool ConnectorConfigBase::isFileColumnNamesReadAsLowerCase(  | 
 | 54 | +    const config::ConfigBase* session) const {  | 
 | 55 | +  return session->get<bool>(  | 
 | 56 | +      kFileColumnNamesReadAsLowerCaseSession,  | 
 | 57 | +      config_->get<bool>(kFileColumnNamesReadAsLowerCase, false));  | 
 | 58 | +}  | 
 | 59 | + | 
 | 60 | +bool ConnectorConfigBase::isPartitionPathAsLowerCase(  | 
 | 61 | +    const config::ConfigBase* session) const {  | 
 | 62 | +  return session->get<bool>(kPartitionPathAsLowerCaseSession, true);  | 
 | 63 | +}  | 
 | 64 | + | 
 | 65 | +bool ConnectorConfigBase::allowNullPartitionKeys(  | 
 | 66 | +    const config::ConfigBase* session) const {  | 
 | 67 | +  return session->get<bool>(  | 
 | 68 | +      kAllowNullPartitionKeysSession,  | 
 | 69 | +      config_->get<bool>(kAllowNullPartitionKeys, true));  | 
 | 70 | +}  | 
 | 71 | + | 
 | 72 | +int64_t ConnectorConfigBase::maxCoalescedBytes(  | 
 | 73 | +    const config::ConfigBase* session) const {  | 
 | 74 | +  return session->get<int64_t>(  | 
 | 75 | +      kMaxCoalescedBytesSession,  | 
 | 76 | +      config_->get<int64_t>(kMaxCoalescedBytes, 128 << 20)); // 128MB  | 
 | 77 | +}  | 
 | 78 | + | 
 | 79 | +int32_t ConnectorConfigBase::maxCoalescedDistanceBytes(  | 
 | 80 | +    const config::ConfigBase* session) const {  | 
 | 81 | +  const auto distance = config::toCapacity(  | 
 | 82 | +      session->get<std::string>(  | 
 | 83 | +          kMaxCoalescedDistanceSession,  | 
 | 84 | +          config_->get<std::string>(kMaxCoalescedDistance, "512kB")),  | 
 | 85 | +      config::CapacityUnit::BYTE);  | 
 | 86 | +  VELOX_USER_CHECK_LE(  | 
 | 87 | +      distance,  | 
 | 88 | +      std::numeric_limits<int32_t>::max(),  | 
 | 89 | +      "The max merge distance to combine read requests must be less than 2GB."  | 
 | 90 | +      " Got {} bytes.",  | 
 | 91 | +      distance);  | 
 | 92 | +  return int32_t(distance);  | 
 | 93 | +}  | 
 | 94 | + | 
 | 95 | +int32_t ConnectorConfigBase::prefetchRowGroups() const {  | 
 | 96 | +  return config_->get<int32_t>(kPrefetchRowGroups, 1);  | 
 | 97 | +}  | 
 | 98 | + | 
 | 99 | +int32_t ConnectorConfigBase::loadQuantum(const config::ConfigBase* session) const {  | 
 | 100 | +  return session->get<int32_t>(  | 
 | 101 | +      kLoadQuantumSession, config_->get<int32_t>(kLoadQuantum, 8 << 20));  | 
 | 102 | +}  | 
 | 103 | + | 
 | 104 | +int32_t ConnectorConfigBase::numCacheFileHandles() const {  | 
 | 105 | +  return config_->get<int32_t>(kNumCacheFileHandles, 20'000);  | 
 | 106 | +}  | 
 | 107 | + | 
 | 108 | +uint64_t ConnectorConfigBase::fileHandleExpirationDurationMs() const {  | 
 | 109 | +  return config_->get<uint64_t>(kFileHandleExpirationDurationMs, 0);  | 
 | 110 | +}  | 
 | 111 | + | 
 | 112 | +bool ConnectorConfigBase::isFileHandleCacheEnabled() const {  | 
 | 113 | +  return config_->get<bool>(kEnableFileHandleCache, true);  | 
 | 114 | +}  | 
 | 115 | + | 
 | 116 | +std::string ConnectorConfigBase::writeFileCreateConfig() const {  | 
 | 117 | +  return config_->get<std::string>(kWriteFileCreateConfig, "");  | 
 | 118 | +}  | 
 | 119 | + | 
 | 120 | +uint64_t ConnectorConfigBase::footerEstimatedSize() const {  | 
 | 121 | +  return config_->get<uint64_t>(kFooterEstimatedSize, 256UL << 10);  | 
 | 122 | +}  | 
 | 123 | + | 
 | 124 | +uint64_t ConnectorConfigBase::filePreloadThreshold() const {  | 
 | 125 | +  return config_->get<uint64_t>(kFilePreloadThreshold, 8UL << 20);  | 
 | 126 | +}  | 
 | 127 | + | 
 | 128 | +uint8_t ConnectorConfigBase::readTimestampUnit(  | 
 | 129 | +    const config::ConfigBase* session) const {  | 
 | 130 | +  const auto unit = session->get<uint8_t>(  | 
 | 131 | +      kReadTimestampUnitSession,  | 
 | 132 | +      config_->get<uint8_t>(kReadTimestampUnit, 3 /*milli*/));  | 
 | 133 | +  VELOX_CHECK(  | 
 | 134 | +      unit == 3 || unit == 6 /*micro*/ || unit == 9 /*nano*/,  | 
 | 135 | +      "Invalid timestamp unit.");  | 
 | 136 | +  return unit;  | 
 | 137 | +}  | 
 | 138 | + | 
 | 139 | +bool ConnectorConfigBase::readTimestampPartitionValueAsLocalTime(  | 
 | 140 | +    const config::ConfigBase* session) const {  | 
 | 141 | +  return session->get<bool>(  | 
 | 142 | +      kReadTimestampPartitionValueAsLocalTimeSession,  | 
 | 143 | +      config_->get<bool>(kReadTimestampPartitionValueAsLocalTime, true));  | 
 | 144 | +}  | 
 | 145 | + | 
 | 146 | +bool ConnectorConfigBase::readStatsBasedFilterReorderDisabled(  | 
 | 147 | +    const config::ConfigBase* session) const {  | 
 | 148 | +  return session->get<bool>(  | 
 | 149 | +      kReadStatsBasedFilterReorderDisabledSession,  | 
 | 150 | +      config_->get<bool>(kReadStatsBasedFilterReorderDisabled, false));  | 
 | 151 | +}  | 
 | 152 | + | 
 | 153 | +} // namespace facebook::velox::connector::lakehouse::base  | 
0 commit comments