Skip to content

filter column must be uint8 in tiflash #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Aug 16, 2019
39 changes: 38 additions & 1 deletion dbms/src/Flash/Coprocessor/DAGExpressionAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

#include <AggregateFunctions/AggregateFunctionFactory.h>
#include <Columns/ColumnSet.h>
#include <Common/typeid_cast.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless include?

#include <DataTypes/DataTypeNullable.h>
#include <DataTypes/DataTypeSet.h>
#include <DataTypes/DataTypesNumber.h>
#include <DataTypes/FieldToDataType.h>
#include <Flash/Coprocessor/DAGUtils.h>
#include <Functions/FunctionFactory.h>
Expand Down Expand Up @@ -103,6 +106,23 @@ void DAGExpressionAnalyzer::appendAggregation(
after_agg = true;
}

bool isUInt8Type(const DataTypePtr & type)
{
if (typeid_cast<const DataTypeUInt8 *>(type.get()))
{
return true;
}
if (type->isNullable())
Copy link
Contributor

@zanmato1984 zanmato1984 Aug 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest write this function like:

{
  auto nested = type->isNullable() ? std::dynamic_pointer_cast<DataTypeNullable>(type)->getNestedType() : type;
  return std::dynamic_pointer_cast<DataTypeUInt8>(nested);
}

It's shorter.

{
auto * nullable = typeid_cast<const DataTypeNullable *>(type.get());
if (typeid_cast<const DataTypeUInt8 *>(nullable->getNestedType().get()))
{
return true;
}
}
return false;
}

void DAGExpressionAnalyzer::appendWhere(ExpressionActionsChain & chain, const tipb::Selection & sel, String & filter_column_name)
{
if (sel.conditions_size() == 0)
Expand All @@ -124,7 +144,24 @@ void DAGExpressionAnalyzer::appendWhere(ExpressionActionsChain & chain, const ti

const tipb::Expr & filter = sel.conditions_size() > 1 ? final_condition : sel.conditions(0);
initChain(chain, getCurrentInputColumns());
filter_column_name = getActions(filter, chain.steps.back().actions);
ExpressionActionsChain::Step & last_step = chain.steps.back();
filter_column_name = getActions(filter, last_step.actions);
auto & filter_column_type = chain.steps.back().actions->getSampleBlock().getByName(filter_column_name).type;
if (!isUInt8Type(filter_column_type))
{
// find the original unit8 column
auto & last_actions = last_step.actions->getActions();
for (auto it = last_actions.rbegin(); it != last_actions.rend(); ++it)
{
if (it->type == ExpressionAction::Type::APPLY_FUNCTION && it->result_name == filter_column_name
&& it->function->getName() == "CAST")
{
// for cast function, the casted column is the first argument
filter_column_name = it->argument_names[0];
break;
}
}
}
chain.steps.back().required_output.push_back(filter_column_name);
}

Expand Down
2 changes: 2 additions & 0 deletions dbms/src/Flash/Coprocessor/DAGQuerySource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ bool fillExecutorOutputFieldTypes(const tipb::Executor & executor, std::vector<t
{
field_type.set_tp(ci.tp());
field_type.set_flag(ci.flag());
field_type.set_flen(ci.columnlen());
field_type.set_decimal(ci.decimal());
output_field_types.push_back(field_type);
}
return true;
Expand Down