0
# Type System Assertions
1
2
Comprehensive assertions for Flink's DataType and LogicalType system with validation of type properties, conversions, and hierarchies. These assertions enable thorough testing of Flink's rich type system including complex nested types.
3
4
## DataType Assertions
5
6
Assertions for Flink's DataType objects that combine logical types with conversion class information.
7
8
```java { .api }
9
public class DataTypeAssert extends AbstractAssert<DataTypeAssert, DataType> {
10
public DataTypeAssert(DataType dataType);
11
12
// Type navigation
13
public LogicalTypeAssert asLogicalType();
14
public ClassAssert getConversionClass();
15
public ListAssert<DataType> getChildren();
16
17
// Type validation
18
public DataTypeAssert hasConversionClass(Class<?> clazz);
19
public DataTypeAssert hasLogicalType(LogicalType logicalType);
20
public DataTypeAssert isNullable();
21
public DataTypeAssert isNotNullable();
22
}
23
```
24
25
### Usage Examples
26
27
```java
28
import static org.apache.flink.table.test.TableAssertions.assertThat;
29
import static org.apache.flink.table.test.DataTypeConditions.*;
30
import org.apache.flink.table.types.DataType;
31
import org.apache.flink.table.api.DataTypes;
32
33
// Basic type validation
34
DataType stringType = DataTypes.STRING();
35
assertThat(stringType)
36
.isNullable()
37
.hasConversionClass(String.class);
38
39
// Complex type validation
40
DataType rowType = DataTypes.ROW(
41
DataTypes.FIELD("id", DataTypes.INT()),
42
DataTypes.FIELD("name", DataTypes.STRING())
43
);
44
45
assertThat(rowType)
46
.isNullable()
47
.getChildren()
48
.hasSize(2);
49
50
// Using conditions
51
assertThat(stringType)
52
.is(NULLABLE)
53
.is(not(INTERNAL));
54
55
// Logical type navigation
56
assertThat(stringType)
57
.asLogicalType()
58
.isNullable()
59
.supportsInputConversion(String.class);
60
```
61
62
## LogicalType Assertions
63
64
Assertions for Flink's LogicalType objects that define the structure and semantics of data types.
65
66
```java { .api }
67
public class LogicalTypeAssert extends AbstractAssert<LogicalTypeAssert, LogicalType> {
68
public LogicalTypeAssert(LogicalType logicalType);
69
70
// Nullability
71
public LogicalTypeAssert isNullable();
72
public LogicalTypeAssert isNotNullable();
73
74
// Type hierarchy
75
public ListAssert<LogicalType> getChildren();
76
public LogicalTypeAssert hasExactlyChildren(LogicalType... children);
77
78
// String representations
79
public LogicalTypeAssert hasSerializableString(String serializableString);
80
public LogicalTypeAssert hasNoSerializableString();
81
public LogicalTypeAssert hasSummaryString(String summaryString);
82
83
// Conversion support
84
public LogicalTypeAssert supportsInputConversion(Class<?> clazz);
85
public LogicalTypeAssert doesNotSupportInputConversion(Class<?> clazz);
86
public LogicalTypeAssert supportsOutputConversion(Class<?> clazz);
87
public LogicalTypeAssert doesNotSupportOutputConversion(Class<?> clazz);
88
89
// Serialization
90
public LogicalTypeAssert isJavaSerializable();
91
92
// Decimal type specific
93
public LogicalTypeAssert isDecimalType();
94
public LogicalTypeAssert hasPrecision(int precision);
95
public LogicalTypeAssert hasScale(int scale);
96
public LogicalTypeAssert hasPrecisionAndScale(int precision, int scale);
97
}
98
```
99
100
### Usage Examples
101
102
```java
103
import org.apache.flink.table.types.logical.*;
104
105
// Basic logical type validation
106
LogicalType intType = new IntType();
107
assertThat(intType)
108
.isNullable()
109
.supportsInputConversion(Integer.class)
110
.supportsOutputConversion(Integer.class)
111
.isJavaSerializable();
112
113
// Complex type validation
114
LogicalType rowType = RowType.of(
115
new IntType(false), // non-nullable int
116
new VarCharType(255) // varchar(255)
117
);
118
119
assertThat(rowType)
120
.isNullable()
121
.getChildren()
122
.hasSize(2);
123
124
assertThat(rowType)
125
.hasExactlyChildren(
126
new IntType(false),
127
new VarCharType(255)
128
);
129
130
// Decimal type validation
131
LogicalType decimalType = new DecimalType(10, 2);
132
assertThat(decimalType)
133
.isDecimalType()
134
.hasPrecision(10)
135
.hasScale(2)
136
.hasPrecisionAndScale(10, 2);
137
138
// Conversion validation
139
assertThat(new VarCharType())
140
.supportsInputConversion(String.class)
141
.supportsInputConversion(byte[].class)
142
.doesNotSupportInputConversion(Integer.class);
143
144
// String representation validation
145
assertThat(new IntType())
146
.hasSummaryString("INT")
147
.hasSerializableString("INT");
148
```
149
150
## Type Condition Utilities
151
152
Pre-defined conditions for common type property tests that can be used with AssertJ's condition assertions.
153
154
### DataType Conditions
155
156
```java { .api }
157
public class DataTypeConditions {
158
public static final Condition<DataType> NULLABLE;
159
public static final Condition<DataType> INTERNAL;
160
}
161
```
162
163
### LogicalType Conditions
164
165
```java { .api }
166
public class LogicalTypeConditions {
167
public static final Condition<LogicalType> NULLABLE;
168
}
169
```
170
171
### Usage Examples
172
173
```java
174
import static org.apache.flink.table.test.DataTypeConditions.*;
175
import static org.apache.flink.table.test.LogicalTypeConditions.*;
176
import static org.assertj.core.api.Assertions.not;
177
178
DataType nullableString = DataTypes.STRING();
179
DataType nonNullableInt = DataTypes.INT().notNull();
180
181
// Using DataType conditions
182
assertThat(nullableString).is(NULLABLE);
183
assertThat(nonNullableInt).is(not(NULLABLE));
184
assertThat(nullableString).is(not(INTERNAL));
185
186
// Using LogicalType conditions
187
assertThat(nullableString.getLogicalType()).is(NULLABLE);
188
assertThat(nonNullableInt.getLogicalType()).is(not(NULLABLE));
189
190
// Combining with other assertions
191
assertThat(Arrays.asList(nullableString, nonNullableInt))
192
.hasSize(2)
193
.allSatisfy(type -> assertThat(type).hasConversionClass(Object.class))
194
.anySatisfy(type -> assertThat(type).is(NULLABLE));
195
```
196
197
## Advanced Type Testing
198
199
### Complex Nested Types
200
201
```java
202
// Test deeply nested types
203
DataType complexType = DataTypes.ROW(
204
DataTypes.FIELD("users", DataTypes.ARRAY(
205
DataTypes.ROW(
206
DataTypes.FIELD("id", DataTypes.BIGINT()),
207
DataTypes.FIELD("profile", DataTypes.MAP(
208
DataTypes.STRING(),
209
DataTypes.STRING()
210
))
211
)
212
))
213
);
214
215
assertThat(complexType)
216
.isNullable()
217
.getChildren()
218
.hasSize(1)
219
.first()
220
.asInstanceOf(InstanceOfAssertFactories.type(DataType.class))
221
.satisfies(arrayType -> {
222
assertThat(arrayType.getLogicalType())
223
.isInstanceOf(ArrayType.class);
224
225
assertThat(arrayType.getChildren())
226
.hasSize(1)
227
.first()
228
.asInstanceOf(InstanceOfAssertFactories.type(DataType.class))
229
.satisfies(elementType -> {
230
assertThat(elementType.getChildren()).hasSize(2);
231
});
232
});
233
```
234
235
### Type Compatibility Testing
236
237
```java
238
// Test type compatibility
239
LogicalType sourceType = new VarCharType(100);
240
LogicalType targetType = new VarCharType(200);
241
242
// Both should support string conversion
243
assertThat(sourceType)
244
.supportsInputConversion(String.class)
245
.supportsOutputConversion(String.class);
246
247
assertThat(targetType)
248
.supportsInputConversion(String.class)
249
.supportsOutputConversion(String.class);
250
251
// Test serialization compatibility
252
assertThat(sourceType)
253
.isJavaSerializable();
254
```