| 247 | } |
| 248 | |
| 249 | std::shared_ptr<exec::VectorFunction> createStringToMap( |
| 250 | const std::string& /*name*/, |
| 251 | const std::vector<exec::VectorFunctionArg>& inputArgs, |
| 252 | const core::QueryConfig& config) { |
| 253 | // according to |
| 254 | // https://docs.databricks.com/en/sql/language-manual/functions/str_to_map.html |
| 255 | // pairDelim and keyValueDelim must be STRING literal |
| 256 | std::string pairDelim = ","; |
| 257 | std::string keyValueDelim = ":"; |
| 258 | bool isPairDelimReg = false; |
| 259 | bool isKeyValueDelimReg = false; |
| 260 | if (inputArgs.size() >= 2) { |
| 261 | BaseVector* constantPairDelim = inputArgs[1].constantValue.get(); |
| 262 | if (constantPairDelim) { |
| 263 | pairDelim = std::string( |
| 264 | constantPairDelim->as<ConstantVector<StringView>>()->valueAt(0)); |
| 265 | isPairDelimReg = stringCore::checkRegexPattern(pairDelim); |
| 266 | } else { |
| 267 | BOLT_USER_FAIL("pairDelim in str_to_map must be STRING literal."); |
| 268 | } |
| 269 | } |
| 270 | if (inputArgs.size() == 3) { |
| 271 | BaseVector* constantKeyValueDelim = inputArgs[2].constantValue.get(); |
| 272 | if (constantKeyValueDelim) { |
| 273 | keyValueDelim = std::string( |
| 274 | constantKeyValueDelim->as<ConstantVector<StringView>>()->valueAt(0)); |
| 275 | isKeyValueDelimReg = stringCore::checkRegexPattern(keyValueDelim); |
| 276 | } else { |
| 277 | BOLT_USER_FAIL("keyValueDelim in str_to_map must be STRING literal."); |
| 278 | } |
| 279 | } |
| 280 | std::string mapKeyDedupPolicy = config.sparkMapKeyDedupPolicy(); |
| 281 | bool isFlinkCompatible = config.enableFlinkCompatible(); |
| 282 | |
| 283 | if (isPairDelimReg) { |
| 284 | if (isKeyValueDelimReg) { |
| 285 | return transmit<true, true>( |
| 286 | pairDelim, keyValueDelim, mapKeyDedupPolicy, isFlinkCompatible); |
| 287 | } else { |
| 288 | return transmit<true, false>( |
| 289 | pairDelim, keyValueDelim, mapKeyDedupPolicy, isFlinkCompatible); |
| 290 | } |
| 291 | } else { |
| 292 | if (isKeyValueDelimReg) { |
| 293 | return transmit<false, true>( |
| 294 | pairDelim, keyValueDelim, mapKeyDedupPolicy, isFlinkCompatible); |
| 295 | } else { |
| 296 | return transmit<false, false>( |
| 297 | pairDelim, keyValueDelim, mapKeyDedupPolicy, isFlinkCompatible); |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | std::vector<std::shared_ptr<exec::FunctionSignature>> signatures() { |
| 303 | // varchar, varchar, varchar -> map(varchar, varchar) |
nothing calls this directly
no test coverage detected