use of org.apache.calcite.avatica.Meta.Frame in project calcite-avatica by apache.
the class ProtobufHandlerTest method testFetch.
@Test
public void testFetch() throws Exception {
final String connectionId = "cnxn1";
final int statementId = 30;
final long offset = 10;
final int fetchMaxRowCount = 100;
final List<Common.TypedValue> values = new ArrayList<>();
values.add(Common.TypedValue.newBuilder().setType(Common.Rep.BOOLEAN).setBoolValue(true).build());
values.add(Common.TypedValue.newBuilder().setType(Common.Rep.STRING).setStringValue("my_string").build());
Requests.FetchRequest protoRequest = Requests.FetchRequest.newBuilder().setConnectionId(connectionId).setStatementId(statementId).setOffset(offset).setFetchMaxRowCount(fetchMaxRowCount).build();
byte[] serializedRequest = protoRequest.toByteArray();
FetchRequest request = new FetchRequest().deserialize(protoRequest);
List<Object> frameRows = new ArrayList<>();
frameRows.add(new Object[] { true, "my_string" });
Meta.Frame frame = Frame.create(0, true, frameRows);
RpcMetadataResponse metadata = new RpcMetadataResponse("localhost:8765");
FetchResponse response = new FetchResponse(frame, false, false, metadata);
when(translation.parseRequest(serializedRequest)).thenReturn(request);
when(service.apply(request)).thenReturn(response);
when(translation.serializeResponse(response)).thenReturn(response.serialize().toByteArray());
HandlerResponse<byte[]> handlerResponse = handler.apply(serializedRequest);
byte[] serializedResponse = handlerResponse.getResponse();
assertEquals(200, handlerResponse.getStatusCode());
Responses.FetchResponse protoResponse = Responses.FetchResponse.parseFrom(serializedResponse);
Common.Frame protoFrame = protoResponse.getFrame();
assertEquals(frame.offset, protoFrame.getOffset());
assertEquals(frame.done, protoFrame.getDone());
List<Common.Row> rows = protoFrame.getRowsList();
assertEquals(1, rows.size());
Common.Row row = rows.get(0);
List<Common.ColumnValue> columnValues = row.getValueList();
assertEquals(2, columnValues.size());
Iterator<Common.ColumnValue> iter = columnValues.iterator();
assertTrue(iter.hasNext());
Common.ColumnValue column = iter.next();
assertTrue("The Column should have contained a scalar: " + column, column.hasField(ColumnValue.getDescriptor().findFieldByNumber(ColumnValue.SCALAR_VALUE_FIELD_NUMBER)));
Common.TypedValue value = column.getScalarValue();
assertEquals(Common.Rep.BOOLEAN, value.getType());
assertEquals(true, value.getBoolValue());
assertTrue(iter.hasNext());
column = iter.next();
assertTrue("The Column should have contained a scalar: " + column, column.hasField(ColumnValue.getDescriptor().findFieldByNumber(ColumnValue.SCALAR_VALUE_FIELD_NUMBER)));
value = column.getScalarValue();
assertEquals(Common.Rep.STRING, value.getType());
assertEquals("my_string", value.getStringValue());
}
use of org.apache.calcite.avatica.Meta.Frame in project calcite-avatica by apache.
the class FrameTest method testDeprecatedValueAttributeForArrays.
@Test
public void testDeprecatedValueAttributeForArrays() {
// Create a row with schema: [VARCHAR, ARRAY]
List<Object> rows = Collections.<Object>singletonList(new Object[] { "string", Arrays.asList(1, 2, 3) });
Meta.Frame frame = Meta.Frame.create(0, true, rows);
// Convert it to a protobuf
Common.Frame protoFrame = frame.toProto();
assertEquals(1, protoFrame.getRowsCount());
// Get that row we created
Common.Row protoRow = protoFrame.getRows(0);
// One row has many columns
List<Common.ColumnValue> protoColumns = protoRow.getValueList();
// We should have two columns
assertEquals(2, protoColumns.size());
// Fetch the ARRAY column
Common.ColumnValue protoColumn = protoColumns.get(1);
// We should have the 3 ARRAY elements in the array_values attribute as well as the deprecated
// values attribute.
List<Common.TypedValue> deprecatedValues = protoColumn.getValueList();
assertEquals(3, deprecatedValues.size());
assertTrue("Column 2 should have an array_value", protoColumns.get(1).getHasArrayValue());
List<Common.TypedValue> arrayValues = protoColumns.get(1).getArrayValueList();
assertEquals(arrayValues, deprecatedValues);
}
use of org.apache.calcite.avatica.Meta.Frame in project calcite-avatica by apache.
the class FrameTest method testMultipleRows.
@Test
public void testMultipleRows() {
ArrayList<Object> rows = new ArrayList<>();
rows.add(new Object[] { "string", Integer.MAX_VALUE, new Date().getTime() });
rows.add(new Object[] { "gnirts", 0, Long.MIN_VALUE });
rows.add(new Object[] { "", null, Long.MAX_VALUE });
Frame singleRow = new Frame(0, true, rows);
serializeAndTestEquality(singleRow);
}
Aggregations