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

ensure consistent index ordering #83

Merged
merged 3 commits into from
Dec 13, 2017
Merged

Conversation

Etomyutikos
Copy link
Member

fixes #82

The databases return index data in a consistent order. The previous
process did not respect that through its use of a map as an
intermediate store. By using slices, we now guarantee that the template
will see the indexes in the order the database returned them.

fixes gnormal#82

The databases return index data in a consistent order. The previous
process did not respect that through its use of a map as an
intermediate store. By using slices, we now guarantee that the template
will see the indexes in the order the database returned them.
Copy link
Member

@natefinch natefinch 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 with a couple tiny tweaks if you could.

indexes[s.TableSchema] = schemaIndex
}

tableIndex, ok := schemaIndex[s.TableName]
if !ok {
tableIndex = make(map[string][]*database.Column)
tableIndex = make([]*database.Index, 0)
Copy link
Member

Choose a reason for hiding this comment

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

you can drop the ,0 here, since that's the default (and I think go vet or go lint will complain at you)

Copy link
Member Author

Choose a reason for hiding this comment

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

I had removed the 0 and go vet complained, but I didn't spend too much time on it. I'll take another look.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have verified that the length parameter is required. The exception being []*database.Index{} syntax.

@@ -126,16 +126,29 @@ func parse(log *log.Logger, conn string, schemaNames []string, filterTables func

schemaIndex, ok := indexes[s.TableSchema]
if !ok {
schemaIndex = make(map[string]map[string][]*database.Column)
schemaIndex = make(map[string][]*database.Index)
indexes[s.TableSchema] = schemaIndex
}

tableIndex, ok := schemaIndex[s.TableName]
Copy link
Member

Choose a reason for hiding this comment

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

can you make this "tableIndexes" (or indices)? I think it would be more clear.

indexes[r.SchemaName] = schemaIndex
}

tableIndex, ok := schemaIndex[r.TableName]
if !ok {
tableIndex = make(map[string][]*database.Column)
tableIndex = make([]*database.Index, 0)
Copy link
Member

Choose a reason for hiding this comment

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

same as above

Copy link
Member

@natefinch natefinch left a comment

Choose a reason for hiding this comment

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

Hey sorry, got a chance to look at this again, and realized we can cut out those lines entirely. Thanks :)

tableIndex = make(map[string][]*database.Column)
schemaIndex[s.TableName] = tableIndex
tableIndices = make([]*database.Index, 0)
schemaIndex[s.TableName] = tableIndices
}
Copy link
Member

Choose a reason for hiding this comment

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

You can actually remove this entire if statement (and the ok above). The map will return a nil array if it doesn't exist, which is fine both for the range and the append below.

tableIndex = make(map[string][]*database.Column)
schemaIndex[r.TableName] = tableIndex
tableIndices = make([]*database.Index, 0)
schemaIndex[r.TableName] = tableIndices
}
Copy link
Member

Choose a reason for hiding this comment

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

same as above

@natefinch natefinch merged commit 61fec0c into gnormal:master Dec 13, 2017
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.

.Indexes output should be consistent
2 participants