Skip to content

Commit

Permalink
Merge pull request #7689 from ClickHouse/constants-and-remote
Browse files Browse the repository at this point in the history
Fix remote constants.

(cherry picked from commit 2233660)
  • Loading branch information
KochetovNicolai committed Nov 9, 2019
1 parent c953312 commit cf5bd81
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
28 changes: 25 additions & 3 deletions dbms/src/DataStreams/RemoteBlockInputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <DataStreams/OneBlockInputStream.h>
#include <Common/NetException.h>
#include <Common/CurrentThread.h>
#include <Columns/ColumnConst.h>
#include <Interpreters/Context.h>
#include <Interpreters/castColumn.h>
#include <Interpreters/InternalTextLogsQueue.h>
Expand Down Expand Up @@ -173,9 +174,30 @@ static Block adaptBlockStructure(const Block & block, const Block & header, cons
ColumnPtr column;

if (elem.column && isColumnConst(*elem.column))
/// TODO: check that column from block contains the same value.
/// TODO: serialize const columns.
column = elem.column->cloneResized(block.rows());
{
/// We expect constant column in block.
/// If block is not empty, then get value for constant from it,
/// because it may be different for remote server for functions like version(), uptime(), ...
if (block.rows() > 0 && block.has(elem.name))
{
/// Const column is passed as materialized. Get first value from it.
///
/// TODO: check that column contains the same value.
/// TODO: serialize const columns.
auto col = block.getByName(elem.name);
col.column = block.getByName(elem.name).column->cut(0, 1);

column = castColumn(col, elem.type, context);

if (!isColumnConst(*column))
column = ColumnConst::create(column, block.rows());
else
/// It is not possible now. Just in case we support const columns serialization.
column = column->cloneResized(block.rows());
}
else
column = elem.column->cloneResized(block.rows());
}
else
column = castColumn(block.getByName(elem.name), elem.type, context);

Expand Down
Empty file.
21 changes: 21 additions & 0 deletions dbms/tests/integration/test_replicating_constants/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest

from helpers.cluster import ClickHouseCluster

cluster = ClickHouseCluster(__file__)

node1 = cluster.add_instance('node1', with_zookeeper=True)
node2 = cluster.add_instance('node2', with_zookeeper=True, image='yandex/clickhouse-server:19.1.14', with_installed_binary=True)

@pytest.fixture(scope="module")
def start_cluster():
try:
cluster.start()

yield cluster
finally:
cluster.shutdown()

def test_different_versions(start_cluster):

assert node1.query("SELECT uniqExact(x) FROM (SELECT version() as x from remote('node{1,2}', system.one))") == "2\n"

0 comments on commit cf5bd81

Please sign in to comment.