Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

Add (or document) way to handle the postgres inet and/or cidr data types #221

Open
emanresusername opened this issue May 18, 2017 · 3 comments

Comments

@emanresusername
Copy link

possibly related to #57
and i'm getting to this from quill, so i'm not 100% sure if there's a way to get around it at that level, but i don't see any quill lines in the stacktrace
I can't get inet values like 192.168.2.0/24 to work
i get the following error

java.net.UnknownHostException: addr is of illegal length
	at java.net.InetAddress.getByAddress(InetAddress.java:1042)
	at java.net.InetAddress.getByAddress(InetAddress.java:1439)
	at com.github.mauricio.async.db.column.InetAddressEncoderDecoder$.decode(InetAddressEncoderDecoder.scala:28)
	at com.github.mauricio.async.db.column.ColumnDecoder$class.decode(ColumnDecoder.scala:28)
	at com.github.mauricio.async.db.column.InetAddressEncoderDecoder$.decode(InetAddressEncoderDecoder.scala:22)
	at com.github.mauricio.async.db.postgresql.column.PostgreSQLColumnDecoderRegistry.decode(PostgreSQLColumnDecoderRegistry.scala:52)
	at com.github.mauricio.async.db.postgresql.PostgreSQLConnection.onDataRow(PostgreSQLConnection.scala:203)
	at com.github.mauricio.async.db.postgresql.codec.PostgreSQLConnectionHandler.channelRead0(PostgreSQLConnectionHandler.scala:203)
	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351)
	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:280)
	at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:396)
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:248)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:129)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:651)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:574)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:488)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:450)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873)
	at java.lang.Thread.run(Thread.java:745)
@mirabout
Copy link

mirabout commented Jun 5, 2017

The 192.168.2.0/24 string does not have a vaild format for an InetAddress.

https://docs.oracle.com/javase/8/docs/api/java/net/InetAddress.html
https://docs.oracle.com/javase/8/docs/api/java/net/Inet4Address.html#format

Its really represents not a single InetAddress but some tuple like (InetAddress, subnet mask length).
You might try selecting the address bits itself and the mask as two separate columns and expect these columns in a result set.

@emanresusername
Copy link
Author

yeah, i guess i should rephrase the title there to clarify i'm mean the format for the inet postgres keyword as opposed to the java InetAddress

@emanresusername emanresusername changed the title Add (or document) way to handle inet addresses in CIDR notation Add (or document) way to handle the postgres inet and/or cidr data types Jun 5, 2017
@mirabout
Copy link

mirabout commented Jun 5, 2017

From https://www.postgresql.org/docs/9.3/static/datatype-net-types.html

Tip: If you do not like the output format for inet or cidr values, try the functions host, text, and abbrev

I suggest selecting the host bits and the subnet mask as two separate columns (not sure how it should be done in your ORM though)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants