tspurway / hustle

A column oriented, embarrassingly distributed relational event database.
Other
240 stars 36 forks source link

New Data Type IP #54

Closed ncloudioj closed 10 years ago

ncloudioj commented 10 years ago

Storing IP addresses in Hustle turns out to be quite common. Directly storing the IP strings like "127.0.0.1" is space wasteful and inefficient when querying it. A better encoding schema would be helpful.

Option 1, convert it to binary format before inserting to database. In turn, convert back to string when fetching it. (inet_aton, inet_ntoa) Option 2, radix trie encoding. The current 32bit Trie can't hold the whole IP collections. The binary radix trie could be the used here.

ncloudioj commented 10 years ago

Seems pointless to add this special data type, since IPv4 is essentially uint32.

To work around this, use the new feature - column functions, consider it as the field transformer of Hustle.

select( ip_ntoa(table.ip), where=... )

ip_ntoa will convert the integer back to its string representation for you.

For more details, reference 1927cd7b137e41eb8efd327f5c5a470a59bc8ba0