Skip to content

Commit

Permalink
Make thrift decode of EntityDefinition respect column ordering. (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
phliar authored Jan 31, 2020
1 parent 95604d5 commit 9318f81
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Changelog

## v3.4.17 (unreleased)
## v3.4.18 (unreleased)
- No changes yet.

## v3.4.17 (2020-01-31)
- Make thrift decode of EntityDefinition respect column ordering.

## v3.4.16 (2020-01-31)
- Update to IDL 3.3 for column ordering
- Send column order with all schema requests
Expand Down
20 changes: 16 additions & 4 deletions connectors/yarpc/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,17 @@ func FromThriftToPrimaryKey(key *dosarpc.PrimaryKey) *dosa.PrimaryKey {
// FromThriftToEntityDefinition converts the RPC EntityDefinition to client EntityDefinition
func FromThriftToEntityDefinition(ed *dosarpc.EntityDefinition) *dosa.EntityDefinition {
fields := make([]*dosa.ColumnDefinition, len(ed.FieldDescs))
i := 0
for k, v := range ed.FieldDescs {
colOrder := ed.ColumnOrder
if colOrder == nil {
colOrder = getRPCEntityColumns(ed)
}
for i, colName := range ed.ColumnOrder {
v := ed.FieldDescs[colName]
fields[i] = &dosa.ColumnDefinition{
Name: k,
Name: colName,
Type: RPCTypeToClientType(*v.Type),
// TODO Tag
}
i++
}

indexes := make(map[string]*dosa.IndexDefinition)
Expand All @@ -310,6 +313,15 @@ func FromThriftToEntityDefinition(ed *dosarpc.EntityDefinition) *dosa.EntityDefi
}
}

// The columns are returned in arbitrary order.
func getRPCEntityColumns(ed *dosarpc.EntityDefinition) []string {
cols := make([]string, 0, len(ed.FieldDescs))
for name := range ed.FieldDescs {
cols = append(cols, name)
}
return cols
}

func encodeOperator(o dosa.Operator) *dosarpc.Operator {
var op dosarpc.Operator
switch o {
Expand Down
6 changes: 6 additions & 0 deletions connectors/yarpc/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,9 @@ func TestGetHeaders(t *testing.T) {
assert.Equal(t, "yarpc.CallOption", reflect.TypeOf(h).String())
}
}

func TestColumnOrder(t *testing.T) {
rpcEDs := EntityDefsToThrift([]*dosa.EntityDefinition{testEntityDefinition})
dosaEd := FromThriftToEntityDefinition(rpcEDs[0])
assert.Equal(t, dosaEd.Columns, testEntityDefinition.Columns)
}
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
package dosa

// VERSION indicates the dosa client version
const VERSION = "3.4.16"
const VERSION = "3.4.17"

0 comments on commit 9318f81

Please sign in to comment.