Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handler functions for Datum/Bools arrays #6735

Merged

Conversation

fabriziomello
Copy link
Contributor

@fabriziomello fabriziomello commented Mar 5, 2024

When updating catalog tables we rely on low level functions instead of SQL statements and in order to read/write data from/to those tables we frequent do something like:

Datum values[natts] = { 0 };
bool nulls[natts] = { false };
char *char_value = "foo";

if (char_value != NULL)
    values[AttrNumberGetAttrOffset(text_value_offset)] =
        PointerGetDatum(cstring_to_text(char_value);
else
    null[AttrNumberGetAttrOffset(char_value_offset)] = true;

So instead of using a pair of Datum and bool arrays we'll replace it by using arrays of NullableDatum that contains both members and introduce some accessor functions to encapsulate the logic to fill the proper values, like:

ts_datum_set_text(int index, NullableDatum *datums, text *value);
ts_datum_set_bool(int index, NullableDatum *datums, bool value);

We also introduce a new ts_heap_form_tuple that essentially to the same as Postgres heap_form_tuple but using array of NullableDatum instead of Datum and bool arrays.

In this first commit we added only the necessary accessor functions to refactor the existing create_cagg_validate_query_datum as example. More accessor functions to deal with other C types should be introduced in the future.

Disable-check: force-changelog-file

@fabriziomello fabriziomello added the tech-debt Needs refactoring and improvement tasks related to the source code and its architecture. label Mar 5, 2024
@fabriziomello fabriziomello self-assigned this Mar 5, 2024
Copy link

codecov bot commented Mar 5, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 80.99%. Comparing base (59f50f2) to head (d691e02).
Report is 59 commits behind head on main.

Files Patch % Lines
src/utils.h 50.00% 0 Missing and 4 partials ⚠️
tsl/src/continuous_aggs/utils.c 92.85% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6735      +/-   ##
==========================================
+ Coverage   80.06%   80.99%   +0.92%     
==========================================
  Files         190      191       +1     
  Lines       37181    36351     -830     
  Branches     9450     9435      -15     
==========================================
- Hits        29770    29443     -327     
- Misses       2997     3159     +162     
+ Partials     4414     3749     -665     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/utils.h Outdated Show resolved Hide resolved
@fabriziomello fabriziomello force-pushed the utility_datum_functions branch 2 times, most recently from 0e92c27 to d2b75e3 Compare March 6, 2024 14:44
When updating catalog tables we rely on low level functions instead of
SQL statements and in order to read/write data from/to those tables we
frequent do something like:

```CPP
Datum values[natts] = { 0 };
bool nulls[natts] = { false };
char *char_value = "foo";

if (char_value != NULL)
    values[AttrNumberGetAttrOffset(text_value_offset)] =
        PointerGetDatum(cstring_to_text(char_value);
else
    null[AttrNumberGetAttrOffset(char_value_offset)] = true;
```

So instead of using a pair of Datum and bool arrays we'll replace it by
using arrays of `NullableDatum` that contains both members and introduce
some accessor functions to encapsulate the logic to fill the proper
values, like:

```CPP
ts_datum_set_text(int index, NullableDatum *datums, text *value);
ts_datum_set_bool(int index, NullableDatum *datums, bool value);
```

We also introduce a new `ts_heap_form_tuple` that essentially to the
same as Postgres `heap_form_tuple` but using array of `NullableDatum`
instead of Datum and bool arrays.

In this first commit we added only the necessary accessor functions to
refactor the existing `create_cagg_validate_query_datum` as example.
More accessor functions to deal with other C types should be introduced
in the future.
@fabriziomello fabriziomello merged commit 898f18b into timescale:main Mar 7, 2024
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core tech-debt Needs refactoring and improvement tasks related to the source code and its architecture.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants