Search in sources :

Example 1 with JdbcColumnMeta

use of org.apache.ignite.client.proto.query.event.JdbcColumnMeta 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 JdbcColumnMeta

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

the class JdbcMetadataCatalog method getColumnsMeta.

/**
 * See {@link DatabaseMetaData#getColumns(String, String, String, String)} for details.
 *
 * <p>Ignite has only one possible CATALOG_NAME, it is handled on the client (driver) side.
 *
 * @param schemaNamePtrn Schema name java regex pattern.
 * @param tblNamePtrn    Table name java regex pattern.
 * @param colNamePtrn    Column name java regex pattern.
 * @return Future of the list of metadatas about columns that match specified schema/tablename/columnname criterias.
 */
public CompletableFuture<Collection<JdbcColumnMeta>> getColumnsMeta(String schemaNamePtrn, String tblNamePtrn, String colNamePtrn) {
    String schemaNameRegex = translateSqlWildcardsToRegex(schemaNamePtrn);
    String tlbNameRegex = translateSqlWildcardsToRegex(tblNamePtrn);
    String colNameRegex = translateSqlWildcardsToRegex(colNamePtrn);
    return tables.tablesAsync().thenApply(tablesList -> {
        return tablesList.stream().filter(t -> matches(getTblSchema(t.name()), schemaNameRegex)).filter(t -> matches(getTblName(t.name()), tlbNameRegex)).flatMap(tbl -> {
            SchemaDescriptor schema = ((TableImpl) tbl).schemaView().schema();
            List<Pair<String, Column>> tblColPairs = new ArrayList<>();
            for (Column column : schema.keyColumns().columns()) {
                tblColPairs.add(new Pair<>(tbl.name(), column));
            }
            for (Column column : schema.valueColumns().columns()) {
                tblColPairs.add(new Pair<>(tbl.name(), column));
            }
            return tblColPairs.stream();
        }).filter(e -> matches(e.getSecond().name(), colNameRegex)).sorted(bySchemaThenTabNameThenColOrder).map(pair -> createColumnMeta(pair.getFirst(), pair.getSecond())).collect(Collectors.toCollection(LinkedHashSet::new));
    });
}
Also used : JdbcColumnMeta(org.apache.ignite.client.proto.query.event.JdbcColumnMeta) Arrays(java.util.Arrays) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Pair(org.apache.ignite.internal.util.Pair) SortedSet(java.util.SortedSet) Collection(java.util.Collection) DatabaseMetaData(java.sql.DatabaseMetaData) CompletableFuture(java.util.concurrent.CompletableFuture) JdbcTableMeta(org.apache.ignite.client.proto.query.event.JdbcTableMeta) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Commons(org.apache.ignite.internal.sql.engine.util.Commons) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) List(java.util.List) Column(org.apache.ignite.internal.schema.Column) TableImpl(org.apache.ignite.internal.table.TableImpl) JdbcPrimaryKeyMeta(org.apache.ignite.client.proto.query.event.JdbcPrimaryKeyMeta) IgniteTables(org.apache.ignite.table.manager.IgniteTables) NativeType(org.apache.ignite.internal.schema.NativeType) Table(org.apache.ignite.table.Table) Comparator(java.util.Comparator) SchemaRegistry(org.apache.ignite.internal.schema.SchemaRegistry) LinkedHashSet(java.util.LinkedHashSet) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) ArrayList(java.util.ArrayList) Pair(org.apache.ignite.internal.util.Pair)

Example 3 with JdbcColumnMeta

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

the class JdbcDatabaseMetadata method getTables.

/**
 * {@inheritDoc}
 */
@Override
public ResultSet getTables(String catalog, String schemaPtrn, String tblNamePtrn, String[] tblTypes) throws SQLException {
    conn.ensureNotClosed();
    final List<JdbcColumnMeta> meta = asList(new JdbcColumnMeta("TABLE_CAT", String.class), new JdbcColumnMeta("TABLE_SCHEM", String.class), new JdbcColumnMeta("TABLE_NAME", String.class), new JdbcColumnMeta("TABLE_TYPE", String.class), new JdbcColumnMeta("REMARKS", String.class), new JdbcColumnMeta("TYPE_CAT", String.class), new JdbcColumnMeta("TYPE_SCHEM", String.class), new JdbcColumnMeta("TYPE_NAME", String.class), new JdbcColumnMeta("SELF_REFERENCING_COL_NAME", String.class), new JdbcColumnMeta("REF_GENERATION", String.class));
    boolean tblTypeMatch = false;
    if (tblTypes == null) {
        tblTypeMatch = true;
    } else {
        for (String type : tblTypes) {
            if (TYPE_TABLE.equals(type)) {
                tblTypeMatch = true;
                break;
            }
        }
    }
    if (!isValidCatalog(catalog) || !tblTypeMatch) {
        return new JdbcResultSet(Collections.emptyList(), meta);
    }
    JdbcMetaTablesResult res = conn.handler().tablesMetaAsync(new JdbcMetaTablesRequest(schemaPtrn, tblNamePtrn, tblTypes)).join();
    if (!res.hasResults()) {
        throw IgniteQueryErrorCode.createJdbcSqlException(res.err(), res.status());
    }
    List<List<Object>> rows = new LinkedList<>();
    for (JdbcTableMeta tblMeta : res.meta()) {
        rows.add(tableRow(tblMeta));
    }
    return new JdbcResultSet(rows, meta);
}
Also used : JdbcTableMeta(org.apache.ignite.client.proto.query.event.JdbcTableMeta) JdbcColumnMeta(org.apache.ignite.client.proto.query.event.JdbcColumnMeta) JdbcMetaTablesRequest(org.apache.ignite.client.proto.query.event.JdbcMetaTablesRequest) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) LinkedList(java.util.LinkedList) List(java.util.List) JdbcMetaTablesResult(org.apache.ignite.client.proto.query.event.JdbcMetaTablesResult) LinkedList(java.util.LinkedList)

Example 4 with JdbcColumnMeta

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

the class JdbcDatabaseMetadata method getIndexInfo.

/**
 * {@inheritDoc}
 */
@Override
public ResultSet getIndexInfo(String catalog, String schema, String tbl, boolean unique, boolean approximate) throws SQLException {
    conn.ensureNotClosed();
    final List<JdbcColumnMeta> meta = asList(new JdbcColumnMeta("TABLE_CAT", String.class), new JdbcColumnMeta("TABLE_SCHEM", String.class), new JdbcColumnMeta("TABLE_NAME", String.class), new JdbcColumnMeta("NON_UNIQUE", Boolean.class), new JdbcColumnMeta("INDEX_QUALIFIER", String.class), new JdbcColumnMeta("INDEX_NAME", String.class), new JdbcColumnMeta("TYPE", Short.class), new JdbcColumnMeta("ORDINAL_POSITION", Short.class), new JdbcColumnMeta("COLUMN_NAME", String.class), new JdbcColumnMeta("ASC_OR_DESC", String.class), new JdbcColumnMeta("CARDINALITY", Integer.class), new JdbcColumnMeta("PAGES", Integer.class), new JdbcColumnMeta("FILTER_CONDITION", String.class));
    if (!isValidCatalog(catalog)) {
        return new JdbcResultSet(Collections.emptyList(), meta);
    }
    throw new UnsupportedOperationException("Index info is not supported yet.");
}
Also used : JdbcColumnMeta(org.apache.ignite.client.proto.query.event.JdbcColumnMeta)

Example 5 with JdbcColumnMeta

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

the class JdbcDatabaseMetadata method getSchemas.

/**
 * {@inheritDoc}
 */
@Override
public ResultSet getSchemas(String catalog, String schemaPtrn) throws SQLException {
    conn.ensureNotClosed();
    final List<JdbcColumnMeta> meta = asList(new JdbcColumnMeta("TABLE_SCHEM", String.class), new JdbcColumnMeta("TABLE_CATALOG", String.class));
    if (!isValidCatalog(catalog)) {
        return new JdbcResultSet(Collections.emptyList(), meta);
    }
    JdbcMetaSchemasResult res = conn.handler().schemasMetaAsync(new JdbcMetaSchemasRequest(schemaPtrn)).join();
    if (!res.hasResults()) {
        throw IgniteQueryErrorCode.createJdbcSqlException(res.err(), res.status());
    }
    List<List<Object>> rows = new LinkedList<>();
    for (String schema : res.schemas()) {
        List<Object> row = new ArrayList<>(2);
        row.add(schema);
        row.add(CATALOG_NAME);
        rows.add(row);
    }
    return new JdbcResultSet(rows, meta);
}
Also used : JdbcMetaSchemasRequest(org.apache.ignite.client.proto.query.event.JdbcMetaSchemasRequest) ArrayList(java.util.ArrayList) 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) JdbcMetaSchemasResult(org.apache.ignite.client.proto.query.event.JdbcMetaSchemasResult) LinkedList(java.util.LinkedList)

Aggregations

JdbcColumnMeta (org.apache.ignite.client.proto.query.event.JdbcColumnMeta)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Arrays.asList (java.util.Arrays.asList)4 Collections.singletonList (java.util.Collections.singletonList)4 LinkedList (java.util.LinkedList)4 JdbcMetaColumnsResult (org.apache.ignite.client.proto.query.event.JdbcMetaColumnsResult)2 JdbcPrimaryKeyMeta (org.apache.ignite.client.proto.query.event.JdbcPrimaryKeyMeta)2 JdbcTableMeta (org.apache.ignite.client.proto.query.event.JdbcTableMeta)2 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)1 IntList (it.unimi.dsi.fastutil.ints.IntList)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 LinkedHashSet (java.util.LinkedHashSet)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Function (java.util.function.Function)1