use of com.google.spanner.v1.ResultSet in project beam by apache.
the class SpannerChangeStreamErrorTest method mockTableExists.
private void mockTableExists() {
Statement tableExistsStatement = Statement.of("SELECT t.table_name FROM information_schema.tables AS t WHERE t.table_catalog = '' AND t.table_schema = '' AND t.table_name = 'my-metadata-table'");
ResultSetMetadata tableExistsResultSetMetadata = ResultSetMetadata.newBuilder().setRowType(StructType.newBuilder().addFields(Field.newBuilder().setName("table_name").setType(Type.newBuilder().setCode(TypeCode.STRING).build()).build()).build()).build();
ResultSet tableExistsResultSet = ResultSet.newBuilder().addRows(ListValue.newBuilder().addValues(Value.newBuilder().setStringValue(TEST_TABLE).build()).build()).setMetadata(tableExistsResultSetMetadata).build();
mockSpannerService.putStatementResult(StatementResult.query(tableExistsStatement, tableExistsResultSet));
}
use of com.google.spanner.v1.ResultSet in project beam by apache.
the class SpannerChangeStreamErrorTest method mockGetParentPartition.
private ResultSet mockGetParentPartition(Timestamp now, Timestamp after3Seconds) {
Statement getPartitionStatement = Statement.newBuilder("SELECT * FROM my-metadata-table WHERE PartitionToken = @partition").bind("partition").to("Parent0").build();
ResultSet getPartitionResultSet = ResultSet.newBuilder().addRows(ListValue.newBuilder().addValues(Value.newBuilder().setStringValue("Parent0")).addValues(Value.newBuilder().setListValue(ListValue.newBuilder().build())).addValues(Value.newBuilder().setStringValue(now.toString())).addValues(Value.newBuilder().setStringValue(after3Seconds.toString())).addValues(Value.newBuilder().setStringValue("500")).addValues(Value.newBuilder().setStringValue(State.CREATED.name())).addValues(Value.newBuilder().setStringValue(now.toString())).addValues(Value.newBuilder().setStringValue(now.toString())).addValues(Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build()).addValues(Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build()).addValues(Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build()).build()).setMetadata(PARTITION_METADATA_RESULT_SET_METADATA).build();
mockSpannerService.putStatementResult(StatementResult.query(getPartitionStatement, getPartitionResultSet));
return getPartitionResultSet;
}
use of com.google.spanner.v1.ResultSet in project google-cloud-java by GoogleCloudPlatform.
the class ReadContextSnippets method analyzeQuery.
ResultSetStats analyzeQuery() {
// [START read_context_analyze_query]
ReadContext rc = dbClient.singleUse();
ResultSet resultSet = rc.analyzeQuery(Statement.of("SELECT SingerId, AlbumId, MarketingBudget FROM Albums"), ReadContext.QueryAnalyzeMode.PROFILE);
while (resultSet.next()) {
// Discard the results. We're only processing because getStats() below requires it.
resultSet.getCurrentRowAsStruct();
}
ResultSetStats stats = resultSet.getStats();
// [END read_context_analyze_query]
return stats;
}
use of com.google.spanner.v1.ResultSet in project googleads-java-lib by googleads.
the class PqlTest method testGetColumnLabels.
@Test
public void testGetColumnLabels() {
ResultSet resultSet = new ResultSet();
resultSet.setColumnTypes(new ColumnType[] { column1, column2, column3 });
assertEquals(Lists.newArrayList(new String[] { "column1", "column2", "column3" }), Pql.getColumnLabels(resultSet));
}
use of com.google.spanner.v1.ResultSet in project googleads-java-lib by googleads.
the class PqlTest method testCombineResultSet_badColumns.
@Test
public void testCombineResultSet_badColumns() {
Row row1 = new Row();
row1.setValues(new Value[] { textValue1, booleanValue1, numberValue1 });
Row row2 = new Row();
row2.setValues(new Value[] { textValue2, booleanValue2, numberValue2 });
Row row3 = new Row();
row3.setValues(new Value[] { textValue3, booleanValue3 });
ResultSet resultSet1 = new ResultSet();
resultSet1.setColumnTypes(new ColumnType[] { column1, column2, column3 });
resultSet1.setRows(new Row[] { row1, row2 });
ResultSet resultSet2 = new ResultSet();
resultSet2.setColumnTypes(new ColumnType[] { column1, column2 });
resultSet2.setRows(new Row[] { row3 });
thrown.expect(IllegalArgumentException.class);
Pql.combineResultSets(resultSet1, resultSet2);
}
Aggregations