Skip to content

Commit b06c85c

Browse files
authored
remove stringFormat (#150)
* use std::format * fix extra precision print * rm testing files
1 parent 9bf2581 commit b06c85c

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

src_cpp/py_connection.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "common/constants.h"
77
#include "common/exception/not_implemented.h"
88
#include "common/exception/runtime.h"
9-
#include "common/string_format.h"
109
#include "common/types/uuid.h"
1110
#include "common/utils.h"
1211
#include "datetime.h" // from Python
@@ -17,6 +16,7 @@
1716
#include "pandas/pandas_scan.h"
1817
#include "processor/result/factorized_table.h"
1918
#include "pyarrow/pyarrow_scan.h"
19+
#include <format>
2020

2121
using namespace lbug::common;
2222
using namespace lbug;
@@ -203,10 +203,10 @@ void PyConnection::getAllEdgesForTorchGeometric(py::array_t<int64_t>& npArray,
203203
// Set the number of threads to 1 for fetching edges to ensure ordering.
204204
auto numThreadsForExec = conn->getMaxNumThreadForExec();
205205
conn->setMaxNumThreadForExec(1);
206-
// Run queries in batch to fetch edges.
207-
auto queryString = "MATCH (a:{})-[:{}]->(b:{}) WHERE offset(id(b)) >= $s AND offset(id(b)) < "
208-
"$e RETURN offset(id(a)), offset(id(b))";
209-
auto query = stringFormat(queryString, srcTableName, relName, dstTableName);
206+
auto query =
207+
std::format("MATCH (a:{})-[:{}]->(b:{}) WHERE offset(id(b)) >= $s AND offset(id(b)) < "
208+
"$e RETURN offset(id(a)), offset(id(b))",
209+
srcTableName, relName, dstTableName);
210210
auto preparedStatement = conn->prepare(query);
211211
auto srcBuffer = buffer;
212212
auto dstBuffer = buffer + numRels;
@@ -378,8 +378,8 @@ static LogicalType pyLogicalType(const py::handle& val) {
378378
}
379379
if (precision > common::DECIMAL_PRECISION_LIMIT) {
380380
throw common::NotImplementedException(
381-
stringFormat("Decimal precision cannot be greater than {}"
382-
"Note: positive exponents contribute to precision",
381+
std::format("Decimal precision cannot be greater than {}"
382+
"Note: positive exponents contribute to precision",
383383
common::DECIMAL_PRECISION_LIMIT));
384384
}
385385
return LogicalType::DECIMAL(precision, -exponent);
@@ -403,13 +403,13 @@ static LogicalType pyLogicalType(const py::handle& val) {
403403
curChildValueType = pyLogicalType(child.second);
404404
LogicalType resultKey, resultValue;
405405
if (!LogicalTypeUtils::tryGetMaxLogicalType(childKeyType, curChildKeyType, resultKey)) {
406-
throw RuntimeException(stringFormat(
406+
throw RuntimeException(std::format(
407407
"Cannot convert Python object to Lbug value : {} is incompatible with {}",
408408
childKeyType.toString(), curChildKeyType.toString()));
409409
}
410410
if (!LogicalTypeUtils::tryGetMaxLogicalType(childValueType, curChildValueType,
411411
resultValue)) {
412-
throw RuntimeException(stringFormat(
412+
throw RuntimeException(std::format(
413413
"Cannot convert Python object to Lbug value : {} is incompatible with {}",
414414
childValueType.toString(), curChildValueType.toString()));
415415
}
@@ -424,7 +424,7 @@ static LogicalType pyLogicalType(const py::handle& val) {
424424
auto curChildType = pyLogicalType(child);
425425
LogicalType result;
426426
if (!LogicalTypeUtils::tryGetMaxLogicalType(childType, curChildType, result)) {
427-
throw RuntimeException(stringFormat(
427+
throw RuntimeException(std::format(
428428
"Cannot convert Python object to Lbug value : {} is incompatible with {}",
429429
childType.toString(), curChildType.toString()));
430430
}
@@ -520,7 +520,7 @@ static LogicalType pyLogicalTypeFromParameter(const py::handle& val) {
520520
auto curChildType = pyLogicalTypeFromParameter(child);
521521
LogicalType result;
522522
if (!LogicalTypeUtils::tryGetMaxLogicalType(childType, curChildType, result)) {
523-
throw RuntimeException(stringFormat(
523+
throw RuntimeException(std::format(
524524
"Cannot convert Python object to Lbug value : {} is incompatible with {}",
525525
childType.toString(), curChildType.toString()));
526526
}

src_cpp/py_conversion.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "common/type_utils.h"
77
#include "common/types/uuid.h"
88
#include "py_objects.h"
9+
#include <format>
910

1011
namespace lbug {
1112

@@ -41,7 +42,7 @@ PythonObjectType getPythonObjectType(py::handle& ele) {
4142
} else if (py::isinstance<py::dict>(ele)) {
4243
return PythonObjectType::Dict;
4344
} else {
44-
throw NotImplementedException(stringFormat("Scanning of type {} has not been implemented",
45+
throw NotImplementedException(std::format("Scanning of type {} has not been implemented",
4546
py::str(py::type::of(ele)).cast<std::string>()));
4647
}
4748
}
@@ -51,7 +52,7 @@ void tryTransformPythonNumeric(common::ValueVector* outputVector, uint64_t pos,
5152
int64_t value = PyLong_AsLongLongAndOverflow(ele.ptr(), &overflow);
5253
if (overflow != 0) {
5354
PyErr_Clear();
54-
throw common::ConversionException(common::stringFormat(
55+
throw common::ConversionException(std::format(
5556
"Failed to cast value: Python value '{}' to INT64", std::string(pybind11::str(ele))));
5657
}
5758
outputVector->setNull(pos, false /* isNull */);
@@ -84,7 +85,7 @@ void transformDictionaryToStruct(common::ValueVector* outputVector, uint64_t pos
8485
auto structKeys = transformStructKeys(dict.keys, dict.len);
8586
if (StructType::getNumFields(outputVector->dataType) != dict.len) {
8687
throw common::ConversionException(
87-
common::stringFormat("Failed to convert python dictionary: {} to target type {}",
88+
std::format("Failed to convert python dictionary: {} to target type {}",
8889
dict.toString(), outputVector->dataType.toString()));
8990
}
9091

src_cpp/py_scan_config.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "common/constants.h"
44
#include "common/exception/binder.h"
55
#include "function/cast/functions/numeric_limits.h"
6+
#include <format>
67

78
namespace lbug {
89

@@ -31,7 +32,7 @@ PyScanConfig::PyScanConfig(const common::case_insensitive_map_t<common::Value>&
3132
ignoreErrors = i.second.val.booleanVal;
3233
} else {
3334
throw common::BinderException(
34-
common::stringFormat("{} Option not recognized by pyArrow scanner.", i.first));
35+
std::format("{} Option not recognized by pyArrow scanner.", i.first));
3536
}
3637
}
3738
}

src_cpp/py_udf.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
#include "cached_import/py_cached_import.h"
66
#include "common/exception/not_implemented.h"
77
#include "common/exception/runtime.h"
8-
#include "common/string_format.h"
98
#include "function/scalar_function.h"
109
#include "py_connection.h"
1110
#include "py_query_result.h"
11+
#include <format>
1212

1313
using namespace lbug::common;
1414
using namespace lbug;
@@ -116,8 +116,8 @@ static LogicalType getLogicalTypeNonNested(const py::handle& ele) {
116116
} else if (ele.is(py::type::of(py::dict()))) {
117117
throw RuntimeException("Map annotations must specify child types");
118118
} else {
119-
throw RuntimeException(common::stringFormat("Unsupported annotation of type {}",
120-
py::cast<std::string>(py::str(ele))));
119+
throw RuntimeException(
120+
std::format("Unsupported annotation of type {}", py::cast<std::string>(py::str(ele))));
121121
}
122122
}
123123

0 commit comments

Comments
 (0)