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; }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.Table)) { return super.equals(obj); } org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.Table other = (org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.Table) obj; boolean result = true; result = result && getFieldNameList() .equals(other.getFieldNameList()); result = result && getRowList() .equals(other.getRowList()); result = result && unknownFields.equals(other.unknownFields); return result; }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); if (getFieldNameCount() > 0) { hash = (37 * hash) + FIELDNAME_FIELD_NUMBER; hash = (53 * hash) + getFieldNameList().hashCode(); } if (getRowCount() > 0) { hash = (37 * hash) + ROW_FIELD_NUMBER; hash = (53 * hash) + getRowList().hashCode(); } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
@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()); }
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()); }