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));
}
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));
});
}
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);
}
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.");
}
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);
}
Aggregations