-
Notifications
You must be signed in to change notification settings - Fork 15
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
Schema: Parse column type #28
Conversation
As an example, using the print_schema example program on https://github.com/ovn-org/ovn/blob/master/ovn-sb.ovsschema outputs:
|
4ac8ac7
to
a6afc84
Compare
The way the column types are specified in RFC7047 is not directly unmarshallable by the json encoder. This patch adds the necessary structs and functions to manually unmarshal the schema definition. The result is the possibility of determining the exact time of golang structure needed to store each column type. Several approaches were considering when implementing this: A) Multiple rounds of json.Unmarshal storing the partial in in-struct json.rawMessage B) Single call to json.Unmarshall and manually decoding the rest of the message (using reflex to guess the type of incoming data) C) Multiple rounds of json.Unmarshal storing partials in private temporary structs. After discarting A) for it's high memory consumption, B) and C) were compared: B) has lower memory allocation needs but more LOC C) has higher memory allocation needs (though after GC, it's the same or less than B), and fewer LOC. This patch implements C) as a good balance between maintainablity and memory efficiency. Signed-off-by: Adrian Moreno <[email protected]>
the special column "_uuid" is not on the schema object. If it is needed, generate the ColumnSchema on the fly Signed-off-by: Adrian Moreno <[email protected]>
Signed-off-by: Adrian Moreno <[email protected]>
Signed-off-by: Adrian Moreno <[email protected]>
a6afc84
to
f94feaa
Compare
@@ -18,15 +18,15 @@ import ( | |||
// OvsdbClient is an OVSDB client | |||
type OvsdbClient struct { | |||
rpcClient *rpc2.Client | |||
Schema map[string]DatabaseSchema | |||
Schema map[string]*DatabaseSchema |
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.
This changes the interface. At least go-ovn will be broken due to this change. Is there a way to avoid interface change?
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.
You're right. I'll try to avoid breaking the API in #30
Thanks @amorenoz! Please take a look at my comments. In addition, apart from the example, could you add some test cases? |
This PR parses the 'type' field in the column schema so that the type of each column can be easily derived.
It includes an example client that parses any schema file and prints a summary of the types of each column.
Currently, this PR depends on #26
Fixes: #27