Skip to content

Commit

Permalink
Add INET column type. Closes #291
Browse files Browse the repository at this point in the history
  • Loading branch information
kaidaguerre authored Mar 9, 2022
1 parent 2b687cb commit 451a3d7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 25 deletions.
54 changes: 29 additions & 25 deletions grpc/proto/plugin.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions grpc/proto/plugin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ enum ColumnType {
IPADDR = 6;
CIDR = 7;
TIMESTAMP = 8;
INET = 9;
LTREE = 10;
UNKNOWN = -1;
}
13 changes: 13 additions & 0 deletions plugin/table_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,19 @@ func (t *Table) interfaceToColumnValue(column *QueryColumn, val interface{}) (*p
columnValue = &proto.Column{Value: &proto.Column_CidrRangeValue{CidrRangeValue: cidrRangeString}}
}
break
case proto.ColumnType_INET:
inetString := types.SafeString(val)
// treat an empty string as a null ip address
if inetString == "" {
columnValue = &proto.Column{Value: &proto.Column_NullValue{}}
} else {
if ip := net.ParseIP(inetString); ip == nil {
if _, _, err := net.ParseCIDR(inetString); err != nil {
return nil, fmt.Errorf("%s: invalid ip address %s", column.Name, inetString)
}
}
columnValue = &proto.Column{Value: &proto.Column_CidrRangeValue{CidrRangeValue: inetString}}
}
case proto.ColumnType_LTREE:
columnValue = &proto.Column{Value: &proto.Column_LtreeValue{LtreeValue: types.ToString(val)}}
break
Expand Down
2 changes: 2 additions & 0 deletions plugin/table_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ func columnTypeToString(columnType proto.ColumnType) string {
return "ColumnType_IPADDR"
case proto.ColumnType_CIDR:
return "ColumnType_CIDR"
case proto.ColumnType_INET:
return "ColumnType_INET"
case proto.ColumnType_TIMESTAMP:
return "ColumnType_TIMESTAMP"
case proto.ColumnType_LTREE:
Expand Down

0 comments on commit 451a3d7

Please sign in to comment.