dgraph icon indicating copy to clipboard operation
dgraph copied to clipboard

RDF Types ignored in mutations

Open etix opened this issue 9 years ago • 9 comments

Based on the documentation and given the following example:

mutation {
    set {
        <alice> <name> "Alice" .
        <alice> <age> "32"^^<xs:int> .
    }
}

query {
    me(id: alice) {
        name
        age
    }
}

We expect age to be of type int, but it ends up being of type string.

{
    "attribute": "_root_",
    "children": [
        {
            "attribute": "me",
            "properties": [
                {
                    "prop": "name",
                    "value": {
                        "Val": {
                            "StrVal": "Alice"
                        }
                    }
                },
                {
                    "prop": "age",
                    "value": {
                        "Val": {
                            "StrVal": "32"
                        }
                    }
                }
            ]
        }
    ]
}

etix avatar Feb 15 '17 16:02 etix

The type specified during mutation is the storage type and not the type that is returned. So this is expected behaviour. If you'd like to retrieve the value as an int, that has to be specified in the schema.

ashwin95r avatar Feb 17 '17 04:02 ashwin95r

In my opinion it would be way more useful to able to specify the return type at runtime and maybe the storage type in the schema than the opposite. I don't really understand the rationale behind that choice.

Furthermore, it prevents a small application to be able to work out of the box with dgraph just by connecting to it (what I understood when reading the documentation). Instead it requires to start the database with the provided schema first which is inconvenient. Think of the overhead for a small GitHub project you want to give a quick try.

Anyway, the documentation needs to be updated to reflect this behavior.

etix avatar Feb 17 '17 07:02 etix

Sure, that sounds fair. We are working on a dynamic schema (#572) which would infer the schema from the mutation and that should address this specific issue.

ashwin95r avatar Feb 17 '17 08:02 ashwin95r

Yeah, dynamic schema would solve this issue. In the absence of a predefined schema type, the first mutation that we receive for a predicate (age in this case), whatever data type it specifies (int in this case), would be stored as schema type. Then any queries for age would always return data in int; which is what you expect from the system.

FYI: @janardhan1993

manishrjain avatar Feb 17 '17 10:02 manishrjain

@etix The changes are merged in master, you can take a look. In absence of predefined schema type, type is derived from the first mutation that we receive for a predicate. So in you case the schema would be set to int. The data is converted to schema type if no storage type is specified or else it is stored as storage type(int in this case).

Later we will provide some way to update schema, so that you can retrieve the same data with different schema.

janardhan1993 avatar Feb 18 '17 07:02 janardhan1993

In the current master <clara> <age> "32"^^<xs:int> . creates a type Bool:

"prop": "age",
"value": {
    "Val": {
         "BoolVal": true
    }
}

But for some reason (maybe unrelated) all the properties that are supposed to be strings, contains a "prop": "name" but without value.

etix avatar Feb 20 '17 13:02 etix

The bool issue was my fault (old version of the proto file on my machine) and the strings issue on the gRPC side has been fixed in ad0648e48f8e46dd2389687b800a8395d2b1edb4.

etix avatar Feb 20 '17 18:02 etix

@etix Can we close this issue now?

pawanrawal avatar Feb 21 '17 00:02 pawanrawal

LGTM, thanks!

etix avatar Feb 21 '17 09:02 etix