Merge branch 'master' into add_CORS

This commit is contained in:
Filatenkov Artur 2021-10-06 16:09:34 +03:00 committed by GitHub
commit 545673248a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 81 additions and 35 deletions

View File

@ -33,6 +33,7 @@
:root {
--background-color: #DDF8FF; /* Or #FFFBEF; actually many pastel colors look great for light theme. */
--element-background-color: #FFF;
--bar-color: #F8F4F0; /* Light bar in background of table cells. */
--border-color: #EEE;
--shadow-color: rgba(0, 0, 0, 0.1);
--button-color: #FFAA00; /* Orange on light-cyan is especially good. */
@ -52,6 +53,7 @@
[data-theme="dark"] {
--background-color: #000;
--element-background-color: #102030;
--bar-color: #182838;
--border-color: #111;
--shadow-color: rgba(255, 255, 255, 0.1);
--text-color: #CCC;
@ -568,17 +570,20 @@
let thead = document.createElement('thead');
for (let idx in response.meta) {
let th = document.createElement('th');
let name = document.createTextNode(response.meta[idx].name);
const name = document.createTextNode(response.meta[idx].name);
th.appendChild(name);
thead.appendChild(th);
}
/// To prevent hanging the browser, limit the number of cells in a table.
/// It's important to have the limit on number of cells, not just rows, because tables may be wide or narrow.
let max_rows = 10000 / response.meta.length;
const max_rows = 10000 / response.meta.length;
let row_num = 0;
let column_classes = response.meta.map(elem => elem.type.match(/^(U?Int|Decimal|Float)/) ? 'right' : 'left');
const column_is_number = response.meta.map(elem => !!elem.type.match(/^(U?Int|Decimal|Float)/));
const column_maximums = column_is_number.map((elem, idx) => elem ? Math.max(...response.data.map(row => row[idx])) : 0);
const column_minimums = column_is_number.map((elem, idx) => elem ? Math.min(...response.data.map(row => Math.max(0, row[idx]))) : 0);
const column_need_render_bars = column_is_number.map((elem, idx) => column_maximums[idx] > 0 && column_maximums[idx] > column_minimums[idx]);
let tbody = document.createElement('tbody');
for (let row_idx in response.data) {
@ -614,11 +619,27 @@
node = link;
}
td.appendChild(node);
td.className = column_classes[col_idx];
td.className = column_is_number[col_idx] ? 'right' : 'left';
if (is_null) {
td.className += ' null';
}
/// If it's a number, render bar in background.
if (column_need_render_bars[col_idx] && text > 0) {
const ratio = 100 * text / column_maximums[col_idx];
let div = document.createElement('div');
div.style.width = '100%';
div.style.background = `linear-gradient(to right,
var(--bar-color) 0%, var(--bar-color) ${ratio}%,
transparent ${ratio}%, transparent 100%)`;
div.appendChild(node);
node = div;
}
td.appendChild(node);
tr.appendChild(td);
}
tbody.appendChild(tr);

View File

@ -67,9 +67,11 @@ public:
const auto * type_col = checkAndGetColumnConst<ColumnString>(column.get());
if (!type_col)
throw Exception("Second argument to " + getName() + " must be a constant string describing type."
" Instead there is non-constant column of type " + arguments.back().type->getName(),
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
"Second argument to {} must be a constant string describing type."
" Instead there is non-constant column of type {}",
getName(),
arguments.back().type->getName());
DataTypePtr to_type = DataTypeFactory::instance().get(type_col->getValue<String>());
@ -78,30 +80,34 @@ public:
if (result_reinterpret_type.isFixedString())
{
if (!from_type->isValueUnambiguouslyRepresentedInFixedSizeContiguousMemoryRegion())
throw Exception("Cannot reinterpret " + from_type->getName() +
" as FixedString because it is not fixed size and contiguous in memory",
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
"Cannot reinterpret {} as FixedString because it is not fixed size and contiguous in memory",
from_type->getName());
}
else if (result_reinterpret_type.isString())
{
if (!from_type->isValueUnambiguouslyRepresentedInContiguousMemoryRegion())
throw Exception("Cannot reinterpret " + from_type->getName() +
" as String because it is not contiguous in memory",
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
"Cannot reinterpret {} as String because it is not contiguous in memory",
from_type->getName());
}
else if (canBeReinterpretedAsNumeric(result_reinterpret_type))
{
WhichDataType from_data_type(from_type);
if (!canBeReinterpretedAsNumeric(from_data_type) && !from_data_type.isStringOrFixedString())
throw Exception("Cannot reinterpret " + from_type->getName() + " as " + to_type->getName()
+ " because only Numeric, String or FixedString can be reinterpreted in Numeric",
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
"Cannot reinterpret {} as {} because only Numeric, String or FixedString can be reinterpreted in Numeric",
from_type->getName(),
to_type->getName());
}
else
throw Exception("Cannot reinterpret " + from_type->getName() + " as " + to_type->getName()
+ " because only reinterpretation in String, FixedString and Numeric types is supported",
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
{
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
"Cannot reinterpret {} as {} because only reinterpretation in String, FixedString and Numeric types is supported",
from_type->getName(),
to_type->getName());
}
return to_type;
}
@ -156,7 +162,6 @@ public:
}
else if constexpr (CanBeReinterpretedAsNumeric<ToType>)
{
using ToColumnType = typename ToType::ColumnType;
using ToFieldType = typename ToType::FieldType;
if constexpr (std::is_same_v<FromType, DataTypeString>)
@ -165,10 +170,10 @@ public:
auto col_res = numericColumnCreateHelper<ToType>(static_cast<const ToType&>(*result_type.get()));
const ColumnString::Chars & data_from = col_from->getChars();
const ColumnString::Offsets & offsets_from = col_from->getOffsets();
const auto & data_from = col_from->getChars();
const auto & offsets_from = col_from->getOffsets();
size_t size = offsets_from.size();
typename ToColumnType::Container & vec_res = col_res->getData();
auto & vec_res = col_res->getData();
vec_res.resize(size);
size_t offset = 0;
@ -192,10 +197,10 @@ public:
auto col_res = numericColumnCreateHelper<ToType>(static_cast<const ToType&>(*result_type.get()));
const ColumnString::Chars & data_from = col_from_fixed->getChars();
const auto& data_from = col_from_fixed->getChars();
size_t step = col_from_fixed->getN();
size_t size = data_from.size() / step;
typename ToColumnType::Container & vec_res = col_res->getData();
auto & vec_res = col_res->getData();
vec_res.resize(size);
size_t offset = 0;
@ -243,8 +248,10 @@ public:
return false;
}))
{
throw Exception("Cannot reinterpret " + from_type->getName() + " as " + result_type->getName(),
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
"Cannot reinterpret {} as {}",
from_type->getName(),
result_type->getName());
}
return result;
@ -255,6 +262,7 @@ private:
IsDataTypeDecimalOrNumber<T> ||
std::is_same_v<T, DataTypeDate> ||
std::is_same_v<T, DataTypeDateTime> ||
std::is_same_v<T, DataTypeDateTime64> ||
std::is_same_v<T, DataTypeUUID>;
static bool canBeReinterpretedAsNumeric(const WhichDataType & type)
@ -359,9 +367,12 @@ public:
size_t getNumberOfArguments() const override { return 1; }
bool useDefaultImplementationForConstants() const override { return true; }
bool useDefaultImplementationForConstants() const override { return impl.useDefaultImplementationForConstants(); }
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return false; }
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & arguments) const override
{
return impl.isSuitableForShortCircuitArgumentsExecution(arguments);
}
static ColumnsWithTypeAndName addTypeColumnToArguments(const ColumnsWithTypeAndName & arguments)
{
@ -374,9 +385,9 @@ public:
const auto & type = argument.type;
if (!type->isValueUnambiguouslyRepresentedInFixedSizeContiguousMemoryRegion())
throw Exception("Cannot reinterpret " + type->getName() +
" as FixedString because it is not fixed size and contiguous in memory",
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
"Cannot reinterpret {} as FixedString because it is not fixed size and contiguous in memory",
type->getName());
size_t type_value_size_in_memory = type->getSizeOfValueInMemory();
data_type = std::make_shared<DataTypeFixedString>(type_value_size_in_memory);

View File

@ -103,12 +103,14 @@ public:
});
}
/// Handle POST or GET with params or OPTIONS queries
/// Handle Post request or (Get or Head) with params or OPTIONS requests
void allowPostAndGetParamsAndOptionsRequest()
{
addFilter([](const auto & request)
{
return request.getURI().find('?') != std::string::npos
return (request.getURI().find('?') != std::string::npos
&& (request.getMethod() == Poco::Net::HTTPRequest::HTTP_GET
|| request.getMethod() == Poco::Net::HTTPRequest::HTTP_HEAD))
|| request.getMethod() == Poco::Net::HTTPRequest::HTTP_OPTIONS
|| request.getMethod() == Poco::Net::HTTPRequest::HTTP_POST;
});

View File

@ -0,0 +1,3 @@
< HTTP/1.1 200 OK
< HTTP/1.1 501 Not Implemented
< HTTP/1.1 200 OK

View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh
$CLICKHOUSE_CURL "${CLICKHOUSE_URL}" -X GET -d "SELECT 1" -vs 2>&1 | grep "OK"
$CLICKHOUSE_CURL "${CLICKHOUSE_URL}" -X aaa -vs 2>&1 | grep "Not Implemented"
$CLICKHOUSE_CURL "${CLICKHOUSE_URL}" -d "SELECT 1" -vs 2>&1 | grep "OK"