use of org.apache.beam.sdk.io.gcp.spanner.changestreams.model.ColumnType in project beam by apache.
the class ChangeStreamRecordMapperTest method testMappingInsertStructRowToDataChangeRecord.
@Test
public void testMappingInsertStructRowToDataChangeRecord() {
final DataChangeRecord dataChangeRecord = new DataChangeRecord("partitionToken", Timestamp.ofTimeSecondsAndNanos(10L, 20), "transactionId", false, "1", "tableName", Arrays.asList(new ColumnType("column1", new TypeCode("type1"), true, 1L), new ColumnType("column2", new TypeCode("type2"), false, 2L)), Collections.singletonList(new Mod("{\"column1\": \"value1\"}", null, "{\"column2\": \"newValue2\"}")), ModType.INSERT, ValueCaptureType.OLD_AND_NEW_VALUES, 10L, 2L, null);
final Struct stringFieldsStruct = recordsToStructWithStrings(dataChangeRecord);
final Struct jsonFieldsStruct = recordsToStructWithJson(dataChangeRecord);
assertEquals(Collections.singletonList(dataChangeRecord), mapper.toChangeStreamRecords(partition, stringFieldsStruct, resultSetMetadata));
assertEquals(Collections.singletonList(dataChangeRecord), mapper.toChangeStreamRecords(partition, jsonFieldsStruct, resultSetMetadata));
}
use of org.apache.beam.sdk.io.gcp.spanner.changestreams.model.ColumnType in project beam by apache.
the class ChangeStreamRecordMapperTest method testMappingDeleteStructRowToDataChangeRecord.
@Test
public void testMappingDeleteStructRowToDataChangeRecord() {
final DataChangeRecord dataChangeRecord = new DataChangeRecord("partitionToken", Timestamp.ofTimeSecondsAndNanos(10L, 20), "transactionId", false, "1", "tableName", Arrays.asList(new ColumnType("column1", new TypeCode("type1"), true, 1L), new ColumnType("column2", new TypeCode("type2"), false, 2L)), Collections.singletonList(new Mod("{\"column1\": \"value1\"}", "{\"column2\": \"oldValue2\"}", null)), ModType.DELETE, ValueCaptureType.OLD_AND_NEW_VALUES, 10L, 2L, null);
final Struct stringFieldsStruct = recordsToStructWithStrings(dataChangeRecord);
final Struct jsonFieldsStruct = recordsToStructWithJson(dataChangeRecord);
assertEquals(Collections.singletonList(dataChangeRecord), mapper.toChangeStreamRecords(partition, stringFieldsStruct, resultSetMetadata));
assertEquals(Collections.singletonList(dataChangeRecord), mapper.toChangeStreamRecords(partition, jsonFieldsStruct, resultSetMetadata));
}
use of org.apache.beam.sdk.io.gcp.spanner.changestreams.model.ColumnType in project beam by apache.
the class ChangeStreamRecordMapperTest method testMappingUpdateStructRowToDataChangeRecord.
@Test
public void testMappingUpdateStructRowToDataChangeRecord() {
final DataChangeRecord dataChangeRecord = new DataChangeRecord("partitionToken", Timestamp.ofTimeSecondsAndNanos(10L, 20), "serverTransactionId", true, "1", "tableName", Arrays.asList(new ColumnType("column1", new TypeCode("type1"), true, 1L), new ColumnType("column2", new TypeCode("type2"), false, 2L)), Collections.singletonList(new Mod("{\"column1\": \"value1\"}", "{\"column2\": \"oldValue2\"}", "{\"column2\": \"newValue2\"}")), ModType.UPDATE, ValueCaptureType.OLD_AND_NEW_VALUES, 10L, 2L, null);
final Struct stringFieldsStruct = recordsToStructWithStrings(dataChangeRecord);
final Struct jsonFieldsStruct = recordsToStructWithJson(dataChangeRecord);
assertEquals(Collections.singletonList(dataChangeRecord), mapper.toChangeStreamRecords(partition, stringFieldsStruct, resultSetMetadata));
assertEquals(Collections.singletonList(dataChangeRecord), mapper.toChangeStreamRecords(partition, jsonFieldsStruct, resultSetMetadata));
}
Aggregations