| 1803 | } |
| 1804 | |
| 1805 | void MergeTreeMetaBase::checkColumnsValidity(const ColumnsDescription & columns, const ASTPtr & new_settings) const |
| 1806 | { |
| 1807 | NamesAndTypesList func_columns = getInMemoryMetadataPtr()->getFuncColumns(); |
| 1808 | MergeTreeSettingsPtr current_settings = getChangedSettings(new_settings); |
| 1809 | |
| 1810 | auto columns_physical = columns.getAllPhysical(); |
| 1811 | for (auto & column: columns_physical) |
| 1812 | { |
| 1813 | /// Check func columns |
| 1814 | for (auto & [name, type]: func_columns) |
| 1815 | { |
| 1816 | if (name == column.name) |
| 1817 | throw Exception("Column " + backQuoteIfNeed(column.name) + " is reserved column", ErrorCodes::BAD_ARGUMENTS); |
| 1818 | } |
| 1819 | |
| 1820 | /// block implicit key name for MergeTree family |
| 1821 | if (isMapImplicitKey(column.name)) |
| 1822 | throw Exception("Column " + backQuoteIfNeed(column.name) + " contains reserved prefix word", ErrorCodes::BAD_ARGUMENTS); |
| 1823 | |
| 1824 | /// Block implicit key name for MergeTree family |
| 1825 | if (column.type && column.type->isMap()) |
| 1826 | { |
| 1827 | const auto & type_map = typeid_cast<const DataTypeMap &>(*column.type); |
| 1828 | /// Check map validity |
| 1829 | type_map.checkValidity(); |
| 1830 | |
| 1831 | /// Check constraint for KVMap |
| 1832 | if (column.type->isKVMap()) |
| 1833 | { |
| 1834 | // To facilitate the processing of file formats compatible with community map and ByteKV map, we restrict the column names of KV map. |
| 1835 | for (const auto & key : MAP_KV_RESERVED_KEYS) |
| 1836 | { |
| 1837 | if (column.name.find(key) != String::npos) |
| 1838 | throw Exception( |
| 1839 | "Column " + backQuoteIfNeed(column.name) + " contains reserved prefix word " + key, ErrorCodes::BAD_ARGUMENTS); |
| 1840 | } |
| 1841 | } |
| 1842 | /// Check constraint for ByteMap |
| 1843 | else |
| 1844 | { |
| 1845 | /// To compatible with old table which may have a Map(xx, Nullable(xx)) type, we can't check this in DataTypeMap |
| 1846 | /// DataTypeLowCardinality->isNullable is false |
| 1847 | if (type_map.getValueType()->isNullable()) |
| 1848 | throw Exception( |
| 1849 | ErrorCodes::BAD_ARGUMENTS, |
| 1850 | "ByteMap column in table cannot have nullable value type, but column {} has type {}", |
| 1851 | backQuoteIfNeed(column.name), |
| 1852 | type_map.getName()); |
| 1853 | |
| 1854 | auto escape_name = escapeForFileName(column.name + getMapSeparator()); |
| 1855 | auto pos = escape_name.find(getMapSeparator()); |
| 1856 | /// The name of map column should not contain map separator, which is convenient for extracting map column name from a implicit column name. |
| 1857 | if (pos + getMapSeparator().size() != escape_name.size()) |
| 1858 | throw Exception( |
| 1859 | ErrorCodes::BAD_ARGUMENTS, |
| 1860 | "Map column name {} is invalid because its escaped name {} contains reserved prefix word {} of map implicit column", |
| 1861 | backQuoteIfNeed(column.name), |
| 1862 | backQuoteIfNeed(escape_name), |
nothing calls this directly
no test coverage detected