Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: built-in-function: support char(int) function #817 #1896

Merged
merged 34 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1a09225
fix: Resolve compiling warnings #1826
Ivyee17 May 21, 2022
81cf88f
fix: Resolve the JavaDoc warning of openmldb-jdbc #1319
Ivyee17 May 21, 2022
4e943ce
fix: Resolve the JavaDoc warning of openmldb-jdbc - complete
Ivyee17 May 21, 2022
fe5d1b1
Merge branch '4paradigm:main' into main
Ivyee17 May 23, 2022
3de60f4
Merge branch 'main' of https://github.com/Ivyee17/OpenMLDB into main
Ivyee17 May 23, 2022
9fd8000
fixed null val
Ivyee17 May 23, 2022
9fbd5bd
Merge branch 'main' of https://github.com/4paradigm/OpenMLDB into main
Ivyee17 May 23, 2022
ae5aa8b
reset
Ivyee17 May 26, 2022
a0bafb0
add
Ivyee17 May 26, 2022
10283cb
stringref
Ivyee17 May 26, 2022
36add00
Update udf.cc
Ivyee17 May 27, 2022
51bec91
Update udf.cc
Ivyee17 May 27, 2022
9cfe678
Update udf_ir_builder_test.cc
Ivyee17 May 27, 2022
6ce4949
Update default_udf_library.cc
Ivyee17 May 27, 2022
ed77fef
Update udf.cc
Ivyee17 May 27, 2022
f0b628e
Update udf.cc
Ivyee17 May 27, 2022
b3a4338
Update udf.cc
Ivyee17 May 27, 2022
0ed0f93
Update udf_ir_builder_test.cc
Ivyee17 May 27, 2022
d19bfd3
Update udf.cc
Ivyee17 May 27, 2022
7b1a104
Update udf.cc
Ivyee17 May 27, 2022
f732fec
Update udf.cc
Ivyee17 May 27, 2022
03c1197
Update udf_ir_builder_test.cc
Ivyee17 May 27, 2022
19cbda3
Update udf.cc
Ivyee17 May 27, 2022
bde00ea
Update udf.cc
Ivyee17 May 28, 2022
da870ee
Merge branch 'main' into ascii_feat
Ivyee17 May 28, 2022
8eeb984
Update udf_ir_builder_test.cc
Ivyee17 May 28, 2022
e141ee3
Merge branch 'main' into ascii_feat
Ivyee17 May 28, 2022
9d5dfc8
Update udf.cc
Ivyee17 May 30, 2022
9c0b398
Update default_udf_library.cc
Ivyee17 May 30, 2022
21b859c
Update udf_ir_builder_test.cc
Ivyee17 May 30, 2022
0b7b6f6
Update udf_ir_builder_test.cc
Ivyee17 May 30, 2022
9e86ab5
Update udf.cc
Ivyee17 May 30, 2022
c876837
Update udf.cc
Ivyee17 May 30, 2022
eb0119f
Update udf_ir_builder_test.cc
Ivyee17 May 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions hybridse/src/codegen/udf_ir_builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,12 @@ TEST_F(UdfIRBuilderTest, degrees) {
CheckUdf<double, double>(udf_name, -90.0, -pi/2);
CheckUdf<Nullable<double>, Nullable<double>>(udf_name, nullptr, nullptr);
}
TEST_F(UdfIRBuilderTest, char_test) {
Ivyee17 marked this conversation as resolved.
Show resolved Hide resolved
auto udf_name = "char";
CheckUdf<StringRef,int32_t>(udf_name, StringRef("A"), 65);
Ivyee17 marked this conversation as resolved.
Show resolved Hide resolved
CheckUdf<StringRef,int32_t>(udf_name, StringRef("B"), 322);
Ivyee17 marked this conversation as resolved.
Show resolved Hide resolved

}
} // namespace codegen
} // namespace hybridse

Expand Down
14 changes: 14 additions & 0 deletions hybridse/src/udf/default_udf_library.cc
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,20 @@ void DefaultUdfLibrary::InitStringUdf() {
@since 0.4.0)");
RegisterAlias("lower", "lcase");
RegisterAlias("upper", "ucase");
RegisterExternal("char")
Ivyee17 marked this conversation as resolved.
Show resolved Hide resolved
.args<int32_t>(
static_cast<void (*)(int32_t, StringRef*)>(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).
Ivyee17 marked this conversation as resolved.
Show resolved Hide resolved

Example:

@code{.sql}
SELECT char(65);
--output "A"
@endcode
@since 0.5.0)");
Ivyee17 marked this conversation as resolved.
Show resolved Hide resolved
}

void DefaultUdfLibrary::InitMathUdf() {
Expand Down
11 changes: 11 additions & 0 deletions hybridse/src/udf/udf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ int32_t weekofyear(Date *date) {
}
}

void int_to_char(int32_t val, StringRef* output){
if (val > 256)
Ivyee17 marked this conversation as resolved.
Show resolved Hide resolved
val = val % 256;
char *buffer = AllocManagedStringBuf(1);
output->size_ = 1;
Ivyee17 marked this conversation as resolved.
Show resolved Hide resolved
char v=(char)(val);
std::string words(&v);
aceforeverd marked this conversation as resolved.
Show resolved Hide resolved
memcpy(buffer, (void*) words.c_str(), output->size_);
output->data_ = buffer;
}

float Cotf(float x) { return cosf(x) / sinf(x); }

double Degrees(double x) { return x * (180 / 3.141592653589793238463L); }
Expand Down
2 changes: 2 additions & 0 deletions hybridse/src/udf/udf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down