Skip to content
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

Merged
merged 4 commits into from
Jun 1, 2020

Conversation

houzhizhen
Copy link
Contributor

@houzhizhen houzhizhen commented May 28, 2020

implement #870

super.initPropertyKeys();
SchemaManager schema = graph().schema();
schema.vertexLabel("person").properties("name", "age", "city")
.primaryKeys("name").create();
Copy link
Contributor

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;



Copy link
Contributor

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;
// }
Copy link
Contributor

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())) {
Copy link
Contributor

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) {
Copy link
Contributor

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

Copy link
Contributor Author

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())) {
Copy link
Contributor

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()) {
Copy link
Contributor

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()) {
Copy link
Contributor

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.
@codecov
Copy link

codecov bot commented May 29, 2020

Codecov Report

Merging #1009 into master will decrease coverage by 0.03%.
The diff coverage is 42.57%.

Impacted file tree graph

@@             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     
Impacted Files Coverage Δ Complexity Δ
...idu/hugegraph/schema/builder/EdgeLabelBuilder.java 81.88% <40.00%> (-5.73%) 75.00 <4.00> (+7.00) ⬇️
...du/hugegraph/schema/builder/IndexLabelBuilder.java 85.80% <42.85%> (-1.04%) 114.00 <3.00> (+7.00) ⬇️
...u/hugegraph/schema/builder/VertexLabelBuilder.java 81.85% <43.75%> (-5.71%) 79.00 <4.00> (+5.00) ⬇️
...u/hugegraph/schema/builder/PropertyKeyBuilder.java 89.60% <50.00%> (+0.61%) 49.00 <2.00> (+5.00)
...om/baidu/hugegraph/api/filter/ExceptionFilter.java 66.66% <0.00%> (-4.31%) 0.00% <0.00%> (ø%)
...du/hugegraph/backend/tx/GraphIndexTransaction.java 79.58% <0.00%> (-0.25%) 189.00% <0.00%> (-1.00%)
...hugegraph/backend/serializer/BinarySerializer.java 85.43% <0.00%> (+1.29%) 119.00% <0.00%> (+4.00%)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eb8fa1c...eab1896. Read the comment docs.

javeme
javeme previously approved these changes May 29, 2020
@houzhizhen houzhizhen changed the title schemaDuplicateCheck throw ExistedException if create schemas with same name and properties different May 30, 2020
return false;
}
} else { // means false
if (existedEdgeLabel.enableLabelIndex() == false) {
Copy link
Contributor

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.

Copy link
Contributor Author

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)) {
Copy link
Contributor

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

}

Id targetId = graph.vertexLabel(this.targetLabel).id();

Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@houzhizhen houzhizhen requested a review from Linary June 1, 2020 06:27
@javeme javeme merged commit b0202d7 into master Jun 1, 2020
@javeme javeme deleted the schemaDuplicateCheck branch June 1, 2020 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants