Search in sources :

Example 56 with ResultSet

use of org.apache.cassandra.cql3.ResultSet in project cassandra by apache.

the class DescribeStatement method executeLocally.

@Override
public ResultMessage executeLocally(QueryState state, QueryOptions options) {
    Keyspaces keyspaces = Schema.instance.snapshot();
    UUID schemaVersion = Schema.instance.getVersion();
    keyspaces = Keyspaces.builder().add(keyspaces).add(VirtualKeyspaceRegistry.instance.virtualKeyspacesMetadata()).build();
    PagingState pagingState = options.getPagingState();
    // The paging implemented here uses some arbitray row number as the partition-key for paging,
    // which is used to skip/limit the result from the Java Stream. This works good enough for
    // reasonably sized schemas. Even a 'DESCRIBE SCHEMA' for an abnormally schema with 10000 tables
    // completes within a few seconds. This seems good enough for now. Once Cassandra actually supports
    // more than a few hundred tables, the implementation here should be reconsidered.
    // 
    // Paging is only supported on row-level.
    // 
    // The "partition key" in the paging-state contains a serialized object:
    // (short) version, currently 0x0001
    // (long) row offset
    // (vint bytes) serialized schema hash (currently the result of Keyspaces.hashCode())
    // 
    long offset = getOffset(pagingState, schemaVersion);
    int pageSize = options.getPageSize();
    Stream<? extends T> stream = describe(state.getClientState(), keyspaces);
    if (offset > 0L)
        stream = stream.skip(offset);
    if (pageSize > 0)
        stream = stream.limit(pageSize);
    List<List<ByteBuffer>> rows = stream.map(e -> toRow(e, includeInternalDetails)).collect(Collectors.toList());
    ResultSet.ResultMetadata resultMetadata = new ResultSet.ResultMetadata(metadata(state.getClientState()));
    ResultSet result = new ResultSet(resultMetadata, rows);
    if (pageSize > 0 && rows.size() == pageSize) {
        result.metadata.setHasMorePages(getPagingState(offset + pageSize, schemaVersion));
    }
    return new ResultMessage.Rows(result);
}
Also used : AuditLogContext(org.apache.cassandra.audit.AuditLogContext) java.util(java.util) RequestValidations.invalidRequest(org.apache.cassandra.cql3.statements.RequestValidations.invalidRequest) DataOutputBuffer(org.apache.cassandra.io.util.DataOutputBuffer) RequestValidations.checkNotEmpty(org.apache.cassandra.cql3.statements.RequestValidations.checkNotEmpty) BiFunction(java.util.function.BiFunction) ByteBufferUtil.bytes(org.apache.cassandra.utils.ByteBufferUtil.bytes) ByteBuffer(java.nio.ByteBuffer) org.apache.cassandra.cql3(org.apache.cassandra.cql3) RequestExecutionException(org.apache.cassandra.exceptions.RequestExecutionException) ListType(org.apache.cassandra.db.marshal.ListType) UTF8Type(org.apache.cassandra.db.marshal.UTF8Type) ImmutableList(com.google.common.collect.ImmutableList) KeyspaceNotDefinedException(org.apache.cassandra.db.KeyspaceNotDefinedException) FunctionName(org.apache.cassandra.cql3.functions.FunctionName) RequestValidations.checkNotNull(org.apache.cassandra.cql3.statements.RequestValidations.checkNotNull) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) RequestValidationException(org.apache.cassandra.exceptions.RequestValidationException) ResultMessage(org.apache.cassandra.transport.messages.ResultMessage) FBUtilities(org.apache.cassandra.utils.FBUtilities) QueryState(org.apache.cassandra.service.QueryState) ByteBufferUtil(org.apache.cassandra.utils.ByteBufferUtil) RequestValidations.checkTrue(org.apache.cassandra.cql3.statements.RequestValidations.checkTrue) ClientState(org.apache.cassandra.service.ClientState) StorageService(org.apache.cassandra.service.StorageService) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) UUIDGen(org.apache.cassandra.utils.UUIDGen) String.format(java.lang.String.format) AuditLogEntryType(org.apache.cassandra.audit.AuditLogEntryType) MapType(org.apache.cassandra.db.marshal.MapType) Stream(java.util.stream.Stream) PagingState(org.apache.cassandra.service.pager.PagingState) VirtualKeyspaceRegistry(org.apache.cassandra.db.virtual.VirtualKeyspaceRegistry) org.apache.cassandra.schema(org.apache.cassandra.schema) DataInputBuffer(org.apache.cassandra.io.util.DataInputBuffer) PagingState(org.apache.cassandra.service.pager.PagingState) ImmutableList(com.google.common.collect.ImmutableList)

Example 57 with ResultSet

use of org.apache.cassandra.cql3.ResultSet in project cassandra by apache.

the class ListUsersStatement method formatResults.

@Override
protected ResultMessage formatResults(List<RoleResource> sortedRoles) {
    ResultSet.ResultMetadata resultMetadata = new ResultSet.ResultMetadata(metadata);
    ResultSet result = new ResultSet(resultMetadata);
    IRoleManager roleManager = DatabaseDescriptor.getRoleManager();
    INetworkAuthorizer networkAuthorizer = DatabaseDescriptor.getNetworkAuthorizer();
    for (RoleResource role : sortedRoles) {
        if (!roleManager.canLogin(role))
            continue;
        result.addColumnValue(UTF8Type.instance.decompose(role.getRoleName()));
        result.addColumnValue(BooleanType.instance.decompose(Roles.hasSuperuserStatus(role)));
        result.addColumnValue(UTF8Type.instance.decompose(networkAuthorizer.authorize(role).toString()));
    }
    return new ResultMessage.Rows(result);
}
Also used : ResultSet(org.apache.cassandra.cql3.ResultSet)

Example 58 with ResultSet

use of org.apache.cassandra.cql3.ResultSet in project googleads-java-lib by googleads.

the class PqlTest method testCombineResultSet.

@Test
public void testCombineResultSet() {
    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, numberValue3 });
    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, column3 });
    resultSet2.setRows(new Row[] { row3 });
    ResultSet combinedResultSet = Pql.combineResultSets(resultSet1, resultSet2);
    assertEquals(3, combinedResultSet.getRows().length);
    assertArrayEquals(new ColumnType[] { column1, column2, column3 }, combinedResultSet.getColumnTypes());
    assertArrayEquals(new Value[] { textValue1, booleanValue1, numberValue1 }, combinedResultSet.getRows()[0].getValues());
    assertArrayEquals(new Value[] { textValue2, booleanValue2, numberValue2 }, combinedResultSet.getRows()[1].getValues());
    assertArrayEquals(new Value[] { textValue3, booleanValue3, numberValue3 }, combinedResultSet.getRows()[2].getValues());
}
Also used : ResultSet(com.google.api.ads.admanager.axis.v202105.ResultSet) Row(com.google.api.ads.admanager.axis.v202105.Row) Test(org.junit.Test)

Example 59 with ResultSet

use of org.apache.cassandra.cql3.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.v202105.ResultSet) Row(com.google.api.ads.admanager.axis.v202105.Row) Test(org.junit.Test)

Example 60 with ResultSet

use of org.apache.cassandra.cql3.ResultSet in project googleads-java-lib by googleads.

the class PqlTest method testCombineResultSet.

@Test
public void testCombineResultSet() {
    Row row1 = new Row();
    row1.getValues().addAll(Lists.newArrayList(textValue1, booleanValue1, numberValue1));
    Row row2 = new Row();
    row2.getValues().addAll(Lists.newArrayList(textValue2, booleanValue2, numberValue2));
    Row row3 = new Row();
    row3.getValues().addAll(Lists.newArrayList(textValue3, booleanValue3, numberValue3));
    ResultSet resultSet1 = new ResultSet();
    resultSet1.getColumnTypes().addAll(Lists.newArrayList(column1, column2, column3));
    resultSet1.getRows().addAll(Lists.newArrayList(row1, row2));
    ResultSet resultSet2 = new ResultSet();
    resultSet2.getColumnTypes().addAll(Lists.newArrayList(column1, column2, column3));
    resultSet2.getRows().addAll(Lists.newArrayList(row3));
    ResultSet combinedResultSet = Pql.combineResultSets(resultSet1, resultSet2);
    assertEquals(3, combinedResultSet.getRows().size());
    assertEquals(Lists.newArrayList(column1, column2, column3), combinedResultSet.getColumnTypes());
    assertEquals(Lists.newArrayList(textValue1, booleanValue1, numberValue1), combinedResultSet.getRows().get(0).getValues());
    assertEquals(Lists.newArrayList(textValue2, booleanValue2, numberValue2), combinedResultSet.getRows().get(1).getValues());
    assertEquals(Lists.newArrayList(textValue3, booleanValue3, numberValue3), combinedResultSet.getRows().get(2).getValues());
}
Also used : ResultSet(com.google.api.ads.admanager.jaxws.v202105.ResultSet) Row(com.google.api.ads.admanager.jaxws.v202105.Row) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)32 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 UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)9 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 DateTime (org.joda.time.DateTime)6 ResultSet (com.google.spanner.v1.ResultSet)5 ResultSet (com.datastax.driver.core.ResultSet)4 Session (com.datastax.driver.core.Session)4 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