forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee7d3c8
commit 1d9ce86
Showing
4 changed files
with
184 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#pragma once | ||
#include <Columns/ColumnString.h> | ||
#include <Columns/ColumnsNumber.h> | ||
#include <Core/Block.h> | ||
|
||
namespace debug | ||
{ | ||
|
||
void headBlock(const DB::Block & block, size_t count=10) | ||
{ | ||
std::cerr << "============Block============" << std::endl; | ||
// print header | ||
for (auto name : block.getNames()) | ||
{ | ||
std::cerr << name << "\t"; | ||
} | ||
std::cerr << std::endl; | ||
// print rows | ||
for (size_t row = 0; row < std::min(count, block.rows()); ++row) | ||
{ | ||
for (size_t column = 0; column < block.columns(); ++column) | ||
{ | ||
auto type = block.getByPosition(column).type; | ||
auto col = block.getByPosition(column).column; | ||
DB::WhichDataType which(type); | ||
if (which.isUInt()) | ||
{ | ||
auto value = DB::checkAndGetColumn<DB::ColumnUInt64>(*col)->getUInt(row); | ||
std::cerr << std::to_string(value) << "\t"; | ||
} | ||
else if (which.isString()) | ||
{ | ||
auto value = DB::checkAndGetColumn<DB::ColumnString>(*col)->getDataAt(row).toString(); | ||
std::cerr << value << "\t"; | ||
} | ||
else if (which.isInt()) | ||
{ | ||
auto value = col->getInt(row); | ||
std::cerr << std::to_string(value) << "\t"; | ||
} | ||
else if (which.isFloat32()) | ||
{ | ||
auto value = col->getFloat32(row); | ||
std::cerr << std::to_string(value) << "\t"; | ||
} | ||
else if (which.isFloat64()) | ||
{ | ||
auto value = col->getFloat64(row); | ||
std::cerr << std::to_string(value) << "\t"; | ||
} | ||
else | ||
{ | ||
std::cerr << "N/A" | ||
<< "\t"; | ||
} | ||
} | ||
std::cerr << std::endl; | ||
} | ||
} | ||
|
||
void headColumn(const DB::ColumnPtr column, size_t count=10) | ||
{ | ||
std::cerr << "============Column============" << std::endl; | ||
// print header | ||
|
||
std::cerr << column->getName() << "\t"; | ||
std::cerr << std::endl; | ||
// print rows | ||
for (size_t row = 0; row < std::min(count, column->size()); ++row) | ||
{ | ||
auto type = column->getDataType(); | ||
auto col = column; | ||
DB::WhichDataType which(type); | ||
if (which.isUInt()) | ||
{ | ||
auto value = DB::checkAndGetColumn<DB::ColumnUInt64>(*col)->getUInt(row); | ||
std::cerr << std::to_string(value) << std::endl; | ||
} | ||
else if (which.isString()) | ||
{ | ||
auto value = DB::checkAndGetColumn<DB::ColumnString>(*col)->getDataAt(row).toString(); | ||
std::cerr << value << std::endl; | ||
} | ||
else if (which.isInt()) | ||
{ | ||
auto value = col->getInt(row); | ||
std::cerr << std::to_string(value) << std::endl; | ||
} | ||
else if (which.isFloat32()) | ||
{ | ||
auto value = col->getFloat32(row); | ||
std::cerr << std::to_string(value) << std::endl; | ||
} | ||
else if (which.isFloat64()) | ||
{ | ||
auto value = col->getFloat64(row); | ||
std::cerr << std::to_string(value) << std::endl; | ||
} | ||
else | ||
{ | ||
std::cerr << "N/A" | ||
<< std::endl; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <Functions/FunctionFactory.h> | ||
#include <Parser/SerializedPlanParser.h> | ||
#include <Common/DebugUtils.h> | ||
#include <gtest/gtest.h> | ||
|
||
TEST(TestFuntion, hash) | ||
{ | ||
auto & factory = DB::FunctionFactory::instance(); | ||
auto function = factory.get("murmurHash2_64", local_engine::SerializedPlanParser::global_context); | ||
auto type0 = DataTypeFactory::instance().get("String"); | ||
auto column0 = type0->createColumn(); | ||
column0->insert("A"); | ||
column0->insert("A"); | ||
column0->insert("B"); | ||
column0->insert("c"); | ||
|
||
auto column1 = type0->createColumn(); | ||
column1->insert("X"); | ||
column1->insert("X"); | ||
column1->insert("Y"); | ||
column1->insert("Z"); | ||
|
||
ColumnsWithTypeAndName columns = {ColumnWithTypeAndName(std::move(column0),type0, "string0"), | ||
ColumnWithTypeAndName(std::move(column1),type0, "string0")}; | ||
Block block(columns); | ||
std::cerr << "input:\n"; | ||
debug::headBlock(block); | ||
auto executable = function->build(block.getColumnsWithTypeAndName()); | ||
auto result = executable->execute(block.getColumnsWithTypeAndName(), executable->getResultType(), block.rows()); | ||
std::cerr << "output:\n"; | ||
debug::headColumn(result); | ||
ASSERT_EQ(result->getUInt(0), result->getUInt(1)); | ||
} | ||
|
||
|
||
//int main(int argc, char ** argv) | ||
//{ | ||
// SharedContextHolder shared_context = Context::createShared(); | ||
// local_engine::SerializedPlanParser::global_context = Context::createGlobal(shared_context.get()); | ||
// local_engine::SerializedPlanParser::global_context->makeGlobalContext(); | ||
// local_engine::SerializedPlanParser::initFunctionEnv(); | ||
// ::testing::InitGoogleTest(&argc, argv); | ||
// return RUN_ALL_TESTS(); | ||
//} |