Search in sources :

Example 66 with Column

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));
    });
}
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 67 with Column

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()));
}
Also used : OneColumnMapper(org.apache.ignite.table.mapper.OneColumnMapper) Arrays(java.util.Arrays) MarshallerException(org.apache.ignite.internal.schema.marshaller.MarshallerException) SchemaMismatchException(org.apache.ignite.internal.schema.SchemaMismatchException) Factory(org.apache.ignite.internal.util.Factory) Objects(java.util.Objects) PojoMapper(org.apache.ignite.table.mapper.PojoMapper) Nullable(org.jetbrains.annotations.Nullable) ObjectFactory(org.apache.ignite.internal.util.ObjectFactory) Row(org.apache.ignite.internal.schema.row.Row) Column(org.apache.ignite.internal.schema.Column) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) Mapper(org.apache.ignite.table.mapper.Mapper) NotNull(org.jetbrains.annotations.NotNull) SchemaMismatchException(org.apache.ignite.internal.schema.SchemaMismatchException) Column(org.apache.ignite.internal.schema.Column)

Example 68 with Column

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;
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) ColumnMapper(org.apache.ignite.internal.schema.mapping.ColumnMapper)

Example 69 with Column

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);
    }
}
Also used : Column(org.apache.ignite.internal.schema.Column)

Example 70 with Column

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);
}
Also used : Column(org.apache.ignite.internal.schema.Column) VarlenNativeType(org.apache.ignite.internal.schema.VarlenNativeType) TemporalNativeType(org.apache.ignite.internal.schema.TemporalNativeType) DecimalNativeType(org.apache.ignite.internal.schema.DecimalNativeType) NumberNativeType(org.apache.ignite.internal.schema.NumberNativeType) NativeType(org.apache.ignite.internal.schema.NativeType) BitmaskNativeType(org.apache.ignite.internal.schema.BitmaskNativeType)

Aggregations

Column (org.apache.ignite.internal.schema.Column)131 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)78 Test (org.junit.jupiter.api.Test)44 Row (org.apache.ignite.internal.schema.row.Row)37 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)31 Tuple (org.apache.ignite.table.Tuple)27 MethodSource (org.junit.jupiter.params.provider.MethodSource)27 SchemaException (org.apache.ignite.internal.schema.SchemaException)22 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)20 RowAssembler (org.apache.ignite.internal.schema.row.RowAssembler)11 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)11 TupleMarshaller (org.apache.ignite.internal.schema.marshaller.TupleMarshaller)10 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)10 TestObjectWithAllTypes (org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes)10 Arrays (java.util.Arrays)7 NotNull (org.jetbrains.annotations.NotNull)7 List (java.util.List)6 Random (java.util.Random)6 NativeTypeSpec (org.apache.ignite.internal.schema.NativeTypeSpec)6 BigDecimal (java.math.BigDecimal)5