mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 07:01:59 +00:00
Add hints for enum names
add test
This commit is contained in:
parent
6f08f945e8
commit
59f5f2d03c
@ -66,11 +66,22 @@ T EnumValues<T>::getValue(StringRef field_name, bool try_treat_as_id) const
|
||||
if (tmp_buf.eof() && value_to_name_map.find(x) != value_to_name_map.end())
|
||||
return x;
|
||||
}
|
||||
throw Exception{"Unknown element '" + field_name.toString() + "' for enum", ErrorCodes::BAD_ARGUMENTS};
|
||||
auto hints = this->getHints(field_name.toString());
|
||||
auto hints_string = !hints.empty() ? ", may be you meant: " + toString(hints) : "";
|
||||
throw Exception{"Unknown element '" + field_name.toString() + "' for enum" + hints_string, ErrorCodes::BAD_ARGUMENTS};
|
||||
}
|
||||
return it->getMapped();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Names EnumValues<T>::getAllRegisteredNames() const
|
||||
{
|
||||
Names result;
|
||||
for (const auto & value : values)
|
||||
result.emplace_back(value.first);
|
||||
return result;
|
||||
}
|
||||
|
||||
template class EnumValues<Int8>;
|
||||
template class EnumValues<Int16>;
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <Common/HashTable/HashMap.h>
|
||||
#include <unordered_map>
|
||||
#include <Common/HashTable/HashMap.h>
|
||||
#include <Common/NamePrompter.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
@ -12,7 +13,7 @@ namespace ErrorCodes
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
class EnumValues
|
||||
class EnumValues : public IHints<1, EnumValues<T>>
|
||||
{
|
||||
public:
|
||||
using Value = std::pair<std::string, T>;
|
||||
@ -65,6 +66,8 @@ public:
|
||||
|
||||
return std::all_of(rhs_values.begin(), rhs_values.end(), check);
|
||||
}
|
||||
|
||||
Names getAllRegisteredNames() const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
OK
|
8
tests/queries/0_stateless/01852_hints_enum_name.sh
Executable file
8
tests/queries/0_stateless/01852_hints_enum_name.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
# shellcheck source=../shell_config.sh
|
||||
. "$CURDIR"/../shell_config.sh
|
||||
|
||||
$CLICKHOUSE_CLIENT --query="SELECT CAST('Helo', 'Enum(\'Hello\' = 1, \'World\' = 2)')" 2>&1 | grep -q "may be you meant: \['Hello'\]" && echo 'OK' || echo 'FAIL'
|
||||
|
Loading…
Reference in New Issue
Block a user