Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Spanner schema admin functions for parent-child relationships #910

Merged
merged 13 commits into from Aug 10, 2018

Conversation

ChengyuanZhao
Copy link
Contributor

related #853

@ChengyuanZhao ChengyuanZhao added the datastore GCP Datastore label Jul 28, 2018
@ChengyuanZhao ChengyuanZhao self-assigned this Jul 28, 2018
@ChengyuanZhao ChengyuanZhao added spanner and removed datastore GCP Datastore labels Jul 28, 2018
if (ConversionUtils.isIterableNonByteArrayType(
spannerPersistentProperty.getType())) {
throw new SpannerDataException(
"Embedded properties cannot be collections: "
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it a limitation of Spanner, or is it just to disambiguate with one-to-many relationship?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

EDIT, was answering a question about something else !

So no, this is a check to make sure people don't put a List<EmbeddedObject> with the annotation @Embedded because embedded objects are meant to be "flattened" into the containing class (columns merged with those of parents). It wouldn't make sense to flatten a list of that embedded object.

"Could not find suitable Cloud Spanner column inner type for "
+ "property type: " + innerType);
}
ddlString = getTypeDdlString(spannerSupportedInnerType, true,
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe just return the result here? if you do that, the further code can be refactored to avoid using else

spannerPersistentProperty.getMaxColumnLength());
}

private void getCreateTableDdlStringsForHierarchy(String parentTable,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

More explicitly name to say "interleaved"

Copy link
Contributor Author

@ChengyuanZhao ChengyuanZhao left a comment

Choose a reason for hiding this comment

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

In-person review notes/changes

spannerPersistentEntity.tableName(),
spannerPersistentProperty.getColumnInnerType(), ddlStrings,
seenClasses));
seenClasses.add(entityClass);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

need to add this to seen before recursion call

Copy link
Contributor Author

Choose a reason for hiding this comment

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

add test case where two properties have the same inner type to catch this

public String getDropTableDdlString(Class entityClass) {
return "DROP TABLE "
+ this.mappingContext.getPersistentEntity(entityClass).tableName();
private void getDropTableDdlStringsForHierarchy(Class entityClass,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

drop DDL and create DDL is very similar, should refactor

@Column(name = "")
String other;

@OneToMany
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps @Interleaved

public void getCreateDdlHierarchyTest() {
List<String> createStrings = this.spannerSchemaUtils
.getCreateTableDdlStringsForHierarchy(ParentEntity.class);
assertEquals(3, createStrings.size());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

assert equals on array of all 3 strings?

return;
}
ddlStrings.add(getCreateTableDdlString(entityClass) + (parentTable == null ? ""
: ", INTERLEAVE IN PARENT " + parentTable + " ON DELETE CASCADE"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Should ON DELETE CASCADE an option through a property?

@ChengyuanZhao
Copy link
Contributor Author

@meltsufin @dmitry-s changes made from in-person discussion, PTAL

@@ -86,6 +86,8 @@

private final int keepAliveIntervalMinutes;

private final boolean createTableDdlCascadeOnDelete;
Copy link
Contributor

Choose a reason for hiding this comment

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

This applies only to interleaved tables, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that's right

@@ -105,6 +107,8 @@
this.writeSessionsFraction = gcpSpannerProperties.getWriteSessionsFraction();
this.keepAliveIntervalMinutes = gcpSpannerProperties
.getKeepAliveIntervalMinutes();
this.createTableDdlCascadeOnDelete = gcpSpannerProperties
.isCreateTableStatementsCascadeOnDelete();
Copy link
Contributor

Choose a reason for hiding this comment

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

inconsistency in naming createTableDdlCascadeOnDelete vs createTableStatementsCascadeOnDelete.

@@ -40,6 +40,10 @@

private String database;

// if True then create-table statements generated will cascade on delete. no-action on delete
Copy link
Contributor

Choose a reason for hiding this comment

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

Please start sentences with an upper-case letter. Also, use {@code true}, and {@code false}.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

technically (grammatically) these aren't sentences , but will change.

* for generating DDL statements.
* @param spannerEntityProcessor an entity processor that is queried for types that it
* can convert for determining compatible column types when generating DDL statements.
*/
public SpannerSchemaUtils(SpannerMappingContext mappingContext,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see a need for this constructor anymore. You always use the one below, except for one instance in test code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed. Made requested changes.

@dmitry-s

@@ -47,76 +52,47 @@

private final SpannerTypeMapper spannerTypeMapper;

private final boolean createTableDdlDeleteOnCascade;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is still different from createTableStatementsCascadeOnDelete. Also, I think a better name would actually indicate that this is for interleaved tables. Maybe createInterleavedTableCascadeOnDelete?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I can change to that new name everywhere. (originally I felt it was OK to have "Ddl" in this class because so many things in this class have those letters in the name, and it would have more meaning given the context of this class and all the "Ddl" related functions.)

Copy link
Contributor

Choose a reason for hiding this comment

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

createTableStatementsCascadeOnDelete to use DDL in the name.
Actually, I'm leaning towards this name now:
createInterleavedTableDdlOnDeleteCascade

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed in all 3 places to createInterleavedTableDdlOnDeleteCascade and merged in other PRs and resolved conflicts.

I'll update the ref doc PR for this new name, too.

meltsufin
meltsufin previously approved these changes Aug 9, 2018
# Conflicts:
#	spring-cloud-gcp-data-spanner/src/main/java/org/springframework/cloud/gcp/data/spanner/core/mapping/SpannerPersistentEntity.java
#	spring-cloud-gcp-data-spanner/src/main/java/org/springframework/cloud/gcp/data/spanner/core/mapping/SpannerPersistentEntityImpl.java
#	spring-cloud-gcp-data-spanner/src/test/java/org/springframework/cloud/gcp/data/spanner/core/mapping/SpannerPersistentEntityImplTests.java
@meltsufin
Copy link
Contributor

@ChengyuanZhao I think you need to resolve conflicts before merging.

@ChengyuanZhao ChengyuanZhao merged commit c873e2b into master Aug 10, 2018
@ChengyuanZhao ChengyuanZhao deleted the spanner-family-schema branch August 10, 2018 16:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

None yet

3 participants