Skip to content

Commit fa3c0e2

Browse files
committed
PLUGIN-296 Add integration test for SpannerSource getSchema from ImportQuery
1 parent 3e771a7 commit fa3c0e2

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

integration-test-remote/src/test/java/io/cdap/cdap/app/etl/gcp/GoogleCloudSpannerTest.java

+19-5
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@ public class GoogleCloudSpannerTest extends DataprocETLTestBase {
125125
"schema",
126126
Schema.Field.of("ID", Schema.nullableOf(Schema.of(Schema.Type.LONG))),
127127
Schema.Field.of("StringCol", Schema.nullableOf(Schema.of(Schema.Type.STRING))),
128-
Schema.Field.of("BOOL_COL", Schema.nullableOf(Schema.of(Schema.Type.BOOLEAN)))
128+
Schema.Field.of("BoolCol", Schema.nullableOf(Schema.of(Schema.Type.BOOLEAN))),
129+
Schema.Field.of("TimestampCol", Schema.nullableOf(Schema.of(Schema.LogicalType.TIMESTAMP_MICROS))),
130+
Schema.Field.of("ArrayIntCol", Schema.arrayOf(Schema.nullableOf(Schema.of(Schema.Type.LONG)))),
131+
Schema.Field.of("BytesCol", Schema.nullableOf(Schema.of(Schema.Type.BYTES))),
132+
Schema.Field.of("DateCol", Schema.nullableOf(Schema.of(Schema.LogicalType.DATE)))
129133
);
130134

131135
private static final ZonedDateTime NOW = ZonedDateTime.now();
@@ -168,6 +172,10 @@ public class GoogleCloudSpannerTest extends DataprocETLTestBase {
168172
.set("ID").to(3)
169173
.set("STRING_COL").to("some string")
170174
.set("BOOL_COL").to(false)
175+
.set("TIMESTAMP_COL").to(Timestamp.ofTimeSecondsAndNanos(NOW.toEpochSecond(), NOW.getNano()))
176+
.set("ARRAY_INT_COL").toInt64Array(Arrays.asList(1L, 2L, null))
177+
.set("BYTES_COL").to(ByteArray.copyFrom("some value".getBytes()))
178+
.set("DATE_COL").to(Date.fromYearMonthDay(NOW.getYear(), NOW.getMonthValue(), NOW.getDayOfMonth()))
171179
.build()
172180
);
173181

@@ -331,7 +339,7 @@ private void testReadWithImportQuery(Engine engine) throws Exception {
331339
.put("instance", "${instance}")
332340
.put("database", "${database}")
333341
.put("table", "${srcTable}")
334-
.put("importQuery","Select ID, STRING_COL as StringCol, BOOL_COL from " + SOURCE_TABLE_NAME)
342+
.put("importQuery","${importQuery}")
335343
.build();
336344

337345
Map<String, String> sinkProperties = new ImmutableMap.Builder<String, String>()
@@ -340,7 +348,6 @@ private void testReadWithImportQuery(Engine engine) throws Exception {
340348
.put("instance", "${instance}")
341349
.put("database", "${database}")
342350
.put("table", "${dstTable}")
343-
.put("serviceAccountType", "JSON")
344351
.put("schema", IMPORT_SCHEMA.toString())
345352
.put("keys", "${keys}")
346353
.build();
@@ -356,6 +363,8 @@ private void testReadWithImportQuery(Engine engine) throws Exception {
356363
args.put("srcTable", SOURCE_TABLE_NAME);
357364
args.put("dstTable", nonExistentSinkTableName);
358365
args.put("keys", "ID");
366+
args.put("importQuery","Select ID, STRING_COL as StringCol, BOOL_COL as BoolCol, TIMESTAMP_COL as TimestampCol, " +
367+
"ARRAY_INT_COL as ArrayIntCol, BYTES_COL as BytesCol, DATE_COL as DateCol from " + SOURCE_TABLE_NAME);
359368
startWorkFlow(applicationManager, ProgramRunStatus.COMPLETED, args);
360369

361370
ResultSet resultSet = spanner.getDatabaseClient(database.getId())
@@ -372,10 +381,15 @@ private void testReadWithImportQuery(Engine engine) throws Exception {
372381
Assert.assertEquals(secondRowExpected.keySet().size(), resultSet.getColumnCount());
373382
Assert.assertEquals(secondRowExpected.get("ID").getInt64(), resultSet.getLong("ID"));
374383
Assert.assertEquals(secondRowExpected.get("STRING_COL").getString(), resultSet.getString("StringCol"));
375-
Assert.assertEquals(secondRowExpected.get("BOOL_COL").getBool(), resultSet.getBoolean("BOOL_COL"));
384+
Assert.assertEquals(secondRowExpected.get("BOOL_COL").getBool(), resultSet.getBoolean("BoolCol"));
385+
Assert.assertEquals(secondRowExpected.get("TIMESTAMP_COL").getTimestamp(), resultSet.getTimestamp("TimestampCol"));
386+
Assert.assertEquals(secondRowExpected.get("ARRAY_INT_COL").getInt64Array(), resultSet.getLongList("ArrayIntCol"));
387+
Assert.assertEquals(secondRowExpected.get("BYTES_COL").getBytes(), resultSet.getBytes("BytesCol"));
388+
Assert.assertEquals(secondRowExpected.get("DATE_COL").getDate(), resultSet.getDate("DateCol"));
389+
spanner.getDatabaseClient(database.getId()).singleUse()
390+
.executeQuery(Statement.of(String.format("drop table %s;", nonExistentSinkTableName)));
376391
}
377392

378-
379393
//TODO:(CDAP-16040) re-enable once plugin is fixed
380394
//@Test
381395
public void testReadAndStoreInNewTableWithNoSourceSchema() throws Exception {

0 commit comments

Comments
 (0)