Skip to content

Commit

Permalink
fix mat column with mat view push broken case
Browse files Browse the repository at this point in the history
  • Loading branch information
ozcelgozde authored May 31, 2024
2 parents 1958243 + 20420a0 commit 56377be
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docker/debian/base/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ sed -i \
-e "s/set (VERSION_SCM [^) ]*/set (VERSION_SCM $VERSION_SCM/g;" \
cmake/version.cmake

cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ${CMAKE_FLAGS} -DENABLE_BREAKPAD=ON -DCMAKE_INSTALL_PREFIX=build_install -S . -B build_docker
cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ${CMAKE_FLAGS} -DENABLE_BREAKPAD=OFF -DCMAKE_INSTALL_PREFIX=build_install -S . -B build_docker
NUM_JOBS=$(( ($(nproc || grep -c ^processor /proc/cpuinfo) + 1) / 2 ))

ninja -C build_docker -j $NUM_JOBS install
2 changes: 1 addition & 1 deletion docker/packager/binary/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ccache_status
ccache --zero-stats ||:

# Build everything
cmake --debug-trycompile -DCMAKE_VERBOSE_MAKEFILE=1 -LA "-DCMAKE_BUILD_TYPE=$BUILD_TYPE" -DENABLE_CHECK_HEAVY_BUILDS=0 -DENABLE_BREAKPAD=ON "${CMAKE_FLAGS[@]}" ..
cmake --debug-trycompile -DCMAKE_VERBOSE_MAKEFILE=1 -LA "-DCMAKE_BUILD_TYPE=$BUILD_TYPE" -DENABLE_CHECK_HEAVY_BUILDS=0 -DENABLE_BREAKPAD=OFF "${CMAKE_FLAGS[@]}" ..

# No quotes because I want it to expand to nothing if empty.
# shellcheck disable=SC2086 # No quotes because I want it to expand to nothing if empty.
Expand Down
16 changes: 6 additions & 10 deletions src/DataStreams/PushingToViewsBlockOutputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ PushingToViewsBlockOutputStream::PushingToViewsBlockOutputStream(
if (dynamic_cast<const StorageView *>(view_table.get()))
continue;

Block output_header;
if (auto * materialized_view = dynamic_cast<StorageMaterializedView *>(view_table.get()))
{
if (materialized_view->async())
Expand All @@ -167,7 +166,6 @@ PushingToViewsBlockOutputStream::PushingToViewsBlockOutputStream(
{
auto target_metadata_snapshot = cnch_target_table->getInMemoryMetadataPtr();
out = std::make_shared<CloudMergeTreeBlockOutputStream>(*cnch_target_table, target_metadata_snapshot, insert_context);
output_header = target_metadata_snapshot->getSampleBlockNonMaterialized(true);
}
else
{
Expand All @@ -181,12 +179,13 @@ PushingToViewsBlockOutputStream::PushingToViewsBlockOutputStream(
auto header = InterpreterSelectQuery(query, select_context, SelectQueryOptions().analyze())
.getSampleBlock();

/// Select columns without materialized columns and columns function of uniq merge tree.
/// Insert only columns returned by select.
auto list = std::make_shared<ASTExpressionList>();
const auto & target_table_columns = target_metadata_snapshot->getSampleBlockNonMaterialized(true);
const auto & target_table_columns = target_metadata_snapshot->getColumns();
for (const auto & column : header)
{
if (target_table_columns.has(column.name))
// But skip columns which storage doesn't have.
if (target_table_columns.hasPhysical(column.name))
list->children.emplace_back(std::make_shared<ASTIdentifier>(column.name));
}

Expand All @@ -195,22 +194,19 @@ PushingToViewsBlockOutputStream::PushingToViewsBlockOutputStream(
InterpreterInsertQuery interpreter(insert_query_ptr, insert_context);
BlockIO io = interpreter.execute();
out = io.out;
output_header = out->getHeader();
}
}
else if (dynamic_cast<const StorageLiveView *>(view_table.get()))
{
out = std::make_shared<PushingToViewsBlockOutputStream>(
view_table, dependent_metadata_snapshot, insert_context, ASTPtr(), true);
output_header = dependent_metadata_snapshot->getSampleBlockNonMaterialized(true);
}
else
{
out = std::make_shared<PushingToViewsBlockOutputStream>(view_table, dependent_metadata_snapshot, insert_context, ASTPtr());
output_header = dependent_metadata_snapshot->getSampleBlockNonMaterialized(true);
}

views.emplace_back(ViewInfo{std::move(query), database_table, std::move(out), nullptr, 0, output_header});
views.emplace_back(ViewInfo{std::move(query), database_table, std::move(out), nullptr, 0});
}

/// Do not push to destination table if the flag is set
Expand Down Expand Up @@ -539,7 +535,7 @@ void PushingToViewsBlockOutputStream::process(const Block & block, ViewInfo & vi
/// and two-level aggregation is triggered).
in = std::make_shared<SquashingBlockInputStream>(
in, getContext()->getSettingsRef().min_insert_block_size_rows, getContext()->getSettingsRef().min_insert_block_size_bytes);
in = std::make_shared<ConvertingBlockInputStream>(in, view.output_header ? view.output_header : view.out->getHeader(), ConvertingBlockInputStream::MatchColumnsMode::Name);
in = std::make_shared<ConvertingBlockInputStream>(in, view.out->getHeader(), ConvertingBlockInputStream::MatchColumnsMode::Name);
}
else
in = std::make_shared<OneBlockInputStream>(block);
Expand Down
1 change: 0 additions & 1 deletion src/DataStreams/PushingToViewsBlockOutputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class PushingToViewsBlockOutputStream : public IBlockOutputStream, WithContext
BlockOutputStreamPtr out;
std::exception_ptr exception;
UInt64 elapsed_ms = 0;
Block output_header;
};

std::vector<ViewInfo> views;
Expand Down
14 changes: 7 additions & 7 deletions src/Interpreters/InterpreterCreateQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1580,13 +1580,13 @@ bool InterpreterCreateQuery::doCreateTable(ASTCreateQuery & create,
if (view->tryGetTargetTable() && !view->hasInnerTable())
{
StoragePtr target_table = view->tryGetTargetTable();
if (!target_table->getInMemoryMetadataPtr()->getColumns().getMaterialized().empty())
throw Exception(
ErrorCodes::ILLEGAL_COLUMN,
"Cannot create materialized view {} to target table {} with materialized columns {}",
view->getStorageID().getNameForLogs(),
target_table->getStorageID().getNameForLogs(),
target_table->getInMemoryMetadataPtr()->getColumns().getMaterialized().toString());
// if (!target_table->getInMemoryMetadataPtr()->getColumns().getMaterialized().empty())
// throw Exception(
// ErrorCodes::ILLEGAL_COLUMN,
// "Cannot create materialized view {} to target table {} with materialized columns {}",
// view->getStorageID().getNameForLogs(),
// target_table->getStorageID().getNameForLogs(),
// target_table->getInMemoryMetadataPtr()->getColumns().getMaterialized().toString());
}
}
}
Expand Down

0 comments on commit 56377be

Please sign in to comment.