Skip to content

Commit

Permalink
feat: changes to support data, timestamp and arrays in IT tests (#1840)
Browse files Browse the repository at this point in the history
* changes to support data, timestamp and arrays

* changes to support data, timestamp and arrays

* linting

* changes as per review

* linting

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
asthamohta and gcf-owl-bot[bot] authored Jul 5, 2022
1 parent c8a2184 commit c667653
Show file tree
Hide file tree
Showing 3 changed files with 273 additions and 67 deletions.
Original file line number Diff line number Diff line change
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)),
Type.array(Type.numeric()));
assertThat(row.isNull(0)).isFalse();
assertThat(row.getBigDecimalList(0))
Expand Down
Loading

0 comments on commit c667653

Please sign in to comment.