-
Notifications
You must be signed in to change notification settings - Fork 40
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
Conversation
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
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
*/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in https://github.com/mkgrgis/sqlite_fdw/tree/convert_data_types, also added mkgrgis@7262db8 about C code style.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
*/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, please verify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed again, @nxhai98 !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
Thanks, @nxhai98 -san! I have fixed some problems in mkgrgis@74bcfea |
There was a problem hiding this 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); | ||
{ /* |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and near fixed
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
Yes. Thanks, @nxhai98 ! |
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
@mkgrgis , Thank you for your reply and development. I will merge it. |
No SQL behaviour changes.
Preparing to implement SQL behaviour from table discussed in #66 (comment)
This PR include:
sqlite_convert_to_pg
fromDatum
toNullableDatum
for future properuuid
processing and other special cases such as voidtext
affinity in data forint
column;sqlite3_column_bytes
andsqlite3_column_bytes
for the same data value;