Search in sources :

Example 1 with TypeCode

use of org.apache.beam.sdk.io.gcp.spanner.changestreams.model.TypeCode 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));
}
Also used : ColumnType(org.apache.beam.sdk.io.gcp.spanner.changestreams.model.ColumnType) Mod(org.apache.beam.sdk.io.gcp.spanner.changestreams.model.Mod) TypeCode(org.apache.beam.sdk.io.gcp.spanner.changestreams.model.TypeCode) DataChangeRecord(org.apache.beam.sdk.io.gcp.spanner.changestreams.model.DataChangeRecord) Struct(com.google.cloud.spanner.Struct) Test(org.junit.Test)

Example 2 with TypeCode

use of org.apache.beam.sdk.io.gcp.spanner.changestreams.model.TypeCode 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));
}
Also used : ColumnType(org.apache.beam.sdk.io.gcp.spanner.changestreams.model.ColumnType) Mod(org.apache.beam.sdk.io.gcp.spanner.changestreams.model.Mod) TypeCode(org.apache.beam.sdk.io.gcp.spanner.changestreams.model.TypeCode) DataChangeRecord(org.apache.beam.sdk.io.gcp.spanner.changestreams.model.DataChangeRecord) Struct(com.google.cloud.spanner.Struct) Test(org.junit.Test)

Example 3 with TypeCode

use of org.apache.beam.sdk.io.gcp.spanner.changestreams.model.TypeCode 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));
}
Also used : ColumnType(org.apache.beam.sdk.io.gcp.spanner.changestreams.model.ColumnType) Mod(org.apache.beam.sdk.io.gcp.spanner.changestreams.model.Mod) TypeCode(org.apache.beam.sdk.io.gcp.spanner.changestreams.model.TypeCode) DataChangeRecord(org.apache.beam.sdk.io.gcp.spanner.changestreams.model.DataChangeRecord) Struct(com.google.cloud.spanner.Struct) Test(org.junit.Test)

Aggregations

Struct (com.google.cloud.spanner.Struct)3 ColumnType (org.apache.beam.sdk.io.gcp.spanner.changestreams.model.ColumnType)3 DataChangeRecord (org.apache.beam.sdk.io.gcp.spanner.changestreams.model.DataChangeRecord)3 Mod (org.apache.beam.sdk.io.gcp.spanner.changestreams.model.Mod)3 TypeCode (org.apache.beam.sdk.io.gcp.spanner.changestreams.model.TypeCode)3 Test (org.junit.Test)3