Skip to content
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

Feature/semantic #253

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10)
project(JasmineGraph)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
Expand Down Expand Up @@ -39,6 +39,14 @@ set(HEADERS globals.h
src/query/algorithms/linkprediction/JasminGraphLinkPredictor.h
src/query/algorithms/triangles/Triangles.h
src/query/algorithms/triangles/StreamingTriangles.h
src/query/processor/cypher/astbuilder/ASTBuilder.h
src/query/processor/cypher/astbuilder/ASTInternalNode.h
src/query/processor/cypher/astbuilder/ASTLeafNoValue.h
src/query/processor/cypher/astbuilder/ASTNode.h
src/query/processor/cypher/astbuilder/ASTLeafValue.h
src/query/processor/cypher/semanticanalyzer/SemanticAnalyzer.h
src/query/processor/cypher/semanticanalyzer/Scope.h
src/query/processor/cypher/semanticanalyzer/ScopeManager.h
src/scale/scaler.h
src/server/JasmineGraphInstance.h
src/server/JasmineGraphInstanceFileTransferService.h
Expand Down Expand Up @@ -71,6 +79,7 @@ set(HEADERS globals.h
src/streamingdb/StreamingSQLiteDBInterface.h
src/frontend/core/executor/impl/PageRankExecutor.h
src/util/dbinterface/DBInterface.h
src/query/processor/cypher/util/Const.h
)

set(SOURCES src/backend/JasmineGraphBackend.cpp
Expand Down Expand Up @@ -106,6 +115,14 @@ set(SOURCES src/backend/JasmineGraphBackend.cpp
src/query/algorithms/linkprediction/JasminGraphLinkPredictor.cpp
src/query/algorithms/triangles/Triangles.cpp
src/query/algorithms/triangles/StreamingTriangles.cpp
src/query/processor/cypher/astbuilder/ASTBuilder.cpp
src/query/processor/cypher/astbuilder/ASTInternalNode.cpp
src/query/processor/cypher/astbuilder/ASTLeafNoValue.cpp
src/query/processor/cypher/astbuilder/ASTNode.cpp
src/query/processor/cypher/astbuilder/ASTLeafValue.cpp
src/query/processor/cypher/semanticanalyzer/SemanticAnalyzer.cpp
src/query/processor/cypher/semanticanalyzer/Scope.cpp
src/query/processor/cypher/semanticanalyzer/ScopeManager.cpp
src/scale/scaler.cpp
src/server/JasmineGraphInstance.cpp
src/server/JasmineGraphInstanceFileTransferService.cpp
Expand All @@ -131,13 +148,16 @@ set(SOURCES src/backend/JasmineGraphBackend.cpp
src/streamingdb/StreamingSQLiteDBInterface.cpp
src/frontend/core/executor/impl/PageRankExecutor.cpp
src/util/dbinterface/DBInterface.cpp
src/query/processor/cypher/semanticanalyzer/SemanticAnalyzer.cpp
src/query/processor/cypher/util/Const.cpp
)

if (CMAKE_BUILD_TYPE STREQUAL "DEBUG")
add_compile_options(-DUNIT_TEST)
endif ()

add_library(JasmineGraphLib ${HEADERS} ${SOURCES})
file(GLOB GENERATED_SRC /home/ubuntu/software/antlr/*.cpp)
add_library(JasmineGraphLib ${HEADERS} ${SOURCES} ${GENERATED_SRC})
add_executable(JasmineGraph main.h main.cpp)

target_compile_definitions(JasmineGraphLib PUBLIC ROOT_DIR="${CMAKE_CURRENT_SOURCE_DIR}/")
Expand All @@ -162,11 +182,15 @@ target_link_libraries(JasmineGraphLib PRIVATE /usr/local/lib/libcppkafka.so)
target_link_libraries(JasmineGraph JasmineGraphLib)
target_link_libraries(JasmineGraph curl)

include_directories(/usr/local/include/antlr4-runtime)
link_directories(/usr/local/lib)
include_directories(/usr/local/include/yaml-cpp)
target_link_libraries(JasmineGraphLib PRIVATE m)
target_link_libraries(JasmineGraphLib PRIVATE /usr/local/lib/libkubernetes.so)
target_link_libraries(JasmineGraphLib PRIVATE yaml-cpp)
target_link_libraries(JasmineGraphLib PRIVATE curl)
target_link_libraries(JasmineGraphLib PRIVATE antlr4-runtime)


if (CMAKE_BUILD_TYPE STREQUAL "DEBUG")
# Include google test
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ RUN if [ "$DEBUG" = "true" ]; then apt-get update \
&& apt-get install --no-install-recommends -y gdb gdbserver \
&& apt-get clean; fi


WORKDIR "${JASMINEGRAPH_HOME}"
COPY ./build.sh ./build.sh
COPY ./CMakeLists.txt ./CMakeLists.txt
COPY ./main.h ./main.h
Expand Down
62 changes: 60 additions & 2 deletions src/frontend/JasmineGraphFrontEnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ limitations under the License.
#include "JasmineGraphFrontEndProtocol.h"
#include "core/CoreConstants.h"
#include "core/scheduler/JobScheduler.h"
#include "antlr4-runtime.h"
#include "/home/ubuntu/software/antlr/CypherLexer.h"
#include "/home/ubuntu/software/antlr/CypherParser.h"
#include "../query/processor/cypher/astbuilder/ASTBuilder.h"
#include "../query/processor/cypher/astbuilder/ASTNode.h"
#include "../query/processor/cypher/semanticanalyzer/SemanticAnalyzer.h"


#define MAX_PENDING_CONNECTIONS 10
#define DATA_BUFFER_SIZE (FRONTEND_DATA_LENGTH + 1)
Expand All @@ -64,6 +71,7 @@ bool JasmineGraphFrontEnd::strian_exit;

static std::string getPartitionCount(std::string path);
static void list_command(int connFd, SQLiteDBInterface *sqlite, bool *loop_exit_p);
static void cypher_ast_command(int connFd, bool *loop_exit_p);
static void add_rdf_command(std::string masterIP, int connFd, SQLiteDBInterface *sqlite, bool *loop_exit_p);
static void add_graph_command(std::string masterIP, int connFd, SQLiteDBInterface *sqlite, bool *loop_exit_p);
static void add_graph_cust_command(std::string masterIP, int connFd, SQLiteDBInterface *sqlite, bool *loop_exit_p);
Expand Down Expand Up @@ -169,7 +177,9 @@ void *frontendservicesesion(void *dummyPt) {
break;
} else if (line.compare(LIST) == 0) {
list_command(connFd, sqlite, &loop_exit);
} else if (line.compare(SHTDN) == 0) {
} else if (line.compare(CYPHER_AST) == 0){
cypher_ast_command(connFd, &loop_exit);
}else if (line.compare(SHTDN) == 0) {
JasmineGraphServer::shutdown_workers();
close(connFd);
exit(0);
Expand Down Expand Up @@ -627,6 +637,53 @@ static void list_command(int connFd, SQLiteDBInterface *sqlite, bool *loop_exit_
}
}

static void cypher_ast_command(int connFd, bool *loop_exit)
{

string msg_1 = "Input Query :";
int result_wr = write(connFd, msg_1.c_str(), msg_1.length());
if (result_wr < 0) {
frontend_logger.error("Error writing to socket");
*loop_exit = true;
return;
}
result_wr = write(connFd, "\r\n", 2);
if (result_wr < 0) {
frontend_logger.error("Error writing to socket");
*loop_exit = true;
return;
}

// Get user response.
char user_res[FRONTEND_DATA_LENGTH + 1];
bzero(user_res, FRONTEND_DATA_LENGTH + 1);
read(connFd, user_res, FRONTEND_DATA_LENGTH);
string user_res_s(user_res);

antlr4::ANTLRInputStream input(user_res_s);
// Create a lexer from the input
CypherLexer lexer(&input);

// Create a token stream from the lexer
antlr4::CommonTokenStream tokens(&lexer);

// Create a parser from the token stream
CypherParser parser(&tokens);

ASTBuilder ast_builder;
auto* ast = any_cast<ASTNode*>(ast_builder.visitOC_Cypher(parser.oC_Cypher()));

SemanticAnalyzer semantic_analyzer;
if(semantic_analyzer.analyze(ast))
{
frontend_logger.log("AST is successfully analyzed", "log");
}else
{
frontend_logger.log(user_res, "error");
frontend_logger.error("query isn't semantically correct");
Copy link
Owner

Choose a reason for hiding this comment

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

Lets add the query also as part of the error message. This will give more details and support for debugging.

Copy link
Author

Choose a reason for hiding this comment

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

okay sir I will add.

Copy link
Owner

Choose a reason for hiding this comment

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

Ok

}
}

static void add_rdf_command(std::string masterIP, int connFd, SQLiteDBInterface *sqlite, bool *loop_exit_p) {
// add RDF graph
int result_wr = write(connFd, SEND.c_str(), FRONTEND_COMMAND_LENGTH);
Expand Down Expand Up @@ -804,7 +861,8 @@ static void add_graph_command(std::string masterIP, int connFd, SQLiteDBInterfac
int result_wr = write(connFd, DONE.c_str(), DONE.size());
if (result_wr < 0) {
frontend_logger.error("Error writing to socket");
*loop_exit_p = true;
*loop_exit_p =
true;
return;
}
result_wr = write(connFd, "\r\n", 2);
Expand Down
1 change: 1 addition & 0 deletions src/frontend/JasmineGraphFrontEndProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ const string SLA = "sla";
const string COMMAND = "command";
const string PRIORITY = "priority(>=1)";
const string INVALID_FORMAT = "Invalid message format";
const string CYPHER_AST = "cypher-ast";

1 change: 1 addition & 0 deletions src/frontend/JasmineGraphFrontEndProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ extern const string STOP_STRIAN;
extern const string ADMDL;
extern const string MERGE;
extern const string INVALID_FORMAT;
extern const string CYPHER_AST;

class JasminGraphFrontEndProtocol {
// Note that this protocol do not need a handshake session since the communication in most of the time is conducted
Expand Down
2 changes: 1 addition & 1 deletion src/localstore/JasmineGraphHashMapLocalStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void JasmineGraphHashMapLocalStore::toLocalAttributeMap(const AttributeStore *at
auto entry = allEntries->Get(i);
long key = entry->key();
auto attributes = entry->value();
auto attributesSize = attributes->Length();
auto attributesSize = attributes->size();
for (int j = 0; j < attributesSize; j = j + 1) {
attributeVector.push_back(attributes->Get(j)->c_str());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ std::pair<std::string, unsigned int> JasmineGraphIncrementalLocalStore::getIDs(s
"Could be due to JSON parsing error or error while persisting the data to disk",
"error");
}
return {"", 0}; // all plath of the function must return std::pair<std::string, unsigned int> type object even there is an error
}

void JasmineGraphIncrementalLocalStore::addEdgeFromString(std::string edgeString) {
Expand Down
2 changes: 2 additions & 0 deletions src/partitioner/local/MetisPartitioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ std::vector<std::map<int, std::string>> MetisPartitioner::partitioneWithGPMetis(
perror("Popen error in executing gpmetis command");
partitioner_logger.log("Popen error in executing gpmetis command", "error");
}

return std::vector<std::map<int, std::string>>{}; // Return an empty vector in case of error
}

void MetisPartitioner::createPartitionFiles(std::map<int, int> partMap) {
Expand Down
Loading