use of org.apache.flink.table.descriptors.DescriptorProperties in project flink by apache.
the class DataGenTableSourceFactoryTest method testDataTypeCoverage.
@Test
public void testDataTypeCoverage() throws Exception {
ResolvedSchema schema = ResolvedSchema.of(Column.physical("f0", DataTypes.CHAR(1)), Column.physical("f1", DataTypes.VARCHAR(10)), Column.physical("f2", DataTypes.STRING()), Column.physical("f3", DataTypes.BOOLEAN()), Column.physical("f4", DataTypes.DECIMAL(32, 2)), Column.physical("f5", DataTypes.TINYINT()), Column.physical("f6", DataTypes.SMALLINT()), Column.physical("f7", DataTypes.INT()), Column.physical("f8", DataTypes.BIGINT()), Column.physical("f9", DataTypes.FLOAT()), Column.physical("f10", DataTypes.DOUBLE()), Column.physical("f11", DataTypes.DATE()), Column.physical("f12", DataTypes.TIME()), Column.physical("f13", DataTypes.TIMESTAMP()), Column.physical("f14", DataTypes.TIMESTAMP_WITH_TIME_ZONE()), Column.physical("f15", DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE()), Column.physical("f16", DataTypes.INTERVAL(DataTypes.DAY())), Column.physical("f17", DataTypes.ARRAY(DataTypes.INT())), Column.physical("f18", DataTypes.MAP(DataTypes.STRING(), DataTypes.DATE())), Column.physical("f19", DataTypes.MULTISET(DataTypes.DECIMAL(32, 2))), Column.physical("f20", DataTypes.ROW(DataTypes.FIELD("a", DataTypes.BIGINT()), DataTypes.FIELD("b", DataTypes.TIME()), DataTypes.FIELD("c", DataTypes.ROW(DataTypes.FIELD("d", DataTypes.TIMESTAMP()))))));
DescriptorProperties descriptor = new DescriptorProperties();
descriptor.putString(FactoryUtil.CONNECTOR.key(), "datagen");
descriptor.putString(DataGenConnectorOptions.NUMBER_OF_ROWS.key(), "10");
// add min max option for numeric types
descriptor.putString("fields.f4.min", "1.0");
descriptor.putString("fields.f4.max", "1000.0");
descriptor.putString("fields.f5.min", "0");
descriptor.putString("fields.f5.max", "127");
descriptor.putString("fields.f6.min", "0");
descriptor.putString("fields.f6.max", "32767");
descriptor.putString("fields.f7.min", "0");
descriptor.putString("fields.f7.max", "65535");
descriptor.putString("fields.f8.min", "0");
descriptor.putString("fields.f8.max", String.valueOf(Long.MAX_VALUE));
descriptor.putString("fields.f9.min", "0");
descriptor.putString("fields.f9.max", String.valueOf(Float.MAX_VALUE));
descriptor.putString("fields.f10.min", "0");
descriptor.putString("fields.f10.max", String.valueOf(Double.MAX_VALUE));
List<RowData> results = runGenerator(schema, descriptor);
Assert.assertEquals("Failed to generate all rows", 10, results.size());
for (RowData row : results) {
for (int i = 0; i < row.getArity(); i++) {
Assert.assertFalse("Column " + schema.getColumnNames().get(i) + " should not be null", row.isNullAt(i));
}
}
}
use of org.apache.flink.table.descriptors.DescriptorProperties in project flink by apache.
the class DataGenTableSourceFactoryTest method testSequenceCheckpointRestore.
@Test
public void testSequenceCheckpointRestore() throws Exception {
DescriptorProperties descriptor = new DescriptorProperties();
descriptor.putString(FactoryUtil.CONNECTOR.key(), "datagen");
descriptor.putString(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.KIND, DataGenConnectorOptionsUtil.SEQUENCE);
descriptor.putLong(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.START, 0);
descriptor.putLong(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.END, 100);
DynamicTableSource dynamicTableSource = createTableSource(ResolvedSchema.of(Column.physical("f0", DataTypes.BIGINT())), descriptor.asMap());
DataGenTableSource dataGenTableSource = (DataGenTableSource) dynamicTableSource;
DataGeneratorSource<RowData> source = dataGenTableSource.createSource();
final int initElement = 0;
final int maxElement = 100;
final Set<RowData> expectedOutput = new HashSet<>();
for (long i = initElement; i <= maxElement; i++) {
expectedOutput.add(GenericRowData.of(i));
}
DataGeneratorSourceTest.innerTestDataGenCheckpointRestore(() -> {
try {
return InstantiationUtil.clone(source);
} catch (IOException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
}, expectedOutput);
}
use of org.apache.flink.table.descriptors.DescriptorProperties in project flink by apache.
the class DataGenTableSourceFactoryTest method testWrongStartInRandom.
@Test
public void testWrongStartInRandom() {
try {
DescriptorProperties descriptor = new DescriptorProperties();
descriptor.putString(FactoryUtil.CONNECTOR.key(), "datagen");
descriptor.putString(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.KIND, DataGenConnectorOptionsUtil.RANDOM);
descriptor.putLong(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.START, 0);
createTableSource(ResolvedSchema.of(Column.physical("f0", DataTypes.BIGINT())), descriptor.asMap());
} catch (ValidationException e) {
Throwable cause = e.getCause();
Assert.assertTrue(cause.toString(), cause instanceof ValidationException);
Assert.assertTrue(cause.getMessage(), cause.getMessage().contains("Unsupported options:\n\nfields.f0.start"));
return;
}
Assert.fail("Should fail by ValidationException.");
}
use of org.apache.flink.table.descriptors.DescriptorProperties in project flink by apache.
the class DataGenTableSourceFactoryTest method testWrongLenInRandomLong.
@Test
public void testWrongLenInRandomLong() {
try {
DescriptorProperties descriptor = new DescriptorProperties();
descriptor.putString(FactoryUtil.CONNECTOR.key(), "datagen");
descriptor.putString(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.KIND, DataGenConnectorOptionsUtil.RANDOM);
descriptor.putInt(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.LENGTH, 100);
createTableSource(ResolvedSchema.of(Column.physical("f0", DataTypes.BIGINT())), descriptor.asMap());
} catch (ValidationException e) {
Throwable cause = e.getCause();
Assert.assertTrue(cause.toString(), cause instanceof ValidationException);
Assert.assertTrue(cause.getMessage(), cause.getMessage().contains("Unsupported options:\n\nfields.f0.length"));
return;
}
Assert.fail("Should fail by ValidationException.");
}
use of org.apache.flink.table.descriptors.DescriptorProperties in project flink by apache.
the class DataGenTableSourceFactoryTest method testWrongTypes.
@Test
public void testWrongTypes() {
try {
DescriptorProperties descriptor = new DescriptorProperties();
descriptor.putString(FactoryUtil.CONNECTOR.key(), "datagen");
descriptor.putString(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.KIND, DataGenConnectorOptionsUtil.SEQUENCE);
descriptor.putString(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.START, "Wrong");
descriptor.putString(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.END, "Wrong");
createTableSource(ResolvedSchema.of(Column.physical("f0", DataTypes.BIGINT())), descriptor.asMap());
} catch (ValidationException e) {
Throwable cause = e.getCause();
Assert.assertTrue(cause.toString(), cause instanceof IllegalArgumentException);
Assert.assertTrue(cause.getMessage(), cause.getMessage().contains("Could not parse value 'Wrong' for key 'fields.f0.start'"));
return;
}
Assert.fail("Should fail by ValidationException.");
}
Aggregations