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
Add Interleaved annotation implementation #168
Conversation
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 that the graph algorithm could potentially be separated into its own class and tested independently.
Just something to consider.
Also, please add more comments to the dense parts of the code.
...-spanner-hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/Interleaved.java
Outdated
Show resolved
Hide resolved
...-spanner-hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/Interleaved.java
Outdated
Show resolved
Hide resolved
...-spanner-hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/Interleaved.java
Outdated
Show resolved
Hide resolved
...-spanner-hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/Interleaved.java
Outdated
Show resolved
Hide resolved
...-spanner-hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/Interleaved.java
Outdated
Show resolved
Hide resolved
...hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/SpannerTableExporter.java
Show resolved
Hide resolved
/** | ||
* Returns a {@link Map} which maps a table to the table it is interleaved with. | ||
*/ | ||
private Map<Table, Table> buildCreateTableDependencies(Metadata metadata) { |
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.
Why does this method belong here rather than the SpannerTableExporter
?
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.
Done, I went with your suggestion of splitting out the table-dependency-tracking stuff to a separate class; this work is now done in that class.
/** | ||
* Returns a {@link Map} which maps a table to the table that must be dropped before it. | ||
*/ | ||
private static Map<Table, Table> buildDropTableDependencies(Metadata metadata) { |
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.
Why does this method belong here rather than the SpannerTableExporter
?
Also, please try to factor out the duplication with the method above.
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.
Done; same as above.
...e-dialect/src/main/java/com/google/cloud/spanner/hibernate/schema/SpannerSchemaMigrator.java
Show resolved
Hide resolved
|
||
private final String createTableTemplate; | ||
private Map<Table, Table> tableDependencies; |
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.
Which generic argument is parent and which is child?
I think the use of the term "dependent" or "dependencies" is a bit confusing.
Would it make sense to call the variables and methods more in terms of "child" tables and "parent" tables?
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.
In the Map<Table, Table> for each (key, value) entry, the Table in the value must be processed (either created or dropped) before the Table in the key position.
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 like the refactoring.
...-spanner-hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/Interleaved.java
Outdated
Show resolved
Hide resolved
...-spanner-hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/SchemaUtils.java
Outdated
Show resolved
Hide resolved
...e-dialect/src/main/java/com/google/cloud/spanner/hibernate/schema/SpannerSchemaMigrator.java
Show resolved
Hide resolved
Unfortunately right now we don't have test coverage over the SchemaMigrator. I think this is best tested through Integration test. I tried to write a unit test for this (i.e. running Hibernate in a unit test with ddl-mode.auto=UPDATE triggers the SchemaMigrator) but it tries to make queries to the underlying Spanner instance to see what the current tables are and see which tables need to be altered. I decided its not worth digging around in the Hibernate code and seeing what mock objects we need to inject in which fields to get this to work. I created #170 to track the integration test efforts. Note that create and drop are covered via unit tests. |
...-spanner-hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/Interleaved.java
Outdated
Show resolved
Hide resolved
...hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/SpannerTableExporter.java
Outdated
Show resolved
Hide resolved
...bernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/TableDependencyTracker.java
Outdated
Show resolved
Hide resolved
...bernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/TableDependencyTracker.java
Outdated
Show resolved
Hide resolved
…e/cloud/spanner/hibernate/Interleaved.java Co-Authored-By: Mike Eltsufin <meltsufin@google.com>
…loud-spanner-hibernate into interleaved
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.
Some more, but minor comments.
...-spanner-hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/SchemaUtils.java
Outdated
Show resolved
Hide resolved
...-spanner-hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/Interleaved.java
Show resolved
Hide resolved
...-spanner-hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/SchemaUtils.java
Outdated
Show resolved
Hide resolved
...bernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/SpannerTableStatements.java
Outdated
Show resolved
Hide resolved
...bernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/SpannerTableStatements.java
Outdated
Show resolved
Hide resolved
...bernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/TableDependencyTracker.java
Outdated
Show resolved
Hide resolved
...e-dialect/src/main/java/com/google/cloud/spanner/hibernate/schema/SpannerSchemaMigrator.java
Show resolved
Hide resolved
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.
Looks good, a few nits.
...-spanner-hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/Interleaved.java
Outdated
Show resolved
Hide resolved
...-spanner-hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/Interleaved.java
Outdated
Show resolved
Hide resolved
*/ | ||
|
||
ArrayList<String> dropStrings = new ArrayList<>(); | ||
private String[] buildSqlStrings(Table currentTable, Metadata metadata, boolean isCreateTables) { |
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.
Non-blocking personal opinion: an enum would be clearer than boolean for CREATE vs DROP.
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.
Agreed, but then you need to check for nulls and invalid options, etc.
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 decided to use the Action Enum provided in the Hibernate libraries (it has Action.CREATE, Action.DROP, etc.)
It'll be fine to use this; as far as invalid options/nulls, I think we will be able to avoid these problems since these functions are not intended to be called by end users. It is more to just make the code easier for us to understand with enums over booleans.
...hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/SpannerTableExporter.java
Show resolved
Hide resolved
...r-hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/schema/SchemaUtils.java
Outdated
Show resolved
Hide resolved
...-dialect/src/main/java/com/google/cloud/spanner/hibernate/schema/SpannerTableStatements.java
Outdated
Show resolved
Hide resolved
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.
All good, after you address Elena's comments.
...-spanner-hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/Interleaved.java
Outdated
Show resolved
Hide resolved
*/ | ||
|
||
ArrayList<String> dropStrings = new ArrayList<>(); | ||
private String[] buildSqlStrings(Table currentTable, Metadata metadata, boolean isCreateTables) { |
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.
Agreed, but then you need to check for nulls and invalid options, etc.
This is the initial implementation of the
@Interleaved
annotation.I would like to get this in and add the full polishing and integration tests in separate PRs.
In progress #140.
Notes:
SpannerTableStatements.getSortedPkColumns(..)
. Details: https://cloud.google.com/spanner/docs/schema-and-data-model