Skip to content

Commit

Permalink
fix(jdbc-postgres): void types from query are converted to null
Browse files Browse the repository at this point in the history
closes #130
  • Loading branch information
brian-mulier-p committed Jun 26, 2023
1 parent 361e3b4 commit 2e25908
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public Object convertCell(int columnIndex, ResultSet rs, Connection connection)
switch (type.toLowerCase()) {
case "json":
return o.getValue();
case "void":
return null;
default:
throw new IllegalArgumentException("PGobject of type [" + type + "] is not supported");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package io.kestra.plugin.jdbc.postgresql;

import com.google.common.collect.ImmutableMap;
import io.kestra.core.exceptions.IllegalVariableEvaluationException;
import io.micronaut.context.ApplicationContext;
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import org.junit.jupiter.api.Test;
import io.kestra.core.models.executions.Execution;
import io.kestra.core.models.flows.State;
import io.kestra.core.runners.RunContext;
import io.kestra.plugin.jdbc.AbstractJdbcQuery;
import io.kestra.plugin.jdbc.AbstractRdbmsTest;
import io.micronaut.context.ApplicationContext;
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import jakarta.inject.Inject;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import org.junit.jupiter.api.Test;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.net.URISyntaxException;
Expand All @@ -26,8 +25,6 @@
import java.util.Map;
import java.util.Properties;

import jakarta.inject.Inject;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -64,6 +61,29 @@ void selectAndFetchOne() throws Exception {
checkRow(runOutput.getRow(), 1);
}

@Test
void selectWithVoidObject() throws Exception {
RunContext runContext = runContextFactory.of(ImmutableMap.of());

Query task = Query.builder()
.url(TestUtils.url())
.username(TestUtils.username())
.password(TestUtils.password())
.ssl(TestUtils.ssl())
.sslMode(TestUtils.sslMode())
.sslRootCert(TestUtils.ca())
.sslCert(TestUtils.cert())
.sslKey(TestUtils.keyNoPass())
.fetchOne(true)
.sql("SELECT 'someString' as stringvalue, pg_sleep(0) as voidvalue")
.build();

AbstractJdbcQuery.Output runOutput = task.run(runContext);
assertThat(runOutput.getRow(), notNullValue());
assertThat(runOutput.getRow().get("voidvalue"), nullValue());
assertThat(runOutput.getRow().get("stringvalue"), is("someString"));
}

private void checkRow(Map<String, Object> row, int concertId) throws DecoderException {
assertThat(row.get("concert_id"), is(concertId));
// May be boolean
Expand Down

0 comments on commit 2e25908

Please sign in to comment.