private List<Map<String, Object>> parseTableResult(final OQLQueryResponse response) { final Table table = response.getTableResult(); final ProtocolStringList fieldNames = table.getFieldNameList(); List<Map<String, Object>> results = new ArrayList<>(); for (BasicTypes.EncodedValueList row : table.getRowList()) { final List<Object> decodedRow = row.getElementList().stream().map(valueEncoder::decodeValue) .collect(Collectors.toList()); Map<String, Object> rowMap = new LinkedHashMap<>(decodedRow.size()); for (int i = 0; i < decodedRow.size(); i++) { rowMap.put(fieldNames.get(i), decodedRow.get(i)); } results.add(rowMap); } return results; }
private void checkResults(final String query, EncodedValue[] bindParameters, String[] fieldnames, final Object[]... rows) throws InvalidExecutionContextException, ConnectionStateException, EncodingException, DecodingException { ProtobufSerializationService serializer = new ProtobufSerializationService(); final Result<OQLQueryResponse> results = invokeHandler(query, bindParameters, serializer); List<BasicTypes.EncodedValueList> expected = new ArrayList<>(); for (Object[] row : rows) { List<EncodedValue> encodedRow = Arrays.asList(row).stream().map(serializer::encode).collect(Collectors.toList()); expected.add(BasicTypes.EncodedValueList.newBuilder().addAllElement(encodedRow).build()); } assertEquals(expected, results.getMessage().getTableResult().getRowList()); assertEquals(Arrays.asList(fieldnames), results.getMessage().getTableResult().getFieldNameList()); }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); switch (resultCase_) { case 1: hash = (37 * hash) + SINGLERESULT_FIELD_NUMBER; hash = (53 * hash) + getSingleResult().hashCode(); break; case 2: hash = (37 * hash) + LISTRESULT_FIELD_NUMBER; hash = (53 * hash) + getListResult().hashCode(); break; case 3: hash = (37 * hash) + TABLERESULT_FIELD_NUMBER; hash = (53 * hash) + getTableResult().hashCode(); break; case 0: default: } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
break; case 3: result = result && getTableResult() .equals(other.getTableResult()); break; case 0:
public Builder mergeFrom(org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse other) { if (other == org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse.getDefaultInstance()) return this; switch (other.getResultCase()) { case SINGLERESULT: { mergeSingleResult(other.getSingleResult()); break; } case LISTRESULT: { mergeListResult(other.getListResult()); break; } case TABLERESULT: { mergeTableResult(other.getTableResult()); break; } case RESULT_NOT_SET: { break; } } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
@Test public void queryForMultipleStructs() throws ConnectionStateException, DecodingException, InvalidExecutionContextException, EncodingException, NameResolutionException, TypeMismatchException, QueryInvocationTargetException, FunctionDomainException { Query query = mock(DefaultQuery.class); when(queryService.newQuery(eq(SELECT_STAR_QUERY))).thenReturn(query); SelectResults results = new LinkedStructSet(); StructTypeImpl elementType = new StructTypeImpl(new String[] {"field1"}); results.setElementType(elementType); results.add(new StructImpl(elementType, new Object[] {STRING_RESULT_1})); results.add(new StructImpl(elementType, new Object[] {STRING_RESULT_2})); when(query.execute((Object[]) any())).thenReturn(results); final OQLQueryRequest request = OQLQueryRequest.newBuilder().setQuery(SELECT_STAR_QUERY).build(); final Result<OQLQueryResponse> result = operationHandler.process(serializationService, request, TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub)); assertEquals( Arrays.asList( BasicTypes.EncodedValueList.newBuilder() .addElement(serializationService.encode(STRING_RESULT_1)).build(), BasicTypes.EncodedValueList.newBuilder() .addElement(serializationService.encode(STRING_RESULT_2)).build()), result.getMessage().getTableResult().getRowList()); }