-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CUBVEC-24] Convert CHAR types to DB Vector in tp_value_cast (#5771)
http://jira.cubrid.org/browse/CUBVEC-24 * feat(object_domain, db_set): coerce str to vector * feat(object_domain): function tp_str_to_vector * style(object_domain): fix style * refactor(object_domain): no magic number for sizes * fix(object_domain): 63 instead of 64 for null terminator * replace intl_skip_spaces to plain c impl * rename tp_str_to_vector to tp_atovector * add db_vector.cpp, db_vector.hpp with db_string_to_vector function * convert db_string_to_vector to cpp style * improve readability * more readability * feat!(db_vector.cpp): use rapidjson parser * style: format and isnan check
- Loading branch information
Showing
8 changed files
with
252 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2008 Search Solution Corporation | ||
* Copyright 2016 CUBRID Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
/* | ||
* @file db_vector.cpp | ||
* @brief Implements string to vector conversion functionality | ||
*/ | ||
|
||
#include "error_code.h" | ||
#include <cmath> | ||
#include <limits> | ||
#include "rapidjson/document.h" | ||
// XXX: SHOULD BE THE LAST INCLUDE HEADER | ||
#include "memory_wrapper.hpp" | ||
|
||
|
||
int db_string_to_vector ( | ||
const char *p, | ||
int str_len, | ||
float *vector, | ||
int *p_count | ||
) | ||
{ | ||
// Validate input parameters | ||
if (!p || !vector || !p_count || str_len <= 0) | ||
{ | ||
return ER_FAILED; | ||
} | ||
|
||
// Parse without modifying the length (fixes const assignment error) | ||
rapidjson::Document doc; | ||
rapidjson::ParseResult result = doc.Parse (p, static_cast<size_t> (str_len)); | ||
if (!result) | ||
{ | ||
return ER_FAILED; | ||
} | ||
|
||
// Check if root is an array | ||
if (!doc.IsArray()) | ||
{ | ||
return ER_FAILED; | ||
} | ||
|
||
// Check array size | ||
size_t size = doc.Size(); | ||
if (size > static_cast<size_t> (std::numeric_limits<int>::max())) | ||
{ | ||
return ER_FAILED; | ||
} | ||
|
||
// Convert each element to float | ||
for (size_t i = 0; i < size; i++) | ||
{ | ||
if (!doc[i].IsNumber()) | ||
{ | ||
return ER_FAILED; | ||
} | ||
|
||
float num = doc[i].GetFloat(); | ||
|
||
if (std::isinf (num) || std::isnan (num)) | ||
{ | ||
return ER_FAILED; | ||
} | ||
|
||
vector[i] = num; | ||
|
||
} | ||
|
||
*p_count = static_cast<int> (size); | ||
return NO_ERROR; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2008 Search Solution Corporation | ||
* Copyright 2016 CUBRID Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
/* | ||
* db_vector.hpp - Definitions for the vector utilities. | ||
*/ | ||
|
||
#ifndef _DB_VECTOR_HPP_ | ||
#define _DB_VECTOR_HPP_ | ||
|
||
#ident "$Id$" | ||
|
||
extern int db_string_to_vector (const char *p, int str_len, float * vector, int * count); | ||
|
||
#endif /* _DB_VECTOR_HPP_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters