Search in sources :

Example 1 with UnresolvedDataType

use of org.apache.flink.table.types.UnresolvedDataType in project flink by apache.

the class ValuesITCase method testTypeConversions.

@Test
public void testTypeConversions() throws Exception {
    List<Row> data = Arrays.asList(Row.of(1, "ABC", java.sql.Timestamp.valueOf("2000-12-12 12:30:57.12"), Row.of(1, new byte[] { 1, 2 }, "ABC", Arrays.asList(1, 2, 3))), Row.of(Math.PI, "ABC", LocalDateTime.parse("2000-12-12T12:30:57.123456"), Row.of(Math.PI, new byte[] { 2, 3 }, "ABC", Arrays.asList(1L, 2L, 3L))), Row.of(3.1f, "DEF", LocalDateTime.parse("2000-12-12T12:30:57.1234567"), Row.of(3.1f, new byte[] { 3 }, "DEF", Arrays.asList(1D, 2D, 3D))), Row.of(99L, "DEFG", LocalDateTime.parse("2000-12-12T12:30:57.12345678"), Row.of(99L, new byte[] { 3, 4 }, "DEFG", Arrays.asList(1f, 2f, 3f))), Row.of(0d, "D", LocalDateTime.parse("2000-12-12T12:30:57.123"), Row.of(0d, new byte[] { 4 }, "D", Arrays.asList(1, 2, 3))));
    UnresolvedDataType rowType = DataTypes.ROW(DataTypes.FIELD("a", // test resolution
    DataTypes.of("DECIMAL(10, 2) NOT NULL")), DataTypes.FIELD("b", DataTypes.CHAR(4).notNull()), DataTypes.FIELD("c", DataTypes.TIMESTAMP(4).notNull()), DataTypes.FIELD("row", DataTypes.ROW(DataTypes.FIELD("a", DataTypes.DECIMAL(10, 3)), DataTypes.FIELD("b", DataTypes.BINARY(2)), DataTypes.FIELD("c", DataTypes.CHAR(5).notNull()), DataTypes.FIELD("d", DataTypes.ARRAY(DataTypes.DECIMAL(10, 2))))));
    Table t = tEnv().fromValues(rowType, data);
    TestCollectionTableFactory.reset();
    tEnv().executeSql("CREATE TABLE SinkTable(" + "a DECIMAL(10, 2) NOT NULL, " + "b CHAR(4) NOT NULL," + "c TIMESTAMP(4) NOT NULL," + "`row` ROW<a DECIMAL(10, 3) NOT NULL, b BINARY(2), c CHAR(5) NOT NULL, d ARRAY<DECIMAL(10, 2)>>) " + "WITH ('connector' = 'COLLECTION')");
    t.executeInsert("SinkTable").await();
    List<Row> expected = Arrays.asList(Row.of(new BigDecimal("1.00"), "ABC ", LocalDateTime.parse("2000-12-12T12:30:57.120"), Row.of(new BigDecimal("1.000"), new byte[] { 1, 2 }, "ABC  ", new BigDecimal[] { new BigDecimal("1.00"), new BigDecimal("2.00"), new BigDecimal("3.00") })), Row.of(new BigDecimal("3.14"), "ABC ", LocalDateTime.parse("2000-12-12T12:30:57.123400"), Row.of(new BigDecimal("3.142"), new byte[] { 2, 3 }, "ABC  ", new BigDecimal[] { new BigDecimal("1.00"), new BigDecimal("2.00"), new BigDecimal("3.00") })), Row.of(new BigDecimal("3.10"), "DEF ", LocalDateTime.parse("2000-12-12T12:30:57.123400"), Row.of(new BigDecimal("3.100"), new byte[] { 3, 0 }, "DEF  ", new BigDecimal[] { new BigDecimal("1.00"), new BigDecimal("2.00"), new BigDecimal("3.00") })), Row.of(new BigDecimal("99.00"), "DEFG", LocalDateTime.parse("2000-12-12T12:30:57.123400"), Row.of(new BigDecimal("99.000"), new byte[] { 3, 4 }, "DEFG ", new BigDecimal[] { new BigDecimal("1.00"), new BigDecimal("2.00"), new BigDecimal("3.00") })), Row.of(new BigDecimal("0.00"), "D   ", LocalDateTime.parse("2000-12-12T12:30:57.123"), Row.of(new BigDecimal("0.000"), new byte[] { 4, 0 }, "D    ", new BigDecimal[] { new BigDecimal("1.00"), new BigDecimal("2.00"), new BigDecimal("3.00") })));
    List<Row> actual = TestCollectionTableFactory.getResult();
    assertThat(new HashSet<>(actual), equalTo(new HashSet<>(expected)));
}
Also used : Table(org.apache.flink.table.api.Table) UnresolvedDataType(org.apache.flink.table.types.UnresolvedDataType) Row(org.apache.flink.types.Row) BigDecimal(java.math.BigDecimal) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

BigDecimal (java.math.BigDecimal)1 HashSet (java.util.HashSet)1 Table (org.apache.flink.table.api.Table)1 UnresolvedDataType (org.apache.flink.table.types.UnresolvedDataType)1 Row (org.apache.flink.types.Row)1 Test (org.junit.Test)1