Search in sources :

Example 1 with AvaticaResultSet

use of org.apache.calcite.avatica.AvaticaResultSet in project calcite-avatica by apache.

the class ArrayFactoryImpl method create.

@Override
public ResultSet create(AvaticaType elementType, Iterable<Object> elements) {
    // The ColumnMetaData for offset "1" in the ResultSet for an Array.
    ScalarType arrayOffsetType = ColumnMetaData.scalar(Types.INTEGER, "INTEGER", Rep.PRIMITIVE_INT);
    // Two columns (types) in the ResultSet we will create
    List<ColumnMetaData> types = Arrays.asList(ColumnMetaData.dummy(arrayOffsetType, false), ColumnMetaData.dummy(elementType, true));
    List<List<Object>> rows = createResultSetRowsForArrayData(elements);
    // `(List<Object>) rows` is a compile error.
    @SuppressWarnings({ "unchecked", "rawtypes" }) List<Object> untypedRows = (List<Object>) ((List) rows);
    try (ListIteratorCursor cursor = new ListIteratorCursor(rows.iterator())) {
        final String sql = "MOCKED";
        QueryState state = new QueryState(sql);
        Meta.Signature signature = new Meta.Signature(types, sql, Collections.<AvaticaParameter>emptyList(), Collections.<String, Object>emptyMap(), Meta.CursorFactory.LIST, Meta.StatementType.SELECT);
        AvaticaResultSetMetaData resultSetMetaData = new AvaticaResultSetMetaData(null, sql, signature);
        Meta.Frame frame = new Meta.Frame(0, true, untypedRows);
        AvaticaResultSet resultSet = new AvaticaResultSet(null, state, signature, resultSetMetaData, timeZone, frame);
        resultSet.execute2(cursor, types);
        return resultSet;
    }
}
Also used : Meta(org.apache.calcite.avatica.Meta) ScalarType(org.apache.calcite.avatica.ColumnMetaData.ScalarType) QueryState(org.apache.calcite.avatica.QueryState) AvaticaResultSet(org.apache.calcite.avatica.AvaticaResultSet) AvaticaResultSetMetaData(org.apache.calcite.avatica.AvaticaResultSetMetaData) ArrayList(java.util.ArrayList) List(java.util.List) ColumnMetaData(org.apache.calcite.avatica.ColumnMetaData)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 AvaticaResultSet (org.apache.calcite.avatica.AvaticaResultSet)1 AvaticaResultSetMetaData (org.apache.calcite.avatica.AvaticaResultSetMetaData)1 ColumnMetaData (org.apache.calcite.avatica.ColumnMetaData)1 ScalarType (org.apache.calcite.avatica.ColumnMetaData.ScalarType)1 Meta (org.apache.calcite.avatica.Meta)1 QueryState (org.apache.calcite.avatica.QueryState)1