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

feat: changes to support data, timestamp and arrays in IT tests #1840

Merged
merged 8 commits into from Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -24,6 +24,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;

import com.google.cloud.ByteArray;
import com.google.cloud.Date;
Expand Down Expand Up @@ -355,7 +356,6 @@ public void bindTimestampNull() {

@Test
public void bindDate() {
assumeFalse("date type is not supported on POSTGRESQL", dialect.dialect == Dialect.POSTGRESQL);
Date d = Date.parseDate("2016-09-18");
Struct row = execute(Statement.newBuilder(selectValueQuery).bind("p1").to(d), Type.date());
assertThat(row.isNull(0)).isFalse();
Expand All @@ -364,7 +364,6 @@ public void bindDate() {

@Test
public void bindDateNull() {
assumeFalse("date type is not supported on POSTGRESQL", dialect.dialect == Dialect.POSTGRESQL);
Struct row =
execute(Statement.newBuilder(selectValueQuery).bind("p1").to((Date) null), Type.date());
assertThat(row.isNull(0)).isTrue();
Expand Down Expand Up @@ -682,43 +681,39 @@ public void bindTimestampArrayNull() {

@Test
public void bindDateArray() {
assumeFalse("date type is not supported on POSTGRESQL", dialect.dialect == Dialect.POSTGRESQL);
Date d1 = Date.parseDate("2016-09-18");
Date d2 = Date.parseDate("2016-09-19");

Struct row =
execute(
Statement.newBuilder("SELECT @v").bind("v").toDateArray(asList(d1, d2, null)),
Statement.newBuilder(selectValueQuery).bind("p1").toDateArray(asList(d1, d2, null)),
Type.array(Type.date()));
assertThat(row.isNull(0)).isFalse();
assertThat(row.getDateList(0)).containsExactly(d1, d2, null).inOrder();
}

@Test
public void bindDateArrayEmpty() {
assumeFalse("date type is not supported on POSTGRESQL", dialect.dialect == Dialect.POSTGRESQL);
Struct row =
execute(
Statement.newBuilder("SELECT @v").bind("v").toDateArray(Collections.emptyList()),
Statement.newBuilder(selectValueQuery).bind("p1").toDateArray(Collections.emptyList()),
Type.array(Type.date()));
assertThat(row.isNull(0)).isFalse();
assertThat(row.getDateList(0)).containsExactly();
}

@Test
public void bindDateArrayNull() {
assumeFalse("date type is not supported on POSTGRESQL", dialect.dialect == Dialect.POSTGRESQL);
Struct row =
execute(
Statement.newBuilder("SELECT @v").bind("v").toDateArray(null), Type.array(Type.date()));
Statement.newBuilder(selectValueQuery).bind("p1").toDateArray(null),
Type.array(Type.date()));
assertThat(row.isNull(0)).isTrue();
}

@Test
public void bindNumericArray() {
assumeFalse(
"array numeric binding is not supported on POSTGRESQL",
dialect.dialect == Dialect.POSTGRESQL);
public void bindNumericArrayGoogleStandardSQL() {
assumeTrue(dialect.dialect == Dialect.GOOGLE_STANDARD_SQL);
assumeFalse("Emulator does not yet support NUMERIC", EmulatorSpannerHelper.isUsingEmulator());
BigDecimal b1 = new BigDecimal("3.14");
BigDecimal b2 = new BigDecimal("6.626");
Expand All @@ -732,10 +727,22 @@ public void bindNumericArray() {
}

@Test
public void bindNumericArrayEmpty() {
assumeFalse(
"array numeric binding is not supported on POSTGRESQL",
dialect.dialect == Dialect.POSTGRESQL);
public void bindNumericArrayPostgreSQL() {
assumeTrue(dialect.dialect == Dialect.POSTGRESQL);
assumeFalse("Emulator does not yet support NUMERIC", EmulatorSpannerHelper.isUsingEmulator());
Struct row =
execute(
Statement.newBuilder(selectValueQuery)
.bind("p1")
.toPgNumericArray(asList("3.14", "6.626", null)),
Type.array(Type.pgNumeric()));
assertThat(row.isNull(0)).isFalse();
assertThat(row.getStringList(0)).containsExactly("3.14", "6.626", null).inOrder();
}

@Test
public void bindNumericArrayEmptyGoogleStandardSQL() {
assumeTrue(dialect.dialect == Dialect.GOOGLE_STANDARD_SQL);
assumeFalse("Emulator does not yet support NUMERIC", EmulatorSpannerHelper.isUsingEmulator());
Struct row =
execute(
Expand All @@ -748,18 +755,39 @@ public void bindNumericArrayEmpty() {
}

@Test
public void bindNumericArrayNull() {
assumeFalse(
"array numeric binding is not supported on POSTGRESQL",
dialect.dialect == Dialect.POSTGRESQL);
public void bindNumericArrayEmptyPostgreSQL() {
assumeTrue(dialect.dialect == Dialect.POSTGRESQL);
assumeFalse("Emulator does not yet support NUMERIC", EmulatorSpannerHelper.isUsingEmulator());
Struct row =
execute(
Statement.newBuilder(selectValueQuery)
.bind("p1")
.toPgNumericArray(Collections.emptyList()),
Type.array(Type.pgNumeric()));
assertThat(row.isNull(0)).isFalse();
assertThat(row.getStringList(0)).containsExactly();
}

@Test
public void bindNumericArrayNullGoogleStandardSQL() {
assumeTrue(dialect.dialect == Dialect.GOOGLE_STANDARD_SQL);
Struct row =
execute(
Statement.newBuilder(selectValueQuery).bind("p1").toNumericArray(null),
Type.array(Type.numeric()));
assertThat(row.isNull(0)).isTrue();
}

@Test
public void bindNumericArrayNullPostgreSQL() {
assumeTrue(dialect.dialect == Dialect.POSTGRESQL);
Struct row =
execute(
Statement.newBuilder(selectValueQuery).bind("p1").toPgNumericArray(null),
Type.array(Type.pgNumeric()));
assertThat(row.isNull(0)).isTrue();
}

@Test
public void bindNumericArray_doesNotPreservePrecision() {
assumeFalse(
Expand All @@ -771,7 +799,7 @@ public void bindNumericArray_doesNotPreservePrecision() {

Struct row =
execute(
Statement.newBuilder("SELECT @v").bind("v").toNumericArray(asList(b1, b2, null)),
Statement.newBuilder(selectValueQuery).bind("p1").toNumericArray(asList(b1, b2, null)),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case seem to be disabled for PostgreSQL still. Is that intentional?
The same also seems to be the case for other numeric array tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed those, adding it

Type.array(Type.numeric()));
assertThat(row.isNull(0)).isFalse();
assertThat(row.getBigDecimalList(0))
Expand Down