Skip to content

Commit

Permalink
Integrated IStreamConfiguration into QueryParser.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeHopcroft committed Sep 11, 2016
1 parent c0a2f49 commit 74dc10d
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/QueryParser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ COMBINE_FILE_LISTS()


add_executable(QueryParser ${CPPFILES} ${PRIVATE_HFILES} ${PUBLIC_HFILES})
target_link_libraries(QueryParser Utilities Plan)
target_link_libraries(QueryParser Utilities Configuration Plan)
set_property(TARGET QueryParser PROPERTY FOLDER "examples")
set_property(TARGET QueryParser PROPERTY PROJECT_LABEL "QueryParser")
10 changes: 9 additions & 1 deletion examples/QueryParser/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include <iostream>

#include "BitFunnel/Configuration/Factories.h"
#include "BitFunnel/Configuration/IStreamConfiguration.h"
#include "BitFunnel/Exceptions.h"
#include "BitFunnel/Plan/QueryPipeline.h"
#include "BitFunnel/Plan/TermMatchNode.h"
Expand Down Expand Up @@ -61,7 +63,13 @@ namespace BitFunnel

std::cout << welcome;

QueryPipeline pipeline;
// Configure parser for three named streams.
auto streamConfiguration = Factories::CreateStreamConfiguration();
streamConfiguration->AddMapping("body", { 0 });
streamConfiguration->AddMapping("title", { 123 });
streamConfiguration->AddMapping("anchors", { 10 });

QueryPipeline pipeline(*streamConfiguration);

for (;;)
{
Expand Down
4 changes: 4 additions & 0 deletions inc/BitFunnel/Configuration/Factories.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace BitFunnel

class IFileManager;
class IShardDefinition;
class IStreamConfiguration;

namespace Factories
{
Expand All @@ -45,5 +46,8 @@ namespace BitFunnel

std::unique_ptr<IShardDefinition> CreateShardDefinition();
std::unique_ptr<IShardDefinition> CreateShardDefinition(std::istream& input);

std::unique_ptr<IStreamConfiguration> CreateStreamConfiguration();
std::unique_ptr<IStreamConfiguration> CreateStreamConfiguration(std::istream& input);
}
}
4 changes: 3 additions & 1 deletion inc/BitFunnel/Plan/QueryPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@

namespace BitFunnel
{
class IStreamConfiguration;
class TermMatchNode;

class QueryPipeline
{
public:
QueryPipeline();
QueryPipeline(IStreamConfiguration const & streamConfiguration);

TermMatchNode const * ParseQuery(char const * query);

private:
IStreamConfiguration const & m_streamConfiguration;
std::unique_ptr<IAllocator> m_allocator;
};
}
12 changes: 12 additions & 0 deletions src/Common/Configuration/src/StreamConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,24 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#include "BitFunnel/Configuration/Factories.h"
#include "BitFunnel/Exceptions.h"
#include "StreamConfiguration.h"


namespace BitFunnel
{
std::unique_ptr<IStreamConfiguration> Factories::CreateStreamConfiguration()
{
return std::unique_ptr<IStreamConfiguration>(new StreamConfiguration());
}

std::unique_ptr<IStreamConfiguration> CreateStreamConfiguration(std::istream& /*input*/)
{
throw NotImplemented();
}


StreamConfiguration::StreamConfiguration()
{
}
Expand Down
11 changes: 7 additions & 4 deletions src/Plan/src/QueryParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <sstream>

#include "BitFunnel/Allocators/IAllocator.h"
#include "BitFunnel/Configuration/IStreamConfiguration.h"
#include "BitFunnel/Plan/TermMatchNode.h"
#include "BitFunnel/Utilities/StringBuilder.h"
#include "QueryParser.h"
Expand All @@ -35,8 +36,11 @@

namespace BitFunnel
{
QueryParser::QueryParser(std::istream& input, IAllocator& allocator)
QueryParser::QueryParser(std::istream& input,
IStreamConfiguration const & streamConfiguration,
IAllocator& allocator)
: m_input(input),
m_streamConfiguration(streamConfiguration),
m_allocator(allocator),
m_currentPosition(0),
m_haveChar(false)
Expand Down Expand Up @@ -305,10 +309,9 @@ namespace BitFunnel
}


Term::StreamId QueryParser::StreamIdFromText(char const * /*streamName*/) const
Term::StreamId QueryParser::StreamIdFromText(char const * streamName) const
{
// TODO: Return correct stream id here.
return 123;
return m_streamConfiguration.GetStreamId(streamName);
}


Expand Down
6 changes: 5 additions & 1 deletion src/Plan/src/QueryParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
namespace BitFunnel
{
class IAllocator;
class IStreamConfiguration;
class TermMatchNode;

class QueryParser
{
public:
QueryParser(std::istream& input, IAllocator& allocator);
QueryParser(std::istream& input,
IStreamConfiguration const & streamConfiguration,
IAllocator& allocator);

TermMatchNode const * Parse();

Expand Down Expand Up @@ -90,6 +93,7 @@ namespace BitFunnel
Term::StreamId StreamIdFromText(char const * /*streamName*/) const;

std::istream& m_input;
IStreamConfiguration const & m_streamConfiguration;
IAllocator& m_allocator;

// Used for errors.
Expand Down
7 changes: 4 additions & 3 deletions src/Plan/src/QueryPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@

namespace BitFunnel
{
QueryPipeline::QueryPipeline()
: m_allocator(new Allocator(4096))
QueryPipeline::QueryPipeline(IStreamConfiguration const & streamConfiguration)
: m_streamConfiguration(streamConfiguration),
m_allocator(new Allocator(4096))
{
}

Expand All @@ -39,7 +40,7 @@ namespace BitFunnel
{
m_allocator->Reset();
std::stringstream s(query);
QueryParser parser(s, *m_allocator);
QueryParser parser(s, m_streamConfiguration, *m_allocator);
return parser.Parse();
}
}
10 changes: 8 additions & 2 deletions src/Plan/test/QueryParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <sstream>

#include "Allocator.h"
#include "BitFunnel/Configuration/Factories.h"
#include "BitFunnel/Configuration/IStreamConfiguration.h"
#include "BitFunnel/Plan/TermMatchNode.h"
#include "BitFunnel/Utilities/TextObjectFormatter.h"
#include "QueryParser.h"
Expand All @@ -47,7 +49,7 @@ namespace BitFunnel
{"Unigram(\"wat\", 0)", "wat"},

// STREAM:UNIGRAM.
{"Unigram(\"wat\", 123)", "StreamsAreCurrentlyIgnored:wat"},
{"Unigram(\"wat\", 1)", "stream:wat"},

// (UNIGRAM)
{"Unigram(\"wat\", 0)", "(wat)"},
Expand Down Expand Up @@ -439,7 +441,11 @@ namespace BitFunnel

std::stringstream s;
s << input;
QueryParser parser(s, allocator);

auto streamConfiguration = Factories::CreateStreamConfiguration();
streamConfiguration->AddMapping("body", { 123 });
streamConfiguration->AddMapping("stream", { 123 });
QueryParser parser(s, *streamConfiguration, allocator);

//std::cout << "input length: " << s.str().size() << std::endl;
std::cout
Expand Down
5 changes: 4 additions & 1 deletion tools/IngestAndQuery/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <iostream>
#include <thread> // sleep_for, this_thread

#include "BitFunnel/Configuration/Factories.h"
#include "BitFunnel/Configuration/IStreamConfiguration.h"
#include "BitFunnel/Exceptions.h"
#include "BitFunnel/Index/IDocument.h"
#include "BitFunnel/Index/IDocumentCache.h"
Expand Down Expand Up @@ -595,7 +597,8 @@ namespace BitFunnel
<< m_query
<< "\"" << std::endl;

QueryPipeline pipeline;
auto streamConfiguration = Factories::CreateStreamConfiguration();
QueryPipeline pipeline(*streamConfiguration);
auto tree = pipeline.ParseQuery(m_query.c_str());
if (tree == nullptr)
{
Expand Down

0 comments on commit 74dc10d

Please sign in to comment.