Skip to content

support SRID value in column definition #3457

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

Merged
merged 37 commits into from
Jun 1, 2022
Merged

support SRID value in column definition #3457

merged 37 commits into from
Jun 1, 2022

Conversation

jennifersp
Copy link
Contributor

@jennifersp jennifersp commented May 19, 2022

Added SRID check for spatial types when converting the value/column between noms and sql values.
Added SRID details for column definition in type params when converting table info.

@jennifersp jennifersp changed the title support SRID value in column definition [WIP] support SRID value in column definition May 19, 2022
Copy link
Contributor

@fulghum fulghum left a comment

Choose a reason for hiding this comment

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

Looking pretty good. I think we can simplify the SRID validation quite a bit and potentially avoid doing it at this level and rely on the validation at higher levels.

if err != nil {
return nil, err
}
GeometryType = &geometryType{sqlGeometryType: sql.GeometryType{InnerType: nil, SRID: uint32(sridVal), DefinedSRID: dSRID}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Assigning this customized type to the shared variable GeometryType seems like it could cause problems or confusion in the future... the other usage still looks correct (e.g. IsColSpatialType uses this var, but the Equals methods just check to see if the types are the same), but it still seems odd to change the global variable to the last value someone converted, instead of just leaving it as a default. I bet there's a correctness issue when a new Geometry TypeInfo is re-assigned and then used by other parts in the code.

I suspect we should just return the new type here and not cache it in the GeometryType var, but let me know if I'm missing something.

// Expect a types.Point, return a sql.Point
if val, ok := v.(types.Point); ok {
return ConvertTypesPointToSQLPoint(val), nil
sqlVal := ConvertTypesPointToSQLPoint(val)
err = ti.sqlPointType.MatchSRID(sqlVal)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we actually need to validate the SRID here... we definitely need to validate any new data coming into the database from the caller (of course) and we need to validate any schema changes to make sure they don't invalidate the SRID matching constraint, but I'm wondering if we can be more lenient when we're loading data into and out of the storage layer interface. The impact of this validation failing is that customer won't be able to load their (already entered into the system) data any more, which could be worse than it being loaded and having inconsistent SRIDs that don't fit the constraint of the column.

Are we testing this constraint in enough other places where the data is coming into the system so that we don't need to test this again as the data goes into the storage layer? I'm not confident yet, but wanted to bring this up to consider.

@jennifersp jennifersp changed the title [WIP] support SRID value in column definition support SRID value in column definition May 26, 2022
@jennifersp jennifersp requested a review from fulghum May 26, 2022 01:07
Copy link
Contributor

@fulghum fulghum left a comment

Choose a reason for hiding this comment

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

Code is looking great! I just had one question I wanted to make sure I understood about the validation logic in alterschema.go.

Thanks again for making the LineString capitalization change to be consistent with MySQL!

@@ -272,6 +275,8 @@ func updateTableWithModifiedColumn(ctx context.Context, tbl *doltdb.Table, oldSc
val, ok := r.GetColVal(modifiedCol.Tag)
if !ok || val == nil || val == types.NullValue {
return true, fmt.Errorf("cannot change column to NOT NULL when one or more values is NULL")
} else if err = validateSpatialTypeSRID(modifiedCol, val); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this validation check be inside the if !modifiedCol.IsNullable() block?

It seems like we only need to run this validation when a column type is changing, and you've got that covered in the if block right above this.

This block seems like it's specific for checking that a modified column that does not allow nulls doesn't have any existing nulls in the data. I'm not sure we need to do anything for SRID here, but let me know if I'm missing something.

Copy link
Contributor

@fulghum fulghum left a comment

Choose a reason for hiding this comment

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

Nice work on these!

@jennifersp jennifersp merged commit eb0577e into main Jun 1, 2022
@jennifersp jennifersp deleted the jennifer/srid branch June 1, 2022 04:02
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.

Changing spatial column type sets row values to NULL Cannot create spatial table with CRS
2 participants