You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@age.apache.org by GitBox <gi...@apache.org> on 2021/07/31 14:28:57 UTC

[GitHub] [incubator-age] uriaash commented on a change in pull request #87: Adding AGType parsers and driver supports for Python & Go

uriaash commented on a change in pull request #87:
URL: https://github.com/apache/incubator-age/pull/87#discussion_r680365752



##########
File path: drivers/golang/models.go
##########
@@ -0,0 +1,269 @@
+package main
+
+import (
+	"bytes"
+	"fmt"
+	"math/big"
+	"reflect"
+)
+
+// GTYPE representing entity types for AGE result data : Vertex, Edge, Path and SimpleEntity
+type GTYPE uint8
+
+const (
+	G_OTHER GTYPE = 1 + iota
+	G_VERTEX
+	G_EDGE
+	G_PATH
+	G_MAP_PATH
+	G_STR
+	G_INT
+	G_INTBIG
+	G_FLOAT
+	G_BOOL
+	G_MAP
+	G_ARR
+)
+
+var _TpV = reflect.TypeOf(&Vertex{})
+var _TpE = reflect.TypeOf(&Edge{})
+var _TpP = reflect.TypeOf(&Path{})
+var _TpMP = reflect.TypeOf(&MapPath{})
+var _TpStr = reflect.TypeOf(string(""))
+var _TpInt = reflect.TypeOf(int(0))
+var _TpIntBig = reflect.TypeOf(big.NewInt(0))
+var _TpFloat = reflect.TypeOf(float64(0))
+var _TpBool = reflect.TypeOf(bool(false))
+var _TpMap = reflect.TypeOf(map[string]interface{}{})
+var _TpArr = reflect.TypeOf([]interface{}{})
+
+// Entity object interface for parsed AGE result data : Vertex, Edge, Path and SimpleEntity
+type Entity interface {
+	GType() GTYPE
+	String() string
+}
+
+func IsEntity(v interface{}) bool {
+	_, ok := v.(Entity)
+	return ok
+}
+
+type SimpleEntity struct {
+	Entity
+	typ   GTYPE
+	value interface{}
+}
+
+func NewSimpleEntity(value interface{}) *SimpleEntity {
+	switch value.(type) {
+	case string:
+		return &SimpleEntity{typ: G_STR, value: value}
+	case int:
+		return &SimpleEntity{typ: G_INT, value: value}
+	case *big.Int:
+		return &SimpleEntity{typ: G_INTBIG, value: value}
+	case float64:
+		return &SimpleEntity{typ: G_FLOAT, value: value}
+	case bool:
+		return &SimpleEntity{typ: G_BOOL, value: value}
+	case map[string]interface{}:
+		return &SimpleEntity{typ: G_MAP, value: value}
+	case []interface{}:
+		return &SimpleEntity{typ: G_ARR, value: value}
+	default:
+		return &SimpleEntity{typ: G_OTHER, value: value}
+	}
+}
+
+func (e *SimpleEntity) GType() GTYPE {
+	return e.typ
+}
+
+func (e *SimpleEntity) Value() interface{} {
+	return e.value
+}
+
+func (e *SimpleEntity) String() string {
+	return fmt.Sprintf("%v", e.value)
+}
+
+func (e *SimpleEntity) AsStr() string {
+	return e.value.(string)
+}
+
+func (e *SimpleEntity) AsInt() int {
+	return e.value.(int)
+}
+
+func (e *SimpleEntity) AsInt64() int64 {
+	return e.value.(int64)
+}
+
+func (e *SimpleEntity) AsFloat() float64 {
+	return e.value.(float64)
+}
+
+func (e *SimpleEntity) AsBool() bool {
+	return e.value.(bool)
+}
+
+func (e *SimpleEntity) AsMap() map[string]interface{} {
+	return e.value.(map[string]interface{})
+}
+
+func (e *SimpleEntity) AsArr() []interface{} {
+	return e.value.([]interface{})
+}
+
+type LabeledEntity struct {
+	Entity
+	id    int64
+	label string
+	props map[string]interface{}

Review comment:
       The `id`, `label`, and `props` should probably be public and changed to `Id`, `Label`, and `Props`.
   Otherwise, you won't be able to use them as described in the README file (see usage example section).




-- 
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: commits-unsubscribe@age.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org