Search in sources :

Example 81 with Column

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

the class RecordBinaryViewOperationsTest method remove.

@Test
public void remove() {
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id".toUpperCase(), NativeTypes.INT64, false) }, new Column[] { new Column("val".toUpperCase(), NativeTypes.INT64, false) });
    RecordView<Tuple> tbl = createTableImpl(schema).recordView();
    tbl.upsert(null, Tuple.create().set("id", 1L).set("val", 11L));
    final Tuple keyTuple = Tuple.create().set("id", 1L);
    // Delete not existed keyTuple.
    assertFalse(tbl.delete(null, Tuple.create().set("id", 2L)));
    // Delete existed keyTuple.
    assertTrue(tbl.delete(null, keyTuple));
    assertNull(tbl.get(null, keyTuple));
    // Delete already deleted keyTuple.
    assertFalse(tbl.delete(null, keyTuple));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 82 with Column

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

the class RecordBinaryViewOperationsTest method validateSchema.

@Test
public void validateSchema() {
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id".toUpperCase(), NativeTypes.INT64, false) }, new Column[] { new Column("val".toUpperCase(), NativeTypes.INT64, true), new Column("str".toUpperCase(), NativeTypes.stringOf(3), true), new Column("blob".toUpperCase(), NativeTypes.blobOf(3), true) });
    RecordView<Tuple> tbl = createTableImpl(schema).recordView();
    final Tuple keyTuple0 = new TestTupleBuilder().set("id", 0).set("id1", 0);
    final Tuple keyTuple1 = new TestTupleBuilder().set("id1", 0);
    final Tuple tuple0 = new TestTupleBuilder().set("id", 1L).set("str", "qweqweqwe").set("val", 11L);
    final Tuple tuple1 = new TestTupleBuilder().set("id", 1L).set("blob", new byte[] { 0, 1, 2, 3 }).set("val", 22L);
    assertThrowsWithCause(InvalidTypeException.class, () -> tbl.get(null, keyTuple0));
    assertThrowsWithCause(SchemaMismatchException.class, () -> tbl.get(null, keyTuple1));
    assertThrowsWithCause(InvalidTypeException.class, () -> tbl.replace(null, tuple0));
    assertThrowsWithCause(InvalidTypeException.class, () -> tbl.replace(null, tuple1));
    assertThrowsWithCause(InvalidTypeException.class, () -> tbl.insert(null, tuple0));
    assertThrowsWithCause(InvalidTypeException.class, () -> tbl.insert(null, tuple1));
    assertThrowsWithCause(InvalidTypeException.class, () -> tbl.replace(null, tuple0));
    assertThrowsWithCause(InvalidTypeException.class, () -> tbl.replace(null, tuple1));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) TestTupleBuilder(org.apache.ignite.internal.table.impl.TestTupleBuilder) Column(org.apache.ignite.internal.schema.Column) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 83 with Column

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

the class RecordBinaryViewOperationsTest method assertEqualsValues.

/**
 * Check value columns equality.
 *
 * @param schema   Schema.
 * @param expected Expected tuple.
 * @param actual   Actual tuple.
 */
void assertEqualsValues(SchemaDescriptor schema, Tuple expected, Tuple actual) {
    for (int i = 0; i < schema.valueColumns().length(); i++) {
        final Column col = schema.valueColumns().column(i);
        final Object val1 = expected.value(col.name());
        final Object val2 = actual.value(col.name());
        if (val1 instanceof byte[] && val2 instanceof byte[]) {
            Assertions.assertArrayEquals((byte[]) val1, (byte[]) val2, "Equality check failed: colIdx=" + col.schemaIndex());
        } else {
            Assertions.assertEquals(val1, val2, "Equality check failed: colIdx=" + col.schemaIndex());
        }
    }
}
Also used : Column(org.apache.ignite.internal.schema.Column)

Example 84 with Column

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

the class AbstractSerializerTest method schemaSerializeTest.

/**
 * (de)Serialize schema test.
 */
@Test
public void schemaSerializeTest() {
    AbstractSchemaSerializer assembler = SchemaSerializerImpl.INSTANCE;
    SchemaDescriptor desc = new SchemaDescriptor(100500, new Column[] { new Column("A", NativeTypes.INT8, false), new Column("B", NativeTypes.INT16, false), new Column("C", NativeTypes.INT32, false), new Column("D", NativeTypes.INT64, false), new Column("E", NativeTypes.UUID, false), new Column("F", NativeTypes.FLOAT, false), new Column("G", NativeTypes.DOUBLE, false), new Column("H", NativeTypes.DATE, false) }, new Column[] { new Column("A1", NativeTypes.stringOf(128), false), new Column("B1", NativeTypes.numberOf(255), false), new Column("C1", NativeTypes.decimalOf(128, 64), false), new Column("D1", NativeTypes.bitmaskOf(256), false), new Column("E1", NativeTypes.datetime(8), false), new Column("F1", NativeTypes.time(8), false), new Column("G1", NativeTypes.timestamp(8), true) });
    byte[] serialize = assembler.serialize(desc);
    SchemaDescriptor deserialize = assembler.deserialize(serialize);
    assertEquals(desc.version(), deserialize.version());
    assertArrayEquals(desc.keyColumns().columns(), deserialize.keyColumns().columns());
    assertArrayEquals(desc.valueColumns().columns(), deserialize.valueColumns().columns());
    assertArrayEquals(desc.colocationColumns(), deserialize.colocationColumns());
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) AbstractSchemaSerializer(org.apache.ignite.internal.schema.marshaller.schema.AbstractSchemaSerializer) Column(org.apache.ignite.internal.schema.Column) Test(org.junit.jupiter.api.Test)

Example 85 with Column

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

the class NumericTypesSerializerTest method testDecimalMaxScale.

@Test
public void testDecimalMaxScale() throws TupleMarshallerException {
    schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("decimalCol", NativeTypes.decimalOf(Integer.MAX_VALUE, Integer.MAX_VALUE), false) });
    final Tuple tup = createTuple().set("key", rnd.nextLong()).set("decimalCol", BigDecimal.valueOf(123, Integer.MAX_VALUE));
    TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
    final Row row = marshaller.marshal(tup);
    assertEquals(row.decimalValue(1), BigDecimal.valueOf(123, Integer.MAX_VALUE));
}
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) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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