Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jdbc-postgres): void types from query are converted to null #135

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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