Search in sources :

Example 1 with JdbcMetaColumnsResult

use of org.apache.ignite.client.proto.query.event.JdbcMetaColumnsResult in project ignite-3 by apache.

the class JdbcQueryEventHandlerImpl method queryMetadataAsync.

/**
 * {@inheritDoc}
 */
@Override
public CompletableFuture<JdbcMetaColumnsResult> queryMetadataAsync(JdbcQueryMetadataRequest req) {
    SqlCursor<List<?>> cur = openCursors.get(req.cursorId());
    if (cur == null) {
        return CompletableFuture.completedFuture(new JdbcMetaColumnsResult(Response.STATUS_FAILED, "Failed to find query cursor with ID: " + req.cursorId()));
    }
    ResultSetMetadata metadata = cur.metadata();
    if (metadata == null) {
        return CompletableFuture.completedFuture(new JdbcMetaColumnsResult(Response.STATUS_FAILED, "Failed to get query metadata for cursor with ID : " + req.cursorId()));
    }
    List<JdbcColumnMeta> meta = metadata.fields().stream().map(this::createColumnMetadata).collect(Collectors.toList());
    return CompletableFuture.completedFuture(new JdbcMetaColumnsResult(meta));
}
Also used : ResultSetMetadata(org.apache.ignite.internal.sql.engine.ResultSetMetadata) JdbcMetaColumnsResult(org.apache.ignite.client.proto.query.event.JdbcMetaColumnsResult) List(java.util.List) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) ArrayList(java.util.ArrayList) IntList(it.unimi.dsi.fastutil.ints.IntList) JdbcColumnMeta(org.apache.ignite.client.proto.query.event.JdbcColumnMeta)

Example 2 with JdbcMetaColumnsResult

use of org.apache.ignite.client.proto.query.event.JdbcMetaColumnsResult in project ignite-3 by apache.

the class JdbcResultSet method meta.

/**
 * Returns columns metadata list.
 *
 * @return Results metadata.
 * @throws SQLException On error.
 */
private List<JdbcColumnMeta> meta() throws SQLException {
    if (finished && (!isQuery || autoClose)) {
        throw new SQLException("Server cursor is already closed.", SqlStateCode.INVALID_CURSOR_STATE);
    }
    if (!metaInit) {
        JdbcMetaColumnsResult res = qryHandler.queryMetadataAsync(new JdbcQueryMetadataRequest(cursorId)).join();
        meta = res.meta();
        metaInit = true;
    }
    return meta;
}
Also used : JdbcQueryMetadataRequest(org.apache.ignite.client.proto.query.event.JdbcQueryMetadataRequest) SQLException(java.sql.SQLException) JdbcMetaColumnsResult(org.apache.ignite.client.proto.query.event.JdbcMetaColumnsResult)

Example 3 with JdbcMetaColumnsResult

use of org.apache.ignite.client.proto.query.event.JdbcMetaColumnsResult in project ignite-3 by apache.

the class JdbcDatabaseMetadata method getColumns.

/**
 * {@inheritDoc}
 */
@Override
public ResultSet getColumns(String catalog, String schemaPtrn, String tblNamePtrn, String colNamePtrn) throws SQLException {
    conn.ensureNotClosed();
    final List<JdbcColumnMeta> meta = asList(// 1
    new JdbcColumnMeta("TABLE_CAT", String.class), // 2
    new JdbcColumnMeta("TABLE_SCHEM", String.class), // 3
    new JdbcColumnMeta("TABLE_NAME", String.class), // 4
    new JdbcColumnMeta("COLUMN_NAME", String.class), // 5
    new JdbcColumnMeta("DATA_TYPE", Short.class), // 6
    new JdbcColumnMeta("TYPE_NAME", String.class), // 7
    new JdbcColumnMeta("COLUMN_SIZE", Integer.class), // 8
    new JdbcColumnMeta("BUFFER_LENGTH", Integer.class), // 9
    new JdbcColumnMeta("DECIMAL_DIGITS", Integer.class), // 10
    new JdbcColumnMeta("NUM_PREC_RADIX", Short.class), // 11
    new JdbcColumnMeta("NULLABLE", Short.class), // 12
    new JdbcColumnMeta("REMARKS", String.class), // 13
    new JdbcColumnMeta("COLUMN_DEF", String.class), // 14
    new JdbcColumnMeta("SQL_DATA_TYPE", Integer.class), // 15
    new JdbcColumnMeta("SQL_DATETIME_SUB", Integer.class), // 16
    new JdbcColumnMeta("CHAR_OCTET_LENGTH", Integer.class), // 17
    new JdbcColumnMeta("ORDINAL_POSITION", Integer.class), // 18
    new JdbcColumnMeta("IS_NULLABLE", String.class), // 19
    new JdbcColumnMeta("SCOPE_CATLOG", String.class), // 20
    new JdbcColumnMeta("SCOPE_SCHEMA", String.class), // 21
    new JdbcColumnMeta("SCOPE_TABLE", String.class), // 22
    new JdbcColumnMeta("SOURCE_DATA_TYPE", Short.class), // 23
    new JdbcColumnMeta("IS_AUTOINCREMENT", String.class), // 24
    new JdbcColumnMeta("IS_GENERATEDCOLUMN", String.class));
    if (!isValidCatalog(catalog)) {
        return new JdbcResultSet(Collections.emptyList(), meta);
    }
    JdbcMetaColumnsResult res = conn.handler().columnsMetaAsync(new JdbcMetaColumnsRequest(schemaPtrn, tblNamePtrn, colNamePtrn)).join();
    if (!res.hasResults()) {
        throw IgniteQueryErrorCode.createJdbcSqlException(res.err(), res.status());
    }
    List<List<Object>> rows = new LinkedList<>();
    for (int i = 0; i < res.meta().size(); ++i) {
        rows.add(columnRow(res.meta().get(i), i + 1));
    }
    return new JdbcResultSet(rows, meta);
}
Also used : JdbcMetaColumnsResult(org.apache.ignite.client.proto.query.event.JdbcMetaColumnsResult) JdbcColumnMeta(org.apache.ignite.client.proto.query.event.JdbcColumnMeta) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) LinkedList(java.util.LinkedList) List(java.util.List) JdbcMetaColumnsRequest(org.apache.ignite.client.proto.query.event.JdbcMetaColumnsRequest) LinkedList(java.util.LinkedList)

Aggregations

JdbcMetaColumnsResult (org.apache.ignite.client.proto.query.event.JdbcMetaColumnsResult)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 JdbcColumnMeta (org.apache.ignite.client.proto.query.event.JdbcColumnMeta)2 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)1 IntList (it.unimi.dsi.fastutil.ints.IntList)1 SQLException (java.sql.SQLException)1 Arrays.asList (java.util.Arrays.asList)1 Collections.singletonList (java.util.Collections.singletonList)1 LinkedList (java.util.LinkedList)1 JdbcMetaColumnsRequest (org.apache.ignite.client.proto.query.event.JdbcMetaColumnsRequest)1 JdbcQueryMetadataRequest (org.apache.ignite.client.proto.query.event.JdbcQueryMetadataRequest)1 ResultSetMetadata (org.apache.ignite.internal.sql.engine.ResultSetMetadata)1