Search in sources :

Example 16 with ColumnMetaData

use of org.apache.calcite.avatica.ColumnMetaData 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

ColumnMetaData (org.apache.calcite.avatica.ColumnMetaData)16 ArrayList (java.util.ArrayList)11 List (java.util.List)7 Accessor (org.apache.calcite.avatica.util.Cursor.Accessor)6 ArrayType (org.apache.calcite.avatica.ColumnMetaData.ArrayType)5 Array (java.sql.Array)3 AvaticaType (org.apache.calcite.avatica.ColumnMetaData.AvaticaType)3 ScalarType (org.apache.calcite.avatica.ColumnMetaData.ScalarType)3 Meta (org.apache.calcite.avatica.Meta)3 Struct (java.sql.Struct)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 AvaticaParameter (org.apache.calcite.avatica.AvaticaParameter)2 StructType (org.apache.calcite.avatica.ColumnMetaData.StructType)2 ConnectionPropertiesImpl (org.apache.calcite.avatica.ConnectionPropertiesImpl)2 Signature (org.apache.calcite.avatica.Meta.Signature)2 SqlType (org.apache.calcite.avatica.SqlType)2 ArrayAccessor (org.apache.calcite.avatica.util.AbstractCursor.ArrayAccessor)2 Test (org.junit.Test)2 IOException (java.io.IOException)1