Title
#users-public
c

cl

09/01/2022, 3:03 PM
Hi, I am running 6.5.1 jdk8 ILP java client. For Sender class, I need to have a better way to handle null. Some fields in the same object could be null for int, short, or long column. I am looking for a better way dynamically to skip some columns which contain null value.
Andrey Pechkurov

Andrey Pechkurov

09/01/2022, 3:19 PM
Hello
3:20 PM
You could simply skip those columns. The inserted row would get null values for the skipped columns then
c

cl

09/01/2022, 3:21 PM
right, but I need to handle all cases. So, I don't want to rebuild all column call every time.
Andrey Pechkurov

Andrey Pechkurov

09/01/2022, 3:23 PM
if (objectLongValue != null) {
    sender.longColumn("my_long_col", objectLongValue);
}
or something like that
c

cl

09/01/2022, 3:24 PM
will it create multiple row if I check for each column.
Andrey Pechkurov

Andrey Pechkurov

09/01/2022, 3:25 PM
No, it'll be the same row. The row gets "finalized" only when you call at/atNow
c

cl

09/01/2022, 3:26 PM
great. Let me give it a try. Thanks a lot.
4:02 PM
sender.table("connections")
.timestampColumn("ts", Os.currentTimeNanos())
.stringColumn("tenantid", "localhost-08312022")
.longColumn("id", conn.getId())
if (conn.getMachine() != null)
	sender.table("connections").stringColumn("machine", conn.getMachine());
if (conn.getPort() != null)
	sender.table("connections").longColumn("port", conn.getPort());
sender.table("connections").atNow();
4:03 PM
The second null check is trying to append more columns, but it failed with error
4:03 PM
io.questdb.cutlass.line.LineSenderException: duplicated table. call <http://sender.at|sender.at>() or sender.atNow() to finish the current row first
Andrey Pechkurov

Andrey Pechkurov

09/01/2022, 4:16 PM
You should remove extra .table() calls
4:17 PM
sender.table("connections")
.timestampColumn("ts", Os.currentTimeNanos())
.stringColumn("tenantid", "localhost-08312022")
.longColumn("id", conn.getId())
if (conn.getMachine() != null)
	sender.stringColumn("machine", conn.getMachine());
if (conn.getPort() != null)
	sender.longColumn("port", conn.getPort());
sender.atNow();
c

cl

09/01/2022, 4:23 PM
I am able to by-pass exception, but no row in db. I do use sender.flush() right away.
Andrey Pechkurov

Andrey Pechkurov

09/01/2022, 4:24 PM
You should call .flush() for a batch of rows, ideally. This would bring the best performance. But for local testing it's fine to call it on each row individually
4:25 PM
As for the inserted rows becoming visible with a delay, we have a concept of "commit lag". Please check this doc page:https://questdb.io/docs/guides/out-of-order-commit-lag
c

cl

09/01/2022, 4:26 PM
ok, but row does not create in questdb.
Andrey Pechkurov

Andrey Pechkurov

09/01/2022, 4:27 PM
That's because you need to call .flush().
c

cl

09/01/2022, 4:30 PM
yes, I did after I set atNow().
5:03 PM
Thanks Andrey. I have a bug in my code. It works now.