- Notifications
You must be signed in to change notification settings - Fork 45
add DefaultPropertiesCombiner and DefaultVertexValueCombiner #16
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits Select commit Hold shift + click to select a range
99d0197 add DefaultPropertiesCombiner and DefaultVertexValueCombiner
houzhizhen 1553768 add OverwriteValueCombiner, MergeNewPropertiesCombiner and MergeOldPr…
houzhizhen 2a76289 remove DefaultPropertiesCombiner
houzhizhen 24ade14 improve test case
houzhizhen aa2d853 add null check and test case
houzhizhen 486dc9b add combine in message
houzhizhen 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
45 changes: 45 additions & 0 deletions 45 .../src/main/java/com/baidu/hugegraph/computer/core/combiner/MergeNewPropertiesCombiner.java
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 |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * Copyright 2017 HugeGraph Authors | ||
| * | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with this | ||
| * work for additional information regarding copyright ownership. The ASF | ||
| * licenses this file to You under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| | ||
| package com.baidu.hugegraph.computer.core.combiner; | ||
| | ||
| import java.util.Map; | ||
| | ||
| import com.baidu.hugegraph.computer.core.graph.properties.Properties; | ||
| import com.baidu.hugegraph.computer.core.graph.value.Value; | ||
| import com.baidu.hugegraph.util.E; | ||
| | ||
| public class MergeNewPropertiesCombiner implements PropertiesCombiner { | ||
| | ||
| /** | ||
| * Merge properties v2 into v1. If a property exists in both v1 and v2, | ||
| * remain the value in v1. | ||
| */ | ||
| @Override | ||
| public Properties combine(Properties v1, Properties v2) { | ||
| E.checkArgumentNotNull(v1, "The parameter v1 can't be null"); | ||
| E.checkArgumentNotNull(v2, "The parameter v2 can't be null"); | ||
| Map<String, Value> v1Map = v1.get(); | ||
| Map<String, Value> v2Map = v2.get(); | ||
| for (Map.Entry<String, Value> entry : v2Map.entrySet()) { | ||
| v1Map.putIfAbsent(entry.getKey(), entry.getValue()); | ||
| } | ||
| return v1; | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions 45 .../src/main/java/com/baidu/hugegraph/computer/core/combiner/MergeOldPropertiesCombiner.java
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 |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * Copyright 2017 HugeGraph Authors | ||
| * | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with this | ||
| * work for additional information regarding copyright ownership. The ASF | ||
| * licenses this file to You under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| | ||
| package com.baidu.hugegraph.computer.core.combiner; | ||
| | ||
| import java.util.Map; | ||
| | ||
| import com.baidu.hugegraph.computer.core.graph.properties.Properties; | ||
| import com.baidu.hugegraph.computer.core.graph.value.Value; | ||
| import com.baidu.hugegraph.util.E; | ||
| | ||
| public class MergeOldPropertiesCombiner implements PropertiesCombiner { | ||
| | ||
| /** | ||
| * Merge properties v1 into v2. If a property exists in both v1 and v2, | ||
| * remain the value in v2. | ||
| */ | ||
| @Override | ||
| public Properties combine(Properties v1, Properties v2) { | ||
| Contributor 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. check v1 and v2 not null, and add test case. | ||
| E.checkArgumentNotNull(v1, "The parameter v1 can't be null"); | ||
| E.checkArgumentNotNull(v2, "The parameter v2 can't be null"); | ||
| Map<String, Value> v1Map = v1.get(); | ||
| Map<String, Value> v2Map = v2.get(); | ||
| for (Map.Entry<String, Value> entry : v1Map.entrySet()) { | ||
| v2Map.putIfAbsent(entry.getKey(), entry.getValue()); | ||
| } | ||
| return v2; | ||
| } | ||
| } | ||
32 changes: 32 additions & 0 deletions 32 ...uter-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/OverwriteCombiner.java
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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * Copyright 2017 HugeGraph Authors | ||
| * | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with this | ||
| * work for additional information regarding copyright ownership. The ASF | ||
| * licenses this file to You under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| | ||
| package com.baidu.hugegraph.computer.core.combiner; | ||
| | ||
| import com.baidu.hugegraph.util.E; | ||
| | ||
| public class OverwriteCombiner<T> implements Combiner<T> { | ||
| | ||
| @Override | ||
| public T combine(T v1, T v2) { | ||
| E.checkArgumentNotNull(v1, "The parameter v1 can't be null"); | ||
| E.checkArgumentNotNull(v2, "The parameter v2 can't be null"); | ||
| return v2; | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions 29 ...ter-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/PropertiesCombiner.java
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 |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * Copyright 2017 HugeGraph Authors | ||
| * | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with this | ||
| * work for additional information regarding copyright ownership. The ASF | ||
| * licenses this file to You under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| | ||
| package com.baidu.hugegraph.computer.core.combiner; | ||
| | ||
| import com.baidu.hugegraph.computer.core.graph.properties.Properties; | ||
| | ||
| /** | ||
| * When vertex properties with the same vertex id are loaded, this class | ||
| * specifies how to combine their properties. | ||
| */ | ||
| public interface PropertiesCombiner extends Combiner<Properties> { | ||
| } |
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
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
92 changes: 92 additions & 0 deletions 92 .../main/java/com/baidu/hugegraph/computer/core/combiner/MergeNewPropertiesCombinerTest.java
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 |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /* | ||
| * Copyright 2017 HugeGraph Authors | ||
| * | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with this | ||
| * work for additional information regarding copyright ownership. The ASF | ||
| * licenses this file to You under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| | ||
| package com.baidu.hugegraph.computer.core.combiner; | ||
| | ||
| import org.junit.Test; | ||
| | ||
| import com.baidu.hugegraph.computer.core.graph.id.Utf8Id; | ||
| import com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties; | ||
| import com.baidu.hugegraph.computer.core.graph.properties.Properties; | ||
| import com.baidu.hugegraph.testutil.Assert; | ||
| | ||
| public class MergeNewPropertiesCombinerTest { | ||
| | ||
| @Test | ||
| public void testCombine() { | ||
| Properties properties1 = new DefaultProperties(); | ||
| properties1.put("name", new Utf8Id("marko").idValue()); | ||
| properties1.put("city", new Utf8Id("Beijing").idValue()); | ||
| | ||
| Properties properties2 = new DefaultProperties(); | ||
| properties2.put("name", new Utf8Id("josh").idValue()); | ||
| properties2.put("age", new Utf8Id("18").idValue()); | ||
| | ||
| Properties expect = new DefaultProperties(); | ||
| expect.put("name", new Utf8Id("marko").idValue()); | ||
| expect.put("age", new Utf8Id("18").idValue()); | ||
| expect.put("city", new Utf8Id("Beijing").idValue()); | ||
| | ||
| PropertiesCombiner combiner = new MergeNewPropertiesCombiner(); | ||
| Properties properties = combiner.combine(properties1, properties2); | ||
| Assert.assertEquals(expect, properties); | ||
| | ||
| Assert.assertThrows(IllegalArgumentException.class, () -> { | ||
| combiner.combine(null, properties2); | ||
| }, e -> { | ||
| Assert.assertEquals("The parameter v1 can't be null", | ||
| e.getMessage()); | ||
| }); | ||
| | ||
| Assert.assertThrows(IllegalArgumentException.class, () -> { | ||
| combiner.combine(properties1, null); | ||
| }, e -> { | ||
| Assert.assertEquals("The parameter v2 can't be null", | ||
| e.getMessage()); | ||
| }); | ||
| } | ||
| | ||
| @Test | ||
| public void testCombineNull() { | ||
| Properties properties1 = new DefaultProperties(); | ||
| properties1.put("name", new Utf8Id("marko").idValue()); | ||
| properties1.put("city", new Utf8Id("Beijing").idValue()); | ||
| | ||
| Properties properties2 = new DefaultProperties(); | ||
| properties2.put("name", new Utf8Id("josh").idValue()); | ||
| properties2.put("age", new Utf8Id("18").idValue()); | ||
| | ||
| | ||
| PropertiesCombiner combiner = new MergeNewPropertiesCombiner(); | ||
| | ||
| Assert.assertThrows(IllegalArgumentException.class, () -> { | ||
| combiner.combine(null, properties2); | ||
| }, e -> { | ||
| Assert.assertEquals("The parameter v1 can't be null", | ||
| e.getMessage()); | ||
| }); | ||
| | ||
| Assert.assertThrows(IllegalArgumentException.class, () -> { | ||
| combiner.combine(properties1, null); | ||
| }, e -> { | ||
| Assert.assertEquals("The parameter v2 can't be null", | ||
| e.getMessage()); | ||
| }); | ||
| } | ||
| } |
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.
The combine parameter
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.
It's unified with others not null checks. If it fails, the stack trance will show the information.