From 1a092256c7b0cfa44420363b5ef39d9ee9b5db5a Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Sat, 21 May 2022 23:01:33 +0800 Subject: [PATCH 01/29] fix: Resolve compiling warnings #1826 --- src/nameserver/name_server_test.cc | 1 - src/tablet/tablet_impl_multi_path_test.cc | 8 ++++---- src/tablet/tablet_impl_projection_test.cc | 8 ++++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/nameserver/name_server_test.cc b/src/nameserver/name_server_test.cc index 30ad09c02ae..a77d5002525 100644 --- a/src/nameserver/name_server_test.cc +++ b/src/nameserver/name_server_test.cc @@ -297,7 +297,6 @@ TEST_P(NameServerImplTest, MakesnapshotTask) { } TEST_P(NameServerImplTest, ConfigGetAndSet) { - openmldb::common::StorageMode storage_mode = GetParam(); FLAGS_zk_cluster = "127.0.0.1:6181"; FLAGS_zk_root_path = "/rtidb3" + ::openmldb::test::GenRand(); diff --git a/src/tablet/tablet_impl_multi_path_test.cc b/src/tablet/tablet_impl_multi_path_test.cc index 7932c728635..c67acf48a8a 100644 --- a/src/tablet/tablet_impl_multi_path_test.cc +++ b/src/tablet/tablet_impl_multi_path_test.cc @@ -70,22 +70,22 @@ class DiskTestEnvironment : public ::testing::Environment{ virtual void SetUp() { std::vector file_path; ::openmldb::base::SplitString(FLAGS_hdd_root_path, ",", file_path); - for (int i = 0; i < file_path.size(); i++) { + for (uint32_t i = 0; i < file_path.size(); i++) { ::openmldb::base::RemoveDirRecursive(file_path[i]); } ::openmldb::base::SplitString(FLAGS_recycle_bin_hdd_root_path, ",", file_path); - for (int i = 0; i < file_path.size(); i++) { + for (uint32_t i = 0; i < file_path.size(); i++) { ::openmldb::base::RemoveDirRecursive(file_path[i]); } } virtual void TearDown() { std::vector file_path; ::openmldb::base::SplitString(FLAGS_hdd_root_path, ",", file_path); - for (int i = 0; i < file_path.size(); i++) { + for (uint32_t i = 0; i < file_path.size(); i++) { ::openmldb::base::RemoveDirRecursive(file_path[i]); } ::openmldb::base::SplitString(FLAGS_recycle_bin_hdd_root_path, ",", file_path); - for (int i = 0; i < file_path.size(); i++) { + for (uint32_t i = 0; i < file_path.size(); i++) { ::openmldb::base::RemoveDirRecursive(file_path[i]); } } diff --git a/src/tablet/tablet_impl_projection_test.cc b/src/tablet/tablet_impl_projection_test.cc index f8d00985afb..5f70b50bb51 100644 --- a/src/tablet/tablet_impl_projection_test.cc +++ b/src/tablet/tablet_impl_projection_test.cc @@ -81,22 +81,22 @@ class DiskTestEnvironment : public ::testing::Environment{ virtual void SetUp() { std::vector file_path; ::openmldb::base::SplitString(FLAGS_hdd_root_path, ",", file_path); - for (int i = 0; i < file_path.size(); i++) { + for (uint32_t i = 0; i < file_path.size(); i++) { ::openmldb::base::RemoveDirRecursive(file_path[i]); } ::openmldb::base::SplitString(FLAGS_recycle_bin_hdd_root_path, ",", file_path); - for (int i = 0; i < file_path.size(); i++) { + for (uint32_t i = 0; i < file_path.size(); i++) { ::openmldb::base::RemoveDirRecursive(file_path[i]); } } virtual void TearDown() { std::vector file_path; ::openmldb::base::SplitString(FLAGS_hdd_root_path, ",", file_path); - for (int i = 0; i < file_path.size(); i++) { + for (uint32_t i = 0; i < file_path.size(); i++) { ::openmldb::base::RemoveDirRecursive(file_path[i]); } ::openmldb::base::SplitString(FLAGS_recycle_bin_hdd_root_path, ",", file_path); - for (int i = 0; i < file_path.size(); i++) { + for (uint32_t i = 0; i < file_path.size(); i++) { ::openmldb::base::RemoveDirRecursive(file_path[i]); } } From 81cf88f592fff76c156c6cc281440fc9cb1ae9cc Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Sat, 21 May 2022 23:55:21 +0800 Subject: [PATCH 02/29] fix: Resolve the JavaDoc warning of openmldb-jdbc #1319 --- .../main/java/com/_4paradigm/openmldb/jdbc/SQLResultSet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/openmldb-jdbc/src/main/java/com/_4paradigm/openmldb/jdbc/SQLResultSet.java b/java/openmldb-jdbc/src/main/java/com/_4paradigm/openmldb/jdbc/SQLResultSet.java index 1ac5ce5d91b..4565f366998 100644 --- a/java/openmldb-jdbc/src/main/java/com/_4paradigm/openmldb/jdbc/SQLResultSet.java +++ b/java/openmldb-jdbc/src/main/java/com/_4paradigm/openmldb/jdbc/SQLResultSet.java @@ -330,7 +330,7 @@ public InputStream getAsciiStream(String s) throws SQLException { } /** - * @param s + * @param s the string for the unicode stream extraction. * @deprecated */ @Override From 4e943ce112b56533cf68ab4f3f7bab12bae6b40c Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Sun, 22 May 2022 00:04:23 +0800 Subject: [PATCH 03/29] fix: Resolve the JavaDoc warning of openmldb-jdbc - complete --- .../com/_4paradigm/openmldb/common/LibraryLoader.java | 5 +++++ .../java/com/_4paradigm/openmldb/sdk/QueryFuture.java | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/java/openmldb-jdbc/src/main/java/com/_4paradigm/openmldb/common/LibraryLoader.java b/java/openmldb-jdbc/src/main/java/com/_4paradigm/openmldb/common/LibraryLoader.java index b20e33f05fa..a4b47a2268b 100644 --- a/java/openmldb-jdbc/src/main/java/com/_4paradigm/openmldb/common/LibraryLoader.java +++ b/java/openmldb-jdbc/src/main/java/com/_4paradigm/openmldb/common/LibraryLoader.java @@ -87,8 +87,13 @@ synchronized public static void loadLibrary(String libraryPath) { } } + /** * Extract library in resource into filesystem + * @param path the path that will be extracted. + * @param isTemp true if a temp file is created, otherwise false. + * @return the absolute path of the resources. + * @throws IOException if the resources cannot be found. */ public static String extractResource(String path, boolean isTemp) throws IOException { InputStream inputStream = LibraryLoader.class.getClassLoader().getResourceAsStream(path); diff --git a/java/openmldb-jdbc/src/main/java/com/_4paradigm/openmldb/sdk/QueryFuture.java b/java/openmldb-jdbc/src/main/java/com/_4paradigm/openmldb/sdk/QueryFuture.java index fa7e269350d..36f50a79448 100644 --- a/java/openmldb-jdbc/src/main/java/com/_4paradigm/openmldb/sdk/QueryFuture.java +++ b/java/openmldb-jdbc/src/main/java/com/_4paradigm/openmldb/sdk/QueryFuture.java @@ -70,11 +70,11 @@ public java.sql.ResultSet get() throws InterruptedException, ExecutionException /** * * @param l current timeout set by executeQeuryAsyn, so the param is invalid - * @param timeUnit - * @return - * @throws InterruptedException - * @throws ExecutionException - * @throws TimeoutException + * @param timeUnit the time unit of the timeout, which is also invalid. + * @return the result of the query from the database + * @throws InterruptedException throws when a thread is waiting, sleeping, or otherwise occupied, and the thread is interrupted, either before or during the activity. + * @throws ExecutionException throws when attempting to retrieve the result of a task that aborted by throwing an exception. + * @throws TimeoutException throws when a blocking operation times out. */ @Override @Deprecated From 9fd80002316561ddf3beb7dd0ea5082df8370803 Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Mon, 23 May 2022 15:51:26 +0800 Subject: [PATCH 04/29] fixed null val --- .../com/_4paradigm/openmldb/batch/nodes/WindowAggPlan.scala | 2 +- .../com/_4paradigm/openmldb/batch/window/WindowComputer.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/java/openmldb-batch/src/main/scala/com/_4paradigm/openmldb/batch/nodes/WindowAggPlan.scala b/java/openmldb-batch/src/main/scala/com/_4paradigm/openmldb/batch/nodes/WindowAggPlan.scala index f7abcfe86e4..4e761848311 100755 --- a/java/openmldb-batch/src/main/scala/com/_4paradigm/openmldb/batch/nodes/WindowAggPlan.scala +++ b/java/openmldb-batch/src/main/scala/com/_4paradigm/openmldb/batch/nodes/WindowAggPlan.scala @@ -730,7 +730,7 @@ object WindowAggPlan { - def isValidOrder(key: Long): Boolean = { + def isValidOrder(key: java.lang.Long): Boolean = { // TODO: Ignore the null value, maybe handle null in the future if (key == null) { false diff --git a/java/openmldb-batch/src/main/scala/com/_4paradigm/openmldb/batch/window/WindowComputer.scala b/java/openmldb-batch/src/main/scala/com/_4paradigm/openmldb/batch/window/WindowComputer.scala index 60acab146eb..7ecbd0e6a4f 100644 --- a/java/openmldb-batch/src/main/scala/com/_4paradigm/openmldb/batch/window/WindowComputer.scala +++ b/java/openmldb-batch/src/main/scala/com/_4paradigm/openmldb/batch/window/WindowComputer.scala @@ -222,7 +222,7 @@ class WindowComputer(config: WindowAggConfig, jit: HybridSeJitWrapper, keepIndex config.startOffset, config.endOffset, config.rowPreceding, config.maxSize) } - def extractKey(curRow: Row): Long = { + def extractKey(curRow: Row): java.lang.Long = { SparkRowUtil.getLongFromIndex(config.orderIdx, orderField.dataType, curRow) } From ae5aa8b9c96c6772495a1396df6a2b3d97cc35fc Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Thu, 26 May 2022 22:44:18 +0800 Subject: [PATCH 05/29] reset --- .../com/_4paradigm/openmldb/batch/nodes/WindowAggPlan.scala | 2 +- .../com/_4paradigm/openmldb/batch/window/WindowComputer.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/java/openmldb-batch/src/main/scala/com/_4paradigm/openmldb/batch/nodes/WindowAggPlan.scala b/java/openmldb-batch/src/main/scala/com/_4paradigm/openmldb/batch/nodes/WindowAggPlan.scala index 4e761848311..f7abcfe86e4 100755 --- a/java/openmldb-batch/src/main/scala/com/_4paradigm/openmldb/batch/nodes/WindowAggPlan.scala +++ b/java/openmldb-batch/src/main/scala/com/_4paradigm/openmldb/batch/nodes/WindowAggPlan.scala @@ -730,7 +730,7 @@ object WindowAggPlan { - def isValidOrder(key: java.lang.Long): Boolean = { + def isValidOrder(key: Long): Boolean = { // TODO: Ignore the null value, maybe handle null in the future if (key == null) { false diff --git a/java/openmldb-batch/src/main/scala/com/_4paradigm/openmldb/batch/window/WindowComputer.scala b/java/openmldb-batch/src/main/scala/com/_4paradigm/openmldb/batch/window/WindowComputer.scala index 7ecbd0e6a4f..60acab146eb 100644 --- a/java/openmldb-batch/src/main/scala/com/_4paradigm/openmldb/batch/window/WindowComputer.scala +++ b/java/openmldb-batch/src/main/scala/com/_4paradigm/openmldb/batch/window/WindowComputer.scala @@ -222,7 +222,7 @@ class WindowComputer(config: WindowAggConfig, jit: HybridSeJitWrapper, keepIndex config.startOffset, config.endOffset, config.rowPreceding, config.maxSize) } - def extractKey(curRow: Row): java.lang.Long = { + def extractKey(curRow: Row): Long = { SparkRowUtil.getLongFromIndex(config.orderIdx, orderField.dataType, curRow) } From a0bafb079b39ac70d39af40e3c1a3f833660b6f4 Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Thu, 26 May 2022 23:06:50 +0800 Subject: [PATCH 06/29] add --- hybridse/src/codegen/udf_ir_builder_test.cc | 6 ++++++ hybridse/src/udf/default_udf_library.cc | 14 ++++++++++++++ hybridse/src/udf/udf.cc | 11 +++++++++++ hybridse/src/udf/udf.h | 2 ++ 4 files changed, 33 insertions(+) diff --git a/hybridse/src/codegen/udf_ir_builder_test.cc b/hybridse/src/codegen/udf_ir_builder_test.cc index b8388ebe6c3..ebdaf4a2e63 100644 --- a/hybridse/src/codegen/udf_ir_builder_test.cc +++ b/hybridse/src/codegen/udf_ir_builder_test.cc @@ -1007,6 +1007,12 @@ TEST_F(UdfIRBuilderTest, degrees) { CheckUdf(udf_name, -90.0, -pi/2); CheckUdf, Nullable>(udf_name, nullptr, nullptr); } +TEST_F(UdfIRBuilderTest, char_test) { + auto udf_name = "char"; + CheckUdf(udf_name, "A", 65); + CheckUdf(udf_name, "B", 322); + +} } // namespace codegen } // namespace hybridse diff --git a/hybridse/src/udf/default_udf_library.cc b/hybridse/src/udf/default_udf_library.cc index 27f84fa5683..ef183ccfa01 100644 --- a/hybridse/src/udf/default_udf_library.cc +++ b/hybridse/src/udf/default_udf_library.cc @@ -895,6 +895,20 @@ void DefaultUdfLibrary::InitStringUdf() { @since 0.4.0)"); RegisterAlias("lower", "lcase"); RegisterAlias("upper", "ucase"); + RegisterExternal("char") + .args( + static_cast(udf::v1::int_to_char)) + .return_by_arg(true) + .doc(R"( + @brief Returns the ASCII character having the binary equivalent to expr. If n is larger than 256 the result is equivalent to chr(n % 256). + + Example: + + @code{.sql} + SELECT char(65); + --output "A" + @endcode + @since 0.5.0)"); } void DefaultUdfLibrary::InitMathUdf() { diff --git a/hybridse/src/udf/udf.cc b/hybridse/src/udf/udf.cc index 31781ea7363..f3056c2e14e 100644 --- a/hybridse/src/udf/udf.cc +++ b/hybridse/src/udf/udf.cc @@ -157,6 +157,17 @@ int32_t weekofyear(Date *date) { } } +void int_to_char(int32_t val, StringRef* output){ + if (val > 256) + val = val % 256; + char *buffer = AllocManagedStringBuf(1); + output->size_ = 1; + char v=(char)(val); + std::string words(&v); + memcpy(buffer, words, output->size_); + output->data_ = buffer; +} + float Cotf(float x) { return cosf(x) / sinf(x); } double Degrees(double x) { return x * (180 / 3.141592653589793238463L); } diff --git a/hybridse/src/udf/udf.h b/hybridse/src/udf/udf.h index 1fca943fd31..fa6fea537fa 100644 --- a/hybridse/src/udf/udf.h +++ b/hybridse/src/udf/udf.h @@ -224,6 +224,8 @@ int32_t weekofyear(int64_t ts); int32_t weekofyear(Timestamp *ts); int32_t weekofyear(Date *ts); +void int_to_char(int32_t, StringRef*); + float Cotf(float x); double Degrees(double x); From 10283cbc3c7880179c3415f49d00660b9098693d Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Fri, 27 May 2022 00:04:20 +0800 Subject: [PATCH 07/29] stringref --- hybridse/src/codegen/udf_ir_builder_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hybridse/src/codegen/udf_ir_builder_test.cc b/hybridse/src/codegen/udf_ir_builder_test.cc index ebdaf4a2e63..9ac386b118e 100644 --- a/hybridse/src/codegen/udf_ir_builder_test.cc +++ b/hybridse/src/codegen/udf_ir_builder_test.cc @@ -1009,8 +1009,8 @@ TEST_F(UdfIRBuilderTest, degrees) { } TEST_F(UdfIRBuilderTest, char_test) { auto udf_name = "char"; - CheckUdf(udf_name, "A", 65); - CheckUdf(udf_name, "B", 322); + CheckUdf(udf_name, StringRef("A"), 65); + CheckUdf(udf_name, StringRef("B"), 322); } } // namespace codegen From 36add00e28bc5c56b7439202b98ec23bb6c05e36 Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Fri, 27 May 2022 10:57:27 +0800 Subject: [PATCH 08/29] Update udf.cc --- hybridse/src/udf/udf.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hybridse/src/udf/udf.cc b/hybridse/src/udf/udf.cc index f3056c2e14e..5c81a7b972a 100644 --- a/hybridse/src/udf/udf.cc +++ b/hybridse/src/udf/udf.cc @@ -164,7 +164,7 @@ void int_to_char(int32_t val, StringRef* output){ output->size_ = 1; char v=(char)(val); std::string words(&v); - memcpy(buffer, words, output->size_); + memcpy(buffer, (void*)words.c_str(), output->size_); output->data_ = buffer; } From 51bec9184454c98eee0c8adf81938d9b6b92180a Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Fri, 27 May 2022 13:10:48 +0800 Subject: [PATCH 09/29] Update udf.cc --- hybridse/src/udf/udf.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hybridse/src/udf/udf.cc b/hybridse/src/udf/udf.cc index 5c81a7b972a..da03b073d0c 100644 --- a/hybridse/src/udf/udf.cc +++ b/hybridse/src/udf/udf.cc @@ -164,7 +164,7 @@ void int_to_char(int32_t val, StringRef* output){ output->size_ = 1; char v=(char)(val); std::string words(&v); - memcpy(buffer, (void*)words.c_str(), output->size_); + memcpy(buffer, (void*) words.c_str(), output->size_); output->data_ = buffer; } From 9cfe678462a7582f50cafb264e73ac5400e519c7 Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Fri, 27 May 2022 18:35:36 +0800 Subject: [PATCH 10/29] Update udf_ir_builder_test.cc --- hybridse/src/codegen/udf_ir_builder_test.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hybridse/src/codegen/udf_ir_builder_test.cc b/hybridse/src/codegen/udf_ir_builder_test.cc index 9ac386b118e..48bf2ceae60 100644 --- a/hybridse/src/codegen/udf_ir_builder_test.cc +++ b/hybridse/src/codegen/udf_ir_builder_test.cc @@ -1009,9 +1009,9 @@ TEST_F(UdfIRBuilderTest, degrees) { } TEST_F(UdfIRBuilderTest, char_test) { auto udf_name = "char"; - CheckUdf(udf_name, StringRef("A"), 65); - CheckUdf(udf_name, StringRef("B"), 322); - + CheckUdf(udf_name, StringRef("A"), 65); + CheckUdf(udf_name, StringRef("B"), 322); + CheckUdf(udf_name, nullptr, nullptr); } } // namespace codegen } // namespace hybridse From 6ce49498fb3f3a78e35d992d136b064b5c6feeab Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Fri, 27 May 2022 18:36:56 +0800 Subject: [PATCH 11/29] Update default_udf_library.cc --- hybridse/src/udf/default_udf_library.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hybridse/src/udf/default_udf_library.cc b/hybridse/src/udf/default_udf_library.cc index ef183ccfa01..e0941fa13db 100644 --- a/hybridse/src/udf/default_udf_library.cc +++ b/hybridse/src/udf/default_udf_library.cc @@ -895,12 +895,12 @@ void DefaultUdfLibrary::InitStringUdf() { @since 0.4.0)"); RegisterAlias("lower", "lcase"); RegisterAlias("upper", "ucase"); - RegisterExternal("char") + RegisterExternal("char") .args( static_cast(udf::v1::int_to_char)) .return_by_arg(true) .doc(R"( - @brief Returns the ASCII character having the binary equivalent to expr. If n is larger than 256 the result is equivalent to chr(n % 256). + @brief Returns the ASCII character having the binary equivalent to expr. If n is larger than 256 the result is equivalent to char(n % 256). Example: @@ -908,7 +908,7 @@ void DefaultUdfLibrary::InitStringUdf() { SELECT char(65); --output "A" @endcode - @since 0.5.0)"); + @since 0.6.0)"); } void DefaultUdfLibrary::InitMathUdf() { From ed77fef6ea61652ae569369e54802b208a4f9240 Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Fri, 27 May 2022 19:09:16 +0800 Subject: [PATCH 12/29] Update udf.cc --- hybridse/src/udf/udf.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/hybridse/src/udf/udf.cc b/hybridse/src/udf/udf.cc index da03b073d0c..d6297769e1f 100644 --- a/hybridse/src/udf/udf.cc +++ b/hybridse/src/udf/udf.cc @@ -160,12 +160,10 @@ int32_t weekofyear(Date *date) { void int_to_char(int32_t val, StringRef* output){ if (val > 256) val = val % 256; - char *buffer = AllocManagedStringBuf(1); output->size_ = 1; char v=(char)(val); - std::string words(&v); - memcpy(buffer, (void*) words.c_str(), output->size_); - output->data_ = buffer; + std::string word(&v); + output->data_ = word; } float Cotf(float x) { return cosf(x) / sinf(x); } From f0b628efd6a7ff24c89d4ad817c9372eadfe3dc0 Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Fri, 27 May 2022 19:43:12 +0800 Subject: [PATCH 13/29] Update udf.cc --- hybridse/src/udf/udf.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hybridse/src/udf/udf.cc b/hybridse/src/udf/udf.cc index d6297769e1f..13f192cb170 100644 --- a/hybridse/src/udf/udf.cc +++ b/hybridse/src/udf/udf.cc @@ -157,11 +157,11 @@ int32_t weekofyear(Date *date) { } } -void int_to_char(int32_t val, StringRef* output){ - if (val > 256) +void int_to_char(int32_t val, StringRef* output) { + if (val > 256) val = val % 256; output->size_ = 1; - char v=(char)(val); + char v = static_cast(val); std::string word(&v); output->data_ = word; } From b3a4338c3bdae6573bc40d109ecaa0e279959117 Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Fri, 27 May 2022 21:03:38 +0800 Subject: [PATCH 14/29] Update udf.cc --- hybridse/src/udf/udf.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hybridse/src/udf/udf.cc b/hybridse/src/udf/udf.cc index 13f192cb170..f7fde3da4d4 100644 --- a/hybridse/src/udf/udf.cc +++ b/hybridse/src/udf/udf.cc @@ -162,8 +162,7 @@ void int_to_char(int32_t val, StringRef* output) { val = val % 256; output->size_ = 1; char v = static_cast(val); - std::string word(&v); - output->data_ = word; + output->data_ = &v; } float Cotf(float x) { return cosf(x) / sinf(x); } From 0ed0f939151648580ab74d5abdafdf33760052ee Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Fri, 27 May 2022 21:40:43 +0800 Subject: [PATCH 15/29] Update udf_ir_builder_test.cc --- hybridse/src/codegen/udf_ir_builder_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hybridse/src/codegen/udf_ir_builder_test.cc b/hybridse/src/codegen/udf_ir_builder_test.cc index 48bf2ceae60..4f2f5a395c6 100644 --- a/hybridse/src/codegen/udf_ir_builder_test.cc +++ b/hybridse/src/codegen/udf_ir_builder_test.cc @@ -1011,7 +1011,7 @@ TEST_F(UdfIRBuilderTest, char_test) { auto udf_name = "char"; CheckUdf(udf_name, StringRef("A"), 65); CheckUdf(udf_name, StringRef("B"), 322); - CheckUdf(udf_name, nullptr, nullptr); + CheckUdf, Nullable>(udf_name, nullptr, nullptr); } } // namespace codegen } // namespace hybridse From d19bfd3738f9cc8efafe765f17c2f0b10d95012f Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Fri, 27 May 2022 23:02:56 +0800 Subject: [PATCH 16/29] Update udf.cc --- hybridse/src/udf/udf.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hybridse/src/udf/udf.cc b/hybridse/src/udf/udf.cc index f7fde3da4d4..39d948b2600 100644 --- a/hybridse/src/udf/udf.cc +++ b/hybridse/src/udf/udf.cc @@ -162,7 +162,9 @@ void int_to_char(int32_t val, StringRef* output) { val = val % 256; output->size_ = 1; char v = static_cast(val); - output->data_ = &v; + std::string s; + s = c; + output->data_ = s.c_str(); } float Cotf(float x) { return cosf(x) / sinf(x); } From 7b1a104e3c8df73432e03ea117b8dadac0cc5a64 Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Sat, 28 May 2022 00:14:50 +0800 Subject: [PATCH 17/29] Update udf.cc --- hybridse/src/udf/udf.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hybridse/src/udf/udf.cc b/hybridse/src/udf/udf.cc index 39d948b2600..f66c4870b08 100644 --- a/hybridse/src/udf/udf.cc +++ b/hybridse/src/udf/udf.cc @@ -163,7 +163,7 @@ void int_to_char(int32_t val, StringRef* output) { output->size_ = 1; char v = static_cast(val); std::string s; - s = c; + s = v; output->data_ = s.c_str(); } From f732fec78642d660b68f3395071da526d1fa744a Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Sat, 28 May 2022 00:40:32 +0800 Subject: [PATCH 18/29] Update udf.cc --- hybridse/src/udf/udf.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hybridse/src/udf/udf.cc b/hybridse/src/udf/udf.cc index f66c4870b08..d17c4fa3f63 100644 --- a/hybridse/src/udf/udf.cc +++ b/hybridse/src/udf/udf.cc @@ -158,7 +158,7 @@ int32_t weekofyear(Date *date) { } void int_to_char(int32_t val, StringRef* output) { - if (val > 256) + if (val > 256 || val < 0) val = val % 256; output->size_ = 1; char v = static_cast(val); From 03c11970de59dff6e9da2c159562e5208205b749 Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Sat, 28 May 2022 00:44:24 +0800 Subject: [PATCH 19/29] Update udf_ir_builder_test.cc --- hybridse/src/codegen/udf_ir_builder_test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hybridse/src/codegen/udf_ir_builder_test.cc b/hybridse/src/codegen/udf_ir_builder_test.cc index 4f2f5a395c6..1f0242f6f26 100644 --- a/hybridse/src/codegen/udf_ir_builder_test.cc +++ b/hybridse/src/codegen/udf_ir_builder_test.cc @@ -1007,10 +1007,11 @@ TEST_F(UdfIRBuilderTest, degrees) { CheckUdf(udf_name, -90.0, -pi/2); CheckUdf, Nullable>(udf_name, nullptr, nullptr); } -TEST_F(UdfIRBuilderTest, char_test) { +TEST_F(UdfIRBuilderTest, charTest) { auto udf_name = "char"; CheckUdf(udf_name, StringRef("A"), 65); CheckUdf(udf_name, StringRef("B"), 322); + CheckUdf(udf_name, StringRef("N"), -178); CheckUdf, Nullable>(udf_name, nullptr, nullptr); } } // namespace codegen From 19cbda374f46d836a363b82ba25b9f50c85b0364 Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Sat, 28 May 2022 00:45:51 +0800 Subject: [PATCH 20/29] Update udf.cc --- hybridse/src/udf/udf.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hybridse/src/udf/udf.cc b/hybridse/src/udf/udf.cc index d17c4fa3f63..6690910b9f8 100644 --- a/hybridse/src/udf/udf.cc +++ b/hybridse/src/udf/udf.cc @@ -158,7 +158,7 @@ int32_t weekofyear(Date *date) { } void int_to_char(int32_t val, StringRef* output) { - if (val > 256 || val < 0) + if (val > 256 || val < -256) val = val % 256; output->size_ = 1; char v = static_cast(val); From bde00ea6b3c066a1b04b2c6bed2378db6d176f31 Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Sat, 28 May 2022 16:06:55 +0800 Subject: [PATCH 21/29] Update udf.cc --- hybridse/src/udf/udf.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hybridse/src/udf/udf.cc b/hybridse/src/udf/udf.cc index 6690910b9f8..8f063a64a09 100644 --- a/hybridse/src/udf/udf.cc +++ b/hybridse/src/udf/udf.cc @@ -162,9 +162,10 @@ void int_to_char(int32_t val, StringRef* output) { val = val % 256; output->size_ = 1; char v = static_cast(val); - std::string s; - s = v; - output->data_ = s.c_str(); + char *buffer = AllocManagedStringBuf(1); + output->size_ = 1; + memcpy(buffer, &v, output->size_); + output->data_ = buffer; } float Cotf(float x) { return cosf(x) / sinf(x); } From 8eeb98401fab0cd152c430574dd037c0b74b1366 Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Sat, 28 May 2022 17:11:38 +0800 Subject: [PATCH 22/29] Update udf_ir_builder_test.cc --- hybridse/src/codegen/udf_ir_builder_test.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/hybridse/src/codegen/udf_ir_builder_test.cc b/hybridse/src/codegen/udf_ir_builder_test.cc index f13436705e9..bae51e31b66 100644 --- a/hybridse/src/codegen/udf_ir_builder_test.cc +++ b/hybridse/src/codegen/udf_ir_builder_test.cc @@ -1013,6 +1013,7 @@ TEST_F(UdfIRBuilderTest, charTest) { CheckUdf(udf_name, StringRef("B"), 322); CheckUdf(udf_name, StringRef("N"), -178); CheckUdf, Nullable>(udf_name, nullptr, nullptr); +} TEST_F(UdfIRBuilderTest, degree_to_radius_check) { auto udf_name = "radians"; CheckUdf(udf_name, 3.141592653589793238463, 180); From 9d5dfc84f29788565f3526d9706b6af82612a9e2 Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Mon, 30 May 2022 14:19:26 +0800 Subject: [PATCH 23/29] Update udf.cc --- hybridse/src/udf/udf.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hybridse/src/udf/udf.cc b/hybridse/src/udf/udf.cc index 68c696fe725..dcb49f3b1db 100644 --- a/hybridse/src/udf/udf.cc +++ b/hybridse/src/udf/udf.cc @@ -158,9 +158,7 @@ int32_t weekofyear(Date *date) { } void int_to_char(int32_t val, StringRef* output) { - if (val > 256 || val < -256) - val = val % 256; - output->size_ = 1; + val = val % 256; char v = static_cast(val); char *buffer = AllocManagedStringBuf(1); output->size_ = 1; From 9c0b3983e5542619fade3d90d0c8b32497e0181b Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Mon, 30 May 2022 14:20:44 +0800 Subject: [PATCH 24/29] Update default_udf_library.cc --- hybridse/src/udf/default_udf_library.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hybridse/src/udf/default_udf_library.cc b/hybridse/src/udf/default_udf_library.cc index 20c7097b971..417653f7e8e 100644 --- a/hybridse/src/udf/default_udf_library.cc +++ b/hybridse/src/udf/default_udf_library.cc @@ -900,7 +900,7 @@ void DefaultUdfLibrary::InitStringUdf() { static_cast(udf::v1::int_to_char)) .return_by_arg(true) .doc(R"( - @brief Returns the ASCII character having the binary equivalent to expr. If n is larger than 256 the result is equivalent to char(n % 256). + @brief Returns the ASCII character having the binary equivalent to expr. If n >= 256 the result is equivalent to char(n % 256). Example: From 21b859cbfbe584091187bfd8ebcdb5ca0d1f4aa3 Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Mon, 30 May 2022 14:26:43 +0800 Subject: [PATCH 25/29] Update udf_ir_builder_test.cc --- hybridse/src/codegen/udf_ir_builder_test.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hybridse/src/codegen/udf_ir_builder_test.cc b/hybridse/src/codegen/udf_ir_builder_test.cc index 80d140e77ea..410b02b63c7 100644 --- a/hybridse/src/codegen/udf_ir_builder_test.cc +++ b/hybridse/src/codegen/udf_ir_builder_test.cc @@ -1012,6 +1012,8 @@ TEST_F(UdfIRBuilderTest, charTest) { CheckUdf(udf_name, StringRef("A"), 65); CheckUdf(udf_name, StringRef("B"), 322); CheckUdf(udf_name, StringRef("N"), -178); + CheckUdf(udf_name, StringRef(""), 256); + CheckUdf(udf_name, StringRef(""), -256); CheckUdf, Nullable>(udf_name, nullptr, nullptr); } TEST_F(UdfIRBuilderTest, char_length_udf_test) { From 0b7b6f66b5321b8a47c1fc08156d4e8f77951cac Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Mon, 30 May 2022 15:33:48 +0800 Subject: [PATCH 26/29] Update udf_ir_builder_test.cc --- hybridse/src/codegen/udf_ir_builder_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hybridse/src/codegen/udf_ir_builder_test.cc b/hybridse/src/codegen/udf_ir_builder_test.cc index 410b02b63c7..bc69d7e0d1d 100644 --- a/hybridse/src/codegen/udf_ir_builder_test.cc +++ b/hybridse/src/codegen/udf_ir_builder_test.cc @@ -1012,8 +1012,8 @@ TEST_F(UdfIRBuilderTest, charTest) { CheckUdf(udf_name, StringRef("A"), 65); CheckUdf(udf_name, StringRef("B"), 322); CheckUdf(udf_name, StringRef("N"), -178); - CheckUdf(udf_name, StringRef(""), 256); - CheckUdf(udf_name, StringRef(""), -256); + CheckUdf(udf_name, StringRef("\0"), 256); + CheckUdf(udf_name, StringRef("\0"), -256); CheckUdf, Nullable>(udf_name, nullptr, nullptr); } TEST_F(UdfIRBuilderTest, char_length_udf_test) { From 9e86ab5c7134b390ff60a3de328ba36f29955481 Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Mon, 30 May 2022 16:48:56 +0800 Subject: [PATCH 27/29] Update udf.cc --- hybridse/src/udf/udf.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hybridse/src/udf/udf.cc b/hybridse/src/udf/udf.cc index dcb49f3b1db..7c11f8009f6 100644 --- a/hybridse/src/udf/udf.cc +++ b/hybridse/src/udf/udf.cc @@ -159,9 +159,15 @@ int32_t weekofyear(Date *date) { void int_to_char(int32_t val, StringRef* output) { val = val % 256; + int32_t strl = 1; + if (val == 0) { + strl = 0; + } else { + strl = 1; + } char v = static_cast(val); - char *buffer = AllocManagedStringBuf(1); - output->size_ = 1; + char *buffer = AllocManagedStringBuf(strl); + output->size_ = strl; memcpy(buffer, &v, output->size_); output->data_ = buffer; } From c876837a71e412cddb567fc07b7a8e2342bf1972 Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Mon, 30 May 2022 23:07:10 +0800 Subject: [PATCH 28/29] Update udf.cc --- hybridse/src/udf/udf.cc | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/hybridse/src/udf/udf.cc b/hybridse/src/udf/udf.cc index 7c11f8009f6..dcb49f3b1db 100644 --- a/hybridse/src/udf/udf.cc +++ b/hybridse/src/udf/udf.cc @@ -159,15 +159,9 @@ int32_t weekofyear(Date *date) { void int_to_char(int32_t val, StringRef* output) { val = val % 256; - int32_t strl = 1; - if (val == 0) { - strl = 0; - } else { - strl = 1; - } char v = static_cast(val); - char *buffer = AllocManagedStringBuf(strl); - output->size_ = strl; + char *buffer = AllocManagedStringBuf(1); + output->size_ = 1; memcpy(buffer, &v, output->size_); output->data_ = buffer; } From eb0119fc4ea20481689560def69c050d2a5cd72e Mon Sep 17 00:00:00 2001 From: Wu Wenhan <1020645987@qq.com> Date: Mon, 30 May 2022 23:08:33 +0800 Subject: [PATCH 29/29] Update udf_ir_builder_test.cc --- hybridse/src/codegen/udf_ir_builder_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hybridse/src/codegen/udf_ir_builder_test.cc b/hybridse/src/codegen/udf_ir_builder_test.cc index bc69d7e0d1d..e72fadaa7d6 100644 --- a/hybridse/src/codegen/udf_ir_builder_test.cc +++ b/hybridse/src/codegen/udf_ir_builder_test.cc @@ -1012,8 +1012,8 @@ TEST_F(UdfIRBuilderTest, charTest) { CheckUdf(udf_name, StringRef("A"), 65); CheckUdf(udf_name, StringRef("B"), 322); CheckUdf(udf_name, StringRef("N"), -178); - CheckUdf(udf_name, StringRef("\0"), 256); - CheckUdf(udf_name, StringRef("\0"), -256); + CheckUdf(udf_name, StringRef(1, "\0"), 256); + CheckUdf(udf_name, StringRef(1, "\0"), -256); CheckUdf, Nullable>(udf_name, nullptr, nullptr); } TEST_F(UdfIRBuilderTest, char_length_udf_test) {