aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvvvv <vvvv@yandex-team.ru>2022-03-28 19:58:14 +0300
committervvvv <vvvv@yandex-team.ru>2022-03-28 19:58:14 +0300
commit53fa597e686e6c0b2e74ebd8ceb8b2f4a38c0a67 (patch)
treeb61cf05472461b09967783aaca1b03b82bf763a7
parent7c332b6a8b33c7d576d976c28500ea767fd091d2 (diff)
downloadydb-53fa597e686e6c0b2e74ebd8ceb8b2f4a38c0a67.tar.gz
YQL-13710 all types in PgConst
ref:d4dde445e2588f9a68be26d68c5b6c86948fd3a6
-rw-r--r--ydb/library/yql/parser/pg_wrapper/comp_factory.cpp92
1 files changed, 42 insertions, 50 deletions
diff --git a/ydb/library/yql/parser/pg_wrapper/comp_factory.cpp b/ydb/library/yql/parser/pg_wrapper/comp_factory.cpp
index 6390675026..dac97fd96a 100644
--- a/ydb/library/yql/parser/pg_wrapper/comp_factory.cpp
+++ b/ydb/library/yql/parser/pg_wrapper/comp_factory.cpp
@@ -21,7 +21,6 @@ extern "C" {
#include "postgres.h"
#include "catalog/pg_type_d.h"
#include "catalog/pg_collation_d.h"
-#include "utils/fmgrprotos.h"
#include "utils/builtins.h"
#include "utils/datum.h"
#include "utils/memutils.h"
@@ -189,6 +188,10 @@ struct TMkqlPgAdapter {
#define SET_MEMORY_CONTEXT \
CurrentMemoryContext = ErrorContext = TMkqlPgAdapter::Instance();
+inline ui32 MakeTypeIOParam(const NPg::TTypeDesc& desc) {
+ return desc.ElementTypeId ? desc.ElementTypeId : desc.TypeId;
+}
+
class TPgConst : public TMutableComputationNode<TPgConst> {
typedef TMutableComputationNode<TPgConst> TBaseComputation;
public:
@@ -196,57 +199,47 @@ public:
: TBaseComputation(mutables)
, TypeId(typeId)
, Value(value)
+ , TypeDesc(NPg::LookupType(TypeId))
{
+ Zero(FInfo);
+ Y_ENSURE(TypeDesc.InFuncId);
+ fmgr_info(TypeDesc.InFuncId, &FInfo);
+ Y_ENSURE(!FInfo.fn_retset);
+ Y_ENSURE(FInfo.fn_addr);
+ Y_ENSURE(FInfo.fn_nargs >=1 && FInfo.fn_nargs <= 3);
+ TypeIOParam = MakeTypeIOParam(TypeDesc);
}
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx) const {
- if (TypeId == INT2OID) {
- return ScalarDatumToPod(Int16GetDatum(FromString<i16>(Value)));
- } else if (TypeId == INT4OID) {
- return ScalarDatumToPod(Int32GetDatum(FromString<i32>(Value)));
- } else if (TypeId == INT8OID) {
- return ScalarDatumToPod(Int64GetDatum(FromString<i64>(Value)));
- } else if (TypeId == FLOAT4OID) {
- return ScalarDatumToPod(Float4GetDatum(FromString<float>(Value)));
- } else if (TypeId == FLOAT8OID) {
- return ScalarDatumToPod(Float8GetDatum(FromString<double>(Value)));
- } else if (TypeId == TEXTOID || TypeId == VARCHAROID || TypeId == BYTEAOID) {
- SET_MEMORY_CONTEXT;
- return PointerDatumToPod(PointerGetDatum(cstring_to_text_with_len(Value.data(), Value.size())));
- } else if (TypeId == BOOLOID) {
- return ScalarDatumToPod(BoolGetDatum(!Value.empty() && Value[0] == 't'));
+ SET_MEMORY_CONTEXT;
+
+ LOCAL_FCINFO(callInfo, 3);
+ Zero(*callInfo);
+ callInfo->flinfo = const_cast<FmgrInfo*>(&FInfo);
+ callInfo->nargs = 3;
+ callInfo->fncollation = DEFAULT_COLLATION_OID;
+ callInfo->isnull = false;
+ callInfo->args[0] = { (Datum)Value.c_str(), false };
+ callInfo->args[1] = { ObjectIdGetDatum(TypeIOParam), false };
+ callInfo->args[2] = { Int32GetDatum(-1), false };
+
+ TPAllocScope call;
+ PG_TRY();
+ {
+ auto ret = FInfo.fn_addr(callInfo);
+ Y_ENSURE(!callInfo->isnull);
+ return TypeDesc.PassByValue ? ScalarDatumToPod(ret) : PointerDatumToPod(ret);
}
- else if (TypeId == NUMERICOID) {
- SET_MEMORY_CONTEXT;
- LOCAL_FCINFO(callInfo, 3);
- Zero(*callInfo);
- callInfo->nargs = 3;
- callInfo->fncollation = DEFAULT_COLLATION_OID;
- callInfo->isnull = false;
- callInfo->args[0] = { (Datum)Value.c_str(), false };
- callInfo->args[1] = { ObjectIdGetDatum(NUMERICOID), false };
- callInfo->args[2] = { Int32GetDatum(-1), false };
-
- TPAllocScope call;
- PG_TRY();
- {
- auto x = numeric_in(callInfo);
- Y_ENSURE(!callInfo->isnull);
- return PointerDatumToPod(x);
- }
- PG_CATCH();
- {
- auto error_data = CopyErrorData();
- TStringBuilder errMsg;
- errMsg << "Error in function: numeric_in, reason: " << error_data->message;
- FreeErrorData(error_data);
- FlushErrorState();
- UdfTerminate(errMsg.c_str());
- }
- PG_END_TRY();
- } else {
- UdfTerminate((TStringBuilder() << "Unsupported pg type: " << NPg::LookupType(TypeId).Name).c_str());
+ PG_CATCH();
+ {
+ auto error_data = CopyErrorData();
+ TStringBuilder errMsg;
+ errMsg << "Error in function: " << NPg::LookupProc(TypeDesc.InFuncId).Name << ", reason: " << error_data->message;
+ FreeErrorData(error_data);
+ FlushErrorState();
+ UdfTerminate(errMsg.c_str());
}
+ PG_END_TRY();
}
private:
@@ -255,6 +248,9 @@ private:
const ui32 TypeId;
const TString Value;
+ const NPg::TTypeDesc TypeDesc;
+ FmgrInfo FInfo;
+ ui32 TypeIOParam;
};
class TPgInternal0 : public TMutableComputationNode<TPgInternal0> {
@@ -460,10 +456,6 @@ private:
TVector<NPg::TTypeDesc> ArgDesc;
};
-inline ui32 MakeTypeIOParam(const NPg::TTypeDesc& desc) {
- return desc.ElementTypeId ? desc.ElementTypeId : desc.TypeId;
-}
-
class TPgCast : public TMutableComputationNode<TPgCast> {
typedef TMutableComputationNode<TPgCast> TBaseComputation;
public: