Search in sources :

Example 26 with LogicalType

use of org.apache.flink.table.types.logical.LogicalType in project flink by apache.

the class InternalDataUtils method toGenericMap.

static GenericMapData toGenericMap(MapData mapData, LogicalType logicalType) {
    final LogicalType keyType = logicalType.is(LogicalTypeRoot.MULTISET) ? ((MultisetType) logicalType).getElementType() : ((MapType) logicalType).getKeyType();
    final LogicalType valueType = logicalType.is(LogicalTypeRoot.MULTISET) ? new IntType(false) : ((MapType) logicalType).getValueType();
    final ArrayData.ElementGetter keyGetter = ArrayData.createElementGetter(keyType);
    final ArrayData.ElementGetter valueGetter = ArrayData.createElementGetter(valueType);
    final ArrayData keys = mapData.keyArray();
    final ArrayData values = mapData.valueArray();
    final LinkedHashMap<Object, Object> newMap = new LinkedHashMap<>();
    for (int i = 0; i < mapData.size(); i++) {
        Object key = null;
        Object value = null;
        if (!keys.isNullAt(i)) {
            key = toGenericInternalData(keyGetter.getElementOrNull(keys, i), keyType);
        }
        if (!values.isNullAt(i)) {
            value = toGenericInternalData(valueGetter.getElementOrNull(values, i), valueType);
        }
        newMap.put(key, value);
    }
    return new GenericMapData(newMap);
}
Also used : GenericMapData(org.apache.flink.table.data.GenericMapData) LogicalType(org.apache.flink.table.types.logical.LogicalType) IntType(org.apache.flink.table.types.logical.IntType) GenericArrayData(org.apache.flink.table.data.GenericArrayData) ArrayData(org.apache.flink.table.data.ArrayData) LinkedHashMap(java.util.LinkedHashMap)

Example 27 with LogicalType

use of org.apache.flink.table.types.logical.LogicalType in project flink by apache.

the class LogicalTypesTest method testRowType.

@Test
public void testRowType() {
    assertThat(new RowType(Arrays.asList(new RowType.RowField("a", new VarCharType(), "Someone's desc."), new RowType.RowField("b`", new TimestampType())))).satisfies(baseAssertions("ROW<`a` VARCHAR(1) 'Someone''s desc.', `b``` TIMESTAMP(6)>", "ROW<`a` VARCHAR(1) '...', `b``` TIMESTAMP(6)>", new Class[] { Row.class }, new Class[] { Row.class }, new LogicalType[] { new VarCharType(), new TimestampType() }, new RowType(Arrays.asList(new RowType.RowField("a", new VarCharType(), "Different desc."), new RowType.RowField("b`", new TimestampType())))));
    assertThatThrownBy(() -> new RowType(Arrays.asList(new RowType.RowField("b", new VarCharType()), new RowType.RowField("b", new VarCharType()), new RowType.RowField("a", new VarCharType()), new RowType.RowField("a", new TimestampType())))).isInstanceOf(ValidationException.class);
    assertThatThrownBy(() -> new RowType(Collections.singletonList(new RowType.RowField("", new VarCharType())))).isInstanceOf(ValidationException.class);
}
Also used : RowType(org.apache.flink.table.types.logical.RowType) LocalZonedTimestampType(org.apache.flink.table.types.logical.LocalZonedTimestampType) TimestampType(org.apache.flink.table.types.logical.TimestampType) ZonedTimestampType(org.apache.flink.table.types.logical.ZonedTimestampType) LogicalType(org.apache.flink.table.types.logical.LogicalType) VarCharType(org.apache.flink.table.types.logical.VarCharType) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 28 with LogicalType

use of org.apache.flink.table.types.logical.LogicalType in project flink by apache.

the class LogicalTypesTest method nullability.

private static void nullability(LogicalType nullableType) {
    final LogicalType notNullInstance = nullableType.copy(false);
    assertThat(notNullInstance).isNotNullable();
    assertThat(nullableType).isNotEqualTo(notNullInstance);
}
Also used : LogicalType(org.apache.flink.table.types.logical.LogicalType)

Example 29 with LogicalType

use of org.apache.flink.table.types.logical.LogicalType in project flink by apache.

the class LogicalTypesTest method testArrayType.

@Test
public void testArrayType() {
    assertThat(new ArrayType(new TimestampType())).satisfies(baseAssertions("ARRAY<TIMESTAMP(6)>", "ARRAY<TIMESTAMP(6)>", new Class[] { java.sql.Timestamp[].class, java.time.LocalDateTime[].class, List.class, ArrayList.class }, new Class[] { java.sql.Timestamp[].class, java.time.LocalDateTime[].class, List.class }, new LogicalType[] { new TimestampType() }, new ArrayType(new SmallIntType())));
    assertThat(new ArrayType(new ArrayType(new TimestampType()))).satisfies(baseAssertions("ARRAY<ARRAY<TIMESTAMP(6)>>", "ARRAY<ARRAY<TIMESTAMP(6)>>", new Class[] { java.sql.Timestamp[][].class, java.time.LocalDateTime[][].class }, new Class[] { java.sql.Timestamp[][].class, java.time.LocalDateTime[][].class }, new LogicalType[] { new ArrayType(new TimestampType()) }, new ArrayType(new ArrayType(new SmallIntType()))));
    final LogicalType nestedArray = new ArrayType(new ArrayType(new TimestampType()));
    assertThat(nestedArray).doesNotSupportInputConversion(java.sql.Timestamp[].class).doesNotSupportOutputConversion(java.sql.Timestamp[].class);
}
Also used : ArrayType(org.apache.flink.table.types.logical.ArrayType) LocalDateTime(java.time.LocalDateTime) SmallIntType(org.apache.flink.table.types.logical.SmallIntType) ArrayList(java.util.ArrayList) LocalZonedTimestampType(org.apache.flink.table.types.logical.LocalZonedTimestampType) TimestampType(org.apache.flink.table.types.logical.TimestampType) ZonedTimestampType(org.apache.flink.table.types.logical.ZonedTimestampType) LogicalType(org.apache.flink.table.types.logical.LogicalType) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 30 with LogicalType

use of org.apache.flink.table.types.logical.LogicalType in project flink by apache.

the class LogicalTypesTest method testMultisetType.

@Test
public void testMultisetType() {
    assertThat(new MultisetType(new TimestampType())).satisfies(baseAssertions("MULTISET<TIMESTAMP(6)>", "MULTISET<TIMESTAMP(6)>", new Class[] { Map.class, HashMap.class, TreeMap.class }, new Class[] { Map.class }, new LogicalType[] { new TimestampType() }, new MultisetType(new SmallIntType())));
    assertThat(new MultisetType(new MultisetType(new TimestampType()))).satisfies(baseAssertions("MULTISET<MULTISET<TIMESTAMP(6)>>", "MULTISET<MULTISET<TIMESTAMP(6)>>", new Class[] { Map.class, HashMap.class, TreeMap.class }, new Class[] { Map.class }, new LogicalType[] { new MultisetType(new TimestampType()) }, new MultisetType(new MultisetType(new SmallIntType()))));
}
Also used : SmallIntType(org.apache.flink.table.types.logical.SmallIntType) HashMap(java.util.HashMap) LocalZonedTimestampType(org.apache.flink.table.types.logical.LocalZonedTimestampType) TimestampType(org.apache.flink.table.types.logical.TimestampType) ZonedTimestampType(org.apache.flink.table.types.logical.ZonedTimestampType) LogicalType(org.apache.flink.table.types.logical.LogicalType) TreeMap(java.util.TreeMap) MultisetType(org.apache.flink.table.types.logical.MultisetType) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Aggregations

LogicalType (org.apache.flink.table.types.logical.LogicalType)192 DataType (org.apache.flink.table.types.DataType)53 RowType (org.apache.flink.table.types.logical.RowType)53 RowData (org.apache.flink.table.data.RowData)45 List (java.util.List)29 ArrayList (java.util.ArrayList)28 TableException (org.apache.flink.table.api.TableException)25 TimestampType (org.apache.flink.table.types.logical.TimestampType)25 Internal (org.apache.flink.annotation.Internal)21 IntType (org.apache.flink.table.types.logical.IntType)21 Map (java.util.Map)20 ValidationException (org.apache.flink.table.api.ValidationException)20 ArrayType (org.apache.flink.table.types.logical.ArrayType)19 DecimalType (org.apache.flink.table.types.logical.DecimalType)19 LocalZonedTimestampType (org.apache.flink.table.types.logical.LocalZonedTimestampType)17 Test (org.junit.Test)17 BigIntType (org.apache.flink.table.types.logical.BigIntType)16 LegacyTypeInformationType (org.apache.flink.table.types.logical.LegacyTypeInformationType)16 GenericRowData (org.apache.flink.table.data.GenericRowData)15 Arrays (java.util.Arrays)14