use of org.apache.ignite.internal.schema.Column 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.internal.schema.Column in project ignite-3 by apache.
the class Marshaller method simpleMarshaller.
/**
* Creates a marshaller for class.
*
* @param cols Columns.
* @param mapper Mapper.
* @return Marshaller.
*/
static <T> SimpleMarshaller simpleMarshaller(Column[] cols, @NotNull OneColumnMapper<T> mapper) {
final Class<T> targetType = mapper.targetType();
Column col = (mapper.mappedColumn() == null && cols.length == 1) ? cols[0] : Arrays.stream(cols).filter(c -> c.name().equals(mapper.mappedColumn())).findFirst().orElseThrow(() -> new SchemaMismatchException("Failed to map object to a single column:" + mapper.mappedColumn()));
assert !targetType.isPrimitive() : "Non-nullable types are not allowed.";
return new SimpleMarshaller(ColumnBinding.createIdentityBinding(col, targetType, mapper.converter()));
}
use of org.apache.ignite.internal.schema.Column in project ignite-3 by apache.
the class SchemaSerializerImpl method readFrom.
/**
* {@inheritDoc}
*/
@Override
public SchemaDescriptor readFrom(ByteBuffer byteBuf) {
int ver = byteBuf.getInt();
Column[] keyCols = readColumns(byteBuf);
Column[] valCols = readColumns(byteBuf);
int colocationColsSize = byteBuf.getInt();
String[] colocationCols = new String[colocationColsSize];
for (int i = 0; i < colocationColsSize; i++) {
colocationCols[i] = readString(byteBuf);
}
SchemaDescriptor descriptor = new SchemaDescriptor(ver, keyCols, colocationCols, valCols);
ColumnMapper mapper = readColumnMapping(descriptor, byteBuf);
descriptor.columnMapping(mapper);
return descriptor;
}
use of org.apache.ignite.internal.schema.Column in project ignite-3 by apache.
the class SchemaSerializerImpl method appendColumns.
/**
* Appends column array to byte buffer.
*
* @param buf Byte buffer.
* @param cols Column array.
*/
private void appendColumns(Columns cols, ByteBuffer buf) {
Column[] colArr = cols.columns();
buf.putInt(colArr.length);
for (Column column : colArr) {
appendColumn(column, buf);
}
}
use of org.apache.ignite.internal.schema.Column in project ignite-3 by apache.
the class SchemaSerializerImpl method readColumn.
/**
* Reads column from byte buffer.
*
* @param buf Byte buffer.
* @return Column.
*/
private Column readColumn(ByteBuffer buf) {
int schemaIdx = buf.getInt();
int columnOrder = buf.getInt();
boolean nullable = buf.get() == 1;
String name = readString(buf);
NativeType nativeType = fromByteBuffer(buf);
Object object = readDefaultValue(buf, nativeType);
return new Column(columnOrder, name, nativeType, nullable, () -> object).copy(schemaIdx);
}
Aggregations