This impacts the Grafana plugin.

From https://github.com/grafana/clickhouse-datasource/issues/198


    if an adhoc filter is specified for the field t1_distributed.f2
        the following query will be built by the plugin SELECT f1 from t1_distributed settings additional_table_filters = {'t1_distributed': 'f2 = xxx'}
        this query will actually not do its job of filtering
        i guess it is coming from the fact that additional_table_filters are applied by clickhouse when it reads the table....but distributed tables are not read.....
        if i replace in the built query, within the additional_table_filters settings, t1_distributed with t1_local (so a query like `SELECT f1 from t1_distributed settings additional_table_filters = {'t1_local': 'f2 = xxx'}), then it is working as expected
    i gave a try to add an adhoc filter on the "local" table (while my "main" query is still on the distributed table) (ie define an adhoc filter on the fied t1_local.f2)
        then the built query by the plugin does not include any additional_table_filters settings (i guess there is a check in order to add additional_table_filters only on the table used in the query)




visitor.visit(query_ast_for_shard);
        }
        else
            query_ast_for_shard = query_ast;
        auto shard_plans = stream_factory.createForShardWithParallelReplicas(shard_info,
            query_ast_for_shard, main_table, table_func_ptr, throttler, context, shards, query_info.storage_limits);
        if (!shard_plans.local_plan && !shard_plans.remote_plan)
            throw Exception(ErrorCodes::LOGICAL_ERROR, "No plans were generated for reading from shard. This is a bug");
        if (shard_plans.local_plan)
            plans.emplace_back(std::move(shard_plans.local_plan));
        if (shard_plans.remote_plan)
            plans.emplace_back(std::move(shard_plans.remote_plan));
    }
    if (plans.empty())
        throw Exception(ErrorCodes::LOGICAL_ERROR, "No plans were generated for reading from Distributed. This is a bug");
    if (plans.size() == 1)
    {
        query_plan = std::move(*plans.front());
        return;
    }
    DataStreams input_streams;
    input_streams.reserve(plans.size());
    for (const auto & plan : plans)
        input_streams.emplace_back(plan->getCurrentDataStream());
    auto union_step = std::make_unique<UnionStep>(std::move(input_streams));
    query_plan.unitePlans(std::move(union_step), std::move(plans));
}
}
}