-
Notifications
You must be signed in to change notification settings - Fork 60
Refactor relationship table operations to be functional index compatible #590
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
Open
jphui
wants to merge
19
commits into
master
Choose a base branch
from
jhui/relanew
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
805d0e9
initial changes, need propagation + injection
jphui a350be6
Large AI refactor, no new testing introduced though
jphui f9649d1
nits
jphui 175992b
nits
jphui c04b9b1
add testing
jphui 325eb69
typo
jphui 98fb1c4
fixes some tests
jphui 7e0e347
line lengths
jphui 7d4f1fe
short name
jphui 5f8d0c1
formatting
jphui ae81100
no more short name
jphui 1a82ae2
Testing is busted because DAO requires real tables to form proper query
jphui ba7362f
triplet
jphui c07c1ce
comments
jphui 2ea9aa3
testing added for addTablePrefixToExpression
jphui d32acf4
Merge branch 'master' into jhui/relanew
jphui 60d5360
fix prefix
jphui c8ed023
Rounds off testing!
jphui f315e89
add tick
jphui 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
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
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 |
|---|---|---|
|
|
@@ -65,29 +65,61 @@ private static String parseIndexValue(@Nullable IndexValue indexValue) { | |
| } | ||
| } | ||
|
|
||
| @Nullable | ||
| private static String getIndexedExpressionOrColumnGeneric(@Nonnull String expectedLegacyColumnName, @Nonnull String expectedExpressionIndexName, | ||
| @Nonnull String tableName, @Nonnull SchemaValidatorUtil schemaValidator) { | ||
| // Check if an expression-based index exists... if it does, use that | ||
| final String indexExpression = schemaValidator.getIndexExpression(tableName, expectedExpressionIndexName); | ||
| if (indexExpression != null) { | ||
| log.info("Using expression index '{}' in table '{}' with expression '{}'", expectedExpressionIndexName, tableName, indexExpression); | ||
| return indexExpression; | ||
| } else if (schemaValidator.columnExists(tableName, expectedLegacyColumnName)) { | ||
| // (Pre-functional-index logic) Check for existence of (virtual) column | ||
| return expectedLegacyColumnName; | ||
| } else { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Get the expression index "identifier", if it exists, otherwise retrieve the generated column name. | ||
| * The idea behind this is that whatever is returned from this method can be used verbatim to query the database; | ||
| * it's either the expression index itself (new approach) or the virtual column (old approach). | ||
| * Intended to be used with entity table metadata. | ||
| */ | ||
| @Nullable | ||
| public static String getIndexedExpressionOrColumn(@Nonnull String assetType, @Nonnull String aspect, @Nonnull String path, | ||
| boolean nonDollarVirtualColumnsEnabled, @Nonnull String tableName, @Nonnull SchemaValidatorUtil schemaValidator) { | ||
| final String expectedLegacyColumnName = getGeneratedColumnName(assetType, aspect, path, nonDollarVirtualColumnsEnabled); | ||
| return getIndexedExpressionOrColumnGeneric(expectedLegacyColumnName, getExpressionIndexName(assetType, aspect, path), tableName, schemaValidator); | ||
| } | ||
|
Comment on lines
+91
to
+96
Contributor
Author
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. Not tested directly in unit testing since the "inferred table variant" is tested thoroughly. |
||
|
|
||
| /** | ||
| * Like the above but derives the 'tableName' from the 'assetType' parameter. Requires strict assurance that it is set. | ||
| */ | ||
| @Nullable | ||
| public static String getIndexedExpressionOrColumn(@Nonnull String assetType, @Nonnull String aspect, @Nonnull String path, | ||
| boolean nonDollarVirtualColumnsEnabled, @Nonnull SchemaValidatorUtil schemaValidator) { | ||
| final String indexColumn = getGeneratedColumnName(assetType, aspect, path, nonDollarVirtualColumnsEnabled); | ||
| final String tableName = getTableName(assetType); | ||
| return getIndexedExpressionOrColumn(assetType, aspect, path, nonDollarVirtualColumnsEnabled, tableName, schemaValidator); | ||
| } | ||
|
|
||
| // Check if an expression-based index exists... if it does, use that | ||
| final String expressionIndexName = getExpressionIndexName(assetType, aspect, path); | ||
| final String indexExpression = schemaValidator.getIndexExpression(tableName, expressionIndexName); | ||
| if (indexExpression != null) { | ||
| log.info("Using expression index '{}' in table '{}' with expression '{}'", expressionIndexName, tableName, indexExpression); | ||
| return indexExpression; | ||
| } else if (schemaValidator.columnExists(tableName, indexColumn)) { | ||
| // (Pre-functional-index logic) Check for existence of (virtual) column | ||
| return indexColumn; | ||
| } else { | ||
| return null; | ||
| } | ||
| /** | ||
| * Get the expression index "identifier", if it exists, otherwise retrieve the generated column name. | ||
| * The idea behind this is that whatever is returned from this method can be used verbatim to query the database; | ||
| * it's either the expression index itself (new approach) or the virtual column (old approach). | ||
| * Intended to be used with relationship table metadata. | ||
| * | ||
| * @param relationshipFieldName the name of the relationship field "name" as stored in the RelationshipField object | ||
| * defined by the RelationshipField.pdl model. This defaults to "metadata". | ||
| */ | ||
| @Nullable | ||
| public static String getIndexedExpressionOrColumnRelationship(@Nonnull String relationshipFieldName, @Nonnull String path, | ||
| boolean nonDollarVirtualColumnsEnabled, @Nonnull String tableName, @Nonnull SchemaValidatorUtil schemaValidator) { | ||
| final String expectedLegacyColumnName = | ||
| SQLSchemaUtils.getGeneratedColumnNameRelationship(relationshipFieldName, path, nonDollarVirtualColumnsEnabled); | ||
| final String expectedExpressionIndexName = SQLSchemaUtils.getExpressionIndexNameRelationship(path); | ||
| return getIndexedExpressionOrColumnGeneric(expectedLegacyColumnName, expectedExpressionIndexName, tableName, schemaValidator); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
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
Oops, something went wrong.
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.
cannot mock at this level, everything is just passing new args in anyway so the testing is deferred to the callees :)