Skip to content

Commit

Permalink
Merge pull request #1354 from finos/exprtk
Browse files Browse the repository at this point in the history
Add Expressions Engine using ExprTk
  • Loading branch information
texodus authored May 12, 2021
2 parents f8b8dbd + 0a1e9b8 commit c97fb0a
Show file tree
Hide file tree
Showing 127 changed files with 12,341 additions and 17,101 deletions.
16 changes: 16 additions & 0 deletions cmake/exprtk.txt.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.7.2)

project(exprtk-download NONE)

include(ExternalProject)
ExternalProject_Add(exprtk
GIT_REPOSITORY https://github.com/ArashPartow/exprtk.git
GIT_TAG master
SOURCE_DIR "${CMAKE_BINARY_DIR}/exprtk-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/exprtk-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
CMAKE_ARGS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}"
)
15 changes: 10 additions & 5 deletions cpp/perspective/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ function (psp_build_dep name cmake_file)
EXCLUDE_FROM_ALL)

include_directories(${CMAKE_BINARY_DIR}/arrow-src/cpp/src/)
elseif(${name} STREQUAL exprtk)
# no cmakelists - just include the header
include_directories(${CMAKE_BINARY_DIR}/${name}-src)
else()
add_subdirectory(${CMAKE_BINARY_DIR}/${name}-src
${CMAKE_BINARY_DIR}/${name}-build
Expand Down Expand Up @@ -252,9 +255,10 @@ if (PSP_WASM_BUILD)
set(OPT_FLAGS " \
-O3 \
-g0 \
-flto \
-s AGGRESSIVE_VARIABLE_ELIMINATION=1 \
")

# TODO: -flto
endif()

set(ASYNC_MODE_FLAGS "")
Expand Down Expand Up @@ -445,6 +449,8 @@ else()
include_directories( ${FLATBUFFERS_INCLUDE_DIR} )
endif()

# Build exprtk for expression parsing
psp_build_dep("exprtk" "${PSP_CMAKE_MODULE_PATH}/exprtk.txt.in")
#####################

set(CMAKE_C_FLAGS " \
Expand Down Expand Up @@ -477,8 +483,7 @@ set (SOURCE_FILES
${PSP_CPP_SRC}/src/cpp/compat_impl_linux.cpp
${PSP_CPP_SRC}/src/cpp/compat_impl_osx.cpp
${PSP_CPP_SRC}/src/cpp/compat_impl_win.cpp
${PSP_CPP_SRC}/src/cpp/computed.cpp
${PSP_CPP_SRC}/src/cpp/computed_column_map.cpp
${PSP_CPP_SRC}/src/cpp/computed_expression.cpp
${PSP_CPP_SRC}/src/cpp/computed_function.cpp
${PSP_CPP_SRC}/src/cpp/config.cpp
${PSP_CPP_SRC}/src/cpp/context_base.cpp
Expand Down Expand Up @@ -553,8 +558,8 @@ set(WASM_SOURCE_FILES ${SOURCE_FILES}

set (PYTHON_BINDING_SOURCE_FILES
${PSP_PYTHON_SRC}/src/accessor.cpp
${PSP_PYTHON_SRC}/src/computed.cpp
${PSP_PYTHON_SRC}/src/context.cpp
${PSP_PYTHON_SRC}/src/expressions.cpp
${PSP_PYTHON_SRC}/src/fill.cpp
${PSP_PYTHON_SRC}/src/numpy.cpp
${PSP_PYTHON_SRC}/src/python.cpp
Expand All @@ -565,7 +570,7 @@ set (PYTHON_BINDING_SOURCE_FILES
)

if (WIN32)
set(CMAKE_CXX_FLAGS " /EHsc /MP")
set(CMAKE_CXX_FLAGS " /EHsc /MP /bigobj")
else()
set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS}")
endif()
Expand Down
136 changes: 0 additions & 136 deletions cpp/perspective/src/cpp/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,142 +303,6 @@ str_to_dtype(const std::string& typestring) {
}
}

t_computed_function_name
str_to_computed_function_name(const std::string& name) {
if (name == "+" || name == "add") {
return t_computed_function_name::ADD;
} else if (name == "-" || name == "subtract") {
return t_computed_function_name::SUBTRACT;
} else if (name == "*" || name == "multiply") {
return t_computed_function_name::MULTIPLY;
} else if (name == "/" || name == "divide") {
return t_computed_function_name::DIVIDE;
} else if (name == "%" || name == "percent_of") {
return t_computed_function_name::PERCENT_OF;
} else if (name == "^" || name == "pow") {
return t_computed_function_name::POW;
} else if (name == "==" || name == "equals") {
return t_computed_function_name::EQUALS;
} else if (name == "!=" || name == "not_equals") {
return t_computed_function_name::NOT_EQUALS;
} else if (name == ">" || name == "greater_than") {
return t_computed_function_name::GREATER_THAN;
} else if (name == "<" || name == "less_than") {
return t_computed_function_name::LESS_THAN;
} else if (name == "1/x" || name == "invert") {
return t_computed_function_name::INVERT;
} else if (name == "x^2" || name == "pow2") {
return t_computed_function_name::POW2;
} else if (name == "sqrt") {
return t_computed_function_name::SQRT;
} else if (name == "abs") {
return t_computed_function_name::ABS;
} else if (name == "log") {
return t_computed_function_name::LOG;
} else if (name == "exp") {
return t_computed_function_name::EXP;
} else if (name == "Uppercase" || name == "uppercase") {
return t_computed_function_name::UPPERCASE;
} else if (name == "Lowercase" || name == "lowercase") {
return t_computed_function_name::LOWERCASE;
} else if (name == "length") {
return t_computed_function_name::LENGTH;
} else if (name == "is") {
return t_computed_function_name::IS;
} else if (name == "concat_space") {
return t_computed_function_name::CONCAT_SPACE;
} else if (name == "concat_comma") {
return t_computed_function_name::CONCAT_COMMA;
} else if (name == "Bucket (10)" || name == "bin10") {
return t_computed_function_name::BUCKET_10;
} else if (name == "Bucket (100)" || name == "bin100") {
return t_computed_function_name::BUCKET_100;
} else if (name == "Bucket (1000)" || name == "bin1000") {
return t_computed_function_name::BUCKET_1000;
} else if (name == "Bucket (1/10)" || name == "bin10th") {
return t_computed_function_name::BUCKET_0_1;
} else if (name == "Bucket (1/100)" || name == "bin100th") {
return t_computed_function_name::BUCKET_0_0_1;
} else if (name == "Bucket (1/1000)" || name == "bin1000th") {
return t_computed_function_name::BUCKET_0_0_0_1;
} else if (name == "Hour of Day" || name == "hour_of_day") {
return t_computed_function_name::HOUR_OF_DAY;
} else if (name == "Day of Week" || name == "day_of_week") {
return t_computed_function_name::DAY_OF_WEEK;
} else if (name == "Month of Year" || name == "month_of_year") {
return t_computed_function_name::MONTH_OF_YEAR;
} else if (name == "Bucket (s)" || name == "second_bucket") {
return t_computed_function_name::SECOND_BUCKET;
} else if (name == "Bucket (m)" || name == "minute_bucket") {
return t_computed_function_name::MINUTE_BUCKET;
} else if (name == "Bucket (h)" || name == "hour_bucket") {
return t_computed_function_name::HOUR_BUCKET;
} else if (name == "Bucket (D)" || name == "day_bucket") {
return t_computed_function_name::DAY_BUCKET;
} else if (name == "Bucket (W)" || name == "week_bucket") {
return t_computed_function_name::WEEK_BUCKET;
} else if (name == "Bucket (M)" || name == "month_bucket") {
return t_computed_function_name::MONTH_BUCKET;
} else if (name == "Bucket (Y)" || name == "year_bucket") {
return t_computed_function_name::YEAR_BUCKET;
} else {
std::cerr
<< "Could not find computed function for `"
<< name << "`" << std::endl;
return t_computed_function_name::INVALID_COMPUTED_FUNCTION;
}
}

std::string
computed_function_name_to_string(t_computed_function_name name) {
switch (name) {
case INVALID_COMPUTED_FUNCTION: return "invalid computed function";
case ADD: return "+";
case SUBTRACT: return "-";
case MULTIPLY: return "*";
case DIVIDE: return "/";
case PERCENT_OF: return "%";
case POW: return "pow";
case EQUALS: return "==";
case NOT_EQUALS: return "!=";
case GREATER_THAN: return ">";
case LESS_THAN: return "<";
case INVERT: return "invert";
case POW2: return "pow2";
case SQRT: return "sqrt";
case ABS: return "abs";
case LOG: return "log";
case EXP: return "exp";
case UPPERCASE: return "uppercase";
case LOWERCASE: return "lowercase";
case LENGTH: return "length";
case IS: return "is";
case CONCAT_SPACE: return "concat_space";
case CONCAT_COMMA: return "concat_comma";
case BUCKET_10: return "bin10";
case BUCKET_100: return "bin100";
case BUCKET_1000: return "bin1000";
case BUCKET_0_1: return "bin10th";
case BUCKET_0_0_1: return "bin100th";
case BUCKET_0_0_0_1: return "bin1000th";
case HOUR_OF_DAY: return "hour_of_day";
case DAY_OF_WEEK: return "day_of_week";
case MONTH_OF_YEAR: return "month_of_year";
case SECOND_BUCKET: return "second_bucket";
case MINUTE_BUCKET: return "minute_bucket";
case HOUR_BUCKET: return "hour_bucket";
case DAY_BUCKET: return "day_bucket";
case WEEK_BUCKET: return "week_bucket";
case MONTH_BUCKET: return "month_bucket";
case YEAR_BUCKET: return "year_bucket";
default: break;
}

std::cerr
<< "Could not convert computed function name to string." << std::endl;
return "INVALID_COMPUTED_FUNCTION";
}

std::string
filter_op_to_str(t_filter_op op) {
switch (op) {
Expand Down
Loading

0 comments on commit c97fb0a

Please sign in to comment.