Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.math.BigInteger;
import java.util.BitSet;
import org.apache.ignite.schema.definition.ColumnType;
import org.jetbrains.annotations.Contract;

/**
* A thin wrapper over {@link NativeTypeSpec} to instantiate parameterized constrained types.
Expand Down Expand Up @@ -177,6 +178,7 @@ public static NativeType timestamp() {
* @param val Object to map to native type.
* @return {@code null} for {@code null} value. Otherwise returns NativeType according to the value's type.
*/
@Contract("null -> null")
public static NativeType fromObject(Object val) {
NativeTypeSpec spec = NativeTypeSpec.fromObject(val);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,28 @@ public enum BinaryMode {
/** Raw byte array. */
BYTE_ARR(NativeTypeSpec.BYTES),

/** BitSet.*/
/** BitSet. */
BITSET(NativeTypeSpec.BITMASK),

/** BigInteger. */
NUMBER(NativeTypeSpec.NUMBER),

/** BigDecimal. */
DECIMAL(NativeTypeSpec.DECIMAL);
DECIMAL(NativeTypeSpec.DECIMAL),

/** Natove type spec. */
/** Date. */
DATE(NativeTypeSpec.DATE),

/** Time. */
TIME(NativeTypeSpec.TIME),

/** Datetime. */
DATETIME(NativeTypeSpec.DATETIME),

/** Timestamp. */
TIMESTAMP(NativeTypeSpec.TIMESTAMP);

/** Native type spec. */
private final NativeTypeSpec typeSpec;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.BitSet;
import java.util.UUID;
import org.apache.ignite.internal.schema.InvalidTypeException;
Expand Down Expand Up @@ -95,6 +99,16 @@ else if (cls == Float.class)
else if (cls == Double.class)
return BinaryMode.DOUBLE;

// Temporal types
else if (cls == LocalDate.class)
return BinaryMode.DATE;
else if (cls == LocalTime.class)
return BinaryMode.TIME;
else if (cls == LocalDateTime.class)
return BinaryMode.DATETIME;
else if (cls == Instant.class)
return BinaryMode.TIMESTAMP;

// Other types
else if (cls == byte[].class)
return BinaryMode.BYTE_ARR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.BitSet;
import java.util.Objects;
import java.util.UUID;
Expand Down Expand Up @@ -103,6 +107,10 @@ static FieldAccessor create(Class<?> type, Column col, int colIdx) {
case BITSET:
case NUMBER:
case DECIMAL:
case TIME:
case DATE:
case DATETIME:
case TIMESTAMP:
return new ReferenceFieldAccessor(varHandle, colIdx, mode);

default:
Expand Down Expand Up @@ -147,6 +155,10 @@ static FieldAccessor createIdentityAccessor(Column col, int colIdx, BinaryMode m
case BITSET:
case NUMBER:
case DECIMAL:
case TIME:
case DATE:
case DATETIME:
case TIMESTAMP:
return new IdentityAccessor(colIdx, mode);

default:
Expand Down Expand Up @@ -231,6 +243,26 @@ private static Object readRefValue(Row reader, int colIdx, BinaryMode mode) {

break;

case DATE:
val = reader.dateValue(colIdx);

break;

case TIME:
val = reader.timeValue(colIdx);

break;

case TIMESTAMP:
val = reader.timestampValue(colIdx);

break;

case DATETIME:
val = reader.dateTimeValue(colIdx);

break;

default:
assert false : "Invalid mode: " + mode;
}
Expand Down Expand Up @@ -315,6 +347,26 @@ private static void writeRefObject(Object val, RowAssembler writer, BinaryMode m

break;

case DATE:
writer.appendDate((LocalDate)val);

break;

case TIME:
writer.appendTime((LocalTime)val);

break;

case TIMESTAMP:
writer.appendTimestamp((Instant)val);

break;

case DATETIME:
writer.appendDateTime((LocalDateTime)val);

break;

default:
assert false : "Invalid mode: " + mode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ private Object[] generateRowValues(SchemaDescriptor schema, Function<NativeType,
* @return Random value of requested type.
*/
private Object generateRandomValue(NativeType type) {
return TestUtils.generateRandomValue(rnd, type);
return SchemaTestUtils.generateRandomValue(rnd, type);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/**
* Test utility class.
*/
public final class TestUtils {
public final class SchemaTestUtils {
/**
* Generates random value of given type.
*
Expand Down Expand Up @@ -118,6 +118,6 @@ public static Object generateRandomValue(Random rnd, NativeType type) {
/**
* Stub.
*/
private TestUtils() {
private SchemaTestUtils() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import org.apache.ignite.internal.schema.NativeTypeSpec;
import org.apache.ignite.internal.schema.NativeTypes;
import org.apache.ignite.internal.schema.SchemaDescriptor;
import org.apache.ignite.internal.schema.TestUtils;
import org.apache.ignite.internal.schema.SchemaTestUtils;
import org.apache.ignite.internal.schema.marshaller.asm.AsmSerializerGenerator;
import org.apache.ignite.internal.schema.marshaller.reflection.JavaSerializerFactory;
import org.apache.ignite.internal.schema.row.Row;
Expand Down Expand Up @@ -401,7 +401,7 @@ private void compareObjects(NativeType type, Object exp, Object act) {
* @param type Type.
*/
private Object generateRandomValue(NativeType type) {
return TestUtils.generateRandomValue(rnd, type);
return SchemaTestUtils.generateRandomValue(rnd, type);
}

/**
Expand Down Expand Up @@ -477,8 +477,8 @@ public static TestObject randomObject(Random rnd) {
obj.bitmaskCol = IgniteTestUtils.randomBitSet(rnd, 42);
obj.stringCol = IgniteTestUtils.randomString(rnd, rnd.nextInt(255));
obj.bytesCol = IgniteTestUtils.randomBytes(rnd, rnd.nextInt(255));
obj.numberCol = (BigInteger)TestUtils.generateRandomValue(rnd, NativeTypes.numberOf(12));
obj.decimalCol = (BigDecimal)TestUtils.generateRandomValue(rnd, NativeTypes.decimalOf(19, 3));
obj.numberCol = (BigInteger)SchemaTestUtils.generateRandomValue(rnd, NativeTypes.numberOf(12));
obj.decimalCol = (BigDecimal)SchemaTestUtils.generateRandomValue(rnd, NativeTypes.decimalOf(19, 3));

return obj;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.UUID;
import org.apache.ignite.internal.schema.Column;
import org.apache.ignite.internal.schema.NativeTypes;
import org.apache.ignite.internal.schema.TestUtils;
import org.apache.ignite.internal.schema.SchemaTestUtils;
import org.apache.ignite.internal.schema.marshaller.BinaryMode;
import org.apache.ignite.internal.schema.marshaller.SerializationException;
import org.apache.ignite.internal.schema.row.Row;
Expand Down Expand Up @@ -322,8 +322,8 @@ public static TestObject randomObject(Random rnd) {
obj.bitmaskCol = IgniteTestUtils.randomBitSet(rnd, rnd.nextInt(42));
obj.stringCol = IgniteTestUtils.randomString(rnd, rnd.nextInt(255));
obj.bytesCol = IgniteTestUtils.randomBytes(rnd, rnd.nextInt(255));
obj.numberCol = (BigInteger)TestUtils.generateRandomValue(rnd, NativeTypes.numberOf(12));
obj.decimalCol = (BigDecimal) TestUtils.generateRandomValue(rnd, NativeTypes.decimalOf(19, 3));
obj.numberCol = (BigInteger)SchemaTestUtils.generateRandomValue(rnd, NativeTypes.numberOf(12));
obj.decimalCol = (BigDecimal) SchemaTestUtils.generateRandomValue(rnd, NativeTypes.decimalOf(19, 3));

return obj;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.apache.ignite.internal.schema.NativeTypeSpec;
import org.apache.ignite.internal.schema.NativeTypes;
import org.apache.ignite.internal.schema.SchemaDescriptor;
import org.apache.ignite.internal.schema.TestUtils;
import org.apache.ignite.internal.schema.SchemaTestUtils;
import org.apache.ignite.internal.schema.mapping.ColumnMapper;
import org.apache.ignite.internal.schema.row.Row;
import org.apache.ignite.internal.schema.row.RowAssembler;
Expand Down Expand Up @@ -184,7 +184,7 @@ private List<Object> generateRowValues(SchemaDescriptor schema) {
for (int i = 0; i < schema.length(); i++) {
NativeType type = schema.column(i).type();

res.add(TestUtils.generateRandomValue(rnd, type));
res.add(SchemaTestUtils.generateRandomValue(rnd, type));
}

return res;
Expand All @@ -195,7 +195,7 @@ private List<Object> generateRowValues(SchemaDescriptor schema) {
*
* @param schema Row schema.
* @param vals Row values.
* @return
* @return Serialized row.
*/
private byte[] serializeValuesToRow(SchemaDescriptor schema, List<Object> vals) {
assertEquals(schema.keyColumns().length() + schema.valueColumns().length(), vals.size());
Expand Down
7 changes: 7 additions & 0 deletions modules/table/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@
<type>test-jar</type>
</dependency>

<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-schema</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<!-- Logging in tests -->
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Loading