Search in sources :

Example 46 with ResultSet

use of com.google.spanner.v1.ResultSet in project google-cloud-java by GoogleCloudPlatform.

the class GrpcResultSetTest method profileResultInExtraFinalResultSet.

@Test
public void profileResultInExtraFinalResultSet() {
    Map<String, com.google.protobuf.Value> statsMap = ImmutableMap.of("f1", Value.string("").toProto(), "f2", Value.string("").toProto());
    ResultSetStats stats = ResultSetStats.newBuilder().setQueryPlan(QueryPlan.newBuilder().build()).setQueryStats(com.google.protobuf.Struct.newBuilder().putAllFields(statsMap).build()).build();
    ArrayList<Type.StructField> dataType = new ArrayList<>();
    dataType.add(Type.StructField.of("data", Type.string()));
    consumer.onPartialResultSet(PartialResultSet.newBuilder().setMetadata(makeMetadata(Type.struct(dataType))).addValues(Value.string("d1").toProto()).setChunkedValue(false).build());
    consumer.onPartialResultSet(PartialResultSet.newBuilder().setMetadata(makeMetadata(Type.struct(dataType))).setChunkedValue(false).setStats(stats).build());
    resultSet = resultSetWithMode(QueryMode.PROFILE);
    consumer.onCompleted();
    assertThat(resultSet.next()).isTrue();
    assertThat(resultSet.next()).isFalse();
    ResultSetStats receivedStats = resultSet.getStats();
    assertThat(stats).isEqualTo(receivedStats);
    resultSet.close();
}
Also used : ResultSetStats(com.google.spanner.v1.ResultSetStats) NullValue(com.google.protobuf.NullValue) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 47 with ResultSet

use of com.google.spanner.v1.ResultSet in project google-cloud-java by GoogleCloudPlatform.

the class GrpcResultSetTest method statsNotSupportedError.

@Test
public void statsNotSupportedError() {
    ResultSetStats stats = ResultSetStats.newBuilder().build();
    consumer.onPartialResultSet(PartialResultSet.newBuilder().setMetadata(makeMetadata(Type.struct(new ArrayList<Type.StructField>()))).setChunkedValue(false).setStats(stats).build());
    resultSet = resultSetWithMode(QueryMode.NORMAL);
    consumer.onCompleted();
    expectedException.expect(UnsupportedOperationException.class);
    expectedException.expectMessage("ResultSetStats are available only in PLAN and PROFILE execution modes");
    resultSet.getStats();
}
Also used : ResultSetStats(com.google.spanner.v1.ResultSetStats) Test(org.junit.Test)

Example 48 with ResultSet

use of com.google.spanner.v1.ResultSet in project beam by apache.

the class SpannerChangeStreamErrorTest method mockInvalidChangeStreamRecordReceived.

private void mockInvalidChangeStreamRecordReceived(Timestamp now, Timestamp after3Seconds) {
    Statement changeStreamQueryStatement = Statement.newBuilder("SELECT * FROM READ_my-change-stream(   start_timestamp => @startTimestamp,   end_timestamp => @endTimestamp,   partition_token => @partitionToken,   read_options => null,   heartbeat_milliseconds => @heartbeatMillis)").bind("startTimestamp").to(now).bind("endTimestamp").to(after3Seconds).bind("partitionToken").to((String) null).bind("heartbeatMillis").to(500).build();
    ResultSetMetadata readChangeStreamResultSetMetadata = ResultSetMetadata.newBuilder().setRowType(StructType.newBuilder().addFields(Field.newBuilder().setName("COL1").setType(Type.newBuilder().setCode(TypeCode.ARRAY).setArrayElementType(Type.newBuilder().setCode(TypeCode.STRUCT).setStructType(StructType.newBuilder().addFields(Field.newBuilder().setName("field_name").setType(Type.newBuilder().setCode(TypeCode.STRUCT).setStructType(StructType.newBuilder().addFields(Field.newBuilder().setType(Type.newBuilder().setCode(TypeCode.STRING))))))))))).build();
    ResultSet readChangeStreamResultSet = ResultSet.newBuilder().addRows(ListValue.newBuilder().addValues(Value.newBuilder().setListValue(ListValue.newBuilder().addValues(Value.newBuilder().setListValue(ListValue.newBuilder().addValues(Value.newBuilder().setListValue(ListValue.newBuilder().addValues(Value.newBuilder().setStringValue("bad_value"))))))))).setMetadata(readChangeStreamResultSetMetadata).build();
    mockSpannerService.putStatementResult(StatementResult.query(changeStreamQueryStatement, readChangeStreamResultSet));
}
Also used : Statement(com.google.cloud.spanner.Statement) ResultSetMetadata(com.google.spanner.v1.ResultSetMetadata) ResultSet(com.google.spanner.v1.ResultSet)

Example 49 with ResultSet

use of com.google.spanner.v1.ResultSet in project beam by apache.

the class SpannerChangeStreamErrorTest method testInvalidRecordReceived.

@Test
public void testInvalidRecordReceived() {
    final Timestamp now = Timestamp.now();
    final Timestamp after3Seconds = Timestamp.ofTimeSecondsAndNanos(now.getSeconds() + 3, now.getNanos());
    mockTableExists();
    ResultSet getPartitionResultSet = mockGetParentPartition(now, after3Seconds);
    mockGetWatermark(now);
    mockGetPartitionsAfter(Timestamp.ofTimeSecondsAndNanos(now.getSeconds(), now.getNanos() + 1000), getPartitionResultSet);
    mockGetPartitionsAfter(Timestamp.ofTimeSecondsAndNanos(now.getSeconds(), now.getNanos() - 1000), getPartitionResultSet);
    mockInvalidChangeStreamRecordReceived(now, after3Seconds);
    try {
        pipeline.apply(SpannerIO.readChangeStream().withSpannerConfig(getSpannerConfig()).withChangeStreamName(TEST_CHANGE_STREAM).withMetadataDatabase(TEST_DATABASE).withMetadataTable(TEST_TABLE).withInclusiveStartAt(now).withInclusiveEndAt(after3Seconds));
        pipeline.run().waitUntilFinish();
    } finally {
        thrown.expect(PipelineExecutionException.class);
        thrown.expectMessage("Field not found");
    }
}
Also used : ResultSet(com.google.spanner.v1.ResultSet) Timestamp(com.google.cloud.Timestamp) Test(org.junit.Test)

Example 50 with ResultSet

use of com.google.spanner.v1.ResultSet in project beam by apache.

the class SpannerChangeStreamErrorTest method mockGetWatermark.

private void mockGetWatermark(Timestamp now) {
    Statement watermarkStatement = Statement.newBuilder("SELECT Watermark FROM my-metadata-table WHERE State != @state ORDER BY Watermark ASC LIMIT 1").bind("state").to(State.FINISHED.name()).build();
    ResultSetMetadata watermarkResultSetMetadata = ResultSetMetadata.newBuilder().setRowType(StructType.newBuilder().addFields(Field.newBuilder().setName("Watermark").setType(Type.newBuilder().setCode(TypeCode.TIMESTAMP).build()).build()).build()).build();
    ResultSet watermarkResultSet = ResultSet.newBuilder().addRows(ListValue.newBuilder().addValues(Value.newBuilder().setStringValue(now.toString()).build()).build()).setMetadata(watermarkResultSetMetadata).build();
    mockSpannerService.putStatementResult(StatementResult.query(watermarkStatement, watermarkResultSet));
}
Also used : Statement(com.google.cloud.spanner.Statement) ResultSetMetadata(com.google.spanner.v1.ResultSetMetadata) ResultSet(com.google.spanner.v1.ResultSet)

Aggregations

Test (org.junit.Test)37 ResultSet (com.google.api.ads.admanager.axis.v202108.ResultSet)12 ResultSet (com.google.api.ads.admanager.axis.v202111.ResultSet)12 ResultSet (com.google.api.ads.admanager.axis.v202202.ResultSet)12 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)8 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)8 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)8 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202108.PublisherQueryLanguageServiceInterface)8 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202111.PublisherQueryLanguageServiceInterface)8 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202202.PublisherQueryLanguageServiceInterface)8 Function (com.google.common.base.Function)8 ResultSetStats (com.google.spanner.v1.ResultSetStats)8 Statement (com.google.cloud.spanner.Statement)6 DateTime (org.joda.time.DateTime)6 PartialResultSet (com.google.spanner.v1.PartialResultSet)5 ResultSet (com.google.spanner.v1.ResultSet)5 ResultSet (com.google.api.ads.admanager.axis.v202105.ResultSet)4 Row (com.google.api.ads.admanager.axis.v202108.Row)4 Row (com.google.api.ads.admanager.axis.v202111.Row)4 Row (com.google.api.ads.admanager.axis.v202202.Row)4