Skip to content

Commit

Permalink
Move SwigFactory creation from udf client into JavaContainerBuilder c…
Browse files Browse the repository at this point in the history
…lass.
  • Loading branch information
tomuben committed Oct 14, 2024
1 parent 967c71f commit 8dc5834
Show file tree
Hide file tree
Showing 20 changed files with 99 additions and 108 deletions.
4 changes: 2 additions & 2 deletions exaudfclient/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ cc_binary(
srcs = ["exaudfclient.cc", "//base:load_dynamic"],
linkopts = ["-ldl"], # needed for dynamicly loading libexaudflib_complete.so into another linker namespace
deps = ["//base/exaudflib:header", "//base/utils:utils"]+VM_ENABLED_DEPS+VM_PYTHON3_DEPS+
["//base/exaudflib:exaudflib-deps", "//base/swig_factory:swig_factory"],
["//base/exaudflib:exaudflib-deps"],
defines = VM_ENABLED_DEFINES,
data = ["//base:libexaudflib_complete.so"]
)
Expand All @@ -101,7 +101,7 @@ cc_binary(
srcs = ["exaudfclient.cc", "//base:load_dynamic"],
linkopts = ["-ldl"], # needed for dynamicly loading libexaudflib_complete.so into another linker namespace
deps = ["//base/exaudflib:header", "//base/utils:utils"]+VM_ENABLED_DEPS+VM_PYTHON3_DEPS+
["//base/exaudflib:exaudflib-deps", "//base/swig_factory:swig_factory"] +
["//base/exaudflib:exaudflib-deps"] +
[ "@zmq//:zmq", "@protobuf//:protobuf"],
defines = VM_ENABLED_DEFINES,
data = ["//base:libexaudflib_complete.so"],
Expand Down
2 changes: 1 addition & 1 deletion exaudfclient/base/javacontainer/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ cc_library(
hdrs = [":filter_swig_code_exascript_java_h", "exascript_java_jni_decl.h"],
deps = ["@java//:java", ":exascript_java", "//base/exaudflib:header",
"//base/utils:utils","//base/javacontainer/script_options:java_script_option_lines",
"//base/swig_factory:swig_factory_if"],
"//base/swig_factory:swig_factory"],
# copts= ["-O0","-fno-lto"],
alwayslink=True,
)
Expand Down
5 changes: 2 additions & 3 deletions exaudfclient/base/javacontainer/javacontainer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
using namespace SWIGVMContainers;
using namespace std;

JavaVMach::JavaVMach(bool checkOnly, SwigFactory& swigFactory,
std::unique_ptr<JavaScriptOptions::ScriptOptionsParser> scriptOptionsParser) {
JavaVMach::JavaVMach(bool checkOnly, std::unique_ptr<JavaScriptOptions::ScriptOptionsParser> scriptOptionsParser) {
try {
m_impl = new JavaVMImpl(checkOnly, false, swigFactory, std::move(scriptOptionsParser));
m_impl = new JavaVMImpl(checkOnly, false, std::move(scriptOptionsParser));
} catch (std::exception& err) {
lock_guard<mutex> lock(exception_msg_mtx);
exception_msg = "F-UDF-CL-SL-JAVA-1000: "+std::string(err.what());
Expand Down
3 changes: 1 addition & 2 deletions exaudfclient/base/javacontainer/javacontainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace SWIGVMContainers {

class JavaVMImpl;
class SwigFactory;

namespace JavaScriptOptions {

Expand All @@ -24,7 +23,7 @@ class JavaVMach: public SWIGVM {
/*
* scriptOptionsParser: JavaVMach takes ownership of ScriptOptionsParser pointer.
*/
JavaVMach(bool checkOnly, SwigFactory& swigFactory, std::unique_ptr<JavaScriptOptions::ScriptOptionsParser> scriptOptionsParser);
JavaVMach(bool checkOnly, std::unique_ptr<JavaScriptOptions::ScriptOptionsParser> scriptOptionsParser);
virtual ~JavaVMach() {}
virtual void shutdown();
virtual bool run();
Expand Down
14 changes: 7 additions & 7 deletions exaudfclient/base/javacontainer/javacontainer_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@
#include "base/javacontainer/script_options/parser_ctpg.h"
#include "base/javacontainer/script_options/parser_legacy.h"
#include "base/javacontainer/javacontainer.h"
#include "base/swig_factory/swig_factory_impl.h"

#ifdef ENABLE_JAVA_VM

namespace SWIGVMContainers {

JavaContainerBuilder::JavaContainerBuilder(SwigFactory& swigFactory)
: m_parser()
, m_swigFactory(swigFactory) {}
JavaContainerBuilder::JavaContainerBuilder()
: m_parser() {}

JavaContainerBuilder& JavaContainerBuilder::useCtpgParser(const bool useCtpgParser) {
m_parser = std::make_unique<JavaScriptOptions::ScriptOptionLinesParserCTPG>();
m_parser = std::make_unique<JavaScriptOptions::ScriptOptionLinesParserCTPG>(std::make_unique<SwigFactoryImpl>());
return *this;
}

JavaVMach* JavaContainerBuilder::build() {
if (m_parser) {
return new JavaVMach(false, m_swigFactory, std::move(m_parser));
return new JavaVMach(false, std::move(m_parser));
} else {
m_parser = std::make_unique<JavaScriptOptions::ScriptOptionLinesParserLegacy>();
return new JavaVMach(false, m_swigFactory, std::move(m_parser));
m_parser = std::make_unique<JavaScriptOptions::ScriptOptionLinesParserLegacy>(std::make_unique<SwigFactoryImpl>());
return new JavaVMach(false, std::move(m_parser));
}
}

Expand Down
5 changes: 1 addition & 4 deletions exaudfclient/base/javacontainer/javacontainer_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace SWIGVMContainers {

class JavaVMach;
struct SwigFactory;

namespace JavaScriptOptions {

Expand All @@ -18,16 +17,14 @@ struct ScriptOptionsParser;

class JavaContainerBuilder {
public:
JavaContainerBuilder(SwigFactory& swigFactory);
JavaContainerBuilder();

JavaContainerBuilder& useCtpgParser(const bool value);

JavaVMach* build();

private:
std::unique_ptr<JavaScriptOptions::ScriptOptionsParser> m_parser;
SwigFactory& m_swigFactory;

};

} //namespace SWIGVMContainers
Expand Down
17 changes: 6 additions & 11 deletions exaudfclient/base/javacontainer/javacontainer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
#include "base/javacontainer/javacontainer.h"
#include "base/javacontainer/javacontainer_impl.h"
#include "base/javacontainer/script_options/extractor.h"
#include "base/javacontainer/script_options/parser_legacy.h"
#include "base/javacontainer/script_options/parser_ctpg.h"
#include "base/swig_factory/swig_factory.h"
#include "base/javacontainer/script_options/parser.h"


using namespace SWIGVMContainers;
using namespace std;

JavaVMImpl::JavaVMImpl(bool checkOnly, bool noJNI, SwigFactory& swigFactory,
std::unique_ptr<JavaScriptOptions::ScriptOptionsParser> scriptOptionsParser)
JavaVMImpl::JavaVMImpl(bool checkOnly, bool noJNI,
std::unique_ptr<JavaScriptOptions::ScriptOptionsParser> scriptOptionsParser)
: m_checkOnly(checkOnly)
, m_exaJavaPath("")
, m_localClasspath("/tmp") // **IMPORTANT**: /tmp needs to be in the classpath, otherwise ExaCompiler crashe with com.exasol.ExaCompilationException: /DATE_STRING.java:3: error: error while writing DATE_STRING: could not create parent directories
Expand All @@ -30,14 +28,12 @@ JavaVMImpl::JavaVMImpl(bool checkOnly, bool noJNI, SwigFactory& swigFactory,
, m_jvm(NULL)
, m_env(NULL)
, m_needsCompilation(true)
, m_swigFactory(swigFactory)
{

stringstream ss;
m_exaJavaPath = "/exaudf/base/javacontainer"; // TODO hardcoded path

JavaScriptOptions::ScriptOptionLinesParserCTPG parser;
parseScriptOptions(std::move(scriptOptionsParser), swigFactory);
parseScriptOptions(std::move(scriptOptionsParser));

m_needsCompilation = checkNeedsCompilation();
if (m_needsCompilation) {
Expand All @@ -54,9 +50,8 @@ JavaVMImpl::JavaVMImpl(bool checkOnly, bool noJNI, SwigFactory& swigFactory,
}
}

void JavaVMImpl::parseScriptOptions(std::unique_ptr<JavaScriptOptions::ScriptOptionsParser> scriptOptionsParser,
SwigFactory& swigFactory) {
JavaScriptOptions::Extractor extractor(*scriptOptionsParser, swigFactory);
void JavaVMImpl::parseScriptOptions(std::unique_ptr<JavaScriptOptions::ScriptOptionsParser> scriptOptionsParser) {
JavaScriptOptions::Extractor extractor(*scriptOptionsParser);

DBG_FUNC_CALL(cerr,extractor.extract(m_scriptCode));

Expand Down
10 changes: 4 additions & 6 deletions exaudfclient/base/javacontainer/javacontainer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class JavaVMImpl {
public:
friend class ::JavaVMTest;
/*
* scriptOptionsParser: JavaVMach takes ownership of ScriptOptionsParser pointer.
* scriptOptionsParser: JavaVMImpl takes ownership of ScriptOptionsParser pointer.
*/
JavaVMImpl(bool checkOnly, bool noJNI, SwigFactory& swigFactory,
std::unique_ptr<JavaScriptOptions::ScriptOptionsParser> scriptOptionsParser);
JavaVMImpl(bool checkOnly, bool noJNI,
std::unique_ptr<JavaScriptOptions::ScriptOptionsParser> scriptOptionsParser);
~JavaVMImpl() {}
void shutdown();
bool run();
Expand All @@ -46,8 +46,7 @@ class JavaVMImpl {
void throwException(const std::string& ex);
void setJvmOptions();
void addJarToClasspath(const std::string& path);
void parseScriptOptions(std::unique_ptr<JavaScriptOptions::ScriptOptionsParser> scriptOptionsParser,
SwigFactory& swigFactory);
void parseScriptOptions(std::unique_ptr<JavaScriptOptions::ScriptOptionsParser> scriptOptionsParser);
bool m_checkOnly;
std::string m_exaJavaPath;
std::string m_localClasspath;
Expand All @@ -59,7 +58,6 @@ class JavaVMImpl {
JavaVM *m_jvm;
JNIEnv *m_env;
bool m_needsCompilation;
SwigFactory& m_swigFactory;
};

} //namespace SWIGVMContainers
Expand Down
8 changes: 3 additions & 5 deletions exaudfclient/base/javacontainer/script_options/extractor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ namespace SWIGVMContainers {

namespace JavaScriptOptions {

Extractor::Extractor(ScriptOptionsParser & parser,
SwigFactory& swigFactory)
: m_parser(parser)
, m_swigFactory(swigFactory) {}
Extractor::Extractor(ScriptOptionsParser & parser)
: m_parser(parser) {}

void Extractor::extract(std::string & scriptCode) {
m_parser.prepareScriptCode(scriptCode);
EXTR_DBG_FUNC_CALL(m_parser.parseForScriptClass( [&](const std::string& value){
EXTR_DBG_FUNC_CALL(m_converter.convertScriptClassName(value)); // To be called before scripts are imported. Otherwise, the script classname from an imported script could be used
}));
EXTR_DBG_FUNC_CALL(m_parser.extractImportScripts(m_swigFactory));
EXTR_DBG_FUNC_CALL(m_parser.extractImportScripts());
EXTR_DBG_FUNC_CALL(m_parser.parseForJvmOptions( [&](const std::string& value){
EXTR_DBG_FUNC_CALL(m_converter.convertJvmOption(value));
}));
Expand Down
7 changes: 1 addition & 6 deletions exaudfclient/base/javacontainer/script_options/extractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@

namespace SWIGVMContainers {

struct SwigFactory;

namespace JavaScriptOptions {

class ScriptOptionsParser;

class Extractor {

public:
Extractor(ScriptOptionsParser & parser,
SwigFactory& swigFactory);
Extractor(ScriptOptionsParser & parser);

const std::set<std::string> & getJarPaths() const {
return m_converter.getJarPaths();
Expand All @@ -36,8 +33,6 @@ class Extractor {

Converter m_converter;
ScriptOptionsParser & m_parser;

SwigFactory& m_swigFactory;
};


Expand Down
4 changes: 1 addition & 3 deletions exaudfclient/base/javacontainer/script_options/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

namespace SWIGVMContainers {

struct SwigFactory;

namespace JavaScriptOptions {

struct ScriptOptionsParser {
Expand Down Expand Up @@ -43,7 +41,7 @@ struct ScriptOptionsParser {
Searches for the "%import" options and embeds the respective imported script code at the same location as
the option in the script code.
*/
virtual void extractImportScripts(SwigFactory & swigFactory) = 0;
virtual void extractImportScripts() = 0;

/*
Returns the (eventually modified) script code.
Expand Down
10 changes: 6 additions & 4 deletions exaudfclient/base/javacontainer/script_options/parser_ctpg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "base/javacontainer/script_options/parser_ctpg_script_importer.h"
#include "base/utils/exceptions.h"
#include "base/script_options_parser/exception.h"
#include "base/swig_factory/swig_factory.h"
#include <sstream>


Expand All @@ -11,10 +12,11 @@ namespace SWIGVMContainers {

namespace JavaScriptOptions {

ScriptOptionLinesParserCTPG::ScriptOptionLinesParserCTPG()
ScriptOptionLinesParserCTPG::ScriptOptionLinesParserCTPG(std::unique_ptr<SwigFactory> swigFactory)
: m_scriptCode()
, m_keywords(false)
, m_needParsing(true) {}
, m_needParsing(true)
, m_swigFactory(std::move(swigFactory)) {}

void ScriptOptionLinesParserCTPG::prepareScriptCode(const std::string & scriptCode) {
m_scriptCode = scriptCode;
Expand Down Expand Up @@ -44,7 +46,7 @@ void ScriptOptionLinesParserCTPG::parseForExternalJars(std::function<void(const
}
}

void ScriptOptionLinesParserCTPG::extractImportScripts(SwigFactory & swigFactory) {
void ScriptOptionLinesParserCTPG::extractImportScripts() {

try {
parse();
Expand All @@ -54,7 +56,7 @@ void ScriptOptionLinesParserCTPG::extractImportScripts(SwigFactory & swigFactory

const auto optionIt = m_foundOptions.find(m_keywords.importKeyword());
if (optionIt != m_foundOptions.end()) {
CTPG::ScriptImporter scriptImporter(swigFactory, m_keywords);
CTPG::ScriptImporter scriptImporter(*m_swigFactory, m_keywords);
scriptImporter.importScript(m_scriptCode, m_foundOptions);
//The imported scripts will change the location of the other options in m_foundOptions
//Also there might be new JVM / External Jar options
Expand Down
9 changes: 6 additions & 3 deletions exaudfclient/base/javacontainer/script_options/parser_ctpg.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
#include "base/javacontainer/script_options/parser.h"
#include "base/javacontainer/script_options/keywords.h"
#include "base/script_options_parser/ctpg/script_option_lines_ctpg.h"

#include <memory>

namespace SWIGVMContainers {

struct SwigFactory;

namespace JavaScriptOptions {

class ScriptOptionLinesParserCTPG : public ScriptOptionsParser {

public:
ScriptOptionLinesParserCTPG();
ScriptOptionLinesParserCTPG(std::unique_ptr<SwigFactory> swigFactory);

virtual ~ScriptOptionLinesParserCTPG() {};

Expand All @@ -25,7 +27,7 @@ class ScriptOptionLinesParserCTPG : public ScriptOptionsParser {

void parseForExternalJars(std::function<void(const std::string &option)> callback) override;

void extractImportScripts(SwigFactory & swigFactory) override;
void extractImportScripts() override;

std::string && getScriptCode() override;

Expand All @@ -42,6 +44,7 @@ class ScriptOptionLinesParserCTPG : public ScriptOptionsParser {
Keywords m_keywords;
ExecutionGraph::OptionsLineParser::CTPG::options_map_t m_foundOptions;
bool m_needParsing;
std::unique_ptr<SwigFactory> m_swigFactory;
};

} //namespace JavaScriptOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ namespace SWIGVMContainers {

namespace JavaScriptOptions {

ScriptOptionLinesParserLegacy::ScriptOptionLinesParserLegacy()
ScriptOptionLinesParserLegacy::ScriptOptionLinesParserLegacy(std::unique_ptr<SwigFactory> swigFactory)
: m_whitespace(" \t\f\v")
, m_lineend(";")
, m_scriptCode()
, m_keywords(true) {}
, m_keywords(true)
, m_swigFactory(std::move(swigFactory)) {}

void ScriptOptionLinesParserLegacy::prepareScriptCode(const std::string & scriptCode) {
m_scriptCode = scriptCode;
}

void ScriptOptionLinesParserLegacy::extractImportScripts(SwigFactory & swigFactory) {
void ScriptOptionLinesParserLegacy::extractImportScripts() {
std::unique_ptr<SWIGMetadataIf> metaData;
// Attention: We must hash the parent script before modifying it (adding the
// package definition). Otherwise we don't recognize if the script imports its self
Expand Down Expand Up @@ -111,7 +112,7 @@ void ScriptOptionLinesParserLegacy::extractImportScripts(SwigFactory & swigFacto
}
if (!newScript.empty()) {
if (!metaData) {
metaData.reset(swigFactory.makeSwigMetadata());
metaData.reset(m_swigFactory->makeSwigMetadata());
if (!metaData)
throw std::runtime_error("F-UDF-CL-SL-JAVA-1615: Failure while importing scripts");
}
Expand Down
Loading

0 comments on commit 8dc5834

Please sign in to comment.