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

v.in.ogr: skip columns with unsupported data type instead of failing to import #2630

Merged
merged 9 commits into from
Nov 10, 2022

Conversation

ninsbl
Copy link
Member

@ninsbl ninsbl commented Nov 5, 2022

Before this PR, vector data failed to import if it contained columns in the attribute table that are of a data type that is not supported by GRASS` s DBMI - like binary data (BLOB). This PR changes the behavior of v.in.ogr to drop such columns from import instead of failing to import the data in total.

@ninsbl ninsbl added bug Something isn't working backport_needed C Related code is in C database Related to database management labels Nov 5, 2022
@ninsbl ninsbl added this to the 8.3.0 milestone Nov 5, 2022
@ninsbl ninsbl requested review from nilason and metzm November 5, 2022 19:58
@ninsbl ninsbl linked an issue Nov 5, 2022 that may be closed by this pull request
Copy link
Contributor

@nilason nilason left a comment

Choose a reason for hiding this comment

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

Looks good to me. Just had some minor remarks.

vector/v.in.ogr/main.c Outdated Show resolved Hide resolved
vector/v.in.ogr/main.c Outdated Show resolved Hide resolved
@ninsbl ninsbl requested a review from nilason November 7, 2022 20:54
@metzm
Copy link
Contributor

metzm commented Nov 7, 2022

Instead of adding a special case for Ogr_ftype == OFTBinary, handling of unsupported field types should be fixed in
https://github.com/OSGeo/grass/blob/main/vector/v.in.ogr/main.c#L1177

Ogr_field = OGR_FD_GetFieldDefn(Ogr_featuredefn, i);
Ogr_ftype = OGR_Fld_GetType(Ogr_field);

G_debug(3, "Ogr_ftype: %i", Ogr_ftype); /* look up below */

/* skip columns with unsupported data type */
if (Ogr_ftype == OFTBinary) {
G_warning(_("Column <%s> is omitted, binary data type is not supported."),
Copy link
Contributor

Choose a reason for hiding this comment

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

Not supported data types are handled below at L1184

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point! And there all columns with unsupported data types may be omitted. However, that would be a break with present behaviour (keep column, but omit rows). Perhaps a new flag for “omit columns with unsupported data types”?

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, but isn't the binary column then included in the output table creation struct grass_col_info already in L1091:

col_info[i_out].idx = i_out;

So, I guess if we fix it in L1184, it would have to be removed from col_info?
How would I do that? A web-search unfortunately did not give me a straight forward solution...

vector/v.in.ogr/main.c Outdated Show resolved Hide resolved
@metzm
Copy link
Contributor

metzm commented Nov 8, 2022

There is a deeper bug in v.in.ogr regarding not supported column types: the behaviour of creating columns and filling columns does not match if there is a not supported column type. See following suggestions to this PR.

vector/v.in.ogr/main.c Outdated Show resolved Hide resolved
Comment on lines -1178 to -1181
G_warning(_("Column type (Ogr_ftype: %d) not supported (Ogr_fieldname: %s)"),
Ogr_ftype, Ogr_fieldname);
buf[0] = 0;
col_info[i_out].type = G_store(buf);
Copy link
Contributor

Choose a reason for hiding this comment

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

Keep the current behaviour, add

i_out--;

remove

col_info[i_out].type = G_store(buf);

/* handle columns of unsupported data type */
G_warning(_("Column type (Ogr_ftype: %d) not supported (Ogr_fieldname: %s)\n"),
Ogr_ftype, Ogr_fieldname);
if (flag.drop->answer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As above, the drop flag does not make sense: unsupported column types can not be transferred in any reasonable way.

@metzm
Copy link
Contributor

metzm commented Nov 8, 2022

When filling attributes, the code block at needs to be removed:

			else {
			    /* column type not supported */
			    G_rasprintf(&sqlbuf, &sqlbufsize, "%c", '\0');
			}

this is the hidden bug: should be ", %c" to create an empty entry for a not supported column type, but dropping any not supported column type avoids confusion later on.

ninsbl and others added 2 commits November 8, 2022 23:30
Co-authored-by: Markus Metz <33666869+metzm@users.noreply.github.com>
@ninsbl
Copy link
Member Author

ninsbl commented Nov 8, 2022

Thanks again. Suggestions implemented in 5cf030a. I hope I got those right...
At least my testcase as well as the unit-test work fine...

@ninsbl
Copy link
Member Author

ninsbl commented Nov 8, 2022

P.S.: I modified the warning message a bit in an attempt to make it a bit more clear what is happening. Happy to change it back if preferred...

@ninsbl ninsbl changed the title v.in.ogr: skip binary columns (instead of failing to import the data) v.in.ogr: skip columns with unsupported data type instead of failing to import Nov 9, 2022
@nilason
Copy link
Contributor

nilason commented Nov 9, 2022

P.S.: I modified the warning message a bit in an attempt to make it a bit more clear what is happening. Happy to change it back if preferred...

With latest changes, may I suggest the following warning message:

                G_warning(_("Column <%s> is of unsupported \"%s\" data type, "
                            "it is omitted from import."),
		          Ogr_fieldname, OGR_GetFieldTypeName(Ogr_ftype));

which will result in a message like:

WARNING: Column <blob> is of unsupported "Binary" data type, it is omitted
         from import.

General note: G_warning will automatically reflow the printed message to fit in a 80 col terminal, no need to break \n (not at the end either).

vector/v.in.ogr/main.c Outdated Show resolved Hide resolved
vector/v.in.ogr/main.c Outdated Show resolved Hide resolved
vector/v.in.ogr/main.c Outdated Show resolved Hide resolved
@ninsbl ninsbl requested a review from nilason November 9, 2022 21:17
@wenzeslaus
Copy link
Member

@ninsbl Can you please update the PR description to reflect the current intention and changes done? (will be needed for the merge/final commit anyway)

@ninsbl
Copy link
Member Author

ninsbl commented Nov 9, 2022

@ninsbl Can you please update the PR description to reflect the current intention and changes done? (will be needed for the merge/final commit anyway)

Done.

Copy link
Contributor

@nilason nilason left a comment

Choose a reason for hiding this comment

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

Great!

vector/v.in.ogr/main.c Outdated Show resolved Hide resolved
Copy link
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

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

That looks good! I'm wondering if the line is not too long, but formatting in this file needs fixing anyway, so maybe not a big deal as long as we are planning to fix it soon.

@ninsbl ninsbl merged commit 726fb2c into OSGeo:main Nov 10, 2022
ninsbl added a commit that referenced this pull request Nov 10, 2022
…to import (#2630)

* skip binary columns

* remove copied comment

* indent + warning message

* handle all unsupported column types with d-flag

* remove second warning

* Update vector/v.in.ogr/main.c

Co-authored-by: Markus Metz <33666869+metzm@users.noreply.github.com>

* implement suggestion from review

* cleanup from review

* simplify warning

Co-authored-by: Markus Metz <33666869+metzm@users.noreply.github.com>
ninsbl added a commit to ninsbl/grass that referenced this pull request Feb 17, 2023
…to import (OSGeo#2630)

* skip binary columns

* remove copied comment

* indent + warning message

* handle all unsupported column types with d-flag

* remove second warning

* Update vector/v.in.ogr/main.c

Co-authored-by: Markus Metz <33666869+metzm@users.noreply.github.com>

* implement suggestion from review

* cleanup from review

* simplify warning

Co-authored-by: Markus Metz <33666869+metzm@users.noreply.github.com>
marisn pushed a commit to marisn/grass that referenced this pull request Jun 2, 2023
…to import (OSGeo#2630)

* skip binary columns

* remove copied comment

* indent + warning message

* handle all unsupported column types with d-flag

* remove second warning

* Update vector/v.in.ogr/main.c

Co-authored-by: Markus Metz <33666869+metzm@users.noreply.github.com>

* implement suggestion from review

* cleanup from review

* simplify warning

Co-authored-by: Markus Metz <33666869+metzm@users.noreply.github.com>
neteler pushed a commit to nilason/grass that referenced this pull request Nov 7, 2023
…to import (OSGeo#2630)

* skip binary columns

* remove copied comment

* indent + warning message

* handle all unsupported column types with d-flag

* remove second warning

* Update vector/v.in.ogr/main.c

Co-authored-by: Markus Metz <33666869+metzm@users.noreply.github.com>

* implement suggestion from review

* cleanup from review

* simplify warning

Co-authored-by: Markus Metz <33666869+metzm@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working C Related code is in C database Related to database management
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] v.in.ogr: handle columns with unsupported datatype in GRASS DBMI
4 participants