Skip to content

Commit

Permalink
Pg 16.3 (ydb-platform#6644)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitstn authored Jul 15, 2024
1 parent e5ae52d commit 1c9d9af
Show file tree
Hide file tree
Showing 1,719 changed files with 147,612 additions and 102,814 deletions.
2 changes: 1 addition & 1 deletion ydb/core/kqp/ut/pg/kqp_pg_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4406,7 +4406,7 @@ Y_UNIT_TEST_SUITE(KqpPg) {
)");
auto result = db.ExecuteQuery(query, NYdb::NQuery::TTxControl::BeginTx().CommitTx(), settings).ExtractValueSync();
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::GENERIC_ERROR, result.GetIssues().ToString());
UNIT_ASSERT(result.GetIssues().ToString().Contains("alternative is not implemented yet : 138"));
UNIT_ASSERT(result.GetIssues().ToString().Contains("alternative is not implemented yet : 34"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion ydb/library/yql/minikql/mkql_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ struct TMkqlPAllocHeader {
} U;

size_t Size;
void* Self; // should be placed right before pointer to allocated area, see GetMemoryChunkContext
ui64 Self; // should be placed right before pointer to allocated area, see GetMemoryChunkContext
};

static_assert(sizeof(TMkqlPAllocHeader) ==
Expand Down
15 changes: 7 additions & 8 deletions ydb/library/yql/parser/pg_catalog/ut/catalog_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,14 @@ Y_UNIT_TEST_SUITE(TAggregationsTests) {
UNIT_ASSERT_VALUES_EQUAL(LookupProc(ret.SerializeFuncId).Name, "int8_avg_serialize");
UNIT_ASSERT_VALUES_EQUAL(LookupProc(ret.DeserializeFuncId).Name, "int8_avg_deserialize");

ret = LookupAggregation("string_agg", {LookupType("text").TypeId, LookupType("text").TypeId});
UNIT_ASSERT_VALUES_EQUAL(ret.TransTypeId, LookupType("internal").TypeId);
UNIT_ASSERT_VALUES_EQUAL(ret.Name, "string_agg");
UNIT_ASSERT_VALUES_EQUAL(ret.ArgTypes.size(), 2);
UNIT_ASSERT_VALUES_EQUAL(ret.ArgTypes[0], LookupType("text").TypeId);
UNIT_ASSERT_VALUES_EQUAL(ret.ArgTypes[1], LookupType("text").TypeId);
UNIT_ASSERT_VALUES_EQUAL(LookupProc(ret.TransFuncId).Name, "string_agg_transfn");
ret = LookupAggregation("xmlagg", {LookupType("xml").TypeId});
UNIT_ASSERT_VALUES_EQUAL(ret.TransTypeId, LookupType("xml").TypeId);
UNIT_ASSERT_VALUES_EQUAL(ret.Name, "xmlagg");
UNIT_ASSERT_VALUES_EQUAL(ret.ArgTypes.size(), 1);
UNIT_ASSERT_VALUES_EQUAL(ret.ArgTypes[0], LookupType("xml").TypeId);
UNIT_ASSERT_VALUES_EQUAL(LookupProc(ret.TransFuncId).Name, "xmlconcat2");
UNIT_ASSERT_VALUES_EQUAL(ret.CombineFuncId, 0);
UNIT_ASSERT_VALUES_EQUAL(LookupProc(ret.FinalFuncId).Name, "string_agg_finalfn");
UNIT_ASSERT_VALUES_EQUAL(ret.FinalFuncId, 0);
UNIT_ASSERT_VALUES_EQUAL(ret.SerializeFuncId, 0);
UNIT_ASSERT_VALUES_EQUAL(ret.DeserializeFuncId, 0);

Expand Down
78 changes: 51 additions & 27 deletions ydb/library/yql/parser/pg_wrapper/arena_ctx.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "arena_ctx.h"
#include <util/generic/yexception.h>

#define TypeName PG_TypeName
#define SortBy PG_SortBy
Expand All @@ -7,35 +8,57 @@ extern "C" {
#include "postgres.h"
#include "nodes/memnodes.h"
#include "utils/memutils.h"
#include "utils/memutils_internal.h"
}

namespace NYql {

struct TArenaPAllocHeader {
size_t Size;
MemoryContext Self; // should be placed right before pointer to allocated area, see GetMemoryChunkContext
ui64 Self; // should be placed right before pointer to allocated area, see GetMemoryChunkContext
};

static_assert(sizeof(TArenaPAllocHeader) == sizeof(size_t) + sizeof(MemoryContext), "Padding is not allowed");

void *MyAllocSetAlloc(MemoryContext context, Size size) {
extern "C" {
extern void *ArenaAlloc(MemoryContext context, Size size);
extern void ArenaFree(void *pointer);
extern void *ArenaRealloc(void *pointer, Size size);
extern void ArenaReset(MemoryContext context);
extern void ArenaDelete(MemoryContext context);
extern MemoryContext ArenaGetChunkContext(void *pointer);
extern Size ArenaGetChunkSpace(void *pointer);
extern bool ArenaIsEmpty(MemoryContext context);
extern void ArenaStats(MemoryContext context,
MemoryStatsPrintFunc printfunc, void *passthru,
MemoryContextCounters *totals,
bool print_to_stderr);
#ifdef MEMORY_CONTEXT_CHECKING
extern void ArenaCheck(MemoryContext context);
#endif
}

extern "C" void *ArenaAlloc(MemoryContext context, Size size) {
Y_UNUSED(context);
auto fullSize = size + MAXIMUM_ALIGNOF - 1 + sizeof(TArenaPAllocHeader);
auto ptr = TArenaMemoryContext::GetCurrentPool().Allocate(fullSize);
auto aligned = (TArenaPAllocHeader*)MAXALIGN(ptr + sizeof(TArenaPAllocHeader));
aligned[-1].Self = context;
Y_ENSURE((ui64(context) & MEMORY_CONTEXT_METHODID_MASK) == 0);
aligned[-1].Self = ui64(context) | MCTX_UNUSED2_ID;
aligned[-1].Size = size;
return aligned;
}

void MyAllocSetFree(MemoryContext context, void* pointer) {
extern "C" void ArenaFree(void* pointer) {
Y_UNUSED(pointer);
}

void* MyAllocSetRealloc(MemoryContext context, void* pointer, Size size) {
extern "C" void* ArenaRealloc(void* pointer, Size size) {
if (!size) {
return nullptr;
}

void* ret = MyAllocSetAlloc(context, size);
void* ret = ArenaAlloc(nullptr, size);
if (pointer) {
auto prevSize = ((const TArenaPAllocHeader*)pointer)[-1].Size;
memmove(ret, pointer, prevSize);
Expand All @@ -44,50 +67,51 @@ void* MyAllocSetRealloc(MemoryContext context, void* pointer, Size size) {
return ret;
}

void MyAllocSetReset(MemoryContext context) {
extern "C" void ArenaReset(MemoryContext context) {
Y_UNUSED(context);
}

void MyAllocSetDelete(MemoryContext context) {
extern "C" void ArenaDelete(MemoryContext context) {
Y_UNUSED(context);
}

Size MyAllocSetGetChunkSpace(MemoryContext context, void* pointer) {
extern "C" MemoryContext ArenaGetChunkContext(void *pointer) {
return (MemoryContext)(((ui64*)pointer)[-1] & ~MEMORY_CONTEXT_METHODID_MASK);
}

extern "C" Size ArenaGetChunkSpace(void* pointer) {
Y_UNUSED(pointer);
return 0;
}

bool MyAllocSetIsEmpty(MemoryContext context) {
extern "C" bool ArenaIsEmpty(MemoryContext context) {
Y_UNUSED(context);
return false;
}

void MyAllocSetStats(MemoryContext context,
extern "C" void ArenaStats(MemoryContext context,
MemoryStatsPrintFunc printfunc, void *passthru,
MemoryContextCounters *totals,
bool print_to_stderr) {
Y_UNUSED(context);
Y_UNUSED(printfunc);
Y_UNUSED(passthru);
Y_UNUSED(totals);
Y_UNUSED(print_to_stderr);
}

void MyAllocSetCheck(MemoryContext context) {
extern "C" void ArenaCheck(MemoryContext context) {
Y_UNUSED(context);
}

const MemoryContextMethods MyMethods = {
MyAllocSetAlloc,
MyAllocSetFree,
MyAllocSetRealloc,
MyAllocSetReset,
MyAllocSetDelete,
MyAllocSetGetChunkSpace,
MyAllocSetIsEmpty,
MyAllocSetStats
#ifdef MEMORY_CONTEXT_CHECKING
,MyAllocSetCheck
#endif
};

__thread TArenaMemoryContext* TArenaMemoryContext::Current = nullptr;

TArenaMemoryContext::TArenaMemoryContext() {
MyContext = (MemoryContext)malloc(sizeof(MemoryContextData));
static_assert(MEMORY_CONTEXT_METHODID_MASK < sizeof(void*));
MemoryContextCreate(MyContext,
T_AllocSetContext,
&MyMethods,
MCTX_UNUSED2_ID,
nullptr,
"arena");
Acquire();
Expand Down
1 change: 1 addition & 0 deletions ydb/library/yql/parser/pg_wrapper/arrow.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "pg_compat.h"
#include "arrow.h"
#include "arrow_impl.h"
#include <ydb/library/yql/minikql/defs.h>
Expand Down
1 change: 1 addition & 0 deletions ydb/library/yql/parser/pg_wrapper/arrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
extern "C" {
#include "postgres.h"
#include "fmgr.h"
#include "varatt.h"
#include "catalog/pg_type_d.h"
#include "catalog/pg_collation_d.h"
}
Expand Down
1 change: 1 addition & 0 deletions ydb/library/yql/parser/pg_wrapper/arrow_impl.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "pg_compat.h"
#include "arrow.h"

namespace NYql {
Expand Down
1 change: 1 addition & 0 deletions ydb/library/yql/parser/pg_wrapper/cflags.inc
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,5 @@ CFLAGS(
-Dpg_prng_fseed=yql_pg_prng_fseed
-Dpg_prng_seed_check=yql_pg_prng_seed_check
-Dpg_prng_seed=yql_pg_prng_seed
-Dpg_prng_double_normal=yql_pg_prng_double_normal
)
Loading

0 comments on commit 1c9d9af

Please sign in to comment.