-
Notifications
You must be signed in to change notification settings - Fork 504
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
throw ExistedException if create schemas with same name and properties different #1009
Conversation
super.initPropertyKeys(); | ||
SchemaManager schema = graph().schema(); | ||
schema.vertexLabel("person").properties("name", "age", "city") | ||
.primaryKeys("name").create(); |
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.
align with ".vertexLabel"
return true; | ||
|
||
|
||
|
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.
remove empty lines
|
||
// if (this.idStrategy != existedVertexLabel.idStrategy()) { | ||
// return false; | ||
// } |
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.
remove unused code
} | ||
for (String propertyName : this.properties) { | ||
PropertyKey propertyKey = this.transaction.getPropertyKey(propertyName); | ||
if (! existedProperties.contains(propertyKey.id())) { |
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.
remove space in "! existedProperties"
@@ -141,6 +141,72 @@ public EdgeLabel create() { | |||
}); | |||
} | |||
|
|||
private boolean hasSameProperties(EdgeLabel existedEdgeLabel) { |
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.
prefer to move this method to class EdgeLabel, and process parent fields by each super class like SchemaLabel/SchemaElement
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.
If move hasSameProperties to EdgeLabel, and parent class, it will reduce some duplicate check.
SchemaLabel has the following fields used by VertexLabel and EdgeLabel.
private final Set<Id> properties;
private final Set<Id> nullableKeys;
private final Set<Id> indexLabels;
private boolean enableLabelIndex;
But the parameter should be Builder, and in should has proper method to retrieve correspond information. There is not common parent Builder with these information.
} | ||
|
||
SchemaLabel schemaLabel = this.loadElement(); | ||
if (! schemaLabel.id().equals(existedIndexLabel.baseValue())) { |
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.
space
private boolean hasSameProperties(IndexLabel existedIndexLabel) { | ||
// baseType is null, it means HugeType.SYS_SCHEMA | ||
if (this.baseType == null && existedIndexLabel.baseType() != HugeType.SYS_SCHEMA | ||
|| this.baseType != existedIndexLabel.baseType()) { |
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.
align
} | ||
|
||
if (this.indexType == null && existedIndexLabel.indexType() != IndexType.SECONDARY | ||
|| this.indexType != existedIndexLabel.indexType()) { |
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.
align
…dgeLabel. If the two or more create statements as the code follows are identical, the system will only create one schema quietly.
82dc4e0
to
97bc6bb
Compare
Codecov Report
@@ Coverage Diff @@
## master #1009 +/- ##
============================================
- Coverage 69.35% 69.31% -0.04%
- Complexity 5275 5304 +29
============================================
Files 325 325
Lines 25870 25967 +97
Branches 3647 3685 +38
============================================
+ Hits 17941 17998 +57
- Misses 6207 6227 +20
- Partials 1722 1742 +20
Continue to review full report at Codecov.
|
return false; | ||
} | ||
} else { // means false | ||
if (existedEdgeLabel.enableLabelIndex() == false) { |
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.
here this. enableLabelIndex = false, seems only existedEdgeLabel.enableLabelIndex() == true
should return false.
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.
Good job, this is a bug.
private boolean hasSameProperties(EdgeLabel existedEdgeLabel) { | ||
HugeGraph graph = this.graph(); | ||
Id sourceId = graph.vertexLabel(this.sourceLabel).id(); | ||
if (! existedEdgeLabel.sourceLabel().equals(sourceId)) { |
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.
There should no space between !
and existedEdgeLabel.sourceLabel().equals(sourceId)
in our code style
…dex is true, it should return false
} | ||
|
||
Id targetId = graph.vertexLabel(this.targetLabel).id(); | ||
|
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.
delete empty line
|
||
/** | ||
* Check whether this has same properties with existedIndexLabel. | ||
* Only baseType,baseValue,indexType, indexFields are checked. |
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.
more or less empty
Only baseType, baseValue, indexType, indexFields are checked.
|
||
/** | ||
* Check whether this has same properties with propertyKey. | ||
* Only dataType, cardinality, aggregateType are checked. |
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.
ditto
@@ -137,6 +137,62 @@ public VertexLabel create() { | |||
}); | |||
} | |||
|
|||
/** | |||
* Check whether this has same properties with existedVertexLabel. | |||
* Only properties, primaryKeys, nullableKeys, enableLabelIndex are checked. |
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.
ditto
implement #870