Skip to content

Commit

Permalink
1. Fixed scriptclass, jvmOptions and jarPaths
Browse files Browse the repository at this point in the history
2. Removed parser_factor
  • Loading branch information
tomuben committed Sep 19, 2024
1 parent d6e57d1 commit f9b3597
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 155 deletions.
6 changes: 3 additions & 3 deletions exaudfclient/base/javacontainer/javacontainer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "base/javacontainer/javacontainer.h"
#include "base/javacontainer/javacontainer_impl.h"
#include "base/javacontainer/script_options/extractor.h"
#include "base/javacontainer/script_options/parser_factory.h"
#include "base/javacontainer/script_options/parser_legacy.h"


using namespace SWIGVMContainers;
Expand All @@ -24,8 +24,8 @@ JavaVMImpl::JavaVMImpl(bool checkOnly, bool noJNI): m_checkOnly(checkOnly), m_ex
stringstream ss;
m_exaJavaPath = "/exaudf/base/javacontainer"; // TODO hardcoded path

JavaScriptOptions::ParserFactoryLegacy scriptOptionsParserFactory;
JavaScriptOptions::Extractor extractor(scriptOptionsParserFactory,
JavaScriptOptions::ScriptOptionLinesParserLegacy scriptOptionsParser;
JavaScriptOptions::Extractor extractor(scriptOptionsParser,
[&](const std::string &msg){throwException(msg);});

DBG_FUNC_CALL(cerr,extractor.extract(m_scriptCode)); // To be called before scripts are imported. Otherwise, the script classname from an imported script could be used
Expand Down
9 changes: 5 additions & 4 deletions exaudfclient/base/javacontainer/script_options/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package(default_visibility = ["//visibility:public"])

cc_library(
name = "java_script_option_lines",
hdrs = [":extractor.h", ":parser_factory.h"],
srcs = [":parser.h", ":converter.h", ":converter.cc", ":parser_legacy.h", ":parser_legacy.cc", ":extractor.cc",
":parser_factory.cc", ":keywords.h", ":checksum.h", ":checksum.cc"],
deps = ["//base/script_options_parser:script_option_lines_parser", "//base/exaudflib:header", "//base/exaudflib:exaudflib-deps"],
hdrs = [":extractor.h", ":parser_legacy.h"],
srcs = [":parser.h", ":converter.h", ":converter.cc", ":parser_legacy.cc", ":extractor.cc",
":keywords.h", ":checksum.h", ":checksum.cc"],
deps = ["//base/script_options_parser:script_option_lines_parser", "//base:debug_message_h",
"//base/exaudflib:header", "//base/exaudflib:exaudflib-deps"],
)
3 changes: 3 additions & 0 deletions exaudfclient/base/javacontainer/script_options/converter.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "base/javacontainer/script_options/converter.h"
#include "base/debug_message.h"
#include <iostream>

namespace SWIGVMContainers {

Expand Down Expand Up @@ -27,6 +29,7 @@ void Converter::convertExternalJar(const std::string & value) {
}

void Converter::convertScriptClassName(const std::string & value) {
DBGVAR(std::cerr, value);
if (value != "") {
m_jvmOptions.push_back("-Dexasol.scriptclass=" + value);
}
Expand Down
30 changes: 18 additions & 12 deletions exaudfclient/base/javacontainer/script_options/extractor.cc
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
#include "base/javacontainer/script_options/extractor.h"
#include "base/javacontainer/script_options/parser_factory.h"
#include "base/javacontainer/script_options/parser.h"

#include "base/debug_message.h"
#include <iostream>

#define EXTR_DBG_FUNC_CALL(f) DBG_FUNC_CALL(std::cerr, f)

namespace SWIGVMContainers {

namespace JavaScriptOptions {



Extractor::Extractor(ParserFactory & parserFactory,
Extractor::Extractor(ScriptOptionsParser & parser,
std::function<void(const std::string&)> throwException)
: m_throwException(throwException)
, m_parserFactory(parserFactory) {}
, m_parser(parser) {}


void Extractor::extract(std::string & scriptCode) {
std::unique_ptr<ScriptOptionsParser> parser(m_parserFactory.makeParser());
parser->prepareScriptCode(scriptCode);
parser->parseForScriptClass( [&](const std::string& value){m_converter.convertScriptClassName(value);}, m_throwException);
parser->extractImportScripts(m_throwException);
parser->parseForJvmOptions( [&](const std::string& value){m_converter.convertScriptClassName(value);}, m_throwException);
parser->parseForExternalJars( [&](const std::string& value){m_converter.convertScriptClassName(value);}, m_throwException);
scriptCode = std::move(parser->getScriptCode());
m_parser.prepareScriptCode(scriptCode);
EXTR_DBG_FUNC_CALL(m_parser.parseForScriptClass( [&](const std::string& value){
EXTR_DBG_FUNC_CALL(m_converter.convertScriptClassName(value));
}, m_throwException));
EXTR_DBG_FUNC_CALL(m_parser.extractImportScripts(m_throwException));
EXTR_DBG_FUNC_CALL(m_parser.parseForJvmOptions( [&](const std::string& value){
EXTR_DBG_FUNC_CALL(m_converter.convertJvmOption(value));
}, m_throwException));
EXTR_DBG_FUNC_CALL(m_parser.parseForExternalJars( [&](const std::string& value){
EXTR_DBG_FUNC_CALL(m_converter.convertExternalJar(value));
}, m_throwException));
scriptCode = std::move(m_parser.getScriptCode());
}

} //namespace JavaScriptOptions
Expand Down
8 changes: 4 additions & 4 deletions exaudfclient/base/javacontainer/script_options/extractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


#include "base/javacontainer/script_options/converter.h"
#include "base/javacontainer/script_options/parser.h"



namespace SWIGVMContainers {
Expand All @@ -17,12 +17,12 @@ class SWIGMetadata;

namespace JavaScriptOptions {

class ParserFactory;
class ScriptOptionsParser;

class Extractor {

public:
Extractor(ParserFactory & parserFactory,
Extractor(ScriptOptionsParser & parser,
std::function<void(const std::string&)> throwException);

const std::set<std::string> & getJarPaths() const {
Expand All @@ -39,7 +39,7 @@ class Extractor {
std::function<void(const std::string&)> m_throwException;

Converter m_converter;
ParserFactory & m_parserFactory;
ScriptOptionsParser & m_parser;
};


Expand Down
15 changes: 0 additions & 15 deletions exaudfclient/base/javacontainer/script_options/parser_factory.cc

This file was deleted.

23 changes: 0 additions & 23 deletions exaudfclient/base/javacontainer/script_options/parser_factory.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ void ScriptOptionLinesParserLegacy::parseForSingleOption(const std::string keywo
}
}


void ScriptOptionLinesParserLegacy::parseForMultipleOptions(const std::string keyword,
std::function<void(const std::string &option, size_t pos)> callback,
std::function<void(const std::string&)> throwException) {
Expand All @@ -117,8 +116,6 @@ void ScriptOptionLinesParserLegacy::parseForMultipleOptions(const std::string ke
}
}



} //namespace JavaScriptOptions

} //namespace SWIGVMContainers
182 changes: 91 additions & 91 deletions exaudfclient/base/javacontainer/test/cpp/javacontainer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,94 +21,94 @@ TEST(JavaContainer, basic_jar) {
"-XX:+UseSerialGC" };
EXPECT_EQ(vm.getJavaVMInternalStatus().m_jvmOptions, expectedJVMOptions);
}


TEST(JavaContainer, basic_inline) {
const std::string script_code = "import java.time.LocalDateTime;"
"import java.time.ZoneOffset;"
"import java.time.format.DateTimeFormatter;"
"class SIMPLE {"
"static void main(String[] args) {"
"int i = 0;"
"}"
"static int run(ExaMetadata exa, ExaIterator ctx) {"
"return 0;"
"}"
"}";
JavaVMTest vm(script_code);
EXPECT_EQ(vm.getJavaVMInternalStatus().m_exaJavaPath, "/exaudf/base/javacontainer");
EXPECT_EQ(vm.getJavaVMInternalStatus().m_localClasspath, "/tmp");
const std::string expected_script_code = std::string("package com.exasol;\r\n") + script_code;
EXPECT_EQ(vm.getJavaVMInternalStatus().m_scriptCode, expected_script_code);
EXPECT_EQ(vm.getJavaVMInternalStatus().m_exaJarPath, "/exaudf/base/javacontainer/exaudf_deploy.jar");
EXPECT_EQ(vm.getJavaVMInternalStatus().m_classpath, "/tmp:/exaudf/base/javacontainer/exaudf_deploy.jar");
EXPECT_TRUE(vm.getJavaVMInternalStatus().m_needsCompilation);
const std::vector<std::string> expectedJVMOptions = { "-Xms128m", "-Xmx128m", "-Xss512k",
"-XX:ErrorFile=/tmp/hs_err_pid%p.log",
"-Djava.class.path=/tmp:/exaudf/base/javacontainer/exaudf_deploy.jar",
"-XX:+UseSerialGC" };
EXPECT_EQ(vm.getJavaVMInternalStatus().m_jvmOptions, expectedJVMOptions);
}



TEST(JavaContainer, combined_inline_jar) {
const std::string script_code = "import java.time.LocalDateTime;"
"import java.time.ZoneOffset;"
"import java.time.format.DateTimeFormatter;"
"class SIMPLE {"
"static void main(String[] args) {"
"int i = 0;"
"}"
"static int run(ExaMetadata exa, ExaIterator ctx) {"
"return 0;"
"}"
"}";
const std::string script_code_with_jar = std::string("%jar base/javacontainer/test/test.jar;") + script_code;
JavaVMTest vm(script_code_with_jar);
EXPECT_EQ(vm.getJavaVMInternalStatus().m_exaJavaPath, "/exaudf/base/javacontainer");
EXPECT_EQ(vm.getJavaVMInternalStatus().m_localClasspath, "/tmp");
const std::string expected_script_code = std::string("package com.exasol;\r\n") + script_code;
EXPECT_EQ(vm.getJavaVMInternalStatus().m_scriptCode, expected_script_code);
EXPECT_EQ(vm.getJavaVMInternalStatus().m_exaJarPath, "/exaudf/base/javacontainer/exaudf_deploy.jar");
EXPECT_EQ(vm.getJavaVMInternalStatus().m_classpath, "/tmp:/exaudf/base/javacontainer/exaudf_deploy.jar:base/javacontainer/test/test.jar");
EXPECT_TRUE(vm.getJavaVMInternalStatus().m_needsCompilation);
const std::vector<std::string> expectedJVMOptions = { "-Xms128m", "-Xmx128m", "-Xss512k",
"-XX:ErrorFile=/tmp/hs_err_pid%p.log",
"-Djava.class.path=/tmp:/exaudf/base/javacontainer/exaudf_deploy.jar:base/javacontainer/test/test.jar",
"-XX:+UseSerialGC" };
EXPECT_EQ(vm.getJavaVMInternalStatus().m_jvmOptions, expectedJVMOptions);
}


TEST(JavaContainer, quoted_jvm_option) {
const std::string script_code =
"%jvmoption -Dhttp.agent=\"ABC DEF\";\n\n"
"class JVMOPTION_TEST_WITH_SPACE {\n"
"static void run(ExaMetadata exa, ExaIterator ctx) throws Exception {\n\n"
" ctx.emit(\"Success!\");\n"
" }\n"
"}\n";
JavaVMTest vm(script_code);
EXPECT_EQ(vm.getJavaVMInternalStatus().m_exaJavaPath, "/exaudf/base/javacontainer");
EXPECT_EQ(vm.getJavaVMInternalStatus().m_localClasspath, "/tmp");
const std::string expected_script_code =
"package com.exasol;\r\n\n\n"
"class JVMOPTION_TEST_WITH_SPACE {\n"
"static void run(ExaMetadata exa, ExaIterator ctx) throws Exception {\n\n"
"\tctx.emit(\"Success!\");\n"
" }\n}\n";
EXPECT_EQ(vm.getJavaVMInternalStatus().m_scriptCode, expected_script_code);
EXPECT_EQ(vm.getJavaVMInternalStatus().m_exaJarPath, "/exaudf/base/javacontainer/exaudf_deploy.jar");
EXPECT_EQ(vm.getJavaVMInternalStatus().m_classpath, "/tmp:/exaudf/base/javacontainer/exaudf_deploy.jar");
EXPECT_TRUE(vm.getJavaVMInternalStatus().m_needsCompilation);
/*
* Note: The option "DEF" is wrong and causes UDF's to crash!
* The correct option would be '-Dhttp.agent=\"ABC DEF\"'
*/
const std::vector<std::string> expectedJVMOptions = { "-Dhttp.agent=\"ABC", "DEF\"", "-Xms128m", "-Xmx128m", "-Xss512k",
"-XX:ErrorFile=/tmp/hs_err_pid%p.log",
"-Djava.class.path=/tmp:/exaudf/base/javacontainer/exaudf_deploy.jar",
"-XX:+UseSerialGC" };
EXPECT_EQ(vm.getJavaVMInternalStatus().m_jvmOptions, expectedJVMOptions);
}
//
//
//TEST(JavaContainer, basic_inline) {
// const std::string script_code = "import java.time.LocalDateTime;"
// "import java.time.ZoneOffset;"
// "import java.time.format.DateTimeFormatter;"
// "class SIMPLE {"
// "static void main(String[] args) {"
// "int i = 0;"
// "}"
// "static int run(ExaMetadata exa, ExaIterator ctx) {"
// "return 0;"
// "}"
// "}";
// JavaVMTest vm(script_code);
// EXPECT_EQ(vm.getJavaVMInternalStatus().m_exaJavaPath, "/exaudf/base/javacontainer");
// EXPECT_EQ(vm.getJavaVMInternalStatus().m_localClasspath, "/tmp");
// const std::string expected_script_code = std::string("package com.exasol;\r\n") + script_code;
// EXPECT_EQ(vm.getJavaVMInternalStatus().m_scriptCode, expected_script_code);
// EXPECT_EQ(vm.getJavaVMInternalStatus().m_exaJarPath, "/exaudf/base/javacontainer/exaudf_deploy.jar");
// EXPECT_EQ(vm.getJavaVMInternalStatus().m_classpath, "/tmp:/exaudf/base/javacontainer/exaudf_deploy.jar");
// EXPECT_TRUE(vm.getJavaVMInternalStatus().m_needsCompilation);
// const std::vector<std::string> expectedJVMOptions = { "-Xms128m", "-Xmx128m", "-Xss512k",
// "-XX:ErrorFile=/tmp/hs_err_pid%p.log",
// "-Djava.class.path=/tmp:/exaudf/base/javacontainer/exaudf_deploy.jar",
// "-XX:+UseSerialGC" };
// EXPECT_EQ(vm.getJavaVMInternalStatus().m_jvmOptions, expectedJVMOptions);
//}
//
//
//
//TEST(JavaContainer, combined_inline_jar) {
// const std::string script_code = "import java.time.LocalDateTime;"
// "import java.time.ZoneOffset;"
// "import java.time.format.DateTimeFormatter;"
// "class SIMPLE {"
// "static void main(String[] args) {"
// "int i = 0;"
// "}"
// "static int run(ExaMetadata exa, ExaIterator ctx) {"
// "return 0;"
// "}"
// "}";
// const std::string script_code_with_jar = std::string("%jar base/javacontainer/test/test.jar;") + script_code;
// JavaVMTest vm(script_code_with_jar);
// EXPECT_EQ(vm.getJavaVMInternalStatus().m_exaJavaPath, "/exaudf/base/javacontainer");
// EXPECT_EQ(vm.getJavaVMInternalStatus().m_localClasspath, "/tmp");
// const std::string expected_script_code = std::string("package com.exasol;\r\n") + script_code;
// EXPECT_EQ(vm.getJavaVMInternalStatus().m_scriptCode, expected_script_code);
// EXPECT_EQ(vm.getJavaVMInternalStatus().m_exaJarPath, "/exaudf/base/javacontainer/exaudf_deploy.jar");
// EXPECT_EQ(vm.getJavaVMInternalStatus().m_classpath, "/tmp:/exaudf/base/javacontainer/exaudf_deploy.jar:base/javacontainer/test/test.jar");
// EXPECT_TRUE(vm.getJavaVMInternalStatus().m_needsCompilation);
// const std::vector<std::string> expectedJVMOptions = { "-Xms128m", "-Xmx128m", "-Xss512k",
// "-XX:ErrorFile=/tmp/hs_err_pid%p.log",
// "-Djava.class.path=/tmp:/exaudf/base/javacontainer/exaudf_deploy.jar:base/javacontainer/test/test.jar",
// "-XX:+UseSerialGC" };
// EXPECT_EQ(vm.getJavaVMInternalStatus().m_jvmOptions, expectedJVMOptions);
//}
//
//
//TEST(JavaContainer, quoted_jvm_option) {
// const std::string script_code =
// "%jvmoption -Dhttp.agent=\"ABC DEF\";\n\n"
// "class JVMOPTION_TEST_WITH_SPACE {\n"
// "static void run(ExaMetadata exa, ExaIterator ctx) throws Exception {\n\n"
// " ctx.emit(\"Success!\");\n"
// " }\n"
// "}\n";
// JavaVMTest vm(script_code);
// EXPECT_EQ(vm.getJavaVMInternalStatus().m_exaJavaPath, "/exaudf/base/javacontainer");
// EXPECT_EQ(vm.getJavaVMInternalStatus().m_localClasspath, "/tmp");
// const std::string expected_script_code =
// "package com.exasol;\r\n\n\n"
// "class JVMOPTION_TEST_WITH_SPACE {\n"
// "static void run(ExaMetadata exa, ExaIterator ctx) throws Exception {\n\n"
// "\tctx.emit(\"Success!\");\n"
// " }\n}\n";
// EXPECT_EQ(vm.getJavaVMInternalStatus().m_scriptCode, expected_script_code);
// EXPECT_EQ(vm.getJavaVMInternalStatus().m_exaJarPath, "/exaudf/base/javacontainer/exaudf_deploy.jar");
// EXPECT_EQ(vm.getJavaVMInternalStatus().m_classpath, "/tmp:/exaudf/base/javacontainer/exaudf_deploy.jar");
// EXPECT_TRUE(vm.getJavaVMInternalStatus().m_needsCompilation);
// /*
// * Note: The option "DEF" is wrong and causes UDF's to crash!
// * The correct option would be '-Dhttp.agent=\"ABC DEF\"'
// */
// const std::vector<std::string> expectedJVMOptions = { "-Dhttp.agent=\"ABC", "DEF\"", "-Xms128m", "-Xmx128m", "-Xss512k",
// "-XX:ErrorFile=/tmp/hs_err_pid%p.log",
// "-Djava.class.path=/tmp:/exaudf/base/javacontainer/exaudf_deploy.jar",
// "-XX:+UseSerialGC" };
// EXPECT_EQ(vm.getJavaVMInternalStatus().m_jvmOptions, expectedJVMOptions);
//}

0 comments on commit f9b3597

Please sign in to comment.