[
https://issues.apache.org/jira/browse/TINKERPOP-848?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17430315#comment-17430315
]
ASF GitHub Bot commented on TINKERPOP-848:
------------------------------------------
amatiushkin commented on a change in pull request #1485:
URL: https://github.com/apache/tinkerpop/pull/1485#discussion_r731503254
##########
File path:
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLReader.java
##########
@@ -138,9 +143,11 @@ public void readGraph(final InputStream graphInputStream,
final Graph graphToWri
case GraphMLTokens.DATA:
final String key = reader.getAttributeValue(null,
GraphMLTokens.KEY);
final String dataAttributeName = keyIdMap.get(key);
+ final String defaultValue = defaultValues.get(key);
if (dataAttributeName != null) {
- final String value = reader.getElementText();
+ String elementValue = reader.getElementText();
+ final String value = elementValue.length() ==
0 && defaultValue.length() != 0 ? defaultValue : elementValue;
Review comment:
The primer says:
> There can be graph elements for which a GraphML-Attribute is defined but
no value is declared by a corresponding data element. If a default value is
defined for this GraphML-Attribute, then this default value is applied to the
graph element.
XML specification (3.1[ Start-Tags, End-Tags, and Empty-Element
Tags](https://www.w3.org/TR/xml/#sec-starttags)) defines what's considered
content and no-content.
No content case is defined as ` The representation of an empty element is
either a start-tag immediately followed by an end-tag, or an empty-element
tag.`
Example data tags with self-closing tag:
```
<data key="abc" />
```
and empty-tag
```
<data key="abc"></data>
```
Therefore, XMLStreamReader returns empty string for such tags (no-content).
It is empty string and not `null`.
So, yes.
**User is precluded from using empty string and default value at the same
time, unless default value is empty string.**
I have added more tests to illustrate it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
> Support default attribute values in GraphMLReader
> -------------------------------------------------
>
> Key: TINKERPOP-848
> URL: https://issues.apache.org/jira/browse/TINKERPOP-848
> Project: TinkerPop
> Issue Type: Improvement
> Components: io
> Affects Versions: 3.0.2-incubating
> Reporter: Pavel Klinov
> Priority: Trivial
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> Looking at the code of GraphMLReader I see that it doesn't support default
> values of attributes, which are allowed by the GraphML spec. This is a bit
> annoying especially if the input defines default values for attributes which
> are used for mandatory data, e.g. edge labels.
> One small example is the sample graph at [1]. "d_e" is the label attribute
> with a default value. There're <edge .. /> elements w/o body later in the
> document and reading those will throw a "java.lang.IllegalArgumentException:
> Label can not be null" exception (if the vendor considers edge labels
> mandatory).
> I'd personaly squash both keyIdMap and keyTypesMap into a single String ->
> AttrInfo map, where AttrInfo would contain information about the data
> attribute name, type, and the default value.
> [1] http://www.eecs.wsu.edu/~yyao/DirectedStudyI/Datasets/AS/sample.graphml
--
This message was sent by Atlassian Jira
(v8.3.4#803005)