org.apache.calcite.avatica.Meta.Frame Java Examples
The following examples show how to use
org.apache.calcite.avatica.Meta.Frame.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FrameTest.java From calcite-avatica with Apache License 2.0 | 6 votes |
@Test public void testColumnValueBackwardsCompatibility() { // 1 final ColumnValue oldStyleScalarValue = ColumnValue.newBuilder().addValue(NUMBER_VALUE).build(); // [1, 1] final ColumnValue oldStyleArrayValue = ColumnValue.newBuilder().addValue(NUMBER_VALUE) .addValue(NUMBER_VALUE).build(); assertFalse(Frame.isNewStyleColumn(oldStyleScalarValue)); assertFalse(Frame.isNewStyleColumn(oldStyleArrayValue)); Object scalar = Frame.parseOldStyleColumn(oldStyleScalarValue); assertEquals(1L, scalar); Object array = Frame.parseOldStyleColumn(oldStyleArrayValue); assertEquals(Arrays.asList(1L, 1L), array); }
Example #2
Source File: FrameTest.java From calcite-avatica with Apache License 2.0 | 6 votes |
@Test public void testColumnValueParsing() { // 1 final ColumnValue scalarValue = ColumnValue.newBuilder().setScalarValue(NUMBER_VALUE).build(); // [1, 1] final ColumnValue arrayValue = ColumnValue.newBuilder().addArrayValue(NUMBER_VALUE) .addArrayValue(NUMBER_VALUE).setHasArrayValue(true).build(); assertTrue(Frame.isNewStyleColumn(scalarValue)); assertTrue(Frame.isNewStyleColumn(arrayValue)); Object scalar = Frame.parseColumn(scalarValue); assertEquals(1L, scalar); Object array = Frame.parseColumn(arrayValue); assertEquals(Arrays.asList(1L, 1L), array); }
Example #3
Source File: FrameTest.java From calcite-avatica with Apache License 2.0 | 6 votes |
@Test public void testDeprecatedValueAttributeForScalars() { // Create a row with schema: [VARCHAR, INTEGER, DATE] List<Object> rows = Collections.<Object>singletonList(new Object[] {"string", Integer.MAX_VALUE, new Date().getTime()}); 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(); assertEquals(3, protoColumns.size()); // Verify that the scalar value is also present in the deprecated values attributes. List<Common.TypedValue> deprecatedValues = protoColumns.get(0).getValueList(); assertEquals(1, deprecatedValues.size()); Common.TypedValue scalarValue = protoColumns.get(0).getScalarValue(); assertEquals(deprecatedValues.get(0), scalarValue); }
Example #4
Source File: FrameTest.java From calcite-avatica with Apache License 2.0 | 6 votes |
@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); }
Example #5
Source File: FrameTest.java From calcite-avatica with Apache License 2.0 | 5 votes |
private void serializeAndTestEquality(Frame frame) { Frame frameCopy = Frame.fromProto(frame.toProto()); assertEquals(frame.done, frameCopy.done); assertEquals(frame.offset, frameCopy.offset); Iterable<Object> origRows = frame.rows; Iterable<Object> copiedRows = frameCopy.rows; assertEquals("Expected rows to both be null, or both be non-null", origRows == null, copiedRows == null); Iterator<Object> origIter = origRows.iterator(); Iterator<Object> copiedIter = copiedRows.iterator(); while (origIter.hasNext() && copiedIter.hasNext()) { Object orig = origIter.next(); Object copy = copiedIter.next(); assertEquals(orig == null, copy == null); // This is goofy, but it seems like an Array comes from the JDBC implementation but then // the resulting Frame has a List to support the Avatica typed Accessors assertEquals(Object[].class, orig.getClass()); assertTrue("Expected List but got " + copy.getClass(), copy instanceof List); @SuppressWarnings("unchecked") List<Object> copyList = (List<Object>) copy; assertArrayEquals((Object[]) orig, copyList.toArray(new Object[0])); } assertEquals(origIter.hasNext(), copiedIter.hasNext()); }
Example #6
Source File: FrameTest.java From calcite-avatica with Apache License 2.0 | 5 votes |
@Test public void testSingleRow() { ArrayList<Object> rows = new ArrayList<>(); rows.add(new Object[] {"string", Integer.MAX_VALUE, new Date().getTime()}); Frame singleRow = new Frame(0, true, rows); serializeAndTestEquality(singleRow); }
Example #7
Source File: FrameTest.java From calcite-avatica with Apache License 2.0 | 5 votes |
@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); }
Example #8
Source File: FrameTest.java From calcite-avatica with Apache License 2.0 | 5 votes |
@Test public void testNestedArraySerialization() { List<Object> rows = new ArrayList<>(); // [ "pk", [[1,2], [3,4]] ] rows.add(Arrays.asList("pk", Arrays.asList(Arrays.asList(1, 2), Arrays.asList(3, 4)))); Frame frame = new Frame(0, true, rows); // Parse back the list in serialized form Common.Frame protoFrame = frame.toProto(); Common.Row protoRow = protoFrame.getRows(0); Common.ColumnValue protoColumn = protoRow.getValue(1); assertTrue(protoColumn.getHasArrayValue()); int value = 1; for (Common.TypedValue arrayElement : protoColumn.getArrayValueList()) { assertEquals(Common.Rep.ARRAY, arrayElement.getType()); for (Common.TypedValue nestedArrayElement : arrayElement.getArrayValueList()) { assertEquals(Common.Rep.INTEGER, nestedArrayElement.getType()); assertEquals(value++, nestedArrayElement.getNumberValue()); } } Frame newFrame = Frame.fromProto(protoFrame); @SuppressWarnings("unchecked") List<Object> newRow = (List<Object>) newFrame.rows.iterator().next(); @SuppressWarnings("unchecked") List<Object> expectedRow = (List<Object>) rows.get(0); assertEquals(expectedRow.get(0), newRow.get(0)); assertEquals(expectedRow.get(1), newRow.get(1)); }
Example #9
Source File: KylinJdbcFactory.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
@Override public AvaticaResultSet newResultSet(AvaticaStatement statement, QueryState state, Signature signature, TimeZone timeZone, Frame firstFrame) throws SQLException { AvaticaResultSetMetaData resultSetMetaData = new AvaticaResultSetMetaData(statement, null, signature); return new KylinResultSet(statement, state, signature, resultSetMetaData, timeZone, firstFrame); }
Example #10
Source File: KylinResultSet.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
public KylinResultSet(AvaticaStatement statement, QueryState state, Signature signature, ResultSetMetaData resultSetMetaData, TimeZone timeZone, Frame firstFrame) throws SQLException { super(statement, state, signature, resultSetMetaData, timeZone, firstFrame); }
Example #11
Source File: FrameTest.java From calcite-avatica with Apache License 2.0 | 4 votes |
@Test public void testEmpty() { serializeAndTestEquality(Frame.EMPTY); }
Example #12
Source File: ProtobufTranslationImplTest.java From calcite-avatica with Apache License 2.0 | 4 votes |
/** * Generates a collection of Responses whose serialization will be tested. */ private static List<Response> getResponses() { final RpcMetadataResponse rpcMetadata = new RpcMetadataResponse("localhost:8765"); LinkedList<Response> responses = new LinkedList<>(); // Nested classes (Signature, ColumnMetaData, CursorFactory, etc) are implicitly getting tested) // Stub out the metadata for a row ScalarType arrayComponentType = ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER); ColumnMetaData arrayColumnMetaData = getArrayColumnMetaData(arrayComponentType, 2, "counts"); List<ColumnMetaData> columns = Arrays.asList(MetaImpl.columnMetaData("str", 0, String.class, true), MetaImpl.columnMetaData("count", 1, Integer.class, true), arrayColumnMetaData); List<AvaticaParameter> params = Arrays.asList( new AvaticaParameter(false, 10, 0, Types.VARCHAR, "VARCHAR", String.class.getName(), "str")); Meta.CursorFactory cursorFactory = Meta.CursorFactory.create(Style.LIST, Object.class, Arrays.asList("str", "count", "counts")); // The row values List<Object> rows = new ArrayList<>(); rows.add(new Object[] {"str_value1", 50, Arrays.asList(1, 2, 3)}); rows.add(new Object[] {"str_value2", 100, Arrays.asList(1)}); // Create the signature and frame using the metadata and values Signature signature = Signature.create(columns, "sql", params, cursorFactory, Meta.StatementType.SELECT); Frame frame = Frame.create(Integer.MAX_VALUE, true, rows); // And then create a ResultSetResponse ResultSetResponse results1 = new ResultSetResponse("connectionId", Integer.MAX_VALUE, true, signature, frame, Long.MAX_VALUE, rpcMetadata); responses.add(results1); responses.add(new CloseStatementResponse(rpcMetadata)); ConnectionPropertiesImpl connProps = new ConnectionPropertiesImpl(false, true, Integer.MAX_VALUE, "catalog", "schema"); responses.add(new ConnectionSyncResponse(connProps, rpcMetadata)); responses.add(new OpenConnectionResponse(rpcMetadata)); responses.add(new CloseConnectionResponse(rpcMetadata)); responses.add(new CreateStatementResponse("connectionId", Integer.MAX_VALUE, rpcMetadata)); Map<Meta.DatabaseProperty, Object> propertyMap = new HashMap<>(); for (Meta.DatabaseProperty prop : Meta.DatabaseProperty.values()) { propertyMap.put(prop, prop.defaultValue); } responses.add(new DatabasePropertyResponse(propertyMap, rpcMetadata)); responses.add( new ExecuteResponse(Arrays.asList(results1, results1, results1), false, rpcMetadata)); responses.add(new FetchResponse(frame, false, false, rpcMetadata)); responses.add(new FetchResponse(frame, true, true, rpcMetadata)); responses.add(new FetchResponse(frame, false, true, rpcMetadata)); responses.add( new PrepareResponse( new Meta.StatementHandle("connectionId", Integer.MAX_VALUE, signature), rpcMetadata)); StringWriter sw = new StringWriter(); new Exception().printStackTrace(new PrintWriter(sw)); responses.add( new ErrorResponse(Collections.singletonList(sw.toString()), "Test Error Message", ErrorResponse.UNKNOWN_ERROR_CODE, ErrorResponse.UNKNOWN_SQL_STATE, AvaticaSeverity.WARNING, rpcMetadata)); // No more results, statement not missing responses.add(new SyncResultsResponse(false, false, rpcMetadata)); // Missing statement, no results responses.add(new SyncResultsResponse(false, true, rpcMetadata)); // More results, no missing statement responses.add(new SyncResultsResponse(true, false, rpcMetadata)); // Some tests to make sure ErrorResponse doesn't fail. responses.add(new ErrorResponse((List<String>) null, null, 0, null, null, null)); responses.add( new ErrorResponse(Arrays.asList("stacktrace1", "stacktrace2"), null, 0, null, null, null)); responses.add(new CommitResponse()); responses.add(new RollbackResponse()); long[] updateCounts = new long[]{1, 0, 1, 1}; responses.add( new ExecuteBatchResponse("connectionId", 12345, updateCounts, false, rpcMetadata)); return responses; }
Example #13
Source File: ProtobufHandlerTest.java From calcite-avatica with Apache License 2.0 | 4 votes |
@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()); }
Example #14
Source File: KylinJdbcFactory.java From kylin with Apache License 2.0 | 4 votes |
@Override public AvaticaResultSet newResultSet(AvaticaStatement statement, QueryState state, Signature signature, TimeZone timeZone, Frame firstFrame) throws SQLException { AvaticaResultSetMetaData resultSetMetaData = new AvaticaResultSetMetaData(statement, null, signature); return new KylinResultSet(statement, state, signature, resultSetMetaData, timeZone, firstFrame); }
Example #15
Source File: KylinResultSet.java From kylin with Apache License 2.0 | 4 votes |
public KylinResultSet(AvaticaStatement statement, QueryState state, Signature signature, ResultSetMetaData resultSetMetaData, TimeZone timeZone, Frame firstFrame) throws SQLException { super(statement, state, signature, resultSetMetaData, timeZone, firstFrame); }