Search in sources :

Example 51 with SchemaDescriptor

use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.

the class NumericTypesSerializerTest method testStringDecimalSpecialCase.

@Test
public void testStringDecimalSpecialCase() throws TupleMarshallerException {
    schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("decimalCol", NativeTypes.decimalOf(1, 0), false) });
    // representation of "0000" value.
    final Tuple tup = createTuple().set("key", rnd.nextLong()).set("decimalCol", new BigDecimal("0E+3"));
    TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
    final Row row = marshaller.marshal(tup);
    assertEquals(row.decimalValue(1), BigDecimal.ZERO);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) TupleMarshaller(org.apache.ignite.internal.schema.marshaller.TupleMarshaller) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) Row(org.apache.ignite.internal.schema.row.Row) Tuple(org.apache.ignite.table.Tuple) BigDecimal(java.math.BigDecimal) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 52 with SchemaDescriptor

use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.

the class NumericTypesSerializerTest method testPrecisionRestrictionsForNumbers.

@Test
public void testPrecisionRestrictionsForNumbers() {
    schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("number1", NativeTypes.numberOf(5), false) });
    TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
    final Tuple badTup = createTuple().set("key", rnd.nextLong());
    assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("number1", BigInteger.valueOf(999991L))), "Column's type mismatch");
    assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("number1", new BigInteger("111111"))), "Column's type mismatch");
    assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("number1", BigInteger.valueOf(-999991L))), "Column's type mismatch");
    assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("number1", new BigInteger("-111111"))), "Column's type mismatch");
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) TupleMarshaller(org.apache.ignite.internal.schema.marshaller.TupleMarshaller) BigInteger(java.math.BigInteger) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 53 with SchemaDescriptor

use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.

the class NumericTypesSerializerTest method testSameBinaryRepresentation.

/**
 * Test.
 */
@ParameterizedTest
@MethodSource("sameDecimals")
public void testSameBinaryRepresentation(Pair<BigInteger, BigInteger> pair) throws Exception {
    schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("decimalCol", NativeTypes.decimalOf(19, 3), false) });
    TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
    long randomKey = rnd.nextLong();
    final Tuple firstTup = createTuple().set("key", randomKey).set("decimalCol", pair.getFirst());
    final Tuple secondTup = createTuple().set("key", randomKey).set("decimalCol", pair.getSecond());
    final Row firstRow = marshaller.marshal(firstTup);
    final Row secondRow = marshaller.marshal(secondTup);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    firstRow.writeTo(stream);
    byte[] firstRowInBytes = stream.toByteArray();
    stream.reset();
    secondRow.writeTo(stream);
    byte[] secondRowInBytes = stream.toByteArray();
    assertArrayEquals(firstRowInBytes, secondRowInBytes);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) TupleMarshaller(org.apache.ignite.internal.schema.marshaller.TupleMarshaller) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) Row(org.apache.ignite.internal.schema.row.Row) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) Tuple(org.apache.ignite.table.Tuple) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 54 with SchemaDescriptor

use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.

the class NumericTypesSerializerTest method testPrecisionRestrictionsForDecimal.

@Test
public void testPrecisionRestrictionsForDecimal() {
    schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("decimalCol", NativeTypes.decimalOf(9, 3), false) });
    final Tuple badTup = createTuple().set("key", rnd.nextLong());
    TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
    assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("decimalCol", new BigDecimal("123456789.0123"))), "Failed to set decimal value for column");
    assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("decimalCol", new BigDecimal("-1234567890123"))), "Failed to set decimal value for column");
    assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("decimalCol", new BigDecimal("1234567"))), "Failed to set decimal value for column");
    assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("decimalCol", new BigDecimal("12345678.9"))), "Failed to set decimal value for column");
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) TupleMarshaller(org.apache.ignite.internal.schema.marshaller.TupleMarshaller) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) Tuple(org.apache.ignite.table.Tuple) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 55 with SchemaDescriptor

use of org.apache.ignite.internal.schema.SchemaDescriptor 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)

Aggregations

SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)105 Column (org.apache.ignite.internal.schema.Column)78 Test (org.junit.jupiter.api.Test)48 Tuple (org.apache.ignite.table.Tuple)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 Row (org.apache.ignite.internal.schema.row.Row)32 MethodSource (org.junit.jupiter.params.provider.MethodSource)30 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)22 TestObjectWithAllTypes (org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes)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 List (java.util.List)9 ArrayList (java.util.ArrayList)8 NotNull (org.jetbrains.annotations.NotNull)8 UUID (java.util.UUID)7 Collectors (java.util.stream.Collectors)7 TableImpl (org.apache.ignite.internal.table.TableImpl)7 Random (java.util.Random)6 Map (java.util.Map)5