From 04fb798756dd0909a09b2c9d636590cfd197bfbc Mon Sep 17 00:00:00 2001 From: Yuan Zhou Date: Mon, 24 Oct 2022 09:15:24 +0800 Subject: [PATCH 1/6] enable C++17 support Signed-off-by: Yuan Zhou --- native-sql-engine/cpp/src/CMakeLists.txt | 2 +- .../cpp/src/codegen/arrow_compute/ext/codegen_common.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/native-sql-engine/cpp/src/CMakeLists.txt b/native-sql-engine/cpp/src/CMakeLists.txt index da7540651..df7a1ec20 100644 --- a/native-sql-engine/cpp/src/CMakeLists.txt +++ b/native-sql-engine/cpp/src/CMakeLists.txt @@ -7,7 +7,7 @@ include(FindPkgConfig) include(GNUInstallDirs) include(CheckCXXCompilerFlag) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/native-sql-engine/cpp/src/codegen/arrow_compute/ext/codegen_common.cc b/native-sql-engine/cpp/src/codegen/arrow_compute/ext/codegen_common.cc index 1d99cd435..302950a4f 100644 --- a/native-sql-engine/cpp/src/codegen/arrow_compute/ext/codegen_common.cc +++ b/native-sql-engine/cpp/src/codegen/arrow_compute/ext/codegen_common.cc @@ -657,7 +657,7 @@ arrow::Status CompileCodes(std::string codes, std::string signature) { struct stat pch_stat; auto ret = stat(libwscg_pch.c_str(), &pch_stat); if (ret == -1) { - cmd += env_gcc + " -std=c++14 -Wno-deprecated-declarations " + arrow_header + + cmd += env_gcc + " -std=c++17 -Wno-deprecated-declarations " + arrow_header + arrow_lib + arrow_lib2 + nativesql_header + nativesql_header_2 + " -c " + libwscgfile + env_codegen_option + " -fPIC && "; } From f5b9a8f0b1da05a3982a038fe5e437d32bec0490 Mon Sep 17 00:00:00 2001 From: Yuan Zhou Date: Mon, 24 Oct 2022 13:28:54 +0800 Subject: [PATCH 2/6] using from_chars instead of stoi/stod Signed-off-by: Yuan Zhou --- .../ext/expression_codegen_visitor.cc | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/native-sql-engine/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc b/native-sql-engine/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc index 9207dc63d..acc1b9344 100644 --- a/native-sql-engine/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc +++ b/native-sql-engine/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc @@ -671,17 +671,27 @@ arrow::Status ExpressionCodegenVisitor::Visit(const gandiva::FunctionNode& node) std::string func_str; if (func_name.compare("castINTOrNull") == 0) { - func_str = " = std::stoi"; + // C++17 based from_chars + // std::from_chars(str.data(), str.data() + str.size(), result); + func_str = " = std::from_chars"; + prepare_ss << "int result = 0" << std::endl; } else if (func_name.compare("castBIGINTOrNull") == 0) { - func_str = " = std::stol"; + // C++17 based from_chars + // std::from_chars(str.data(), str.data() + str.size(), result); + func_str = " = std::from_chars"; + prepare_ss << "long int result = 0" << std::endl; } else if (func_name.compare("castFLOAT4OrNull") == 0) { - func_str = " = std::stof"; + func_str = " = ::arrow_vendored::fast_float::from_chars"; + prepare_ss << "float result = 0" << std::endl; } else { - func_str = " = std::stod"; + func_str = " = ::arrow_vendored::fast_float::from_chars"; + prepare_ss << "double result = 0" << std::endl; } prepare_ss << "try {" << std::endl; prepare_ss << codes_str_ << func_str << "(" << child_visitor_list[0]->GetResult() - << ");" << std::endl; + << ".data(), " << child_visitor_list[0]->GetResult() << ".length(), " + << "result);" << std::endl; + prepare_ss << codes_str_ << " = result;" << std::endl; prepare_ss << "} catch (std::invalid_argument) {" << std::endl; prepare_ss << validity << " = false;" << std::endl; prepare_ss << "} catch (std::out_of_range) {" << std::endl; From b11ab7e3591880c1b9216d2f4fbd02899cfe9f63 Mon Sep 17 00:00:00 2001 From: Yuan Zhou Date: Mon, 24 Oct 2022 16:44:20 +0800 Subject: [PATCH 3/6] fix compile Signed-off-by: Yuan Zhou --- .../arrow_compute/ext/expression_codegen_visitor.cc | 11 ++++++----- native-sql-engine/cpp/src/precompile/wscgapi.hpp | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/native-sql-engine/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc b/native-sql-engine/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc index acc1b9344..a0df20eff 100644 --- a/native-sql-engine/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc +++ b/native-sql-engine/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc @@ -674,22 +674,23 @@ arrow::Status ExpressionCodegenVisitor::Visit(const gandiva::FunctionNode& node) // C++17 based from_chars // std::from_chars(str.data(), str.data() + str.size(), result); func_str = " = std::from_chars"; - prepare_ss << "int result = 0" << std::endl; + prepare_ss << "int result = 0;" << std::endl; } else if (func_name.compare("castBIGINTOrNull") == 0) { // C++17 based from_chars // std::from_chars(str.data(), str.data() + str.size(), result); func_str = " = std::from_chars"; - prepare_ss << "long int result = 0" << std::endl; + prepare_ss << "long int result = 0;" << std::endl; } else if (func_name.compare("castFLOAT4OrNull") == 0) { func_str = " = ::arrow_vendored::fast_float::from_chars"; - prepare_ss << "float result = 0" << std::endl; + prepare_ss << "float result = 0;" << std::endl; } else { func_str = " = ::arrow_vendored::fast_float::from_chars"; - prepare_ss << "double result = 0" << std::endl; + prepare_ss << "double result = 0;" << std::endl; } prepare_ss << "try {" << std::endl; prepare_ss << codes_str_ << func_str << "(" << child_visitor_list[0]->GetResult() - << ".data(), " << child_visitor_list[0]->GetResult() << ".length(), " + << ".data(), " << child_visitor_list[0]->GetResult() << ".data() + " + << child_visitor_list[0]->GetResult() << ".length(), " << "result);" << std::endl; prepare_ss << codes_str_ << " = result;" << std::endl; prepare_ss << "} catch (std::invalid_argument) {" << std::endl; diff --git a/native-sql-engine/cpp/src/precompile/wscgapi.hpp b/native-sql-engine/cpp/src/precompile/wscgapi.hpp index 49bd18cf3..d293b0e51 100644 --- a/native-sql-engine/cpp/src/precompile/wscgapi.hpp +++ b/native-sql-engine/cpp/src/precompile/wscgapi.hpp @@ -6,6 +6,7 @@ #include #include +#include #include #include From 4a132dd3f28f3674ab406016371c368cba093859 Mon Sep 17 00:00:00 2001 From: Yuan Zhou Date: Mon, 24 Oct 2022 17:08:11 +0800 Subject: [PATCH 4/6] fix codegen Signed-off-by: Yuan Zhou --- .../arrow_compute/ext/expression_codegen_visitor.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/native-sql-engine/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc b/native-sql-engine/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc index a0df20eff..99ff235bc 100644 --- a/native-sql-engine/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc +++ b/native-sql-engine/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc @@ -673,22 +673,22 @@ arrow::Status ExpressionCodegenVisitor::Visit(const gandiva::FunctionNode& node) if (func_name.compare("castINTOrNull") == 0) { // C++17 based from_chars // std::from_chars(str.data(), str.data() + str.size(), result); - func_str = " = std::from_chars"; + func_str = " std::from_chars"; prepare_ss << "int result = 0;" << std::endl; } else if (func_name.compare("castBIGINTOrNull") == 0) { // C++17 based from_chars // std::from_chars(str.data(), str.data() + str.size(), result); - func_str = " = std::from_chars"; + func_str = " std::from_chars"; prepare_ss << "long int result = 0;" << std::endl; } else if (func_name.compare("castFLOAT4OrNull") == 0) { - func_str = " = ::arrow_vendored::fast_float::from_chars"; + func_str = " ::arrow_vendored::fast_float::from_chars"; prepare_ss << "float result = 0;" << std::endl; } else { - func_str = " = ::arrow_vendored::fast_float::from_chars"; + func_str = " ::arrow_vendored::fast_float::from_chars"; prepare_ss << "double result = 0;" << std::endl; } prepare_ss << "try {" << std::endl; - prepare_ss << codes_str_ << func_str << "(" << child_visitor_list[0]->GetResult() + prepare_ss << func_str << "(" << child_visitor_list[0]->GetResult() << ".data(), " << child_visitor_list[0]->GetResult() << ".data() + " << child_visitor_list[0]->GetResult() << ".length(), " << "result);" << std::endl; From d0dcc079f1ec39658bcb95b70ca533a8b002c445 Mon Sep 17 00:00:00 2001 From: Yuan Zhou Date: Mon, 24 Oct 2022 21:44:00 +0800 Subject: [PATCH 5/6] fix format Signed-off-by: Yuan Zhou --- .../codegen/arrow_compute/ext/expression_codegen_visitor.cc | 4 ++-- native-sql-engine/cpp/src/precompile/wscgapi.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/native-sql-engine/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc b/native-sql-engine/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc index 99ff235bc..da2bd8116 100644 --- a/native-sql-engine/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc +++ b/native-sql-engine/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc @@ -688,8 +688,8 @@ arrow::Status ExpressionCodegenVisitor::Visit(const gandiva::FunctionNode& node) prepare_ss << "double result = 0;" << std::endl; } prepare_ss << "try {" << std::endl; - prepare_ss << func_str << "(" << child_visitor_list[0]->GetResult() - << ".data(), " << child_visitor_list[0]->GetResult() << ".data() + " + prepare_ss << func_str << "(" << child_visitor_list[0]->GetResult() << ".data(), " + << child_visitor_list[0]->GetResult() << ".data() + " << child_visitor_list[0]->GetResult() << ".length(), " << "result);" << std::endl; prepare_ss << codes_str_ << " = result;" << std::endl; diff --git a/native-sql-engine/cpp/src/precompile/wscgapi.hpp b/native-sql-engine/cpp/src/precompile/wscgapi.hpp index d293b0e51..2490edbaf 100644 --- a/native-sql-engine/cpp/src/precompile/wscgapi.hpp +++ b/native-sql-engine/cpp/src/precompile/wscgapi.hpp @@ -5,8 +5,8 @@ #include #include -#include #include +#include #include #include From f29b27250bf9c340fb668165bb488248b41d28d4 Mon Sep 17 00:00:00 2001 From: Yuan Zhou Date: Tue, 25 Oct 2022 08:33:16 +0800 Subject: [PATCH 6/6] adding missing header Signed-off-by: Yuan Zhou --- native-sql-engine/cpp/src/precompile/wscgapi.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/native-sql-engine/cpp/src/precompile/wscgapi.hpp b/native-sql-engine/cpp/src/precompile/wscgapi.hpp index 2490edbaf..f9ae1d6ca 100644 --- a/native-sql-engine/cpp/src/precompile/wscgapi.hpp +++ b/native-sql-engine/cpp/src/precompile/wscgapi.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include