Skip to content

Commit c9f45a2

Browse files
authored
fix: Validate and normalize inet test values (#2205)
#### Summary The inet type, uses the `net.ParseCIDR` function which when returning the network, actually drop some of the details of the CIDR string that is passed in... ``` It returns the IP address and the network implied by the IP and prefix length. For example, ParseCIDR("192.0.2.1/24") returns the IP address 192.0.2.1 and the network 192.0.2.0/24. ``` This fix ensures that all inet values will be unchanged if they go through a read --> write --> read (like we do in the filetypes tests) This issue was discovered in the filetypes tests where a value was written to a parquet file then read back into an arrow record where the inet builder normalized the data and when compared to the original record a difference was detected
1 parent 6b91b19 commit c9f45a2

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

schema/testdata.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/base64"
66
"fmt"
77
"math/rand"
8+
"net"
89
"strconv"
910
"strings"
1011
"time"
@@ -316,9 +317,11 @@ func (tg TestDataGenerator) getExampleJSON(colName string, dataType arrow.DataTy
316317

317318
// Generate a CIDR prefix length between 8 and 30
318319
cidr := 8 + rnd.Intn(23)
320+
input := fmt.Sprintf(`%d.%d.%d.%d/%d`, ip[0], ip[1], ip[2], ip[3], cidr)
321+
_, data, _ := net.ParseCIDR(input)
319322

320323
// Format as an IP address with CIDR notation
321-
return fmt.Sprintf(`"%d.%d.%d.%d/%d"`, ip[0], ip[1], ip[2], ip[3], cidr)
324+
return fmt.Sprintf(`"%s"`, data.String())
322325
}
323326
if arrow.TypeEqual(dataType, types.ExtensionTypes.MAC) {
324327
mac := make([]byte, 6)

0 commit comments

Comments
 (0)