-
Notifications
You must be signed in to change notification settings - Fork 469
Fix creating SQLServerDataTable being O(n^2) issue #514
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
peterbae
merged 6 commits into
microsoft:dev
from
peterbae:SQLServerDataTableImprovement-497
Oct 11, 2017
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e77a046
Implement checkDuplicateColumnName to check duplicate columns
peterbae 8f69956
Revert "Implement checkDuplicateColumnName to check duplicate columns"
peterbae f8e89df
Revert "Revert "Implement checkDuplicateColumnName to check duplicate…
peterbae 91a3eea
Apply same logic for TVP
peterbae 8c0ebf2
remove null check and change Set object name
peterbae adf10ea
Refactoring the logic for checking duplicate column into Util class a…
peterbae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,17 +13,20 @@ | |
| import java.time.OffsetDateTime; | ||
| import java.time.OffsetTime; | ||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.Iterator; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.Map; | ||
| import java.util.Map.Entry; | ||
| import java.util.Set; | ||
| import java.util.UUID; | ||
|
|
||
| public final class SQLServerDataTable { | ||
|
|
||
| int rowCount = 0; | ||
| int columnCount = 0; | ||
| Map<Integer, SQLServerDataColumn> columnMetadata = null; | ||
| Set<String> columnList = null; | ||
| Map<Integer, Object[]> rows = null; | ||
|
|
||
| private String tvpName = null; | ||
|
|
@@ -37,6 +40,7 @@ public final class SQLServerDataTable { | |
| // Name used in CREATE TYPE | ||
| public SQLServerDataTable() throws SQLServerException { | ||
| columnMetadata = new LinkedHashMap<>(); | ||
| columnList = new HashSet<>(); | ||
| rows = new HashMap<>(); | ||
| } | ||
|
|
||
|
|
@@ -75,7 +79,7 @@ public synchronized Iterator<Entry<Integer, Object[]>> getIterator() { | |
| public synchronized void addColumnMetadata(String columnName, | ||
| int sqlType) throws SQLServerException { | ||
| // column names must be unique | ||
| Util.checkDuplicateColumnName(columnName, columnMetadata); | ||
| checkDuplicateColumnName(columnName); | ||
| columnMetadata.put(columnCount++, new SQLServerDataColumn(columnName, sqlType)); | ||
| } | ||
|
|
||
|
|
@@ -89,10 +93,29 @@ public synchronized void addColumnMetadata(String columnName, | |
| */ | ||
| public synchronized void addColumnMetadata(SQLServerDataColumn column) throws SQLServerException { | ||
| // column names must be unique | ||
| Util.checkDuplicateColumnName(column.columnName, columnMetadata); | ||
| checkDuplicateColumnName(column.columnName); | ||
| columnMetadata.put(columnCount++, column); | ||
| } | ||
|
|
||
| /** | ||
| * Checks if duplicate columns exists, in O(n) time. | ||
| * | ||
| * @param columnName | ||
| * the name of the column | ||
| * @throws SQLServerException | ||
| * when a duplicate column exists | ||
| */ | ||
| private void checkDuplicateColumnName(String columnName) throws SQLServerException { | ||
| if (null != columnList) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather an NPE than silently fail to check dupes if someone messes up null handling. Better IMO would be defining the local variable like |
||
| //columnList.add will return false if the same column name already exists | ||
| if (!columnList.add(columnName)) { | ||
| MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_TVPDuplicateColumnName")); | ||
| Object[] msgArgs = {columnName}; | ||
| throw new SQLServerException(null, form.format(msgArgs), null, 0, false); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Adds one row of data to the data table. | ||
| * | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 naming this
columNameswould be clearer