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

Prepare C-language infrastructure for ISO:SQL #74

Merged
merged 5 commits into from
May 17, 2023

Conversation

mkgrgis
Copy link
Contributor

@mkgrgis mkgrgis commented May 2, 2023

No SQL behaviour changes.

Preparing to implement SQL behaviour from table discussed in #66 (comment)

This PR include:

  • improve naming;
  • add function for human readable error message about SQLite data value affinity;
  • change return type for sqlite_convert_to_pg from Datum to NullableDatum for future proper uuid processing and other special cases such as void text affinity in data for int column;
  • add TODO comments about PostgreSQL database encoding in proper places;
  • reduce double calculating for two functions: sqlite3_column_bytes and sqlite3_column_bytes for the same data value;
  • add draft for human readable error message about SQLite data value affinity;
  • etc.

No SQL behaviour changes.
This PR include:
* improve naming
* add function for human readable error message about SQLite data value affinity
* change return type for `sqlite_convert_to_pg` from `Datum` to `NullableDatum`
* add TODO comments about PostgreSQL database encoding in proper places
* add draft for human readable error message about SQLite data value affinity
* etc
Copy link
Contributor

@nxhai98 nxhai98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some comments for your PR. Could you check it?

deparse.c Outdated
@@ -2092,6 +2092,7 @@ sqlite_deparse_column_option(int varno, int varattno, PlannerInfo *root, char *o
void
sqlite_deparse_string_literal(StringInfo buf, const char *val)
{
// TODO: text input for SQLite is always UTF-8, we need to respect PostgreSQL database encoding
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you check the indent, please indent by Tabs, not Spaces.
And the comment should be in style (Same with Postgres):

/* some comment */

or

/*
 * some comment
 */

Copy link
Contributor Author

@mkgrgis mkgrgis May 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the change, but it not same as my expectation. Could you refer this patch:
fix_comment_style.patch

Copy link
Contributor Author

@mkgrgis mkgrgis May 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think now all my comments are /t aligned and 2nd+ lines also begins from some /t and one whitespace. Please show a problems not fixed by me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

sqlite_fdw.c Outdated
row[attnum] = sqlite_convert_to_pg(pgtype, pgtypmod,
stmt, attid, festate->attinmeta, attnum);
/* Here will be processing of column options about special convert behaviour
options = GetForeignColumnOptions(rel, attnum_base);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this code unnecessary? If so, please remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code will be uncommented during implementation of data transformation table. @t-kataym have wrote this implementation need to change SQL behaviour during column and other levelled options. It's important to leave this necessary draft for other contributors. My next PR will be about PostgreSQL encoding, PR after next about human readable error message (uncommenting) and than first PR with data transformation table implementation and introducing a new option or options.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank for your explanation,

However, we cannot accept the PR containing such comment code.
Leaving commented-out code in source code is bad practice, as it takes up space, causes confusion, and leads to maintenance issues if it's not removed.

Could you remove it or change it to a TODO note?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have reduced this draft to one TODO comment line. It's really "leaving commented-out code in source code is bad practice".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you check the other place also?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please comment on lines after my new commit with missing code style. Now I have no idea where is problems.

sqlite_query.c Outdated
elog(ERROR, "invalid input syntax for type =%d, column type =%d", sqlite_type, col_type);
if (affinity_for_pg_column != sqlite_value_affinity && sqlite_value_affinity == SQLITE3_TEXT)
{
/* Here will be human readable error message
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These codes seem be using for creating a human readable error message, should it be anable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My next PR will be about PostgreSQL encoding, PR after next about human readable error message (uncommenting). So, this code will be uncommented in a small PR after next small PR if this PR will be accepted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to break any tests with the message in this PR, but will uncomment in near future.

SET_VARSIZE(value_datum, blobsize + VARHDRSZ);
return PointerGetDatum(value_datum);
// int value_byte_size_blob_or_utf = sqlite3_column_bytes(stmt, stmt_colid); // Calculated always for detectind void values
value_datum = (Datum) palloc0(value_byte_size_blob_or_utf8 + VARHDRSZ);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value_byte_size_blob_or_utf8 is used only in this block, could you explain why we need define it outside?
I do not understand your comment as well: // Compute always, void text and void BLOB will be special cases

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our data transformation table empty value with text affinity is special case. For example for PostgreSQL uuid we should always threat void text value as NULL. For PostgreSQL int we can threat this value as NULL if a special boolean option is true. So for all PostgreSQL data types if (value_byte_size_blob_or_utf8) will be necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank for your explanation.
I understood.

@@ -111,15 +131,24 @@ sqlite_convert_to_pg(Oid pgtyp, int pgtypmod, sqlite3_stmt * stmt, int stmt_coli
valstr = DatumGetCString(DirectFunctionCall1(float8out, Float8GetDatum((float8) value)));
break;
}
/* some popular datatypes for default algorythm branch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please using comment style:

/*
 * some comment
 */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, please verify.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed again, @nxhai98 !

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@mkgrgis
Copy link
Contributor Author

mkgrgis commented May 11, 2023

Thanks, @nxhai98 -san! I have fixed some problems in mkgrgis@74bcfea

Copy link
Contributor

@nxhai98 nxhai98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add some more comments. Could you please help me check it again?

sqlite_fdw.c Outdated
@@ -1572,14 +1573,33 @@ make_tuple_from_result_row(sqlite3_stmt * stmt,
int attnum = lfirst_int(lc) - 1;
Oid pgtype = TupleDescAttr(tupleDescriptor, attnum)->atttypid;
int32 pgtypmod = TupleDescAttr(tupleDescriptor, attnum)->atttypmod;
//List *options = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

sqlite_fdw.c Outdated
is_null[attnum] = false;
row[attnum] = sqlite_convert_to_pg(pgtype, pgtypmod,
stmt, attid, festate->attinmeta, attnum);
/* TODO: Processing of column options about special convert behaviour
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indent is not correct. Please using \t instead of 3 spaces

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

elog(ERROR, "invalid input syntax for type =%d, column type =%d", sqlite_type, col_type);
if (affinity_for_pg_column != sqlite_value_affinity && sqlite_value_affinity == SQLITE3_TEXT)
{
/* TODO: human readable error message based on this code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the error message format or error message example is enough, not need to add the code here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really. I have reduced the comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

sqlite_query.c Outdated
default:
valstr = (char *) sqlite3_column_text(stmt, stmt_colid);
{ /*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please enter the comment to the new line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

sqlite_fdw.c Outdated
* Flags about special convert behaviour from options on database, table or column level
*/

sqlite_coverted = sqlite_convert_to_pg(pgtype, pgtypmod,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please using \t instead of spaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and near fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@@ -111,15 +131,24 @@ sqlite_convert_to_pg(Oid pgtyp, int pgtypmod, sqlite3_stmt * stmt, int stmt_coli
valstr = DatumGetCString(DirectFunctionCall1(float8out, Float8GetDatum((float8) value)));
break;
}
/* some popular datatypes for default algorythm branch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@mkgrgis
Copy link
Contributor Author

mkgrgis commented May 16, 2023

I add some more comments. Could you please help me check it again?

Yes. Thanks, @nxhai98 !

Copy link
Contributor

@nxhai98 nxhai98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank for your fixing. I confirmed all the change.

elog(ERROR, "invalid input syntax for type =%d, column type =%d", sqlite_type, col_type);
if (affinity_for_pg_column != sqlite_value_affinity && sqlite_value_affinity == SQLITE3_TEXT)
{
/* TODO: human readable error message based on this code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@t-kataym
Copy link
Contributor

@mkgrgis
@nxhai98's confirmation has completed. We can accept the PR. Can I merge it?

@mkgrgis
Copy link
Contributor Author

mkgrgis commented May 16, 2023

@t-kataym , yes, you can squash and merge my PR. Reviews by @nxhai98 was very good and helpful for me! My next little PR will be about database encoding, also without breaking of any tests.

@t-kataym
Copy link
Contributor

@mkgrgis , Thank you for your reply and development. I will merge it.

@t-kataym t-kataym merged commit 8ad5278 into pgspider:master May 17, 2023
@mkgrgis mkgrgis deleted the convert_data_types branch May 17, 2023 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants