Skip to content

Commit

Permalink
Add smaller_casts.patch
Browse files Browse the repository at this point in the history
  • Loading branch information
carlopi committed Sep 25, 2024
1 parent 13e4ccb commit 8e78310
Showing 1 changed file with 151 additions and 0 deletions.
151 changes: 151 additions & 0 deletions patches/duckdb/smaller_casts.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
diff --git a/.github/workflows/Regression.yml b/.github/workflows/Regression.yml
index 25b5a470f7..bc9e633d0a 100644
--- a/.github/workflows/Regression.yml
+++ b/.github/workflows/Regression.yml
@@ -77,6 +77,11 @@ jobs:
make
cd ..

+ - name: List sizes of both binaries
+ shell: bash
+ run: |
+ ls -la build/release/duckdb duckdb/build/release/duckdb
+
- name: Set up benchmarks
shell: bash
run: |
diff --git a/src/function/cast/enum_casts.cpp b/src/function/cast/enum_casts.cpp
index 7e22cb932d..2b5b604982 100644
--- a/src/function/cast/enum_casts.cpp
+++ b/src/function/cast/enum_casts.cpp
@@ -17,8 +17,9 @@ bool EnumEnumCast(Vector &source, Vector &result, idx_t count, CastParameters &p
auto key = EnumType::GetPos(res_enum_type, dictionary_data[value]);
if (key == -1) {
if (!parameters.error_message) {
- return HandleVectorCastError::Operation<RES_TYPE>(CastExceptionText<SRC_TYPE, RES_TYPE>(value),
- mask, row_idx, vector_cast_data);
+ return HandleVectorCastError::Operation<RES_TYPE>(
+ CastExceptionText<SRC_TYPE>(value, TypeIdInfo::CreateObject<RES_TYPE>), mask, row_idx,
+ vector_cast_data);
} else {
mask.SetInvalid(row_idx);
}
diff --git a/src/function/cast/string_cast.cpp b/src/function/cast/string_cast.cpp
index 9f8b5ee298..5fd0d370fe 100644
--- a/src/function/cast/string_cast.cpp
+++ b/src/function/cast/string_cast.cpp
@@ -22,8 +22,10 @@ bool StringEnumCastLoop(const string_t *source_data, ValidityMask &source_mask,
if (source_mask.RowIsValid(source_idx)) {
auto pos = EnumType::GetPos(result_type, source_data[source_idx]);
if (pos == -1) {
+
result_data[i] = HandleVectorCastError::Operation<T>(
- CastExceptionText<string_t, T>(source_data[source_idx]), result_mask, i, vector_cast_data);
+ CastExceptionText<string_t>(source_data[source_idx], TypeIdInfo::CreateObject<T>), result_mask, i,
+ vector_cast_data);
} else {
result_data[i] = UnsafeNumericCast<T>(pos);
}
diff --git a/src/include/duckdb/common/operator/cast_operators.hpp b/src/include/duckdb/common/operator/cast_operators.hpp
index 3e4cb35e92..2b157157e2 100644
--- a/src/include/duckdb/common/operator/cast_operators.hpp
+++ b/src/include/duckdb/common/operator/cast_operators.hpp
@@ -51,19 +51,31 @@ struct TryCastErrorMessageCommaSeparated {
}
};

-template <class SRC, class DST>
-static string CastExceptionText(SRC input) {
+struct TypeIdInfo {
+ explicit TypeIdInfo(string name, bool isNum) : name(name), isNum(isNum) {
+ }
+ template <typename TYPE>
+ __attribute__((noinline)) static TypeIdInfo CreateObject() {
+ return TypeIdInfo(TypeIdToString(GetTypeId<TYPE>()), TypeIsNumber<TYPE>());
+ }
+ string name;
+ bool isNum;
+};
+
+typedef TypeIdInfo (*callback_typeidinfo)(void);
+
+template <class SRC>
+static string CastExceptionText(SRC input, callback_typeidinfo func) {
+ auto info = func();
if (std::is_same<SRC, string_t>()) {
- return "Could not convert string '" + ConvertToString::Operation<SRC>(input) + "' to " +
- TypeIdToString(GetTypeId<DST>());
+ return "Could not convert string '" + ConvertToString::Operation<SRC>(input) + "' to " + info.name;
}
- if (TypeIsNumber<SRC>() && TypeIsNumber<DST>()) {
+ if (TypeIsNumber<SRC>() && info.isNum) {
return "Type " + TypeIdToString(GetTypeId<SRC>()) + " with value " + ConvertToString::Operation<SRC>(input) +
- " can't be cast because the value is out of range for the destination type " +
- TypeIdToString(GetTypeId<DST>());
+ " can't be cast because the value is out of range for the destination type " + info.name;
}
return "Type " + TypeIdToString(GetTypeId<SRC>()) + " with value " + ConvertToString::Operation<SRC>(input) +
- " can't be cast to the destination type " + TypeIdToString(GetTypeId<DST>());
+ " can't be cast to the destination type " + info.name;
}

struct Cast {
@@ -71,7 +83,7 @@ struct Cast {
static inline DST Operation(SRC input) {
DST result;
if (!TryCast::Operation(input, result)) {
- throw InvalidInputException(CastExceptionText<SRC, DST>(input));
+ throw InvalidInputException(CastExceptionText<SRC>(input, TypeIdInfo::CreateObject<DST>));
}
return result;
}
diff --git a/src/include/duckdb/function/cast/vector_cast_helpers.hpp b/src/include/duckdb/function/cast/vector_cast_helpers.hpp
index 9766df4e32..8e07c465b4 100644
--- a/src/include/duckdb/function/cast/vector_cast_helpers.hpp
+++ b/src/include/duckdb/function/cast/vector_cast_helpers.hpp
@@ -35,8 +35,8 @@ struct VectorTryCastOperator {
return output;
}
auto data = reinterpret_cast<VectorTryCastData *>(dataptr);
- return HandleVectorCastError::Operation<RESULT_TYPE>(CastExceptionText<INPUT_TYPE, RESULT_TYPE>(input), mask,
- idx, *data);
+ return HandleVectorCastError::Operation<RESULT_TYPE>(
+ CastExceptionText<INPUT_TYPE>(input, TypeIdInfo::CreateObject<RESULT_TYPE>), mask, idx, *data);
}
};

@@ -49,8 +49,9 @@ struct VectorTryCastStrictOperator {
if (DUCKDB_LIKELY(OP::template Operation<INPUT_TYPE, RESULT_TYPE>(input, output, data->parameters.strict))) {
return output;
}
- return HandleVectorCastError::Operation<RESULT_TYPE>(CastExceptionText<INPUT_TYPE, RESULT_TYPE>(input), mask,
- idx, *data);
+
+ return HandleVectorCastError::Operation<RESULT_TYPE>(
+ CastExceptionText<INPUT_TYPE>(input, TypeIdInfo::CreateObject<RESULT_TYPE>), mask, idx, *data);
}
};

@@ -65,8 +66,9 @@ struct VectorTryCastErrorOperator {
}
bool has_error = data->parameters.error_message && !data->parameters.error_message->empty();
return HandleVectorCastError::Operation<RESULT_TYPE>(
- has_error ? *data->parameters.error_message : CastExceptionText<INPUT_TYPE, RESULT_TYPE>(input), mask, idx,
- *data);
+ has_error ? *data->parameters.error_message
+ : CastExceptionText<INPUT_TYPE>(input, TypeIdInfo::CreateObject<RESULT_TYPE>),
+ mask, idx, *data);
}
};

@@ -80,8 +82,8 @@ struct VectorTryCastStringOperator {
OP::template Operation<INPUT_TYPE, RESULT_TYPE>(input, output, data->result, data->parameters))) {
return output;
}
- return HandleVectorCastError::Operation<RESULT_TYPE>(CastExceptionText<INPUT_TYPE, RESULT_TYPE>(input), mask,
- idx, *data);
+ return HandleVectorCastError::Operation<RESULT_TYPE>(
+ CastExceptionText<INPUT_TYPE>(input, TypeIdInfo::CreateObject<RESULT_TYPE>), mask, idx, *data);
}
};

0 comments on commit 8e78310

Please sign in to comment.