def __init__(self, j_closeable_iterator, field_data_types): self._j_closeable_iterator = j_closeable_iterator self._j_field_data_types = field_data_types self._data_types = [ _from_java_type(j_field_data_type) for j_field_data_type in self._j_field_data_types ]
def test_atomic_type_with_data_type_with_parameters(self): gateway = get_gateway() JDataTypes = gateway.jvm.DataTypes java_types = [ JDataTypes.TIME(3).notNull(), JDataTypes.TIMESTAMP().notNull(), JDataTypes.VARBINARY(100).notNull(), JDataTypes.BINARY(2).notNull(), JDataTypes.VARCHAR(30).notNull(), JDataTypes.CHAR(50).notNull(), JDataTypes.DECIMAL(20, 10).notNull() ] converted_python_types = [_from_java_type(item) for item in java_types] expected = [ DataTypes.TIME(3, False), DataTypes.TIMESTAMP(TimestampKind.REGULAR).not_null(), DataTypes.VARBINARY(100, False), DataTypes.BINARY(2, False), DataTypes.VARCHAR(30, False), DataTypes.CHAR(50, False), DataTypes.DECIMAL(20, 10, False) ] self.assertEqual(converted_python_types, expected)
def to_row_data_type(self) -> RowType: """ Converts a table schema into a (nested) data type describing a :func:`pyflink.table.types.DataTypes.ROW`. :return: The row data type. """ return _from_java_type(self._j_table_schema.toRowDataType())
def test_atomic_type_with_data_type_with_parameters(self): gateway = get_gateway() JDataTypes = gateway.jvm.DataTypes java_types = [ JDataTypes.TIME(3).notNull(), JDataTypes.TIMESTAMP(3).notNull(), JDataTypes.VARBINARY(100).notNull(), JDataTypes.BINARY(2).notNull(), JDataTypes.VARCHAR(30).notNull(), JDataTypes.CHAR(50).notNull(), JDataTypes.DECIMAL(20, 10).notNull() ] converted_python_types = [_from_java_type(item) for item in java_types] expected = [ DataTypes.TIME(3, False), DataTypes.TIMESTAMP(3).not_null(), DataTypes.VARBINARY(100, False), DataTypes.BINARY(2, False), DataTypes.VARCHAR(30, False), DataTypes.CHAR(50, False), DataTypes.DECIMAL(20, 10, False) ] self.assertEqual(converted_python_types, expected) # Legacy type tests Types = gateway.jvm.org.apache.flink.table.api.Types InternalBigDecimalTypeInfo = \ gateway.jvm.org.apache.flink.table.runtime.typeutils.BigDecimalTypeInfo java_types = [ Types.STRING(), Types.DECIMAL(), InternalBigDecimalTypeInfo(12, 5) ] converted_python_types = [_from_java_type(item) for item in java_types] expected = [ DataTypes.VARCHAR(2147483647), DataTypes.DECIMAL(38, 18), DataTypes.DECIMAL(12, 5) ] self.assertEqual(converted_python_types, expected)
def get_field_data_types(self) -> List[DataType]: """ Returns all field data types as a list. :return: A list of all field data types. """ return [ _from_java_type(item) for item in self._j_table_schema.getFieldDataTypes() ]
def test_list_view_type(self): test_types = [ DataTypes.LIST_VIEW(DataTypes.BIGINT()), DataTypes.LIST_VIEW(DataTypes.STRING()) ] java_types = [_to_java_type(item) for item in test_types] converted_python_types = [_from_java_type(item) for item in java_types] self.assertEqual(test_types, converted_python_types)
def test_multiset_type(self): test_types = [DataTypes.MULTISET(DataTypes.BIGINT()), DataTypes.MULTISET(DataTypes.STRING()), DataTypes.MULTISET(DataTypes.MULTISET(DataTypes.BIGINT())), DataTypes.MULTISET(DataTypes.MULTISET(DataTypes.STRING()))] java_types = [_to_java_type(item) for item in test_types] converted_python_types = [_from_java_type(item) for item in java_types] self.assertEqual(test_types, converted_python_types)
def test_row_type(self): test_types = [DataTypes.ROW([DataTypes.FIELD("a", DataTypes.INT()), DataTypes.FIELD("b", DataTypes.ROW( [DataTypes.FIELD("c", DataTypes.STRING())]))])] java_types = [_to_java_type(item) for item in test_types] converted_python_types = [_from_java_type(item) for item in java_types] self.assertEqual(test_types, converted_python_types)
def test_array_type(self): # nullable/not_null flag will be lost during the conversion. test_types = [DataTypes.ARRAY(DataTypes.BIGINT()), DataTypes.ARRAY(DataTypes.BIGINT()), DataTypes.ARRAY(DataTypes.STRING()), DataTypes.ARRAY(DataTypes.ARRAY(DataTypes.BIGINT())), DataTypes.ARRAY(DataTypes.ARRAY(DataTypes.STRING()))] java_types = [_to_java_type(item) for item in test_types] converted_python_types = [_from_java_type(item) for item in java_types] self.assertEqual(test_types, converted_python_types)
def test_array_type(self): test_types = [DataTypes.ARRAY(DataTypes.BIGINT()), # array type with not null basic data type means primitive array DataTypes.ARRAY(DataTypes.BIGINT().not_null()), DataTypes.ARRAY(DataTypes.STRING()), DataTypes.ARRAY(DataTypes.ARRAY(DataTypes.BIGINT())), DataTypes.ARRAY(DataTypes.ARRAY(DataTypes.STRING()))] java_types = [_to_java_type(item) for item in test_types] converted_python_types = [_from_java_type(item) for item in java_types] self.assertEqual(test_types, converted_python_types)
def get_field_data_type(self, field): """ Returns the specified data type for the given field index or field name. :param field: The index of the field or the name of the field. :return: The data type of the specified field. """ if not isinstance(field, (int, str, unicode)): raise TypeError("Expected field index or field name, got %s" % type(field)) optional_result = self._j_table_schema.getFieldDataType(field) if optional_result.isPresent(): return _from_java_type(optional_result.get()) else: return None
def test_basic_type(self): test_types = [DataTypes.STRING(), DataTypes.BOOLEAN(), DataTypes.BYTES(), DataTypes.TINYINT(), DataTypes.SMALLINT(), DataTypes.INT(), DataTypes.BIGINT(), DataTypes.FLOAT(), DataTypes.DOUBLE(), DataTypes.DATE(), DataTypes.TIME(), DataTypes.TIMESTAMP(3)] java_types = [_to_java_type(item) for item in test_types] converted_python_types = [_from_java_type(item) for item in java_types] self.assertEqual(test_types, converted_python_types)