//////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2017 KDE Laboratory, University of Tsukuba, Tsukuba, Japan.            //
//                                                                                      //
// The JsSpinnerSPE/StreamingCube and the accompanying materials are made available     //
// under the terms of Eclipse Public License v1.0 which accompanies this distribution   //
// and is available at <https://eclipse.org/org/documents/epl-v10.php>                  //
//////////////////////////////////////////////////////////////////////////////////////////

#include "../Common/stdafx.h"
#include "../BinaryJson/json.h"
#include "../Common/Types.h"
#include "../Internal/Element/Element.h"
#include "../Query/QueryIntermediateRepresentation.h"
#include "../Server/JsonStreamServer.h"
#include "../Schema/JsonSchema.h"
#include "../IO/SocketStreamOutput.h"
#include "../IO/csvOutput.h"
#include "../IO/IOManager.h"
#include "../IO/IStreamOutput.h"
#include "../Parser/ParserManager.h"
#include "../Configure/ConfigureManager.h"
#include "../Query/GetJaqlQuery.h"
#include "../Utility/TimeCounterUtility.h"
#include "../OLAP/MaterializedLattice.h"
#include "../OLAP/OLAPManager.h"
#include "../Operator/CubifyOperator.h"

#include <boost/asio.hpp>
#include <boost/asio/streambuf.hpp>
#include <boost/regex.hpp>
#include <iostream>
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>
#include <sys/types.h>
#include <fstream>

#ifdef PROFILER
#include  <google/profiler.h>
#endif

int main()
{
// Saving own PID
ofstream PIDFile;
PIDFile.open ("myPID.txt");
PIDFile << getpid();
PIDFile.close();

#ifdef PROFILER
	 ProfilerStart("MyProfile.prof");
#endif
	JsonStreamServer* server = JsonStreamServer::getInstance();

    std::string streamWindowSize = ConfigureManager::getInstance()->getConfigureValue("streamWindowSize");
	std::string stream1WindowSize = ConfigureManager::getInstance()->getConfigureValue("stream1_window_size");
	std::string stream2WindowSize = ConfigureManager::getInstance()->getConfigureValue("stream2_window_size");
	std::string stream3WindowSize = ConfigureManager::getInstance()->getConfigureValue("stream3_window_size");
	std::string stream4WindowSize = ConfigureManager::getInstance()->getConfigureValue("stream4_window_size");
	std::string activateDuration = ConfigureManager::getInstance()->getConfigureValue("activate_duration");

	std::string nodeType = ConfigureManager::getInstance()->getConfigureValue("node_type");
	std::string queryIndex = ConfigureManager::getInstance()->getConfigureValue("query_index");
	std::string querySource = ConfigureManager::getInstance()->getConfigureValue("query_source");
	std::string jaqlQuery = GetJaqlQuery::getInstance()->getJaqlQuery("Q1");

    std::string query0 =
	"stream1 = readFromWrapper (\"performanceTestStream2\", true) ;\
	tmp1 = stream1 -> window[range "+ stream2WindowSize +" seconds] ;\
	tmp1 -> istream;";

    std::string query1 =
	"stream1 = readFromWrapper (\"performanceTestStream1\", true) ;\
	stream2 = readFromWrapper (\"performanceTestStream2\", false) ;\
	tmp1 = stream1 -> window[range "+ stream1WindowSize +" seconds] ;\
	tmp2 = stream2 -> window[rows "+ stream2WindowSize +"] ; \
	j = join s in tmp1,\
           	d in tmp2\
		where s.A == d.A\
		into {s.B, d.C};\
	j -> istream;";

    // Simple join query
    //std::string queryIntermediateRepresentation1 = "{\"type\":\"root\",\"input\":{\"type\":\"istream\",\"input\":{\"type\":\"join\",\"left_join_attribute\":[\"A\"],\"right_join_attribute\":[\"A\"],\"left_outer\":false,\"right_outer\":false,\"projection\":{\"type\":\"projection_obj\",\"projection_type\":\"object\",\"fields\":[{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"B\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"C\"],\"attribute_source\":\"right\"}}]},\"left_input\":{\"type\":\"rangewindow\",\"windowsize\":\"" + stream1WindowSize + " milliseconds\",\"input\":{\"type\":\"leaf\",\"stream_source\":\"performanceTestStream1\",\"is_master\":true}},\"right_input\":{\"type\":\"rowwindow\",\"windowsize\":"+ stream2WindowSize +",\"input\":{\"type\":\"leaf\",\"stream_source\":\"performanceTestStream2\",\"is_master\":false}}}}}";

    // Synthetic data (StreamOLAP Query)
    //Query with 3 dimension and a fact join with 5 dimension ID and names
    //std::string queryIntermediateRepresentation1 = "{\"type\":\"root\",\"input\":{\"type\":\"cubify\",\"input\":{\"type\":\"join\",\"left_join_attribute\":[\"promoID\"],\"right_join_attribute\":[\"promoID\"],\"left_outer\":false,\"right_outer\":false,\"projection\":{\"type\":\"projection_obj\",\"projection_type\":\"object\",\"fields\":[{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"prodID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"prodName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"promoID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"promoName\"],\"attribute_source\":\"right\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeArea\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesAmountFACT\"],\"attribute_source\":\"left\"}}]},\"left_input\":{\"type\":\"join\",\"left_join_attribute\":[\"suppID\"],\"right_join_attribute\":[\"suppID\"],\"left_outer\":false,\"right_outer\":false,\"projection\":{\"type\":\"projection_obj\",\"projection_type\":\"object\",\"fields\":[{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"prodID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"prodName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppName\"],\"attribute_source\":\"right\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"promoID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeArea\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesAmountFACT\"],\"attribute_source\":\"left\"}}]},\"left_input\":{\"type\":\"join\",\"left_join_attribute\":[\"prodID\"],\"right_join_attribute\":[\"prodID\"],\"left_outer\":false,\"right_outer\":false,\"projection\":{\"type\":\"projection_obj\",\"projection_type\":\"object\",\"fields\":[{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"prodID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"prodName\"],\"attribute_source\":\"right\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"promoID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeArea\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesAmountFACT\"],\"attribute_source\":\"left\"}}]},\"left_input\":{\"type\":\"rowwindow\",\"windowsize\":100000,\"input\":{\"type\":\"leaf\",\"stream_source\":\"salesFact5DimWNamesWrapper\",\"is_master\":true}},\"right_input\":{\"type\":\"csv_leaf\",\"csv_source\":\"productDimension\"}},\"right_input\":{\"type\":\"csv_leaf\",\"csv_source\":\"supplierDimension\"}},\"right_input\":{\"type\":\"csv_leaf\",\"csv_source\":\"promotionDimension\"}}}}";

    //Query with 3 dimension and a fact join with 6 dimension ID and names
    //std::string queryIntermediateRepresentation1 = "{\"type\":\"root\",\"input\":{\"type\":\"cubify\",\"input\":{\"type\":\"join\",\"left_join_attribute\":[\"promoID\"],\"right_join_attribute\":[\"promoID\"],\"left_outer\":false,\"right_outer\":false,\"projection\":{\"type\":\"projection_obj\",\"projection_type\":\"object\",\"fields\":[{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"prodID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"prodName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"promoID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"promoName\"],\"attribute_source\":\"right\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeArea\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesPersonID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesPersonName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesAmountFACT\"],\"attribute_source\":\"left\"}}]},\"left_input\":{\"type\":\"join\",\"left_join_attribute\":[\"suppID\"],\"right_join_attribute\":[\"suppID\"],\"left_outer\":false,\"right_outer\":false,\"projection\":{\"type\":\"projection_obj\",\"projection_type\":\"object\",\"fields\":[{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"prodID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"prodName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppName\"],\"attribute_source\":\"right\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"promoID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeArea\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesPersonID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesPersonName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesAmountFACT\"],\"attribute_source\":\"left\"}}]},\"left_input\":{\"type\":\"join\",\"left_join_attribute\":[\"prodID\"],\"right_join_attribute\":[\"prodID\"],\"left_outer\":false,\"right_outer\":false,\"projection\":{\"type\":\"projection_obj\",\"projection_type\":\"object\",\"fields\":[{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"prodID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"prodName\"],\"attribute_source\":\"right\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"promoID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeArea\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesPersonID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesPersonName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesAmountFACT\"],\"attribute_source\":\"left\"}}]},\"left_input\":{\"type\":\"rowwindow\",\"windowsize\":" + stream1WindowSize + ",\"input\":{\"type\":\"leaf\",\"stream_source\":\"salesFact6DimWNamesWrapper\",\"is_master\":true}},\"right_input\":{\"type\":\"csv_leaf\",\"csv_source\":\"productDimension\"}},\"right_input\":{\"type\":\"csv_leaf\",\"csv_source\":\"supplierDimension\"}},\"right_input\":{\"type\":\"csv_leaf\",\"csv_source\":\"promotionDimension\"}}}}";

    //Query with pre-joined 6 dimensions with a fact table
    std::string queryIntermediateRepresentation1 = "{\"type\":\"root\",\"input\":{\"type\":\"cubify\",\"input\":{\"type\":\"rowwindow\",\"windowsize\":\" + streamWindowSize + \",\"input\":{\"type\":\"leaf\",\"stream_source\":\"salesFactPreJoined6DWrapper\",\"is_master\":true}}}}";

    //Send out through socket - Query with 3 dimension and a fact join with 6 dimension ID and names without cubify operator
    //std::string queryIntermediateRepresentation1 = "{\"type\":\"root\",\"input\":{\"type\":\"istream\",\"input\":{\"type\":\"join\",\"left_join_attribute\":[\"promoID\"],\"right_join_attribute\":[\"promoID\"],\"left_outer\":false,\"right_outer\":false,\"projection\":{\"type\":\"projection_obj\",\"projection_type\":\"object\",\"fields\":[{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"prodID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"prodName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"promoID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"promoName\"],\"attribute_source\":\"right\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeArea\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesPersonID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesPersonName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesAmountFACT\"],\"attribute_source\":\"left\"}}]},\"left_input\":{\"type\":\"join\",\"left_join_attribute\":[\"suppID\"],\"right_join_attribute\":[\"suppID\"],\"left_outer\":false,\"right_outer\":false,\"projection\":{\"type\":\"projection_obj\",\"projection_type\":\"object\",\"fields\":[{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"prodID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"prodName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppName\"],\"attribute_source\":\"right\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"promoID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeArea\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesPersonID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesPersonName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesAmountFACT\"],\"attribute_source\":\"left\"}}]},\"left_input\":{\"type\":\"join\",\"left_join_attribute\":[\"prodID\"],\"right_join_attribute\":[\"prodID\"],\"left_outer\":false,\"right_outer\":false,\"projection\":{\"type\":\"projection_obj\",\"projection_type\":\"object\",\"fields\":[{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"prodID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"prodName\"],\"attribute_source\":\"right\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"promoID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeArea\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesPersonID\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesPersonName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesAmountFACT\"],\"attribute_source\":\"left\"}}]},\"left_input\":{\"type\":\"rowwindow\",\"windowsize\":" + IoI + ",\"input\":{\"type\":\"leaf\",\"stream_source\":\"salesFact6DimWNamesWrapper\",\"is_master\":true}},\"right_input\":{\"type\":\"csv_leaf\",\"csv_source\":\"productDimension\"}},\"right_input\":{\"type\":\"csv_leaf\",\"csv_source\":\"supplierDimension\"}},\"right_input\":{\"type\":\"csv_leaf\",\"csv_source\":\"promotionDimension\"}}}}";

    //Send out through socket - TPCH query with 4 dimensions
    //std::string queryIntermediateRepresentation1 = "{\"type\":\"root\",\"input\":{\"type\":\"istream\",\"input\":{\"type\":\"join\",\"left_join_attribute\":[\"custKey\"],\"right_join_attribute\":[\"custKey\"],\"left_outer\":false,\"right_outer\":false,\"projection\":{\"type\":\"projection_obj\",\"projection_type\":\"object\",\"fields\":[{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"partKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"partName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custName\"],\"attribute_source\":\"right\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeArea\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesQtyFACT\"],\"attribute_source\":\"left\"}}]},\"left_input\":{\"type\":\"join\",\"left_join_attribute\":[\"suppKey\"],\"right_join_attribute\":[\"suppKey\"],\"left_outer\":false,\"right_outer\":false,\"projection\":{\"type\":\"projection_obj\",\"projection_type\":\"object\",\"fields\":[{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"partKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"partName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppName\"],\"attribute_source\":\"right\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeArea\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesQtyFACT\"],\"attribute_source\":\"left\"}}]},\"left_input\":{\"type\":\"join\",\"left_join_attribute\":[\"partKey\"],\"right_join_attribute\":[\"partKey\"],\"left_outer\":false,\"right_outer\":false,\"projection\":{\"type\":\"projection_obj\",\"projection_type\":\"object\",\"fields\":[{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"partKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"partName\"],\"attribute_source\":\"right\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeArea\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesQtyFACT\"],\"attribute_source\":\"left\"}}]},\"left_input\":{\"type\":\"rowwindow\",\"windowsize\":" + IoI + ",\"input\":{\"type\":\"leaf\",\"stream_source\":\"salesFact4DimTPCH\",\"is_master\":true}},\"right_input\":{\"type\":\"csv_leaf\",\"csv_source\":\"PartDimensionTPCH\"}},\"right_input\":{\"type\":\"csv_leaf\",\"csv_source\":\"SupplierDimensionTPCH\"}},\"right_input\":{\"type\":\"csv_leaf\",\"csv_source\":\"CustomerDimensionTPCH\"}}}}";

    //Unified StreamingCube - TPCH query with 4 dimensions
    //std::string queryIntermediateRepresentation1 = "{\"type\":\"root\",\"input\":{\"type\":\"cubify\",\"input\":{\"type\":\"join\",\"left_join_attribute\":[\"custKey\"],\"right_join_attribute\":[\"custKey\"],\"left_outer\":false,\"right_outer\":false,\"projection\":{\"type\":\"projection_obj\",\"projection_type\":\"object\",\"fields\":[{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"partKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"partName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custName\"],\"attribute_source\":\"right\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeArea\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesQtyFACT\"],\"attribute_source\":\"left\"}}]},\"left_input\":{\"type\":\"join\",\"left_join_attribute\":[\"suppKey\"],\"right_join_attribute\":[\"suppKey\"],\"left_outer\":false,\"right_outer\":false,\"projection\":{\"type\":\"projection_obj\",\"projection_type\":\"object\",\"fields\":[{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"partKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"partName\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppName\"],\"attribute_source\":\"right\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeArea\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesQtyFACT\"],\"attribute_source\":\"left\"}}]},\"left_input\":{\"type\":\"join\",\"left_join_attribute\":[\"partKey\"],\"right_join_attribute\":[\"partKey\"],\"left_outer\":false,\"right_outer\":false,\"projection\":{\"type\":\"projection_obj\",\"projection_type\":\"object\",\"fields\":[{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"partKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"partName\"],\"attribute_source\":\"right\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"suppKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"custKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeKey\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"storeArea\"],\"attribute_source\":\"left\"}},{\"type\":\"projection_obj\",\"need_rename\":false,\"projection_type\":\"direct\",\"expression\":{\"type\":\"expression_obj\",\"expression_type\":\"id\",\"id_name\":[\"salesQtyFACT\"],\"attribute_source\":\"left\"}}]},\"left_input\":{\"type\":\"rowwindow\",\"windowsize\":" + IoI + ",\"input\":{\"type\":\"leaf\",\"stream_source\":\"salesFact4DimTPCH\",\"is_master\":true}},\"right_input\":{\"type\":\"csv_leaf\",\"csv_source\":\"PartDimensionTPCH\"}},\"right_input\":{\"type\":\"csv_leaf\",\"csv_source\":\"SupplierDimensionTPCH\"}},\"right_input\":{\"type\":\"csv_leaf\",\"csv_source\":\"CustomerDimensionTPCH\"}}}}";

	Document queryIntermediateDocument = fromjson(queryIntermediateRepresentation1);
    boost::shared_ptr<QueryIntermediateRepresentation> queryIntermediateRepresentation(new QueryIntermediateRepresentation(queryIntermediateDocument));

    // Output mode
    // show result on screen mode
    boost::shared_ptr<IStreamOutput> streamOutput(new ShowResultStreamOutput());

    // socket output mode
    std::string ip = "192.168.0.107";
    //std::string ip = "192.168.0.150";
	std::string port = "8042";
	//boost::shared_ptr<IStreamOutput> streamOutput(new SocketStreamOutput(ip,port));

    // Registering intermediate query
    server->registerQuery(queryIntermediateRepresentation,streamOutput,activateDuration);

    // Register JSON query
    //server->registerQuery(query0, streamOutput, activateDuration);

    server->execute();    //exeute the query


#ifdef PROFILER
	ProfilerStop();
#endif
}
