Search in sources :

Example 6 with ResultSet

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));
}
Also used : Statement(com.google.cloud.spanner.Statement) ResultSetMetadata(com.google.spanner.v1.ResultSetMetadata) ResultSet(com.google.spanner.v1.ResultSet)

Example 7 with ResultSet

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;
}
Also used : Statement(com.google.cloud.spanner.Statement) ResultSet(com.google.spanner.v1.ResultSet)

Example 8 with ResultSet

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;
}
Also used : ResultSetStats(com.google.spanner.v1.ResultSetStats) ReadContext(com.google.cloud.spanner.ReadContext) ResultSet(com.google.cloud.spanner.ResultSet)

Example 9 with ResultSet

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));
}
Also used : ResultSet(com.google.api.ads.admanager.axis.v202202.ResultSet) Test(org.junit.Test)

Example 10 with 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);
}
Also used : ResultSet(com.google.api.ads.admanager.axis.v202202.ResultSet) Row(com.google.api.ads.admanager.axis.v202202.Row) Test(org.junit.Test)

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